fix(Page): Use _pageBindings as a Map (#3001)

In accordance with its declared type, `Map<string, Function>`.
Currently, it is used as a plain old JS object. The compiler marks this
usage as an error when `noImplicitAny: true`. This change switches to
use the appropriate Map methods `has/get/set`.

Fixes #3000
This commit is contained in:
Nathan Shively-Sanders 2018-07-31 12:18:10 -07:00 committed by Andrey Lushnikov
parent 3335d369d3
commit 25d7eff374

View File

@ -384,9 +384,9 @@ class Page extends EventEmitter {
* @param {function(?)} puppeteerFunction * @param {function(?)} puppeteerFunction
*/ */
async exposeFunction(name, puppeteerFunction) { async exposeFunction(name, puppeteerFunction) {
if (this._pageBindings[name]) if (this._pageBindings.has(name))
throw new Error(`Failed to add page binding with name ${name}: window['${name}'] already exists!`); throw new Error(`Failed to add page binding with name ${name}: window['${name}'] already exists!`);
this._pageBindings[name] = puppeteerFunction; this._pageBindings.set(name, puppeteerFunction);
const expression = helper.evaluationString(addPageBinding, name); const expression = helper.evaluationString(addPageBinding, name);
await this._client.send('Runtime.addBinding', {name: name}); await this._client.send('Runtime.addBinding', {name: name});
@ -486,7 +486,7 @@ class Page extends EventEmitter {
*/ */
async _onBindingCalled(event) { async _onBindingCalled(event) {
const {name, seq, args} = JSON.parse(event.payload); const {name, seq, args} = JSON.parse(event.payload);
const result = await this._pageBindings[name](...args); const result = await this._pageBindings.get(name)(...args);
const expression = helper.evaluationString(deliverResult, name, seq, result); const expression = helper.evaluationString(deliverResult, name, seq, result);
this._client.send('Runtime.evaluate', { expression, contextId: event.executionContextId }).catch(debugError); this._client.send('Runtime.evaluate', { expression, contextId: event.executionContextId }).catch(debugError);