diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index b0e34fb794..74697c6138 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -13,6 +13,8 @@ #define ENUMERATE_BYTECODE_OPS(O) \ O(Add) \ O(Append) \ + O(AsyncIteratorClose) \ + O(Await) \ O(BitwiseAnd) \ O(BitwiseNot) \ O(BitwiseOr) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 1cf54287f6..6152b5f61c 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1130,12 +1130,15 @@ ThrowCompletionOr Yield::execute_impl(Bytecode::Interpreter& interpreter) auto yielded_value = interpreter.accumulator().value_or(js_undefined()); auto object = Object::create(interpreter.realm(), nullptr); object->define_direct_property("result", yielded_value, JS::default_attributes); + if (m_continuation_label.has_value()) // FIXME: If we get a pointer, which is not accurately representable as a double // will cause this to explode object->define_direct_property("continuation", Value(static_cast(reinterpret_cast(&m_continuation_label->block()))), JS::default_attributes); else object->define_direct_property("continuation", Value(0), JS::default_attributes); + + object->define_direct_property("isAwait", Value(false), JS::default_attributes); interpreter.do_return(object); return {}; } @@ -1146,6 +1149,25 @@ void Yield::replace_references_impl(BasicBlock const& from, BasicBlock const& to m_continuation_label = Label { to }; } +ThrowCompletionOr Await::execute_impl(Bytecode::Interpreter& interpreter) const +{ + auto yielded_value = interpreter.accumulator().value_or(js_undefined()); + auto object = Object::create(interpreter.realm(), nullptr); + object->define_direct_property("result", yielded_value, JS::default_attributes); + // FIXME: If we get a pointer, which is not accurately representable as a double + // will cause this to explode + object->define_direct_property("continuation", Value(static_cast(reinterpret_cast(&m_continuation_label.block()))), JS::default_attributes); + object->define_direct_property("isAwait", Value(true), JS::default_attributes); + interpreter.do_return(object); + return {}; +} + +void Await::replace_references_impl(BasicBlock const& from, BasicBlock const& to) +{ + if (&m_continuation_label.block() == &from) + m_continuation_label = Label { to }; +} + ThrowCompletionOr GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); @@ -1353,6 +1375,17 @@ ThrowCompletionOr IteratorClose::execute_impl(Bytecode::Interpreter& inter return {}; } +ThrowCompletionOr AsyncIteratorClose::execute_impl(Bytecode::Interpreter& interpreter) const +{ + auto& vm = interpreter.vm(); + auto iterator_object = TRY(interpreter.accumulator().to_object(vm)); + auto iterator = object_to_iterator(vm, iterator_object); + + // FIXME: Return the value of the resulting completion. (Note that m_completion_value can be empty!) + TRY(async_iterator_close(vm, iterator, Completion { m_completion_type, m_completion_value, {} })); + return {}; +} + ThrowCompletionOr IteratorNext::execute_impl(Bytecode::Interpreter& interpreter) const { auto& vm = interpreter.vm(); @@ -1806,6 +1839,11 @@ DeprecatedString Yield::to_deprecated_string_impl(Bytecode::Executable const&) c return DeprecatedString::formatted("Yield return"); } +DeprecatedString Await::to_deprecated_string_impl(Bytecode::Executable const&) const +{ + return DeprecatedString::formatted("Await continuation:@{}", m_continuation_label.block().name()); +} + DeprecatedString GetByValue::to_deprecated_string_impl(Bytecode::Executable const&) const { return DeprecatedString::formatted("GetByValue base:{}", m_base); @@ -1873,6 +1911,15 @@ DeprecatedString IteratorClose::to_deprecated_string_impl(Bytecode::Executable c return DeprecatedString::formatted("IteratorClose completion_type={} completion_value={}", to_underlying(m_completion_type), completion_value_string); } +DeprecatedString AsyncIteratorClose::to_deprecated_string_impl(Bytecode::Executable const&) const +{ + if (!m_completion_value.has_value()) + return DeprecatedString::formatted("AsyncIteratorClose completion_type={} completion_value=", to_underlying(m_completion_type)); + + auto completion_value_string = m_completion_value->to_string_without_side_effects().release_value_but_fixme_should_propagate_errors(); + return DeprecatedString::formatted("AsyncIteratorClose completion_type={} completion_value={}", to_underlying(m_completion_type), completion_value_string); +} + DeprecatedString IteratorNext::to_deprecated_string_impl(Executable const&) const { return "IteratorNext"; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index f466892e8d..7a54522dff 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1377,6 +1377,27 @@ private: Optional