Truly independent web browser
LibJS: Run a module with top-level await as an async arrow function
Shannon Booth9fd6b54d9408
diff --git a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs b/Libraries/LibJS/Rust/src/runtime/source_text_module.rsindex d82951d0d9c..44879337d29 100644--- a/Libraries/LibJS/Rust/src/runtime/source_text_module.rs+++ b/Libraries/LibJS/Rust/src/runtime/source_text_module.rs@@ -316,6 +316,8 @@ impl SourceTextModule {vm: &Vm,top_level_await_executable: Gc<Executable>,) -> Gc<SharedFunctionInstanceData> {+ // NB: As an arrow function, the wrapper has no this binding, so GetThisEnvironment finds the module Environment+ // Record, as it does for the code that AsyncBlockStart evaluates in moduleContext.let tla_shared_data = SharedFunctionInstanceData::create_without_compile_input(vm,FunctionKind::Async,@@ -323,7 +325,7 @@ impl SourceTextModule {0,0,true,- false,+ true,true,Vec::new(),);diff --git a/Tests/LibJS/Runtime/modules/basic-modules.js b/Tests/LibJS/Runtime/modules/basic-modules.jsindex e04189dfb57..22cc6b1f871 100644--- a/Tests/LibJS/Runtime/modules/basic-modules.js+++ b/Tests/LibJS/Runtime/modules/basic-modules.js@@ -387,6 +387,12 @@ describe("scoping in modules", () => {const result = expectModulePassed("./module-level-bindings-with-top-level-await.mjs");expect(result.counterAfterAwait).toBe(11);});++ test("direct eval at the top level of a module with top-level await is not in a function", () => {+ const result = expectModulePassed("./eval-with-top-level-await.mjs");+ expect(result.errors).toEqual(["SyntaxError", "SyntaxError", "SyntaxError", "SyntaxError"]);+ expect(result.thisValues).toEqual([undefined, undefined]);+ });});describe("top-level await", () => {diff --git a/Tests/LibJS/Runtime/modules/eval-with-top-level-await.mjs b/Tests/LibJS/Runtime/modules/eval-with-top-level-await.mjsnew file mode 100644index 00000000000..8428b46eec3--- /dev/null+++ b/Tests/LibJS/Runtime/modules/eval-with-top-level-await.mjs@@ -0,0 +1,26 @@+await 0;++function errorOf(callback) {+ try {+ callback();+ return "none";+ } catch (error) {+ return error.name;+ }+}++export const errors = [+ errorOf(() => eval("new.target")),+ errorOf(() => eval("super.x")),+ errorOf(() => eval("super()")),+];+try {+ eval("new.target");+ errors.push("none");+} catch (error) {+ errors.push(error.name);+}++export const thisValues = [eval("this"), (() => eval("this"))()];++export const passed = true;