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

vm: add support for import.meta to Module #19277

Closed
wants to merge 1 commit into from

Conversation

punteek
Copy link
Contributor

@punteek punteek commented Mar 11, 2018

Fixes: #18570

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

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Mar 11, 2018
@TimothyGu
Copy link
Member

@TimothyGu TimothyGu requested a review from devsnek March 11, 2018 02:15
@TimothyGu TimothyGu added vm Issues and PRs related to the vm subsystem. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Mar 11, 2018
Copy link
Member

@devsnek devsnek left a comment

Choose a reason for hiding this comment

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

generally looks good 👍, just a few notes

@@ -19,7 +23,20 @@ function normalizeReferrerURL(referrer) {
}

function initializeImportMetaObject(wrap, meta) {
meta.url = wrap.url;
const vmModule = wrapToModuleMap.get(wrap);
Copy link
Member

@devsnek devsnek Mar 11, 2018

Choose a reason for hiding this comment

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

could you just simplify this to const initializeImportMeta = wrapToFnMap.get(wrap)?

you could also initalise an undefined property in module_wrap and check wrap.property !== undefined which should be faster than a weakmap check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does const initializeImportMeta = wrapToFnMap.get(wrap) serve as a simplification?

const {
initImportMetaMap,
wrapToModuleMap
} = require('internal/vm/Module-common');
Copy link
Member

@devsnek devsnek Mar 11, 2018

Choose a reason for hiding this comment

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

you can just export these maps from internal/vm/module, and if for some reason this file is kept please rename it to module_common.js to keep with the rest of our files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I can move the maps to Module.js.

@@ -108,7 +108,8 @@
'DeprecationWarning', 'DEP0062', startup, true);
}

if (process.binding('config').experimentalModules) {
if (process.binding('config').experimentalModules ||
process.binding('config').experimentalVMModules) {
process.emitWarning(
Copy link
Member

Choose a reason for hiding this comment

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

this warning should still only show up for --experimental-modules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means that the original way the warning was written is ok?

Copy link
Member

Choose a reason for hiding this comment

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

@punteek, I think @devsnek meant

if (experimentalModules || experimentalVMModules) {
  if (experimentalModules)
    process.emitWarning(...);
  NativeModule.require(...);
}

meta.url = wrap.url;
} else {
const initializeImportMeta = initImportMetaMap.get(vmModule);
if (initializeImportMeta === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

you can change this to if (initializeImportMeta !== undefined) { /* call method */ }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I currently have a check for undefined is that we would like nothing to happen in the case that no callback is provided.

Copy link
Member

Choose a reason for hiding this comment

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

i meant

if (initializeImportMeta !== undefined) {
  initializeImportMeta(meta, vmModule);
} // no else, does the same thing as your code but without an empty case


Creates a new ES `Module` object.

*Note*: Properties assigned to the `import.meta` object that are objects may
Copy link
Member

Choose a reason for hiding this comment

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

i think people are already used to this just from using vm, might not need this example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I would prefer to keep the example for now.

@devsnek
Copy link
Member

devsnek commented Mar 24, 2018

@punteek are you still interested in working on this?

@punteek
Copy link
Contributor Author

punteek commented Mar 25, 2018

Hey! Yes I'd still like to get this update working. I have some questions regarding your suggested changes which you can see above.

@punteek
Copy link
Contributor Author

punteek commented Mar 29, 2018

I've updated some of the discussed changes.

@devsnek
Copy link
Member

devsnek commented Mar 29, 2018

lgtm after a rebase against master

@devsnek
Copy link
Member

devsnek commented Mar 29, 2018

@punteek you'll need to rebase your branch against master. git rebase master --preserve-merges should do it, and then you can safely drop that last merge commit you made.

@punteek punteek force-pushed the import-meta-vm branch 2 times, most recently from 3753c02 to 3b6fb05 Compare March 30, 2018 00:00
@punteek
Copy link
Contributor Author

punteek commented Mar 30, 2018

Sorry, I did not see your comment until just now. I tried fixing it on my own, does everything look correct?

@devsnek
Copy link
Member

devsnek commented Mar 30, 2018

@punteek your branch still has lib/internal/bootstrap_node.js, once you get rid of that you should be good to go 👍

@punteek
Copy link
Contributor Author

punteek commented Mar 30, 2018

Alright, it should be gone.

@devsnek
Copy link
Member

devsnek commented Mar 30, 2018

@punteek sorry to keep doing this to you 😄 it seems you also have lib/internal/vm/Modules.js and lib/internal/process/modules.js still in your branch as well.

@punteek
Copy link
Contributor Author

punteek commented Mar 30, 2018

No problem, I should have caught it the first time. Those files should be gone too now.

@TimothyGu
Copy link
Member

@punteek
Copy link
Contributor Author

punteek commented Mar 31, 2018

I found additional errors in importing due to file name changes. These should be fixed now.

@TimothyGu
Copy link
Member

@devsnek
Copy link
Member

devsnek commented Apr 1, 2018

landed in 07ba914. congratulations @punteek on your first contribution 🎉

@devsnek devsnek closed this Apr 1, 2018
devsnek pushed a commit that referenced this pull request Apr 1, 2018
Fixes: #18570

PR-URL: #19277
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
@punteek
Copy link
Contributor Author

punteek commented Apr 1, 2018

Thanks to both @TimothyGu and @devsnek, you both made the process very clear for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow vm.Module creators to customize import.meta in the created module
5 participants