1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibJS/Bytecode: Move to a new bytecode format

This patch moves us away from the accumulator-based bytecode format to
one with explicit source and destination registers.

The new format has multiple benefits:

- ~25% faster on the Kraken and Octane benchmarks :^)
- Fewer instructions to accomplish the same thing
- Much easier for humans to read(!)

Because this change requires a fundamental shift in how bytecode is
generated, it is quite comprehensive.

Main implementation mechanism: generate_bytecode() virtual function now
takes an optional "preferred dst" operand, which allows callers to
communicate when they have an operand that would be optimal for the
result to go into. It also returns an optional "actual dst" operand,
which is where the completion value (if any) of the AST node is stored
after the node has "executed".

One thing of note that's new: because instructions can now take locals
as operands, this means we got rid of the GetLocal instruction.
A side-effect of that is we have to think about the temporal deadzone
(TDZ) a bit differently for locals (GetLocal would previously check
for empty values and interpret that as a TDZ access and throw).
We now insert special ThrowIfTDZ instructions in places where a local
access may be in the TDZ, to maintain the correct behavior.

There are a number of progressions and regressions from this test:

A number of async generator tests have been accidentally fixed while
converting the implementation to the new bytecode format. It didn't
seem useful to preserve bugs in the original code when converting it.

Some "does eval() return the correct completion value" tests have
regressed, in particular ones related to propagating the appropriate
completion after control flow statements like continue and break.
These are all fairly obscure issues, and I believe we can continue
working on them separately.

The net test262 result is a progression though. :^)
This commit is contained in:
Andreas Kling 2024-02-04 08:00:54 +01:00
parent 7f1a62a1d3
commit e46b217e42
14 changed files with 2311 additions and 1642 deletions

View file

@ -239,7 +239,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
// FIXME: A potential optimization is not creating the functions here since these are never directly accessible. // FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
auto function_code = create_ast_node<ClassFieldInitializerStatement>(m_initializer->source_range(), copy_initializer.release_nonnull(), name); auto function_code = create_ast_node<ClassFieldInitializerStatement>(m_initializer->source_range(), copy_initializer.release_nonnull(), name);
initializer = make_handle(*ECMAScriptFunctionObject::create(realm, ByteString::empty(), ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false, property_key_or_private_name)); initializer = make_handle(*ECMAScriptFunctionObject::create(realm, "field", ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, false, m_contains_direct_call_to_eval, false, property_key_or_private_name));
initializer->make_method(target); initializer->make_method(target);
} }

File diff suppressed because it is too large Load diff

View file

@ -367,7 +367,7 @@ inline ThrowCompletionOr<void> set_variable(
return {}; return {};
} }
inline Value new_function(VM& vm, FunctionExpression const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Register> const& home_object) inline Value new_function(VM& vm, FunctionExpression const& function_node, Optional<IdentifierTableIndex> const& lhs_name, Optional<Operand> const& home_object)
{ {
Value value; Value value;
@ -381,7 +381,7 @@ inline Value new_function(VM& vm, FunctionExpression const& function_node, Optio
} }
if (home_object.has_value()) { if (home_object.has_value()) {
auto home_object_value = vm.bytecode_interpreter().reg(home_object.value()); auto home_object_value = vm.bytecode_interpreter().get(home_object.value());
static_cast<ECMAScriptFunctionObject&>(value.as_function()).set_home_object(&home_object_value.as_object()); static_cast<ECMAScriptFunctionObject&>(value.as_function()).set_home_object(&home_object_value.as_object());
} }

View file

@ -1,11 +1,9 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#define FIXME_NEWBC (void)
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <LibJS/AST.h> #include <LibJS/AST.h>
#include <LibJS/Bytecode/BasicBlock.h> #include <LibJS/Bytecode/BasicBlock.h>
@ -24,29 +22,42 @@ Generator::Generator()
{ {
} }
CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTNode const& node, FunctionKind enclosing_function_kind) CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTNode const& node, ReadonlySpan<FunctionParameter> parameters, FunctionKind enclosing_function_kind)
{ {
Generator generator; Generator generator;
for (auto const& parameter : parameters) {
if (auto const* identifier = parameter.binding.get_pointer<NonnullRefPtr<Identifier const>>();
identifier && (*identifier)->is_local()) {
generator.set_local_initialized((*identifier)->local_variable_index());
}
}
generator.switch_to_basic_block(generator.make_block()); generator.switch_to_basic_block(generator.make_block());
SourceLocationScope scope(generator, node); SourceLocationScope scope(generator, node);
generator.m_enclosing_function_kind = enclosing_function_kind; generator.m_enclosing_function_kind = enclosing_function_kind;
if (generator.is_in_generator_or_async_function()) { if (generator.is_in_generator_or_async_function()) {
// Immediately yield with no value. // Immediately yield with no value.
auto& start_block = generator.make_block(); auto& start_block = generator.make_block();
generator.emit<Bytecode::Op::Yield>(Label { start_block }); generator.emit<Bytecode::Op::Yield>(Label { start_block }, generator.add_constant(js_undefined()));
generator.switch_to_basic_block(start_block); generator.switch_to_basic_block(start_block);
// NOTE: This doesn't have to handle received throw/return completions, as GeneratorObject::resume_abrupt // NOTE: This doesn't have to handle received throw/return completions, as GeneratorObject::resume_abrupt
// will not enter the generator from the SuspendedStart state and immediately completes the generator. // will not enter the generator from the SuspendedStart state and immediately completes the generator.
} }
FIXME_NEWBC TRY(node.generate_bytecode(generator));
auto last_value = TRY(node.generate_bytecode(generator));
if (!generator.current_block().is_terminated() && last_value.has_value()) {
generator.emit<Bytecode::Op::End>(last_value.value());
}
if (generator.is_in_generator_or_async_function()) { if (generator.is_in_generator_or_async_function()) {
// Terminate all unterminated blocks with yield return // Terminate all unterminated blocks with yield return
for (auto& block : generator.m_root_basic_blocks) { for (auto& block : generator.m_root_basic_blocks) {
if (block->is_terminated()) if (block->is_terminated())
continue; continue;
generator.switch_to_basic_block(*block); generator.switch_to_basic_block(*block);
generator.emit<Bytecode::Op::LoadImmediate>(js_undefined()); generator.emit<Bytecode::Op::Yield>(nullptr, generator.add_constant(js_undefined()));
generator.emit<Bytecode::Op::Yield>(nullptr);
} }
} }
@ -169,26 +180,23 @@ void Generator::end_breakable_scope()
end_boundary(BlockBoundaryType::Break); end_boundary(BlockBoundaryType::Break);
} }
CodeGenerationErrorOr<Generator::ReferenceRegisters> Generator::emit_super_reference(MemberExpression const& expression) CodeGenerationErrorOr<Generator::ReferenceOperands> Generator::emit_super_reference(MemberExpression const& expression)
{ {
VERIFY(is<SuperExpression>(expression.object())); VERIFY(is<SuperExpression>(expression.object()));
// https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
// 1. Let env be GetThisEnvironment(). // 1. Let env be GetThisEnvironment().
// 2. Let actualThis be ? env.GetThisBinding(). // 2. Let actualThis be ? env.GetThisBinding().
auto actual_this_register = allocate_register(); auto actual_this = Operand(allocate_register());
emit<Bytecode::Op::ResolveThisBinding>(); emit<Bytecode::Op::ResolveThisBinding>(actual_this);
emit<Bytecode::Op::Store>(actual_this_register);
Optional<Bytecode::Register> computed_property_value_register; Optional<Bytecode::Operand> computed_property_value;
if (expression.is_computed()) { if (expression.is_computed()) {
// SuperProperty : super [ Expression ] // SuperProperty : super [ Expression ]
// 3. Let propertyNameReference be ? Evaluation of Expression. // 3. Let propertyNameReference be ? Evaluation of Expression.
// 4. Let propertyNameValue be ? GetValue(propertyNameReference). // 4. Let propertyNameValue be ? GetValue(propertyNameReference).
FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); computed_property_value = TRY(expression.property().generate_bytecode(*this)).value();
computed_property_value_register = allocate_register();
emit<Bytecode::Op::Store>(*computed_property_value_register);
} }
// 5/7. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict). // 5/7. Return ? MakeSuperPropertyReference(actualThis, propertyKey, strict).
@ -197,135 +205,128 @@ CodeGenerationErrorOr<Generator::ReferenceRegisters> Generator::emit_super_refer
// 1. Let env be GetThisEnvironment(). // 1. Let env be GetThisEnvironment().
// 2. Assert: env.HasSuperBinding() is true. // 2. Assert: env.HasSuperBinding() is true.
// 3. Let baseValue be ? env.GetSuperBase(). // 3. Let baseValue be ? env.GetSuperBase().
auto super_base_register = allocate_register(); auto base_value = Operand(allocate_register());
emit<Bytecode::Op::ResolveSuperBase>(); emit<Bytecode::Op::ResolveSuperBase>(base_value);
emit<Bytecode::Op::Store>(super_base_register);
// 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }. // 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
return ReferenceRegisters { return ReferenceOperands {
.base = super_base_register, .base = base_value,
.referenced_name = move(computed_property_value_register), .referenced_name = computed_property_value,
.this_value = actual_this_register, .this_value = actual_this,
}; };
} }
CodeGenerationErrorOr<Optional<Generator::ReferenceRegisters>> Generator::emit_load_from_reference(JS::ASTNode const& node, CollectRegisters collect_registers) CodeGenerationErrorOr<Generator::ReferenceOperands> Generator::emit_load_from_reference(JS::ASTNode const& node, Optional<Operand> preferred_dst)
{ {
if (is<Identifier>(node)) { if (is<Identifier>(node)) {
auto& identifier = static_cast<Identifier const&>(node); auto& identifier = static_cast<Identifier const&>(node);
FIXME_NEWBC TRY(identifier.generate_bytecode(*this)); auto loaded_value = TRY(identifier.generate_bytecode(*this, preferred_dst)).value();
return Optional<ReferenceRegisters> {}; return ReferenceOperands {
.loaded_value = loaded_value,
};
} }
if (is<MemberExpression>(node)) { if (!is<MemberExpression>(node)) {
auto& expression = static_cast<MemberExpression const&>(node); return CodeGenerationError {
&node,
"Unimplemented/invalid node used as a reference"sv
};
}
auto& expression = static_cast<MemberExpression const&>(node);
// https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
if (is<SuperExpression>(expression.object())) { if (is<SuperExpression>(expression.object())) {
auto super_reference = TRY(emit_super_reference(expression)); auto super_reference = TRY(emit_super_reference(expression));
auto dst = preferred_dst.has_value() ? preferred_dst.value() : Operand(allocate_register());
if (super_reference.referenced_name.has_value()) { if (super_reference.referenced_name.has_value()) {
// 5. Let propertyKey be ? ToPropertyKey(propertyNameValue). // 5. Let propertyKey be ? ToPropertyKey(propertyNameValue).
// FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive! // FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive!
emit<Bytecode::Op::Load>(*super_reference.referenced_name); emit<Bytecode::Op::GetByValueWithThis>(dst, *super_reference.base, *super_reference.referenced_name, *super_reference.this_value);
emit<Bytecode::Op::GetByValueWithThis>(super_reference.base, super_reference.this_value);
} else {
// 3. Let propertyKey be StringValue of IdentifierName.
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit_get_by_id_with_this(identifier_table_ref, super_reference.this_value);
}
return super_reference;
} else { } else {
FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); // 3. Let propertyKey be StringValue of IdentifierName.
if (expression.is_computed()) { auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
auto object_reg = allocate_register(); emit_get_by_id_with_this(dst, *super_reference.base, identifier_table_ref, *super_reference.this_value);
emit<Bytecode::Op::Store>(object_reg);
FIXME_NEWBC TRY(expression.property().generate_bytecode(*this));
Optional<Register> property_reg {};
if (collect_registers == CollectRegisters::Yes) {
property_reg = allocate_register();
emit<Bytecode::Op::Store>(property_reg.value());
}
emit<Bytecode::Op::GetByValue>(object_reg);
if (collect_registers == CollectRegisters::Yes)
return ReferenceRegisters {
.base = object_reg,
.referenced_name = property_reg.value(),
.this_value = object_reg,
};
return Optional<ReferenceRegisters> {};
} else if (expression.property().is_identifier()) {
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit_get_by_id(identifier_table_ref);
} else if (expression.property().is_private_identifier()) {
auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string());
emit<Bytecode::Op::GetPrivateById>(identifier_table_ref);
} else {
return CodeGenerationError {
&expression,
"Unimplemented non-computed member expression"sv
};
}
} }
return Optional<ReferenceRegisters> {};
super_reference.loaded_value = dst;
return super_reference;
}
auto base = TRY(expression.object().generate_bytecode(*this)).value();
if (expression.is_computed()) {
auto property = TRY(expression.property().generate_bytecode(*this)).value();
auto dst = preferred_dst.has_value() ? preferred_dst.value() : Operand(allocate_register());
emit<Bytecode::Op::GetByValue>(dst, base, property);
return ReferenceOperands {
.base = base,
.referenced_name = property,
.this_value = base,
.loaded_value = dst,
};
}
if (expression.property().is_identifier()) {
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
auto dst = preferred_dst.has_value() ? preferred_dst.value() : Operand(allocate_register());
emit_get_by_id(dst, base, identifier_table_ref);
return ReferenceOperands {
.base = base,
.referenced_identifier = identifier_table_ref,
.this_value = base,
.loaded_value = dst,
};
}
if (expression.property().is_private_identifier()) {
auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string());
auto dst = preferred_dst.has_value() ? preferred_dst.value() : Operand(allocate_register());
emit<Bytecode::Op::GetPrivateById>(dst, base, identifier_table_ref);
return ReferenceOperands {
.base = base,
.referenced_private_identifier = identifier_table_ref,
.this_value = base,
.loaded_value = dst,
};
} }
return CodeGenerationError { return CodeGenerationError {
&node, &expression,
"Unimplemented/invalid node used a reference"sv "Unimplemented non-computed member expression"sv
}; };
} }
CodeGenerationErrorOr<Optional<Operand>> Generator::emit_store_to_reference(JS::ASTNode const& node) CodeGenerationErrorOr<void> Generator::emit_store_to_reference(JS::ASTNode const& node, Operand value)
{ {
if (is<Identifier>(node)) { if (is<Identifier>(node)) {
auto& identifier = static_cast<Identifier const&>(node); auto& identifier = static_cast<Identifier const&>(node);
emit_set_variable(identifier); emit_set_variable(identifier, value);
return Optional<Operand> {}; return {};
} }
if (is<MemberExpression>(node)) { if (is<MemberExpression>(node)) {
// NOTE: The value is in the accumulator, so we have to store that away first.
auto value_reg = allocate_register();
emit<Bytecode::Op::Store>(value_reg);
auto& expression = static_cast<MemberExpression const&>(node); auto& expression = static_cast<MemberExpression const&>(node);
// https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation // https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
if (is<SuperExpression>(expression.object())) { if (is<SuperExpression>(expression.object())) {
auto super_reference = TRY(emit_super_reference(expression)); auto super_reference = TRY(emit_super_reference(expression));
emit<Bytecode::Op::Load>(value_reg);
// 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }. // 4. Return the Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
if (super_reference.referenced_name.has_value()) { if (super_reference.referenced_name.has_value()) {
// 5. Let propertyKey be ? ToPropertyKey(propertyNameValue). // 5. Let propertyKey be ? ToPropertyKey(propertyNameValue).
// FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive! // FIXME: This does ToPropertyKey out of order, which is observable by Symbol.toPrimitive!
emit<Bytecode::Op::PutByValueWithThis>(super_reference.base, *super_reference.referenced_name, super_reference.this_value); emit<Bytecode::Op::PutByValueWithThis>(*super_reference.base, *super_reference.referenced_name, *super_reference.this_value, value);
} else { } else {
// 3. Let propertyKey be StringValue of IdentifierName. // 3. Let propertyKey be StringValue of IdentifierName.
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit<Bytecode::Op::PutByIdWithThis>(super_reference.base, super_reference.this_value, identifier_table_ref, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache()); emit<Bytecode::Op::PutByIdWithThis>(*super_reference.base, *super_reference.this_value, identifier_table_ref, value, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache());
} }
} else { } else {
FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); auto object = TRY(expression.object().generate_bytecode(*this)).value();
auto object_reg = allocate_register();
emit<Bytecode::Op::Store>(object_reg);
if (expression.is_computed()) { if (expression.is_computed()) {
FIXME_NEWBC TRY(expression.property().generate_bytecode(*this)); auto property = TRY(expression.property().generate_bytecode(*this)).value();
auto property_reg = allocate_register(); emit<Bytecode::Op::PutByValue>(object, property, value);
emit<Bytecode::Op::Store>(property_reg);
emit<Bytecode::Op::Load>(value_reg);
emit<Bytecode::Op::PutByValue>(object_reg, property_reg);
} else if (expression.property().is_identifier()) { } else if (expression.property().is_identifier()) {
emit<Bytecode::Op::Load>(value_reg);
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit<Bytecode::Op::PutById>(object_reg, identifier_table_ref, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache()); emit<Bytecode::Op::PutById>(object, identifier_table_ref, value, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache());
} else if (expression.property().is_private_identifier()) { } else if (expression.property().is_private_identifier()) {
emit<Bytecode::Op::Load>(value_reg);
auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string()); auto identifier_table_ref = intern_identifier(verify_cast<PrivateIdentifier>(expression.property()).string());
emit<Bytecode::Op::PutPrivateById>(object_reg, identifier_table_ref); emit<Bytecode::Op::PutPrivateById>(object, identifier_table_ref, value);
} else { } else {
return CodeGenerationError { return CodeGenerationError {
&expression, &expression,
@ -334,7 +335,7 @@ CodeGenerationErrorOr<Optional<Operand>> Generator::emit_store_to_reference(JS::
} }
} }
return Optional<Operand> {}; return {};
} }
return CodeGenerationError { return CodeGenerationError {
@ -343,24 +344,36 @@ CodeGenerationErrorOr<Optional<Operand>> Generator::emit_store_to_reference(JS::
}; };
} }
CodeGenerationErrorOr<Optional<Operand>> Generator::emit_store_to_reference(ReferenceRegisters const& reference_registers) CodeGenerationErrorOr<void> Generator::emit_store_to_reference(ReferenceOperands const& reference, Operand value)
{ {
if (reference_registers.base == reference_registers.this_value) if (reference.referenced_private_identifier.has_value()) {
emit<Bytecode::Op::PutByValue>(reference_registers.base, reference_registers.referenced_name.value()); emit<Bytecode::Op::PutPrivateById>(*reference.base, *reference.referenced_private_identifier, value);
return {};
}
if (reference.referenced_identifier.has_value()) {
if (reference.base == reference.this_value)
emit<Bytecode::Op::PutById>(*reference.base, *reference.referenced_identifier, value, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache());
else
emit<Bytecode::Op::PutByIdWithThis>(*reference.base, *reference.this_value, *reference.referenced_identifier, value, Bytecode::Op::PropertyKind::KeyValue, next_property_lookup_cache());
return {};
}
if (reference.base == reference.this_value)
emit<Bytecode::Op::PutByValue>(*reference.base, *reference.referenced_name, value);
else else
emit<Bytecode::Op::PutByValueWithThis>(reference_registers.base, reference_registers.referenced_name.value(), reference_registers.this_value); emit<Bytecode::Op::PutByValueWithThis>(*reference.base, *reference.referenced_name, *reference.this_value, value);
return Optional<Operand> {}; return {};
} }
CodeGenerationErrorOr<Optional<Operand>> Generator::emit_delete_reference(JS::ASTNode const& node) CodeGenerationErrorOr<Optional<Operand>> Generator::emit_delete_reference(JS::ASTNode const& node)
{ {
if (is<Identifier>(node)) { if (is<Identifier>(node)) {
auto& identifier = static_cast<Identifier const&>(node); auto& identifier = static_cast<Identifier const&>(node);
if (identifier.is_local()) if (identifier.is_local()) {
emit<Bytecode::Op::LoadImmediate>(Value(false)); return add_constant(Value(false));
else }
emit<Bytecode::Op::DeleteVariable>(intern_identifier(identifier.string())); auto dst = Operand(allocate_register());
return Optional<Operand> {}; emit<Bytecode::Op::DeleteVariable>(dst, intern_identifier(identifier.string()));
return dst;
} }
if (is<MemberExpression>(node)) { if (is<MemberExpression>(node)) {
@ -370,27 +383,26 @@ CodeGenerationErrorOr<Optional<Operand>> Generator::emit_delete_reference(JS::AS
if (is<SuperExpression>(expression.object())) { if (is<SuperExpression>(expression.object())) {
auto super_reference = TRY(emit_super_reference(expression)); auto super_reference = TRY(emit_super_reference(expression));
auto dst = Operand(allocate_register());
if (super_reference.referenced_name.has_value()) { if (super_reference.referenced_name.has_value()) {
emit<Bytecode::Op::DeleteByValueWithThis>(super_reference.this_value, *super_reference.referenced_name); emit<Bytecode::Op::DeleteByValueWithThis>(dst, *super_reference.base, *super_reference.this_value, *super_reference.referenced_name);
} else { } else {
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit<Bytecode::Op::DeleteByIdWithThis>(super_reference.this_value, identifier_table_ref); emit<Bytecode::Op::DeleteByIdWithThis>(dst, *super_reference.base, *super_reference.this_value, identifier_table_ref);
} }
return Optional<Operand> {}; return Optional<Operand> {};
} }
FIXME_NEWBC TRY(expression.object().generate_bytecode(*this)); auto object = TRY(expression.object().generate_bytecode(*this)).value();
auto dst = Operand(allocate_register());
if (expression.is_computed()) { if (expression.is_computed()) {
auto object_reg = allocate_register(); auto property = TRY(expression.property().generate_bytecode(*this)).value();
emit<Bytecode::Op::Store>(object_reg); emit<Bytecode::Op::DeleteByValue>(dst, object, property);
FIXME_NEWBC TRY(expression.property().generate_bytecode(*this));
emit<Bytecode::Op::DeleteByValue>(object_reg);
} else if (expression.property().is_identifier()) { } else if (expression.property().is_identifier()) {
auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string()); auto identifier_table_ref = intern_identifier(verify_cast<Identifier>(expression.property()).string());
emit<Bytecode::Op::DeleteById>(identifier_table_ref); emit<Bytecode::Op::DeleteById>(dst, object, identifier_table_ref);
} else { } else {
// NOTE: Trying to delete a private field generates a SyntaxError in the parser. // NOTE: Trying to delete a private field generates a SyntaxError in the parser.
return CodeGenerationError { return CodeGenerationError {
@ -398,7 +410,7 @@ CodeGenerationErrorOr<Optional<Operand>> Generator::emit_delete_reference(JS::AS
"Unimplemented non-computed member expression"sv "Unimplemented non-computed member expression"sv
}; };
} }
return Optional<Operand> {}; return dst;
} }
// Though this will have no deletion effect, we still have to evaluate the node as it can have side effects. // Though this will have no deletion effect, we still have to evaluate the node as it can have side effects.
@ -407,21 +419,23 @@ CodeGenerationErrorOr<Optional<Operand>> Generator::emit_delete_reference(JS::AS
// 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation // 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation
// 1. Let ref be the result of evaluating UnaryExpression. // 1. Let ref be the result of evaluating UnaryExpression.
// 2. ReturnIfAbrupt(ref). // 2. ReturnIfAbrupt(ref).
FIXME_NEWBC TRY(node.generate_bytecode(*this)); (void)TRY(node.generate_bytecode(*this));
// 3. If ref is not a Reference Record, return true. // 3. If ref is not a Reference Record, return true.
emit<Bytecode::Op::LoadImmediate>(Value(true));
// NOTE: The rest of the steps are handled by Delete{Variable,ByValue,Id}. // NOTE: The rest of the steps are handled by Delete{Variable,ByValue,Id}.
return Optional<Operand> {}; return add_constant(Value(true));
} }
void Generator::emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Op::EnvironmentMode mode) void Generator::emit_set_variable(JS::Identifier const& identifier, Operand value, Bytecode::Op::SetVariable::InitializationMode initialization_mode, Bytecode::Op::EnvironmentMode mode)
{ {
if (identifier.is_local()) { if (identifier.is_local()) {
emit<Bytecode::Op::SetLocal>(identifier.local_variable_index()); if (value.is_local() && value.index() == identifier.local_variable_index()) {
// Moving a local to itself is a no-op.
return;
}
emit<Bytecode::Op::SetLocal>(identifier.local_variable_index(), value);
} else { } else {
emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()), next_environment_variable_cache(), initialization_mode, mode); emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()), value, next_environment_variable_cache(), initialization_mode, mode);
} }
} }
@ -540,9 +554,9 @@ void Generator::generate_continue(DeprecatedFlyString const& continue_label)
generate_labelled_jump(JumpType::Continue, continue_label); generate_labelled_jump(JumpType::Continue, continue_label);
} }
void Generator::push_home_object(Register register_) void Generator::push_home_object(Operand object)
{ {
m_home_objects.append(register_); m_home_objects.append(object);
} }
void Generator::pop_home_object() void Generator::pop_home_object()
@ -550,54 +564,62 @@ void Generator::pop_home_object()
m_home_objects.take_last(); m_home_objects.take_last();
} }
void Generator::emit_new_function(FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name) void Generator::emit_new_function(Operand dst, FunctionExpression const& function_node, Optional<IdentifierTableIndex> lhs_name)
{ {
if (m_home_objects.is_empty()) if (m_home_objects.is_empty()) {
emit<Op::NewFunction>(function_node, lhs_name); emit<Op::NewFunction>(dst, function_node, lhs_name);
else } else {
emit<Op::NewFunction>(function_node, lhs_name, m_home_objects.last()); emit<Op::NewFunction>(dst, function_node, lhs_name, m_home_objects.last());
}
} }
CodeGenerationErrorOr<void> Generator::emit_named_evaluation_if_anonymous_function(Expression const& expression, Optional<IdentifierTableIndex> lhs_name) CodeGenerationErrorOr<Optional<Operand>> Generator::emit_named_evaluation_if_anonymous_function(Expression const& expression, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> preferred_dst)
{ {
if (is<FunctionExpression>(expression)) { if (is<FunctionExpression>(expression)) {
auto const& function_expression = static_cast<FunctionExpression const&>(expression); auto const& function_expression = static_cast<FunctionExpression const&>(expression);
if (!function_expression.has_name()) { if (!function_expression.has_name()) {
FIXME_NEWBC TRY(function_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); return TRY(function_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name), preferred_dst)).value();
return {};
} }
} }
if (is<ClassExpression>(expression)) { if (is<ClassExpression>(expression)) {
auto const& class_expression = static_cast<ClassExpression const&>(expression); auto const& class_expression = static_cast<ClassExpression const&>(expression);
if (!class_expression.has_name()) { if (!class_expression.has_name()) {
FIXME_NEWBC TRY(class_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name))); return TRY(class_expression.generate_bytecode_with_lhs_name(*this, move(lhs_name), preferred_dst)).value();
return {};
} }
} }
FIXME_NEWBC TRY(expression.generate_bytecode(*this)); return expression.generate_bytecode(*this, preferred_dst);
return {};
} }
void Generator::emit_get_by_id(IdentifierTableIndex id) void Generator::emit_get_by_id(Operand dst, Operand base, IdentifierTableIndex id)
{ {
emit<Op::GetById>(id, m_next_property_lookup_cache++); emit<Op::GetById>(dst, base, id, m_next_property_lookup_cache++);
} }
void Generator::emit_get_by_id_with_this(IdentifierTableIndex id, Register this_reg) void Generator::emit_get_by_id_with_this(Operand dst, Operand base, IdentifierTableIndex id, Operand this_value)
{ {
emit<Op::GetByIdWithThis>(id, this_reg, m_next_property_lookup_cache++); emit<Op::GetByIdWithThis>(dst, base, id, this_value, m_next_property_lookup_cache++);
} }
void Generator::emit_iterator_value() void Generator::emit_iterator_value(Operand dst, Operand result)
{ {
emit_get_by_id(intern_identifier("value"sv)); emit_get_by_id(dst, result, intern_identifier("value"sv));
} }
void Generator::emit_iterator_complete() void Generator::emit_iterator_complete(Operand dst, Operand result)
{ {
emit_get_by_id(intern_identifier("done"sv)); emit_get_by_id(dst, result, intern_identifier("done"sv));
}
bool Generator::is_local_initialized(u32 local_index) const
{
return m_initialized_locals.find(local_index) != m_initialized_locals.end();
}
void Generator::set_local_initialized(u32 local_index)
{
m_initialized_locals.set(local_index);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021-2024, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -30,10 +30,13 @@ public:
Function, Function,
Block, Block,
}; };
static CodeGenerationErrorOr<NonnullGCPtr<Executable>> generate(VM&, ASTNode const&, FunctionKind = FunctionKind::Normal); static CodeGenerationErrorOr<NonnullGCPtr<Executable>> generate(VM&, ASTNode const&, ReadonlySpan<FunctionParameter> parameters, FunctionKind = FunctionKind::Normal);
Register allocate_register(); Register allocate_register();
void set_local_initialized(u32 local_index);
[[nodiscard]] bool is_local_initialized(u32 local_index) const;
class SourceLocationScope { class SourceLocationScope {
public: public:
SourceLocationScope(Generator&, ASTNode const& node); SourceLocationScope(Generator&, ASTNode const& node);
@ -77,11 +80,11 @@ public:
} }
template<typename OpType, typename... Args> template<typename OpType, typename... Args>
void emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args) void emit_with_extra_operand_slots(size_t extra_operand_slots, Args&&... args)
{ {
VERIFY(!is_current_block_terminated()); VERIFY(!is_current_block_terminated());
size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_register_slots * sizeof(Register), alignof(void*)); size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_operand_slots * sizeof(Operand), alignof(void*));
size_t slot_offset = m_current_basic_block->size(); size_t slot_offset = m_current_basic_block->size();
grow(size_to_allocate); grow(size_to_allocate);
void* slot = m_current_basic_block->data() + slot_offset; void* slot = m_current_basic_block->data() + slot_offset;
@ -92,30 +95,29 @@ public:
op->set_source_record({ m_current_ast_node->start_offset(), m_current_ast_node->end_offset() }); op->set_source_record({ m_current_ast_node->start_offset(), m_current_ast_node->end_offset() });
} }
struct ReferenceRegisters { struct ReferenceOperands {
Register base; // [[Base]] Optional<Operand> base {}; // [[Base]]
Optional<Register> referenced_name; // [[ReferencedName]] Optional<Operand> referenced_name {}; // [[ReferencedName]] as an operand
Register this_value; // [[ThisValue]] Optional<IdentifierTableIndex> referenced_identifier {}; // [[ReferencedName]] as an identifier
Optional<IdentifierTableIndex> referenced_private_identifier {}; // [[ReferencedName]] as a private identifier
Optional<Operand> this_value {}; // [[ThisValue]]
Optional<Operand> loaded_value {}; // Loaded value, if we've performed a load.
}; };
enum class CollectRegisters { CodeGenerationErrorOr<ReferenceOperands> emit_load_from_reference(JS::ASTNode const&, Optional<Operand> preferred_dst = {});
Yes, CodeGenerationErrorOr<void> emit_store_to_reference(JS::ASTNode const&, Operand value);
No CodeGenerationErrorOr<void> emit_store_to_reference(ReferenceOperands const&, Operand value);
};
CodeGenerationErrorOr<Optional<ReferenceRegisters>> emit_load_from_reference(JS::ASTNode const&, CollectRegisters);
CodeGenerationErrorOr<Optional<Operand>> emit_store_to_reference(JS::ASTNode const&);
CodeGenerationErrorOr<Optional<Operand>> emit_store_to_reference(ReferenceRegisters const&);
CodeGenerationErrorOr<Optional<Operand>> emit_delete_reference(JS::ASTNode const&); CodeGenerationErrorOr<Optional<Operand>> emit_delete_reference(JS::ASTNode const&);
CodeGenerationErrorOr<ReferenceRegisters> emit_super_reference(MemberExpression const&); CodeGenerationErrorOr<ReferenceOperands> emit_super_reference(MemberExpression const&);
void emit_set_variable(JS::Identifier const& identifier, Bytecode::Op::SetVariable::InitializationMode initialization_mode = Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Op::EnvironmentMode mode = Bytecode::Op::EnvironmentMode::Lexical); void emit_set_variable(JS::Identifier const& identifier, Operand value, Bytecode::Op::SetVariable::InitializationMode initialization_mode = Bytecode::Op::SetVariable::InitializationMode::Set, Bytecode::Op::EnvironmentMode mode = Bytecode::Op::EnvironmentMode::Lexical);
void push_home_object(Register); void push_home_object(Operand);
void pop_home_object(); void pop_home_object();
void emit_new_function(JS::FunctionExpression const&, Optional<IdentifierTableIndex> lhs_name); void emit_new_function(Operand dst, JS::FunctionExpression const&, Optional<IdentifierTableIndex> lhs_name);
CodeGenerationErrorOr<void> emit_named_evaluation_if_anonymous_function(Expression const&, Optional<IdentifierTableIndex> lhs_name); CodeGenerationErrorOr<Optional<Operand>> emit_named_evaluation_if_anonymous_function(Expression const&, Optional<IdentifierTableIndex> lhs_name, Optional<Operand> preferred_dst = {});
void begin_continuable_scope(Label continue_target, Vector<DeprecatedFlyString> const& language_label_set); void begin_continuable_scope(Label continue_target, Vector<DeprecatedFlyString> const& language_label_set);
void end_continuable_scope(); void end_continuable_scope();
@ -231,21 +233,28 @@ public:
m_boundaries.take_last(); m_boundaries.take_last();
} }
void emit_get_by_id(IdentifierTableIndex); void emit_get_by_id(Operand dst, Operand base, IdentifierTableIndex);
void emit_get_by_id_with_this(IdentifierTableIndex, Register);
void emit_iterator_value(); void emit_get_by_id_with_this(Operand dst, Operand base, IdentifierTableIndex, Operand this_value);
void emit_iterator_complete();
void emit_iterator_value(Operand dst, Operand result);
void emit_iterator_complete(Operand dst, Operand result);
[[nodiscard]] size_t next_global_variable_cache() { return m_next_global_variable_cache++; } [[nodiscard]] size_t next_global_variable_cache() { return m_next_global_variable_cache++; }
[[nodiscard]] size_t next_environment_variable_cache() { return m_next_environment_variable_cache++; } [[nodiscard]] size_t next_environment_variable_cache() { return m_next_environment_variable_cache++; }
[[nodiscard]] size_t next_property_lookup_cache() { return m_next_property_lookup_cache++; } [[nodiscard]] size_t next_property_lookup_cache() { return m_next_property_lookup_cache++; }
[[nodiscard]] Operand add_constant(Value value) enum class DeduplicateConstant {
Yes,
No,
};
[[nodiscard]] Operand add_constant(Value value, DeduplicateConstant deduplicate_constant = DeduplicateConstant::Yes)
{ {
for (size_t i = 0; i < m_constants.size(); ++i) { if (deduplicate_constant == DeduplicateConstant::Yes) {
if (m_constants[i] == value) for (size_t i = 0; i < m_constants.size(); ++i) {
return Operand(Operand::Type::Constant, i); if (m_constants[i] == value)
return Operand(Operand::Type::Constant, i);
}
} }
m_constants.append(value); m_constants.append(value);
return Operand(Operand::Type::Constant, m_constants.size() - 1); return Operand(Operand::Type::Constant, m_constants.size() - 1);
@ -288,7 +297,9 @@ private:
Vector<LabelableScope> m_continuable_scopes; Vector<LabelableScope> m_continuable_scopes;
Vector<LabelableScope> m_breakable_scopes; Vector<LabelableScope> m_breakable_scopes;
Vector<BlockBoundaryType> m_boundaries; Vector<BlockBoundaryType> m_boundaries;
Vector<Register> m_home_objects; Vector<Operand> m_home_objects;
HashTable<u32> m_initialized_locals;
}; };
} }

View file

@ -14,7 +14,7 @@
#define ENUMERATE_BYTECODE_OPS(O) \ #define ENUMERATE_BYTECODE_OPS(O) \
O(Add) \ O(Add) \
O(Append) \ O(ArrayAppend) \
O(AsyncIteratorClose) \ O(AsyncIteratorClose) \
O(Await) \ O(Await) \
O(BitwiseAnd) \ O(BitwiseAnd) \
@ -37,6 +37,8 @@
O(DeleteByValueWithThis) \ O(DeleteByValueWithThis) \
O(DeleteVariable) \ O(DeleteVariable) \
O(Div) \ O(Div) \
O(Dump) \
O(End) \
O(EnterUnwindContext) \ O(EnterUnwindContext) \
O(EnterObjectEnvironment) \ O(EnterObjectEnvironment) \
O(Exp) \ O(Exp) \
@ -55,7 +57,6 @@
O(GetPrivateById) \ O(GetPrivateById) \
O(GetVariable) \ O(GetVariable) \
O(GetGlobal) \ O(GetGlobal) \
O(GetLocal) \
O(GreaterThan) \ O(GreaterThan) \
O(GreaterThanEquals) \ O(GreaterThanEquals) \
O(HasPrivateId) \ O(HasPrivateId) \
@ -67,7 +68,7 @@
O(IteratorNext) \ O(IteratorNext) \
O(IteratorToArray) \ O(IteratorToArray) \
O(Jump) \ O(Jump) \
O(JumpConditional) \ O(JumpIf) \
O(JumpNullish) \ O(JumpNullish) \
O(JumpUndefined) \ O(JumpUndefined) \
O(LeaveLexicalEnvironment) \ O(LeaveLexicalEnvironment) \
@ -75,11 +76,10 @@
O(LeftShift) \ O(LeftShift) \
O(LessThan) \ O(LessThan) \
O(LessThanEquals) \ O(LessThanEquals) \
O(Load) \
O(LoadImmediate) \
O(LooselyEquals) \ O(LooselyEquals) \
O(LooselyInequals) \ O(LooselyInequals) \
O(Mod) \ O(Mod) \
O(Mov) \
O(Mul) \ O(Mul) \
O(NewArray) \ O(NewArray) \
O(NewBigInt) \ O(NewBigInt) \
@ -103,7 +103,6 @@
O(ScheduleJump) \ O(ScheduleJump) \
O(SetVariable) \ O(SetVariable) \
O(SetLocal) \ O(SetLocal) \
O(Store) \
O(StrictlyEquals) \ O(StrictlyEquals) \
O(StrictlyInequals) \ O(StrictlyInequals) \
O(Sub) \ O(Sub) \
@ -111,10 +110,10 @@
O(Throw) \ O(Throw) \
O(ThrowIfNotObject) \ O(ThrowIfNotObject) \
O(ThrowIfNullish) \ O(ThrowIfNullish) \
O(ThrowIfTDZ) \
O(ToNumeric) \ O(ToNumeric) \
O(Typeof) \ O(Typeof) \
O(TypeofVariable) \ O(TypeofVariable) \
O(TypeofLocal) \
O(UnaryMinus) \ O(UnaryMinus) \
O(UnaryPlus) \ O(UnaryPlus) \
O(UnsignedRightShift) \ O(UnsignedRightShift) \

File diff suppressed because it is too large Load diff

View file

@ -89,7 +89,7 @@ public:
void enter_unwind_context(); void enter_unwind_context();
void leave_unwind_context(); void leave_unwind_context();
void catch_exception(); void catch_exception(Operand dst);
void enter_object_environment(Object&); void enter_object_environment(Object&);
@ -130,6 +130,6 @@ private:
extern bool g_dump_bytecode; extern bool g_dump_bytecode;
ThrowCompletionOr<NonnullGCPtr<Bytecode::Executable>> compile(VM&, ASTNode const& no, JS::FunctionKind kind, DeprecatedFlyString const& name); ThrowCompletionOr<NonnullGCPtr<Bytecode::Executable>> compile(VM&, ASTNode const&, ReadonlySpan<FunctionParameter>, JS::FunctionKind kind, DeprecatedFlyString const& name);
} }

File diff suppressed because it is too large Load diff

View file

@ -685,7 +685,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
// 29. If result.[[Type]] is normal, then // 29. If result.[[Type]] is normal, then
// a. Set result to the result of evaluating body. // a. Set result to the result of evaluating body.
auto executable_result = Bytecode::Generator::generate(vm, program); auto executable_result = Bytecode::Generator::generate(vm, program, {});
if (executable_result.is_error()) if (executable_result.is_error())
return vm.throw_completion<InternalError>(ErrorType::NotImplemented, TRY_OR_THROW_OOM(vm, executable_result.error().to_string())); return vm.throw_completion<InternalError>(ErrorType::NotImplemented, TRY_OR_THROW_OOM(vm, executable_result.error().to_string()));

View file

@ -1099,7 +1099,7 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
if constexpr (!IsCallableWithArguments<T, Completion>) { if constexpr (!IsCallableWithArguments<T, Completion>) {
// a. Let result be the result of evaluating asyncBody. // a. Let result be the result of evaluating asyncBody.
// FIXME: Cache this executable somewhere. // FIXME: Cache this executable somewhere.
auto maybe_executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"sv); auto maybe_executable = Bytecode::compile(vm, async_body, {}, FunctionKind::Async, "AsyncBlockStart"sv);
if (maybe_executable.is_error()) if (maybe_executable.is_error())
result = maybe_executable.release_error(); result = maybe_executable.release_error();
else else
@ -1196,7 +1196,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
if (!parameter.default_value) if (!parameter.default_value)
continue; continue;
if (parameter.bytecode_executable.is_null()) { if (parameter.bytecode_executable.is_null()) {
auto executable = TRY(Bytecode::compile(vm, *parameter.default_value, FunctionKind::Normal, ByteString::formatted("default parameter #{} for {}", default_parameter_index++, m_name))); auto executable = TRY(Bytecode::compile(vm, *parameter.default_value, {}, FunctionKind::Normal, ByteString::formatted("default parameter #{} for {}", default_parameter_index++, m_name)));
const_cast<FunctionParameter&>(parameter).bytecode_executable = executable; const_cast<FunctionParameter&>(parameter).bytecode_executable = executable;
m_default_parameter_bytecode_executables.append(move(executable)); m_default_parameter_bytecode_executables.append(move(executable));
} else { } else {
@ -1218,7 +1218,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
if (!m_bytecode_executable) { if (!m_bytecode_executable) {
if (!m_ecmascript_code->bytecode_executable()) if (!m_ecmascript_code->bytecode_executable())
const_cast<Statement&>(*m_ecmascript_code).set_bytecode_executable(TRY(Bytecode::compile(vm, *m_ecmascript_code, m_kind, m_name))); const_cast<Statement&>(*m_ecmascript_code).set_bytecode_executable(TRY(Bytecode::compile(vm, *m_ecmascript_code, m_formal_parameters, m_kind, m_name)));
m_bytecode_executable = m_ecmascript_code->bytecode_executable(); m_bytecode_executable = m_ecmascript_code->bytecode_executable();
} }

View file

@ -174,7 +174,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex
// 17. If result.[[Type]] is normal, then // 17. If result.[[Type]] is normal, then
if (!eval_result.is_throw_completion()) { if (!eval_result.is_throw_completion()) {
// a. Set result to the result of evaluating body. // a. Set result to the result of evaluating body.
auto maybe_executable = Bytecode::compile(vm, program, FunctionKind::Normal, "ShadowRealmEval"sv); auto maybe_executable = Bytecode::compile(vm, program, {}, FunctionKind::Normal, "ShadowRealmEval"sv);
if (maybe_executable.is_error()) if (maybe_executable.is_error())
result = maybe_executable.release_error(); result = maybe_executable.release_error();
else { else {

View file

@ -286,7 +286,7 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern
ThrowCompletionOr<Value> VM::execute_ast_node(ASTNode const& node) ThrowCompletionOr<Value> VM::execute_ast_node(ASTNode const& node)
{ {
auto executable = TRY(Bytecode::compile(*this, node, FunctionKind::Normal, ""sv)); auto executable = TRY(Bytecode::compile(*this, node, {}, FunctionKind::Normal, ""sv));
auto result_or_error = bytecode_interpreter().run_and_return_frame(*executable, nullptr); auto result_or_error = bytecode_interpreter().run_and_return_frame(*executable, nullptr);
if (result_or_error.value.is_error()) if (result_or_error.value.is_error())
return result_or_error.value.release_error(); return result_or_error.value.release_error();

View file

@ -711,7 +711,7 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GCPtr<PromiseCa
// c. Let result be the result of evaluating module.[[ECMAScriptCode]]. // c. Let result be the result of evaluating module.[[ECMAScriptCode]].
Completion result; Completion result;
auto maybe_executable = Bytecode::compile(vm, m_ecmascript_code, FunctionKind::Normal, "ShadowRealmEval"sv); auto maybe_executable = Bytecode::compile(vm, m_ecmascript_code, {}, FunctionKind::Normal, "ShadowRealmEval"sv);
if (maybe_executable.is_error()) if (maybe_executable.is_error())
result = maybe_executable.release_error(); result = maybe_executable.release_error();
else { else {