LibJS: Handle Object.prototype.hasOwnProperty() with no arg correctly

I.e. the same as hasOwnProperty(undefined) or
hasOwnProperty("undefined") :^)
This commit is contained in:
Linus Groh 2020-04-28 18:59:38 +01:00 committed by Andreas Kling
parent 4419685b7e
commit 0a0ba64383
Notes: sideshowbarker 2024-07-19 07:13:12 +09:00
2 changed files with 6 additions and 2 deletions

View file

@ -57,8 +57,6 @@ Value ObjectPrototype::has_own_property(Interpreter& interpreter)
auto* this_object = interpreter.this_value().to_object(interpreter.heap());
if (!this_object)
return {};
if (!interpreter.argument_count())
return {};
return Value(this_object->has_own_property(interpreter.argument(0).to_string()));
}

View file

@ -5,6 +5,12 @@ try {
o.foo = 1;
assert(o.hasOwnProperty("foo") === true);
assert(o.hasOwnProperty("bar") === false);
assert(o.hasOwnProperty() === false);
assert(o.hasOwnProperty(undefined) === false);
o.undefined = 2;
assert(o.hasOwnProperty() === true);
assert(o.hasOwnProperty(undefined) === true);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);