From b958e4f573b6171f8507efa9c097c82f072d73a3 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 2 Jun 2020 12:32:54 +0100 Subject: LibJS: Disallow changing the prototype of non-extensible objects Object::set_prototype() now returns a boolean indicating success. Setting the prototype to an identical object is always considered successful, even if the object is non-extensible. --- Libraries/LibJS/Runtime/ObjectConstructor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Libraries/LibJS/Runtime/ObjectConstructor.cpp') diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 23b247d6b7..a4882889b4 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -112,7 +112,10 @@ Value ObjectConstructor::set_prototype_of(Interpreter& interpreter) interpreter.throw_exception("Prototype must be null or object"); return {}; } - object->set_prototype(prototype); + if (!object->set_prototype(prototype)) { + interpreter.throw_exception("Can't set prototype of non-extensible object"); + return {}; + } return object; } -- cgit v1.2.3