2016-10-02 21:22:49 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-05-19 00:35:45 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start("Tests that Runtime.evaluate works with awaitPromise flag.");
|
2016-10-02 21:22:49 +00:00
|
|
|
|
2017-05-19 00:35:45 +00:00
|
|
|
contextGroup.addScript(`
|
2016-10-02 21:22:49 +00:00
|
|
|
function createPromiseAndScheduleResolve()
|
|
|
|
{
|
|
|
|
var resolveCallback;
|
|
|
|
var promise = new Promise((resolve) => resolveCallback = resolve);
|
|
|
|
setTimeout(resolveCallback.bind(null, { a : 239 }), 0);
|
|
|
|
return promise;
|
2017-07-07 03:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function throwError()
|
|
|
|
{
|
|
|
|
function foo() {
|
|
|
|
throw new Error('MyError');
|
|
|
|
}
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
function throwSyntaxError()
|
|
|
|
{
|
|
|
|
function foo() {
|
|
|
|
eval('}');
|
|
|
|
}
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
`);
|
2016-10-02 21:22:49 +00:00
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function testResolvedPromise()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "Promise.resolve(239)",
|
|
|
|
awaitPromise: true,
|
|
|
|
generatePreview: true
|
|
|
|
}));
|
2016-10-02 21:22:49 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testRejectedPromise()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "Promise.reject(239)",
|
|
|
|
awaitPromise: true
|
|
|
|
}));
|
2016-10-02 21:22:49 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testRejectedPromiseWithError()
|
2017-07-07 03:29:37 +00:00
|
|
|
{
|
|
|
|
Protocol.Runtime.enable();
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "Promise.resolve().then(throwError)",
|
|
|
|
awaitPromise: true
|
|
|
|
}));
|
|
|
|
await Protocol.Runtime.disable();
|
2017-07-07 03:29:37 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testRejectedPromiseWithSyntaxError()
|
2017-07-07 03:29:37 +00:00
|
|
|
{
|
|
|
|
Protocol.Runtime.enable();
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "Promise.resolve().then(throwSyntaxError)",
|
|
|
|
awaitPromise: true
|
|
|
|
}));
|
|
|
|
await Protocol.Runtime.disable();
|
2017-07-07 03:29:37 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testPrimitiveValueInsteadOfPromise()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "true",
|
|
|
|
awaitPromise: true
|
|
|
|
}));
|
2016-10-02 21:22:49 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testObjectInsteadOfPromise()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "({})",
|
2017-08-14 22:21:45 +00:00
|
|
|
awaitPromise: true,
|
|
|
|
returnByValue: true
|
2017-08-10 05:43:50 +00:00
|
|
|
}));
|
2016-10-02 21:22:49 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testPendingPromise()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "createPromiseAndScheduleResolve()",
|
|
|
|
awaitPromise: true,
|
|
|
|
returnByValue: true
|
|
|
|
}));
|
2016-10-02 21:22:49 +00:00
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testExceptionInEvaluate()
|
2016-10-02 21:22:49 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: "throw 239",
|
|
|
|
awaitPromise: true
|
|
|
|
}));
|
2017-08-02 20:28:25 +00:00
|
|
|
},
|
|
|
|
|
2017-08-14 22:21:45 +00:00
|
|
|
async function testThenableJob()
|
|
|
|
{
|
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: '({then: resolve => resolve(42)})',
|
|
|
|
awaitPromise: true}));
|
|
|
|
},
|
|
|
|
|
2017-08-10 05:43:50 +00:00
|
|
|
async function testLastEvaluatedResult()
|
2017-08-02 20:28:25 +00:00
|
|
|
{
|
2017-08-10 05:43:50 +00:00
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: 'Promise.resolve(42)',
|
|
|
|
awaitPromise: true,
|
|
|
|
objectGroup: 'console'
|
|
|
|
}));
|
|
|
|
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
|
|
|
|
expression: '$_',
|
|
|
|
includeCommandLineAPI: true
|
|
|
|
}));
|
2017-08-02 20:28:25 +00:00
|
|
|
},
|
2017-08-10 05:43:50 +00:00
|
|
|
|
|
|
|
async function testRuntimeDisable()
|
|
|
|
{
|
|
|
|
await Protocol.Runtime.enable();
|
|
|
|
Protocol.Runtime.evaluate({
|
|
|
|
expression: 'new Promise(r1 => r = r1)',
|
|
|
|
awaitPromise: true }).then(InspectorTest.logMessage);
|
|
|
|
await Protocol.Runtime.disable();
|
|
|
|
InspectorTest.log('Resolving promise..');
|
|
|
|
await Protocol.Runtime.evaluate({expression: 'r({a:1})'});
|
|
|
|
InspectorTest.log('Promise resolved');
|
|
|
|
},
|
|
|
|
|
|
|
|
async function testImmediatelyResolvedAfterAfterContextDestroyed()
|
|
|
|
{
|
|
|
|
Protocol.Runtime.evaluate({
|
2017-08-11 17:36:26 +00:00
|
|
|
expression: 'new Promise(() => 42)',
|
2017-08-10 05:43:50 +00:00
|
|
|
awaitPromise: true }).then(InspectorTest.logMessage);
|
|
|
|
InspectorTest.log('Destroying context..');
|
|
|
|
await Protocol.Runtime.evaluate({expression: 'inspector.fireContextDestroyed()'});
|
|
|
|
InspectorTest.log('Context destroyed');
|
2017-08-11 17:36:26 +00:00
|
|
|
InspectorTest.log('Triggering weak callback..');
|
|
|
|
await Protocol.HeapProfiler.collectGarbage();
|
2017-08-10 05:43:50 +00:00
|
|
|
}
|
2016-10-02 21:22:49 +00:00
|
|
|
]);
|