Skip to content

Commit

Permalink
src: refactor deprecated v8::String::NewFromTwoByte call
Browse files Browse the repository at this point in the history
PR-URL: #23803
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
RomainLanz authored and targos committed Oct 24, 2018
1 parent 48ed81f commit 9fbe91a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/node_process.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "node.h"
#include "node_internals.h"
#include "node_errors.h"
#include "base_object.h"
#include "base_object-inl.h"
#include "env-inl.h"
Expand Down Expand Up @@ -626,8 +627,13 @@ void EnvGetter(Local<Name> property,
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
result < arraysize(buffer)) {
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
return info.GetReturnValue().Set(rc);
v8::MaybeLocal<String> rc = String::NewFromTwoByte(
isolate, two_byte_buffer, v8::NewStringType::kNormal);
if (rc.IsEmpty()) {
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
return;
}
return info.GetReturnValue().Set(rc.ToLocalChecked());
}
#endif
}
Expand Down Expand Up @@ -768,10 +774,17 @@ void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
}
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(p);
const size_t two_byte_buffer_len = s - p;
argv[idx] = String::NewFromTwoByte(isolate,
two_byte_buffer,
String::kNormalString,
two_byte_buffer_len);
v8::MaybeLocal<String> rc =
String::NewFromTwoByte(isolate,
two_byte_buffer,
v8::NewStringType::kNormal,
two_byte_buffer_len);
if (rc.IsEmpty()) {
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
FreeEnvironmentStringsW(environment);
return;
}
argv[idx] = rc.ToLocalChecked();
if (++idx >= arraysize(argv)) {
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
idx = 0;
Expand Down

0 comments on commit 9fbe91a

Please sign in to comment.