diff options
author | Taylor Woll <taylor.woll@microsoft.com> | 2017-08-30 02:48:41 -0700 |
---|---|---|
committer | Michael Dawson <mdawson@devrus.com> | 2017-09-14 15:02:10 -0400 |
commit | 92e5f5cc09fdbf223a418aef1154b2b75b3f9dcd (patch) | |
tree | 86f3b8071340f5ef9ecd1f07796c23248a1d06b6 /src | |
parent | d195a069b697d4cfc41f09037471908089cbd98f (diff) | |
download | android-node-v8-92e5f5cc09fdbf223a418aef1154b2b75b3f9dcd.tar.gz android-node-v8-92e5f5cc09fdbf223a418aef1154b2b75b3f9dcd.tar.bz2 android-node-v8-92e5f5cc09fdbf223a418aef1154b2b75b3f9dcd.zip |
n-api: refactor napi_addon_register_func
As per discussion in abi-stable-node:
https://github.com/nodejs/abi-stable-node/issues/256,
take a refactor to napi_addon_register_func such that
the result from the register function is assigned to
the module exports property. By making this change,
native module can be agnostic about which type of
module the environment supports.
PR-URL: https://github.com/nodejs/node/pull/15088
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_api.cc | 16 | ||||
-rw-r--r-- | src/node_api.h | 6 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index 8f84de7879..a8b449ece5 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -822,11 +822,17 @@ void napi_module_register_cb(v8::Local<v8::Object> exports, // one is found. napi_env env = v8impl::GetEnv(context); - mod->nm_register_func( - env, - v8impl::JsValueFromV8LocalValue(exports), - v8impl::JsValueFromV8LocalValue(module), - mod->nm_priv); + napi_value _exports = + mod->nm_register_func(env, v8impl::JsValueFromV8LocalValue(exports)); + + // If register function returned a non-null exports object different from + // the exports object we passed it, set that as the "exports" property of + // the module. + if (_exports != nullptr && + _exports != v8impl::JsValueFromV8LocalValue(exports)) { + napi_value _module = v8impl::JsValueFromV8LocalValue(module); + napi_set_named_property(env, _module, "exports", _exports); + } } } // end of anonymous namespace diff --git a/src/node_api.h b/src/node_api.h index b127fd7fe8..cdc3a6bdb7 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -44,10 +44,8 @@ #endif -typedef void (*napi_addon_register_func)(napi_env env, - napi_value exports, - napi_value module, - void* priv); +typedef napi_value (*napi_addon_register_func)(napi_env env, + napi_value exports); typedef struct { int nm_version; |