summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-11-22 17:04:40 +0000
committerAndreas Kling <kling@serenityos.org>2020-11-22 19:00:19 +0100
commitc52739ea4bfb10d212f34df920e01148ac11ae4b (patch)
tree75d99198d31235e3c127e2bf797d2d6175424fbd /Libraries
parent773df8826dddeb4fced0af6377233d79fc5ad74c (diff)
downloadserenity-c52739ea4bfb10d212f34df920e01148ac11ae4b.zip
LibJS: Make call_native_property_{g,s}etter() take a NativeProperty&
Passing in a plain Value and expecting it to be a native property is error prone, let's use a more narrow type and pass a NativeProperty reference directly.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/Object.cpp25
-rw-r--r--Libraries/LibJS/Runtime/Object.h4
2 files changed, 13 insertions, 16 deletions
diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp
index 48d6fcafef..60977acfcd 100644
--- a/Libraries/LibJS/Runtime/Object.cpp
+++ b/Libraries/LibJS/Runtime/Object.cpp
@@ -178,11 +178,10 @@ Value Object::get_own_property(const Object& this_object, PropertyName property_
}
ASSERT(!value_here.is_empty());
- if (value_here.is_accessor()) {
+ if (value_here.is_accessor())
return value_here.as_accessor().call_getter(receiver);
- }
if (value_here.is_native_property())
- return call_native_property_getter(const_cast<Object*>(&this_object), value_here);
+ return call_native_property_getter(const_cast<Object*>(&this_object), value_here.as_native_property());
return value_here;
}
@@ -288,7 +287,7 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN
PropertyDescriptor descriptor { attributes, {}, nullptr, nullptr };
if (value.is_native_property()) {
- auto result = call_native_property_getter(const_cast<Object*>(this), value);
+ auto result = call_native_property_getter(const_cast<Object*>(this), value.as_native_property());
descriptor.value = result.value_or(js_undefined());
} else if (value.is_accessor()) {
auto& pair = value.as_accessor();
@@ -564,7 +563,7 @@ bool Object::put_own_property(Object& this_object, const StringOrSymbol& propert
return true;
if (value_here.is_native_property()) {
- call_native_property_setter(const_cast<Object*>(&this_object), value_here, value);
+ call_native_property_setter(const_cast<Object*>(&this_object), value_here.as_native_property(), value);
} else {
m_storage[metadata.value().offset] = value;
}
@@ -618,7 +617,7 @@ bool Object::put_own_property_by_index(Object& this_object, u32 property_index,
return true;
if (value_here.is_native_property()) {
- call_native_property_setter(const_cast<Object*>(&this_object), value_here, value);
+ call_native_property_setter(const_cast<Object*>(&this_object), value_here.as_native_property(), value);
} else {
m_indexed_properties.put(&this_object, property_index, value, attributes, mode == PutOwnPropertyMode::Put);
}
@@ -732,7 +731,7 @@ bool Object::put_by_index(u32 property_index, Value value)
return true;
}
if (value_here.value.is_native_property()) {
- call_native_property_setter(const_cast<Object*>(this), value_here.value, value);
+ call_native_property_setter(const_cast<Object*>(this), value_here.value.as_native_property(), value);
return true;
}
}
@@ -775,7 +774,7 @@ bool Object::put(const PropertyName& property_name, Value value, Value receiver)
return true;
}
if (value_here.is_native_property()) {
- call_native_property_setter(const_cast<Object*>(this), value_here, value);
+ call_native_property_setter(const_cast<Object*>(this), value_here.as_native_property(), value);
return true;
}
}
@@ -896,9 +895,8 @@ Value Object::invoke(const StringOrSymbol& property_name, Optional<MarkedValueLi
return vm.call(property.as_function(), this, move(arguments));
}
-Value Object::call_native_property_getter(Object* this_object, Value property) const
+Value Object::call_native_property_getter(Object* this_object, NativeProperty& property) const
{
- ASSERT(property.is_native_property());
auto& vm = this->vm();
CallFrame call_frame;
call_frame.is_strict_mode = vm.in_strict_mode();
@@ -906,14 +904,13 @@ Value Object::call_native_property_getter(Object* this_object, Value property) c
vm.push_call_frame(call_frame, global_object());
if (vm.exception())
return {};
- auto result = property.as_native_property().get(vm, global_object());
+ auto result = property.get(vm, global_object());
vm.pop_call_frame();
return result;
}
-void Object::call_native_property_setter(Object* this_object, Value property, Value value) const
+void Object::call_native_property_setter(Object* this_object, NativeProperty& property, Value value) const
{
- ASSERT(property.is_native_property());
auto& vm = this->vm();
CallFrame call_frame;
call_frame.is_strict_mode = vm.in_strict_mode();
@@ -921,7 +918,7 @@ void Object::call_native_property_setter(Object* this_object, Value property, Va
vm.push_call_frame(call_frame, global_object());
if (vm.exception())
return;
- property.as_native_property().set(vm, global_object(), value);
+ property.set(vm, global_object(), value);
vm.pop_call_frame();
}
diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h
index 93e9daac69..417dedc591 100644
--- a/Libraries/LibJS/Runtime/Object.h
+++ b/Libraries/LibJS/Runtime/Object.h
@@ -167,8 +167,8 @@ private:
bool put_own_property(Object& this_object, const StringOrSymbol& property_name, Value, PropertyAttributes attributes, PutOwnPropertyMode = PutOwnPropertyMode::Put, bool throw_exceptions = true);
bool put_own_property_by_index(Object& this_object, u32 property_index, Value, PropertyAttributes attributes, PutOwnPropertyMode = PutOwnPropertyMode::Put, bool throw_exceptions = true);
- Value call_native_property_getter(Object* this_object, Value property) const;
- void call_native_property_setter(Object* this_object, Value property, Value) const;
+ Value call_native_property_getter(Object* this_object, NativeProperty& property) const;
+ void call_native_property_setter(Object* this_object, NativeProperty& property, Value) const;
void set_shape(Shape&);