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