mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +00:00 
			
		
		
		
	LibJS: Replace boolean without_side_effects parameters with an enum
This commit is contained in:
		
							parent
							
								
									864beb0bd5
								
							
						
					
					
						commit
						dcb55db99b
					
				
					 16 changed files with 56 additions and 51 deletions
				
			
		|  | @ -101,7 +101,7 @@ SheetGlobalObject::~SheetGlobalObject() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JS::Value SheetGlobalObject::get(const JS::PropertyName& name, JS::Value receiver, bool without_side_effects) const | JS::Value SheetGlobalObject::get(const JS::PropertyName& name, JS::Value receiver, JS::AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     if (name.is_string()) { |     if (name.is_string()) { | ||||||
|         if (name.as_string() == "value") { |         if (name.as_string() == "value") { | ||||||
|  | @ -117,7 +117,7 @@ JS::Value SheetGlobalObject::get(const JS::PropertyName& name, JS::Value receive | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return GlobalObject::get(name, receiver, without_side_effects); |     return GlobalObject::get(name, receiver, allow_side_effects); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool SheetGlobalObject::put(const JS::PropertyName& name, JS::Value value, JS::Value receiver) | bool SheetGlobalObject::put(const JS::PropertyName& name, JS::Value value, JS::Value receiver) | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     virtual ~SheetGlobalObject() override; |     virtual ~SheetGlobalObject() override; | ||||||
| 
 | 
 | ||||||
|     virtual JS::Value get(const JS::PropertyName&, JS::Value receiver = {}, bool without_side_effects = false) const override; |     virtual JS::Value get(const JS::PropertyName&, JS::Value receiver = {}, JS::AllowSideEffects = JS::AllowSideEffects::Yes) const override; | ||||||
|     virtual bool put(const JS::PropertyName&, JS::Value value, JS::Value receiver = {}) override; |     virtual bool put(const JS::PropertyName&, JS::Value value, JS::Value receiver = {}) override; | ||||||
|     virtual void initialize_global_object() override; |     virtual void initialize_global_object() override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,16 +21,16 @@ DebuggerGlobalJSObject::DebuggerGlobalJSObject() | ||||||
|     m_variables = lib->debug_info->get_variables_in_current_scope(regs); |     m_variables = lib->debug_info->get_variables_in_current_scope(regs); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JS::Value DebuggerGlobalJSObject::get(const JS::PropertyName& name, JS::Value receiver, bool without_side_effects) const | JS::Value DebuggerGlobalJSObject::get(const JS::PropertyName& name, JS::Value receiver, JS::AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     if (m_variables.is_empty() || !name.is_string()) |     if (m_variables.is_empty() || !name.is_string()) | ||||||
|         return JS::Object::get(name, receiver, without_side_effects); |         return JS::Object::get(name, receiver, allow_side_effects); | ||||||
| 
 | 
 | ||||||
|     auto it = m_variables.find_if([&](auto& variable) { |     auto it = m_variables.find_if([&](auto& variable) { | ||||||
|         return variable->name == name.as_string(); |         return variable->name == name.as_string(); | ||||||
|     }); |     }); | ||||||
|     if (it.is_end()) |     if (it.is_end()) | ||||||
|         return JS::Object::get(name, receiver, without_side_effects); |         return JS::Object::get(name, receiver, allow_side_effects); | ||||||
|     auto& target_variable = **it; |     auto& target_variable = **it; | ||||||
|     auto js_value = debugger_to_js(target_variable); |     auto js_value = debugger_to_js(target_variable); | ||||||
|     if (js_value.has_value()) |     if (js_value.has_value()) | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ class DebuggerGlobalJSObject final | ||||||
| public: | public: | ||||||
|     DebuggerGlobalJSObject(); |     DebuggerGlobalJSObject(); | ||||||
| 
 | 
 | ||||||
|     JS::Value get(const JS::PropertyName& name, JS::Value receiver, bool without_side_effects) const override; |     JS::Value get(const JS::PropertyName& name, JS::Value receiver, JS::AllowSideEffects = JS::AllowSideEffects::Yes) const override; | ||||||
|     bool put(const JS::PropertyName& name, JS::Value value, JS::Value receiver) override; |     bool put(const JS::PropertyName& name, JS::Value value, JS::Value receiver) override; | ||||||
| 
 | 
 | ||||||
|     Optional<JS::Value> debugger_to_js(const Debug::DebugInfo::VariableInfo&) const; |     Optional<JS::Value> debugger_to_js(const Debug::DebugInfo::VariableInfo&) const; | ||||||
|  |  | ||||||
|  | @ -165,6 +165,11 @@ class TypedArrayPrototype; | ||||||
| // Tag type used to differentiate between u8 as used by Uint8Array and u8 as used by Uint8ClampedArray.
 | // Tag type used to differentiate between u8 as used by Uint8Array and u8 as used by Uint8ClampedArray.
 | ||||||
| struct ClampedU8; | struct ClampedU8; | ||||||
| 
 | 
 | ||||||
|  | enum class AllowSideEffects { | ||||||
|  |     Yes, | ||||||
|  |     No | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName, ArrayType) \ | #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName, ArrayType) \ | ||||||
|     class ClassName;                                                                     \ |     class ClassName;                                                                     \ | ||||||
|     class ConstructorName;                                                               \ |     class ConstructorName;                                                               \ | ||||||
|  |  | ||||||
|  | @ -207,10 +207,10 @@ bool IndexedPropertyIterator::operator!=(const IndexedPropertyIterator& other) c | ||||||
|     return m_index != other.m_index; |     return m_index != other.m_index; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ValueAndAttributes IndexedPropertyIterator::value_and_attributes(Object* this_object, bool evaluate_accessors) | ValueAndAttributes IndexedPropertyIterator::value_and_attributes(Object* this_object, AllowSideEffects allow_side_effects) | ||||||
| { | { | ||||||
|     if (m_index < m_indexed_properties.array_like_size()) |     if (m_index < m_indexed_properties.array_like_size()) | ||||||
|         return m_indexed_properties.get(this_object, m_index, evaluate_accessors).value_or({}); |         return m_indexed_properties.get(this_object, m_index, allow_side_effects).value_or({}); | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -226,10 +226,10 @@ void IndexedPropertyIterator::skip_empty_indices() | ||||||
|     m_index = m_indexed_properties.array_like_size(); |     m_index = m_indexed_properties.array_like_size(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Optional<ValueAndAttributes> IndexedProperties::get(Object* this_object, u32 index, bool evaluate_accessors) const | Optional<ValueAndAttributes> IndexedProperties::get(Object* this_object, u32 index, AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     auto result = m_storage->get(index); |     auto result = m_storage->get(index); | ||||||
|     if (!evaluate_accessors) |     if (allow_side_effects == AllowSideEffects::No) | ||||||
|         return result; |         return result; | ||||||
|     if (!result.has_value()) |     if (!result.has_value()) | ||||||
|         return {}; |         return {}; | ||||||
|  | @ -242,13 +242,13 @@ Optional<ValueAndAttributes> IndexedProperties::get(Object* this_object, u32 ind | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void IndexedProperties::put(Object* this_object, u32 index, Value value, PropertyAttributes attributes, bool evaluate_accessors) | void IndexedProperties::put(Object* this_object, u32 index, Value value, PropertyAttributes attributes, AllowSideEffects allow_side_effects) | ||||||
| { | { | ||||||
|     if (m_storage->is_simple_storage() && (attributes != default_attributes || index > (array_like_size() + SPARSE_ARRAY_HOLE_THRESHOLD))) { |     if (m_storage->is_simple_storage() && (attributes != default_attributes || index > (array_like_size() + SPARSE_ARRAY_HOLE_THRESHOLD))) { | ||||||
|         switch_to_generic_storage(); |         switch_to_generic_storage(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (m_storage->is_simple_storage() || !evaluate_accessors) { |     if (m_storage->is_simple_storage() || allow_side_effects == AllowSideEffects::No) { | ||||||
|         m_storage->put(index, value, attributes); |         m_storage->put(index, value, attributes); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -104,7 +104,7 @@ public: | ||||||
|     bool operator!=(const IndexedPropertyIterator&) const; |     bool operator!=(const IndexedPropertyIterator&) const; | ||||||
| 
 | 
 | ||||||
|     u32 index() const { return m_index; }; |     u32 index() const { return m_index; }; | ||||||
|     ValueAndAttributes value_and_attributes(Object* this_object, bool evaluate_accessors = true); |     ValueAndAttributes value_and_attributes(Object* this_object, AllowSideEffects = AllowSideEffects::Yes); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     void skip_empty_indices(); |     void skip_empty_indices(); | ||||||
|  | @ -124,15 +124,15 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     bool has_index(u32 index) const { return m_storage->has_index(index); } |     bool has_index(u32 index) const { return m_storage->has_index(index); } | ||||||
|     Optional<ValueAndAttributes> get(Object* this_object, u32 index, bool evaluate_accessors = true) const; |     Optional<ValueAndAttributes> get(Object* this_object, u32 index, AllowSideEffects = AllowSideEffects::Yes) const; | ||||||
|     void put(Object* this_object, u32 index, Value value, PropertyAttributes attributes = default_attributes, bool evaluate_accessors = true); |     void put(Object* this_object, u32 index, Value value, PropertyAttributes attributes = default_attributes, AllowSideEffects allow_side_effects = AllowSideEffects::Yes); | ||||||
|     bool remove(u32 index); |     bool remove(u32 index); | ||||||
| 
 | 
 | ||||||
|     void insert(u32 index, Value value, PropertyAttributes attributes = default_attributes); |     void insert(u32 index, Value value, PropertyAttributes attributes = default_attributes); | ||||||
|     ValueAndAttributes take_first(Object* this_object); |     ValueAndAttributes take_first(Object* this_object); | ||||||
|     ValueAndAttributes take_last(Object* this_object); |     ValueAndAttributes take_last(Object* this_object); | ||||||
| 
 | 
 | ||||||
|     void append(Value value, PropertyAttributes attributes = default_attributes) { put(nullptr, array_like_size(), value, attributes, false); } |     void append(Value value, PropertyAttributes attributes = default_attributes) { put(nullptr, array_like_size(), value, attributes, AllowSideEffects::No); } | ||||||
| 
 | 
 | ||||||
|     IndexedPropertyIterator begin(bool skip_empty = true) const { return IndexedPropertyIterator(*this, 0, skip_empty); }; |     IndexedPropertyIterator begin(bool skip_empty = true) const { return IndexedPropertyIterator(*this, 0, skip_empty); }; | ||||||
|     IndexedPropertyIterator end() const { return IndexedPropertyIterator(*this, array_like_size(), false); }; |     IndexedPropertyIterator end() const { return IndexedPropertyIterator(*this, array_like_size(), false); }; | ||||||
|  |  | ||||||
|  | @ -169,10 +169,10 @@ bool Object::set_integrity_level(IntegrityLevel level) | ||||||
|     // FIXME: This feels clunky and should get nicer abstractions.
 |     // FIXME: This feels clunky and should get nicer abstractions.
 | ||||||
|     auto update_property = [this](auto& property_name, auto new_attributes) { |     auto update_property = [this](auto& property_name, auto new_attributes) { | ||||||
|         if (property_name.is_number()) { |         if (property_name.is_number()) { | ||||||
|             auto value_and_attributes = m_indexed_properties.get(nullptr, property_name.as_number(), false).value(); |             auto value_and_attributes = m_indexed_properties.get(nullptr, property_name.as_number(), AllowSideEffects::No).value(); | ||||||
|             auto value = value_and_attributes.value; |             auto value = value_and_attributes.value; | ||||||
|             auto attributes = value_and_attributes.attributes.bits() & new_attributes; |             auto attributes = value_and_attributes.attributes.bits() & new_attributes; | ||||||
|             m_indexed_properties.put(nullptr, property_name.as_number(), value, attributes, false); |             m_indexed_properties.put(nullptr, property_name.as_number(), value, attributes, AllowSideEffects::No); | ||||||
|         } else { |         } else { | ||||||
|             auto metadata = shape().lookup(property_name.to_string_or_symbol()).value(); |             auto metadata = shape().lookup(property_name.to_string_or_symbol()).value(); | ||||||
|             auto attributes = metadata.attributes.bits() & new_attributes; |             auto attributes = metadata.attributes.bits() & new_attributes; | ||||||
|  | @ -248,7 +248,7 @@ bool Object::test_integrity_level(IntegrityLevel level) | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Value Object::get_own_property(const PropertyName& property_name, Value receiver, bool without_side_effects) const | Value Object::get_own_property(const PropertyName& property_name, Value receiver, AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     VERIFY(property_name.is_valid()); |     VERIFY(property_name.is_valid()); | ||||||
|     VERIFY(!receiver.is_empty()); |     VERIFY(!receiver.is_empty()); | ||||||
|  | @ -256,7 +256,7 @@ Value Object::get_own_property(const PropertyName& property_name, Value receiver | ||||||
|     Value value_here; |     Value value_here; | ||||||
| 
 | 
 | ||||||
|     if (property_name.is_number()) { |     if (property_name.is_number()) { | ||||||
|         auto existing_property = m_indexed_properties.get(nullptr, property_name.as_number(), false); |         auto existing_property = m_indexed_properties.get(nullptr, property_name.as_number(), AllowSideEffects::No); | ||||||
|         if (!existing_property.has_value()) |         if (!existing_property.has_value()) | ||||||
|             return {}; |             return {}; | ||||||
|         value_here = existing_property.value().value.value_or(js_undefined()); |         value_here = existing_property.value().value.value_or(js_undefined()); | ||||||
|  | @ -268,7 +268,7 @@ Value Object::get_own_property(const PropertyName& property_name, Value receiver | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     VERIFY(!value_here.is_empty()); |     VERIFY(!value_here.is_empty()); | ||||||
|     if (!without_side_effects) { |     if (allow_side_effects == AllowSideEffects::Yes) { | ||||||
|         if (value_here.is_accessor()) |         if (value_here.is_accessor()) | ||||||
|             return value_here.as_accessor().call_getter(receiver); |             return value_here.as_accessor().call_getter(receiver); | ||||||
|         if (value_here.is_native_property()) |         if (value_here.is_native_property()) | ||||||
|  | @ -379,7 +379,7 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN | ||||||
|     PropertyAttributes attributes; |     PropertyAttributes attributes; | ||||||
| 
 | 
 | ||||||
|     if (property_name.is_number()) { |     if (property_name.is_number()) { | ||||||
|         auto existing_value = m_indexed_properties.get(nullptr, property_name.as_number(), false); |         auto existing_value = m_indexed_properties.get(nullptr, property_name.as_number(), AllowSideEffects::No); | ||||||
|         if (!existing_value.has_value()) |         if (!existing_value.has_value()) | ||||||
|             return {}; |             return {}; | ||||||
|         value = existing_value.value().value; |         value = existing_value.value().value; | ||||||
|  | @ -579,7 +579,7 @@ bool Object::define_accessor(const PropertyName& property_name, Function* getter | ||||||
| { | { | ||||||
|     VERIFY(property_name.is_valid()); |     VERIFY(property_name.is_valid()); | ||||||
| 
 | 
 | ||||||
|     auto existing_property = get_own_property(property_name, this, true); |     auto existing_property = get_own_property(property_name, this, AllowSideEffects::No); | ||||||
|     auto* accessor = existing_property.is_accessor() ? &existing_property.as_accessor() : nullptr; |     auto* accessor = existing_property.is_accessor() ? &existing_property.as_accessor() : nullptr; | ||||||
|     if (!accessor) { |     if (!accessor) { | ||||||
|         accessor = Accessor::create(vm(), getter, setter); |         accessor = Accessor::create(vm(), getter, setter); | ||||||
|  | @ -712,7 +712,7 @@ bool Object::put_own_property_by_index(u32 property_index, Value value, Property | ||||||
| { | { | ||||||
|     VERIFY(!(mode == PutOwnPropertyMode::Put && value.is_accessor())); |     VERIFY(!(mode == PutOwnPropertyMode::Put && value.is_accessor())); | ||||||
| 
 | 
 | ||||||
|     auto existing_property = m_indexed_properties.get(nullptr, property_index, false); |     auto existing_property = m_indexed_properties.get(nullptr, property_index, AllowSideEffects::No); | ||||||
|     auto new_property = !existing_property.has_value(); |     auto new_property = !existing_property.has_value(); | ||||||
| 
 | 
 | ||||||
|     if (!is_extensible() && new_property) { |     if (!is_extensible() && new_property) { | ||||||
|  | @ -751,7 +751,7 @@ bool Object::put_own_property_by_index(u32 property_index, Value value, Property | ||||||
|     if (value_here.is_native_property()) { |     if (value_here.is_native_property()) { | ||||||
|         call_native_property_setter(value_here.as_native_property(), this, value); |         call_native_property_setter(value_here.as_native_property(), this, value); | ||||||
|     } else { |     } else { | ||||||
|         m_indexed_properties.put(this, property_index, value, attributes, mode == PutOwnPropertyMode::Put); |         m_indexed_properties.put(this, property_index, value, attributes, mode == PutOwnPropertyMode::Put ? AllowSideEffects::Yes : AllowSideEffects::No); | ||||||
|     } |     } | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
|  | @ -789,7 +789,7 @@ void Object::ensure_shape_is_unique() | ||||||
|     m_shape = m_shape->create_unique_clone(); |     m_shape = m_shape->create_unique_clone(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Value Object::get_by_index(u32 property_index, bool without_side_effects) const | Value Object::get_by_index(u32 property_index, AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     const Object* object = this; |     const Object* object = this; | ||||||
|     while (object) { |     while (object) { | ||||||
|  | @ -798,7 +798,7 @@ Value Object::get_by_index(u32 property_index, bool without_side_effects) const | ||||||
|             if (property_index < string.length()) |             if (property_index < string.length()) | ||||||
|                 return js_string(heap(), string.substring(property_index, 1)); |                 return js_string(heap(), string.substring(property_index, 1)); | ||||||
|         } else if (static_cast<size_t>(property_index) < object->m_indexed_properties.array_like_size()) { |         } else 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, !without_side_effects); |             auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index, allow_side_effects); | ||||||
|             if (vm().exception()) |             if (vm().exception()) | ||||||
|                 return {}; |                 return {}; | ||||||
|             if (result.has_value() && !result.value().value.is_empty()) |             if (result.has_value() && !result.value().value.is_empty()) | ||||||
|  | @ -811,19 +811,19 @@ Value Object::get_by_index(u32 property_index, bool without_side_effects) const | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Value Object::get(const PropertyName& property_name, Value receiver, bool without_side_effects) const | Value Object::get(const PropertyName& property_name, Value receiver, AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     VERIFY(property_name.is_valid()); |     VERIFY(property_name.is_valid()); | ||||||
| 
 | 
 | ||||||
|     if (property_name.is_number()) |     if (property_name.is_number()) | ||||||
|         return get_by_index(property_name.as_number(), without_side_effects); |         return get_by_index(property_name.as_number(), allow_side_effects); | ||||||
| 
 | 
 | ||||||
|     if (receiver.is_empty()) |     if (receiver.is_empty()) | ||||||
|         receiver = Value(this); |         receiver = Value(this); | ||||||
| 
 | 
 | ||||||
|     const Object* object = this; |     const Object* object = this; | ||||||
|     while (object) { |     while (object) { | ||||||
|         auto value = object->get_own_property(property_name, receiver, without_side_effects); |         auto value = object->get_own_property(property_name, receiver, allow_side_effects); | ||||||
|         if (vm().exception()) |         if (vm().exception()) | ||||||
|             return {}; |             return {}; | ||||||
|         if (!value.is_empty()) |         if (!value.is_empty()) | ||||||
|  | @ -838,7 +838,7 @@ Value Object::get(const PropertyName& property_name, Value receiver, bool withou | ||||||
| Value Object::get_without_side_effects(const PropertyName& property_name) const | Value Object::get_without_side_effects(const PropertyName& property_name) const | ||||||
| { | { | ||||||
|     TemporaryClearException clear_exception(vm()); |     TemporaryClearException clear_exception(vm()); | ||||||
|     return get(property_name, {}, true); |     return get(property_name, {}, AllowSideEffects::No); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool Object::put_by_index(u32 property_index, Value value) | bool Object::put_by_index(u32 property_index, Value value) | ||||||
|  | @ -849,7 +849,7 @@ bool Object::put_by_index(u32 property_index, Value value) | ||||||
|     // Otherwise, it goes in the own property storage.
 |     // Otherwise, it goes in the own property storage.
 | ||||||
|     Object* object = this; |     Object* object = this; | ||||||
|     while (object) { |     while (object) { | ||||||
|         auto existing_value = object->m_indexed_properties.get(nullptr, property_index, false); |         auto existing_value = object->m_indexed_properties.get(nullptr, property_index, AllowSideEffects::No); | ||||||
|         if (existing_value.has_value()) { |         if (existing_value.has_value()) { | ||||||
|             auto value_here = existing_value.value(); |             auto value_here = existing_value.value(); | ||||||
|             if (value_here.value.is_accessor()) { |             if (value_here.value.is_accessor()) { | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     GlobalObject& global_object() const { return *shape().global_object(); } |     GlobalObject& global_object() const { return *shape().global_object(); } | ||||||
| 
 | 
 | ||||||
|     virtual Value get(const PropertyName&, Value receiver = {}, bool without_side_effects = false) const; |     virtual Value get(const PropertyName&, Value receiver = {}, AllowSideEffects = AllowSideEffects::Yes) const; | ||||||
|     Value get_without_side_effects(const PropertyName&) const; |     Value get_without_side_effects(const PropertyName&) const; | ||||||
| 
 | 
 | ||||||
|     virtual bool has_property(const PropertyName&) const; |     virtual bool has_property(const PropertyName&) const; | ||||||
|  | @ -82,7 +82,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     virtual bool put(const PropertyName&, Value, Value receiver = {}); |     virtual bool put(const PropertyName&, Value, Value receiver = {}); | ||||||
| 
 | 
 | ||||||
|     Value get_own_property(const PropertyName&, Value receiver, bool without_side_effects = false) const; |     Value get_own_property(const PropertyName&, Value receiver, AllowSideEffects = AllowSideEffects::Yes) const; | ||||||
|     MarkedValueList get_own_properties(PropertyKind, bool only_enumerable_properties = false, GetOwnPropertyReturnType = GetOwnPropertyReturnType::All) const; |     MarkedValueList get_own_properties(PropertyKind, bool only_enumerable_properties = false, GetOwnPropertyReturnType = GetOwnPropertyReturnType::All) const; | ||||||
|     MarkedValueList get_enumerable_own_property_names(PropertyKind) const; |     MarkedValueList get_enumerable_own_property_names(PropertyKind) const; | ||||||
|     virtual Optional<PropertyDescriptor> get_own_property_descriptor(const PropertyName&) const; |     virtual Optional<PropertyDescriptor> get_own_property_descriptor(const PropertyName&) const; | ||||||
|  | @ -163,7 +163,7 @@ protected: | ||||||
|     explicit Object(GlobalObjectTag); |     explicit Object(GlobalObjectTag); | ||||||
|     Object(ConstructWithoutPrototypeTag, GlobalObject&); |     Object(ConstructWithoutPrototypeTag, GlobalObject&); | ||||||
| 
 | 
 | ||||||
|     virtual Value get_by_index(u32 property_index, bool without_side_effects = false) const; |     virtual Value get_by_index(u32 property_index, AllowSideEffects = AllowSideEffects::Yes) const; | ||||||
|     virtual bool put_by_index(u32 property_index, Value); |     virtual bool put_by_index(u32 property_index, Value); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -305,10 +305,10 @@ bool ProxyObject::has_property(const PropertyName& name) const | ||||||
|     return trap_result.to_boolean(); |     return trap_result.to_boolean(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Value ProxyObject::get(const PropertyName& name, Value receiver, bool without_side_effects) const | Value ProxyObject::get(const PropertyName& name, Value receiver, AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     auto& vm = this->vm(); |     auto& vm = this->vm(); | ||||||
|     if (without_side_effects) { |     if (allow_side_effects == AllowSideEffects::No) { | ||||||
|         // Sorry, we're not going to call anything on this proxy.
 |         // Sorry, we're not going to call anything on this proxy.
 | ||||||
|         return js_string(vm, "<ProxyObject>"); |         return js_string(vm, "<ProxyObject>"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -35,7 +35,7 @@ public: | ||||||
|     virtual Optional<PropertyDescriptor> get_own_property_descriptor(const PropertyName&) const override; |     virtual Optional<PropertyDescriptor> get_own_property_descriptor(const PropertyName&) const override; | ||||||
|     virtual bool define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions = true) override; |     virtual bool define_property(const StringOrSymbol& property_name, const Object& descriptor, bool throw_exceptions = true) override; | ||||||
|     virtual bool has_property(const PropertyName& name) const override; |     virtual bool has_property(const PropertyName& name) const override; | ||||||
|     virtual Value get(const PropertyName& name, Value receiver, bool without_side_effects = false) const override; |     virtual Value get(const PropertyName& name, Value receiver, AllowSideEffects = AllowSideEffects::Yes) const override; | ||||||
|     virtual bool put(const PropertyName& name, Value value, Value receiver) override; |     virtual bool put(const PropertyName& name, Value value, Value receiver) override; | ||||||
|     virtual bool delete_property(const PropertyName& name) override; |     virtual bool delete_property(const PropertyName& name) override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -67,9 +67,9 @@ void StringPrototype::initialize(GlobalObject& global_object) | ||||||
|     define_native_function(vm.names.padEnd, pad_end, 1, attr); |     define_native_function(vm.names.padEnd, pad_end, 1, attr); | ||||||
|     define_native_function(vm.names.trim, trim, 0, attr); |     define_native_function(vm.names.trim, trim, 0, attr); | ||||||
|     define_native_function(vm.names.trimStart, trim_start, 0, attr); |     define_native_function(vm.names.trimStart, trim_start, 0, attr); | ||||||
|     define_property(vm.names.trimLeft, get(vm.names.trimStart, {}, true), attr); |     define_property(vm.names.trimLeft, get_without_side_effects(vm.names.trimStart), attr); | ||||||
|     define_native_function(vm.names.trimEnd, trim_end, 0, attr); |     define_native_function(vm.names.trimEnd, trim_end, 0, attr); | ||||||
|     define_property(vm.names.trimRight, get(vm.names.trimEnd, {}, true), attr); |     define_property(vm.names.trimRight, get_without_side_effects(vm.names.trimEnd), attr); | ||||||
|     define_native_function(vm.names.concat, concat, 1, attr); |     define_native_function(vm.names.concat, concat, 1, attr); | ||||||
|     define_native_function(vm.names.substr, substr, 2, attr); |     define_native_function(vm.names.substr, substr, 2, attr); | ||||||
|     define_native_function(vm.names.substring, substring, 2, attr); |     define_native_function(vm.names.substring, substring, 2, attr); | ||||||
|  |  | ||||||
|  | @ -80,7 +80,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // 10.4.5.10 IntegerIndexedElementGet ( O, index ), https://tc39.es/ecma262/#sec-integerindexedelementget
 |     // 10.4.5.10 IntegerIndexedElementGet ( O, index ), https://tc39.es/ecma262/#sec-integerindexedelementget
 | ||||||
|     virtual Value get_by_index(u32 property_index, [[maybe_unused]] bool without_side_effects = false) const override |     virtual Value get_by_index(u32 property_index, AllowSideEffects = AllowSideEffects::Yes) const override | ||||||
|     { |     { | ||||||
|         if (!is_valid_integer_index(property_index)) |         if (!is_valid_integer_index(property_index)) | ||||||
|             return js_undefined(); |             return js_undefined(); | ||||||
|  |  | ||||||
|  | @ -11,12 +11,12 @@ | ||||||
| 
 | 
 | ||||||
| namespace Web::Bindings { | namespace Web::Bindings { | ||||||
| 
 | 
 | ||||||
| JS::Value CSSStyleDeclarationWrapper::get(const JS::PropertyName& name, JS::Value receiver, bool without_side_effects) const | JS::Value CSSStyleDeclarationWrapper::get(const JS::PropertyName& name, JS::Value receiver, JS::AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     // FIXME: These should actually use camelCase versions of the property names!
 |     // FIXME: These should actually use camelCase versions of the property names!
 | ||||||
|     auto property_id = CSS::property_id_from_string(name.to_string()); |     auto property_id = CSS::property_id_from_string(name.to_string()); | ||||||
|     if (property_id == CSS::PropertyID::Invalid) |     if (property_id == CSS::PropertyID::Invalid) | ||||||
|         return Base::get(name, receiver, without_side_effects); |         return Base::get(name, receiver, allow_side_effects); | ||||||
|     for (auto& property : impl().properties()) { |     for (auto& property : impl().properties()) { | ||||||
|         if (property.property_id == property_id) |         if (property.property_id == property_id) | ||||||
|             return js_string(vm(), property.value->to_string()); |             return js_string(vm(), property.value->to_string()); | ||||||
|  |  | ||||||
|  | @ -12,21 +12,21 @@ | ||||||
| 
 | 
 | ||||||
| namespace Web::Bindings { | namespace Web::Bindings { | ||||||
| 
 | 
 | ||||||
| JS::Value HTMLCollectionWrapper::get(JS::PropertyName const& name, JS::Value receiver, bool without_side_effects) const | JS::Value HTMLCollectionWrapper::get(JS::PropertyName const& name, JS::Value receiver, JS::AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     if (!name.is_string()) |     if (!name.is_string()) | ||||||
|         return Base::get(name, receiver, without_side_effects); |         return Base::get(name, receiver, allow_side_effects); | ||||||
|     auto* item = const_cast<DOM::HTMLCollection&>(impl()).named_item(name.to_string()); |     auto* item = const_cast<DOM::HTMLCollection&>(impl()).named_item(name.to_string()); | ||||||
|     if (!item) |     if (!item) | ||||||
|         return Base::get(name, receiver, without_side_effects); |         return Base::get(name, receiver, allow_side_effects); | ||||||
|     return JS::Value { wrap(global_object(), *item) }; |     return JS::Value { wrap(global_object(), *item) }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index, bool without_side_effects) const | JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index, JS::AllowSideEffects allow_side_effects) const | ||||||
| { | { | ||||||
|     auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index); |     auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index); | ||||||
|     if (!item) |     if (!item) | ||||||
|         return Base::get_by_index(property_index, without_side_effects); |         return Base::get_by_index(property_index, allow_side_effects); | ||||||
|     return wrap(global_object(), *item); |     return wrap(global_object(), *item); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -786,12 +786,12 @@ public: | ||||||
| 
 | 
 | ||||||
|     if (interface.extended_attributes.contains("CustomGet")) { |     if (interface.extended_attributes.contains("CustomGet")) { | ||||||
|         generator.append(R"~~~( |         generator.append(R"~~~( | ||||||
|     virtual JS::Value get(const JS::PropertyName&, JS::Value receiver = {}, bool without_side_effects = false) const override; |     virtual JS::Value get(const JS::PropertyName&, JS::Value receiver = {}, JS::AllowSideEffects = JS::AllowSideEffects::Yes) const override; | ||||||
| )~~~"); | )~~~"); | ||||||
|     } |     } | ||||||
|     if (interface.extended_attributes.contains("CustomGetByIndex")) { |     if (interface.extended_attributes.contains("CustomGetByIndex")) { | ||||||
|         generator.append(R"~~~( |         generator.append(R"~~~( | ||||||
|     virtual JS::Value get_by_index(u32 property_index, bool without_side_effects = false) const override; |     virtual JS::Value get_by_index(u32 property_index, JS::AllowSideEffects = JS::AllowSideEffects::Yes) const override; | ||||||
| )~~~"); | )~~~"); | ||||||
|     } |     } | ||||||
|     if (interface.extended_attributes.contains("CustomPut")) { |     if (interface.extended_attributes.contains("CustomPut")) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Idan Horowitz
						Idan Horowitz