-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. style nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
auto that = args.This(); | ||
ModuleWrap* obj = Unwrap<ModuleWrap>(that); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
auto result = obj->module_.Get(iso)->GetModuleNamespace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe I understand how the previous code enforced that invariant (by calling There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. made it throw after checking status |
||
args.GetReturnValue().Set(result); | ||
} | ||
|
||
MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, | ||
Local<String> specifier, | ||
Local<Module> referrer) { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it can throw if it isn't instantiated. |
||
|
||
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction()); | ||
env->SetMethod(target, "resolve", node::loader::ModuleWrap::Resolve); | ||
|
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