summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-06-02 11:39:24 +0100
committerAndreas Kling <kling@serenityos.org>2020-06-02 13:51:02 +0200
commit1a64bdd80c8a1c54f92842350c42814a24bd8e7a (patch)
tree2f39bdd5692973137b21aa842e43339d9ddd870e
parenta60a5bc70a4fffd5e4d98adec87a89e1704799fd (diff)
downloadserenity-1a64bdd80c8a1c54f92842350c42814a24bd8e7a.zip
LibJS: Return specified object from Object.setPrototypeOf()
We were leaking an empty value.
-rw-r--r--Libraries/LibJS/Runtime/ObjectConstructor.cpp2
-rw-r--r--Libraries/LibJS/Tests/Object.setPrototypeOf.js12
2 files changed, 13 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp
index 1c56ce254f..c9ed9087f2 100644
--- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp
+++ b/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)
diff --git a/Libraries/LibJS/Tests/Object.setPrototypeOf.js b/Libraries/LibJS/Tests/Object.setPrototypeOf.js
new file mode 100644
index 0000000000..c803865c1f
--- /dev/null
+++ b/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);
+}