1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 18:47:41 +00:00

LibJS: Use VM::exception() instead of Interpreter::exception() a bunch

There's a lot more of these things to fix. We'll also want to move from
passing Interpreter& around to VM& instead wherever that is enough.
This commit is contained in:
Andreas Kling 2020-09-21 16:46:45 +02:00
parent d74bb87d46
commit 676cb87a8f
5 changed files with 79 additions and 79 deletions

View file

@ -86,10 +86,10 @@ inline void GlobalObject::add_constructor(const FlyString& property_name, Constr
{ {
constructor = heap().allocate<ConstructorType>(*this, *this); constructor = heap().allocate<ConstructorType>(*this, *this);
constructor->define_property("name", js_string(heap(), property_name), Attribute::Configurable); constructor->define_property("name", js_string(heap(), property_name), Attribute::Configurable);
if (interpreter().exception()) if (vm().exception())
return; return;
prototype.define_property("constructor", constructor, Attribute::Writable | Attribute::Configurable); prototype.define_property("constructor", constructor, Attribute::Writable | Attribute::Configurable);
if (interpreter().exception()) if (vm().exception())
return; return;
define_property(property_name, constructor, Attribute::Writable | Attribute::Configurable); define_property(property_name, constructor, Attribute::Writable | Attribute::Configurable);
} }

View file

@ -42,40 +42,40 @@
namespace JS { namespace JS {
PropertyDescriptor PropertyDescriptor::from_dictionary(Interpreter& interpreter, const Object& object) PropertyDescriptor PropertyDescriptor::from_dictionary(VM& vm, const Object& object)
{ {
PropertyAttributes attributes; PropertyAttributes attributes;
if (object.has_property("configurable")) { if (object.has_property("configurable")) {
attributes.set_has_configurable(); attributes.set_has_configurable();
if (object.get("configurable").value_or(Value(false)).to_boolean()) if (object.get("configurable").value_or(Value(false)).to_boolean())
attributes.set_configurable(); attributes.set_configurable();
if (interpreter.exception()) if (vm.exception())
return {}; return {};
} }
if (object.has_property("enumerable")) { if (object.has_property("enumerable")) {
attributes.set_has_enumerable(); attributes.set_has_enumerable();
if (object.get("enumerable").value_or(Value(false)).to_boolean()) if (object.get("enumerable").value_or(Value(false)).to_boolean())
attributes.set_enumerable(); attributes.set_enumerable();
if (interpreter.exception()) if (vm.exception())
return {}; return {};
} }
if (object.has_property("writable")) { if (object.has_property("writable")) {
attributes.set_has_writable(); attributes.set_has_writable();
if (object.get("writable").value_or(Value(false)).to_boolean()) if (object.get("writable").value_or(Value(false)).to_boolean())
attributes.set_writable(); attributes.set_writable();
if (interpreter.exception()) if (vm.exception())
return {}; return {};
} }
PropertyDescriptor descriptor { attributes, object.get("value"), nullptr, nullptr }; PropertyDescriptor descriptor { attributes, object.get("value"), nullptr, nullptr };
if (interpreter.exception()) if (vm.exception())
return {}; return {};
auto getter = object.get("get"); auto getter = object.get("get");
if (interpreter.exception()) if (vm.exception())
return {}; return {};
if (getter.is_function()) if (getter.is_function())
descriptor.getter = &getter.as_function(); descriptor.getter = &getter.as_function();
auto setter = object.get("set"); auto setter = object.get("set");
if (interpreter.exception()) if (vm.exception())
return {}; return {};
if (setter.is_function()) if (setter.is_function())
descriptor.setter = &setter.as_function(); descriptor.setter = &setter.as_function();
@ -140,7 +140,7 @@ bool Object::set_prototype(Object* new_prototype)
bool Object::has_prototype(const Object* prototype) const bool Object::has_prototype(const Object* prototype) const
{ {
for (auto* object = this->prototype(); object; object = object->prototype()) { for (auto* object = this->prototype(); object; object = object->prototype()) {
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (object == prototype) if (object == prototype)
return true; return true;
@ -198,7 +198,7 @@ Value Object::get_own_properties(const Object& this_object, PropertyKind kind, b
entry_array->define_property(1, js_string(interpreter(), String::format("%c", str[i]))); entry_array->define_property(1, js_string(interpreter(), String::format("%c", str[i])));
properties_array->define_property(i, entry_array); properties_array->define_property(i, entry_array);
} }
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
@ -221,7 +221,7 @@ Value Object::get_own_properties(const Object& this_object, PropertyKind kind, b
entry_array->define_property(1, value_and_attributes.value); entry_array->define_property(1, value_and_attributes.value);
properties_array->define_property(property_index, entry_array); properties_array->define_property(property_index, entry_array);
} }
if (interpreter().exception()) if (vm().exception())
return {}; return {};
++property_index; ++property_index;
@ -246,7 +246,7 @@ Value Object::get_own_properties(const Object& this_object, PropertyKind kind, b
entry_array->define_property(1, this_object.get(it.key)); entry_array->define_property(1, this_object.get(it.key));
properties_array->define_property(property_index, entry_array); properties_array->define_property(property_index, entry_array);
} }
if (interpreter().exception()) if (vm().exception())
return {}; return {};
++property_index; ++property_index;
@ -272,7 +272,7 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN
if (!metadata.has_value()) if (!metadata.has_value())
return {}; return {};
value = m_storage[metadata.value().offset]; value = m_storage[metadata.value().offset];
if (interpreter().exception()) if (vm().exception())
return {}; return {};
attributes = metadata.value().attributes; attributes = metadata.value().attributes;
} }
@ -303,27 +303,27 @@ Value Object::get_own_property_descriptor_object(const PropertyName& property_na
auto* descriptor_object = Object::create_empty(global_object()); auto* descriptor_object = Object::create_empty(global_object());
descriptor_object->define_property("enumerable", Value(descriptor.attributes.is_enumerable())); descriptor_object->define_property("enumerable", Value(descriptor.attributes.is_enumerable()));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
descriptor_object->define_property("configurable", Value(descriptor.attributes.is_configurable())); descriptor_object->define_property("configurable", Value(descriptor.attributes.is_configurable()));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (descriptor.is_data_descriptor()) { if (descriptor.is_data_descriptor()) {
descriptor_object->define_property("value", descriptor.value.value_or(js_undefined())); descriptor_object->define_property("value", descriptor.value.value_or(js_undefined()));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
descriptor_object->define_property("writable", Value(descriptor.attributes.is_writable())); descriptor_object->define_property("writable", Value(descriptor.attributes.is_writable()));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} else if (descriptor.is_accessor_descriptor()) { } else if (descriptor.is_accessor_descriptor()) {
if (descriptor.getter) { if (descriptor.getter) {
descriptor_object->define_property("get", Value(descriptor.getter)); descriptor_object->define_property("get", Value(descriptor.getter));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
if (descriptor.setter) { if (descriptor.setter) {
descriptor_object->define_property("set", Value(descriptor.setter)); descriptor_object->define_property("set", Value(descriptor.setter));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
} }
@ -344,14 +344,14 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object&
attributes.set_has_configurable(); attributes.set_has_configurable();
if (descriptor.get("configurable").value_or(Value(false)).to_boolean()) if (descriptor.get("configurable").value_or(Value(false)).to_boolean())
attributes.set_configurable(); attributes.set_configurable();
if (interpreter().exception()) if (vm().exception())
return false; return false;
} }
if (descriptor.has_property("enumerable")) { if (descriptor.has_property("enumerable")) {
attributes.set_has_enumerable(); attributes.set_has_enumerable();
if (descriptor.get("enumerable").value_or(Value(false)).to_boolean()) if (descriptor.get("enumerable").value_or(Value(false)).to_boolean())
attributes.set_enumerable(); attributes.set_enumerable();
if (interpreter().exception()) if (vm().exception())
return false; return false;
} }
@ -363,10 +363,10 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object&
} }
auto getter = descriptor.get("get").value_or(js_undefined()); auto getter = descriptor.get("get").value_or(js_undefined());
if (interpreter().exception()) if (vm().exception())
return {}; return {};
auto setter = descriptor.get("set").value_or(js_undefined()); auto setter = descriptor.get("set").value_or(js_undefined());
if (interpreter().exception()) if (vm().exception())
return {}; return {};
Function* getter_function { nullptr }; Function* getter_function { nullptr };
@ -396,16 +396,16 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object&
} }
auto value = descriptor.get("value"); auto value = descriptor.get("value");
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (descriptor.has_property("writable")) { if (descriptor.has_property("writable")) {
attributes.set_has_writable(); attributes.set_has_writable();
if (descriptor.get("writable").value_or(Value(false)).to_boolean()) if (descriptor.get("writable").value_or(Value(false)).to_boolean())
attributes.set_writable(); attributes.set_writable();
if (interpreter().exception()) if (vm().exception())
return false; return false;
} }
if (interpreter().exception()) if (vm().exception())
return {}; return {};
#ifdef OBJECT_DEBUG #ifdef OBJECT_DEBUG
@ -440,7 +440,7 @@ bool Object::define_accessor(const PropertyName& property_name, Function& getter
if (!accessor) { if (!accessor) {
accessor = Accessor::create(interpreter(), nullptr, nullptr); accessor = Accessor::create(interpreter(), nullptr, nullptr);
bool definition_success = define_property(property_name, accessor, attributes, throw_exceptions); bool definition_success = define_property(property_name, accessor, attributes, throw_exceptions);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!definition_success) if (!definition_success)
return false; return false;
@ -633,14 +633,14 @@ Value Object::get_by_index(u32 property_index) const
} }
if (static_cast<size_t>(property_index) < object->m_indexed_properties.array_like_size()) { if (static_cast<size_t>(property_index) < object->m_indexed_properties.array_like_size()) {
auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index); auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (result.has_value() && !result.value().value.is_empty()) if (result.has_value() && !result.value().value.is_empty())
return result.value().value; return result.value().value;
return {}; return {};
} }
object = object->prototype(); object = object->prototype();
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
return {}; return {};
@ -663,12 +663,12 @@ Value Object::get(const PropertyName& property_name, Value receiver) const
if (receiver.is_empty()) if (receiver.is_empty())
receiver = Value(const_cast<Object*>(this)); receiver = Value(const_cast<Object*>(this));
auto value = object->get_own_property(*this, property_name, receiver); auto value = object->get_own_property(*this, property_name, receiver);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!value.is_empty()) if (!value.is_empty())
return value; return value;
object = object->prototype(); object = object->prototype();
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
return {}; return {};
@ -695,7 +695,7 @@ bool Object::put_by_index(u32 property_index, Value value)
} }
} }
object = object->prototype(); object = object->prototype();
if (interpreter().exception()) if (vm().exception())
return {}; return {};
} }
return put_own_property_by_index(*this, property_index, value, default_attributes, PutOwnPropertyMode::Put); return put_own_property_by_index(*this, property_index, value, default_attributes, PutOwnPropertyMode::Put);
@ -736,7 +736,7 @@ bool Object::put(const PropertyName& property_name, Value value, Value receiver)
} }
} }
object = object->prototype(); object = object->prototype();
if (interpreter().exception()) if (vm().exception())
return false; return false;
} }
return put_own_property(*this, string_or_symbol, value, default_attributes, PutOwnPropertyMode::Put); return put_own_property(*this, string_or_symbol, value, default_attributes, PutOwnPropertyMode::Put);
@ -752,10 +752,10 @@ bool Object::define_native_function(const StringOrSymbol& property_name, AK::Fun
} }
auto* function = NativeFunction::create(global_object(), function_name, move(native_function)); auto* function = NativeFunction::create(global_object(), function_name, move(native_function));
function->define_property("length", Value(length), Attribute::Configurable); function->define_property("length", Value(length), Attribute::Configurable);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
function->define_property("name", js_string(heap(), function_name), Attribute::Configurable); function->define_property("name", js_string(heap(), function_name), Attribute::Configurable);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
return define_property(property_name, function, attribute); return define_property(property_name, function, attribute);
} }
@ -784,7 +784,7 @@ bool Object::has_property(const PropertyName& property_name) const
if (object->has_own_property(property_name)) if (object->has_own_property(property_name))
return true; return true;
object = object->prototype(); object = object->prototype();
if (interpreter().exception()) if (vm().exception())
return false; return false;
} }
return false; return false;

