Skip to content

Commit 9523e2c

Browse files
anonrigmhdawson
authored andcommitted
test: set test-structuredclone-* as flaky
PR-URL: nodejs#50261 Refs: nodejs#50260 Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> meta: move Trott to TSC regular member At the current time, I'm not able to give Node.js the time and attention it needs and deserves from a voting TSC member. I'm proud of the work and efforts I've made as a TSC voting member, and I want to leave before I'm less happy with my efforts. Thanks for all the trust and good will over the years. PR-URL: nodejs#50297 Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: Richard Lau <rlau@redhat.com> node-api: refactor napi set property function for improved performance fix: lint fix: lint refactor: Improve performance by using internalized property keys refactor: Update node_api_create_property_key_utf16 signature and remove napi_set_property_utf16 lint lint fix: Resolve compilation error in node_api_create_property_key_utf16 fix: Resolve type conversion error in node_api_create_property_key_utf16 refactor: Simplify node_api_create_property_key_utf16 implementation lint add node_api_create_property_key_utf16 property name added doc for node_api_create_property_key_utf16 lint lint update napi doc for node_api_create_property_key_utf16 update: code snipet test: added test for node_api_create_property_key_utf16 lint lint lint call node_api_create_property_key_utf16 Update doc/api/n-api.md Co-authored-by: Chengzhong Wu <legendecas@gmail.com> Update test/js-native-api/test_string/test_string.c Co-authored-by: Chengzhong Wu <legendecas@gmail.com> Update test/js-native-api/test_string/test_string.c Co-authored-by: Chengzhong Wu <legendecas@gmail.com> Update doc/api/n-api.md Co-authored-by: Chengzhong Wu <legendecas@gmail.com> added TestPropertyKeyUtf16 napi_property_descriptor lint doc lint cpp minor updates to PR nodejs#50282 feat: removed not used function for test Update doc/api/n-api.md Co-authored-by: Michael Dawson <mdawson@devrus.com> Update doc/api/n-api.md Co-authored-by: Michael Dawson <mdawson@devrus.com>
1 parent e45e73b commit 9523e2c

File tree

7 files changed

+101
-2
lines changed

7 files changed

