Commit 8566083c authored by Ingvar Stepanyan's avatar Ingvar Stepanyan Committed by Commit Bot

Fix and simplify InspectorFrontendHost stubs

 - ES6 `class` members are non-enumerable, so `for-in` iterated over an
   empty list, not stubbing anything.
 - When `window.InspectorFrontendHost` was missing, it was unnecessarily
   set to a new object twice.
 - Stub error was shown each time command was invoked; changed to
   showing it once for reduced noise in logs and simpler implementation.

Change-Id: Ib0083737873a373220b3a5e1c0ea18b10482bc6c
Reviewed-on: https://chromium-review.googlesource.com/1068915Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Ingvar Stepanyan <ingvar@cloudflare.com>
Cr-Commit-Position: refs/heads/master@{#592011}
parent 057aefb2
......@@ -556,8 +556,7 @@ Host.InspectorFrontendAPIImpl = class {
/**
* @type {!InspectorFrontendHostAPI}
*/
let InspectorFrontendHost = window.InspectorFrontendHost || null;
window.InspectorFrontendHost = InspectorFrontendHost;
let InspectorFrontendHost = window.InspectorFrontendHost;
(function() {
function initializeInspectorFrontendHost() {
......@@ -568,25 +567,17 @@ window.InspectorFrontendHost = InspectorFrontendHost;
} else {
// Otherwise add stubs for missing methods that are declared in the interface.
proto = Host.InspectorFrontendHostStub.prototype;
for (const name in proto) {
const value = proto[name];
if (typeof value !== 'function' || InspectorFrontendHost[name])
for (const name of Object.getOwnPropertyNames(proto)) {
const stub = proto[name];
if (typeof stub !== 'function' || InspectorFrontendHost[name])
continue;
InspectorFrontendHost[name] = stub.bind(null, name);
console.error(
'Incompatible embedder: method InspectorFrontendHost.' + name + ' is missing. Using stub instead.');
InspectorFrontendHost[name] = stub;
}
}
/**
* @param {string} name
* @return {?}
*/
function stub(name) {
console.error('Incompatible embedder: method InspectorFrontendHost.' + name + ' is missing. Using stub instead.');
const args = Array.prototype.slice.call(arguments, 1);
return proto[name].apply(InspectorFrontendHost, args);
}
// Attach the events object.
InspectorFrontendHost.events = new Common.Object();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment