8000
We read every piece of feedback, and take your input very seriously.
1 parent ef177da commit e2462a2Copy full SHA for e2462a2
src/js_native_api_v8.cc
@@ -936,8 +936,8 @@ napi_status napi_get_all_property_names(napi_env env,
936
filter | v8::PropertyFilter::ONLY_ENUMERABLE);
937
}
938
if (key_filter & napi_key_configurable) {
939
- filter = static_cast<v8::PropertyFilter>(filter |
940
- v8::PropertyFilter::ONLY_WRITABLE);
+ filter = static_cast<v8::PropertyFilter>(
+ filter | v8::PropertyFilter::ONLY_CONFIGURABLE);
941
942
if (key_filter & napi_key_skip_strings) {
943
filter = static_cast<v8::PropertyFilter>(filter |
test/js-native-api/test_object/test.js
@@ -19,7 +19,7 @@ const object = {
19
assert.strictEqual(test_object.Get(object, 'hello'), 'world');
20
assert.strictEqual(test_object.GetNamed(object, 'hello'), 'world');
21
assert.deepStrictEqual(test_object.Get(object, 'array'),
22
- [ 1, 94, 'str', 12.321, { test: 'obj in arr' } ]);
+ [1, 94, 'str', 12.321, { test: 'obj in arr' }]);
23
assert.deepStrictEqual(test_object.Get(object, 'newObject'),
24
{ test: 'obj in obj' });
25
@@ -54,7 +54,7 @@ assert.strictEqual(newObject.test_string, 'test string');
54
55
{
56
// Verify that napi_has_own_property() fails if property is not a name.
57
- [true, false, null, undefined, {}, [], 0, 1, () => {}].forEach((value) => {
+ [true, false, null, undefined, {}, [], 0, 1, () => { }].forEach((value) => {
58
assert.throws(() => {
59
test_object.HasOwn({}, value);
60
}, /^Error: A string or symbol was expected$/);
@@ -240,13 +240,57 @@ assert.strictEqual(newObject.test_string, 'test string');
240
writable: true,
241
configurable: true
242
});
243
+ Object.defineProperty(object, 'writable', {
244
+ value: 4,
245
+ enumerable: true,
246
+ writable: true,
247
+ configurable: false
248
+ });
249
+ Object.defineProperty(object, 'configurable', {
250
251
252
+ writable: false,
253
+ configurable: true
254
255
object[5] = 5;
256
257
assert.deepStrictEqual(test_object.GetPropertyNames(object),
- ['5', 'normal', 'inherited']);
258
+ ['5',
259
+ 'normal',
260
+ 'writable',
261
+ 'configurable',
262
+ 'inherited']);
263
264
assert.deepStrictEqual(test_object.GetSymbolNames(object),
265
[fooSymbol]);
266
+
267
+ assert.deepStrictEqual(test_object.GetEnumerableWritableNames(object),
268
269
270
271
+ fooSymbol,
272
273
274
+ assert.deepStrictEqual(test_object.GetOwnWritableNames(object),
275
276
277
+ 'unenumerable',
278
279
+ fooSymbol]);
280
281
+ assert.deepStrictEqual(test_object.GetEnumerableConfigurableNames(object),
282
283
284
285
286
287
288
+ assert.deepStrictEqual(test_object.GetOwnConfigurableNames(object),
289
290
291
292
293
294
295
296
// Verify that passing NULL to napi_set_property() results in the correct
test/js-native-api/test_object/test_object.c
@@ -106,6 +106,119 @@ static napi_value GetSymbolNames(napi_env env, napi_callback_info info) {
106
return output;
107
108
109
+static napi_value GetEnumerableWritableNames(napi_env env,
110
+ napi_callback_info info) {
111
+ size_t argc = 1;
112
+ napi_value args[1];
113
+ NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
114
115
+ NODE_API_ASSERT(env, argc >= 1, "Wrong number of arguments");
116
117
+ napi_valuetype value_type0;
118
+ NODE_API_CALL(env, napi_typeof(env, args[0], &value_type0));
119
120
+ NODE_API_ASSERT(
121
+ env,
122
+ value_type0 == napi_object,
123
+ "Wrong type of arguments. Expects an object as first argument.");
124
125
+ napi_value output;
126
+ NODE_API_CALL(
127
128
+ napi_get_all_property_names(env,
129
+ args[0],
130
+ napi_key_include_prototypes,
131
+ napi_key_enumerable | napi_key_writable,
132
+ napi_key_numbers_to_strings,
133
+ &output));
134
135
+ return output;
136
+}
137
138
+static napi_value GetOwnWritableNames(napi_env env, napi_callback_info info) {
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
+ NODE_API_CALL(env,
155
156
157
+ napi_key_own_only,
158
+ napi_key_writable,
159
160
161
162
163
164
165
+static napi_value GetEnumerableConfigurableNames(napi_env env,
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
+ napi_key_enumerable | napi_key_configurable,
188
189
190
191
192
193
194
+static napi_value GetOwnConfigurableNames(napi_env env,
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
+ napi_key_configurable,
216
217
218
219
220
221
222
static napi_value Set(napi_env env, napi_callback_info info) {
223
size_t argc = 3;
224
napi_value args[3];
@@ -536,6 +649,10 @@ napi_value Init(napi_env env, napi_value exports) {
536
649
DECLARE_NODE_API_PROPERTY("GetNamed", GetNamed),
537
650
DECLARE_NODE_API_PROPERTY("GetPropertyNames", GetPropertyNames),
538
651
DECLARE_NODE_API_PROPERTY("GetSymbolNames", GetSymbolNames),
652
+ DECLARE_NODE_API_PROPERTY("GetEnumerableWritableNames", GetEnumerableWritableNames),
653
+ DECLARE_NODE_API_PROPERTY("GetOwnWritableNames", GetOwnWritableNames),
654
+ DECLARE_NODE_API_PROPERTY("GetEnumerableConfigurableNames", GetEnumerableConfigurableNames),
655
+ DECLARE_NODE_API_PROPERTY("GetOwnConfigurableNames", GetOwnConfigurableNames),
539
656
DECLARE_NODE_API_PROPERTY("Set", Set),
540
657
DECLARE_NODE_API_PROPERTY("SetNamed", SetNamed),
541
658
DECLARE_NODE_API_PROPERTY("Has", Has),