GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node-api: use WriteV2 in napi_get_value_string_utf16 · nodejs/node@429c38d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • js_native_api_v8.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/js_native_api_v8.cc‎

Copy file name to clipboardExpand all lines: src/js_native_api_v8.cc
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,21 +2520,23 @@ napi_status NAPI_CDECL napi_get_value_string_utf16(napi_env env,
25202520

25212521
v8::Local<v8::Value> val = v8impl::V8LocalValueFromJsValue(value);
25222522
RETURN_STATUS_IF_FALSE(env, val->IsString(), napi_string_expected);
2523+
v8::Local<v8::String> str = val.As<v8::String>();
25232524

25242525
if (!buf) {
25252526
CHECK_ARG(env, result);
25262527
// V8 assumes UTF-16 length is the same as the number of characters.
2527-
*result = val.As<v8::String>()->Length();
2528+
*result = str->Length();
25282529
} else if (bufsize != 0) {
2529-
int copied = val.As<v8::String>()->Write(env->isolate,
2530-
reinterpret_cast<uint16_t*>(buf),
2531-
0,
2532-
bufsize - 1,
2533-
v8::String::NO_NULL_TERMINATION);
2530+
uint32_t length = static_cast<uint32_t>(
2531+
std::min(bufsize - 1, static_cast<size_t>(str->Length())));
2532+
str->WriteV2(env->isolate,
2533+
0,
2534+
length,
2535+
reinterpret_cast<uint16_t*>(buf),
2536+
v8::String::WriteFlags::kNullTerminate);
25342537

2535-
buf[copied] = '\0';
25362538
if (result != nullptr) {
2537-
*result = copied;
2539+
*result = length;
25382540
}
25392541
} else if (result != nullptr) {
25402542
*result = 0;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.