View file

@ -51,7 +51,7 @@ struct PropertyDescriptor {
Function* getter { nullptr }; Function* getter { nullptr };
Function* setter { nullptr }; Function* setter { nullptr };
static PropertyDescriptor from_dictionary(Interpreter&, const Object&); static PropertyDescriptor from_dictionary(VM&, const Object&);
bool is_accessor_descriptor() const { return getter || setter; } bool is_accessor_descriptor() const { return getter || setter; }
bool is_data_descriptor() const { return !(value.is_empty() && !attributes.has_writable()); } bool is_data_descriptor() const { return !(value.is_empty() && !attributes.has_writable()); }

View file

@ -81,7 +81,7 @@ Object* ProxyObject::prototype()
return nullptr; return nullptr;
} }
auto trap = m_handler.get("getPrototypeOf"); auto trap = m_handler.get("getPrototypeOf");
if (interpreter().exception()) if (vm().exception())
return nullptr; return nullptr;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.prototype(); return m_target.prototype();
@ -91,21 +91,21 @@ Object* ProxyObject::prototype()
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target));
if (interpreter().exception()) if (vm().exception())
return nullptr; return nullptr;
if (!trap_result.is_object() && !trap_result.is_null()) { if (!trap_result.is_object() && !trap_result.is_null()) {
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfReturn); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfReturn);
return nullptr; return nullptr;
} }
if (m_target.is_extensible()) { if (m_target.is_extensible()) {
if (interpreter().exception()) if (vm().exception())
return nullptr; return nullptr;
if (trap_result.is_null()) if (trap_result.is_null())
return nullptr; return nullptr;
return &trap_result.as_object(); return &trap_result.as_object();
} }
auto target_proto = m_target.prototype(); auto target_proto = m_target.prototype();
if (interpreter().exception()) if (vm().exception())
return nullptr; return nullptr;
if (!same_value(interpreter(), trap_result, Value(target_proto))) { if (!same_value(interpreter(), trap_result, Value(target_proto))) {
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfNonExtensible); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfNonExtensible);
@ -130,7 +130,7 @@ bool ProxyObject::set_prototype(Object* object)
return false; return false;
} }
auto trap = m_handler.get("setPrototypeOf"); auto trap = m_handler.get("setPrototypeOf");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.set_prototype(object); return m_target.set_prototype(object);
@ -140,12 +140,12 @@ bool ProxyObject::set_prototype(Object* object)
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object)).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object)).to_boolean();
if (interpreter().exception() || !trap_result) if (vm().exception() || !trap_result)
return false; return false;
if (m_target.is_extensible()) if (m_target.is_extensible())
return true; return true;
auto* target_proto = m_target.prototype(); auto* target_proto = m_target.prototype();
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (!same_value(interpreter(), Value(object), Value(target_proto))) { if (!same_value(interpreter(), Value(object), Value(target_proto))) {
interpreter().throw_exception<TypeError>(ErrorType::ProxySetPrototypeOfNonExtensible); interpreter().throw_exception<TypeError>(ErrorType::ProxySetPrototypeOfNonExtensible);
@ -161,7 +161,7 @@ bool ProxyObject::is_extensible() const
return false; return false;
} }
auto trap = m_handler.get("isExtensible"); auto trap = m_handler.get("isExtensible");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.is_extensible(); return m_target.is_extensible();
@ -171,10 +171,10 @@ bool ProxyObject::is_extensible() const
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap_result != m_target.is_extensible()) { if (trap_result != m_target.is_extensible()) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyIsExtensibleReturn); interpreter().throw_exception<TypeError>(ErrorType::ProxyIsExtensibleReturn);
return false; return false;
} }
@ -188,7 +188,7 @@ bool ProxyObject::prevent_extensions()
return false; return false;
} }
auto trap = m_handler.get("preventExtensions"); auto trap = m_handler.get("preventExtensions");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.prevent_extensions(); return m_target.prevent_extensions();
@ -198,10 +198,10 @@ bool ProxyObject::prevent_extensions()
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap_result && m_target.is_extensible()) { if (trap_result && m_target.is_extensible()) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyPreventExtensionsReturn); interpreter().throw_exception<TypeError>(ErrorType::ProxyPreventExtensionsReturn);
return false; return false;
} }
@ -215,7 +215,7 @@ Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const Prop
return {}; return {};
} }
auto trap = m_handler.get("getOwnPropertyDescriptor"); auto trap = m_handler.get("getOwnPropertyDescriptor");
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.get_own_property_descriptor(name); return m_target.get_own_property_descriptor(name);
@ -225,14 +225,14 @@ Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const Prop
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!trap_result.is_object() && !trap_result.is_undefined()) { if (!trap_result.is_object() && !trap_result.is_undefined()) {
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorReturn); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorReturn);
return {}; return {};
} }
auto target_desc = m_target.get_own_property_descriptor(name); auto target_desc = m_target.get_own_property_descriptor(name);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (trap_result.is_undefined()) { if (trap_result.is_undefined()) {
if (!target_desc.has_value()) if (!target_desc.has_value())
@ -242,17 +242,17 @@ Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const Prop
return {}; return {};
} }
if (!m_target.is_extensible()) { if (!m_target.is_extensible()) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorUndefReturn); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorUndefReturn);
return {}; return {};
} }
return {}; return {};
} }
auto result_desc = PropertyDescriptor::from_dictionary(interpreter(), trap_result.as_object()); auto result_desc = PropertyDescriptor::from_dictionary(vm(), trap_result.as_object());
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), result_desc, target_desc)) { if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), result_desc, target_desc)) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorInvalidDescriptor); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorInvalidDescriptor);
return {}; return {};
} }
@ -270,7 +270,7 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj
return false; return false;
} }
auto trap = m_handler.get("defineProperty"); auto trap = m_handler.get("defineProperty");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.define_property(property_name, descriptor, throw_exceptions); return m_target.define_property(property_name, descriptor, throw_exceptions);
@ -280,19 +280,19 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(interpreter()), Value(const_cast<Object*>(&descriptor))).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(interpreter()), Value(const_cast<Object*>(&descriptor))).to_boolean();
if (interpreter().exception() || !trap_result) if (vm().exception() || !trap_result)
return false; return false;
auto target_desc = m_target.get_own_property_descriptor(property_name); auto target_desc = m_target.get_own_property_descriptor(property_name);
if (interpreter().exception()) if (vm().exception())
return false; return false;
bool setting_config_false = false; bool setting_config_false = false;
if (descriptor.has_property("configurable") && !descriptor.get("configurable").to_boolean()) if (descriptor.has_property("configurable") && !descriptor.get("configurable").to_boolean())
setting_config_false = true; setting_config_false = true;
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (!target_desc.has_value()) { if (!target_desc.has_value()) {
if (!m_target.is_extensible()) { if (!m_target.is_extensible()) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropNonExtensible); interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropNonExtensible);
return false; return false;
} }
@ -301,8 +301,8 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj
return false; return false;
} }
} else { } else {
if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), PropertyDescriptor::from_dictionary(interpreter(), descriptor), target_desc)) { if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), PropertyDescriptor::from_dictionary(vm(), descriptor), target_desc)) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropIncompatibleDescriptor); interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropIncompatibleDescriptor);
return false; return false;
} }
@ -321,7 +321,7 @@ bool ProxyObject::has_property(const PropertyName& name) const
return false; return false;
} }
auto trap = m_handler.get("has"); auto trap = m_handler.get("has");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.has_property(name); return m_target.has_property(name);
@ -331,11 +331,11 @@ bool ProxyObject::has_property(const PropertyName& name) const
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean();
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (!trap_result) { if (!trap_result) {
auto target_desc = m_target.get_own_property_descriptor(name); auto target_desc = m_target.get_own_property_descriptor(name);
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (target_desc.has_value()) { if (target_desc.has_value()) {
if (!target_desc.value().attributes.is_configurable()) { if (!target_desc.value().attributes.is_configurable()) {
@ -343,7 +343,7 @@ bool ProxyObject::has_property(const PropertyName& name) const
return false; return false;
} }
if (!m_target.is_extensible()) { if (!m_target.is_extensible()) {
if (!interpreter().exception()) if (!vm().exception())
interpreter().throw_exception<TypeError>(ErrorType::ProxyHasExistingNonExtensible); interpreter().throw_exception<TypeError>(ErrorType::ProxyHasExistingNonExtensible);
return false; return false;
} }
@ -359,7 +359,7 @@ Value ProxyObject::get(const PropertyName& name, Value) const
return {}; return {};
} }
auto trap = m_handler.get("get"); auto trap = m_handler.get("get");
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.get(name); return m_target.get(name);
@ -369,11 +369,11 @@ Value ProxyObject::get(const PropertyName& name, Value) const
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), Value(const_cast<ProxyObject*>(this))); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), Value(const_cast<ProxyObject*>(this)));
if (interpreter().exception()) if (vm().exception())
return {}; return {};
auto target_desc = m_target.get_own_property_descriptor(name); auto target_desc = m_target.get_own_property_descriptor(name);
if (target_desc.has_value()) { if (target_desc.has_value()) {
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), trap_result, target_desc.value().value)) { if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), trap_result, target_desc.value().value)) {
interpreter().throw_exception<TypeError>(ErrorType::ProxyGetImmutableDataProperty); interpreter().throw_exception<TypeError>(ErrorType::ProxyGetImmutableDataProperty);
@ -394,7 +394,7 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value)
return false; return false;
} }
auto trap = m_handler.get("set"); auto trap = m_handler.get("set");
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.put(name, value); return m_target.put(name, value);
@ -403,10 +403,10 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value)
return false; return false;
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), value, Value(const_cast<ProxyObject*>(this))).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string()), value, Value(const_cast<ProxyObject*>(this))).to_boolean();
if (interpreter().exception() || !trap_result) if (vm().exception() || !trap_result)
return false; return false;
auto target_desc = m_target.get_own_property_descriptor(name); auto target_desc = m_target.get_own_property_descriptor(name);
if (interpreter().exception()) if (vm().exception())
return false; return false;
if (target_desc.has_value() && !target_desc.value().attributes.is_configurable()) { if (target_desc.has_value() && !target_desc.value().attributes.is_configurable()) {
if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), value, target_desc.value().value)) { if (target_desc.value().is_data_descriptor() && !target_desc.value().attributes.is_writable() && !same_value(interpreter(), value, target_desc.value().value)) {
@ -427,7 +427,7 @@ Value ProxyObject::delete_property(const PropertyName& name)
return {}; return {};
} }
auto trap = m_handler.get("deleteProperty"); auto trap = m_handler.get("deleteProperty");
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (trap.is_empty() || trap.is_undefined() || trap.is_null()) if (trap.is_empty() || trap.is_undefined() || trap.is_null())
return m_target.delete_property(name); return m_target.delete_property(name);
@ -437,12 +437,12 @@ Value ProxyObject::delete_property(const PropertyName& name)
} }
auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean(); auto trap_result = interpreter().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(interpreter(), name.to_string())).to_boolean();
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!trap_result) if (!trap_result)
return Value(false); return Value(false);
auto target_desc = m_target.get_own_property_descriptor(name); auto target_desc = m_target.get_own_property_descriptor(name);
if (interpreter().exception()) if (vm().exception())
return {}; return {};
if (!target_desc.has_value()) if (!target_desc.has_value())
return Value(true); return Value(true);

View file

@ -70,7 +70,7 @@ bool Uint8ClampedArray::put_by_index(u32 property_index, Value value)
// FIXME: Use attributes // FIXME: Use attributes
ASSERT(property_index < m_length); ASSERT(property_index < m_length);
auto number = value.to_i32(interpreter()); auto number = value.to_i32(interpreter());
if (interpreter().exception()) if (vm().exception())
return {}; return {};
m_data[property_index] = clamp(number, 0, 255); m_data[property_index] = clamp(number, 0, 255);
return true; return true;