Ver Fonte

LibJS: Return specified object from Object.setPrototypeOf()

We were leaking an empty value.
Linus Groh há 5 anos atrás
pai
commit
1a64bdd80c

+ 1 - 1
Libraries/LibJS/Runtime/ObjectConstructor.cpp

@@ -103,7 +103,7 @@ Value ObjectConstructor::set_prototype_of(Interpreter& interpreter)
     if (interpreter.exception())
         return {};
     object->set_prototype(&const_cast<Object&>(interpreter.argument(1).as_object()));
-    return {};
+    return object;
 }
 
 Value ObjectConstructor::is_extensible(Interpreter& interpreter)

+ 12 - 0
Libraries/LibJS/Tests/Object.setPrototypeOf.js

@@ -0,0 +1,12 @@
+load("test-common.js");
+
+try {
+    assert(Object.setPrototypeOf.length === 2);
+
+    o = {};
+    assert(Object.setPrototypeOf(o, {}) === o);
+
+    console.log("PASS");
+} catch (e) {
+    console.log("FAIL: " + e);
+}