summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRomain Lanz <romain.lanz@slynova.ch>2018-10-21 16:29:52 +0200
committerAnna Henningsen <anna@addaleax.net>2018-10-24 12:12:00 +0200
commitadded1b0c5ad82ed47921bea00f05aad85548a62 (patch)
tree97346e3c6473ca6a7ba938e5620ea6a0ca2795db /src
parent1365f657b51d31044cca54c3152d3940a4bd9dc3 (diff)
downloadandroid-node-v8-added1b0c5ad82ed47921bea00f05aad85548a62.tar.gz
android-node-v8-added1b0c5ad82ed47921bea00f05aad85548a62.tar.bz2
android-node-v8-added1b0c5ad82ed47921bea00f05aad85548a62.zip
src: refactor deprecated v8::String::NewFromTwoByte call
PR-URL: https://github.com/nodejs/node/pull/23803 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_process.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/node_process.cc b/src/node_process.cc
index 51041c49ed..600f85b804 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<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
}
@@ -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;