| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 InspectorTest.evaluateInPage( | |
| 6 `function TestExpression(a, b) { | |
| 7 return a + b; | |
| 8 }`); | |
| 9 | |
| 10 // A general-purpose engine for sending a sequence of protocol commands. | |
| 11 // The clients provide requests and response handlers, while the engine catches | |
| 12 // errors and makes sure that once there's nothing to do completeTest() is calle
d. | |
| 13 // @param step is an object with command, params and callback fields | |
| 14 function runRequestSeries(step) { | |
| 15 processStep(step); | |
| 16 | |
| 17 function processStep(currentStep) { | |
| 18 try { | |
| 19 processStepOrFail(currentStep); | |
| 20 } catch (e) { | |
| 21 InspectorTest.log(e.stack); | |
| 22 InspectorTest.completeTest(); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 function processStepOrFail(currentStep) { | |
| 27 if (!currentStep) { | |
| 28 InspectorTest.completeTest(); | |
| 29 return; | |
| 30 } | |
| 31 if (!currentStep.command) { | |
| 32 // A simple loopback step. | |
| 33 var next = currentStep.callback(); | |
| 34 processStep(next); | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 var innerCallback = function(response) { | |
| 39 var next; | |
| 40 if ("error" in response) { | |
| 41 if (!("errorHandler" in currentStep)) { | |
| 42 // Error message is not logged intentionally, it may be platform-speci
fic. | |
| 43 InspectorTest.log("Protocol command '" + currentStep.command + "' fail
ed"); | |
| 44 InspectorTest.completeTest(); | |
| 45 return; | |
| 46 } | |
| 47 try { | |
| 48 next = currentStep.errorHandler(response.error); | |
| 49 } catch (e) { | |
| 50 InspectorTest.log(e.stack); | |
| 51 InspectorTest.completeTest(); | |
| 52 return; | |
| 53 } | |
| 54 } else { | |
| 55 try { | |
| 56 next = currentStep.callback(response.result); | |
| 57 } catch (e) { | |
| 58 InspectorTest.log(e.stack); | |
| 59 InspectorTest.completeTest(); | |
| 60 return; | |
| 61 } | |
| 62 } | |
| 63 processStep(next); | |
| 64 } | |
| 65 InspectorTest.sendCommand(currentStep.command, currentStep.params, innerCall
back); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 function logEqualsCheck(actual, expected) | |
| 70 { | |
| 71 if (actual === expected) { | |
| 72 InspectorTest.log("PASS, result value: " + actual); | |
| 73 } else { | |
| 74 InspectorTest.log("FAIL, actual value: " + actual + ", expected: " + expecte
d); | |
| 75 } | |
| 76 } | |
| 77 function logCheck(description, success) | |
| 78 { | |
| 79 InspectorTest.log(description + ": " + (success ? "PASS" : "FAIL")); | |
| 80 } | |
| 81 | |
| 82 var firstStep = { callback: enableDebugger }; | |
| 83 | |
| 84 runRequestSeries(firstStep); | |
| 85 | |
| 86 function enableDebugger() { | |
| 87 return { command: "Debugger.enable", params: {}, callback: evalFunction }; | |
| 88 } | |
| 89 | |
| 90 function evalFunction(response) { | |
| 91 var expression = "TestExpression(2, 4)"; | |
| 92 return { command: "Runtime.evaluate", params: { expression: expression }, call
back: callbackEvalFunction }; | |
| 93 } | |
| 94 | |
| 95 function callbackEvalFunction(result) { | |
| 96 InspectorTest.log("Function evaluate: " + JSON.stringify(result.result)); | |
| 97 logEqualsCheck(result.result.value, 6); | |
| 98 | |
| 99 return { command: "Runtime.evaluate", params: { expression: "TestExpression" }
, callback: callbackEvalFunctionObject }; | |
| 100 } | |
| 101 | |
| 102 function callbackEvalFunctionObject(result) { | |
| 103 return { command: "Runtime.getProperties", params: { objectId: result.result.o
bjectId }, callback: callbackFunctionDetails }; | |
| 104 } | |
| 105 | |
| 106 function callbackFunctionDetails(result) | |
| 107 { | |
| 108 var scriptId; | |
| 109 for (var prop of result.internalProperties) { | |
| 110 if (prop.name === "[[FunctionLocation]]") | |
| 111 scriptId = prop.value.value.scriptId; | |
| 112 } | |
| 113 return createScriptManipulationArc(scriptId, null); | |
| 114 } | |
| 115 | |
| 116 // Several steps with scriptId in context. | |
| 117 function createScriptManipulationArc(scriptId, next) { | |
| 118 return { command: "Debugger.getScriptSource", params: { scriptId: scriptId },
callback: callbackGetScriptSource }; | |
| 119 | |
| 120 var originalText; | |
| 121 | |
| 122 function callbackGetScriptSource(result) { | |
| 123 originalText = result.scriptSource; | |
| 124 var patched = originalText.replace("a + b", "a * b"); | |
| 125 | |
| 126 return { command: "Debugger.setScriptSource", params: { scriptId: scriptId,
scriptSource: patched }, callback: callbackSetScriptSource }; | |
| 127 } | |
| 128 | |
| 129 function callbackSetScriptSource(result) { | |
| 130 var expression = "TestExpression(2, 4)"; | |
| 131 return { command: "Runtime.evaluate", params: { expression: expression }, ca
llback: callbackEvalFunction2 }; | |
| 132 } | |
| 133 | |
| 134 function callbackEvalFunction2(result) { | |
| 135 InspectorTest.log("Function evaluate: " + JSON.stringify(result.result)); | |
| 136 logEqualsCheck(result.result.value, 8); | |
| 137 | |
| 138 var patched = originalText.replace("a + b", "a # b"); | |
| 139 | |
| 140 return { command: "Debugger.setScriptSource", params: { scriptId: scriptId,
scriptSource: patched }, callback: errorCallbackSetScriptSource2 }; | |
| 141 } | |
| 142 | |
| 143 function errorCallbackSetScriptSource2(result) { | |
| 144 var exceptionDetails = result.exceptionDetails; | |
| 145 logCheck("Has error reported", !!exceptionDetails); | |
| 146 logCheck("Reported error is a compile error", !!exceptionDetails); | |
| 147 if (exceptionDetails) | |
| 148 logEqualsCheck(exceptionDetails.lineNumber, 1); | |
| 149 return next; | |
| 150 } | |
| 151 } | |
| OLD | NEW |