mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
LibJS+Everywhere: Remove VM::exception() and most related functions
This commit removes all exception related code: Remove VM::exception(), VM::throw_exception() etc. Any leftover throw_exception calls are moved to throw_completion. The one method left is clear_exception() which is now a no-op. Most of these calls are just to clear whatever exception might have been thrown when handling a Completion. So to have a cleaner commit this will be removed in a next commit. It also removes the actual Exception and TemporaryClearException classes since these are no longer used. In any spot where the exception was actually used an attempt was made to preserve that behavior. However since it is no longer tracked by the VM we cannot access exceptions which were thrown in previous calls. There are two such cases which might have different behavior: - In Web::DOM::Document::interpreter() the on_call_stack_emptied hook used to print any uncaught exception but this is now no longer possible as the VM does not store uncaught exceptions. - In js the code used to be interruptable by throwing an exception on the VM. This is no longer possible but was already somewhat fragile before as you could happen to throw an exception just before a VERIFY.
This commit is contained in:
parent
4ef1e8f226
commit
9264f9d24e
35 changed files with 145 additions and 349 deletions
|
@ -964,7 +964,6 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
|
|||
// 8. Set obj.[[Delete]] as specified in 10.4.4.5.
|
||||
// 9. Set obj.[[Prototype]] to %Object.prototype%.
|
||||
auto* object = vm.heap().allocate<ArgumentsObject>(global_object, global_object, environment);
|
||||
VERIFY(!vm.exception());
|
||||
|
||||
// 14. Let index be 0.
|
||||
// 15. Repeat, while index < len,
|
||||
|
|
|
@ -26,13 +26,11 @@ public:
|
|||
template<typename T>
|
||||
static Array* create_from(GlobalObject& global_object, Span<T const> elements, Function<Value(T const&)> map_fn)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto values = MarkedValueList { global_object.heap() };
|
||||
values.ensure_capacity(elements.size());
|
||||
for (auto const& element : elements) {
|
||||
for (auto const& element : elements)
|
||||
values.append(map_fn(element));
|
||||
VERIFY(!vm.exception());
|
||||
}
|
||||
|
||||
return Array::create_from(global_object, values);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,10 +115,6 @@ ThrowCompletionOr<Value> await(GlobalObject& global_object, Value value)
|
|||
|
||||
if (success.value())
|
||||
return result;
|
||||
// NOTE: This is temporary until we remove VM::exception(). It's required as callers of
|
||||
// AwaitExpression still need to check for an exception rather than a completion
|
||||
// type as long as ASTNode::execute() returns a plain Value.
|
||||
vm.throw_exception(global_object, result);
|
||||
return throw_completion(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -551,7 +551,6 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
|
|||
});
|
||||
});
|
||||
|
||||
VERIFY(!vm.exception());
|
||||
auto* private_environment = callee_context.private_environment;
|
||||
for (auto& declaration : functions_to_initialize) {
|
||||
auto* function = ECMAScriptFunctionObject::create(global_object(), declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), lex_environment, private_environment, declaration.kind(), declaration.is_strict_mode(), declaration.might_need_arguments_object(), declaration.contains_direct_call_to_eval());
|
||||
|
@ -731,7 +730,6 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
|
|||
VERIFY(result.type() == Completion::Type::Throw);
|
||||
|
||||
// ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
|
||||
vm.clear_exception();
|
||||
MUST(call(global_object, promise_capability.reject, js_undefined(), *result.value()));
|
||||
}
|
||||
// g. Return.
|
||||
|
@ -781,14 +779,11 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
|
|||
m_bytecode_executable->dump();
|
||||
}
|
||||
auto result_and_frame = bytecode_interpreter->run_and_return_frame(*m_bytecode_executable, nullptr);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
|
||||
VERIFY(result_and_frame.frame != nullptr);
|
||||
if (result_and_frame.value.is_error()) {
|
||||
vm.throw_exception(bytecode_interpreter->global_object(), *result_and_frame.value.release_error().value());
|
||||
return throw_completion(vm.exception()->value());
|
||||
}
|
||||
if (result_and_frame.value.is_error())
|
||||
return result_and_frame.value.release_error();
|
||||
|
||||
auto result = result_and_frame.value.release_value();
|
||||
|
||||
// NOTE: Running the bytecode should eventually return a completion.
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/Exception.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
Exception::Exception(Value value)
|
||||
: m_value(value)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
m_traceback.ensure_capacity(vm.execution_context_stack().size());
|
||||
for (ssize_t i = vm.execution_context_stack().size() - 1; i >= 0; i--) {
|
||||
auto* context = vm.execution_context_stack()[i];
|
||||
auto function_name = context->function_name;
|
||||
if (function_name.is_empty())
|
||||
function_name = "<anonymous>";
|
||||
m_traceback.empend(
|
||||
move(function_name),
|
||||
// We might not have an AST node associated with the execution context, e.g. in promise
|
||||
// reaction jobs (which aren't called anywhere from the source code).
|
||||
// They're not going to generate any _unhandled_ exceptions though, so a meaningless
|
||||
// source range is fine.
|
||||
context->current_node ? context->current_node->source_range() : SourceRange {});
|
||||
}
|
||||
}
|
||||
|
||||
void Exception::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Cell::visit_edges(visitor);
|
||||
visitor.visit(m_value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibJS/SourceRange.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class Exception : public Cell {
|
||||
public:
|
||||
explicit Exception(Value);
|
||||
virtual ~Exception() override = default;
|
||||
|
||||
Value value() const { return m_value; }
|
||||
const Vector<TracebackFrame, 32>& traceback() const { return m_traceback; }
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "Exception"; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
Value m_value;
|
||||
Vector<TracebackFrame, 32> m_traceback;
|
||||
};
|
||||
|
||||
}
|
|
@ -104,8 +104,8 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
|
|||
|
||||
// Pretend that 'yield' returned the passed value, or threw
|
||||
if (value_to_throw.has_value()) {
|
||||
vm.throw_exception(global_object, value_to_throw.release_value());
|
||||
bytecode_interpreter->accumulator() = js_undefined();
|
||||
return throw_completion(value_to_throw.release_value());
|
||||
} else {
|
||||
bytecode_interpreter->accumulator() = next_argument.value_or(js_undefined());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <LibJS/Runtime/FunctionObject.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/IteratorOperations.h>
|
||||
#include <LibJS/Runtime/TemporaryClearException.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -141,10 +140,6 @@ static Completion iterator_close_impl(GlobalObject& global_object, Iterator cons
|
|||
// 2. Let iterator be iteratorRecord.[[Iterator]].
|
||||
auto* iterator = iterator_record.iterator;
|
||||
|
||||
// The callers of iterator_close() are often in an exceptional state.
|
||||
// Temporarily clear that exception for invocation(s) to Call.
|
||||
TemporaryClearException clear_exception(vm);
|
||||
|
||||
// 3. Let innerResult be GetMethod(iterator, "return").
|
||||
auto inner_result = ThrowCompletionOr<Value> { js_undefined() };
|
||||
auto get_method_result = Value(iterator).get_method(global_object, vm.names.return_);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <LibJS/Runtime/PropertyDescriptor.h>
|
||||
#include <LibJS/Runtime/ProxyObject.h>
|
||||
#include <LibJS/Runtime/Shape.h>
|
||||
#include <LibJS/Runtime/TemporaryClearException.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
namespace JS {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <LibJS/Runtime/PromiseConstructor.h>
|
||||
#include <LibJS/Runtime/PromiseReaction.h>
|
||||
#include <LibJS/Runtime/PromiseResolvingElementFunctions.h>
|
||||
#include <LibJS/Runtime/TemporaryClearException.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -209,7 +208,6 @@ static ThrowCompletionOr<Value> perform_promise_any(GlobalObject& global_object,
|
|||
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
|
||||
|
||||
// 3. Return ThrowCompletion(error).
|
||||
vm.throw_exception(global_object, error);
|
||||
return throw_completion(error);
|
||||
},
|
||||
[&](PromiseValueList& errors, RemainingElements& remaining_elements_count, Value next_promise, size_t index) {
|
||||
|
@ -304,14 +302,12 @@ ThrowCompletionOr<Object*> PromiseConstructor::construct(FunctionObject& new_tar
|
|||
auto [resolve_function, reject_function] = promise->create_resolving_functions();
|
||||
|
||||
// 9. Let completion be Call(executor, undefined, « resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]] »).
|
||||
(void)JS::call(global_object, executor.as_function(), js_undefined(), &resolve_function, &reject_function);
|
||||
auto completion = JS::call(global_object, executor.as_function(), js_undefined(), &resolve_function, &reject_function);
|
||||
|
||||
// 10. If completion is an abrupt completion, then
|
||||
if (auto* exception = vm.exception()) {
|
||||
vm.clear_exception();
|
||||
|
||||
if (completion.is_error()) {
|
||||
// a. Perform ? Call(resolvingFunctions.[[Reject]], undefined, « completion.[[Value]] »).
|
||||
TRY(JS::call(global_object, reject_function, js_undefined(), exception->value()));
|
||||
TRY(JS::call(global_object, reject_function, js_undefined(), *completion.release_error().value()));
|
||||
}
|
||||
|
||||
// 11. Return promise.
|
||||
|
|
|
@ -70,7 +70,7 @@ ThrowCompletionOr<Value> PromiseReactionJob::call()
|
|||
// f. If promiseCapability is undefined, then
|
||||
if (!promise_capability.has_value()) {
|
||||
// i. Assert: handlerResult is not an abrupt completion.
|
||||
VERIFY(!vm.exception());
|
||||
VERIFY(!handler_result.is_abrupt());
|
||||
|
||||
// ii. Return NormalCompletion(empty).
|
||||
dbgln_if(PROMISE_DEBUG, "[PromiseReactionJob @ {}]: Reaction has no PromiseCapability, returning empty value", this);
|
||||
|
|
|
@ -138,9 +138,8 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
|||
auto* promise = TRY(promise_resolve(global_object, constructor, result));
|
||||
|
||||
// iv. Let thrower be ! CreateBuiltinFunction(throwReason, 0, "", « »).
|
||||
auto* thrower = NativeFunction::create(global_object, "", [reason](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
||||
auto* thrower = NativeFunction::create(global_object, "", [reason](auto&, auto&) -> ThrowCompletionOr<Value> {
|
||||
// 1. Return ThrowCompletion(reason).
|
||||
vm.throw_exception(global_object, reason);
|
||||
return throw_completion(reason);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/Exception.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class TemporaryClearException {
|
||||
public:
|
||||
explicit TemporaryClearException(VM& vm)
|
||||
: m_vm(vm)
|
||||
, m_previous_exception(vm.exception())
|
||||
{
|
||||
m_vm.clear_exception();
|
||||
}
|
||||
|
||||
~TemporaryClearException()
|
||||
{
|
||||
if (m_previous_exception)
|
||||
m_vm.set_exception(*m_previous_exception);
|
||||
}
|
||||
|
||||
private:
|
||||
VM& m_vm;
|
||||
Exception* m_previous_exception;
|
||||
};
|
||||
|
||||
}
|
|
@ -26,7 +26,6 @@
|
|||
#include <LibJS/Runtime/PromiseReaction.h>
|
||||
#include <LibJS/Runtime/Reference.h>
|
||||
#include <LibJS/Runtime/Symbol.h>
|
||||
#include <LibJS/Runtime/TemporaryClearException.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibJS/SourceTextModule.h>
|
||||
#include <LibJS/SyntheticModule.h>
|
||||
|
@ -152,8 +151,6 @@ void VM::gather_roots(HashTable<Cell*>& roots)
|
|||
for (auto* string : m_single_ascii_character_strings)
|
||||
roots.set(string);
|
||||
|
||||
roots.set(m_exception);
|
||||
|
||||
auto gather_roots_from_execution_context_stack = [&roots](Vector<ExecutionContext*> const& stack) {
|
||||
for (auto& execution_context : stack) {
|
||||
if (execution_context->this_value.is_cell())
|
||||
|
@ -564,11 +561,6 @@ ThrowCompletionOr<void> VM::initialize_instance_elements(Object& object, ECMAScr
|
|||
return {};
|
||||
}
|
||||
|
||||
void VM::throw_exception(Exception& exception)
|
||||
{
|
||||
set_exception(exception);
|
||||
}
|
||||
|
||||
// 9.4.4 ResolveThisBinding ( ), https://tc39.es/ecma262/#sec-resolvethisbinding
|
||||
ThrowCompletionOr<Value> VM::resolve_this_binding(GlobalObject& global_object)
|
||||
{
|
||||
|
@ -610,9 +602,7 @@ bool VM::in_strict_mode() const
|
|||
void VM::run_queued_promise_jobs()
|
||||
{
|
||||
dbgln_if(PROMISE_DEBUG, "Running queued promise jobs");
|
||||
// Temporarily get rid of the exception, if any - job functions must be called
|
||||
// either way, and that can't happen if we already have an exception stored.
|
||||
TemporaryClearException temporary_clear_exception(*this);
|
||||
|
||||
while (!m_promise_jobs.is_empty()) {
|
||||
auto* job = m_promise_jobs.take_first();
|
||||
dbgln_if(PROMISE_DEBUG, "Calling promise job function @ {}", job);
|
||||
|
@ -633,15 +623,11 @@ void VM::run_queued_promise_jobs()
|
|||
// This doesn't match the spec, it actually defines that Job Abstract Closures must return
|
||||
// a normal completion. In reality that's not the case however, and all major engines clear
|
||||
// exceptions when running Promise jobs. See the commit where these two lines were initially
|
||||
// added for a much more detailed explanation.
|
||||
clear_exception();
|
||||
// added for a much more detailed explanation. (Hash: a53542e0a3fbd7bf22b685d87f0473e489e1cf42)
|
||||
|
||||
if (pushed_execution_context)
|
||||
pop_execution_context();
|
||||
}
|
||||
// Ensure no job has created a new exception, they must clean up after themselves.
|
||||
// If they don't, we help a little (see above) so that this assumption remains valid.
|
||||
VERIFY(!m_exception);
|
||||
}
|
||||
|
||||
// 9.5.4 HostEnqueuePromiseJob ( job, realm ), https://tc39.es/ecma262/#sec-hostenqueuepromisejob
|
||||
|
@ -654,7 +640,8 @@ void VM::run_queued_finalization_registry_cleanup_jobs()
|
|||
{
|
||||
while (!m_finalization_registry_cleanup_jobs.is_empty()) {
|
||||
auto* registry = m_finalization_registry_cleanup_jobs.take_first();
|
||||
registry->cleanup();
|
||||
// FIXME: Handle any uncatched exceptions here.
|
||||
(void)registry->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,8 +780,6 @@ ThrowCompletionOr<void> VM::link_and_eval_module(Module& module)
|
|||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Linking passed, now evaluating module {}", filepath);
|
||||
auto evaluated_or_error = module.evaluate(*this);
|
||||
|
||||
VERIFY(!exception());
|
||||
|
||||
if (evaluated_or_error.is_error())
|
||||
return evaluated_or_error.throw_completion();
|
||||
|
||||
|
@ -806,10 +791,8 @@ ThrowCompletionOr<void> VM::link_and_eval_module(Module& module)
|
|||
// FIXME: This will break if we start doing promises actually asynchronously.
|
||||
VERIFY(evaluated_value->state() != Promise::State::Pending);
|
||||
|
||||
if (evaluated_value->state() == Promise::State::Rejected) {
|
||||
VERIFY(!exception());
|
||||
if (evaluated_value->state() == Promise::State::Rejected)
|
||||
return JS::throw_completion(evaluated_value->result());
|
||||
}
|
||||
|
||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] Evaluating passed for module {}", module.filename());
|
||||
return {};
|
||||
|
@ -954,13 +937,10 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module,
|
|||
}
|
||||
}
|
||||
|
||||
VERIFY(!exception());
|
||||
// Note: If host_resolve_imported_module returns a module it has been loaded successfully and the next call in finish_dynamic_import will retrieve it again.
|
||||
auto module_or_error = host_resolve_imported_module(referencing_script_or_module, module_request);
|
||||
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] HostImportModuleDynamically(..., {}) -> {}", module_request.module_specifier, module_or_error.is_error() ? "failed" : "passed");
|
||||
if (module_or_error.is_throw_completion()) {
|
||||
// Note: We should not leak the exception thrown in host_resolve_imported_module.
|
||||
clear_exception();
|
||||
promise->reject(*module_or_error.throw_completion().value());
|
||||
} else {
|
||||
auto module = module_or_error.release_value();
|
||||
|
@ -969,11 +949,8 @@ void VM::import_module_dynamically(ScriptOrModule referencing_script_or_module,
|
|||
auto evaluated_or_error = link_and_eval_module(source_text_module);
|
||||
|
||||
if (evaluated_or_error.is_throw_completion()) {
|
||||
// Note: Again we don't want to leak the exception from link_and_eval_module.
|
||||
clear_exception();
|
||||
promise->reject(*evaluated_or_error.throw_completion().value());
|
||||
} else {
|
||||
VERIFY(!exception());
|
||||
promise->fulfill(js_undefined());
|
||||
}
|
||||
}
|
||||
|
@ -1001,7 +978,6 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
|
|||
// d. Let namespace be GetModuleNamespace(moduleRecord).
|
||||
auto namespace_ = module_record->get_module_namespace(vm);
|
||||
|
||||
VERIFY(!vm.exception());
|
||||
// e. If namespace is an abrupt completion, then
|
||||
if (namespace_.is_throw_completion()) {
|
||||
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
|
||||
|
@ -1033,8 +1009,6 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
|
|||
|
||||
// 5. Perform ! PerformPromiseThen(innerPromise, onFulfilled, onRejected).
|
||||
inner_promise->perform_then(on_fulfilled, on_rejected, {});
|
||||
|
||||
VERIFY(!exception());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/ErrorTypes.h>
|
||||
#include <LibJS/Runtime/Exception.h>
|
||||
#include <LibJS/Runtime/ExecutionContext.h>
|
||||
#include <LibJS/Runtime/Iterator.h>
|
||||
#include <LibJS/Runtime/MarkedValueList.h>
|
||||
|
@ -49,10 +48,7 @@ public:
|
|||
void push_interpreter(Interpreter&);
|
||||
void pop_interpreter(Interpreter&);
|
||||
|
||||
Exception* exception() { return m_exception; }
|
||||
void set_exception(Exception& exception) { m_exception = &exception; }
|
||||
void clear_exception() { m_exception = nullptr; }
|
||||
|
||||
void clear_exception() { }
|
||||
void dump_backtrace() const;
|
||||
|
||||
class InterpreterExecutionScope {
|
||||
|
@ -90,7 +86,6 @@ public:
|
|||
|
||||
ThrowCompletionOr<void> push_execution_context(ExecutionContext& context, GlobalObject& global_object)
|
||||
{
|
||||
VERIFY(!exception());
|
||||
// Ensure we got some stack space left, so the next function call doesn't kill us.
|
||||
if (did_reach_stack_space_limit())
|
||||
return throw_completion<InternalError>(global_object, ErrorType::CallStackSizeExceeded);
|
||||
|
@ -160,32 +155,11 @@ public:
|
|||
ThrowCompletionOr<Reference> resolve_binding(FlyString const&, Environment* = nullptr);
|
||||
ThrowCompletionOr<Reference> get_identifier_reference(Environment*, FlyString, bool strict, size_t hops = 0);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void throw_exception(GlobalObject& global_object, Args&&... args)
|
||||
{
|
||||
return throw_exception(global_object, T::create(global_object, forward<Args>(args)...));
|
||||
}
|
||||
|
||||
void throw_exception(Exception&);
|
||||
void throw_exception(GlobalObject& global_object, Value value)
|
||||
{
|
||||
return throw_exception(*heap().allocate<Exception>(global_object, value));
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void throw_exception(GlobalObject& global_object, ErrorType type, Args&&... args)
|
||||
{
|
||||
return throw_exception(global_object, T::create(global_object, String::formatted(type.message(), forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
// 5.2.3.2 Throw an Exception, https://tc39.es/ecma262/#sec-throw-an-exception
|
||||
template<typename T, typename... Args>
|
||||
Completion throw_completion(GlobalObject& global_object, Args&&... args)
|
||||
{
|
||||
auto* error = T::create(global_object, forward<Args>(args)...);
|
||||
// NOTE: This is temporary until we remove VM::exception().
|
||||
throw_exception(global_object, error);
|
||||
return JS::throw_completion(error);
|
||||
return JS::throw_completion(T::create(global_object, forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
|
@ -255,8 +229,6 @@ private:
|
|||
void import_module_dynamically(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability promise_capability);
|
||||
void finish_dynamic_import(ScriptOrModule referencing_script_or_module, ModuleRequest module_request, PromiseCapability promise_capability, Promise* inner_promise);
|
||||
|
||||
Exception* m_exception { nullptr };
|
||||
|
||||
HashMap<String, PrimitiveString*> m_string_cache;
|
||||
|
||||
Heap m_heap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue