mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibJS: Introduce NativeJavaScriptBackedFunction
This hosts the ability to compile and run JavaScript to implement native functions. This is particularly useful for any native function that is not a normal function, for example async functions such as Array.fromAsync, which require yielding. These functions are not allowed to observe anything from outside their environment. Any global identifiers will instead be assumed to be a reference to an abstract operation or a constant. The generator will inject the appropriate bytecode if the name of the global identifier matches a known name. Anything else will cause a code generation error.
This commit is contained in:
parent
899c6ebffc
commit
a63b0cfaba
Notes:
github-actions[bot]
2025-11-30 10:56:11 +00:00
Author: https://github.com/Lubrsi
Commit: a63b0cfaba
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6728
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/awesomekling
21 changed files with 412 additions and 52 deletions
43
Libraries/LibJS/Runtime/NativeJavaScriptBackedFunction.h
Normal file
43
Libraries/LibJS/Runtime/NativeJavaScriptBackedFunction.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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_constants_and_locals_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 const> shared_function_instance_data, Object& prototype);
|
||||
|
||||
GC::Ref<SharedFunctionInstanceData const> m_shared_function_instance_data;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue