LadybirdBrowser / ladybird

Truly independent web browser
https://ladybird.org
BSD 2-Clause "Simplified" License
21.97k stars 973 forks source link

`export let test = await foo();` throws ReferenceError when `import`ed #2245

Open Psychpsyo opened 6 days ago

Psychpsyo commented 6 days ago

Summary

Importing this module throws a ReferenceError ('foo' is not defined) instead of working:

function foo() {
    return {a: "b"};
}

export let test = await foo();

Operating system

Linux

Steps to reproduce

  1. Create these files in a folder and load index.html:

index.html:

<script src="./scriptA.mjs" type="module"></script>

scriptA.mjs:

import {test} from "./scriptB.mjs";

scriptB.mjs:

function foo() {
    return {a: "b"};
}
export let test = await foo();
  1. ladybird logs [ReferenceError] 'foo' is not defined.

Expected behavior

The module should be imported successfully and test should be filled with the return value of foo(), async or not.

Actual behavior

ReferenceError.

URL for a reduced test case

Not a reduced test case, but it does happen here, on page load, and makes the entire site unusable. https://battle.crossuniverse.net/intro/index.html

HTML/SVG/etc. source for a reduced test case

Already given above.

Log output and (if possible) backtrace

See screenshot below. (clipboard sharing to my Linux VM doesn't work -_-)

Screenshots or screen recordings

image

Build flags or config settings

none(?)

Contribute a patch?

Psychpsyo commented 5 days ago

I've looked into this some more, this seems to be due to the fact that modules with top-level-await aren't properly supported yet. SourceTextModule.cpp just wraps all the module's code in an async function and runs tht instead of using AsyncBlockStart directly. (and making it do that just breaks things even further, so I've decided that this is beyond me and I won't do it as my first PR)