mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
test: increase n-api constructor coverage
Add tests to validate that properties marked as static are available through the class as opposed to instances Backport-PR-URL: https://github.com/nodejs/node/pull/19447 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>
This commit is contained in:
1 parent
2e2905266e
commit
d89afe8685
2 files changed
+21
No files matched your search
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user