diff options
author | Michael Dawson <michael_dawson@ca.ibm.com> | 2017-05-19 18:18:54 -0400 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-05-28 07:00:37 -0700 |
commit | 4ccfd7cf15507198136b1d0e53f0166774444274 (patch) | |
tree | 0753a2a44a3f675470ea51fbb9577ba5cac46b94 | |
parent | 336d33b6466b7802cbc2fc609eadd6831ef2c240 (diff) | |
download | node-new-4ccfd7cf15507198136b1d0e53f0166774444274.tar.gz |
test: increase n-api constructor coverage
Add tests to validate that properties marked as static
are available through the class as opposed to instances
PR-URL: https://github.com/nodejs/node/pull/13124
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
-rw-r--r-- | test/addons-napi/test_constructor/test.js | 5 | ||||
-rw-r--r-- | test/addons-napi/test_constructor/test_constructor.c | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test/addons-napi/test_constructor/test.js b/test/addons-napi/test_constructor/test.js index 26083db7a2..75c7b36783 100644 --- a/test/addons-napi/test_constructor/test.js +++ b/test/addons-napi/test_constructor/test.js @@ -40,3 +40,8 @@ test_object.readwriteAccessor2 = 2; assert.strictEqual(test_object.readwriteAccessor2, 2); assert.strictEqual(test_object.readonlyAccessor2, 2); assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError); + +// validate that static properties are on the class as opposed +// to the instance +assert.strictEqual(TestConstructor.staticReadonlyAccessor1, 10); +assert.strictEqual(test_object.staticReadonlyAccessor1, undefined); diff --git a/test/addons-napi/test_constructor/test_constructor.c b/test/addons-napi/test_constructor/test_constructor.c index 0a73010d72..220d564753 100644 --- a/test/addons-napi/test_constructor/test_constructor.c +++ b/test/addons-napi/test_constructor/test_constructor.c @@ -2,6 +2,7 @@ #include "../common.h" static double value_ = 1; +static double static_value_ = 10; napi_ref constructor_; napi_value GetValue(napi_env env, napi_callback_info info) { @@ -45,6 +46,19 @@ napi_value New(napi_env env, napi_callback_info info) { return _this; } +napi_value GetStaticValue(napi_env env, napi_callback_info info) { + size_t argc = 0; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, NULL, NULL, NULL)); + + NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); + + napi_value number; + NAPI_CALL(env, napi_create_number(env, static_value_, &number)); + + return number; +} + + void Init(napi_env env, napi_value exports, napi_value module, void* priv) { napi_value number; NAPI_CALL_RETURN_VOID(env, napi_create_number(env, value_, &number)); @@ -58,6 +72,8 @@ void Init(napi_env env, napi_value exports, napi_value module, void* priv) { { "readwriteAccessor2", 0, 0, GetValue, SetValue, 0, napi_writable, 0}, { "readonlyAccessor1", 0, 0, GetValue, NULL, 0, napi_default, 0}, { "readonlyAccessor2", 0, 0, GetValue, NULL, 0, napi_writable, 0}, + { "staticReadonlyAccessor1", 0, 0, GetStaticValue, NULL, 0, + napi_default | napi_static, 0}, }; napi_value cons; |