Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <script> | |
| 2 | |
| 3 function Runtime(delegate) { | |
| 4 this.delegate_ = delegate; | |
| 5 } | |
| 6 | |
| 7 function logParams(name, params) { | |
| 8 console.log(name + "(" + JSON.stringify(params, null, " ") + ")") | |
| 9 } | |
| 10 | |
| 11 function debug(name) { | |
| 12 return function(params) { | |
| 13 logParams(name, params); | |
| 14 } | |
| 15 } | |
|
abarth-chromium
2014/10/29 00:58:24
Should we factor these into a separate module? Th
| |
| 16 | |
| 17 Runtime.prototype.enable = function() { | |
| 18 this.delegate_.sendMessage("Runtime.executionContextCreated", { | |
| 19 "context": { | |
| 20 "frameId": 1, | |
| 21 "id": 1, | |
| 22 } | |
| 23 }); | |
| 24 return { | |
| 25 result: true, | |
| 26 }; | |
| 27 }; | |
| 28 | |
| 29 Runtime.prototype.callFunctionOn = function(params) { | |
| 30 logParams("callFunctionOn", params); | |
| 31 var object = g_objectRegistry.lookup(params.objectId); | |
| 32 // This is a horrible hack: | |
| 33 var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1]; | |
| 34 var expression = params.functionDeclaration + "; return " + functionName + ";" ; | |
| 35 var wasThrown = false; | |
| 36 var value; | |
| 37 try { | |
| 38 var func = new Function('', expression)(); | |
| 39 value = func(object); | |
| 40 } catch (e) { | |
| 41 value = e; | |
| 42 wasThrown = true; | |
| 43 } | |
| 44 | |
| 45 return makeResult(params, value, wasThrown); | |
| 46 } | |
| 47 | |
| 48 Runtime.prototype.releaseObjectGroup = debug("releaseObjectGroup"); | |
| 49 | |
| 50 // See InjectedScript._bind for a fancier version of this: | |
| 51 | |
| 52 function RemoteObjectRegistery() { | |
| 53 this.lastObjectId = 0; | |
| 54 this.objectsById = []; | |
|
abarth-chromium
2014/10/29 00:58:24
this.objectsById = new Map() ?
Presumably you'll
| |
| 55 } | |
| 56 | |
| 57 RemoteObjectRegistery.prototype.register = function(object) { | |
| 58 var objectId = ++this.lastObjectId; | |
| 59 this.objectsById[objectId] = object; | |
| 60 return String(objectId); | |
| 61 } | |
| 62 | |
| 63 RemoteObjectRegistery.prototype.lookup = function(objectId) { | |
| 64 return this.objectsById[Number(objectId)]; | |
| 65 } | |
| 66 | |
| 67 var g_objectRegistry = new RemoteObjectRegistery(); | |
| 68 | |
| 69 | |
| 70 function makeResult(params, value, wasThrown) { | |
| 71 var type = typeof(value) | |
| 72 var result = { | |
| 73 "result": { | |
| 74 "type": type, | |
| 75 }, | |
| 76 "wasThrown": wasThrown, | |
| 77 }; | |
| 78 | |
| 79 // Unclear why this often fails with: | |
| 80 // "TypeError: Cannot convert object to primitive value" | |
| 81 try { | |
| 82 result['result']['description'] = String(value); | |
| 83 } catch (e) {} | |
| 84 | |
| 85 if (type == "object") { | |
| 86 result["result"]["objectId"] = g_objectRegistry.register(value); | |
| 87 } | |
| 88 | |
| 89 if (params.returnByValue) { | |
| 90 result["result"]["value"] = value; | |
| 91 } | |
| 92 | |
| 93 if (wasThrown) { | |
| 94 // If we don"t have exceptionDetails, inspector hits an exception. | |
| 95 result["exceptionDetails"] = { | |
| 96 "text": value.message, | |
| 97 "url": "", | |
| 98 "line": 0, | |
| 99 "column": 0, | |
| 100 "stackTrace": [{ | |
| 101 "functionName": "", | |
| 102 "scriptId": "1", | |
| 103 "url": "", | |
| 104 "lineNumber": 0, | |
| 105 "columnNumber": 0 | |
| 106 }] | |
| 107 } | |
| 108 } | |
| 109 return result; | |
| 110 } | |
| 111 | |
| 112 // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject. | |
| 113 Runtime.prototype.evaluate = function(params) { | |
| 114 logParams("evaluate", params); | |
| 115 var wasThrown = false; | |
| 116 var value; | |
| 117 try { | |
| 118 value = eval(params.expression); | |
|
pfeldman
2014/10/29 06:12:36
I need to get this running myself to get to know w
| |
| 119 } catch (e) { | |
| 120 value = e; | |
| 121 wasThrown = true; | |
| 122 } | |
| 123 | |
| 124 return makeResult(params, value, wasThrown); | |
| 125 } | |
| 126 | |
| 127 Runtime.prototype.getProperties = debug("getProperties"); | |
| 128 | |
| 129 this.exports = Runtime; | |
| 130 </script> | |
| OLD | NEW |