Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2900)

Unified Diff: sky/framework/inspector/runtime-agent.sky

Issue 837933003: Convert the inspector framework to use ES6 classes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: prevent extensions Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/inspector/page-agent.sky ('k') | sky/framework/inspector/worker-agent.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/inspector/runtime-agent.sky
diff --git a/sky/framework/inspector/runtime-agent.sky b/sky/framework/inspector/runtime-agent.sky
index d17982499cfdcfdbca55bc231173ebf55c8d7267..62f6a9c2c75d3c6e68e3325e8fa904ef9365e5ed 100644
--- a/sky/framework/inspector/runtime-agent.sky
+++ b/sky/framework/inspector/runtime-agent.sky
@@ -1,37 +1,65 @@
<import src="debug.sky" as="debug" />
<script>
-function Runtime(delegate) {
- this.delegate_ = delegate;
-}
+class Runtime {
+ constructor(delegate) {
+ this.delegate_ = delegate;
+ Object.preventExtensions(this);
+ }
+
+ enable() {
+ this.delegate_.sendMessage("Runtime.executionContextCreated", {
+ "context": {
+ "frameId": 1,
+ "id": 1,
+ }
+ });
+ return {
+ result: true,
+ };
+ }
-Runtime.prototype.enable = function() {
- this.delegate_.sendMessage("Runtime.executionContextCreated", {
- "context": {
- "frameId": 1,
- "id": 1,
+ callFunctionOn(params) {
+ var object = g_objectRegistry.lookup(params.objectId);
+ // This is a horrible hack:
+ var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1];
+ var expression = params.functionDeclaration + "; return " + functionName + ";";
+ var wasThrown = false;
+ var value;
+ try {
+ var func = new Function('', expression)();
+ value = func(object);
+ } catch (e) {
+ value = e;
+ wasThrown = true;
}
- });
- return {
- result: true,
- };
-};
-
-Runtime.prototype.callFunctionOn = function(params) {
- var object = g_objectRegistry.lookup(params.objectId);
- // This is a horrible hack:
- var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1];
- var expression = params.functionDeclaration + "; return " + functionName + ";";
- var wasThrown = false;
- var value;
- try {
- var func = new Function('', expression)();
- value = func(object);
- } catch (e) {
- value = e;
- wasThrown = true;
+
+ return makeResult(params, value, wasThrown);
}
- return makeResult(params, value, wasThrown);
+ // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject.
+ evaluate(params) {
+ var wasThrown = false;
+ var value;
+ try {
+ value = eval(params.expression);
+ } catch (e) {
+ value = e;
+ wasThrown = true;
+ }
+
+ return makeResult(params, value, wasThrown);
+ }
+
+ getProperties(params) {
+ var properties = injectedScript.getProperties(params.objectId, !!params.ownProperties, !!params.accessorPropertiesOnly);
+ var result = {
+ result: properties
+ };
+ if (!params.accessorPropertiesOnly) {
+ result.internalProperties = injectedScript.getInternalProperties(params.objectId);
+ }
+ return result;
+ }
}
// FIXME: This should release all objects associated with an object
@@ -41,24 +69,26 @@ Runtime.prototype.releaseObjectGroup = debug.loggingStub("releaseObjectGroup");
// See InjectedScript._bind for a fancier version of this:
-function RemoteObjectRegistery() {
- this.lastObjectId = 0;
- this.objectsById = [];
-}
+class RemoteObjectRegistery {
+ constructor() {
+ this.lastObjectId = 0;
+ this.objectsById = [];
+ Object.preventExtensions(this);
+ }
-RemoteObjectRegistery.prototype.register = function(object) {
- var objectId = ++this.lastObjectId;
- this.objectsById[objectId] = object;
- return String(objectId);
-}
+ register(object) {
+ var objectId = ++this.lastObjectId;
+ this.objectsById[objectId] = object;
+ return String(objectId);
+ }
-RemoteObjectRegistery.prototype.lookup = function(objectId) {
- return this.objectsById[Number(objectId)];
+ lookup(objectId) {
+ return this.objectsById[Number(objectId)];
+ }
}
var g_objectRegistry = new RemoteObjectRegistery();
-
function makeResult(params, value, wasThrown) {
var type = typeof(value)
var result = {
@@ -101,30 +131,5 @@ function makeResult(params, value, wasThrown) {
return result;
}
-// FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject.
-Runtime.prototype.evaluate = function(params) {
- var wasThrown = false;
- var value;
- try {
- value = eval(params.expression);
- } catch (e) {
- value = e;
- wasThrown = true;
- }
-
- return makeResult(params, value, wasThrown);
-}
-
-Runtime.prototype.getProperties = function(params) {
- var properties = injectedScript.getProperties(params.objectId, !!params.ownProperties, !!params.accessorPropertiesOnly);
- var result = {
- result: properties
- };
- if (!params.accessorPropertiesOnly) {
- result.internalProperties = injectedScript.getInternalProperties(params.objectId);
- }
- return result;
-}
-
module.exports = Runtime;
</script>
« no previous file with comments | « sky/framework/inspector/page-agent.sky ('k') | sky/framework/inspector/worker-agent.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698