-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: Use V8 function to get Module Namespace #16261
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
Changes from 2 commits
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,28 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { | |
| args.GetReturnValue().Set(ret); | ||
| } | ||
|
|
||
| void ModuleWrap::Namespace(const FunctionCallbackInfo<Value>& args) { | ||
| Environment* env = Environment::GetCurrent(args); | ||
| auto isolate = args.GetIsolate(); | ||
| auto that = args.This(); | ||
| ModuleWrap* obj = Unwrap<ModuleWrap>(that); | ||
| CHECK_NE(obj, nullptr); | ||
|
|
||
| auto module = obj->module_.Get(isolate); | ||
|
|
||
| switch (module->GetStatus()) { | ||
| default: | ||
| return env->ThrowError("cannot get namespace, Module has not been instantiated"); | ||
|
Member
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. Long line. Didn't
Member
Author
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 didn't see one. fixed. |
||
| case v8::Module::Status::kInstantiated: | ||
| case v8::Module::Status::kEvaluating: | ||
| case v8::Module::Status::kEvaluated: | ||
| break; | ||
| } | ||
|
|
||
| auto result = module->GetModuleNamespace(); | ||
| args.GetReturnValue().Set(result); | ||
| } | ||
|
|
||
| MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, | ||
| Local<String> specifier, | ||
| Local<Module> referrer) { | ||
|
|
@@ -516,6 +538,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); | ||
|
Member
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.
Member
Author
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.
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