Cleanup typechecker errors

This patch cleans up different issues which were spotted by the
typechecker.
This commit is contained in:
Andrey Lushnikov 2017-06-11 23:10:33 -07:00
parent e1d9b29666
commit ac3e76fb22
2 changed files with 11 additions and 7 deletions

View File

@ -61,6 +61,7 @@ class Browser {
}
if (Array.isArray(options.args))
this._chromeArguments.push(...options.args);
this._terminated = false;
this._chromeProcess = null;
this._tabSymbol = Symbol('Browser.TabSymbol');
}
@ -70,7 +71,7 @@ class Browser {
*/
async newPage() {
await this._ensureChromeIsRunning();
if (!this._chromeProcess || this._chromeProcess.killed)
if (!this._chromeProcess || this._terminated)
throw new Error('ERROR: this chrome instance is not alive any more!');
var tab = await CDP.New({port: this._remoteDebuggingPort});
var client = await CDP({tab: tab, port: this._remoteDebuggingPort});
@ -83,7 +84,7 @@ class Browser {
* @param {!Page} page
*/
async closePage(page) {
if (!this._chromeProcess || this._chromeProcess.killed)
if (!this._chromeProcess || this._terminated)
throw new Error('ERROR: this chrome instance is not running');
var tab = page[this._tabSymbol];
if (!tab)
@ -106,7 +107,10 @@ class Browser {
this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {});
// Cleanup as processes exit.
process.on('exit', () => this._chromeProcess.kill());
this._chromeProcess.on('exit', () => removeRecursive(this._userDataDir));
this._chromeProcess.on('exit', () => {
this._terminated = true;
removeRecursive(this._userDataDir);
});
await waitForChromeResponsive(this._remoteDebuggingPort);
}

View File

@ -314,7 +314,7 @@ class Page extends EventEmitter {
/**
* @param {function()} fun
* @param {!Array<*>} args
* @return {!Promise<(!Object|udndefined)>}
* @return {!Promise<(!Object|undefined)>}
*/
async evaluate(fun, ...args) {
var response = await helpers.evaluate(this._client, fun, args, false /* awaitPromise */);
@ -328,7 +328,7 @@ class Page extends EventEmitter {
/**
* @param {function()} fun
* @param {!Array<*>} args
* @return {!Promise<(!Object|udndefined)>}
* @return {!Promise<(!Object|undefined)>}
*/
async evaluateAsync(fun, ...args) {
var response = await helpers.evaluate(this._client, fun, args, true /* awaitPromise */);
@ -396,7 +396,7 @@ class Page extends EventEmitter {
else if (mimeType === 'image/jpeg')
screenshotType = Page.ScreenshotTypes.JPG;
if (!screenshotType)
throw new Error(`Cannot render to file ${fileName} - unsupported mimeType ${mimeType}`);
throw new Error(`Cannot render to file ${filePath} - unsupported mimeType ${mimeType}`);
var buffer = await this.screenshot(screenshotType, clipRect);
fs.writeFileSync(filePath, buffer);
}
@ -538,7 +538,7 @@ function convertPrintParameterToInches(parameter) {
}
var value = Number(valueText);
console.assert(!isNaN(value), 'Failed to parse parameter value: ' + text);
var pixels = value * unitToPixels[unit];
pixels = value * unitToPixels[unit];
} else {
throw new Error('printToPDF Cannot handle parameter type: ' + (typeof parameter));
}