diff options
author | Gus Caplan <me@gus.host> | 2018-09-19 10:33:52 -0500 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2018-09-23 15:57:19 -0500 |
commit | de0441f6f677b338b78752b8fbaac767fdf35075 (patch) | |
tree | 6257215ec115f9c47457bdd109e7ad9b71af7cb3 /test/parallel/test-queue-microtask.js | |
parent | 59a8324d2793c504fc81a3126478d8c401df314e (diff) | |
download | android-node-v8-de0441f6f677b338b78752b8fbaac767fdf35075.tar.gz android-node-v8-de0441f6f677b338b78752b8fbaac767fdf35075.tar.bz2 android-node-v8-de0441f6f677b338b78752b8fbaac767fdf35075.zip |
lib: implement queueMicrotask
PR-URL: https://github.com/nodejs/node/pull/22951
Refs: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-queue-microtask.js')
-rw-r--r-- | test/parallel/test-queue-microtask.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/parallel/test-queue-microtask.js b/test/parallel/test-queue-microtask.js new file mode 100644 index 0000000000..ea9b88c71e --- /dev/null +++ b/test/parallel/test-queue-microtask.js @@ -0,0 +1,60 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); + +assert.strictEqual(typeof queueMicrotask, 'function'); + +[ + undefined, + null, + 0, + 'x = 5', +].forEach((t) => { + assert.throws(common.mustCall(() => { + queueMicrotask(t); + }), { + code: 'ERR_INVALID_ARG_TYPE', + }); +}); + +{ + let called = false; + queueMicrotask(common.mustCall(() => { + called = true; + })); + assert.strictEqual(called, false); +} + +queueMicrotask(common.mustCall(function() { + assert.strictEqual(arguments.length, 0); +}), 'x', 'y'); + +{ + const q = []; + Promise.resolve().then(() => q.push('a')); + queueMicrotask(common.mustCall(() => q.push('b'))); + Promise.reject().catch(() => q.push('c')); + + queueMicrotask(common.mustCall(() => { + assert.deepStrictEqual(q, ['a', 'b', 'c']); + })); +} + +const eq = []; +process.on('error', (e) => { + eq.push(e); +}); + +process.on('exit', () => { + assert.strictEqual(eq.length, 2); + assert.strictEqual(eq[0].message, 'E1'); + assert.strictEqual( + eq[1].message, 'Class constructor cannot be invoked without \'new\''); +}); + +queueMicrotask(common.mustCall(() => { + throw new Error('E1'); +})); + +queueMicrotask(class {}); |