Skip to content

Commit

Permalink
LibJS: Avoid returning Completions from more Bytecode instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendiadyoin1 authored and awesomekling committed May 15, 2024
1 parent 99579f1 commit 73fdd31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
18 changes: 7 additions & 11 deletions Userland/Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
handle_##name: \
{ \
auto& instruction = *reinterpret_cast<Op::name const*>(&bytecode[program_counter]); \
(void)instruction.execute_impl(*this); \
instruction.execute_impl(*this); \
DISPATCH_NEXT(name); \
}

Expand Down Expand Up @@ -638,20 +638,20 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)

handle_Await: {
auto& instruction = *reinterpret_cast<Op::Await const*>(&bytecode[program_counter]);
(void)instruction.execute_impl(*this);
instruction.execute_impl(*this);
will_yield = true;
goto run_finalizer_and_return;
}

handle_Return: {
auto& instruction = *reinterpret_cast<Op::Return const*>(&bytecode[program_counter]);
(void)instruction.execute_impl(*this);
instruction.execute_impl(*this);
goto run_finalizer_and_return;
}

handle_Yield: {
auto& instruction = *reinterpret_cast<Op::Yield const*>(&bytecode[program_counter]);
(void)instruction.execute_impl(*this);
instruction.execute_impl(*this);
// Note: A `yield` statement will not go through a finally statement,
// hence we need to set a flag to not do so,
// but we generate a Yield Operation in the case of returns in
Expand Down Expand Up @@ -1300,14 +1300,13 @@ void CreatePrivateEnvironment::execute_impl(Bytecode::Interpreter& interpreter)
running_execution_context.private_environment = new_private_environment(interpreter.vm(), outer_private_environment);
}

ThrowCompletionOr<void> CreateVariableEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
void CreateVariableEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto& running_execution_context = interpreter.running_execution_context();
auto var_environment = new_declarative_environment(*running_execution_context.lexical_environment);
var_environment->ensure_capacity(m_capacity);
running_execution_context.variable_environment = var_environment;
running_execution_context.lexical_environment = var_environment;
return {};
}

ThrowCompletionOr<void> EnterObjectEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
Expand Down Expand Up @@ -1768,7 +1767,7 @@ void LeaveUnwindContext::execute_impl(Bytecode::Interpreter& interpreter) const
interpreter.leave_unwind_context();
}

ThrowCompletionOr<void> Yield::execute_impl(Bytecode::Interpreter& interpreter) const
void Yield::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto yielded_value = interpreter.get(m_value).value_or(js_undefined());

Expand All @@ -1784,11 +1783,9 @@ ThrowCompletionOr<void> Yield::execute_impl(Bytecode::Interpreter& interpreter)

object->define_direct_property("isAwait", Value(false), JS::default_attributes);
interpreter.do_return(object);

return {};
}

ThrowCompletionOr<void> Await::execute_impl(Bytecode::Interpreter& interpreter) const
void Await::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto yielded_value = interpreter.get(m_argument).value_or(js_undefined());
auto object = Object::create(interpreter.realm(), nullptr);
Expand All @@ -1798,7 +1795,6 @@ ThrowCompletionOr<void> Await::execute_impl(Bytecode::Interpreter& interpreter)
object->define_direct_property("continuation", Value(m_continuation_label.address()), JS::default_attributes);
object->define_direct_property("isAwait", Value(true), JS::default_attributes);
interpreter.do_return(object);
return {};
}

ThrowCompletionOr<void> GetByValue::execute_impl(Bytecode::Interpreter& interpreter) const
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibJS/Bytecode/Op.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class CreateVariableEnvironment final : public Instruction {
{
}

ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
void execute_impl(Bytecode::Interpreter&) const;
ByteString to_byte_string_impl(Bytecode::Executable const&) const;

private:
Expand Down Expand Up @@ -2194,7 +2194,7 @@ class Yield final : public Instruction {
{
}

ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
void execute_impl(Bytecode::Interpreter&) const;
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
void visit_labels_impl(Function<void(Label&)> visitor)
{
Expand Down Expand Up @@ -2225,7 +2225,7 @@ class Await final : public Instruction {
{
}

ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
void execute_impl(Bytecode::Interpreter&) const;
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
void visit_labels_impl(Function<void(Label&)> visitor)
{
Expand Down

0 comments on commit 73fdd31

Please sign in to comment.