| OLD | NEW |
| 1 <link rel="import" href="debug.sky" as="debug" /> |
| 1 <script> | 2 <script> |
| 2 | |
| 3 function Runtime(delegate) { | 3 function Runtime(delegate) { |
| 4 this.delegate_ = delegate; | 4 this.delegate_ = delegate; |
| 5 } | 5 } |
| 6 | 6 |
| 7 // FIXME: Move these to their own 'debug' module. | |
| 8 function logParams(name, params) { | |
| 9 console.log(name + "(" + JSON.stringify(params, null, " ") + ")") | |
| 10 } | |
| 11 | |
| 12 function debug(name) { | |
| 13 return function(params) { | |
| 14 logParams(name, params); | |
| 15 } | |
| 16 } | |
| 17 | |
| 18 Runtime.prototype.enable = function() { | 7 Runtime.prototype.enable = function() { |
| 19 this.delegate_.sendMessage("Runtime.executionContextCreated", { | 8 this.delegate_.sendMessage("Runtime.executionContextCreated", { |
| 20 "context": { | 9 "context": { |
| 21 "frameId": 1, | 10 "frameId": 1, |
| 22 "id": 1, | 11 "id": 1, |
| 23 } | 12 } |
| 24 }); | 13 }); |
| 25 return { | 14 return { |
| 26 result: true, | 15 result: true, |
| 27 }; | 16 }; |
| 28 }; | 17 }; |
| 29 | 18 |
| 30 Runtime.prototype.callFunctionOn = function(params) { | 19 Runtime.prototype.callFunctionOn = function(params) { |
| 31 logParams("callFunctionOn", params); | |
| 32 var object = g_objectRegistry.lookup(params.objectId); | 20 var object = g_objectRegistry.lookup(params.objectId); |
| 33 // This is a horrible hack: | 21 // This is a horrible hack: |
| 34 var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1]; | 22 var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1]; |
| 35 var expression = params.functionDeclaration + "; return " + functionName + ";"
; | 23 var expression = params.functionDeclaration + "; return " + functionName + ";"
; |
| 36 var wasThrown = false; | 24 var wasThrown = false; |
| 37 var value; | 25 var value; |
| 38 try { | 26 try { |
| 39 var func = new Function('', expression)(); | 27 var func = new Function('', expression)(); |
| 40 value = func(object); | 28 value = func(object); |
| 41 } catch (e) { | 29 } catch (e) { |
| 42 value = e; | 30 value = e; |
| 43 wasThrown = true; | 31 wasThrown = true; |
| 44 } | 32 } |
| 45 | 33 |
| 46 return makeResult(params, value, wasThrown); | 34 return makeResult(params, value, wasThrown); |
| 47 } | 35 } |
| 48 | 36 |
| 49 // FIXME: This should release all objects associated with an object | 37 // FIXME: This should release all objects associated with an object |
| 50 // group, see InjectedScriptSource.js for an example. Just have to | 38 // group, see InjectedScriptSource.js for an example. Just have to |
| 51 // track which object ids are associated with which object groups first. | 39 // track which object ids are associated with which object groups first. |
| 52 Runtime.prototype.releaseObjectGroup = debug("releaseObjectGroup"); | 40 Runtime.prototype.releaseObjectGroup = debug.loggingStub("releaseObjectGroup"); |
| 53 | 41 |
| 54 // See InjectedScript._bind for a fancier version of this: | 42 // See InjectedScript._bind for a fancier version of this: |
| 55 | 43 |
| 56 function RemoteObjectRegistery() { | 44 function RemoteObjectRegistery() { |
| 57 this.lastObjectId = 0; | 45 this.lastObjectId = 0; |
| 58 this.objectsById = []; | 46 this.objectsById = []; |
| 59 } | 47 } |
| 60 | 48 |
| 61 RemoteObjectRegistery.prototype.register = function(object) { | 49 RemoteObjectRegistery.prototype.register = function(object) { |
| 62 var objectId = ++this.lastObjectId; | 50 var objectId = ++this.lastObjectId; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 "lineNumber": 0, | 96 "lineNumber": 0, |
| 109 "columnNumber": 0 | 97 "columnNumber": 0 |
| 110 }] | 98 }] |
| 111 } | 99 } |
| 112 } | 100 } |
| 113 return result; | 101 return result; |
| 114 } | 102 } |
| 115 | 103 |
| 116 // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject. | 104 // FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject. |
| 117 Runtime.prototype.evaluate = function(params) { | 105 Runtime.prototype.evaluate = function(params) { |
| 118 logParams("evaluate", params); | |
| 119 var wasThrown = false; | 106 var wasThrown = false; |
| 120 var value; | 107 var value; |
| 121 try { | 108 try { |
| 122 value = eval(params.expression); | 109 value = eval(params.expression); |
| 123 } catch (e) { | 110 } catch (e) { |
| 124 value = e; | 111 value = e; |
| 125 wasThrown = true; | 112 wasThrown = true; |
| 126 } | 113 } |
| 127 | 114 |
| 128 return makeResult(params, value, wasThrown); | 115 return makeResult(params, value, wasThrown); |
| 129 } | 116 } |
| 130 | 117 |
| 131 Runtime.prototype.getProperties = debug("getProperties"); | 118 Runtime.prototype.getProperties = debug.loggingStub("getProperties"); |
| 132 | 119 |
| 133 this.exports = Runtime; | 120 this.exports = Runtime; |
| 134 </script> | 121 </script> |
| OLD | NEW |