ladybird/Libraries/LibJS/Runtime/NativeJavaScriptBackedFunction.h
Andreas Kling 7281091fdb LibJS: Make bytecode generation infallible
Remove CodeGenerationError and make all bytecode generation functions
return their results directly instead of wrapping them in
CodeGenerationErrorOr.

For the few remaining sites where codegen encounters an unimplemented
or unexpected AST node, we now use a new emit_todo() helper that emits
a NewTypeError + Throw sequence at compile time (preserving the runtime
behavior) and then switches to a dead basic block so subsequent codegen
for the same function can continue without issue.

This allows us to remove error handling from all callers of the
bytecode compiler, simplifying the code significantly.
2026-02-12 11:37:43 +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&, GC::Ref<SharedFunctionInstanceData>, PropertyKey const& name, i32 length);
virtual ~NativeJavaScriptBackedFunction() override = default;
virtual void visit_edges(Visitor&) override;
virtual 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;
};
}