-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src: Use V8 function to get Module Namespace #16261
Conversation
src/module_wrap.cc
Outdated
void ModuleWrap::Namespace(const FunctionCallbackInfo<Value>& args) { | ||
auto iso = args.GetIsolate(); | ||
auto that = args.This(); | ||
ModuleWrap* obj = Unwrap<ModuleWrap>(that); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you CHECK_NE(obj, nullptr);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/module_wrap.cc
Outdated
@@ -207,6 +207,14 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { | |||
args.GetReturnValue().Set(ret); | |||
} | |||
|
|||
void ModuleWrap::Namespace(const FunctionCallbackInfo<Value>& args) { | |||
auto iso = args.GetIsolate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: isolate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -516,6 +524,7 @@ void ModuleWrap::Initialize(Local<Object> target, | |||
env->SetProtoMethod(tpl, "link", Link); | |||
env->SetProtoMethod(tpl, "instantiate", Instantiate); | |||
env->SetProtoMethod(tpl, "evaluate", Evaluate); | |||
env->SetProtoMethod(tpl, "namespace", Namespace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getNamespace
& GetNamespace
? At least if this is idempotent I think that’d be a better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can throw if it isn't instantiated.
lib/internal/loader/Loader.js
Outdated
@@ -3,7 +3,6 @@ | |||
const { getURLFromFilePath } = require('internal/url'); | |||
|
|||
const { | |||
getNamespaceOfModuleWrap, | |||
createDynamicModule | |||
} = require('internal/loader/ModuleWrap'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could fit this on one line now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/module_wrap.cc
Outdated
auto iso = args.GetIsolate(); | ||
auto that = args.This(); | ||
ModuleWrap* obj = Unwrap<ModuleWrap>(that); | ||
auto result = obj->module_.Get(iso)->GetModuleNamespace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetModuleNamespace()
terminates with a fatal error when GetStatus()
isn't one of kInstantiated
, kEvaluating
or kEvaluated
.
I believe I understand how the previous code enforced that invariant (by calling .instantiate()
and .evaluate()
, right?) but what ensures that now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing except when it is called, can add a check and throw though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made it throw after checking status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo style nit.
src/module_wrap.cc
Outdated
|
||
switch (module->GetStatus()) { | ||
default: | ||
return env->ThrowError("cannot get namespace, Module has not been instantiated"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line. Didn't make lint
or make test
complain about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't see one. fixed.
Landed in 1c07724 |
PR-URL: #16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: #16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs/node#16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs/node#16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs/node#16261 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Newer V8 does this for us without an intermediate Module Record.
Checklist
Affected core subsystem(s)
src, module