summaryrefslogtreecommitdiff
path: root/test_napi/src
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-10 15:35:46 +0100
committerGitHub <noreply@github.com>2023-01-10 15:35:46 +0100
commit0329bc69dabbcc4d57ff9d34d695ffd4ddb1de4f (patch)
treeaa54ee523d47191c4816fe8d70839f8d892e3ba5 /test_napi/src
parent636352e0ca1e611c7673f2ab68538e1ddb2dc5b7 (diff)
fix(napi): handle static properties in classes (#17320)
Adds support for static properties when using "napi_define_class".
Diffstat (limited to 'test_napi/src')
-rw-r--r--test_napi/src/object_wrap.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/test_napi/src/object_wrap.rs b/test_napi/src/object_wrap.rs
index bedb6d852..5b15a16d7 100644
--- a/test_napi/src/object_wrap.rs
+++ b/test_napi/src/object_wrap.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use napi_sys::PropertyAttributes;
use napi_sys::Status::napi_ok;
use napi_sys::ValueType::napi_number;
use napi_sys::*;
@@ -116,13 +117,31 @@ impl NapiObject {
ptr::null_mut()
}
+
+ pub extern "C" fn factory(
+ env: napi_env,
+ info: napi_callback_info,
+ ) -> napi_value {
+ let (_args, argc, _this) = crate::get_callback_info!(env, info, 0);
+ assert_eq!(argc, 0);
+
+ let int64 = 64;
+ let mut value: napi_value = ptr::null_mut();
+ assert!(unsafe { napi_create_int64(env, int64, &mut value) } == napi_ok);
+ value
+ }
}
pub fn init(env: napi_env, exports: napi_value) {
+ let mut static_prop =
+ crate::new_property!(env, "factory\0", NapiObject::factory);
+ static_prop.attributes = PropertyAttributes::static_;
+
let properties = &[
crate::new_property!(env, "set_value\0", NapiObject::set_value),
crate::new_property!(env, "get_value\0", NapiObject::get_value),
crate::new_property!(env, "increment\0", NapiObject::increment),
+ static_prop,
];
let mut cons: napi_value = ptr::null_mut();