+101
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ For information about the governance of the Node.js project, see
204204
**Michaël Zasso** <<targos@protonmail.com>> (he/him)
205205
* [tniessen](https://github.com/tniessen) -
206206
**Tobias Nießen** <<tniessen@tnie.de>> (he/him)
207-
* [Trott](https://github.com/Trott) -
208-
**Rich Trott** <<rtrott@gmail.com>> (he/him)
209207

210208
#### TSC regular members
211209

@@ -233,6 +231,8 @@ For information about the governance of the Node.js project, see
233231
**Rod Vagg** <<r@va.gg>>
234232
* [TimothyGu](https://github.com/TimothyGu) -
235233
**Tiancheng "Timothy" Gu** <<timothygu99@gmail.com>> (he/him)
234+
* [Trott](https://github.com/Trott) -
235+
**Rich Trott** <<rtrott@gmail.com>> (he/him)
236236

237237
<details>
238238

doc/api/n-api.md

+44
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,50 @@ The native string is copied.
30003000
The JavaScript `string` type is described in
30013001
[Section 6.1.4][] of the ECMAScript Language Specification.
30023002

3003+
#### `node_api_create_property_key_utf16`
3004+
3005+
<!-- YAML
3006+
added: REPLACEME
3007+
-->
3008+
3009+
> Stability: 1 - Experimental
3010+
3011+
```c
3012+
napi_status NAPI_CDECL node_api_create_property_key_utf16(napi_env env,
3013+
const char16_t* str,
3014+
size_t length,
3015+
napi_value* result);
3016+
```
3017+
3018+
* `[in] env`: The environment that the API is invoked under.
3019+
* `[in] str`: Character buffer representing a UTF16-LE-encoded string.
3020+
* `[in] length`: The length of the string in two-byte code units, or
3021+
`NAPI_AUTO_LENGTH` if it is null-terminated.
3022+
* `[out] result`: A `napi_value` representing an optimized JavaScript `string`
3023+
to be used as a property key for objects.
3024+
3025+
Returns `napi_ok` if the API succeeded.
3026+
3027+
This API creates an optimized JavaScript `string` value from
3028+
a UTF16-LE-encoded C string to be used as a property key for objects.
3029+
The native string is copied.
3030+
3031+
Many JavaScript engines including V8 use internalized strings as keys
3032+
to set and get property values. They typically use a hash table to create
3033+
and lookup such strings. While it adds some cost per key creation, it improves
3034+
the performance after that by enabling comparison of string pointers instead
3035+
of the whole strings.
3036+
3037+
If a new JavaScript string is intended to be used as a property key, then for
3038+
some JavaScript engines it will be more efficient to use
3039+
the `node_api_create_property_key_utf16` function.
3040+
Otherwise, use the `napi_create_string_utf16` or
3041+
`node_api_create_external_string_utf16` functions as there may be additional
3042+
overhead in creating/storing strings with this method.
3043+
3044+
The JavaScript `string` type is described in
3045+
[Section 6.1.4][] of the ECMAScript Language Specification.
3046+
30033047
### Functions to convert from Node-API to C types
30043048

30053049
#### `napi_get_array_length`

src/js_native_api.h

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ node_api_create_external_string_utf16(napi_env env,
110110
napi_value* result,
111111
bool* copied);
112112
#endif // NAPI_EXPERIMENTAL
113+
114+
#ifdef NAPI_EXPERIMENTAL
115+
#define NODE_API_EXPERIMENTAL_HAS_PROPERTY_KEYS
116+
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf16(
117+
napi_env env, const char16_t* str, size_t length, napi_value* result);
118+
#endif // NAPI_EXPERIMENTAL
119+
113120
NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
114121
napi_value description,
115122
napi_value* result);

src/js_native_api_v8.cc

+12
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,18 @@ node_api_create_external_string_utf16(napi_env env,
16511651
});
16521652
}
16531653

1654+
napi_status NAPI_CDECL node_api_create_property_key_utf16(napi_env env,
1655+
const char16_t* str,
1656+
size_t length,
1657+
napi_value* result) {
1658+
return v8impl::NewString(env, str, length, result, [&](v8::Isolate* isolate) {
1659+
return v8::String::NewFromTwoByte(isolate,
1660+
reinterpret_cast<const uint16_t*>(str),
1661+
v8::NewStringType::kInternalized,
1662+
static_cast<int>(length));
1663+
});
1664+
}
1665+
16541666
napi_status NAPI_CDECL napi_create_double(napi_env env,
16551667
double value,
16561668
napi_value* result) {

test/js-native-api/test_string/test.js

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ assert.strictEqual(test_string.TestLatin1External(empty), empty);
1616
assert.strictEqual(test_string.TestUtf16External(empty), empty);
1717
assert.strictEqual(test_string.TestLatin1ExternalAutoLength(empty), empty);
1818
assert.strictEqual(test_string.TestUtf16ExternalAutoLength(empty), empty);
19+
assert.strictEqual(test_string.TestPropertyKeyUtf16(empty), empty);
20+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(empty), empty);
1921
assert.strictEqual(test_string.Utf16Length(empty), 0);
2022
assert.strictEqual(test_string.Utf8Length(empty), 0);
2123

@@ -33,6 +35,8 @@ assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str1), str1);
3335
assert.strictEqual(test_string.TestLatin1Insufficient(str1), str1.slice(0, 3));
3436
assert.strictEqual(test_string.TestUtf8Insufficient(str1), str1.slice(0, 3));
3537
assert.strictEqual(test_string.TestUtf16Insufficient(str1), str1.slice(0, 3));
38+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str1), str1);
39+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str1), str1);
3640
assert.strictEqual(test_string.Utf16Length(str1), 11);
3741
assert.strictEqual(test_string.Utf8Length(str1), 11);
3842

@@ -50,6 +54,8 @@ assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str2), str2);
5054
assert.strictEqual(test_string.TestLatin1Insufficient(str2), str2.slice(0, 3));
5155
assert.strictEqual(test_string.TestUtf8Insufficient(str2), str2.slice(0, 3));
5256
assert.strictEqual(test_string.TestUtf16Insufficient(str2), str2.slice(0, 3));
57+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str2), str2);
58+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str2), str2);
5359
assert.strictEqual(test_string.Utf16Length(str2), 62);
5460
assert.strictEqual(test_string.Utf8Length(str2), 62);
5561

@@ -67,6 +73,8 @@ assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str3), str3);
6773
assert.strictEqual(test_string.TestLatin1Insufficient(str3), str3.slice(0, 3));
6874
assert.strictEqual(test_string.TestUtf8Insufficient(str3), str3.slice(0, 3));
6975
assert.strictEqual(test_string.TestUtf16Insufficient(str3), str3.slice(0, 3));
76+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str3), str3);
77+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str3), str3);
7078
assert.strictEqual(test_string.Utf16Length(str3), 27);
7179
assert.strictEqual(test_string.Utf8Length(str3), 27);
7280

