1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:05:08 +00:00

LibJS: Allow function calls with missing arguments

We were interpreting "undefined" as a variable lookup failure in some
cases and throwing a ReferenceError exception instead of treating it
as the valid value "undefined".

This patch wraps the result of variable lookup in Optional<>, which
allows us to only throw ReferenceError when lookup actually fails.
This commit is contained in:
Andreas Kling 2020-03-27 12:54:18 +01:00
parent 04ced9e24a
commit c60dc84a33
7 changed files with 45 additions and 10 deletions

View file

@ -0,0 +1,19 @@
function assert(x) { if (!x) throw 1; }
function foo(a) {
return a;
}
try {
var x = undefined;
assert(x === undefined);
assert(foo(x) === undefined);
var o = {};
o.x = x;
assert(o.x === undefined);
assert(o.x === x);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}