Skip to content

Commit

Permalink
n-api: throw when entry point is null
Browse files Browse the repository at this point in the history
PR-URL: nodejs#20779
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Gabriel Schulhof committed Jul 14, 2018
1 parent 52cc2d2 commit d4e5de2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
void* priv) {
napi_module* mod = static_cast<napi_module*>(priv);

if (mod->nm_register_func == 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
// one is found.
napi_env env = v8impl::GetEnv(context);
Expand Down
8 changes: 8 additions & 0 deletions test/addons-napi/test_null_init/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'test_null_init',
'sources': [ 'test_null_init.c' ]
}
]
}
7 changes: 7 additions & 0 deletions test/addons-napi/test_null_init/test.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions test/addons-napi/test_null_init/test_null_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <node_api.h>

NAPI_MODULE(NODE_GYP_MODULE_NAME, NULL)

0 comments on commit d4e5de2

Please sign in to comment.