Truly independent web browser
LibJS: Remove unused C++ runtime helpers
Shannon Booth69c58f06dd85
diff --git a/Libraries/LibJS/CMakeLists.txt b/Libraries/LibJS/CMakeLists.txtindex 721c67c7330..770a6c91fb5 100644--- a/Libraries/LibJS/CMakeLists.txt+++ b/Libraries/LibJS/CMakeLists.txt@@ -64,7 +64,6 @@ set(SOURCESRuntime/JSONObject.cppRuntime/Map.cppRuntime/MapIterator.cpp- Runtime/ModuleEnvironment.cppRuntime/NativeFunction.cppRuntime/NumberObject.cppRuntime/Object.cppdiff --git a/Libraries/LibJS/HostClassBuilder.h b/Libraries/LibJS/HostClassBuilder.hindex bc4fce88153..d2c84a43544 100644--- a/Libraries/LibJS/HostClassBuilder.h+++ b/Libraries/LibJS/HostClassBuilder.h@@ -15,7 +15,6 @@#include <LibJS/Runtime/FunctionObject.h>#include <LibJS/Runtime/HostArray.h>#include <LibJS/Runtime/HostFunction.h>-#include <LibJS/Runtime/HostModule.h>#include <LibJS/Runtime/HostObject.h>#include <LibJS/Runtime/Object.h>#include <LibJS/Runtime/PropertyDescriptor.h>@@ -443,39 +442,6 @@ struct HostArrayHookThunks {}};-template<typename Traits>-struct HostModuleHookThunks {- static HostModule& host_module_from_abi(JSModule* module)- {- return static_cast<HostModule&>(*module_from_abi(module));- }-- static void get_exported_names(JSModule* module, JSStringSink* names)- {- for (auto const& name : Traits::get_exported_names(host_module_from_abi(module)))- append_string_to_abi_sink(*names, name);- }-- static void resolve_export(JSModule* module, u16 const* export_name, size_t export_name_length, JSResolvedBinding* out)- {- auto binding = Traits::resolve_export(host_module_from_abi(module), string_from_abi(export_name, export_name_length));- out->type = resolved_binding_type_to_abi(binding.type);- out->module = module_to_abi(binding.module.ptr());- if (binding.type == ResolvedBinding::BindingName)- append_string_to_abi_sink(out->binding_name, binding.export_name);- }-- static JSCompletion initialize_environment(JSModule* module)- {- return completion_to_abi(Traits::initialize_environment(host_module_from_abi(module)));- }-- static JSCompletion execute_module(JSModule* module, JSPromiseCapability* capability)- {- return completion_to_abi(Traits::execute_module(host_module_from_abi(module), promise_capability_from_abi(capability)));- }-};-}namespace JS {@@ -544,19 +510,6 @@ consteval JSHostArrayHooks make_host_array_hooks()return hooks;}-// All four module hooks are required.-template<typename Traits>-consteval JSHostModuleHooks make_host_module_hooks()-{- using Thunks = HostABI::HostModuleHookThunks<Traits>;- return JSHostModuleHooks {- .get_exported_names = &Thunks::get_exported_names,- .resolve_export = &Thunks::resolve_export,- .initialize_environment = &Thunks::initialize_environment,- .execute_module = &Thunks::execute_module,- };-}-consteval JSHostClass make_host_class(u8 kind, StringView name, JSHostClass const* parent, void const* hooks, void const* user_data, u32 flags){constexpr u32 flags_copied_into_objects = JS_HOST_CLASS_IS_PLATFORM_OBJECTdiff --git a/Libraries/LibJS/Runtime/Environment.cpp b/Libraries/LibJS/Runtime/Environment.cppindex c6a46685994..ecc8c87d506 100644--- a/Libraries/LibJS/Runtime/Environment.cpp+++ b/Libraries/LibJS/Runtime/Environment.cpp@@ -12,10 +12,6 @@ namespace JS {using namespace EmbeddingABI;-static_assert(to_underlying(Environment::InitializeBindingHint::Normal) == JS_INITIALIZE_BINDING_HINT_NORMAL);-static_assert(to_underlying(Environment::InitializeBindingHint::SyncDispose) == JS_INITIALIZE_BINDING_HINT_SYNC_DISPOSE);-static_assert(to_underlying(Environment::InitializeBindingHint::AsyncDispose) == JS_INITIALIZE_BINDING_HINT_ASYNC_DISPOSE);-static_assert(to_underlying(Environment::EngineEnvironmentKind::Declarative) == JS_ENVIRONMENT_KIND_DECLARATIVE);static_assert(to_underlying(Environment::EngineEnvironmentKind::Function) == JS_ENVIRONMENT_KIND_FUNCTION);static_assert(to_underlying(Environment::EngineEnvironmentKind::Module) == JS_ENVIRONMENT_KIND_MODULE);@@ -32,16 +28,6 @@ static JSUtf16View binding_name_to_abi(Utf16FlyString const& name)return utf16_view_to_abi(name.view());}-ThrowCompletionOr<void> Environment::create_immutable_binding(VM& vm, Utf16FlyString const& name, bool strict)-{- return completion_from_abi<void>(js_environment_create_immutable_binding(vm_to_abi(vm), environment_to_abi(*this), binding_name_to_abi(name), strict));-}--ThrowCompletionOr<void> Environment::initialize_binding(VM& vm, Utf16FlyString const& name, Value value, InitializeBindingHint hint)-{- return completion_from_abi<void>(js_environment_initialize_binding(vm_to_abi(vm), environment_to_abi(*this), binding_name_to_abi(name), value_to_abi(value), to_underlying(hint)));-}-ThrowCompletionOr<void> Environment::set_mutable_binding(VM& vm, Utf16FlyString const& name, Value value, bool strict){return completion_from_abi<void>(js_environment_set_mutable_binding(vm_to_abi(vm), environment_to_abi(*this), binding_name_to_abi(name), value_to_abi(value), strict));diff --git a/Libraries/LibJS/Runtime/Environment.h b/Libraries/LibJS/Runtime/Environment.hindex d45708ff524..8ba120aa70c 100644--- a/Libraries/LibJS/Runtime/Environment.h+++ b/Libraries/LibJS/Runtime/Environment.h@@ -23,14 +23,6 @@ namespace JS {// `static bool T::is_environment_kind_of(Environment const&)`.class JS_API Environment : public EngineCell {public:- enum class InitializeBindingHint {- Normal,- SyncDispose,- AsyncDispose,- };-- ThrowCompletionOr<void> create_immutable_binding(VM&, Utf16FlyString const& name, bool strict);- ThrowCompletionOr<void> initialize_binding(VM&, Utf16FlyString const& name, Value, InitializeBindingHint);ThrowCompletionOr<void> set_mutable_binding(VM&, Utf16FlyString const& name, Value, bool strict);ThrowCompletionOr<Value> get_binding_value(VM&, Utf16FlyString const& name, bool strict);ThrowCompletionOr<bool> delete_binding(VM&, Utf16FlyString const& name);diff --git a/Libraries/LibJS/Runtime/Error.cpp b/Libraries/LibJS/Runtime/Error.cppindex 4f46df746b1..88b0187bf95 100644--- a/Libraries/LibJS/Runtime/Error.cpp+++ b/Libraries/LibJS/Runtime/Error.cpp@@ -61,12 +61,6 @@ Utf16String Error::stack_string(CompactTraceback compact) constreturn own_error_data().stack_string(compact);}-// 20.5.8.1 InstallErrorCause ( O, options ), https://tc39.es/ecma262/#sec-installerrorcause-ThrowCompletionOr<void> Error::install_error_cause(Value options)-{- return completion_from_abi<void>(js_error_install_error_cause(vm_to_abi(vm()), error_to_abi(*this), value_to_abi(options)));-}-void Error::set_message(Utf16String message){js_error_set_owned_message(vm_to_abi(vm()), error_to_abi(*this), owned_utf16_string_to_abi(move(message)));diff --git a/Libraries/LibJS/Runtime/Error.h b/Libraries/LibJS/Runtime/Error.hindex 8014843a62b..d14a3325418 100644--- a/Libraries/LibJS/Runtime/Error.h+++ b/Libraries/LibJS/Runtime/Error.h@@ -31,8 +31,6 @@ public:[[nodiscard]] Utf16String stack_string(CompactTraceback compact = CompactTraceback::No) const;- ThrowCompletionOr<void> install_error_cause(Value options);-void set_message(Utf16String);void set_message(Utf16View);diff --git a/Libraries/LibJS/Runtime/ExecutionContext.h b/Libraries/LibJS/Runtime/ExecutionContext.hindex e7c682b27fe..3dc45802443 100644--- a/Libraries/LibJS/Runtime/ExecutionContext.h+++ b/Libraries/LibJS/Runtime/ExecutionContext.h@@ -170,11 +170,6 @@ struct JS_API ExecutionContext {return reinterpret_cast<Value const*>(reinterpret_cast<uintptr_t>(this) + sizeof(ExecutionContext));}- Span<Value> registers_and_constants_and_locals_and_arguments_span()- {- return { registers_and_constants_and_locals_and_arguments(), registers_and_constants_and_locals_and_arguments_count };- }-Value* arguments_data(){return registers_and_constants_and_locals_and_arguments() + (registers_and_constants_and_locals_and_arguments_count - argument_count);diff --git a/Libraries/LibJS/Runtime/ExternalMemory.h b/Libraries/LibJS/Runtime/ExternalMemory.hindex 5a2aff3c2cd..1e3e7bfb80c 100644--- a/Libraries/LibJS/Runtime/ExternalMemory.h+++ b/Libraries/LibJS/Runtime/ExternalMemory.h@@ -6,10 +6,8 @@#pragma once-#include <AK/ByteString.h>#include <AK/HashTable.h>#include <AK/NumericLimits.h>-#include <AK/String.h>#include <AK/Utf16String.h>#include <AK/Vector.h>@@ -22,20 +20,6 @@ inline size_t saturating_add_external_memory_size(size_t lhs, size_t rhs)return lhs + rhs;}-inline size_t string_external_memory_size(String const& string)-{- if (string.is_short_string())- return 0;- return string.byte_count();-}--inline size_t byte_string_external_memory_size(ByteString const& string)-{- if (string.is_empty())- return 0;- return AK::allocation_size_for_stringimpl(string.length());-}-inline size_t utf16_string_external_memory_size(Utf16String const& string){if (!string.has_long_storage())diff --git a/Libraries/LibJS/Runtime/ModuleEnvironment.cpp b/Libraries/LibJS/Runtime/ModuleEnvironment.cppdeleted file mode 100644index e3ed68a6248..00000000000--- a/Libraries/LibJS/Runtime/ModuleEnvironment.cpp+++ /dev/null@@ -1,21 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibJS/EmbeddingABIConversions.h>-#include <LibJS/Runtime/ModuleEnvironment.h>-#include <LibJS/Runtime/VM.h>--namespace JS {--using namespace EmbeddingABI;--GC::Ref<ModuleEnvironment> new_module_environment(GC::Ptr<Environment> outer_environment)-{- auto* abi_outer_environment = outer_environment ? cell_to_abi<JSEnvironment>(*outer_environment) : nullptr;- return cell_ref_from_abi<ModuleEnvironment>(js_environment_new_module_environment(vm_to_abi(VM::the()), abi_outer_environment));-}--}diff --git a/Libraries/LibJS/Runtime/ModuleEnvironment.h b/Libraries/LibJS/Runtime/ModuleEnvironment.hindex 22b29a571ef..2d36c0a759e 100644--- a/Libraries/LibJS/Runtime/ModuleEnvironment.h+++ b/Libraries/LibJS/Runtime/ModuleEnvironment.h@@ -21,7 +21,4 @@ public:static bool is_environment_kind_of(Environment const& environment) { return environment.engine_environment_kind() == EngineEnvironmentKind::Module; }};-// 9.1.2.6 NewModuleEnvironment ( E ), https://tc39.es/ecma262/#sec-newmoduleenvironment-JS_API GC::Ref<ModuleEnvironment> new_module_environment(GC::Ptr<Environment> outer_environment);-}diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cppindex 6eb73634404..14a0e299043 100644--- a/Libraries/LibJS/Runtime/Object.cpp+++ b/Libraries/LibJS/Runtime/Object.cpp@@ -77,22 +77,6 @@ ThrowCompletionOr<bool> Object::create_data_property_or_throw(PropertyKey const&return completion_from_abi<bool>(js_object_create_data_property_or_throw(vm_of(*this), object_to_abi(*this), property_key_to_abi(property_key), value_to_abi(value)));}-// 7.3.8 CreateNonEnumerableDataPropertyOrThrow ( O, P, V ), https://tc39.es/ecma262/#sec-createnonenumerabledatapropertyorthrow-void Object::create_non_enumerable_data_property_or_throw(PropertyKey const& property_key, Value value)-{- VERIFY(!value.is_special_empty_value());-- // 1. Assert: O is an ordinary, extensible object with no non-configurable properties.-- // 2. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.- auto new_description = PropertyDescriptor { .value = value, .writable = true, .enumerable = false, .configurable = true };-- // 3. Perform ! DefinePropertyOrThrow(O, P, newDesc).- MUST(define_property_or_throw(property_key, new_description));-- // 4. Return unused.-}-// 7.3.9 DefinePropertyOrThrow ( O, P, desc ), https://tc39.es/ecma262/#sec-definepropertyorthrowThrowCompletionOr<void> Object::define_property_or_throw(PropertyKey const& property_key, PropertyDescriptor& property_descriptor){@@ -356,11 +340,6 @@ void Object::define_native_accessor(Realm& realm, PropertyKey const& property_kedefine_direct_accessor(property_key, getter_function, setter_function, attributes);}-bool Object::is_date() const-{- return is_of_engine_class_or_subclass(JS_LAYOUT_CLASS_ID_DATE);-}-bool Object::is_weak_map() const{return engine_class_id() == JS_LAYOUT_CLASS_ID_WEAK_MAP;diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.hindex 0aaffc656ea..7c1c3463407 100644--- a/Libraries/LibJS/Runtime/Object.h+++ b/Libraries/LibJS/Runtime/Object.h@@ -78,7 +78,6 @@ public:ThrowCompletionOr<void> set(PropertyKey const&, Value, ShouldThrowExceptions);ThrowCompletionOr<bool> create_data_property(PropertyKey const&, Value, Optional<u32>* new_property_offset = nullptr, Optional<PropertyDescriptor>* precomputed_get_own_property = nullptr);ThrowCompletionOr<bool> create_data_property_or_throw(PropertyKey const&, Value);- void create_non_enumerable_data_property_or_throw(PropertyKey const&, Value);ThrowCompletionOr<void> define_property_or_throw(PropertyKey const&, PropertyDescriptor&);ThrowCompletionOr<bool> has_property(PropertyKey const&) const;ThrowCompletionOr<bool> has_own_property(PropertyKey const&) const;@@ -156,7 +155,6 @@ public:void define_native_accessor(Realm&, PropertyKey const&, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>> getter, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>> setter, PropertyAttributes attributes);[[nodiscard]] bool is_function() const { return has_engine_object_flag(JS_LAYOUT_OBJECT_FLAG_IS_FUNCTION); }- bool is_date() const;bool is_weak_map() const;bool is_weak_set() const;bool is_generator() const;diff --git a/Libraries/LibJS/Runtime/PropertyDescriptor.cpp b/Libraries/LibJS/Runtime/PropertyDescriptor.cppindex 965d766d6d6..3be4b3c6afd 100644--- a/Libraries/LibJS/Runtime/PropertyDescriptor.cpp+++ b/Libraries/LibJS/Runtime/PropertyDescriptor.cpp@@ -43,23 +43,6 @@ bool PropertyDescriptor::is_data_descriptor() constreturn false;}-// 6.2.5.3 IsGenericDescriptor ( Desc ), https://tc39.es/ecma262/#sec-isgenericdescriptor-bool PropertyDescriptor::is_generic_descriptor() const-{- // 1. If Desc is undefined, return false.-- // 2. If IsAccessorDescriptor(Desc) is true, return false.- if (is_accessor_descriptor())- return false;-- // 3. If IsDataDescriptor(Desc) is true, return false.- if (is_data_descriptor())- return false;-- // 4. Return true.- return true;-}-void PropertyDescriptor::visit_edges(GC::Cell::Visitor& visitor){visitor.visit(value);diff --git a/Libraries/LibJS/Runtime/PropertyDescriptor.h b/Libraries/LibJS/Runtime/PropertyDescriptor.hindex 96bcda05448..6a8430311e2 100644--- a/Libraries/LibJS/Runtime/PropertyDescriptor.h+++ b/Libraries/LibJS/Runtime/PropertyDescriptor.h@@ -23,8 +23,6 @@ class JS_API PropertyDescriptor {public:[[nodiscard]] bool is_accessor_descriptor() const;[[nodiscard]] bool is_data_descriptor() const;- [[nodiscard]] bool is_generic_descriptor() const;-// Not a standard abstract operation, but "If every field in Desc is absent".[[nodiscard]] bool is_empty() const{diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cppindex 2cfd5e4cab8..e2671fee97d 100644--- a/Libraries/LibJS/Runtime/VM.cpp+++ b/Libraries/LibJS/Runtime/VM.cpp@@ -520,11 +520,6 @@ Utf16String const& VM::error_message(ErrorMessage type) constreturn message;}-bool VM::did_reach_stack_space_limit() const-{- return js_vm_did_reach_stack_space_limit(vm_abi(*this));-}-void VM::push_execution_context_growing_the_stack(ExecutionContext& execution_context){js_execution_context_push(vm_abi(*this), execution_context_to_abi(execution_context));diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.hindex 8666cf4ef9e..32bdf30fc81 100644--- a/Libraries/LibJS/Runtime/VM.h+++ b/Libraries/LibJS/Runtime/VM.h@@ -211,8 +211,6 @@ public:};Utf16String const& error_message(ErrorMessage) const;- bool did_reach_stack_space_limit() const;-// Pushes onto the runtime's execution context stack in place, as the runtime itself does, unless the stack's// storage is full, which only the runtime can grow.void push_execution_context(ExecutionContext& execution_context)diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cppindex 3c1f69c0e7b..8d4e7f12583 100644--- a/Libraries/LibJS/Runtime/Value.cpp+++ b/Libraries/LibJS/Runtime/Value.cpp@@ -331,14 +331,6 @@ ThrowCompletionOr<u32> Value::to_u32(VM& vm) constreturn result;}-// 7.1.9 ToUint16 ( argument ), https://tc39.es/ecma262/#sec-touint16-ThrowCompletionOr<u16> Value::to_u16(VM& vm) const-{- u16 result = 0;- TRY(completion_from_abi<void>(js_value_to_u16(vm_to_abi(vm), value_to_abi(*this), &result)));- return result;-}-// 7.1.11 ToUint8 ( argument ), https://tc39.es/ecma262/#sec-touint8ThrowCompletionOr<u8> Value::to_u8(VM& vm) const{diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.hindex fa5a1c69695..fc5adf98e69 100644--- a/Libraries/LibJS/Runtime/Value.h+++ b/Libraries/LibJS/Runtime/Value.h@@ -421,7 +421,6 @@ public:ThrowCompletionOr<double> to_double(VM&) const;ThrowCompletionOr<i32> to_i32(VM&) const;ThrowCompletionOr<u32> to_u32(VM&) const;- ThrowCompletionOr<u16> to_u16(VM&) const;ThrowCompletionOr<u8> to_u8(VM&) const;ThrowCompletionOr<size_t> to_length(VM&) const;bool to_boolean() const;diff --git a/Libraries/LibJS/SourceCode.cpp b/Libraries/LibJS/SourceCode.cppindex df5098afed7..ba606833ed7 100644--- a/Libraries/LibJS/SourceCode.cpp+++ b/Libraries/LibJS/SourceCode.cpp@@ -6,7 +6,6 @@#include <LibJS/ScriptAndModuleABIConversions.h>#include <LibJS/SourceCode.h>-#include <LibTextCodec/Decoder.h>namespace JS {@@ -42,16 +41,6 @@ size_t SourceCode::length_in_code_units() constreturn js_source_code_length_in_code_units(source_code_to_abi(*this));}-Utf16String SourceCode::source_text_from_offsets(size_t start_offset, size_t length) const-{- if (length == 0)- return {};-- VERIFY(start_offset <= NumericLimits<size_t>::max() - length);- auto code = this->code();- return Utf16String::from_utf16(code.utf16_view().substring_view(start_offset, length));-}-void SourceCode::ref() const{js_source_code_retain(source_code_to_abi(*this));diff --git a/Libraries/LibJS/SourceCode.h b/Libraries/LibJS/SourceCode.hindex f37dc2ac073..cbda67e5b01 100644--- a/Libraries/LibJS/SourceCode.h+++ b/Libraries/LibJS/SourceCode.h@@ -36,8 +36,6 @@ public:Utf16String code() const;size_t length_in_code_units() const;- Utf16String source_text_from_offsets(size_t start_offset, size_t length) const;-void ref() const;void unref() const;diff --git a/Libraries/LibJS/Token.h b/Libraries/LibJS/Token.hindex d0f185b70e3..f1d4e595606 100644--- a/Libraries/LibJS/Token.h+++ b/Libraries/LibJS/Token.h@@ -162,11 +162,6 @@ inline u64 pack_token_data(TokenType type, TokenCategory category)return (static_cast<u64>(category) << 8) | static_cast<u64>(type);}-inline TokenType token_type_from_packed(u64 data)-{- return static_cast<TokenType>(data & 0xFF);-}-inline TokenCategory token_category_from_packed(u64 data){return static_cast<TokenCategory>((data >> 8) & 0xFF);