From 1a64bdd80c8a1c54f92842350c42814a24bd8e7a Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 2 Jun 2020 11:39:24 +0100 Subject: [PATCH] LibJS: Return specified object from Object.setPrototypeOf() We were leaking an empty value. --- Libraries/LibJS/Runtime/ObjectConstructor.cpp | 2 +- Libraries/LibJS/Tests/Object.setPrototypeOf.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Libraries/LibJS/Tests/Object.setPrototypeOf.js diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 1c56ce254f3..c9ed9087f22 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(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 00000000000..c803865c1f7 --- /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); +}