summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/ObjectConstructor.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-06-02 12:32:54 +0100
committerAndreas Kling <kling@serenityos.org>2020-06-02 13:51:02 +0200
commitb958e4f573b6171f8507efa9c097c82f072d73a3 (patch)
treebfafc1af7f84be718a34af0d16d7a58c7a31acfb /Libraries/LibJS/Runtime/ObjectConstructor.cpp
parent8cf1ded478a702d2a8235b16db413e04e0147dd1 (diff)
downloadserenity-b958e4f573b6171f8507efa9c097c82f072d73a3.zip
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.
Diffstat (limited to 'Libraries/LibJS/Runtime/ObjectConstructor.cpp')
-rw-r--r--Libraries/LibJS/Runtime/ObjectConstructor.cpp5
1 files changed, 4 insertions, 1 deletions
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<TypeError>("Prototype must be null or object");
return {};
}
- object->set_prototype(prototype);
+ if (!object->set_prototype(prototype)) {
+ interpreter.throw_exception<TypeError>("Can't set prototype of non-extensible object");
+ return {};
+ }
return object;
}