Skip to content

Commit

Permalink
n-api: refactor napi_set_property function for improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mert.altin committed Oct 19, 2023
1 parent b30acb7 commit 3b5302d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ For information about the governance of the Node.js project, see
**Michaël Zasso** <<targos@protonmail.com>> (he/him)
* [tniessen](https://github.com/tniessen) -
**Tobias Nießen** <<tniessen@tnie.de>> (he/him)
* [Trott](https://github.com/Trott) -
**Rich Trott** <<rtrott@gmail.com>> (he/him)

#### TSC regular members

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

<details>

Expand Down
1 change: 1 addition & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ function fromString(string, encoding) {
if (string.length === 0)
return new FastBuffer();
ops = encodingOps.utf8;
encoding = undefined;
} else {
ops = getEncodingOps(encoding);
if (ops === undefined)
Expand Down
25 changes: 25 additions & 0 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,31 @@ napi_status NAPI_CDECL napi_set_property(napi_env env,
return GET_RETURN_STATUS(env);
}

napi_status NAPI_CDECL napi_set_property_utf16(napi_env env,
napi_value object,
const uint16_t* utf16name,
napi_value value) {
NAPI_PREAMBLE(env);
CHECK_ARG(env, utf16name);
CHECK_ARG(env, value);

v8::Local<v8::Context> context = env->context();
v8::Local<v8::Object> obj;

CHECK_TO_OBJECT(env, context, obj, object);

v8::Local<v8::Value> k = v8::String::NewFromTwoByte(context->GetIsolate(),
utf16name,
v8::NewStringType::kNormal)
.ToLocalChecked();
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);

v8::Maybe<bool> set_maybe = obj->Set(context, k, val);

RETURN_STATUS_IF_FALSE(env, set_maybe.FromMaybe(false), napi_generic_failure);
return GET_RETURN_STATUS(env);
}

napi_status NAPI_CDECL napi_has_property(napi_env env,
napi_value object,
napi_value key,
Expand Down
2 changes: 0 additions & 2 deletions test/pummel/pummel.status
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ prefix pummel
[$system==win32]
# https://github.com/nodejs/node/issues/40728
test-fs-watch-non-recursive: PASS,FLAKY
# https://github.com/nodejs/node/issues/50260
test-structuredclone-jstransferable: PASS,FLAKY

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

0 comments on commit 3b5302d

Please sign in to comment.