summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/AST.cpp
diff options
context:
space:
mode:
authorJack Karamanian <karamanian.jack@gmail.com>2020-06-13 21:23:33 -0500
committerAndreas Kling <kling@serenityos.org>2020-06-29 17:54:54 +0200
commita535d58cac6cfef7c85cd9ee8419189d58560afb (patch)
tree05d2391f38957189ab9e2ad6a19a4fc625c7bab3 /Libraries/LibJS/AST.cpp
parent949bffdc933a5e992c7ae09fa7d2031abd343276 (diff)
downloadserenity-a535d58cac6cfef7c85cd9ee8419189d58560afb.zip
LibJS: Add Object::define_accessor()
This is a helper function based on the getter/setter definition logic from ObjectExpression::execute() to look up an Accessor property if it already exists, define a new Accessor property if it doesn't exist, and set the getter or setter function on the Accessor.
Diffstat (limited to 'Libraries/LibJS/AST.cpp')
-rw-r--r--Libraries/LibJS/AST.cpp20
1 files changed, 3 insertions, 17 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp
index 308c951914..4d86f628c2 100644
--- a/Libraries/LibJS/AST.cpp
+++ b/Libraries/LibJS/AST.cpp
@@ -1364,23 +1364,9 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o
if (property.type() == ObjectProperty::Type::Getter || property.type() == ObjectProperty::Type::Setter) {
ASSERT(value.is_function());
- Accessor* accessor { nullptr };
- auto property_metadata = object->shape().lookup(key);
- if (property_metadata.has_value()) {
- auto existing_property = object->get_direct(property_metadata.value().offset);
- if (existing_property.is_accessor())
- accessor = &existing_property.as_accessor();
- }
- if (!accessor) {
- accessor = Accessor::create(interpreter, global_object, nullptr, nullptr);
- object->define_property(key, accessor, Attribute::Configurable | Attribute::Enumerable);
- if (interpreter.exception())
- return {};
- }
- if (property.type() == ObjectProperty::Type::Getter)
- accessor->set_getter(&value.as_function());
- else
- accessor->set_setter(&value.as_function());
+ object->define_accessor(key, value.as_function(), property.type() == ObjectProperty::Type::Getter, Attribute::Configurable | Attribute::Enumerable);
+ if (interpreter.exception())
+ return {};
} else {
object->define_property(key, value);
if (interpreter.exception())