ladybird/Libraries/LibJS/Runtime/NativeJavaScriptBackedFunction.h
Andreas Kling 658ba1d023 LibJS: Clear compile-only data from SharedFunctionInstanceData
After successful bytecode compilation, the m_functions_to_initialize
and m_var_names_to_initialize_binding vectors are no longer needed
as they are only consumed by emit_function_declaration_instantiation()
during code generation.

Add clear_compile_inputs() to release these vectors post-compile,
and call it from both ECMAScriptFunctionObject::get_stack_frame_size()
and NativeJavaScriptBackedFunction::bytecode_executable() after their
respective lazy compilation succeeds.

Also add a pre-compile assertion in Generator::generate_from_function()
to verify we never try to compile the same function data twice, and a
VERIFY in ECMAScriptFunctionObject::ecmascript_code() to guard against
null dereference.
2026-02-11 23:57:41 +01:00

43 lines
1.4 KiB
C++

/*
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/SharedFunctionInstanceData.h>
namespace JS {
class NativeJavaScriptBackedFunction final : public NativeFunction {
JS_OBJECT(NativeJavaScriptBackedFunction, NativeFunction);
GC_DECLARE_ALLOCATOR(NativeJavaScriptBackedFunction);
public:
static GC::Ref<NativeJavaScriptBackedFunction> create(Realm&, FunctionNode const& function_node, PropertyKey const& name, i32 length);
virtual ~NativeJavaScriptBackedFunction() override = default;
virtual void visit_edges(Visitor&) override;
virtual ThrowCompletionOr<void> get_stack_frame_size(size_t& registers_and_locals_count, size_t& constants_count, size_t& argument_count) override;
virtual ThrowCompletionOr<Value> call() override;
Bytecode::Executable& bytecode_executable();
FunctionKind kind() const;
ThisMode this_mode() const;
virtual bool function_environment_needed() const override;
virtual size_t function_environment_bindings_count() const override;
virtual bool is_strict_mode() const override;
private:
explicit NativeJavaScriptBackedFunction(GC::Ref<SharedFunctionInstanceData> shared_function_instance_data, Object& prototype);
GC::Ref<SharedFunctionInstanceData> m_shared_function_instance_data;
};
}