Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not return undefined for missing global properties #24474

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/node/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ pub fn getter<'s>(
let reflect_get = v8::Local::new(scope, reflect_get);
let inner = v8::Local::new(scope, inner);

if !inner.has_own_property(scope, key).unwrap_or(false) {
return v8::Intercepted::No;
}

let undefined = v8::undefined(scope);
let Some(value) = reflect_get.call(
scope,
Expand Down
6 changes: 3 additions & 3 deletions ext/web/02_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function checkThis(thisArg) {
function setImmediate(callback, ...args) {
if (args.length > 0) {
const unboundCallback = callback;
callback = () => ReflectApply(unboundCallback, window, args);
callback = () => ReflectApply(unboundCallback, globalThis, args);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure why these had to be changed, i'm pretty sure this file should be deno mode.

}

return core.queueImmediate(
Expand All @@ -55,7 +55,7 @@ function setTimeout(callback, timeout = 0, ...args) {
}
if (args.length > 0) {
const unboundCallback = callback;
callback = () => ReflectApply(unboundCallback, window, args);
callback = () => ReflectApply(unboundCallback, globalThis, args);
}
timeout = webidl.converters.long(timeout);
return core.queueUserTimer(
Expand All @@ -77,7 +77,7 @@ function setInterval(callback, timeout = 0, ...args) {
}
if (args.length > 0) {
const unboundCallback = callback;
callback = () => ReflectApply(unboundCallback, window, args);
callback = () => ReflectApply(unboundCallback, globalThis, args);
}
timeout = webidl.converters.long(timeout);
return core.queueUserTimer(
Expand Down
1 change: 0 additions & 1 deletion tests/node_compat/test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ let knownGlobals = [
self,
sessionStorage,
setImmediate,
window,
];

if (global.AbortController)
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/globals_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

// deno-lint-ignore-file no-window-prefix no-window
import { assert, assertEquals, assertRejects } from "./test_util.ts";
import {
assert,
assertEquals,
assertRejects,
assertThrows,
} from "./test_util.ts";

Deno.test(function globalThisExists() {
assert(globalThis != null);
Expand Down Expand Up @@ -224,3 +229,10 @@ Deno.test(function mapGroupBy() {
quantity: 5,
}]);
});

Deno.test(function nodeGlobalsRaise() {
assertThrows(() => {
// @ts-ignore yes that's the point
Buffer;
}, ReferenceError);
});