| Index: sky/framework/inspector/inspector.sky
|
| diff --git a/sky/framework/inspector/inspector.sky b/sky/framework/inspector/inspector.sky
|
| index 4d5107de19a95c7e7b8d782f7b8cd114191c51b4..aa2fe070da95a036204269e59016157020663baf 100644
|
| --- a/sky/framework/inspector/inspector.sky
|
| +++ b/sky/framework/inspector/inspector.sky
|
| @@ -11,110 +11,111 @@
|
| <import src="indexeddb-agent.sky" as="IndexedDBAgent" />
|
| <import src="css-agent.sky" as="CSSAgent" />
|
| <script>
|
| -function InspectorBackend(frontend) {
|
| - var domAgent = new DOMAgent(this);
|
| - this.agents = {
|
| - Console: new ConsoleAgent(),
|
| - DOM: domAgent,
|
| - Page: new PageAgent(this),
|
| - Worker: new WorkerAgent(),
|
| - Runtime: new RuntimeAgent(this),
|
| - CSS: new CSSAgent(domAgent),
|
| - IndexedDB: new IndexedDBAgent(),
|
| - };
|
| - this.missingNames_ = {};
|
| - this.unansweredMessages_ = [];
|
| -}
|
| +class InspectorBackend extends inspector.InspectorBackend.stubClass {
|
| + constructor(frontend) {
|
| + var domAgent = new DOMAgent(this);
|
| + this.agents = {
|
| + Console: new ConsoleAgent(),
|
| + DOM: domAgent,
|
| + Page: new PageAgent(this),
|
| + Worker: new WorkerAgent(),
|
| + Runtime: new RuntimeAgent(this),
|
| + CSS: new CSSAgent(domAgent),
|
| + IndexedDB: new IndexedDBAgent(),
|
| + };
|
| + this.missingNames_ = {};
|
| + this.unansweredMessages_ = [];
|
| +
|
| + this.IMPLEMENTED_IN_CPP = "IMPLEMENTED_IN_CPP";
|
| + this.ASYNC_RESPONSE = "ASYNC_RESPONSE";
|
| + this.MESSAGE_TIMEOUT_MS = 30000;
|
| +
|
| + Object.preventExtensions(this);
|
| + }
|
|
|
| -InspectorBackend.prototype = Object.create(
|
| - inspector.InspectorBackend.stubClass.prototype);
|
| + onConnect() {
|
| + }
|
|
|
| -InspectorBackend.prototype.IMPLEMENTED_IN_CPP = "IMPLEMENTED_IN_CPP";
|
| -InspectorBackend.prototype.ASYNC_RESPONSE = "ASYNC_RESPONSE";
|
| -InspectorBackend.prototype.MESSAGE_TIMEOUT_MS = 30000;
|
| + onDisconnect() {
|
| + }
|
|
|
| -InspectorBackend.prototype.onConnect = function() {
|
| -};
|
| + logMissing_(name) {
|
| + if (name in this.missingNames_)
|
| + return;
|
| + this.missingNames_[name] = true;
|
| + console.log("InspectorBackend missing " + name);
|
| + }
|
|
|
| -InspectorBackend.prototype.onDisconnect = function() {
|
| -};
|
| + dispatch_(descriptor, params, message_id) {
|
| + var parsed = descriptor.split('.');
|
|
|
| -InspectorBackend.prototype.logMissing_ = function(name) {
|
| - if (name in this.missingNames_)
|
| - return;
|
| - this.missingNames_[name] = true;
|
| - console.log("InspectorBackend missing " + name);
|
| -}
|
| + var agentName = parsed[0];
|
| + var methodName = parsed[1];
|
|
|
| -InspectorBackend.prototype.dispatch_ = function(descriptor, params, message_id) {
|
| - var parsed = descriptor.split('.');
|
| + // Debugger is implemented in c++.
|
| + if (agentName == "Debugger")
|
| + return this.IMPLEMENTED_IN_CPP;
|
|
|
| - var agentName = parsed[0];
|
| - var methodName = parsed[1];
|
| + if (!(agentName in this.agents)) {
|
| + this.logMissing_(agentName);
|
| + return {};
|
| + }
|
|
|
| - // Debugger is implemented in c++.
|
| - if (agentName == "Debugger")
|
| - return this.IMPLEMENTED_IN_CPP;
|
| + var agent = this.agents[agentName];
|
|
|
| - if (!(agentName in this.agents)) {
|
| - this.logMissing_(agentName);
|
| - return {};
|
| - }
|
| + if (!(methodName in agent)) {
|
| + this.logMissing_(descriptor);
|
| + return {};
|
| + }
|
|
|
| - var agent = this.agents[agentName];
|
| + try {
|
| + return agent[methodName](params, message_id);
|
| + } catch(ex) {
|
| + console.log(descriptor + ": " + ex);
|
| + }
|
| + }
|
|
|
| - if (!(methodName in agent)) {
|
| - this.logMissing_(descriptor);
|
| - return {};
|
| + onMessage(data) {
|
| + var message = JSON.parse(data);
|
| + var result = this.dispatch_(message.method, message.params, message.id);
|
| + if (result === this.IMPLEMENTED_IN_CPP)
|
| + return;
|
| + this.unansweredMessages_.push(message.id);
|
| + // FIXME: This magic return value is kinda hacky.
|
| + if (result !== this.ASYNC_RESPONSE)
|
| + this.sendResponse(message.id, result);
|
| + else {
|
| + window.setTimeout(function() {
|
| + if (this.unansweredMessages_.indexOf(message.id) == -1)
|
| + return;
|
| + console.log("Error, failed to reply to message id " + message.id);
|
| + }.bind(this), this.MESSAGE_TIMEOUT_MS);
|
| + }
|
| }
|
|
|
| - try {
|
| - return agent[methodName](params, message_id);
|
| - } catch(ex) {
|
| - console.log(descriptor + ": " + ex);
|
| + sendResponse(message_id, result) {
|
| + var messageIndex = this.unansweredMessages_.indexOf(message_id);
|
| + if (messageIndex != -1)
|
| + this.unansweredMessages_.splice(messageIndex, 1);
|
| + else
|
| + console.log("Error, responding to unknown message id " + message_id);
|
| + var response = {
|
| + id: message_id,
|
| + };
|
| + if (typeof result !== "undefined")
|
| + response.result = result;
|
| + window.frontend.sendMessage(JSON.stringify(response));
|
| }
|
| -};
|
|
|
| -InspectorBackend.prototype.onMessage = function(data) {
|
| - var message = JSON.parse(data);
|
| - var result = this.dispatch_(message.method, message.params, message.id);
|
| - if (result === this.IMPLEMENTED_IN_CPP)
|
| - return;
|
| - this.unansweredMessages_.push(message.id);
|
| - // FIXME: This magic return value is kinda hacky.
|
| - if (result !== this.ASYNC_RESPONSE)
|
| - this.sendResponse(message.id, result);
|
| - else {
|
| - window.setTimeout(function() {
|
| - if (this.unansweredMessages_.indexOf(message.id) == -1)
|
| - return;
|
| - console.log("Error, failed to reply to message id " + message.id);
|
| - }.bind(this), this.MESSAGE_TIMEOUT_MS);
|
| + sendMessage(method, params) {
|
| + var message = JSON.stringify({
|
| + method: method,
|
| + params: params,
|
| + });
|
| + window.frontend.sendMessage(message);
|
| }
|
| -};
|
| -
|
| -InspectorBackend.prototype.sendResponse = function(message_id, result) {
|
| - var messageIndex = this.unansweredMessages_.indexOf(message_id);
|
| - if (messageIndex != -1)
|
| - this.unansweredMessages_.splice(messageIndex, 1);
|
| - else
|
| - console.log("Error, responding to unknown message id " + message_id);
|
| - var response = {
|
| - id: message_id,
|
| - };
|
| - if (typeof result !== "undefined")
|
| - response.result = result;
|
| - window.frontend.sendMessage(JSON.stringify(response));
|
| }
|
|
|
| -InspectorBackend.prototype.sendMessage = function(method, params) {
|
| - var message = JSON.stringify({
|
| - method: method,
|
| - params: params,
|
| - });
|
| - window.frontend.sendMessage(message);
|
| -};
|
| -
|
| (function() {
|
| var app = new application.Application(internals.passShellProxyHandle());
|
| var tracingApp = app.shell.connectToApplication("mojo:sky_inspector_server");
|
| @@ -122,6 +123,4 @@ InspectorBackend.prototype.sendMessage = function(method, params) {
|
|
|
| window.frontend = tracingApp.requestService(inspector.InspectorFrontend);
|
| })();
|
| -
|
| -
|
| </script>
|
|
|