@@ -84,6 +92,8 @@ assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str4), str4);
8492
assert.strictEqual(test_string.TestLatin1Insufficient(str4), str4.slice(0, 3));
8593
assert.strictEqual(test_string.TestUtf8Insufficient(str4), str4.slice(0, 1));
8694
assert.strictEqual(test_string.TestUtf16Insufficient(str4), str4.slice(0, 3));
95+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str4), str4);
96+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str4), str4);
8797
assert.strictEqual(test_string.Utf16Length(str4), 31);
8898
assert.strictEqual(test_string.Utf8Length(str4), 62);
8999

@@ -101,6 +111,8 @@ assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str5), str5);
101111
assert.strictEqual(test_string.TestLatin1Insufficient(str5), str5.slice(0, 3));
102112
assert.strictEqual(test_string.TestUtf8Insufficient(str5), str5.slice(0, 1));
103113
assert.strictEqual(test_string.TestUtf16Insufficient(str5), str5.slice(0, 3));
114+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str5), str5);
115+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str5), str5);
104116
assert.strictEqual(test_string.Utf16Length(str5), 63);
105117
assert.strictEqual(test_string.Utf8Length(str5), 126);
106118

@@ -113,6 +125,8 @@ assert.strictEqual(test_string.TestUtf16External(str6), str6);
113125
assert.strictEqual(test_string.TestUtf16ExternalAutoLength(str6), str6);
114126
assert.strictEqual(test_string.TestUtf8Insufficient(str6), str6.slice(0, 1));
115127
assert.strictEqual(test_string.TestUtf16Insufficient(str6), str6.slice(0, 3));
128+
assert.strictEqual(test_string.TestPropertyKeyUtf16(str6), str6);
129+
assert.strictEqual(test_string.TestPropertyKeyUtf16AutoLength(str6), str6);
116130
assert.strictEqual(test_string.Utf16Length(str6), 5);
117131
assert.strictEqual(test_string.Utf8Length(str6), 14);
118132

test/js-native-api/test_string/test_string.c

+20
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,23 @@ static napi_value TestUtf16Insufficient(napi_env env, napi_callback_info info) {
294294
return output;
295295
}
296296

297+
static napi_value TestPropertyKeyUtf16(napi_env env, napi_callback_info info) {
298+
return TestTwoByteImpl(env,
299+
info,
300+
napi_get_value_string_utf16,
301+
node_api_create_property_key_utf16,
302+
actual_length);
303+
}
304+
305+
static napi_value TestPropertyKeyUtf16AutoLength(napi_env env,
306+
napi_callback_info info) {
307+
return TestTwoByteImpl(env,
308+
info,
309+
napi_get_value_string_utf16,
310+
node_api_create_property_key_utf16,
311+
auto_length);
312+
}
313+
297314
static napi_value Utf16Length(napi_env env, napi_callback_info info) {
298315
napi_value args[1];
299316
NODE_API_CALL(env, validate_and_retrieve_single_string_arg(env, info, args));
@@ -410,6 +427,9 @@ napi_value Init(napi_env env, napi_value exports) {
410427
DECLARE_NODE_API_PROPERTY("TestLargeLatin1", TestLargeLatin1),
411428
DECLARE_NODE_API_PROPERTY("TestLargeUtf16", TestLargeUtf16),
412429
DECLARE_NODE_API_PROPERTY("TestMemoryCorruption", TestMemoryCorruption),
430+
DECLARE_NODE_API_PROPERTY("TestPropertyKeyUtf16", TestPropertyKeyUtf16),
431+
DECLARE_NODE_API_PROPERTY("TestPropertyKeyUtf16AutoLength",
432+
TestPropertyKeyUtf16AutoLength),
413433
};
414434

415435
init_test_null(env, exports);

test/pummel/pummel.status

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ prefix pummel
99
[$system==win32]
1010
# https://github.com/nodejs/node/issues/40728
1111
test-fs-watch-non-recursive: PASS,FLAKY
12+
# https://github.com/nodejs/node/issues/50260
13+
test-structuredclone-jstransferable: PASS,FLAKY
1214

1315
[$system==linux]
1416
# https://github.com/nodejs/node/issues/38226

0 commit comments

Comments
 (0)