summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-02-07 15:12:41 +0100
committerLinus Groh <mail@linusgroh.de>2022-02-08 09:12:42 +0000
commit9264f9d24e10c3ca8d522450bc9152e69cbd6cda (patch)
tree68ad59cc9fb5328c8925e6f790c2da805dadbbe0 /Tests
parent4ef1e8f226caff2a0d9002cb5e30fbd7bc99b7b3 (diff)
downloadserenity-9264f9d24e10c3ca8d522450bc9152e69cbd6cda.zip
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.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibJS/test-bytecode-js.cpp7
-rw-r--r--Tests/LibWeb/test-web.cpp33
2 files changed, 21 insertions, 19 deletions
diff --git a/Tests/LibJS/test-bytecode-js.cpp b/Tests/LibJS/test-bytecode-js.cpp
index 5c21d25fd8..d6f0c8792d 100644
--- a/Tests/LibJS/test-bytecode-js.cpp
+++ b/Tests/LibJS/test-bytecode-js.cpp
@@ -25,8 +25,7 @@
#define EXPECT_NO_EXCEPTION(executable) \
auto executable = JS::Bytecode::Generator::generate(program); \
auto result = bytecode_interpreter.run(*executable); \
- EXPECT(!result.is_error()); \
- EXPECT(!vm->exception());
+ EXPECT(!result.is_error());
#define EXPECT_NO_EXCEPTION_WITH_OPTIMIZATIONS(executable) \
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline(); \
@@ -34,8 +33,7 @@
\
auto result_with_optimizations = bytecode_interpreter.run(*executable); \
\
- EXPECT(!result_with_optimizations.is_error()); \
- EXPECT(!vm->exception())
+ EXPECT(!result_with_optimizations.is_error());
#define EXPECT_NO_EXCEPTION_ALL(source) \
SETUP_AND_PARSE(source) \
@@ -117,7 +115,6 @@ TEST_CASE(loading_multiple_files)
auto executable = JS::Bytecode::Generator::generate(test_file_program);
auto result = bytecode_interpreter.run(*executable);
EXPECT(!result.is_error());
- EXPECT(!vm->exception());
}
}
diff --git a/Tests/LibWeb/test-web.cpp b/Tests/LibWeb/test-web.cpp
index fd21598bbb..d778cd1bc3 100644
--- a/Tests/LibWeb/test-web.cpp
+++ b/Tests/LibWeb/test-web.cpp
@@ -22,8 +22,8 @@ TEST_ROOT("Userland/Libraries/LibWeb/Tests");
RefPtr<Web::InProcessWebView> g_page_view;
RefPtr<GUI::Application> g_app;
Optional<URL> next_page_to_load;
-Vector<Function<void(JS::Object&)>> after_initial_load_hooks;
-Vector<Function<void(JS::Object&)>> before_initial_load_hooks;
+Vector<Function<JS::ThrowCompletionOr<void>(JS::Object&)>> after_initial_load_hooks;
+Vector<Function<JS::ThrowCompletionOr<void>(JS::Object&)>> before_initial_load_hooks;
TESTJS_MAIN_HOOK()
{
@@ -62,8 +62,9 @@ TESTJS_GLOBAL_FUNCTION(after_initial_page_load, afterInitialPageLoad)
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Function");
}
- after_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) {
- [[maybe_unused]] auto unused = JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
+ after_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) -> JS::ThrowCompletionOr<void> {
+ TRY(JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object));
+ return {};
});
return JS::js_undefined();
}
@@ -76,8 +77,9 @@ TESTJS_GLOBAL_FUNCTION(before_initial_page_load, beforeInitialPageLoad)
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Function");
}
- before_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) {
- [[maybe_unused]] auto unused = JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
+ before_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) -> JS::ThrowCompletionOr<void> {
+ TRY(JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object));
+ return {};
});
return JS::js_undefined();
}
@@ -89,12 +91,14 @@ TESTJS_GLOBAL_FUNCTION(wait_for_page_to_load, waitForPageToLoad)
// Run the "before" hooks
for (auto& entry : before_initial_load_hooks)
- entry(document->interpreter().global_object());
+ TRY(entry(document->interpreter().global_object()));
// Set the load hook
Web::LoadRequest request;
request.set_url(next_page_to_load.value());
+ JS::ThrowCompletionOr<void> result = {};
+
auto& loader = Web::ResourceLoader::the();
loader.load_sync(
request,
@@ -103,22 +107,23 @@ TESTJS_GLOBAL_FUNCTION(wait_for_page_to_load, waitForPageToLoad)
// Now parse the HTML page.
parser.run(next_page_to_load.value());
g_page_view->set_document(&parser.document());
- if (vm.exception()) {
- // FIXME: Should we do something about this? the document itself threw unhandled exceptions...
- vm.clear_exception();
- }
+ // Note: Unhandled exceptions are just dropped here.
// Run the "after" hooks
for (auto& entry : after_initial_load_hooks) {
- entry(document->interpreter().global_object());
- if (vm.exception())
+ auto ran_or_error = entry(document->interpreter().global_object());
+ if (ran_or_error.is_error()) {
+ result = ran_or_error.release_error();
break;
+ }
}
},
[&](auto&, auto) {
dbgln("Load of resource {} failed", next_page_to_load.value());
- vm.throw_exception<JS::TypeError>(global_object, "Resource load failed");
+ result = vm.template throw_completion<JS::TypeError>(global_object, "Resource load failed");
});
+ if (result.is_error())
+ return result.release_error();
return JS::js_undefined();
}