OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 print("Tests that Runtime.compileScript and Runtime.runScript work with awaitPro
mise flag."); | 5 print("Tests that Runtime.compileScript and Runtime.runScript work with awaitPro
mise flag."); |
6 | 6 |
7 InspectorTest.runTestSuite([ | 7 InspectorTest.runTestSuite([ |
8 function testRunAndCompileWithoutAgentEnable(next) | 8 function testRunAndCompileWithoutAgentEnable(next) |
9 { | 9 { |
10 InspectorTest.sendCommandPromise("Runtime.compileScript", { expression: "",
sourceURL: "", persistScript: true }) | 10 Protocol.Runtime.compileScript({ expression: "", sourceURL: "", persistScrip
t: true }) |
11 .then((result) => dumpResult(result)) | 11 .then((result) => InspectorTest.logMessage(result)) |
12 .then(() => InspectorTest.sendCommandPromise("Runtime.runScript", { script
Id: "1" })) | 12 .then(() => Protocol.Runtime.runScript({ scriptId: "1" })) |
13 .then((result) => dumpResult(result)) | 13 .then((result) => InspectorTest.logMessage(result)) |
14 .then(() => next()); | 14 .then(() => next()); |
15 }, | 15 }, |
16 | 16 |
17 function testSyntaxErrorInScript(next) | 17 function testSyntaxErrorInScript(next) |
18 { | 18 { |
19 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 19 Protocol.Runtime.enable() |
20 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "\n }", sourceURL: "boo.js", persistScript: true })) | 20 .then(() => Protocol.Runtime.compileScript({ expression: "\n }", sourceURL
: "boo.js", persistScript: true })) |
21 .then((result) => dumpResult(result)) | 21 .then((result) => InspectorTest.logMessage(result)) |
22 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 22 .then(() => Protocol.Runtime.disable()) |
23 .then(() => next()); | 23 .then(() => next()); |
24 }, | 24 }, |
25 | 25 |
26 function testSyntaxErrorInEvalInScript(next) | 26 function testSyntaxErrorInEvalInScript(next) |
27 { | 27 { |
28 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 28 Protocol.Runtime.enable() |
29 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "{\n eval(\"\\\n}\")\n}", sourceURL: "boo.js", persistScript: true })) | 29 .then(() => Protocol.Runtime.compileScript({ expression: "{\n eval(\"\\\n}
\")\n}", sourceURL: "boo.js", persistScript: true })) |
30 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId })) | 30 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
31 .then((result) => dumpResult(result)) | 31 .then((result) => InspectorTest.logMessage(result)) |
32 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 32 .then(() => Protocol.Runtime.disable()) |
33 .then(() => next()); | 33 .then(() => next()); |
34 }, | 34 }, |
35 | 35 |
36 function testRunNotCompiledScript(next) | 36 function testRunNotCompiledScript(next) |
37 { | 37 { |
38 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 38 Protocol.Runtime.enable() |
39 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: "1" })) | 39 .then((result) => Protocol.Runtime.runScript({ scriptId: "1" })) |
40 .then((result) => dumpResult(result)) | 40 .then((result) => InspectorTest.logMessage(result)) |
41 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 41 .then(() => Protocol.Runtime.disable()) |
42 .then(() => next()); | 42 .then(() => next()); |
43 }, | 43 }, |
44 | 44 |
45 function testRunCompiledScriptAfterAgentWasReenabled(next) | 45 function testRunCompiledScriptAfterAgentWasReenabled(next) |
46 { | 46 { |
47 var scriptId; | 47 var scriptId; |
48 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 48 Protocol.Runtime.enable() |
49 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "{\n eval(\"\\\n}\")\n}", sourceURL: "boo.js", persistScript: true })) | 49 .then(() => Protocol.Runtime.compileScript({ expression: "{\n eval(\"\\\n}
\")\n}", sourceURL: "boo.js", persistScript: true })) |
50 .then((result) => scriptId = result.result.scriptId) | 50 .then((result) => scriptId = result.result.scriptId) |
51 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 51 .then(() => Protocol.Runtime.disable()) |
52 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: scriptId })) | 52 .then((result) => Protocol.Runtime.runScript({ scriptId: scriptId })) |
53 .then((result) => dumpResult(result)) | 53 .then((result) => InspectorTest.logMessage(result)) |
54 .then(() => InspectorTest.sendCommandPromise("Runtime.enable", {})) | 54 .then(() => Protocol.Runtime.enable()) |
55 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: scriptId })) | 55 .then((result) => Protocol.Runtime.runScript({ scriptId: scriptId })) |
56 .then((result) => dumpResult(result)) | 56 .then((result) => InspectorTest.logMessage(result)) |
57 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 57 .then(() => Protocol.Runtime.disable()) |
58 .then(() => next()); | 58 .then(() => next()); |
59 }, | 59 }, |
60 | 60 |
61 function testRunScriptWithPreview(next) | 61 function testRunScriptWithPreview(next) |
62 { | 62 { |
63 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 63 Protocol.Runtime.enable() |
64 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "({a:1})", sourceURL: "boo.js", persistScript: true })) | 64 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", source
URL: "boo.js", persistScript: true })) |
65 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId, generatePreview: true })) | 65 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId, generatePreview: true })) |
66 .then((result) => dumpResult(result)) | 66 .then((result) => InspectorTest.logMessage(result)) |
67 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 67 .then(() => Protocol.Runtime.disable()) |
68 .then(() => next()); | 68 .then(() => next()); |
69 }, | 69 }, |
70 | 70 |
71 function testRunScriptReturnByValue(next) | 71 function testRunScriptReturnByValue(next) |
72 { | 72 { |
73 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 73 Protocol.Runtime.enable() |
74 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "({a:1})", sourceURL: "boo.js", persistScript: true })) | 74 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", source
URL: "boo.js", persistScript: true })) |
75 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId, returnByValue: true })) | 75 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId, returnByValue: true })) |
76 .then((result) => dumpResult(result)) | 76 .then((result) => InspectorTest.logMessage(result)) |
77 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 77 .then(() => Protocol.Runtime.disable()) |
78 .then(() => next()); | 78 .then(() => next()); |
79 }, | 79 }, |
80 | 80 |
81 function testAwaitNotPromise(next) | 81 function testAwaitNotPromise(next) |
82 { | 82 { |
83 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 83 Protocol.Runtime.enable() |
84 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "({a:1})", sourceURL: "boo.js", persistScript: true })) | 84 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", source
URL: "boo.js", persistScript: true })) |
85 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId, awaitPromise: true })) | 85 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId, awaitPromise: true })) |
86 .then((result) => dumpResult(result)) | 86 .then((result) => InspectorTest.logMessage(result)) |
87 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 87 .then(() => Protocol.Runtime.disable()) |
88 .then(() => next()); | 88 .then(() => next()); |
89 }, | 89 }, |
90 | 90 |
91 function testAwaitResolvedPromise(next) | 91 function testAwaitResolvedPromise(next) |
92 { | 92 { |
93 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 93 Protocol.Runtime.enable() |
94 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "Promise.resolve({a:1})", sourceURL: "boo.js", persistScript: true })) | 94 .then(() => Protocol.Runtime.compileScript({ expression: "Promise.resolve(
{a:1})", sourceURL: "boo.js", persistScript: true })) |
95 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId, awaitPromise: true, returnByValue: true })) | 95 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId, awaitPromise: true, returnByValue: true })) |
96 .then((result) => dumpResult(result)) | 96 .then((result) => InspectorTest.logMessage(result)) |
97 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 97 .then(() => Protocol.Runtime.disable()) |
98 .then(() => next()); | 98 .then(() => next()); |
99 }, | 99 }, |
100 | 100 |
101 function testAwaitRejectedPromise(next) | 101 function testAwaitRejectedPromise(next) |
102 { | 102 { |
103 InspectorTest.sendCommandPromise("Runtime.enable", {}) | 103 Protocol.Runtime.enable() |
104 .then(() => InspectorTest.sendCommandPromise("Runtime.compileScript", { ex
pression: "Promise.reject({a:1})", sourceURL: "boo.js", persistScript: true })) | 104 .then(() => Protocol.Runtime.compileScript({ expression: "Promise.reject({
a:1})", sourceURL: "boo.js", persistScript: true })) |
105 .then((result) => InspectorTest.sendCommandPromise("Runtime.runScript", {
scriptId: result.result.scriptId, awaitPromise: true, returnByValue: true })) | 105 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId, awaitPromise: true, returnByValue: true })) |
106 .then((result) => dumpResult(result)) | 106 .then((result) => InspectorTest.logMessage(result)) |
107 .then(() => InspectorTest.sendCommandPromise("Runtime.disable", {})) | 107 .then(() => Protocol.Runtime.disable()) |
108 .then(() => next()); | 108 .then(() => next()); |
109 } | 109 } |
110 ]); | 110 ]); |
111 | |
112 function dumpResult(result) | |
113 { | |
114 if (result.error) { | |
115 result.error.code = 0; | |
116 InspectorTest.logObject(result.error); | |
117 return; | |
118 } | |
119 result = result.result; | |
120 if (result.exceptionDetails) { | |
121 result.exceptionDetails.exceptionId = 0; | |
122 result.exceptionDetails.exception.objectId = 0; | |
123 } | |
124 if (result.exceptionDetails && result.exceptionDetails.scriptId) | |
125 result.exceptionDetails.scriptId = 0; | |
126 if (result.exceptionDetails && result.exceptionDetails.stackTrace) { | |
127 for (var frame of result.exceptionDetails.stackTrace.callFrames) | |
128 frame.scriptId = 0; | |
129 } | |
130 if (result.result && result.result.objectId) | |
131 result.result.objectId = "[ObjectId]"; | |
132 InspectorTest.logObject(result); | |
133 } | |
OLD | NEW |