diff options
author | Gerhard Stöbich <deb2001-github@yahoo.de> | 2020-09-18 23:04:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 23:04:23 +0300 |
commit | a63b90e8b1e2fd35afe3f7994207da66a315fc1e (patch) | |
tree | e881a230c95a936c83a84d4488c534fe1859d29d /doc/api/n-api.md | |
parent | ed8af4e93831d3cf21d5562e900371d796b5fa20 (diff) |
doc: update attributes used by n-api samples (#35220)
Update n-api samples to create object properties matching to the JS defaults.
Using non configurable, non writable properties has its usecases but
the JS default for class methods is `configurable` and `writable`.
Js properties set by JS code `obj.prop = val` are `configurable`, `writable`
and `enumerable`.
Diffstat (limited to 'doc/api/n-api.md')
-rw-r--r-- | doc/api/n-api.md | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 22fe991142f..c02a034e2a9 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1777,8 +1777,16 @@ provided by the addon: ```c napi_value Init(napi_env env, napi_value exports) { napi_status status; - napi_property_descriptor desc = - {"hello", NULL, Method, NULL, NULL, NULL, napi_default, NULL}; + napi_property_descriptor desc = { + "hello", + NULL, + Method, + NULL, + NULL, + NULL, + napi_writable | napi_enumerable | napi_configurable, + NULL + }; status = napi_define_properties(env, exports, 1, &desc); if (status != napi_ok) return NULL; return exports; @@ -1805,7 +1813,7 @@ To define a class so that new instances can be created (often used with napi_value Init(napi_env env, napi_value exports) { napi_status status; napi_property_descriptor properties[] = { - { "value", NULL, NULL, GetValue, SetValue, NULL, napi_default, NULL }, + { "value", NULL, NULL, GetValue, SetValue, NULL, napi_writable | napi_configurable, NULL }, DECLARE_NAPI_METHOD("plusOne", PlusOne), DECLARE_NAPI_METHOD("multiply", Multiply), }; @@ -3719,8 +3727,8 @@ if (status != napi_ok) return status; // Set the properties napi_property_descriptor descriptors[] = { - { "foo", NULL, NULL, NULL, NULL, fooValue, napi_default, NULL }, - { "bar", NULL, NULL, NULL, NULL, barValue, napi_default, NULL } + { "foo", NULL, NULL, NULL, NULL, fooValue, napi_writable | napi_configurable, NULL }, + { "bar", NULL, NULL, NULL, NULL, barValue, napi_writable | napi_configurable, NULL } } status = napi_define_properties(env, obj, |