11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciassert.strictEqual(typeof queueMicrotask, 'function');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci[
91cb0ef41Sopenharmony_ci  undefined,
101cb0ef41Sopenharmony_ci  null,
111cb0ef41Sopenharmony_ci  0,
121cb0ef41Sopenharmony_ci  'x = 5',
131cb0ef41Sopenharmony_ci].forEach((t) => {
141cb0ef41Sopenharmony_ci  assert.throws(common.mustCall(() => {
151cb0ef41Sopenharmony_ci    queueMicrotask(t);
161cb0ef41Sopenharmony_ci  }), {
171cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci});
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci{
221cb0ef41Sopenharmony_ci  let called = false;
231cb0ef41Sopenharmony_ci  queueMicrotask(common.mustCall(() => {
241cb0ef41Sopenharmony_ci    called = true;
251cb0ef41Sopenharmony_ci  }));
261cb0ef41Sopenharmony_ci  assert.strictEqual(called, false);
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciqueueMicrotask(common.mustCall(function() {
301cb0ef41Sopenharmony_ci  assert.strictEqual(arguments.length, 0);
311cb0ef41Sopenharmony_ci}), 'x', 'y');
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci  const q = [];
351cb0ef41Sopenharmony_ci  Promise.resolve().then(() => q.push('a'));
361cb0ef41Sopenharmony_ci  queueMicrotask(common.mustCall(() => q.push('b')));
371cb0ef41Sopenharmony_ci  Promise.reject().catch(() => q.push('c'));
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  queueMicrotask(common.mustCall(() => {
401cb0ef41Sopenharmony_ci    assert.deepStrictEqual(q, ['a', 'b', 'c']);
411cb0ef41Sopenharmony_ci  }));
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciconst eq = [];
451cb0ef41Sopenharmony_ciprocess.on('uncaughtException', (e) => {
461cb0ef41Sopenharmony_ci  eq.push(e);
471cb0ef41Sopenharmony_ci});
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciprocess.on('exit', () => {
501cb0ef41Sopenharmony_ci  assert.strictEqual(eq.length, 2);
511cb0ef41Sopenharmony_ci  assert.strictEqual(eq[0].message, 'E1');
521cb0ef41Sopenharmony_ci  assert.strictEqual(
531cb0ef41Sopenharmony_ci    eq[1].message, 'Class constructor  cannot be invoked without \'new\'');
541cb0ef41Sopenharmony_ci});
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciqueueMicrotask(common.mustCall(() => {
571cb0ef41Sopenharmony_ci  throw new Error('E1');
581cb0ef41Sopenharmony_ci}));
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciqueueMicrotask(class {});
61