1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

fix(ext/node): have process global available in Node context (#27562)

This commit makes `process` global always available in Node context.

`process` global was previously available explicitly in `deno_node`, but then
got removed in #25291 and made globally available regardless of whether it's in
Deno or Node context, so this commit does not have any effect on Deno CLI.
However, for users who want to use `deno_node` ext only, it makes sense to have
`process` available to simulate the Node environment individually.

This change may bring some negative performance impact. To measure how large the
impact would be, a very simple benchmark was performed whose results can be
found at https://github.com/magurotuna/process_global_bench.
This commit is contained in:
Yusuke Tanaka 2025-01-07 20:14:57 -08:00 committed by GitHub
parent cabdfa8c2d
commit 1661ddd9ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -54,6 +54,8 @@ const fn str_to_utf16<const N: usize>(s: &str) -> [u16; N] {
// - clearTimeout (both, but different implementation)
// - global (node only)
// - performance (both, but different implementation)
// - process (always available in Node, while the availability in Deno depends
// on project creation time in Deno Deploy)
// - setImmediate (node only)
// - setInterval (both, but different implementation)
// - setTimeout (both, but different implementation)
@ -61,7 +63,7 @@ const fn str_to_utf16<const N: usize>(s: &str) -> [u16; N] {
// UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED.
#[rustfmt::skip]
const MANAGED_GLOBALS: [&[u16]; 12] = [
const MANAGED_GLOBALS: [&[u16]; 13] = [
&str_to_utf16::<6>("Buffer"),
&str_to_utf16::<17>("WorkerGlobalScope"),
&str_to_utf16::<14>("clearImmediate"),
@ -69,6 +71,7 @@ const MANAGED_GLOBALS: [&[u16]; 12] = [
&str_to_utf16::<12>("clearTimeout"),
&str_to_utf16::<6>("global"),
&str_to_utf16::<11>("performance"),
&str_to_utf16::<7>("process"),
&str_to_utf16::<4>("self"),
&str_to_utf16::<12>("setImmediate"),
&str_to_utf16::<11>("setInterval"),

View file

@ -946,7 +946,7 @@ Module.prototype.require = function (id) {
// wrapper function we run the users code in. The only observable difference is
// that in Deno `arguments.callee` is not null.
Module.wrapper = [
"(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, global, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {",
"(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {",
"\n}).call(this, exports, require, module, __filename, __dirname); })",
];
Module.wrap = function (script) {
@ -1031,6 +1031,7 @@ Module.prototype._compile = function (content, filename, format) {
clearInterval,
clearTimeout,
global,
process,
setImmediate,
setInterval,
setTimeout,
@ -1049,6 +1050,7 @@ Module.prototype._compile = function (content, filename, format) {
clearInterval,
clearTimeout,
global,
process,
setImmediate,
setInterval,
setTimeout,