diff --git a/ext/node/global.rs b/ext/node/global.rs index c09e67966a..1e4ea21464 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -50,11 +50,9 @@ const fn str_to_utf16(s: &str) -> [u16; N] { // The Deno and Node specific globals are stored in a struct in a context slot. // // These are the globals that are handled: -// - Buffer (node only) // - clearImmediate (node only) // - clearInterval (both, but different implementation) // - clearTimeout (both, but different implementation) -// - global (node only) // - process (always available in Node, while the availability in Deno depends // on project creation time in Deno Deploy) // - setImmediate (node only) @@ -64,12 +62,10 @@ const fn str_to_utf16(s: &str) -> [u16; N] { // UTF-16 encodings of the managed globals. THIS LIST MUST BE SORTED. #[rustfmt::skip] -const MANAGED_GLOBALS: [&[u16]; 10] = [ - &str_to_utf16::<6>("Buffer"), +const MANAGED_GLOBALS: [&[u16]; 8] = [ &str_to_utf16::<14>("clearImmediate"), &str_to_utf16::<13>("clearInterval"), &str_to_utf16::<12>("clearTimeout"), - &str_to_utf16::<6>("global"), &str_to_utf16::<7>("process"), &str_to_utf16::<12>("setImmediate"), &str_to_utf16::<11>("setInterval"), diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index e7294ca3f6..7933a08bcc 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -343,16 +343,6 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { )), FixSuggestion::hint(cstr!("Use import.meta.dirname instead.")), ]; - } else if msg.contains("Buffer is not defined") { - return vec![ - FixSuggestion::info(cstr!( - "Buffer is not available in the global scope in Deno." - )), - FixSuggestion::hint_multiline(&[ - cstr!("Import it explicitly with import { Buffer } from \"node:buffer\";,"), - cstr!("or run again with --unstable-node-globals flag to add this global."), - ]), - ]; } else if msg.contains("clearImmediate is not defined") { return vec![ FixSuggestion::info(cstr!( @@ -373,16 +363,6 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { cstr!("or run again with --unstable-node-globals flag to add this global."), ]), ]; - } else if msg.contains("global is not defined") { - return vec![ - FixSuggestion::info(cstr!( - "global is not available in the global scope in Deno." - )), - FixSuggestion::hint_multiline(&[ - cstr!("Use globalThis instead, or assign globalThis.global = globalThis,"), - cstr!("or run again with --unstable-node-globals flag to add this global."), - ]), - ]; } else if msg.contains("openKv is not a function") { return vec![ FixSuggestion::info("Deno.openKv() is an unstable API."), diff --git a/runtime/js/98_global_scope_shared.js b/runtime/js/98_global_scope_shared.js index 36543a869d..589fe2c821 100644 --- a/runtime/js/98_global_scope_shared.js +++ b/runtime/js/98_global_scope_shared.js @@ -142,6 +142,12 @@ const windowOrWorkerGlobalScope = { EventSource: core.propWritable(eventSource.EventSource), performance: core.propWritable(performance.performance), process: core.propWritable(process), + Buffer: core.propWritable(Buffer), + global: { + enumerable: true, + configurable: true, + get: () => globalThis, + }, reportError: core.propWritable(event.reportError), setInterval: core.propWritable(timers.setInterval), setTimeout: core.propWritable(timers.setTimeout), @@ -332,14 +338,8 @@ unstableForWindowOrWorkerGlobalScope[unstableIds.net] = { unstableForWindowOrWorkerGlobalScope[unstableIds.webgpu] = {}; unstableForWindowOrWorkerGlobalScope[unstableIds.nodeGlobals] = { - Buffer: core.propWritable(Buffer), setImmediate: core.propWritable(setImmediate), clearImmediate: core.propWritable(clearImmediate), - global: { - enumerable: true, - configurable: true, - get: () => globalThis, - }, }; export { unstableForWindowOrWorkerGlobalScope, windowOrWorkerGlobalScope }; diff --git a/tests/specs/run/node_globals_hints/__test__.jsonc b/tests/specs/run/node_globals_hints/__test__.jsonc index c5c5d6e42e..87d342f295 100644 --- a/tests/specs/run/node_globals_hints/__test__.jsonc +++ b/tests/specs/run/node_globals_hints/__test__.jsonc @@ -15,16 +15,6 @@ "output": "clear_immediate.out", "exitCode": 1 }, - "buffer": { - "args": "run buffer.js", - "output": "buffer.out", - "exitCode": 1 - }, - "global": { - "args": "run global.js", - "output": "global.out", - "exitCode": 1 - }, "setImmediate": { "args": "run set_immediate.js", "output": "set_immediate.out", diff --git a/tests/specs/run/node_globals_hints/buffer.js b/tests/specs/run/node_globals_hints/buffer.js deleted file mode 100644 index 9809e1656e..0000000000 --- a/tests/specs/run/node_globals_hints/buffer.js +++ /dev/null @@ -1 +0,0 @@ -Buffer; diff --git a/tests/specs/run/node_globals_hints/buffer.out b/tests/specs/run/node_globals_hints/buffer.out deleted file mode 100644 index 858f404ab5..0000000000 --- a/tests/specs/run/node_globals_hints/buffer.out +++ /dev/null @@ -1,8 +0,0 @@ -error: Uncaught (in promise) ReferenceError: Buffer is not defined -Buffer; -^ - at [WILDCARD]buffer.js:1:1 - - info: Buffer is not available in the global scope in Deno. - hint: Import it explicitly with import { Buffer } from "node:buffer";, - or run again with --unstable-node-globals flag to add this global. diff --git a/tests/specs/run/node_globals_hints/global.js b/tests/specs/run/node_globals_hints/global.js deleted file mode 100644 index 56676d726a..0000000000 --- a/tests/specs/run/node_globals_hints/global.js +++ /dev/null @@ -1 +0,0 @@ -global; diff --git a/tests/specs/run/node_globals_hints/global.out b/tests/specs/run/node_globals_hints/global.out deleted file mode 100644 index ad01ac426d..0000000000 --- a/tests/specs/run/node_globals_hints/global.out +++ /dev/null @@ -1,8 +0,0 @@ -error: Uncaught (in promise) ReferenceError: global is not defined -global; -^ - at [WILDCARD]global.js:1:1 - - info: global is not available in the global scope in Deno. - hint: Use globalThis instead, or assign globalThis.global = globalThis, - or run again with --unstable-node-globals flag to add this global. diff --git a/tests/unit/globals_test.ts b/tests/unit/globals_test.ts index 84773dbf47..078cffd38b 100644 --- a/tests/unit/globals_test.ts +++ b/tests/unit/globals_test.ts @@ -210,6 +210,6 @@ Deno.test(function mapGroupBy() { Deno.test(function nodeGlobalsRaise() { assertThrows(() => { // @ts-ignore yes that's the point - Buffer; + setImmediate; }, ReferenceError); });