LibJS: Take SharedFunctionInstanceData in NativeJavaScriptBackedFunction

Change NativeJavaScriptBackedFunction::create() to accept an
already-created GC::Ref<SharedFunctionInstanceData> instead of a
FunctionNode const&, removing another point of AST-runtime coupling.
This commit is contained in:
Andreas Kling 2026-02-11 12:05:57 +01:00 committed by Andreas Kling
parent 7e85bb251f
commit ef992b2010
Notes: github-actions[bot] 2026-02-11 22:58:51 +00:00
2 changed files with 2 additions and 14 deletions

View file

@ -18,7 +18,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(NativeJavaScriptBackedFunction);
// 10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] ), https://tc39.es/ecma262/#sec-createbuiltinfunction
GC::Ref<NativeJavaScriptBackedFunction> NativeJavaScriptBackedFunction::create(Realm& realm, FunctionNode const& function_node, PropertyKey const& name, i32 length)
GC::Ref<NativeJavaScriptBackedFunction> NativeJavaScriptBackedFunction::create(Realm& realm, GC::Ref<SharedFunctionInstanceData> shared_data, PropertyKey const& name, i32 length)
{
// 1. If realm is not present, set realm to the current Realm Record.
// 2. If prototype is not present, set prototype to realm.[[Intrinsics]].[[%Function.prototype%]].
@ -32,18 +32,6 @@ GC::Ref<NativeJavaScriptBackedFunction> NativeJavaScriptBackedFunction::create(R
// 7. Set func.[[Extensible]] to true.
// 8. Set func.[[Realm]] to realm.
// 9. Set func.[[InitialName]] to null.
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(realm.vm(),
function_node.kind(),
function_node.name(),
function_node.function_length(),
function_node.parameters(),
*function_node.body_ptr(),
function_node.source_text(),
function_node.is_strict_mode(),
function_node.is_arrow_function(),
function_node.parsing_insights(),
function_node.local_variables_names());
auto function = realm.create<NativeJavaScriptBackedFunction>(shared_data, *prototype);
function->unsafe_set_shape(realm.intrinsics().native_function_shape());