Skip to content

Commit

Permalink
AK+LibJS: Remove OFFSET_OF and its users
Browse files Browse the repository at this point in the history
With the LibJS JIT removed, let's not expose pointers to internal
members.
  • Loading branch information
trflynn89 authored and awesomekling committed Feb 29, 2024
1 parent 4646a87 commit d878975
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 53 deletions.
3 changes: 0 additions & 3 deletions AK/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,6 @@ requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
}
}

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 };
Expand Down
2 changes: 0 additions & 2 deletions AK/StdLibExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <AK/Assertions.h>

#define OFFSET_OF(class, member) __builtin_offsetof(class, member)

namespace AK {

template<typename T, typename U>
Expand Down
2 changes: 0 additions & 2 deletions AK/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,6 @@ requires(!IsRvalueReference<T>) class Vector {
AK::swap(at(i), at(size() - i - 1));
}

static FlatPtr outline_buffer_offset() { return OFFSET_OF(Vector, m_outline_buffer); }

private:
void reset_capacity()
{
Expand Down
2 changes: 0 additions & 2 deletions AK/Weakable.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class WeakLink : public RefCounted<WeakLink> {

void revoke() { m_ptr = nullptr; }

static FlatPtr ptr_offset() { return OFFSET_OF(WeakLink, m_ptr); }

private:
template<typename T>
explicit WeakLink(T& weakable)
Expand Down
5 changes: 0 additions & 5 deletions Userland/Libraries/LibJS/Bytecode/Executable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> shape;
Optional<u32> property_offset;
};

struct GlobalVariableCache : public PropertyLookupCache {
static FlatPtr environment_serial_number_offset() { return OFFSET_OF(GlobalVariableCache, environment_serial_number); }

u64 environment_serial_number { 0 };
};

Expand Down
6 changes: 0 additions & 6 deletions Userland/Libraries/LibJS/Runtime/DeclarativeEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -71,9 +68,6 @@ class DeclarativeEnvironment : public Environment {

[[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<Value> get_binding_value_direct(VM&, Binding&, bool strict);
ThrowCompletionOr<void> set_mutable_binding_direct(VM&, Binding&, Value, bool strict);
Expand Down
3 changes: 0 additions & 3 deletions Userland/Libraries/LibJS/Runtime/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class Environment : public Cell {
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);

Expand Down
3 changes: 0 additions & 3 deletions Userland/Libraries/LibJS/Runtime/EnvironmentCoordinate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions Userland/Libraries/LibJS/Runtime/ExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&);

Expand Down
3 changes: 0 additions & 3 deletions Userland/Libraries/LibJS/Runtime/GlobalEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class GlobalEnvironment final : public Environment {
ThrowCompletionOr<void> create_global_var_binding(DeprecatedFlyString const& name, bool can_be_deleted);
ThrowCompletionOr<void> 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);

Expand Down
7 changes: 0 additions & 7 deletions Userland/Libraries/LibJS/Runtime/IndexedProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class IndexedPropertyStorage {

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) {};
Expand Down Expand Up @@ -76,9 +74,6 @@ class SimpleIndexedPropertyStorage final : public IndexedPropertyStorage {

Vector<Value> 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;

Expand Down Expand Up @@ -177,8 +172,6 @@ class IndexedProperties {
}
}

static FlatPtr storage_offset() { return OFFSET_OF(IndexedProperties, m_storage); }

private:
void switch_to_generic_storage();
void ensure_storage();
Expand Down
8 changes: 0 additions & 8 deletions Userland/Libraries/LibJS/Runtime/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,27 +204,19 @@ class Object : public Cell {
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<Value>&& values) { m_indexed_properties = IndexedProperties(move(values)); }

Shape& shape() { return *m_shape; }
Shape const& shape() const { return *m_shape; }

static FlatPtr shape_offset() { return OFFSET_OF(Object, m_shape); }

template<typename T>
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; }
Expand Down
2 changes: 0 additions & 2 deletions Userland/Libraries/LibJS/Runtime/ObjectEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class ObjectEnvironment final : public Environment {
// [[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);

Expand Down
3 changes: 0 additions & 3 deletions Userland/Libraries/LibJS/Runtime/Realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class Realm final
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;

Expand Down

0 comments on commit d878975

Please sign in to comment.