Skip to content

Commit 9a02de7

Browse files
author
Gabriel Schulhof
committed
n-api: throw when entry point is null
PR-URL: #20779 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 82f1811 commit 9a02de7

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
@@ -868,6 +868,12 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
868868
v8::Local<v8::Value> module,
869869
v8::Local<v8::Context> context,
870870
napi_addon_register_func init) {
871+
if (init == nullptr) {
872+
node::Environment::GetCurrent(context)->ThrowError(
873+
"Module has no declared entry point.");
874+
return;
875+
}
876+
871877
// Create a new napi_env for this module or reference one if a pre-existing
872878
// one is found.
873879
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)