Skip to content

Commit 1661ddd

Browse files
authored
fix(ext/node): have process global available in Node context (denoland#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 denoland#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.
1 parent cabdfa8 commit 1661ddd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/node/global.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,24 @@ const fn str_to_utf16<const N: usize>(s: &str) -> [u16; N] {
5454
// - clearTimeout (both, but different implementation)
5555
// - global (node only)
5656
// - performance (both, but different implementation)
57+
// - process (always available in Node, while the availability in Deno depends
58+
// on project creation time in Deno Deploy)
5759
// - setImmediate (node only)
5860
// - setInterval (both, but different implementation)
5961
// - setTimeout (both, but different implementation)
6062
// - window (deno only)
6163

6264
// UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED.
6365
#[rustfmt::skip]
64-
const MANAGED_GLOBALS: [&[u16]; 12] = [
66+
const MANAGED_GLOBALS: [&[u16]; 13] = [
6567
&str_to_utf16::<6>("Buffer"),
6668
&str_to_utf16::<17>("WorkerGlobalScope"),
6769
&str_to_utf16::<14>("clearImmediate"),
6870
&str_to_utf16::<13>("clearInterval"),
6971
&str_to_utf16::<12>("clearTimeout"),
7072
&str_to_utf16::<6>("global"),
7173
&str_to_utf16::<11>("performance"),
74+
&str_to_utf16::<7>("process"),
7275
&str_to_utf16::<4>("self"),
7376
&str_to_utf16::<12>("setImmediate"),
7477
&str_to_utf16::<11>("setInterval"),

ext/node/polyfills/01_require.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ Module.prototype.require = function (id) {
946946
// wrapper function we run the users code in. The only observable difference is
947947
// that in Deno `arguments.callee` is not null.
948948
Module.wrapper = [
949-
"(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, global, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {",
949+
"(function (exports, require, module, __filename, __dirname, Buffer, clearImmediate, clearInterval, clearTimeout, global, process, setImmediate, setInterval, setTimeout, performance) { (function (exports, require, module, __filename, __dirname) {",
950950
"\n}).call(this, exports, require, module, __filename, __dirname); })",
951951
];
952952
Module.wrap = function (script) {
@@ -1031,6 +1031,7 @@ Module.prototype._compile = function (content, filename, format) {
10311031
clearInterval,
10321032
clearTimeout,
10331033
global,
1034+
process,
10341035
setImmediate,
10351036
setInterval,
10361037
setTimeout,
@@ -1049,6 +1050,7 @@ Module.prototype._compile = function (content, filename, format) {
10491050
clearInterval,
10501051
clearTimeout,
10511052
global,
1053+
process,
10521054
setImmediate,
10531055
setInterval,
10541056
setTimeout,

0 commit comments

Comments
 (0)