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.evaluate works with awaitPromise flag."); | 5 print("Tests that Runtime.evaluate works with awaitPromise flag."); |
6 | 6 |
7 InspectorTest.evaluateInPage(` | 7 InspectorTest.addScript(` |
8 function createPromiseAndScheduleResolve() | 8 function createPromiseAndScheduleResolve() |
9 { | 9 { |
10 var resolveCallback; | 10 var resolveCallback; |
11 var promise = new Promise((resolve) => resolveCallback = resolve); | 11 var promise = new Promise((resolve) => resolveCallback = resolve); |
12 setTimeout(resolveCallback.bind(null, { a : 239 }), 0); | 12 setTimeout(resolveCallback.bind(null, { a : 239 }), 0); |
13 return promise; | 13 return promise; |
14 }`); | 14 }`); |
15 | 15 |
16 function dumpResult(result) | |
17 { | |
18 if (result.exceptionDetails) { | |
19 result.exceptionDetails.scriptId = "(scriptId)"; | |
20 result.exceptionDetails.exceptionId = 0; | |
21 result.exceptionDetails.exception.objectId = 0; | |
22 } | |
23 InspectorTest.logObject(result); | |
24 } | |
25 | |
26 InspectorTest.runTestSuite([ | 16 InspectorTest.runTestSuite([ |
27 function testResolvedPromise(next) | 17 function testResolvedPromise(next) |
28 { | 18 { |
29 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promise.
resolve(239)", awaitPromise: true, generatePreview: true }) | 19 Protocol.Runtime.evaluate({ expression: "Promise.resolve(239)", awaitPromise
: true, generatePreview: true }) |
30 .then((result) => dumpResult(result.result)) | 20 .then(result => InspectorTest.logMessage(result)) |
31 .then(() => next()); | 21 .then(_ => next()); |
32 }, | 22 }, |
33 | 23 |
34 function testRejectedPromise(next) | 24 function testRejectedPromise(next) |
35 { | 25 { |
36 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "Promise.
reject(239)", awaitPromise: true }) | 26 Protocol.Runtime.evaluate({ expression: "Promise.reject(239)", awaitPromise:
true }) |
37 .then((result) => dumpResult(result.result)) | 27 .then(result => InspectorTest.logMessage(result)) |
38 .then(() => next()); | 28 .then(_ => next()); |
39 }, | 29 }, |
40 | 30 |
41 function testPrimitiveValueInsteadOfPromise(next) | 31 function testPrimitiveValueInsteadOfPromise(next) |
42 { | 32 { |
43 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "true", a
waitPromise: true }) | 33 Protocol.Runtime.evaluate({ expression: "true", awaitPromise: true }) |
44 .then((result) => InspectorTest.logObject(result.error)) | 34 .then(result => InspectorTest.logMessage(result)) |
45 .then(() => next()); | 35 .then(_ => next()); |
46 }, | 36 }, |
47 | 37 |
48 function testObjectInsteadOfPromise(next) | 38 function testObjectInsteadOfPromise(next) |
49 { | 39 { |
50 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "({})", a
waitPromise: true }) | 40 Protocol.Runtime.evaluate({ expression: "({})", awaitPromise: true }) |
51 .then((result) => InspectorTest.logObject(result.error)) | 41 .then(result => InspectorTest.logMessage(result)) |
52 .then(() => next()); | 42 .then(_ => next()); |
53 }, | 43 }, |
54 | 44 |
55 function testPendingPromise(next) | 45 function testPendingPromise(next) |
56 { | 46 { |
57 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "createPr
omiseAndScheduleResolve()", awaitPromise: true, returnByValue: true }) | 47 Protocol.Runtime.evaluate({ expression: "createPromiseAndScheduleResolve()",
awaitPromise: true, returnByValue: true }) |
58 .then((result) => dumpResult(result.result)) | 48 .then(result => InspectorTest.logMessage(result)) |
59 .then(() => next()); | 49 .then(_ => next()); |
60 }, | 50 }, |
61 | 51 |
62 function testExceptionInEvaluate(next) | 52 function testExceptionInEvaluate(next) |
63 { | 53 { |
64 InspectorTest.sendCommandPromise("Runtime.evaluate", { expression: "throw 23
9", awaitPromise: true }) | 54 Protocol.Runtime.evaluate({ expression: "throw 239", awaitPromise: true }) |
65 .then((result) => dumpResult(result.result)) | 55 .then(result => InspectorTest.logMessage(result)) |
66 .then(() => next()); | 56 .then(_ => next()); |
67 } | 57 } |
68 ]); | 58 ]); |
OLD | NEW |