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>
38 lines
932 B
JavaScript
38 lines
932 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { promiseHooks } = require('v8');
|
|
|
|
assert.throws(() => {
|
|
promiseHooks.onInit(async function() { });
|
|
}, /The "initHook" argument must be of type function/);
|
|
|
|
assert.throws(() => {
|
|
promiseHooks.onInit(async function*() { });
|
|
}, /The "initHook" argument must be of type function/);
|
|
|
|
let seenPromise;
|
|
let seenParent;
|
|
|
|
const stop = promiseHooks.onInit(common.mustCall((promise, parent) => {
|
|
seenPromise = promise;
|
|
seenParent = parent;
|
|
}, 2));
|
|
|
|
const parent = Promise.resolve();
|
|
assert.strictEqual(seenPromise, parent);
|
|
assert.strictEqual(seenParent, undefined);
|
|
|
|
const child = parent.then();
|
|
assert.strictEqual(seenPromise, child);
|
|
assert.strictEqual(seenParent, parent);
|
|
|
|
seenPromise = undefined;
|
|
seenParent = undefined;
|
|
|
|
stop();
|
|
|
|
Promise.resolve();
|
|
assert.strictEqual(seenPromise, undefined);
|
|
assert.strictEqual(seenParent, undefined);
|