diff options
author | Linus Groh <mail@linusgroh.de> | 2020-06-02 12:32:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-02 13:51:02 +0200 |
commit | b958e4f573b6171f8507efa9c097c82f072d73a3 (patch) | |
tree | bfafc1af7f84be718a34af0d16d7a58c7a31acfb /Libraries/LibJS/Runtime/ObjectConstructor.cpp | |
parent | 8cf1ded478a702d2a8235b16db413e04e0147dd1 (diff) | |
download | serenity-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.cpp | 5 |
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; } |