1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:17:46 +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:
davidot 2022-02-07 15:12:41 +01:00 committed by Linus Groh
parent 4ef1e8f226
commit 9264f9d24e
35 changed files with 145 additions and 349 deletions

View file

@ -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;