@@ -2656,6 +2656,7 @@ KJ_TEST("an await_js() whose promise GC collects in another request releases its
26562656
26572657constexpr kj::StringPtr PROBE_SPECIFIER = " test:io-context-probe" _kj;
26582658constexpr kj::StringPtr FAILING_SPECIFIER = " test:io-context-failing" _kj;
2659+ constexpr kj::StringPtr TERMINATING_SPECIFIER = " test:io-context-terminating" _kj;
26592660
26602661// Has `registerModules` add Rust modules to a legacy registry, then calls `body` with the
26612662// registry inside a request.
@@ -2698,6 +2699,20 @@ void withNewRustRegistry(auto&& registerModules, auto&& body) {
26982699 fixture.runInIoContext ([&](const TestFixture::Environment& env) { body (env); });
26992700}
27002701
2702+ // Whether calling `fn` throws `JsExceptionThrown` with execution terminating. Cancels the
2703+ // termination.
2704+ bool terminates (const TestFixture::Environment& env, auto && fn) {
2705+ // NOLINTNEXTLINE(custom-raw-v8-trycatch): the test only checks that the termination stays.
2706+ v8::TryCatch tryCatch (env.isolate );
2707+ KJ_DEFER (env.isolate ->CancelTerminateExecution ());
2708+ try {
2709+ fn ();
2710+ return false ;
2711+ } catch (jsg::JsExceptionThrown&) {
2712+ return tryCatch.HasTerminated ();
2713+ }
2714+ }
2715+
27012716// What calling `fn` throws, as a string.
27022717kj::String thrownBy (jsg::Lock& js, auto && fn) {
27032718 return js.tryCatch ([&]() -> kj::String {
@@ -3077,5 +3092,20 @@ KJ_TEST("the new registry throws the error of a failing Rust module callback") {
30773092 });
30783093}
30793094
3095+ KJ_TEST (" the legacy registry keeps the termination of a terminating Rust module callback" ) {
3096+ withLegacyRustRegistry (register_terminating_module, [](const auto & env, auto & registry) {
3097+ KJ_EXPECT (terminates (env, [&] {
3098+ registry.resolve (env.js , kj::Path::parse (TERMINATING_SPECIFIER ), kj::none,
3099+ jsg::ModuleRegistry::ResolveOption::INTERNAL_ONLY );
3100+ }));
3101+ });
3102+ }
3103+
3104+ KJ_TEST (" the new registry keeps the termination of a terminating Rust module callback" ) {
3105+ withNewRustRegistry (register_terminating_module, [](const auto & env) {
3106+ KJ_EXPECT (terminates (env, [&] { env.js .resolveInternalModule (TERMINATING_SPECIFIER ); }));
3107+ });
3108+ }
3109+
30803110} // namespace
30813111} // namespace workerd::io_context::test
0 commit comments