mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
da82844493
PR-URL: https://github.com/nodejs/node/pull/39283 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { promiseHooks } = require('v8');
|
|
|
|
assert.throws(() => {
|
|
promiseHooks.onSettled(async function() { });
|
|
}, /The "settledHook" argument must be of type function/);
|
|
|
|
assert.throws(() => {
|
|
promiseHooks.onSettled(async function*() { });
|
|
}, /The "settledHook" argument must be of type function/);
|
|
|
|
let seen;
|
|
|
|
const stop = promiseHooks.onSettled(common.mustCall((promise) => {
|
|
seen = promise;
|
|
}, 4));
|
|
|
|
// Constructor resolve triggers hook
|
|
const promise = new Promise((resolve, reject) => {
|
|
assert.strictEqual(seen, undefined);
|
|
setImmediate(() => {
|
|
resolve();
|
|
assert.strictEqual(seen, promise);
|
|
seen = undefined;
|
|
|
|
constructorReject();
|
|
});
|
|
});
|
|
|
|
// Constructor reject triggers hook
|
|
function constructorReject() {
|
|
const promise = new Promise((resolve, reject) => {
|
|
assert.strictEqual(seen, undefined);
|
|
setImmediate(() => {
|
|
reject();
|
|
assert.strictEqual(seen, promise);
|
|
seen = undefined;
|
|
|
|
simpleResolveReject();
|
|
});
|
|
});
|
|
promise.catch(() => {});
|
|
}
|
|
|
|
// Sync resolve/reject helpers trigger hook
|
|
function simpleResolveReject() {
|
|
const resolved = Promise.resolve();
|
|
assert.strictEqual(seen, resolved);
|
|
seen = undefined;
|
|
|
|
const rejected = Promise.reject();
|
|
assert.strictEqual(seen, rejected);
|
|
seen = undefined;
|
|
|
|
stop();
|
|
rejected.catch(() => {});
|
|
}
|