Bladeren bron

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

I.e. the same as hasOwnProperty(undefined) or
hasOwnProperty("undefined") :^)
Linus Groh 5 jaren geleden
bovenliggende
commit
0a0ba64383

+ 0 - 2
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());
     auto* this_object = interpreter.this_value().to_object(interpreter.heap());
     if (!this_object)
     if (!this_object)
         return {};
         return {};
-    if (!interpreter.argument_count())
-        return {};
     return Value(this_object->has_own_property(interpreter.argument(0).to_string()));
     return Value(this_object->has_own_property(interpreter.argument(0).to_string()));
 }
 }
 
 

+ 6 - 0
Libraries/LibJS/Tests/Object.prototype.hasOwnProperty.js

@@ -5,6 +5,12 @@ try {
     o.foo = 1;
     o.foo = 1;
     assert(o.hasOwnProperty("foo") === true);
     assert(o.hasOwnProperty("foo") === true);
     assert(o.hasOwnProperty("bar") === false);
     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");
     console.log("PASS");
 } catch (e) {
 } catch (e) {
     console.log("FAIL: " + e);
     console.log("FAIL: " + e);