diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-28 18:59:38 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-28 20:03:50 +0200 |
commit | 0a0ba64383ecea92b0e8fbfbea56c54d7c0c8de3 (patch) | |
tree | 23d1e7d212e9bfddbefcd084d58bd1c3d59155be | |
parent | 4419685b7e6d78306c6d1e31402c20822fbfb610 (diff) | |
download | serenity-0a0ba64383ecea92b0e8fbfbea56c54d7c0c8de3.zip |
LibJS: Handle Object.prototype.hasOwnProperty() with no arg correctly
I.e. the same as hasOwnProperty(undefined) or
hasOwnProperty("undefined") :^)
-rw-r--r-- | Libraries/LibJS/Runtime/ObjectPrototype.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/Libraries/LibJS/Runtime/ObjectPrototype.cpp b/Libraries/LibJS/Runtime/ObjectPrototype.cpp index 53a3c4f518..f6d5aee272 100644 --- a/Libraries/LibJS/Runtime/ObjectPrototype.cpp +++ b/Libraries/LibJS/Runtime/ObjectPrototype.cpp @@ -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())); } diff --git a/Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js b/Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js index 0a12f2ee52..16dec1062c 100644 --- a/Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js +++ b/Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js @@ -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); |