提交 461dc840 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

code clean

上级 d5271cc6
......@@ -85,6 +85,7 @@ export class Browser extends EventEmitter {
} catch (e) {
log.error('PuppetWebBrowser', 'init() exception: %s', e.message)
this.state.current('close')
await this.quit()
throw e
......@@ -99,7 +100,6 @@ export class Browser extends EventEmitter {
await this.driver.get(url)
} catch (e) {
log.error('PuppetWebBrowser', 'open() exception: %s', e.message)
this.dead(e.message)
throw e
}
}
......@@ -117,7 +117,6 @@ export class Browser extends EventEmitter {
await this.quit()
// if (this.currentState() === 'opening') {
if (this.state.current() === 'open' && this.state.inprocess()) {
log.warn('PuppetWebBrowser', 'restart() found state.current() === open and inprocess()')
return
......@@ -129,14 +128,12 @@ export class Browser extends EventEmitter {
public async quit(): Promise<void> {
log.verbose('PuppetWebBrowser', 'quit()')
// if (this.currentState() === 'closing') {
if (this.state.current() === 'close' && this.state.inprocess()) {
const e = new Error('quit() be called when state.current() is close with inprocess()?')
log.warn('PuppetWebBrowser', e.message)
throw e
}
// this.currentState('closing')
this.state.current('close', false)
try {
......@@ -327,7 +324,6 @@ export class Browser extends EventEmitter {
if (forceReason) {
dead = true
msg = forceReason
// } else if (this.targetState() !== 'open') {
} else if (this.state.target() !== 'open') {
dead = true
msg = 'state.target() not open'
......@@ -343,15 +339,7 @@ export class Browser extends EventEmitter {
: ''
, msg
)
// no need to quit here. dead event listener will do this async job, and do it better than here
// this.quit()
// if (this.targetState() !== 'open' || this.currentState() === 'opening') {
// log.warn('PuppetWebBrowser', 'dead() wil not emit `dead` event because currentState is `opening` or targetState !== open')
// } else {
// log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg)
// this.emit('dead', msg)
// }
if ( this.state.target() === 'open'
&& this.state.current() === 'open'
&& this.state.stable()
......@@ -359,10 +347,11 @@ export class Browser extends EventEmitter {
log.verbose('PuppetWebBrowser', 'dead() emit a `dead` event because %s', msg)
this.emit('dead', msg)
} else {
log.warn('PuppetWebBrowser', 'dead() wil not emit `dead` event because %s'
, 'state is not `stable open`'
log.warn('PuppetWebBrowser', 'dead() wil not emit `dead` event because states are: target(%s), current(%s), stable(%s)'
, this.state.target(), this.state.current(), this.state.stable()
)
}
}
return dead
}
......
......@@ -82,7 +82,6 @@ async function onBrowserDead(this: PuppetWeb, e): Promise<void> {
await this.browser.quit()
log.verbose('PuppetWebEvent', 'onBrowserDead() browser quit-ed')
// if (this.browser.targetState() !== 'open') {
if (browser.state.target() !== 'open') {
log.warn('PuppetWebEvent', 'onBrowserDead() will not init browser because browser.state.target(%s) !== open'
, browser.state.target()
......
......@@ -105,28 +105,24 @@ export class PuppetWeb extends Puppet {
public async quit(): Promise<void> {
log.verbose('PuppetWeb', 'quit()')
// this.targetState('dead')
// XXX should we set `target` to `dead` in `quit()`?
this.state.target('dead')
// this.state.target('dead')
// if (this.currentState() === 'killing') {
if (this.state.current() === 'dead' && this.state.inprocess()) {
// log.warn('PuppetWeb', 'quit() is called but readyState is `disconnecting`?')
log.warn('PuppetWeb', 'quit() is called but state.current()) is `dead` and inprocess()?')
throw new Error('do not call quit again when quiting')
}
// POISON must feed before readyState set to "disconnecting"
// POISON must feed before state set to `dead` & `inprocess`
this.emit('watchdog', {
data: 'PuppetWeb.quit()',
type: 'POISON'
})
// this.currentState('killing')
this.state.current('dead', false)
// return co.call(this, function* () {
try {
if (this.bridge) { // TODO use StateMonitor
......@@ -153,25 +149,15 @@ export class PuppetWeb extends Puppet {
// this.browser = null
} else { log.warn('PuppetWeb', 'quit() without a browser') }
// @deprecated 20161004
// log.verbose('PuppetWeb', 'quit() server.quit() this.initAttach(null)')
// await this.initAttach(null)
// this.currentState('dead')
this.state.current('dead')
// }).catch(e => { // Reject
} catch (e) {
log.error('PuppetWeb', 'quit() exception: %s', e.message)
// this.currentState('dead')
this.state.current('dead')
throw e
}
// .then(() => { // Finally, Fail Safe
log.verbose('PuppetWeb', 'quit() done')
// this.currentState('dead')
this.state.current('dead')
// })
log.verbose('PuppetWeb', 'quit() done')
this.state.current('dead')
}
public async initBrowser(): Promise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册