From 08c1065ecefbb4c01d299238f891fbd92c8661ba Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Sun, 21 Oct 2018 16:29:52 +0200 Subject: [PATCH] src: refactor deprecated v8::String::NewFromTwoByte call --- src/node_process.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/node_process.cc b/src/node_process.cc index 51041c49eda71b..600f85b8044671 100644 --- a/src/node_process.cc +++ b/src/node_process.cc @@ -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" @@ -626,8 +627,13 @@ void EnvGetter(Local property, if ((result > 0 || GetLastError() == ERROR_SUCCESS) && result < arraysize(buffer)) { const uint16_t* two_byte_buffer = reinterpret_cast(buffer); - Local rc = String::NewFromTwoByte(isolate, two_byte_buffer); - return info.GetReturnValue().Set(rc); + v8::MaybeLocal 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 } @@ -768,10 +774,17 @@ void EnvEnumerator(const PropertyCallbackInfo& info) { } const uint16_t* two_byte_buffer = reinterpret_cast(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 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;