diff --git a/Libraries/LibJS/SourceTextModule.cpp b/Libraries/LibJS/SourceTextModule.cpp index ff200d5fbe3..956b584ccc9 100644 --- a/Libraries/LibJS/SourceTextModule.cpp +++ b/Libraries/LibJS/SourceTextModule.cpp @@ -760,6 +760,10 @@ ThrowCompletionOr SourceTextModule::execute_module(VM& vm, GC::Ptr SourceTextModule::execute_module(VM& vm, GC::Ptrset_is_module_wrapper(true); - // AD-HOC: We push/pop the moduleContext around the call to ensure that the async execution context - // captures the module execution context. - vm.push_execution_context(*module_context); - auto result = call(vm, Value { module_wrapper_function }, js_undefined(), ReadonlySpan {}); vm.pop_execution_context(); + auto result = call(vm, Value { module_wrapper_function }, js_undefined(), ReadonlySpan {}); + // AD-HOC: This is basically analogous to what AsyncBlockStart would do. if (result.is_throw_completion()) { MUST(call(vm, *capability->reject(), js_undefined(), result.throw_completion().value().value())); diff --git a/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js b/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js index 9b7ab9677a1..ffbad80f2af 100644 --- a/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js +++ b/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js @@ -53,6 +53,33 @@ describe("normal behavior", () => { expect(value).not.toHaveProperty("default", null); expect(value).not.toHaveProperty("bar", null); + expect(value).not.toHaveProperty("baz", null); + expect(value).not.toHaveProperty("qux", null); + passed = true; + }) + .catch(value => { + error = value; + }); + runQueuedPromiseJobs(); + expect(error).toBeNull(); + expect(passed).toBeTrue(); + }); + + test("value from async module from top-level awaited function", () => { + const shadowRealm = new ShadowRealm(); + const promise = shadowRealm.importValue("./async-module.mjs", "qux"); + expect(promise).toBeInstanceOf(Promise); + let error = null; + let passed = false; + promise + .then(value => { + expect(value).toBe("'qux' export"); + expect(typeof value).toBe("string"); + + expect(value).not.toHaveProperty("default", null); + expect(value).not.toHaveProperty("foo", null); + expect(value).not.toHaveProperty("bar", null); + expect(value).not.toHaveProperty("baz", null); passed = true; }) .catch(value => { diff --git a/Libraries/LibJS/Tests/builtins/ShadowRealm/async-module.mjs b/Libraries/LibJS/Tests/builtins/ShadowRealm/async-module.mjs index a95ab095aad..703789f6719 100644 --- a/Libraries/LibJS/Tests/builtins/ShadowRealm/async-module.mjs +++ b/Libraries/LibJS/Tests/builtins/ShadowRealm/async-module.mjs @@ -9,3 +9,9 @@ export default "Default export"; await Promise.resolve(2); export const bar = "'bar' export"; + +async function baz() { + return "'qux' export"; +} + +export const qux = await baz();