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.
|
2019-04-03 10:11:59 +00:00
|
|
|
|
|
|
|
// Flags: --expose-gc
|
2016-10-02 21:22:49 +00:00
|
|
|
|
2017-05-19 00:35:45 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start("Tests that Runtime.awaitPromise works.");
|
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
|
|
|
`
|
|
|
|
var resolveCallback;
|
|
|
|
var rejectCallback;
|
|
|
|
function createPromise()
|
|
|
|
{
|
|
|
|
return new Promise((resolve, reject) => { resolveCallback = resolve; rejectCallback = reject });
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolvePromise()
|
|
|
|
{
|
|
|
|
resolveCallback(239);
|
|
|
|
resolveCallback = undefined;
|
|
|
|
rejectCallback = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rejectPromise()
|
|
|
|
{
|
|
|
|
rejectCallback(239);
|
|
|
|
resolveCallback = undefined;
|
|
|
|
rejectCallback = undefined;
|
|
|
|
}
|
|
|
|
|
2017-07-07 03:29:37 +00:00
|
|
|
function rejectPromiseWithAnError()
|
|
|
|
{
|
|
|
|
rejectCallback(new Error('MyError'));
|
|
|
|
resolveCallback = undefined;
|
|
|
|
rejectCallback = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function throwError()
|
|
|
|
{
|
|
|
|
throw new Error('MyError');
|
|
|
|
}
|
|
|
|
|
2016-10-02 21:22:49 +00:00
|
|
|
//# sourceURL=test.js`);
|
|
|
|
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Debugger.enable()
|
|
|
|
.then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 }))
|
|
|
|
.then(() => testSuite());
|
2016-10-02 21:22:49 +00:00
|
|
|
|
|
|
|
function testSuite()
|
|
|
|
{
|
|
|
|
InspectorTest.runTestSuite([
|
|
|
|
function testResolvedPromise(next)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Runtime.evaluate({ expression: "Promise.resolve(239)"})
|
|
|
|
.then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: false, generatePreview: true }))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
2016-10-02 21:22:49 +00:00
|
|
|
.then(() => next());
|
|
|
|
},
|
|
|
|
|
|
|
|
function testRejectedPromise(next)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Runtime.evaluate({ expression: "Promise.reject({ a : 1 })"})
|
|
|
|
.then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
2016-10-02 21:22:49 +00:00
|
|
|
.then(() => next());
|
|
|
|
},
|
|
|
|
|
|
|
|
function testRejectedPromiseWithStack(next)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Runtime.evaluate({ expression: "createPromise()"})
|
|
|
|
.then(result => scheduleRejectAndAwaitPromise(result))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
2016-10-02 21:22:49 +00:00
|
|
|
.then(() => next());
|
|
|
|
|
|
|
|
function scheduleRejectAndAwaitPromise(result)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId });
|
|
|
|
Protocol.Runtime.evaluate({ expression: "rejectPromise()" });
|
2016-10-02 21:22:49 +00:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-07-07 03:29:37 +00:00
|
|
|
function testRejectedPromiseWithError(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.evaluate({ expression: "createPromise()"})
|
|
|
|
.then(result => scheduleRejectAndAwaitPromise(result))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
|
|
|
.then(() => next());
|
|
|
|
|
|
|
|
function scheduleRejectAndAwaitPromise(result)
|
|
|
|
{
|
|
|
|
var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId });
|
|
|
|
Protocol.Runtime.evaluate({ expression: "rejectPromiseWithAnError()" });
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-02 21:22:49 +00:00
|
|
|
function testPendingPromise(next)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Runtime.evaluate({ expression: "createPromise()"})
|
|
|
|
.then(result => scheduleFulfillAndAwaitPromise(result))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
2016-10-02 21:22:49 +00:00
|
|
|
.then(() => next());
|
|
|
|
|
|
|
|
function scheduleFulfillAndAwaitPromise(result)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
var promise = Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId });
|
|
|
|
Protocol.Runtime.evaluate({ expression: "resolvePromise()" });
|
2016-10-02 21:22:49 +00:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
function testResolvedWithoutArgsPromise(next)
|
|
|
|
{
|
2016-10-03 23:32:52 +00:00
|
|
|
Protocol.Runtime.evaluate({ expression: "Promise.resolve()"})
|
|
|
|
.then(result => Protocol.Runtime.awaitPromise({ promiseObjectId: result.result.result.objectId, returnByValue: true, generatePreview: false }))
|
|
|
|
.then(result => InspectorTest.logMessage(result))
|
2016-10-02 21:22:49 +00:00
|
|
|
.then(() => next());
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|