n-api: throw when entry point is null
PR-URL: https://github.com/nodejs/node/pull/20779 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
82f18118ff
commit
9a02de7084
@ -868,6 +868,12 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
|
|||||||
v8::Local<v8::Value> module,
|
v8::Local<v8::Value> module,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
napi_addon_register_func init) {
|
napi_addon_register_func init) {
|
||||||
|
if (init == nullptr) {
|
||||||
|
node::Environment::GetCurrent(context)->ThrowError(
|
||||||
|
"Module has no declared entry point.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new napi_env for this module or reference one if a pre-existing
|
// Create a new napi_env for this module or reference one if a pre-existing
|
||||||
// one is found.
|
// one is found.
|
||||||
napi_env env = v8impl::GetEnv(context);
|
napi_env env = v8impl::GetEnv(context);
|
||||||
|
8
test/addons-napi/test_null_init/binding.gyp
Normal file
8
test/addons-napi/test_null_init/binding.gyp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
'targets': [
|
||||||
|
{
|
||||||
|
'target_name': 'test_null_init',
|
||||||
|
'sources': [ 'test_null_init.c' ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
7
test/addons-napi/test_null_init/test.js
Normal file
7
test/addons-napi/test_null_init/test.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => require(`./build/${common.buildType}/test_null_init`),
|
||||||
|
/Module has no declared entry point[.]/);
|
3
test/addons-napi/test_null_init/test_null_init.c
Normal file
3
test/addons-napi/test_null_init/test_null_init.c
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include <node_api.h>
|
||||||
|
|
||||||
|
NAPI_MODULE(NODE_GYP_MODULE_NAME, NULL)
|
Loading…
x
Reference in New Issue
Block a user