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

Side by Side Diff: sky/framework/inspector/runtime-agent.sky

Issue 951673003: Remove outdated examples and framework pieces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
(Empty)
1 <import src="debug.sky" as="debug" />
2 <script>
3 class Runtime {
4 constructor(delegate) {
5 this.delegate_ = delegate;
6 Object.preventExtensions(this);
7 }
8
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 }
63 }
64
65 // FIXME: This should release all objects associated with an object
66 // group, see InjectedScriptSource.js for an example. Just have to
67 // track which object ids are associated with which object groups first.
68 Runtime.prototype.releaseObjectGroup = debug.loggingStub("releaseObjectGroup");
69
70 // See InjectedScript._bind for a fancier version of this:
71
72 class RemoteObjectRegistery {
73 constructor() {
74 this.lastObjectId = 0;
75 this.objectsById = [];
76 Object.preventExtensions(this);
77 }
78
79 register(object) {
80 var objectId = ++this.lastObjectId;
81 this.objectsById[objectId] = object;
82 return String(objectId);
83 }
84
85 lookup(objectId) {
86 return this.objectsById[Number(objectId)];
87 }
88 }
89
90 var g_objectRegistry = new RemoteObjectRegistery();
91
92 function makeResult(params, value, wasThrown) {
93 var type = typeof(value)
94 var result = {
95 "result": {
96 "type": type,
97 },
98 "wasThrown": wasThrown,
99 };
100
101 // Unclear why this often fails with:
102 // "TypeError: Cannot convert object to primitive value"
103 try {
104 result['result']['description'] = String(value);
105 } catch (e) {}
106
107 if (type == "object") {
108 result["result"]["objectId"] = g_objectRegistry.register(value);
109 }
110
111 if (params.returnByValue) {
112 result["result"]["value"] = value;
113 }
114
115 if (wasThrown) {
116 // If we don"t have exceptionDetails, inspector hits an exception.
117 result["exceptionDetails"] = {
118 "text": value.message,
119 "url": "",
120 "line": 0,
121 "column": 0,
122 "stackTrace": [{
123 "functionName": "",
124 "scriptId": "1",
125 "url": "",
126 "lineNumber": 0,
127 "columnNumber": 0
128 }]
129 }
130 }
131 return result;
132 }
133
134 module.exports = Runtime;
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