diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-08-26 11:28:17 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-08-29 13:28:14 +0300 |
commit | a64fd7f320af90dd76b7d922f104e5715797f0a6 (patch) | |
tree | 426036092af5c19bc0c90c4bb8424d0c69686d6a /src/node_buffer.cc | |
parent | 7c84489b8828797e77236da26594bd642d0120f9 (diff) |
src: use String::Write{OneByte,Utf8} with isolate
PR-URL: https://github.com/nodejs/node/pull/22531
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 858852e748f..95ffaa1993f 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -806,15 +806,16 @@ int64_t IndexOfOffset(size_t length, } void IndexOfString(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); + CHECK(args[1]->IsString()); CHECK(args[2]->IsNumber()); CHECK(args[4]->IsBoolean()); - enum encoding enc = ParseEncoding(args.GetIsolate(), - args[3], - UTF8); + enum encoding enc = ParseEncoding(isolate, args[3], UTF8); - THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); + THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); Local<String> needle = args[1].As<String>(); @@ -826,8 +827,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { const size_t haystack_length = (enc == UCS2) ? ts_obj_length &~ 1 : ts_obj_length; // NOLINT(whitespace/operators) - const size_t needle_length = - StringBytes::Size(args.GetIsolate(), needle, enc); + const size_t needle_length = StringBytes::Size(isolate, needle, enc); int64_t opt_offset = IndexOfOffset(haystack_length, offset_i64, @@ -857,7 +857,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { size_t result = haystack_length; if (enc == UCS2) { - String::Value needle_value(args.GetIsolate(), needle); + String::Value needle_value(isolate, needle); if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); @@ -867,7 +867,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { if (IsBigEndian()) { StringBytes::InlineDecoder decoder; - decoder.Decode(Environment::GetCurrent(args), needle, args[3], UCS2); + decoder.Decode(env, needle, args[3], UCS2); const uint16_t* decoded_string = reinterpret_cast<const uint16_t*>(decoder.out()); @@ -890,7 +890,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { } result *= 2; } else if (enc == UTF8) { - String::Utf8Value needle_value(args.GetIsolate(), needle); + String::Utf8Value needle_value(isolate, needle); if (*needle_value == nullptr) return args.GetReturnValue().Set(-1); @@ -906,7 +906,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { return args.GetReturnValue().Set(-1); } needle->WriteOneByte( - needle_data, 0, needle_length, String::NO_NULL_TERMINATION); + isolate, needle_data, 0, needle_length, String::NO_NULL_TERMINATION); result = SearchString(reinterpret_cast<const uint8_t*>(haystack), haystack_length, @@ -1057,18 +1057,20 @@ void Swap64(const FunctionCallbackInfo<Value>& args) { // Used in TextEncoder.prototype.encode. static void EncodeUtf8String(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); Local<String> str = args[0].As<String>(); size_t length = str->Utf8Length(); char* data = node::UncheckedMalloc(length); - str->WriteUtf8(data, - -1, // We are certain that `data` is sufficiently large + str->WriteUtf8(isolate, + data, + -1, // We are certain that `data` is sufficiently large nullptr, String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8); - auto array_buf = ArrayBuffer::New(env->isolate(), data, length, - ArrayBufferCreationMode::kInternalized); + auto array_buf = ArrayBuffer::New( + isolate, data, length, ArrayBufferCreationMode::kInternalized); auto array = Uint8Array::New(array_buf, 0, length); args.GetReturnValue().Set(array); } |