tc39 / test262

Official ECMAScript Conformance Test Suite
Other
2.35k stars 461 forks source link

Tests for top-level await with circular module import #4250

Open theoludwig opened 4 days ago

theoludwig commented 4 days ago

Repo: https://github.com/tc39/proposal-top-level-await/ Spec text: https://tc39.github.io/proposal-top-level-await/ ECMA-262 PR: https://github.com/tc39/ecma262/pull/2408

In the Google Chrome v129 release, the JavaScript module import is broken with circular + top-level-await (discovered by @antfu). Related:

To avoid other engines or implementers to also break accidentally this feature, or even for Google Chrome to avoid breaking it again, it would be great to add tests for this in Test262 (as suggested here: https://x.com/robpalmer2/status/1836846820418601384).

Demonstration

Online demo

When the entry file is foo.js, with the following content:

// bar.js
import { define } from './foo.js'

export default define('It works!')
// foo.js
export function define(foo) {
  return foo.toUpperCase()
}

const getter = () => import('./bar.js')

await 1

getter()
  .then(r => {
    // this will never be resolved
  })
  .catch(e => {
    // this either
  })

Note that if remove the await 1, it will work again.

nicolo-ribaudo commented 4 days ago

Tests have been a used in https://github.com/tc39/test262/pull/4116. Would you like to open a PR to move it out of the staging directory?

theoludwig commented 1 hour ago

Tests have been a used in #4116. Would you like to open a PR to move it out of the staging directory?

@nicolo-ribaudo Sure! :smile: PR opened: #4262