diff options
Diffstat (limited to 'test/addons-napi/test_constructor_name')
-rw-r--r-- | test/addons-napi/test_constructor_name/binding.gyp | 8 | ||||
-rw-r--r-- | test/addons-napi/test_constructor_name/test.js | 7 | ||||
-rw-r--r-- | test/addons-napi/test_constructor_name/test_constructor_name.c | 23 |
3 files changed, 38 insertions, 0 deletions
diff --git a/test/addons-napi/test_constructor_name/binding.gyp b/test/addons-napi/test_constructor_name/binding.gyp new file mode 100644 index 0000000000..8beb209888 --- /dev/null +++ b/test/addons-napi/test_constructor_name/binding.gyp @@ -0,0 +1,8 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ "test_constructor_name.c" ] + } + ] +} diff --git a/test/addons-napi/test_constructor_name/test.js b/test/addons-napi/test_constructor_name/test.js new file mode 100644 index 0000000000..0f713ff55c --- /dev/null +++ b/test/addons-napi/test_constructor_name/test.js @@ -0,0 +1,7 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); + +// Testing api calls for a constructor that defines properties +const TestConstructor = require(`./build/${common.buildType}/binding`); +assert.strictEqual(TestConstructor.name, 'MyObject'); diff --git a/test/addons-napi/test_constructor_name/test_constructor_name.c b/test/addons-napi/test_constructor_name/test_constructor_name.c new file mode 100644 index 0000000000..a5c89791f0 --- /dev/null +++ b/test/addons-napi/test_constructor_name/test_constructor_name.c @@ -0,0 +1,23 @@ +#include <node_api.h> +#include "../common.h" + +napi_ref constructor_; + +napi_value New(napi_env env, napi_callback_info info) { + napi_value _this; + NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &_this, NULL)); + + return _this; +} + +napi_value Init(napi_env env, napi_value exports) { + napi_value cons; + NAPI_CALL(env, napi_define_class( + env, "MyObject_Extra", 8, New, NULL, 0, NULL, &cons)); + + NAPI_CALL(env, + napi_create_reference(env, cons, 1, &constructor_)); + return cons; +} + +NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) |