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

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

Powered by Google App Engine
This is Rietveld 408576698