1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:47:35 +00:00

LibJS: Make typeof return undefined for undefined variables

This makes `typeof i_dont_exist` return `undefined` instead of 
throwing an error.
This commit is contained in:
Marcin Gasperowicz 2020-06-02 23:26:39 +02:00 committed by Andreas Kling
parent b0932b0aec
commit 0b74ea3d6a
2 changed files with 32 additions and 3 deletions

View file

@ -8,6 +8,19 @@ try {
assert(typeof null === "object");
assert(typeof undefined === "undefined");
var iExist = 1;
assert(typeof iExist === "number");
assert(typeof iDontExist === "undefined");
var calls = 0;
Object.defineProperty(globalThis, "foo", {
get() {
calls++;
},
});
assert(typeof foo === "undefined");
assert(calls === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);