mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
LibJS: Wire NewClass to ClassBlueprint
Replace the ClassExpression const& reference in the NewClass instruction with a u32 class_blueprint_index. The interpreter now reads from the ClassBlueprint stored on the Executable and calls construct_class() instead of the AST-based create_class_constructor(). Literal field initializers (numbers, booleans, null, strings, negated numbers) are used directly in construct_class() without creating an ECMAScriptFunctionObject, avoiding function creation overhead for common field patterns like `x = 0` or `name = "hello"`. Set class_field_initializer_name on SharedFunctionInstanceData at codegen time for statically-known field keys (identifiers, private identifiers, string literals, and numeric literals). For computed keys, the name is set at runtime in construct_class(). ClassExpression AST nodes are no longer referenced from bytecode.
This commit is contained in:
committed by
Andreas Kling
parent
fa6a3f31dc
commit
ec2f4e4a7b
Notes:
github-actions[bot]
2026-02-11 23:01:20 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/ec2f4e4a7bd Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7896
@@ -25,6 +25,7 @@
|
||||
#include <LibJS/Runtime/AsyncFromSyncIterator.h>
|
||||
#include <LibJS/Runtime/AsyncFromSyncIteratorPrototype.h>
|
||||
#include <LibJS/Runtime/BigInt.h>
|
||||
#include <LibJS/Runtime/ClassConstruction.h>
|
||||
#include <LibJS/Runtime/CompletionCell.h>
|
||||
#include <LibJS/Runtime/DeclarativeEnvironment.h>
|
||||
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
|
||||
@@ -3034,19 +3035,21 @@ NEVER_INLINE ThrowCompletionOr<void> NewClass::execute_impl(Bytecode::Interprete
|
||||
}
|
||||
|
||||
auto& running_execution_context = interpreter.running_execution_context();
|
||||
auto class_environment = &as<Environment>(interpreter.get(m_class_environment).as_cell());
|
||||
auto* class_environment = &as<Environment>(interpreter.get(m_class_environment).as_cell());
|
||||
auto& outer_environment = running_execution_context.lexical_environment;
|
||||
|
||||
auto const& blueprint = interpreter.current_executable().class_blueprints[m_class_blueprint_index];
|
||||
|
||||
Optional<Utf16FlyString> binding_name;
|
||||
Utf16FlyString class_name;
|
||||
if (!m_class_expression.has_name() && m_lhs_name.has_value()) {
|
||||
if (!blueprint.has_name && m_lhs_name.has_value()) {
|
||||
class_name = interpreter.get_identifier(m_lhs_name.value());
|
||||
} else {
|
||||
class_name = m_class_expression.name();
|
||||
class_name = blueprint.name;
|
||||
binding_name = class_name;
|
||||
}
|
||||
|
||||
auto retval = TRY(m_class_expression.create_class_constructor(interpreter.vm(), class_environment, outer_environment, super_class, element_keys, binding_name, class_name));
|
||||
auto* retval = TRY(construct_class(interpreter.vm(), blueprint, interpreter.current_executable(), class_environment, outer_environment, super_class, element_keys, binding_name, class_name));
|
||||
interpreter.set(dst(), retval);
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user