Skip to content

vm: SourceTextModule refactor - #29776

Closed
devsnek wants to merge 1 commit into
nodejs:masterfrom
devsnek:vm-module-2
Closed

vm: SourceTextModule refactor#29776
devsnek wants to merge 1 commit into
nodejs:masterfrom
devsnek:vm-module-2

Conversation

@devsnek

Copy link
Copy Markdown
Member
  • Removes redundant instantiate method
  • Refactors link to match the spec linking steps more accurately
  • Removes URL validation from SourceTextModule specifiers
  • DRYs some dynamic import logic

Closes#29030

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@devsnekdevsnek added the vm Issues and PRs related to the vm subsystem. label Sep 30, 2019
@nodejs-github-botnodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Sep 30, 2019
@devsnek

Copy link
Copy Markdown
MemberAuthor

cc @nodejs/vm

@devsnekdevsnek removed the lib / src Issues and PRs related to general changes in the lib or src directory. label Sep 30, 2019
Comment threaddoc/api/vm.md Outdated
Comment threadlib/internal/vm/source_text_module.js Outdated
@devsnekdevsnek added the experimental Issues and PRs related to experimental features. label Sep 30, 2019
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@guybedfordguybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great to see these refinements.

Comment threaddoc/api/vm.md Outdated
Comment threadlib/internal/vm/source_text_module.js Outdated
Comment threadlib/internal/errors.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest to abstract this into a private function for less repetition. That way it could be used as: this.#getPrivateProperty(name) where name would e.g., be '#error'.

@devsnekdevsnekOct 1, 2019

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

obj['#error'] is not the same as obj.#error, also you have to check for this.#getPrivateProperty in the first place 🙃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uh, of course! Too bad that it seems like there's no nice way around this 😞

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's pretty ugly but it should be possible to abstract it like this:

functiongetPrivateProperty(module,name){try{switch(name){case'error':
returnmodule.#error;
...
}}catch{thrownewERR_VM_MODULE_NOT_MODULE();}}

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I think how the current code is the best we can get it. you can blame tc39 for not generalizing private fields better 🤷

- Removes redundant `instantiate` method
- Refactors `link` to match the spec linking steps more accurately
- Removes URL validation from SourceTextModule specifiers
- DRYs some dynamic import logic
Closesnodejs#29030
Co-Authored-By: Michaël Zasso <targos@protonmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@devsnekdevsnek added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 2, 2019
Trott pushed a commit that referenced this pull request Oct 2, 2019
- Removes redundant `instantiate` method
- Refactors `link` to match the spec linking steps more accurately
- Removes URL validation from SourceTextModule specifiers
- DRYs some dynamic import logic
Closes: #29030
Co-Authored-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #29776
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
@Trott

Trott commented Oct 2, 2019

Copy link
Copy Markdown
Member

Landed in 5e7946f

@TrottTrott closed this Oct 2, 2019
@devsnek
devsnek deleted the vm-module-2 branch October 2, 2019 23:50
BridgeAR pushed a commit that referenced this pull request Oct 9, 2019
- Removes redundant `instantiate` method
- Refactors `link` to match the spec linking steps more accurately
- Removes URL validation from SourceTextModule specifiers
- DRYs some dynamic import logic
Closes: #29030
Co-Authored-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #29776
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
@BridgeARBridgeAR mentioned this pull request Oct 10, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.experimentalIssues and PRs related to experimental features.vmIssues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs vm.SourceTextModule: Instantiate() abstract operation has been replaced with InitializeEnvironment()

8 participants

@devsnek@nodejs-github-bot@Trott@jasnell@guybedford@targos@JungMinu@BridgeAR