From d878975f95fa0d4d3e23044cc4a5c28c0941f709 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 28 Feb 2024 13:08:15 -0500 Subject: [PATCH] AK+LibJS: Remove OFFSET_OF and its users With the LibJS JIT removed, let's not expose pointers to internal members. --- AK/Optional.h | 3 --- AK/StdLibExtras.h | 2 -- AK/Vector.h | 2 -- AK/Weakable.h | 2 -- Userland/Libraries/LibJS/Bytecode/Executable.h | 5 ----- Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h | 6 ------ Userland/Libraries/LibJS/Runtime/Environment.h | 3 --- Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h | 3 --- Userland/Libraries/LibJS/Runtime/ExecutionContext.h | 4 ---- Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h | 3 --- Userland/Libraries/LibJS/Runtime/IndexedProperties.h | 7 ------- Userland/Libraries/LibJS/Runtime/Object.h | 8 -------- Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h | 2 -- Userland/Libraries/LibJS/Runtime/Realm.h | 3 --- 14 files changed, 53 deletions(-) diff --git a/AK/Optional.h b/AK/Optional.h index 7f96e3a831..3e3950eb6b 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -318,9 +318,6 @@ public: } } - static FlatPtr value_offset() { return OFFSET_OF(Optional, m_storage); } - static FlatPtr has_value_offset() { return OFFSET_OF(Optional, m_has_value); } - private: alignas(T) u8 m_storage[sizeof(T)]; bool m_has_value { false }; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 84fb6034ca..57c986c67c 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -16,8 +16,6 @@ #include -#define OFFSET_OF(class, member) __builtin_offsetof(class, member) - namespace AK { template diff --git a/AK/Vector.h b/AK/Vector.h index 52f73c4946..52db632ce1 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -811,8 +811,6 @@ public: AK::swap(at(i), at(size() - i - 1)); } - static FlatPtr outline_buffer_offset() { return OFFSET_OF(Vector, m_outline_buffer); } - private: void reset_capacity() { diff --git a/AK/Weakable.h b/AK/Weakable.h index 8f841a4df6..38999445f1 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -42,8 +42,6 @@ public: void revoke() { m_ptr = nullptr; } - static FlatPtr ptr_offset() { return OFFSET_OF(WeakLink, m_ptr); } - private: template explicit WeakLink(T& weakable) diff --git a/Userland/Libraries/LibJS/Bytecode/Executable.h b/Userland/Libraries/LibJS/Bytecode/Executable.h index b69b1167e3..d31f414d58 100644 --- a/Userland/Libraries/LibJS/Bytecode/Executable.h +++ b/Userland/Libraries/LibJS/Bytecode/Executable.h @@ -22,16 +22,11 @@ namespace JS::Bytecode { struct PropertyLookupCache { - static FlatPtr shape_offset() { return OFFSET_OF(PropertyLookupCache, shape); } - static FlatPtr property_offset_offset() { return OFFSET_OF(PropertyLookupCache, property_offset); } - WeakPtr shape; Optional property_offset; }; struct GlobalVariableCache : public PropertyLookupCache { - static FlatPtr environment_serial_number_offset() { return OFFSET_OF(GlobalVariableCache, environment_serial_number); } - u64 environment_serial_number { 0 }; }; diff --git a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h index dc89bb11dd..b1d922e826 100644 --- a/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h @@ -20,9 +20,6 @@ class DeclarativeEnvironment : public Environment { JS_DECLARE_ALLOCATOR(DeclarativeEnvironment); struct Binding { - static FlatPtr value_offset() { return OFFSET_OF(Binding, value); } - static FlatPtr initialized_offset() { return OFFSET_OF(Binding, initialized); } - DeprecatedFlyString name; Value value; bool strict { false }; @@ -71,9 +68,6 @@ public: [[nodiscard]] u64 environment_serial_number() const { return m_environment_serial_number; } - static FlatPtr bindings_offset() { return OFFSET_OF(DeclarativeEnvironment, m_bindings); } - static FlatPtr environment_serial_number_offset() { return OFFSET_OF(DeclarativeEnvironment, m_environment_serial_number); } - private: ThrowCompletionOr get_binding_value_direct(VM&, Binding&, bool strict); ThrowCompletionOr set_mutable_binding_direct(VM&, Binding&, Value, bool strict); diff --git a/Userland/Libraries/LibJS/Runtime/Environment.h b/Userland/Libraries/LibJS/Runtime/Environment.h index 481ff52595..480057abca 100644 --- a/Userland/Libraries/LibJS/Runtime/Environment.h +++ b/Userland/Libraries/LibJS/Runtime/Environment.h @@ -57,9 +57,6 @@ public: bool is_permanently_screwed_by_eval() const { return m_permanently_screwed_by_eval; } void set_permanently_screwed_by_eval(); - static FlatPtr is_permanently_screwed_by_eval_offset() { return OFFSET_OF(Environment, m_permanently_screwed_by_eval); } - static FlatPtr outer_environment_offset() { return OFFSET_OF(Environment, m_outer_environment); } - protected: explicit Environment(Environment* parent); diff --git a/Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h b/Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h index 45f6d62be2..7f2cc9c354 100644 --- a/Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h +++ b/Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h @@ -15,9 +15,6 @@ struct EnvironmentCoordinate { u32 hops { invalid_marker }; u32 index { invalid_marker }; - static FlatPtr hops_offset() { return OFFSET_OF(EnvironmentCoordinate, hops); } - static FlatPtr index_offset() { return OFFSET_OF(EnvironmentCoordinate, index); } - bool is_valid() const { return hops != invalid_marker && index != invalid_marker; } static constexpr u32 invalid_marker = 0xfffffffe; diff --git a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h index f157d3eeb8..43df15c60a 100644 --- a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h +++ b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h @@ -30,10 +30,6 @@ struct ExecutionContext { void visit_edges(Cell::Visitor&); - static FlatPtr realm_offset() { return OFFSET_OF(ExecutionContext, realm); } - static FlatPtr lexical_environment_offset() { return OFFSET_OF(ExecutionContext, lexical_environment); } - static FlatPtr variable_environment_offset() { return OFFSET_OF(ExecutionContext, variable_environment); } - private: ExecutionContext(Heap&); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h index 634f8a2f48..7bda97591e 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h @@ -38,9 +38,6 @@ public: ThrowCompletionOr create_global_var_binding(DeprecatedFlyString const& name, bool can_be_deleted); ThrowCompletionOr create_global_function_binding(DeprecatedFlyString const& name, Value, bool can_be_deleted); - static FlatPtr object_record_offset() { return OFFSET_OF(GlobalEnvironment, m_object_record); } - static FlatPtr declarative_record_offset() { return OFFSET_OF(GlobalEnvironment, m_declarative_record); } - private: GlobalEnvironment(Object&, Object& this_value); diff --git a/Userland/Libraries/LibJS/Runtime/IndexedProperties.h b/Userland/Libraries/LibJS/Runtime/IndexedProperties.h index 2561c84b44..cc895c4d69 100644 --- a/Userland/Libraries/LibJS/Runtime/IndexedProperties.h +++ b/Userland/Libraries/LibJS/Runtime/IndexedProperties.h @@ -46,8 +46,6 @@ public: bool is_simple_storage() const { return m_is_simple_storage; } - static FlatPtr is_simple_storage_offset() { return OFFSET_OF(IndexedPropertyStorage, m_is_simple_storage); } - protected: explicit IndexedPropertyStorage(IsSimpleStorage is_simple_storage) : m_is_simple_storage(is_simple_storage == IsSimpleStorage::Yes) {}; @@ -76,9 +74,6 @@ public: Vector const& elements() const { return m_packed_elements; } - static FlatPtr array_size_offset() { return OFFSET_OF(SimpleIndexedPropertyStorage, m_array_size); } - static FlatPtr elements_offset() { return OFFSET_OF(SimpleIndexedPropertyStorage, m_packed_elements); } - private: friend GenericIndexedPropertyStorage; @@ -177,8 +172,6 @@ public: } } - static FlatPtr storage_offset() { return OFFSET_OF(IndexedProperties, m_storage); } - private: void switch_to_generic_storage(); void ensure_storage(); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 757d7ee031..193200541d 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -204,8 +204,6 @@ public: Value get_direct(size_t index) const { return m_storage[index]; } void put_direct(size_t index, Value value) { m_storage[index] = value; } - static FlatPtr storage_offset() { return OFFSET_OF(Object, m_storage); } - IndexedProperties const& indexed_properties() const { return m_indexed_properties; } IndexedProperties& indexed_properties() { return m_indexed_properties; } void set_indexed_property_elements(Vector&& values) { m_indexed_properties = IndexedProperties(move(values)); } @@ -213,18 +211,12 @@ public: Shape& shape() { return *m_shape; } Shape const& shape() const { return *m_shape; } - static FlatPtr shape_offset() { return OFFSET_OF(Object, m_shape); } - template bool fast_is() const = delete; void set_prototype(Object*); - static FlatPtr may_interfere_with_indexed_property_access_offset() { return OFFSET_OF(Object, m_may_interfere_with_indexed_property_access); } - static FlatPtr indexed_properties_offset() { return OFFSET_OF(Object, m_indexed_properties); } - [[nodiscard]] bool has_magical_length_property() const { return m_has_magical_length_property; } - static FlatPtr has_magical_length_property_offset() { return OFFSET_OF(Object, m_has_magical_length_property); } [[nodiscard]] bool is_typed_array() const { return m_is_typed_array; } void set_is_typed_array() { m_is_typed_array = true; } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h index f126a1d1fd..2093b3d94c 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h @@ -42,8 +42,6 @@ public: // [[IsWithEnvironment]], Indicates whether this Environment Record is created for a with statement. bool is_with_environment() const { return m_with_environment; } - static FlatPtr binding_object_offset() { return OFFSET_OF(ObjectEnvironment, m_binding_object); } - private: ObjectEnvironment(Object& binding_object, IsWithEnvironment, Environment* outer_environment); diff --git a/Userland/Libraries/LibJS/Runtime/Realm.h b/Userland/Libraries/LibJS/Runtime/Realm.h index bf362a9188..9252e50184 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.h +++ b/Userland/Libraries/LibJS/Runtime/Realm.h @@ -62,9 +62,6 @@ public: return *m_builtins[to_underlying(builtin)]; } - static FlatPtr global_environment_offset() { return OFFSET_OF(Realm, m_global_environment); } - static FlatPtr builtins_offset() { return OFFSET_OF(Realm, m_builtins); } - private: Realm() = default;