Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect assert in GetModuleNamespace() #3114

Open
iamstolis opened this issue Jul 5, 2023 · 1 comment
Open

Incorrect assert in GetModuleNamespace() #3114

iamstolis opened this issue Jul 5, 2023 · 1 comment
Labels

Comments

@iamstolis
Copy link

Consider the following modules:

// main.js
import {pi} from "./other.js";
export * as common from "./common.js";

// other.js
import {common} from "./main.js";
export var pi = 3.14;

// common.js
export var e = 2.718;

The linking of main.js leads to the violation of the assert at the begining of GetModuleNamespace(). In other words, GetModuleNamespace() is invoked with a module in unlinked state.

The relevant operations are

InnerModuleLinking('main.js')
-> InnerModuleLinking('other.js')
-> <other.js>.InitializeEnvironment()
-> GetModuleNamespace('common.js')

Note that InnerModuleLinking('main.js') invokes InnerModuleLinking('other.js') before InnerModuleLinking('common.js') (due to the order of statements in main.js). So, common.js remains in unlinked state during InnerModuleLinking('other.js').

FYI: This violation of the assert can be reproduced using engine262 easily:

$ node bin/engine262.js --module main.js 
/somePath/dist/engine262.js:29106
      throw new AssertError(source);
      ^

AssertError: module.Status !== 'new' && module.Status !== 'unlinked'
    at Assert (/somePath/dist/engine262.js:29106:13)
    at GetModuleNamespace (/somePath/dist/engine262.js:29044:7)
    at ManagedSourceTextModuleRecord.InitializeEnvironment (/somePath/dist/engine262.js:21004:31)
    at InnerModuleLinking (/somePath/dist/engine262.js:28690:25)
    at InnerModuleLinking (/somePath/dist/engine262.js:28672:20)
    at ManagedSourceTextModuleRecord.Link (/somePath/dist/engine262.js:20678:22)
    at /somePath/bin/engine262.js:159:27
    at ManagedRealm.scope (/somePath/dist/engine262.js:56724:17)
    at oneShotEval (/somePath/bin/engine262.js:143:9)
    at Object.<anonymous> (/somePath/bin/engine262.js:183:3)

Node.js v18.14.1
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 6, 2023

Both GetExportedNames and ResolveExport support being called on unlinked modules, so we can just relax the assertion in GetModuleNamespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants