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

[N-API] Missing module object at initialization time #26221

Closed
raffaeler opened this issue Feb 20, 2019 · 7 comments
Closed

[N-API] Missing module object at initialization time #26221

raffaeler opened this issue Feb 20, 2019 · 7 comments
Labels
node-api Issues and PRs related to the Node-API.

Comments

@raffaeler
Copy link

  • Version: v8.9.4
  • Platform: Windows 10 x64

With the legacy api, I obtain the addon module using this code:

void Init(Local<Object> exports, Local<Object> module) {
  NODE_SET_METHOD(module, "exports", CreateObject);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)

Now I found the way to access the _module internal variable but it is a plain structure and not a Napi::Value.
The reason for needing the Module is accessing, for example, the full pathname of the C++ addon.

@mhdawson
Copy link
Member

Can you add how you accessed the _module internal variable?

@raffaeler
Copy link
Author

Sure, here it is the relevant code:

#define NODE_ADDON_API_DISABLE_DEPRECATED
#include <napi.h>

namespace xcoreplus
{
	using namespace Napi;
	using namespace std;

	Object LoadPlugin(Env env, Object exports);    // forward declaration
	NODE_API_MODULE(addon, LoadPlugin)       // declares _module

        Object LoadPlugin(Env env, Object exports) {
        napi_module& module = _module;

        // do something with exports
        return exports;
    }


}

@mhdawson
Copy link
Member

After a quick scan of the code I'm not sure how that sets _module but its going to be unintentional...

I think the correct way forward is for us to understand what info is needed from the module and see if there is a way to provide that.

@raffaeler
Copy link
Author

I totally agree that _module is certainly not a solid way to make an addon version-resistant.
In any case napi_module is a plain structure and not the Napi::Value I would expect if Module was exposed to the addon world.
Also, _module has the main C++ source filename which has nothing to do with the runtime location of the addon binary.

@gabrielschulhof gabrielschulhof added the node-api Issues and PRs related to the Node-API. label Feb 20, 2019
@gabrielschulhof
Copy link
Contributor

@raffaeler why do you need access to module?

@raffaeler
Copy link
Author

@gabrielschulhof Here is why:
nodejs/node-addon-api#449

(we can close one of the two threads, not sure which one)

@mhdawson
Copy link
Member

mhdawson commented Feb 22, 2019

Going to close this one a duplicate of nodejs/node-addon-api#449 as there is more discussion in the other thread.

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

No branches or pull requests

3 participants