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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <import src="debug.sky" as="debug" /> 1 <import src="debug.sky" as="debug" />
2 <script> 2 <script>
3 function Runtime(delegate) { 3 class Runtime {
4 this.delegate_ = delegate; 4 constructor(delegate) {
5 } 5 this.delegate_ = delegate;
6 6 Object.preventExtensions(this);
7 Runtime.prototype.enable = function() {
8 this.delegate_.sendMessage("Runtime.executionContextCreated", {
9 "context": {
10 "frameId": 1,
11 "id": 1,
12 }
13 });
14 return {
15 result: true,
16 };
17 };
18
19 Runtime.prototype.callFunctionOn = function(params) {
20 var object = g_objectRegistry.lookup(params.objectId);
21 // This is a horrible hack:
22 var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1];
23 var expression = params.functionDeclaration + "; return " + functionName + ";" ;
24 var wasThrown = false;
25 var value;
26 try {
27 var func = new Function('', expression)();
28 value = func(object);
29 } catch (e) {
30 value = e;
31 wasThrown = true;
32 } 7 }
33 8
34 return makeResult(params, value, wasThrown); 9 enable() {
10 this.delegate_.sendMessage("Runtime.executionContextCreated", {
11 "context": {
12 "frameId": 1,
13 "id": 1,
14 }
15 });
16 return {
17 result: true,
18 };
19 }
20
21 callFunctionOn(params) {
22 var object = g_objectRegistry.lookup(params.objectId);
23 // This is a horrible hack:
24 var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1];
25 var expression = params.functionDeclaration + "; return " + functionName + " ;";
26 var wasThrown = false;
27 var value;
28 try {
29 var func = new Function('', expression)();
30 value = func(object);
31 } catch (e) {
32 value = e;
33 wasThrown = true;
34 }
35
36 return makeResult(params, value, wasThrown);
37 }
38
39 // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject.
40 evaluate(params) {
41 var wasThrown = false;
42 var value;
43 try {
44 value = eval(params.expression);
45 } catch (e) {
46 value = e;
47 wasThrown = true;
48 }
49
50 return makeResult(params, value, wasThrown);
51 }
52
53 getProperties(params) {
54 var properties = injectedScript.getProperties(params.objectId, !!params.ownP roperties, !!params.accessorPropertiesOnly);
55 var result = {
56 result: properties
57 };
58 if (!params.accessorPropertiesOnly) {
59 result.internalProperties = injectedScript.getInternalProperties(params.ob jectId);
60 }
61 return result;
62 }
35 } 63 }
36 64
37 // FIXME: This should release all objects associated with an object 65 // FIXME: This should release all objects associated with an object
38 // group, see InjectedScriptSource.js for an example. Just have to 66 // group, see InjectedScriptSource.js for an example. Just have to
39 // track which object ids are associated with which object groups first. 67 // track which object ids are associated with which object groups first.
40 Runtime.prototype.releaseObjectGroup = debug.loggingStub("releaseObjectGroup"); 68 Runtime.prototype.releaseObjectGroup = debug.loggingStub("releaseObjectGroup");
41 69
42 // See InjectedScript._bind for a fancier version of this: 70 // See InjectedScript._bind for a fancier version of this:
43 71
44 function RemoteObjectRegistery() { 72 class RemoteObjectRegistery {
45 this.lastObjectId = 0; 73 constructor() {
46 this.objectsById = []; 74 this.lastObjectId = 0;
47 } 75 this.objectsById = [];
76 Object.preventExtensions(this);
77 }
48 78
49 RemoteObjectRegistery.prototype.register = function(object) { 79 register(object) {
50 var objectId = ++this.lastObjectId; 80 var objectId = ++this.lastObjectId;
51 this.objectsById[objectId] = object; 81 this.objectsById[objectId] = object;
52 return String(objectId); 82 return String(objectId);
53 } 83 }
54 84
55 RemoteObjectRegistery.prototype.lookup = function(objectId) { 85 lookup(objectId) {
56 return this.objectsById[Number(objectId)]; 86 return this.objectsById[Number(objectId)];
87 }
57 } 88 }
58 89
59 var g_objectRegistry = new RemoteObjectRegistery(); 90 var g_objectRegistry = new RemoteObjectRegistery();
60 91
61
62 function makeResult(params, value, wasThrown) { 92 function makeResult(params, value, wasThrown) {
63 var type = typeof(value) 93 var type = typeof(value)
64 var result = { 94 var result = {
65 "result": { 95 "result": {
66 "type": type, 96 "type": type,
67 }, 97 },
68 "wasThrown": wasThrown, 98 "wasThrown": wasThrown,
69 }; 99 };
70 100
71 // Unclear why this often fails with: 101 // Unclear why this often fails with:
(...skipping 22 matching lines...) Expand all
94 "scriptId": "1", 124 "scriptId": "1",
95 "url": "", 125 "url": "",
96 "lineNumber": 0, 126 "lineNumber": 0,
97 "columnNumber": 0 127 "columnNumber": 0
98 }] 128 }]
99 } 129 }
100 } 130 }
101 return result; 131 return result;
102 } 132 }
103 133
104 // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject.
105 Runtime.prototype.evaluate = function(params) {
106 var wasThrown = false;
107 var value;
108 try {
109 value = eval(params.expression);
110 } catch (e) {
111 value = e;
112 wasThrown = true;
113 }
114
115 return makeResult(params, value, wasThrown);
116 }
117
118 Runtime.prototype.getProperties = function(params) {
119 var properties = injectedScript.getProperties(params.objectId, !!params.ownPro perties, !!params.accessorPropertiesOnly);
120 var result = {
121 result: properties
122 };
123 if (!params.accessorPropertiesOnly) {
124 result.internalProperties = injectedScript.getInternalProperties(params.obje ctId);
125 }
126 return result;
127 }
128
129 module.exports = Runtime; 134 module.exports = Runtime;
130 </script> 135 </script>
OLDNEW
« 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