summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-02 21:37:50 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-03 21:50:50 +0100
commitda856d7742339bd107600ff3491d9274b4ecf676 (patch)
tree4ec2b2d4b996cda591a406389d74a97c72ff0fe4 /Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
parent95acb1ce885b2d2b833e6f4e3b12dfd41b50bc80 (diff)
downloadserenity-da856d7742339bd107600ff3491d9274b4ecf676.zip
LibJS: Update AST to use completions :^)
This is another major milestone on our journey towards removing global VM exception state :^) Does pretty much exactly what it says on the tin: updating ASTNode::execute() to return a Completion instead of a plain value. This will *also* allow us to eventually remove the non-standard unwinding mechanism and purely rely on the various completion types.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index 3fc1810ee3..cc11fa17a1 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@@ -564,7 +564,7 @@ ThrowCompletionOr<Value> perform_eval(Value x, GlobalObject& caller_realm, Calle
TemporaryChange scope_change_strict(vm.running_execution_context().is_strict_mode, strict_eval);
- Value eval_result;
+ Optional<Value> eval_result;
if (auto* bytecode_interpreter = Bytecode::Interpreter::current()) {
auto executable = JS::Bytecode::Generator::generate(program);
@@ -572,16 +572,16 @@ ThrowCompletionOr<Value> perform_eval(Value x, GlobalObject& caller_realm, Calle
if (JS::Bytecode::g_dump_bytecode)
executable.dump();
eval_result = TRY(bytecode_interpreter->run(executable));
+ // Turn potentially empty JS::Value from the bytecode interpreter into an empty Optional
+ if (eval_result.has_value() && eval_result->is_empty())
+ eval_result = {};
} else {
auto& ast_interpreter = vm.interpreter();
// FIXME: We need to use evaluate_statements() here because Program::execute() calls global_declaration_instantiation() when it shouldn't
- eval_result = program->evaluate_statements(ast_interpreter, caller_realm);
+ eval_result = TRY(program->evaluate_statements(ast_interpreter, caller_realm));
}
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
- else
- return eval_result.value_or(js_undefined());
+ return eval_result.value_or(js_undefined());
}
// 19.2.1.3 EvalDeclarationInstantiation ( body, varEnv, lexEnv, privateEnv, strict ), https://tc39.es/ecma262/#sec-evaldeclarationinstantiation