Skip to content

Commit 3b5302d

Browse files
author
mert.altin
committed
n-api: refactor napi_set_property function for improved performance
1 parent b30acb7 commit 3b5302d

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

README.md

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

208210
#### TSC regular members
209211

@@ -231,8 +233,6 @@ For information about the governance of the Node.js project, see
231233
**Rod Vagg** <<[email protected]>>
232234
* [TimothyGu](https://github.com/TimothyGu) -
233235
**Tiancheng "Timothy" Gu** <<[email protected]>> (he/him)
234-
* [Trott](https://github.com/Trott) -
235-
**Rich Trott** <<[email protected]>> (he/him)
236236

237237
<details>
238238

lib/buffer.js

+1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function fromString(string, encoding) {
475475
if (string.length === 0)
476476
return new FastBuffer();
477477
ops = encodingOps.utf8;
478+
encoding = undefined;
478479
} else {
479480
ops = getEncodingOps(encoding);
480481
if (ops === undefined)

src/js_native_api_v8.cc

+25
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,31 @@ napi_status NAPI_CDECL napi_set_property(napi_env env,
11091109
return GET_RETURN_STATUS(env);
11101110
}
11111111

1112+
napi_status NAPI_CDECL napi_set_property_utf16(napi_env env,
1113+
napi_value object,
1114+
const uint16_t* utf16name,
1115+
napi_value value) {
1116+
NAPI_PREAMBLE(env);
1117+
CHECK_ARG(env, utf16name);
1118+
CHECK_ARG(env, value);
1119+
1120+
v8::Local<v8::Context> context = env->context();
1121+
v8::Local<v8::Object> obj;
1122+
1123+
CHECK_TO_OBJECT(env, context, obj, object);
1124+
1125+
v8::Local<v8::Value> k = v8::String::NewFromTwoByte(context->GetIsolate(),
1126+
utf16name,
1127+
v8::NewStringType::kNormal)
1128+
.ToLocalChecked();
1129+
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
1130+
1131+
v8::Maybe<bool> set_maybe = obj->Set(context, k, val);
1132+
1133+
RETURN_STATUS_IF_FALSE(env, set_maybe.FromMaybe(false), napi_generic_failure);
1134+
return GET_RETURN_STATUS(env);
1135+
}
1136+
11121137
napi_status NAPI_CDECL napi_has_property(napi_env env,
11131138
napi_value object,
11141139
napi_value key,

test/pummel/pummel.status

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ 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
1412

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

0 commit comments

Comments
 (0)