node/deps/v8/test/debugger/debug/debug-evaluate-repl-mode-await.js
Matheus Marchini 2883c855e0
deps: update V8 to 8.1.307.20
PR-URL: https://github.com/nodejs/node/pull/32116
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-03-18 16:23:22 -07:00

47 lines
1.6 KiB
JavaScript

// Copyright 2019 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.
Debug = debug.Debug
const evaluate = Debug.evaluateGlobalREPL;
(async () => {
// Test that the completion value of the REPL script is the resolve value of the
// promise returned by evalute.
let result = evaluate('5;');
assertPromiseResult(result, (value) => {
assertEquals(5, value);
}, assertUnreachable);
// Test that top-level await in REPL mode works.
result = evaluate('let x = await Promise.resolve(42);');
assertPromiseResult(result, (value) => {
assertEquals(undefined, value);
assertEquals(42, x);
}, assertUnreachable);
// Test that a throwing REPL script results in a rejected promise.
result = evaluate('throw new Error("ba dum tsh");');
assertPromiseResult(result, assertUnreachable, (error) => {
assertEquals("ba dum tsh", error.message);
});
// Test that a rejected promise throws.
result = evaluate('await Promise.reject("Reject promise!");');
assertPromiseResult(result, assertUnreachable, (error) => {
assertEquals('Reject promise!', error);
});
// Test that we can bind a promise in REPL mode.
await evaluate('let y = Promise.resolve(21);');
assertPromiseResult(y, (value) => {
assertEquals(21, value);
}, assertUnreachable);
})().then(() => {
print("Async test completed successfully.");
}).catch(e => {
print(e.stack);
%AbortJS("Async test is failing");
});