-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src: use NativeModuleLoader to compile per_context.js #24660
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
// arguments: global | ||
|
||
'use strict'; | ||
|
||
// node::NewContext calls this script | ||
|
||
(function(global) { | ||
// https://github.com/nodejs/node/issues/14909 | ||
if (global.Intl) delete global.Intl.v8BreakIterator; | ||
// https://github.com/nodejs/node/issues/14909 | ||
if (global.Intl) delete global.Intl.v8BreakIterator; | ||
|
||
// https://github.com/nodejs/node/issues/21219 | ||
// Adds Atomics.notify and warns on first usage of Atomics.wake | ||
// https://github.com/v8/v8/commit/c79206b363 adds Atomics.notify so | ||
// now we alias Atomics.wake to notify so that we can remove it | ||
// semver major without worrying about V8. | ||
// https://github.com/nodejs/node/issues/21219 | ||
// Adds Atomics.notify and warns on first usage of Atomics.wake | ||
// https://github.com/v8/v8/commit/c79206b363 adds Atomics.notify so | ||
// now we alias Atomics.wake to notify so that we can remove it | ||
// semver major without worrying about V8. | ||
|
||
const AtomicsNotify = global.Atomics.notify; | ||
const ReflectApply = global.Reflect.apply; | ||
const AtomicsNotify = global.Atomics.notify; | ||
const ReflectApply = global.Reflect.apply; | ||
|
||
const warning = 'Atomics.wake will be removed in a future version, ' + | ||
'use Atomics.notify instead.'; | ||
const warning = 'Atomics.wake will be removed in a future version, ' + | ||
'use Atomics.notify instead.'; | ||
|
||
let wakeWarned = false; | ||
function wake(typedArray, index, count) { | ||
if (!wakeWarned) { | ||
wakeWarned = true; | ||
let wakeWarned = false; | ||
function wake(typedArray, index, count) { | ||
if (!wakeWarned) { | ||
wakeWarned = true; | ||
|
||
if (global.process !== undefined) { | ||
global.process.emitWarning(warning, 'Atomics'); | ||
} else { | ||
global.console.error(`Atomics: ${warning}`); | ||
} | ||
if (global.process !== undefined) { | ||
global.process.emitWarning(warning, 'Atomics'); | ||
} else { | ||
global.console.error(`Atomics: ${warning}`); | ||
} | ||
|
||
return ReflectApply(AtomicsNotify, this, arguments); | ||
} | ||
|
||
global.Object.defineProperties(global.Atomics, { | ||
wake: { | ||
value: wake, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
}, | ||
}); | ||
}(this)); | ||
return ReflectApply(AtomicsNotify, this, arguments); | ||
} | ||
|
||
global.Object.defineProperties(global.Atomics, { | ||
wake: { | ||
value: wake, | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the important part here wasn't the global, it was creating the closure to avoid variables leaking, since this is a script. can you make a note of that here or in node.cc so we don't accidentally break things in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devsnek I thought about that, but how does one break this from the JS side? This source is now wrapped inside a function provided by
CompileFunctionInContext
, so any declaration in this file goes into the scope of that function. Since we are in strict mode, one cannot accidentally declare a global, and as you can see here, the global object is...global
. Also, additional properties should be caught byleakedGlobals
in thetest/common
unless someone deliberately add them viaObject.defineProperty
with additional attributes..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung i'm not saying the current code doesn't work, just that there should be a note mentioning that this code expects a closure of some sort. if it were changed in the future, we could end up leaking the variables like
AtomicsNotify
to all evaluations in node.jsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devsnek: I see...but I think that can be said about all the built in JS, this just puts the per_context.js in the same situation as other native modules, maybe we should find a better place to document about them all...(I have a WIP that migrates the other two bootstrapper, once we are done they are all in the same situation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in node_native_module.h? Or even a README in lib?