mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: do not return undefined for missing global properties (#24474)
accessing e.g. `Buffer` in `Mode::Deno` mode should throw, not return undefined. --------- Signed-off-by: snek <snek@deno.com>
This commit is contained in:
parent
839caf6faf
commit
c461f8fd2e
4 changed files with 20 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
return core.queueImmediate(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
|
|
@ -62,7 +62,6 @@ let knownGlobals = [
|
|||
self,
|
||||
sessionStorage,
|
||||
setImmediate,
|
||||
window,
|
||||
];
|
||||
|
||||
if (global.AbortController)
|
||||
|
|
|
@ -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);
|
||||
|
@ -224,3 +229,10 @@ Deno.test(function mapGroupBy() {
|
|||
quantity: 5,
|
||||
}]);
|
||||
});
|
||||
|
||||
Deno.test(function nodeGlobalsRaise() {
|
||||
assertThrows(() => {
|
||||
// @ts-ignore yes that's the point
|
||||
Buffer;
|
||||
}, ReferenceError);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue