diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 5b2958f6c5..3c81dae364 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -344,7 +344,7 @@ Bytecode::CodeGenerationErrorOr SuperCall::generate_bytecode(Bytecode::Gen TRY(arguments_to_array_for_call(generator, m_arguments)); } - generator.emit(m_is_synthetic == IsPartOfSyntheticConstructor::Yes); + generator.emit(m_is_synthetic == IsPartOfSyntheticConstructor::Yes); return {}; } @@ -1465,20 +1465,20 @@ Bytecode::CodeGenerationErrorOr CallExpression::generate_bytecode(Bytecode TRY(arguments_to_array_for_call(generator, arguments())); - Bytecode::Op::Call::CallType call_type; + Bytecode::Op::CallType call_type; if (is(*this)) { - call_type = Bytecode::Op::Call::CallType::Construct; + call_type = Bytecode::Op::CallType::Construct; } else if (m_callee->is_identifier() && static_cast(*m_callee).string() == "eval"sv) { - call_type = Bytecode::Op::Call::CallType::DirectEval; + call_type = Bytecode::Op::CallType::DirectEval; } else { - call_type = Bytecode::Op::Call::CallType::Call; + call_type = Bytecode::Op::CallType::Call; } Optional expression_string_index; if (auto expression_string = this->expression_string(); expression_string.has_value()) expression_string_index = generator.intern_string(expression_string.release_value()); - generator.emit(call_type, callee_reg, this_reg, expression_string_index); + generator.emit(call_type, callee_reg, this_reg, expression_string_index); return {}; } @@ -1582,7 +1582,7 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod // i. Let innerResult be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »). generator.emit_with_extra_register_slots(2, AK::Array { received_completion_value_register, received_completion_value_register }); - generator.emit(Bytecode::Op::Call::CallType::Call, next_method_register, iterator_register); + generator.emit(Bytecode::Op::CallType::Call, next_method_register, iterator_register); // FIXME: ii. If generatorKind is async, set innerResult to ? Await(innerResult). @@ -1654,7 +1654,7 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod // 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). generator.emit_with_extra_register_slots(2, AK::Array { received_completion_value_register, received_completion_value_register }); - generator.emit(Bytecode::Op::Call::CallType::Call, throw_method_register, iterator_register); + generator.emit(Bytecode::Op::CallType::Call, throw_method_register, iterator_register); // FIXME: 2. If generatorKind is async, set innerResult to ? Await(innerResult). @@ -1742,7 +1742,7 @@ Bytecode::CodeGenerationErrorOr YieldExpression::generate_bytecode(Bytecod // iv. Let innerReturnResult be ? Call(return, iterator, « received.[[Value]] »). generator.emit_with_extra_register_slots(2, AK::Array { received_completion_value_register, received_completion_value_register }); - generator.emit(Bytecode::Op::Call::CallType::Call, return_method_register, iterator_register); + generator.emit(Bytecode::Op::CallType::Call, return_method_register, iterator_register); // FIXME: v. If generatorKind is async, set innerReturnResult to ? Await(innerReturnResult). @@ -2047,7 +2047,7 @@ Bytecode::CodeGenerationErrorOr TaggedTemplateLiteral::generate_bytecode(B else generator.emit(); - generator.emit(Bytecode::Op::Call::CallType::Call, tag_reg, this_reg); + generator.emit(Bytecode::Op::CallType::Call, tag_reg, this_reg); return {}; } @@ -2815,7 +2815,7 @@ static Bytecode::CodeGenerationErrorOr generate_optional_chain(Bytecode::G TRY(reference.visit( [&](OptionalChain::Call const& call) -> Bytecode::CodeGenerationErrorOr { TRY(arguments_to_array_for_call(generator, call.arguments)); - generator.emit(Bytecode::Op::Call::CallType::Call, current_value_register, current_base_register); + generator.emit(Bytecode::Op::CallType::Call, current_value_register, current_base_register); generator.emit(current_value_register); diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index dff8d1dd71..3fee52806f 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -18,7 +18,7 @@ O(BitwiseOr) \ O(BitwiseXor) \ O(BlockDeclarationInstantiation) \ - O(Call) \ + O(CallWithArgumentArray) \ O(ConcatString) \ O(ContinuePendingUnwind) \ O(CopyObjectExcludingProperties) \ @@ -89,7 +89,7 @@ O(StrictlyEquals) \ O(StrictlyInequals) \ O(Sub) \ - O(SuperCall) \ + O(SuperCallWithArgumentArray) \ O(Throw) \ O(ThrowIfNotObject) \ O(ThrowIfNullish) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 2ce37b857c..7fecd59ba5 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -694,7 +694,7 @@ static MarkedVector argument_list_evaluation(Bytecode::Interpreter& inter return argument_values; } -Completion Call::throw_type_error_for_callee(Bytecode::Interpreter& interpreter, StringView callee_type) const +Completion CallWithArgumentArray::throw_type_error_for_callee(Bytecode::Interpreter& interpreter, StringView callee_type) const { auto& vm = interpreter.vm(); auto callee = interpreter.reg(m_callee); @@ -705,7 +705,7 @@ Completion Call::throw_type_error_for_callee(Bytecode::Interpreter& interpreter, return vm.throw_completion(ErrorType::IsNotA, TRY_OR_THROW_OOM(vm, callee.to_string_without_side_effects()), callee_type); } -ThrowCompletionOr Call::execute_impl(Bytecode::Interpreter& interpreter) const +ThrowCompletionOr CallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); @@ -738,7 +738,7 @@ ThrowCompletionOr Call::execute_impl(Bytecode::Interpreter& interpreter) c } // 13.3.7.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation -ThrowCompletionOr SuperCall::execute_impl(Bytecode::Interpreter& interpreter) const +ThrowCompletionOr SuperCallWithArgumentArray::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); // 1. Let newTarget be GetNewTarget(). @@ -896,7 +896,7 @@ void CopyObjectExcludingProperties::replace_references_impl(Register from, Regis } } -void Call::replace_references_impl(Register from, Register to) +void CallWithArgumentArray::replace_references_impl(Register from, Register to) { if (m_callee == from) m_callee = to; @@ -1383,30 +1383,30 @@ DeprecatedString JumpUndefined::to_deprecated_string_impl(Bytecode::Executable c return DeprecatedString::formatted("JumpUndefined undefined:{} not undefined:{}", true_string, false_string); } -DeprecatedString Call::to_deprecated_string_impl(Bytecode::Executable const& executable) const +DeprecatedString CallWithArgumentArray::to_deprecated_string_impl(Bytecode::Executable const& executable) const { StringView type; switch (m_type) { - case Call::CallType::Call: + case CallType::Call: type = ""sv; break; - case Call::CallType::Construct: + case CallType::Construct: type = " (Construct)"sv; break; - case Call::CallType::DirectEval: + case CallType::DirectEval: type = " (DirectEval)"sv; break; } if (m_expression_string.has_value()) - return DeprecatedString::formatted("Call{} callee:{}, this:{}, arguments:[...acc] ({})", type, m_callee, m_this_value, executable.get_string(m_expression_string.value())); + return DeprecatedString::formatted("CallWithArgumentArray{} callee:{}, this:{}, arguments:[...acc] ({})", type, m_callee, m_this_value, executable.get_string(m_expression_string.value())); - return DeprecatedString::formatted("Call{} callee:{}, this:{}, arguments:[...acc]", type, m_callee, m_this_value); + return DeprecatedString::formatted("CallWithArgumentArray{} callee:{}, this:{}, arguments:[...acc]", type, m_callee, m_this_value); } -DeprecatedString SuperCall::to_deprecated_string_impl(Bytecode::Executable const&) const +DeprecatedString SuperCallWithArgumentArray::to_deprecated_string_impl(Bytecode::Executable const&) const { - return "SuperCall arguments:[...acc]"sv; + return "SuperCallWithArgumentArray arguments:[...acc]"sv; } DeprecatedString NewFunction::to_deprecated_string_impl(Bytecode::Executable const&) const diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index a7aaec1143..ff4cf1cce5 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -770,17 +770,16 @@ public: DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; }; -// NOTE: This instruction is variable-width depending on the number of arguments! -class Call final : public Instruction { -public: - enum class CallType { - Call, - Construct, - DirectEval, - }; +enum class CallType { + Call, + Construct, + DirectEval, +}; - Call(CallType type, Register callee, Register this_value, Optional expression_string = {}) - : Instruction(Type::Call) +class CallWithArgumentArray final : public Instruction { +public: + CallWithArgumentArray(CallType type, Register callee, Register this_value, Optional expression_string = {}) + : Instruction(Type::CallWithArgumentArray) , m_callee(callee) , m_this_value(this_value) , m_type(type) @@ -802,11 +801,10 @@ private: Optional m_expression_string; }; -// NOTE: This instruction is variable-width depending on the number of arguments! -class SuperCall : public Instruction { +class SuperCallWithArgumentArray : public Instruction { public: - explicit SuperCall(bool is_synthetic) - : Instruction(Type::SuperCall) + explicit SuperCallWithArgumentArray(bool is_synthetic) + : Instruction(Type::SuperCallWithArgumentArray) , m_is_synthetic(is_synthetic) { } diff --git a/Userland/Libraries/LibJS/Bytecode/Pass/LoadElimination.cpp b/Userland/Libraries/LibJS/Bytecode/Pass/LoadElimination.cpp index 10db412cbe..c91e943ce9 100644 --- a/Userland/Libraries/LibJS/Bytecode/Pass/LoadElimination.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Pass/LoadElimination.cpp @@ -124,7 +124,7 @@ static NonnullOwnPtr eliminate_loads(BasicBlock const& block, size_t // Attribute accesses (`a.o` or `a[o]`) may result in calls to getters or setters // or may trigger proxies // So these are treated like calls - case Call: + case CallWithArgumentArray: // Calls, especially to local functions and eval, may poison visible and // cached variables, hence we need to clear the lookup cache after emitting them // FIXME: In strict mode and with better identifier metrics, we might be able