From b32761f2e0e1e65d739f995fd512724eea37865a Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 2 Jun 2020 12:39:02 +0100 Subject: [PATCH] LibJS: Consider non-extensible objects in Reflect.setPrototypeOf() --- Libraries/LibJS/Runtime/ReflectObject.cpp | 4 +--- Libraries/LibJS/Tests/Reflect.setPrototypeOf.js | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Libraries/LibJS/Runtime/ReflectObject.cpp b/Libraries/LibJS/Runtime/ReflectObject.cpp index 3fd2dddb04..2a10fce38e 100644 --- a/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -261,9 +261,7 @@ Value ReflectObject::set_prototype_of(Interpreter& interpreter) Object* prototype = nullptr; if (!prototype_value.is_null()) prototype = const_cast(&prototype_value.as_object()); - target->set_prototype(prototype); - // FIXME: Needs to return false for prototype chain cycles and non-extensible objects (don't have those yet). - return Value(true); + return Value(target->set_prototype(prototype)); } } diff --git a/Libraries/LibJS/Tests/Reflect.setPrototypeOf.js b/Libraries/LibJS/Tests/Reflect.setPrototypeOf.js index bd7d7f4fd1..81758ff3ec 100644 --- a/Libraries/LibJS/Tests/Reflect.setPrototypeOf.js +++ b/Libraries/LibJS/Tests/Reflect.setPrototypeOf.js @@ -28,10 +28,14 @@ try { assert(Reflect.setPrototypeOf({}, Reflect.getPrototypeOf({})) === true); var o = {}; + var p = { foo: "bar" }; assert(o.foo === undefined); - assert(Reflect.setPrototypeOf(o, { foo: "bar" }) === true); + assert(Reflect.setPrototypeOf(o, p) === true); assert(o.foo === "bar"); + Reflect.preventExtensions(o); + assert(Reflect.setPrototypeOf(o, {}) === false); + assert(Reflect.setPrototypeOf(o, p) === true); console.log("PASS"); } catch (e) {