Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script> | 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script> |
| 4 <script> | 4 <script> |
| 5 function test() | 5 function test() |
| 6 { | 6 { |
| 7 var executionContextId; | 7 var executionContextId; |
| 8 | 8 |
| 9 InspectorTest.sendCommand("Runtime.enable", {}); | 9 InspectorTest.sendCommand("Debugger.enable", {}, onDebuggerEnabled); |
|
kozy
2016/08/09 16:25:44
We can use more promises!
InspectorTest.sendComman
lushnikov
2016/08/09 20:16:13
Unfortunately, there's no waitForEventPromise! Wit
| |
| 10 InspectorTest.eventHandler["Runtime.executionContextCreated"] = function(mes sageObject) | 10 |
| 11 function onDebuggerEnabled() | |
| 12 { | |
| 13 InspectorTest.sendCommand("Runtime.enable", {}); | |
| 14 InspectorTest.eventHandler["Debugger.scriptParsed"] = onScriptParsed; | |
| 15 InspectorTest.eventHandler["Runtime.executionContextCreated"] = onExecut ionContextCreated; | |
| 16 } | |
| 17 | |
| 18 function onScriptParsed(messageObject) | |
| 19 { | |
| 20 if (!messageObject.params.url) | |
| 21 return; | |
| 22 InspectorTest.log("Debugger.scriptParsed: " + messageObject.params.url); | |
| 23 } | |
| 24 | |
| 25 function onExecutionContextCreated(messageObject) | |
| 11 { | 26 { |
| 12 executionContextId = messageObject.params.context.id; | 27 executionContextId = messageObject.params.context.id; |
| 13 | 28 testCompileScript("\n (", false, "foo1.js") |
| 14 compileScriptPromise("\n (", false, "foo1.js") | 29 .then(() => testCompileScript("239", true, "foo2.js")) |
| 15 .then(dumpResult) | 30 .then(() => testCompileScript("239", false, "foo3.js")) |
| 16 .then(() => compileScriptPromise("239", true, "foo2.js")) | 31 .then(() => testCompileScript("testfunction f()\n{\n return 0;\n} \n", false, "foo4.js")) |
| 17 .then(dumpResult) | |
| 18 .then(() => compileScriptPromise("239", false, "foo3.js")) | |
| 19 .then(dumpResult) | |
| 20 .then(() => compileScriptPromise("testfunction f()\n{\n return 0; \n}\n", false, "foo4.js")) | |
| 21 .then(dumpResult) | |
| 22 .then(() => InspectorTest.completeTest()); | 32 .then(() => InspectorTest.completeTest()); |
| 23 } | 33 } |
| 24 | 34 |
| 25 function dumpResult(messageObject) | 35 function testCompileScript(expression, persistScript, sourceURL) |
| 26 { | 36 { |
| 27 if (messageObject.result.exceptionDetails) | 37 InspectorTest.log("Compiling script: " + sourceURL); |
| 28 messageObject.result.exceptionDetails.scriptId = 0; | 38 InspectorTest.log(" persist: " + persistScript); |
| 29 if (messageObject.result.scriptId) | 39 var callback; |
| 30 messageObject.result.scriptId = 0; | 40 var promise = new Promise(resolver => callback = resolver); |
| 31 InspectorTest.logObject(messageObject.result); | 41 hasReportedScript = false; |
| 32 } | 42 InspectorTest.sendCommand("Runtime.compileScript", { |
| 43 expression: expression, | |
| 44 sourceURL: sourceURL, | |
| 45 persistScript: persistScript, | |
| 46 executionContextId: executionContextId | |
| 47 }, onCompiled); | |
| 48 return promise; | |
| 33 | 49 |
| 34 function compileScriptPromise(expression, persistScript, sourceURL) | 50 function onCompiled(messageObject) |
| 35 { | 51 { |
| 36 var cb; | 52 var result = messageObject.result; |
| 37 var p = new Promise((resolver) => cb = resolver); | 53 if (result.exceptionDetails) |
| 38 InspectorTest.sendCommand("Runtime.compileScript", { expression: express ion, sourceURL: sourceURL, persistScript: persistScript, executionContextId: exe cutionContextId }, cb); | 54 result.exceptionDetails.scriptId = 0; |
| 39 return p; | 55 if (result.scriptId) |
| 56 result.scriptId = 0; | |
| 57 InspectorTest.logObject(result, "compilation result: "); | |
| 58 InspectorTest.log("-----"); | |
| 59 callback(); | |
| 60 } | |
| 40 } | 61 } |
| 41 } | 62 } |
| 42 </script> | 63 </script> |
| 43 </head> | 64 </head> |
| 44 <body onLoad="runTest();"></body> | 65 <body onLoad="runTest();"></body> |
| 45 </html> | 66 </html> |
| OLD | NEW |