Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d316f64

Browse filesBrowse files
RomainLanzMylesBorins
authored andcommitted
src: refactor deprecated v8::String::NewFromTwoByte call
PR-URL: #23803 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c601fde commit d316f64
Copy full SHA for d316f64

File tree

Expand file treeCollapse file tree

1 file changed

+19
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-6
lines changed
Open diff view settings
Collapse file

‎src/node_process.cc‎

Copy file name to clipboardExpand all lines: src/node_process.cc
+19-6Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "node.h"
22
#include "node_internals.h"
3+
#include "node_errors.h"
34
#include "base_object.h"
45
#include "base_object-inl.h"
56
#include "env-inl.h"
@@ -617,8 +618,13 @@ void EnvGetter(Local<Name> property,
617618
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
618619
result < arraysize(buffer)) {
619620
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
620-
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
621-
return info.GetReturnValue().Set(rc);
621+
v8::MaybeLocal<String> rc = String::NewFromTwoByte(
622+
isolate, two_byte_buffer, v8::NewStringType::kNormal);
623+
if (rc.IsEmpty()) {
624+
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
625+
return;
626+
}
627+
return info.GetReturnValue().Set(rc.ToLocalChecked());
622628
}
623629
#endif
624630
}
@@ -759,10 +765,17 @@ void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
759765
}
760766
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(p);
761767
const size_t two_byte_buffer_len = s - p;
762-
argv[idx] = String::NewFromTwoByte(isolate,
763-
two_byte_buffer,
764-
String::kNormalString,
765-
two_byte_buffer_len);
768+
v8::MaybeLocal<String> rc =
769+
String::NewFromTwoByte(isolate,
770+
two_byte_buffer,
771+
v8::NewStringType::kNormal,
772+
two_byte_buffer_len);
773+
if (rc.IsEmpty()) {
774+
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
775+
FreeEnvironmentStringsW(environment);
776+
return;
777+
}
778+
argv[idx] = rc.ToLocalChecked();
766779
if (++idx >= arraysize(argv)) {
767780
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
768781
idx = 0;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.