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

module: do not set CJS variables for Worker eval #53050

Merged
merged 5 commits into from
May 25, 2024

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented May 18, 2024

There are no local CJS variables in the Worker eval context – it's all global variables, just like in the --eval context.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. vm Issues and PRs related to the vm subsystem. labels May 18, 2024
Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a separate PR, but could detect-module be a way to resolve #30682?

src/node_contextify.cc Show resolved Hide resolved
test/es-module/test-esm-detect-ambiguous.mjs Outdated Show resolved Hide resolved
@GeoffreyBooth
Copy link
Member

I think the same bug applies to regular --eval, too, doesn’t it?

node --eval "let __filename,__dirname,require,module,exports;this.a" # Clean exit

node --experimental-detect-module --eval "let __filename,__dirname,require,module,exports;this.a"
file:///Users/geoffrey/Sites/node/[eval1]:1
let __filename,__dirname,require,module,exports;this.a
                                                     ^

TypeError: Cannot read properties of undefined (reading 'a')
    at file:///Users/geoffrey/Sites/node/[eval1]:1:54
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.eval (node:internal/modules/esm/loader:218:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)

Node.js v22.2.0

I feel like we should fix it for --eval as well and add a corresponding test.

@GeoffreyBooth GeoffreyBooth added module Issues and PRs related to the module subsystem. esm Issues and PRs related to the ECMAScript Modules implementation. labels May 19, 2024
@dygabo
Copy link
Member

dygabo commented May 19, 2024

Probably a separate PR, but could detect-module be a way to resolve #30682?

IMO that could work. As soon as detect-module will also be the default (i.e. unflagged) it should work seamlessly, excepr the performance warning that should be suppressed in case of eval.

aduh95 and others added 2 commits May 19, 2024 22:43
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com>
@aduh95
Copy link
Contributor Author

aduh95 commented May 20, 2024

could detect-module be a way to resolve #30682?

I mean, it's already the case, no? When you set --experimental-detect-module, passing a string containing JS code that's parsable as ESM and not parsable as CJS to the Worker constructor does eval it as ESM.

@aduh95 aduh95 requested a review from GeoffreyBooth May 23, 2024 08:11
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels May 23, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 23, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@GeoffreyBooth GeoffreyBooth added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 25, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 25, 2024
@nodejs-github-bot nodejs-github-bot merged commit 2079a7a into nodejs:main May 25, 2024
62 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 2079a7a

@aduh95 aduh95 deleted the no-cjs-var-in-worker-eval branch May 25, 2024 18:22
targos pushed a commit that referenced this pull request Jun 1, 2024
PR-URL: #53050
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
lukins-cz pushed a commit to lukins-cz/OS-Aplet-node that referenced this pull request Jun 1, 2024
PR-URL: nodejs#53050
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants