diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-08-17 11:16:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-17 11:16:43 +0900 |
commit | b6cdb31c0591ffd4dd9fee7a44554f5d915ba58e (patch) | |
tree | b815eb1d3c847b1a57b04631c6e6dc246baaffaa /ext/node/global.rs | |
parent | 2eeea0a1d2011567d3a41065d66802097366dc8c (diff) |
fix(ext/node): fix prismjs compatibiliy in Web Worker (#25062)
PrismJS uses `WorkerGlobalScope` and `self` for detecting browser's Web
Worker context:
https://github.com/PrismJS/prism/blob/59e5a3471377057de1f401ba38337aca27b80e03/prism.js#L11
Now the detection logic above is broken when it's imported from Deno's
Web Worker context because we only hide `self` (Prism assumes when
`WorkerGlobalScope` is available, `self` is also available).
This change fixes the above by also hiding `WorkerGlobalScope` global in
Node compat mode.
closes #25008
Diffstat (limited to 'ext/node/global.rs')
-rw-r--r-- | ext/node/global.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/ext/node/global.rs b/ext/node/global.rs index 0fc215bd4..0b4adfc7d 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -63,8 +63,9 @@ 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]; 13] = [ +const MANAGED_GLOBALS: [&[u16]; 14] = [ &str_to_utf16::<6>("Buffer"), + &str_to_utf16::<17>("WorkerGlobalScope"), &str_to_utf16::<14>("clearImmediate"), &str_to_utf16::<13>("clearInterval"), &str_to_utf16::<12>("clearTimeout"), @@ -79,8 +80,25 @@ const MANAGED_GLOBALS: [&[u16]; 13] = [ &str_to_utf16::<6>("window"), ]; -const SHORTEST_MANAGED_GLOBAL: usize = 4; -const LONGEST_MANAGED_GLOBAL: usize = 14; +// Calculates the shortest & longest length of global var names +const MANAGED_GLOBALS_INFO: (usize, usize) = { + let l = MANAGED_GLOBALS[0].len(); + let (mut longest, mut shortest, mut i) = (l, l, 1); + while i < MANAGED_GLOBALS.len() { + let l = MANAGED_GLOBALS[i].len(); + if l > longest { + longest = l + } + if l < shortest { + shortest = l + } + i += 1; + } + (shortest, longest) +}; + +const SHORTEST_MANAGED_GLOBAL: usize = MANAGED_GLOBALS_INFO.0; +const LONGEST_MANAGED_GLOBAL: usize = MANAGED_GLOBALS_INFO.1; #[derive(Debug, Clone, Copy)] enum Mode { |