diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-21 16:46:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-22 20:10:20 +0200 |
commit | 676cb87a8f767577260b6088cdb443ed4733016e (patch) | |
tree | 632ac66827496564db2c38bbadc07ade1dcb70c1 /Libraries | |
parent | d74bb87d469b29ead6e39337e7eaf5fadc288c71 (diff) | |
download | serenity-676cb87a8f767577260b6088cdb443ed4733016e.zip |
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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Runtime/GlobalObject.h | 4 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Object.cpp | 70 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Object.h | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/ProxyObject.cpp | 80 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Uint8ClampedArray.cpp | 2 |
5 files changed, 79 insertions, 79 deletions
diff --git a/Libraries/LibJS/Runtime/GlobalObject.h b/Libraries/LibJS/Runtime/GlobalObject.h index 36472a7f2f..7b39ef9b9a 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Libraries/LibJS/Runtime/GlobalObject.h @@ -86,10 +86,10 @@ inline void GlobalObject::add_constructor(const FlyString& property_name, Constr { constructor = heap().allocate<ConstructorType>(*this, *this); constructor->define_property("name", js_string(heap(), property_name), Attribute::Configurable); - if (interpreter().exception()) + if (vm().exception()) return; prototype.define_property("constructor", constructor, Attribute::Writable | Attribute::Configurable); - if (interpreter().exception()) + if (vm().exception()) return; define_property(property_name, constructor, Attribute::Writable | Attribute::Configurable); } diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index 149bc1cfe0..a77c78df95 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -42,40 +42,40 @@ namespace JS { -PropertyDescriptor PropertyDescriptor::from_dictionary(Interpreter& interpreter, const Object& object) +PropertyDescriptor PropertyDescriptor::from_dictionary(VM& vm, const Object& object) { PropertyAttributes attributes; if (object.has_property("configurable")) { attributes.set_has_configurable(); if (object.get("configurable").value_or(Value(false)).to_boolean()) attributes.set_configurable(); - if (interpreter.exception()) + if (vm.exception()) return {}; } if (object.has_property("enumerable")) { attributes.set_has_enumerable(); if (object.get("enumerable").value_or(Value(false)).to_boolean()) attributes.set_enumerable(); - if (interpreter.exception()) + if (vm.exception()) return {}; } if (object.has_property("writable")) { attributes.set_has_writable(); if (object.get("writable").value_or(Value(false)).to_boolean()) attributes.set_writable(); - if (interpreter.exception()) + if (vm.exception()) return {}; } PropertyDescriptor descriptor { attributes, object.get("value"), nullptr, nullptr }; - if (interpreter.exception()) + if (vm.exception()) return {}; auto getter = object.get("get"); - if (interpreter.exception()) + if (vm.exception()) return {}; if (getter.is_function()) descriptor.getter = &getter.as_function(); auto setter = object.get("set"); - if (interpreter.exception()) + if (vm.exception()) return {}; if (setter.is_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 { for (auto* object = this->prototype(); object; object = object->prototype()) { - if (interpreter().exception()) + if (vm().exception()) return false; if (object == prototype) 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]))); properties_array->define_property(i, entry_array); } - if (interpreter().exception()) + if (vm().exception()) 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); properties_array->define_property(property_index, entry_array); } - if (interpreter().exception()) + if (vm().exception()) return {}; ++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)); properties_array->define_property(property_index, entry_array); } - if (interpreter().exception()) + if (vm().exception()) return {}; ++property_index; @@ -272,7 +272,7 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN if (!metadata.has_value()) return {}; value = m_storage[metadata.value().offset]; - if (interpreter().exception()) + if (vm().exception()) return {}; 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()); descriptor_object->define_property("enumerable", Value(descriptor.attributes.is_enumerable())); - if (interpreter().exception()) + if (vm().exception()) return {}; descriptor_object->define_property("configurable", Value(descriptor.attributes.is_configurable())); - if (interpreter().exception()) + if (vm().exception()) return {}; if (descriptor.is_data_descriptor()) { descriptor_object->define_property("value", descriptor.value.value_or(js_undefined())); - if (interpreter().exception()) + if (vm().exception()) return {}; descriptor_object->define_property("writable", Value(descriptor.attributes.is_writable())); - if (interpreter().exception()) + if (vm().exception()) return {}; } else if (descriptor.is_accessor_descriptor()) { if (descriptor.getter) { descriptor_object->define_property("get", Value(descriptor.getter)); - if (interpreter().exception()) + if (vm().exception()) return {}; } if (descriptor.setter) { descriptor_object->define_property("set", Value(descriptor.setter)); - if (interpreter().exception()) + if (vm().exception()) return {}; } } @@ -344,14 +344,14 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object& attributes.set_has_configurable(); if (descriptor.get("configurable").value_or(Value(false)).to_boolean()) attributes.set_configurable(); - if (interpreter().exception()) + if (vm().exception()) return false; } if (descriptor.has_property("enumerable")) { attributes.set_has_enumerable(); if (descriptor.get("enumerable").value_or(Value(false)).to_boolean()) attributes.set_enumerable(); - if (interpreter().exception()) + if (vm().exception()) 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()); - if (interpreter().exception()) + if (vm().exception()) return {}; auto setter = descriptor.get("set").value_or(js_undefined()); - if (interpreter().exception()) + if (vm().exception()) return {}; Function* getter_function { nullptr }; @@ -396,16 +396,16 @@ bool Object::define_property(const StringOrSymbol& property_name, const Object& } auto value = descriptor.get("value"); - if (interpreter().exception()) + if (vm().exception()) return {}; if (descriptor.has_property("writable")) { attributes.set_has_writable(); if (descriptor.get("writable").value_or(Value(false)).to_boolean()) attributes.set_writable(); - if (interpreter().exception()) + if (vm().exception()) return false; } - if (interpreter().exception()) + if (vm().exception()) return {}; #ifdef OBJECT_DEBUG @@ -440,7 +440,7 @@ bool Object::define_accessor(const PropertyName& property_name, Function& getter if (!accessor) { accessor = Accessor::create(interpreter(), nullptr, nullptr); bool definition_success = define_property(property_name, accessor, attributes, throw_exceptions); - if (interpreter().exception()) + if (vm().exception()) return {}; if (!definition_success) 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()) { auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index); - if (interpreter().exception()) + if (vm().exception()) return {}; if (result.has_value() && !result.value().value.is_empty()) return result.value().value; return {}; } object = object->prototype(); - if (interpreter().exception()) + if (vm().exception()) return {}; } return {}; @@ -663,12 +663,12 @@ Value Object::get(const PropertyName& property_name, Value receiver) const if (receiver.is_empty()) receiver = Value(const_cast<Object*>(this)); auto value = object->get_own_property(*this, property_name, receiver); - if (interpreter().exception()) + if (vm().exception()) return {}; if (!value.is_empty()) return value; object = object->prototype(); - if (interpreter().exception()) + if (vm().exception()) return {}; } return {}; @@ -695,7 +695,7 @@ bool Object::put_by_index(u32 property_index, Value value) } } object = object->prototype(); - if (interpreter().exception()) + if (vm().exception()) return {}; } 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(); - if (interpreter().exception()) + if (vm().exception()) return false; } 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)); function->define_property("length", Value(length), Attribute::Configurable); - if (interpreter().exception()) + if (vm().exception()) return {}; function->define_property("name", js_string(heap(), function_name), Attribute::Configurable); - if (interpreter().exception()) + if (vm().exception()) return {}; 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)) return true; object = object->prototype(); - if (interpreter().exception()) + if (vm().exception()) return false; } return false; diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 35a7e00a1f..85fa50acc5 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -51,7 +51,7 @@ struct PropertyDescriptor { Function* getter { 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_data_descriptor() const { return !(value.is_empty() && !attributes.has_writable()); } diff --git a/Libraries/LibJS/Runtime/ProxyObject.cpp b/Libraries/LibJS/Runtime/ProxyObject.cpp index e63931bcbd..98318d1cb8 100644 --- a/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -81,7 +81,7 @@ Object* ProxyObject::prototype() return nullptr; } auto trap = m_handler.get("getPrototypeOf"); - if (interpreter().exception()) + if (vm().exception()) return nullptr; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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)); - if (interpreter().exception()) + if (vm().exception()) return nullptr; if (!trap_result.is_object() && !trap_result.is_null()) { interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfReturn); return nullptr; } if (m_target.is_extensible()) { - if (interpreter().exception()) + if (vm().exception()) return nullptr; if (trap_result.is_null()) return nullptr; return &trap_result.as_object(); } auto target_proto = m_target.prototype(); - if (interpreter().exception()) + if (vm().exception()) return nullptr; if (!same_value(interpreter(), trap_result, Value(target_proto))) { interpreter().throw_exception<TypeError>(ErrorType::ProxyGetPrototypeOfNonExtensible); @@ -130,7 +130,7 @@ bool ProxyObject::set_prototype(Object* object) return false; } auto trap = m_handler.get("setPrototypeOf"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception() || !trap_result) + if (vm().exception() || !trap_result) return false; if (m_target.is_extensible()) return true; auto* target_proto = m_target.prototype(); - if (interpreter().exception()) + if (vm().exception()) return false; if (!same_value(interpreter(), Value(object), Value(target_proto))) { interpreter().throw_exception<TypeError>(ErrorType::ProxySetPrototypeOfNonExtensible); @@ -161,7 +161,7 @@ bool ProxyObject::is_extensible() const return false; } auto trap = m_handler.get("isExtensible"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap_result != m_target.is_extensible()) { - if (!interpreter().exception()) + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyIsExtensibleReturn); return false; } @@ -188,7 +188,7 @@ bool ProxyObject::prevent_extensions() return false; } auto trap = m_handler.get("preventExtensions"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap_result && m_target.is_extensible()) { - if (!interpreter().exception()) + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyPreventExtensionsReturn); return false; } @@ -215,7 +215,7 @@ Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const Prop return {}; } auto trap = m_handler.get("getOwnPropertyDescriptor"); - if (interpreter().exception()) + if (vm().exception()) return {}; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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())); - if (interpreter().exception()) + if (vm().exception()) return {}; if (!trap_result.is_object() && !trap_result.is_undefined()) { interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorReturn); return {}; } auto target_desc = m_target.get_own_property_descriptor(name); - if (interpreter().exception()) + if (vm().exception()) return {}; if (trap_result.is_undefined()) { if (!target_desc.has_value()) @@ -242,17 +242,17 @@ Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const Prop return {}; } if (!m_target.is_extensible()) { - if (!interpreter().exception()) + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyGetOwnDescriptorUndefReturn); return {}; } return {}; } - auto result_desc = PropertyDescriptor::from_dictionary(interpreter(), trap_result.as_object()); - if (interpreter().exception()) + auto result_desc = PropertyDescriptor::from_dictionary(vm(), trap_result.as_object()); + if (vm().exception()) return {}; 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); return {}; } @@ -270,7 +270,7 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj return false; } auto trap = m_handler.get("defineProperty"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception() || !trap_result) + if (vm().exception() || !trap_result) return false; auto target_desc = m_target.get_own_property_descriptor(property_name); - if (interpreter().exception()) + if (vm().exception()) return false; bool setting_config_false = false; if (descriptor.has_property("configurable") && !descriptor.get("configurable").to_boolean()) setting_config_false = true; - if (interpreter().exception()) + if (vm().exception()) return false; if (!target_desc.has_value()) { if (!m_target.is_extensible()) { - if (!interpreter().exception()) + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropNonExtensible); return false; } @@ -301,8 +301,8 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj return false; } } else { - if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), PropertyDescriptor::from_dictionary(interpreter(), descriptor), target_desc)) { - if (!interpreter().exception()) + if (!is_compatible_property_descriptor(interpreter(), m_target.is_extensible(), PropertyDescriptor::from_dictionary(vm(), descriptor), target_desc)) { + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyDefinePropIncompatibleDescriptor); return false; } @@ -321,7 +321,7 @@ bool ProxyObject::has_property(const PropertyName& name) const return false; } auto trap = m_handler.get("has"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception()) + if (vm().exception()) return false; if (!trap_result) { auto target_desc = m_target.get_own_property_descriptor(name); - if (interpreter().exception()) + if (vm().exception()) return false; if (target_desc.has_value()) { if (!target_desc.value().attributes.is_configurable()) { @@ -343,7 +343,7 @@ bool ProxyObject::has_property(const PropertyName& name) const return false; } if (!m_target.is_extensible()) { - if (!interpreter().exception()) + if (!vm().exception()) interpreter().throw_exception<TypeError>(ErrorType::ProxyHasExistingNonExtensible); return false; } @@ -359,7 +359,7 @@ Value ProxyObject::get(const PropertyName& name, Value) const return {}; } auto trap = m_handler.get("get"); - if (interpreter().exception()) + if (vm().exception()) return {}; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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))); - if (interpreter().exception()) + if (vm().exception()) return {}; auto target_desc = m_target.get_own_property_descriptor(name); if (target_desc.has_value()) { - if (interpreter().exception()) + if (vm().exception()) return {}; 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); @@ -394,7 +394,7 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value) return false; } auto trap = m_handler.get("set"); - if (interpreter().exception()) + if (vm().exception()) return false; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) return m_target.put(name, value); @@ -403,10 +403,10 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value) 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(); - if (interpreter().exception() || !trap_result) + if (vm().exception() || !trap_result) return false; auto target_desc = m_target.get_own_property_descriptor(name); - if (interpreter().exception()) + if (vm().exception()) return false; 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)) { @@ -427,7 +427,7 @@ Value ProxyObject::delete_property(const PropertyName& name) return {}; } auto trap = m_handler.get("deleteProperty"); - if (interpreter().exception()) + if (vm().exception()) return {}; if (trap.is_empty() || trap.is_undefined() || trap.is_null()) 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(); - if (interpreter().exception()) + if (vm().exception()) return {}; if (!trap_result) return Value(false); auto target_desc = m_target.get_own_property_descriptor(name); - if (interpreter().exception()) + if (vm().exception()) return {}; if (!target_desc.has_value()) return Value(true); diff --git a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp index 318b983eaa..e6163f5923 100644 --- a/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp +++ b/Libraries/LibJS/Runtime/Uint8ClampedArray.cpp @@ -70,7 +70,7 @@ bool Uint8ClampedArray::put_by_index(u32 property_index, Value value) // FIXME: Use attributes ASSERT(property_index < m_length); auto number = value.to_i32(interpreter()); - if (interpreter().exception()) + if (vm().exception()) return {}; m_data[property_index] = clamp(number, 0, 255); return true; |