summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-23 09:27:35 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-29 18:58:39 +0800
commit8a60be4f0fd6a8f6591b7d591e20960fc4372fe4 (patch)
tree2fda3d51f20e2dae137ab1a2a58c6e5049fc2677 /lib
parent00944c7cc25f391c3fbeba1e054a56a62cf0de12 (diff)
downloadandroid-node-v8-8a60be4f0fd6a8f6591b7d591e20960fc4372fe4.tar.gz
android-node-v8-8a60be4f0fd6a8f6591b7d591e20960fc4372fe4.tar.bz2
android-node-v8-8a60be4f0fd6a8f6591b7d591e20960fc4372fe4.zip
process: make internal/queue_microtask.js more self-contained
- Instead of passing triggerFatalException through node.js, simply put it on `internalBinding('util')` which has to be loaded anyway. - Expose the implementation of `queueMicrotask` directly instead of through an unnecessary factory function. PR-URL: https://github.com/nodejs/node/pull/25189 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/bootstrap/node.js11
-rw-r--r--lib/internal/queue_microtask.js57
2 files changed, 33 insertions, 35 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index 5bf2dc523f..3c14d4851a 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -14,8 +14,7 @@
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::LoadEnvironment()
-/* global process, loaderExports, triggerFatalException */
-/* global isMainThread */
+/* global process, loaderExports, isMainThread */
const { internalBinding, NativeModule } = loaderExports;
@@ -605,12 +604,12 @@ function setupGlobalEncoding() {
function setupQueueMicrotask() {
Object.defineProperty(global, 'queueMicrotask', {
- get: () => {
+ get() {
process.emitWarning('queueMicrotask() is experimental.',
'ExperimentalWarning');
- const { setupQueueMicrotask } =
+ const { queueMicrotask } =
NativeModule.require('internal/queue_microtask');
- const queueMicrotask = setupQueueMicrotask(triggerFatalException);
+
Object.defineProperty(global, 'queueMicrotask', {
value: queueMicrotask,
writable: true,
@@ -619,7 +618,7 @@ function setupQueueMicrotask() {
});
return queueMicrotask;
},
- set: (v) => {
+ set(v) {
Object.defineProperty(global, 'queueMicrotask', {
value: v,
writable: true,
diff --git a/lib/internal/queue_microtask.js b/lib/internal/queue_microtask.js
index 6421e7f940..6ca0c1e144 100644
--- a/lib/internal/queue_microtask.js
+++ b/lib/internal/queue_microtask.js
@@ -3,37 +3,36 @@
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
const { AsyncResource } = require('async_hooks');
const { getDefaultTriggerAsyncId } = require('internal/async_hooks');
-const { enqueueMicrotask } = internalBinding('util');
+const {
+ enqueueMicrotask,
+ triggerFatalException
+} = internalBinding('util');
-const setupQueueMicrotask = (triggerFatalException) => {
- const queueMicrotask = (callback) => {
- if (typeof callback !== 'function') {
- throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
- }
+function queueMicrotask(callback) {
+ if (typeof callback !== 'function') {
+ throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
+ }
- const asyncResource = new AsyncResource('Microtask', {
- triggerAsyncId: getDefaultTriggerAsyncId(),
- requireManualDestroy: true,
- });
+ const asyncResource = new AsyncResource('Microtask', {
+ triggerAsyncId: getDefaultTriggerAsyncId(),
+ requireManualDestroy: true,
+ });
- enqueueMicrotask(() => {
- asyncResource.runInAsyncScope(() => {
- try {
- callback();
- } catch (error) {
- // TODO(devsnek) remove this if
- // https://bugs.chromium.org/p/v8/issues/detail?id=8326
- // is resolved such that V8 triggers the fatal exception
- // handler for microtasks
- triggerFatalException(error);
- } finally {
- asyncResource.emitDestroy();
- }
- });
+ enqueueMicrotask(() => {
+ asyncResource.runInAsyncScope(() => {
+ try {
+ callback();
+ } catch (error) {
+ // TODO(devsnek) remove this if
+ // https://bugs.chromium.org/p/v8/issues/detail?id=8326
+ // is resolved such that V8 triggers the fatal exception
+ // handler for microtasks
+ triggerFatalException(error);
+ } finally {
+ asyncResource.emitDestroy();
+ }
});
- };
-
- return queueMicrotask;
-};
+ });
+}
-module.exports = { setupQueueMicrotask };
+module.exports = { queueMicrotask };