Skip to content

Commit 7033bba

Browse files
Gabriel Schulhofrvagg
Gabriel Schulhof
authored andcommitted
n-api: throw when entry point is null
Backport-PR-URL: #21732 PR-URL: #20779 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 1cf17df commit 7033bba

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/node_api.cc

+6
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,12 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
866866
void* priv) {
867867
napi_module* mod = static_cast<napi_module*>(priv);
868868

869+
if (mod->nm_register_func == nullptr) {
870+
node::Environment::GetCurrent(context)->ThrowError(
871+
"Module has no declared entry point.");
872+
return;
873+
}
874+
869875
// Create a new napi_env for this module or reference one if a pre-existing
870876
// one is found.
871877
napi_env env = v8impl::GetEnv(context);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'test_null_init',
5+
'sources': [ 'test_null_init.c' ]
6+
}
7+
]
8+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
const common = require('../../common');
3+
const assert = require('assert');
4+
5+
assert.throws(
6+
() => require(`./build/${common.buildType}/test_null_init`),
7+
/Module has no declared entry point[.]/);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <node_api.h>
2+
3+
NAPI_MODULE(NODE_GYP_MODULE_NAME, NULL)

0 commit comments

Comments
 (0)