Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: move queueMicrotask to stable #25594

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ added: v11.0.0

<!-- type=global -->

> Stability: 1 - Experimental
* `callback` {Function} Function to be queued.

The `queueMicrotask()` method queues a microtask to invoke `callback`. If
Expand Down
28 changes: 5 additions & 23 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,30 +396,12 @@ function createGlobalConsole(consoleFromVM) {
}

function setupQueueMicrotask() {
const { queueMicrotask } =
NativeModule.require('internal/queue_microtask');
Object.defineProperty(global, 'queueMicrotask', {
Copy link
Member

@lpinca lpinca Feb 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do

global.queueMicrotask = queueMicrotask;

now no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can, but it's best to be explicit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do it for setTimeout, setImmediate, etc. I'm fine with it as is though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it global means semver-major.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's already a global

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Right lol... Had forgotten that :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer

global.queueMicrotask = queueMicrotask;

It is significantly shorter and the implications should be clear.

get() {
process.emitWarning('queueMicrotask() is experimental.',
'ExperimentalWarning');
const { queueMicrotask } =
NativeModule.require('internal/queue_microtask');

Object.defineProperty(global, 'queueMicrotask', {
value: queueMicrotask,
writable: true,
enumerable: false,
configurable: true,
});
return queueMicrotask;
},
set(v) {
Object.defineProperty(global, 'queueMicrotask', {
value: v,
writable: true,
enumerable: false,
configurable: true,
});
},
enumerable: false,
value: queueMicrotask,
writable: true,
enumerable: true,
configurable: true,
});
}
Expand Down
3 changes: 2 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ let knownGlobals = [
global,
setImmediate,
setInterval,
setTimeout
setTimeout,
queueMicrotask,
];

if (global.gc) {
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ builtinModules.forEach((moduleName) => {
{
const expected = [
'global',
'queueMicrotask',
'clearImmediate',
'clearInterval',
'clearTimeout',
Expand Down