Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d4ab36

Browse filesBrowse files
Flarnaruyadorno
authored andcommitted
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`.
1 parent 7610fe5 commit 6d4ab36
Copy full SHA for 6d4ab36

File tree

Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+13-5Lines changed: 13 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,16 @@ provided by the addon:
17771777
```c
17781778
napi_value Init(napi_env env, napi_value exports) {
17791779
napi_status status;
1780-
napi_property_descriptor desc =
1781-
{"hello", NULL, Method, NULL, NULL, NULL, napi_default, NULL};
1780+
napi_property_descriptor desc = {
1781+
"hello",
1782+
NULL,
1783+
Method,
1784+
NULL,
1785+
NULL,
1786+
NULL,
1787+
napi_writable | napi_enumerable | napi_configurable,
1788+
NULL
1789+
};
17821790
status = napi_define_properties(env, exports, 1, &desc);
17831791
if (status != napi_ok) return NULL;
17841792
return exports;
@@ -1805,7 +1813,7 @@ To define a class so that new instances can be created (often used with
18051813
napi_value Init(napi_env env, napi_value exports) {
18061814
napi_status status;
18071815
napi_property_descriptor properties[] = {
1808-
{ "value", NULL, NULL, GetValue, SetValue, NULL, napi_default, NULL },
1816+
{ "value", NULL, NULL, GetValue, SetValue, NULL, napi_writable | napi_configurable, NULL },
18091817
DECLARE_NAPI_METHOD("plusOne", PlusOne),
18101818
DECLARE_NAPI_METHOD("multiply", Multiply),
18111819
};
@@ -3714,8 +3722,8 @@ if (status != napi_ok) return status;
37143722

37153723
// Set the properties
37163724
napi_property_descriptor descriptors[] = {
3717-
{ "foo", NULL, NULL, NULL, NULL, fooValue, napi_default, NULL },
3718-
{ "bar", NULL, NULL, NULL, NULL, barValue, napi_default, NULL }
3725+
{ "foo", NULL, NULL, NULL, NULL, fooValue, napi_writable | napi_configurable, NULL },
3726+
{ "bar", NULL, NULL, NULL, NULL, barValue, napi_writable | napi_configurable, NULL }
37193727
}
37203728
status = napi_define_properties(env,
37213729
obj,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.