Skip to content

Commit 9fbe91a

Browse files
RomainLanztargos
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 48ed81f commit 9fbe91a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/node_process.cc

+19-6
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"
@@ -626,8 +627,13 @@ void EnvGetter(Local<Name> property,
626627
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
627628
result < arraysize(buffer)) {
628629
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
629-
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
630-
return info.GetReturnValue().Set(rc);
630+
v8::MaybeLocal<String> rc = String::NewFromTwoByte(
631+
isolate, two_byte_buffer, v8::NewStringType::kNormal);
632+
if (rc.IsEmpty()) {
633+
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
634+
return;
635+
}
636+
return info.GetReturnValue().Set(rc.ToLocalChecked());
631637
}
632638
#endif
633639
}
@@ -768,10 +774,17 @@ void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
768774
}
769775
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(p);
770776
const size_t two_byte_buffer_len = s - p;
771-
argv[idx] = String::NewFromTwoByte(isolate,
772-
two_byte_buffer,
773-
String::kNormalString,
774-
two_byte_buffer_len);
777+
v8::MaybeLocal<String> rc =
778+
String::NewFromTwoByte(isolate,
779+
two_byte_buffer,
780+
v8::NewStringType::kNormal,
781+
two_byte_buffer_len);
782+
if (rc.IsEmpty()) {
783+
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
784+
FreeEnvironmentStringsW(environment);
785+
return;
786+
}
787+
argv[idx] = rc.ToLocalChecked();
775788
if (++idx >= arraysize(argv)) {
776789
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
777790
idx = 0;

0 commit comments

Comments
 (0)