-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: use NativeModuleLoader to compile per_context.js
This patch introduces a NativeModuleLoader::CompileAndCall that can run a JS script under `lib/` as a function called with a null receiver and arguments specified from the C++ layer. Since all our bootstrappers are wrapped in functions in the source to avoid leaking variables into the global scope anyway, this allows us to remove that extra indentation in the JS source code. As a start we move the compilation and execution of per_context.js to NativeModuleLoader::CompileAndCall(). This patch also changes the return value of NativeModuleLoader::LookupAndCompile() to a MaybeLocal since the caller has to take care of the result being empty anyway. This patch reverts the previous design of having the NativeModuleLoader::Compile() method magically know about the parameters of the function - until we have tooling in-place to guess the parameter names in the source with some annotation, it's more readable to allow the caller to specify the parameters along with the arguments values. PR-URL: #24660 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
- Loading branch information
1 parent
83ab5f4
commit c708abb
Showing
4 changed files
with
144 additions
and
100 deletions.
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