| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d50e1ff commit 8375f75
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ void CallWithString(const FunctionCallbackInfo<Value>& args) { | |||
| 21 | 21 | Local<String> str = args[0].As<String>(); | |
| 22 | 22 | const int32_t length = str->Utf8Length() + 1; | |
| 23 | 23 | char* buf = new char[length]; | |
| 24 | - str->WriteUtf8(buf, length); | ||
| 24 | + str->WriteUtf8(args.GetIsolate(), buf, length); | ||
| 25 | 25 | delete [] buf; | |
| 26 | 26 | } | |
| 27 | 27 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2362,9 +2362,12 @@ napi_status napi_get_value_string_latin1(napi_env env, | |||
| 2362 | 2362 | CHECK_ARG(env, result); | |
| 2363 | 2363 | *result = val.As<v8::String>()->Length(); | |
| 2364 | 2364 | } else { | |
| 2365 | - int copied = val.As<v8::String>()->WriteOneByte( | ||
| 2366 | - reinterpret_cast<uint8_t*>(buf), 0, bufsize - 1, | ||
| 2367 | - v8::String::NO_NULL_TERMINATION); | ||
| 2365 | + int copied = | ||
| 2366 | + val.As<v8::String>()->WriteOneByte(env->isolate, | ||
| 2367 | + reinterpret_cast<uint8_t*>(buf), | ||
| 2368 | + 0, | ||
| 2369 | + bufsize - 1, | ||
| 2370 | + v8::String::NO_NULL_TERMINATION); | ||
| 2368 | 2371 | ||
| 2369 | 2372 | buf[copied] = '\0'; | |
| 2370 | 2373 | if (result != nullptr) { | |
@@ -2399,8 +2402,11 @@ napi_status napi_get_value_string_utf8(napi_env env, | |||
| 2399 | 2402 | *result = val.As<v8::String>()->Utf8Length(); | |
| 2400 | 2403 | } else { | |
| 2401 | 2404 | int copied = val.As<v8::String>()->WriteUtf8( | |
| 2402 | - buf, bufsize - 1, nullptr, v8::String::REPLACE_INVALID_UTF8 | | ||
| 2403 | - v8::String::NO_NULL_TERMINATION); | ||
| 2405 | + env->isolate, | ||
| 2406 | + buf, | ||
| 2407 | + bufsize - 1, | ||
| 2408 | + nullptr, | ||
| 2409 | + v8::String::REPLACE_INVALID_UTF8 | v8::String::NO_NULL_TERMINATION); | ||
| 2404 | 2410 | ||
| 2405 | 2411 | buf[copied] = '\0'; | |
| 2406 | 2412 | if (result != nullptr) { | |
@@ -2435,9 +2441,11 @@ napi_status napi_get_value_string_utf16(napi_env env, | |||
| 2435 | 2441 | // V8 assumes UTF-16 length is the same as the number of characters. | |
| 2436 | 2442 | *result = val.As<v8::String>()->Length(); | |
| 2437 | 2443 | } else { | |
| 2438 | - int copied = val.As<v8::String>()->Write( | ||
| 2439 | - reinterpret_cast<uint16_t*>(buf), 0, bufsize - 1, | ||
| 2440 | - v8::String::NO_NULL_TERMINATION); | ||
| 2444 | + int copied = val.As<v8::String>()->Write(env->isolate, | ||
| 2445 | + reinterpret_cast<uint16_t*>(buf), | ||
| 2446 | + 0, | ||
| 2447 | + bufsize - 1, | ||
| 2448 | + v8::String::NO_NULL_TERMINATION); | ||
| 2441 | 2449 | ||
| 2442 | 2450 | buf[copied] = '\0'; | |
| 2443 | 2451 | if (result != nullptr) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -806,15 +806,16 @@ int64_t IndexOfOffset(size_t length, | |||
| 806 | 806 | } | |
| 807 | 807 | ||
| 808 | 808 | void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |
| 809 | + Environment* env = Environment::GetCurrent(args); | ||
| 810 | + Isolate* isolate = env->isolate(); | ||
| 811 | + | ||
| 809 | 812 | CHECK(args[1]->IsString()); | |
| 810 | 813 | CHECK(args[2]->IsNumber()); | |
| 811 | 814 | CHECK(args[4]->IsBoolean()); | |
| 812 | 815 | ||
| 813 | - enum encoding enc = ParseEncoding(args.GetIsolate(), | ||
| 814 | - args[3], | ||
| 815 | - UTF8); | ||
| 816 | + enum encoding enc = ParseEncoding(isolate, args[3], UTF8); | ||
| 816 | 817 | ||
| 817 | - THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); | ||
| 818 | + THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); | ||
| 818 | 819 | SPREAD_BUFFER_ARG(args[0], ts_obj); | |
| 819 | 820 | ||
| 820 | 821 | Local<String> needle = args[1].As<String>(); | |
@@ -826,8 +827,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 826 | 827 | const size_t haystack_length = (enc == UCS2) ? | |
| 827 | 828 | ts_obj_length &~ 1 : ts_obj_length; // NOLINT(whitespace/operators) | |
| 828 | 829 | ||
| 829 | - const size_t needle_length = | ||
| 830 | - StringBytes::Size(args.GetIsolate(), needle, enc); | ||
| 830 | + const size_t needle_length = StringBytes::Size(isolate, needle, enc); | ||
| 831 | 831 | ||
| 832 | 832 | int64_t opt_offset = IndexOfOffset(haystack_length, | |
| 833 | 833 | offset_i64, | |
@@ -857,7 +857,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 857 | 857 | size_t result = haystack_length; | |
| 858 | 858 | ||
| 859 | 859 | if (enc == UCS2) { | |
| 860 | - String::Value needle_value(args.GetIsolate(), needle); | ||
| 860 | + String::Value needle_value(isolate, needle); | ||
| 861 | 861 | if (*needle_value == nullptr) | |
| 862 | 862 | return args.GetReturnValue().Set(-1); | |
| 863 | 863 | ||
@@ -867,7 +867,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 867 | 867 | ||
| 868 | 868 | if (IsBigEndian()) { | |
| 869 | 869 | StringBytes::InlineDecoder decoder; | |
| 870 | - decoder.Decode(Environment::GetCurrent(args), needle, args[3], UCS2); | ||
| 870 | + decoder.Decode(env, needle, args[3], UCS2); | ||
| 871 | 871 | const uint16_t* decoded_string = | |
| 872 | 872 | reinterpret_cast<const uint16_t*>(decoder.out()); | |
| 873 | 873 | ||
@@ -890,7 +890,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 890 | 890 | } | |
| 891 | 891 | result *= 2; | |
| 892 | 892 | } else if (enc == UTF8) { | |
| 893 | - String::Utf8Value needle_value(args.GetIsolate(), needle); | ||
| 893 | + String::Utf8Value needle_value(isolate, needle); | ||
| 894 | 894 | if (*needle_value == nullptr) | |
| 895 | 895 | return args.GetReturnValue().Set(-1); | |
| 896 | 896 | ||
@@ -906,7 +906,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 906 | 906 | return args.GetReturnValue().Set(-1); | |
| 907 | 907 | } | |
| 908 | 908 | needle->WriteOneByte( | |
| 909 | - needle_data, 0, needle_length, String::NO_NULL_TERMINATION); | ||
| 909 | + isolate, needle_data, 0, needle_length, String::NO_NULL_TERMINATION); | ||
| 910 | 910 | ||
| 911 | 911 | result = SearchString(reinterpret_cast<const uint8_t*>(haystack), | |
| 912 | 912 | haystack_length, | |
@@ -1057,18 +1057,20 @@ void Swap64(const FunctionCallbackInfo<Value>& args) { | |||
| 1057 | 1057 | // Used in TextEncoder.prototype.encode. | |
| 1058 | 1058 | static void EncodeUtf8String(const FunctionCallbackInfo<Value>& args) { | |
| 1059 | 1059 | Environment* env = Environment::GetCurrent(args); | |
| 1060 | + Isolate* isolate = env->isolate(); | ||
| 1060 | 1061 | CHECK_GE(args.Length(), 1); | |
| 1061 | 1062 | CHECK(args[0]->IsString()); | |
| 1062 | 1063 | ||
| 1063 | 1064 | Local<String> str = args[0].As<String>(); | |
| 1064 | 1065 | size_t length = str->Utf8Length(); | |
| 1065 | 1066 | char* data = node::UncheckedMalloc(length); | |
| 1066 | - str->WriteUtf8(data, | ||
| 1067 | - -1, // We are certain that `data` is sufficiently large | ||
| 1067 | + str->WriteUtf8(isolate, | ||
| 1068 | + data, | ||
| 1069 | + -1, // We are certain that `data` is sufficiently large | ||
| 1068 | 1070 | nullptr, | |
| 1069 | 1071 | String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8); | |
| 1070 | - auto array_buf = ArrayBuffer::New(env->isolate(), data, length, | ||
| 1071 | - ArrayBufferCreationMode::kInternalized); | ||
| 1072 | + auto array_buf = ArrayBuffer::New( | ||
| 1073 | + isolate, data, length, ArrayBufferCreationMode::kInternalized); | ||
| 1072 | 1074 | auto array = Uint8Array::New(array_buf, 0, length); | |
| 1073 | 1075 | args.GetReturnValue().Set(array); | |
| 1074 | 1076 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -381,10 +381,12 @@ Headers::Headers(Isolate* isolate, | |||
| 381 | 381 | nghttp2_nv* const nva = reinterpret_cast<nghttp2_nv*>(start); | |
| 382 | 382 | ||
| 383 | 383 | CHECK_LE(header_contents + header_string_len, *buf_ + buf_.length()); | |
| 384 | - CHECK_EQ(header_string.As<String>() | ||
| 385 | - ->WriteOneByte(reinterpret_cast<uint8_t*>(header_contents), | ||
| 386 | - 0, header_string_len, | ||
| 387 | - String::NO_NULL_TERMINATION), | ||
| 384 | + CHECK_EQ(header_string.As<String>()->WriteOneByte( | ||
| 385 | + isolate, | ||
| 386 | + reinterpret_cast<uint8_t*>(header_contents), | ||
| 387 | + 0, | ||
| 388 | + header_string_len, | ||
| 389 | + String::NO_NULL_TERMINATION), | ||
| 388 | 390 | header_string_len); | |
| 389 | 391 | ||
| 390 | 392 | size_t n = 0; | |
@@ -2633,8 +2635,8 @@ void Http2Session::AltSvc(const FunctionCallbackInfo<Value>& args) { | |||
| 2633 | 2635 | ||
| 2634 | 2636 | MaybeStackBuffer<uint8_t> origin(origin_len); | |
| 2635 | 2637 | MaybeStackBuffer<uint8_t> value(value_len); | |
| 2636 | - origin_str->WriteOneByte(*origin); | ||
| 2637 | - value_str->WriteOneByte(*value); | ||
| 2638 | + origin_str->WriteOneByte(env->isolate(), *origin); | ||
| 2639 | + value_str->WriteOneByte(env->isolate(), *value); | ||
| 2638 | 2640 | ||
| 2639 | 2641 | session->AltSvc(id, *origin, origin_len, *value, value_len); | |
| 2640 | 2642 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,8 +257,8 @@ static size_t hex_decode(char* buf, | |||
| 257 | 257 | return i; | |
| 258 | 258 | } | |
| 259 | 259 | ||
| 260 | - | ||
| 261 | - size_t StringBytes::WriteUCS2(char* buf, | ||
| 260 | + size_t StringBytes::WriteUCS2(Isolate* isolate, | ||
| 261 | + char* buf, | ||
| 262 | 262 | size_t buflen, | |
| 263 | 263 | Local<String> str, | |
| 264 | 264 | int flags, | |
@@ -273,7 +273,7 @@ size_t StringBytes::WriteUCS2(char* buf, | |||
| 273 | 273 | size_t nchars; | |
| 274 | 274 | size_t alignment = reinterpret_cast<uintptr_t>(dst) % sizeof(*dst); | |
| 275 | 275 | if (alignment == 0) { | |
| 276 | - nchars = str->Write(dst, 0, max_chars, flags); | ||
| 276 | + nchars = str->Write(isolate, dst, 0, max_chars, flags); | ||
| 277 | 277 | *chars_written = nchars; | |
| 278 | 278 | return nchars * sizeof(*dst); | |
| 279 | 279 | } | |
@@ -283,14 +283,15 @@ size_t StringBytes::WriteUCS2(char* buf, | |||
| 283 | 283 | CHECK_EQ(reinterpret_cast<uintptr_t>(aligned_dst) % sizeof(*dst), 0); | |
| 284 | 284 | ||
| 285 | 285 | // Write all but the last char | |
| 286 | - nchars = str->Write(aligned_dst, 0, max_chars - 1, flags); | ||
| 286 | + nchars = str->Write(isolate, aligned_dst, 0, max_chars - 1, flags); | ||
| 287 | 287 | ||
| 288 | 288 | // Shift everything to unaligned-left | |
| 289 | 289 | memmove(dst, aligned_dst, nchars * sizeof(*dst)); | |
| 290 | 290 | ||
| 291 | 291 | // One more char to be written | |
| 292 | 292 | uint16_t last; | |
| 293 | - if (nchars == max_chars - 1 && str->Write(&last, nchars, 1, flags) != 0) { | ||
| 293 | + if (nchars == max_chars - 1 && | ||
| 294 | + str->Write(isolate, &last, nchars, 1, flags) != 0) { | ||
| 294 | 295 | memcpy(buf + nchars * sizeof(*dst), &last, sizeof(last)); | |
| 295 | 296 | nchars++; | |
| 296 | 297 | } | |
@@ -329,20 +330,20 @@ size_t StringBytes::Write(Isolate* isolate, | |||
| 329 | 330 | memcpy(buf, ext->data(), nbytes); | |
| 330 | 331 | } else { | |
| 331 | 332 | uint8_t* const dst = reinterpret_cast<uint8_t*>(buf); | |
| 332 | - nbytes = str->WriteOneByte(dst, 0, buflen, flags); | ||
| 333 | + nbytes = str->WriteOneByte(isolate, dst, 0, buflen, flags); | ||
| 333 | 334 | } | |
| 334 | 335 | *chars_written = nbytes; | |
| 335 | 336 | break; | |
| 336 | 337 | ||
| 337 | 338 | case BUFFER: | |
| 338 | 339 | case UTF8: | |
| 339 | - nbytes = str->WriteUtf8(buf, buflen, chars_written, flags); | ||
| 340 | + nbytes = str->WriteUtf8(isolate, buf, buflen, chars_written, flags); | ||
| 340 | 341 | break; | |
| 341 | 342 | ||
| 342 | 343 | case UCS2: { | |
| 343 | 344 | size_t nchars; | |
| 344 | 345 | ||
| 345 | - nbytes = WriteUCS2(buf, buflen, str, flags, &nchars); | ||
| 346 | + nbytes = WriteUCS2(isolate, buf, buflen, str, flags, &nchars); | ||
| 346 | 347 | *chars_written = static_cast<int>(nchars); | |
| 347 | 348 | ||
| 348 | 349 | // Node's "ucs2" encoding wants LE character data stored in | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,7 +112,8 @@ class StringBytes { | |||
| 112 | 112 | v8::Local<v8::Value>* error); | |
| 113 | 113 | ||
| 114 | 114 | private: | |
| 115 | - static size_t WriteUCS2(char* buf, | ||
| 115 | + static size_t WriteUCS2(v8::Isolate* isolate, | ||
| 116 | + char* buf, | ||
| 116 | 117 | size_t buflen, | |
| 117 | 118 | v8::Local<v8::String> str, | |
| 118 | 119 | int flags, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,8 @@ static void MakeUtf8String(Isolate* isolate, | |||
| 45 | 45 | target->AllocateSufficientStorage(storage); | |
| 46 | 46 | const int flags = | |
| 47 | 47 | String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8; | |
| 48 | - const int length = string->WriteUtf8(target->out(), storage, 0, flags); | ||
| 48 | + const int length = | ||
| 49 | + string->WriteUtf8(isolate, target->out(), storage, 0, flags); | ||
| 49 | 50 | target->SetLengthAndZeroTerminate(length); | |
| 50 | 51 | } | |
| 51 | 52 | ||
@@ -71,7 +72,7 @@ TwoByteValue::TwoByteValue(Isolate* isolate, Local<Value> value) { | |||
| 71 | 72 | AllocateSufficientStorage(storage); | |
| 72 | 73 | ||
| 73 | 74 | const int flags = String::NO_NULL_TERMINATION; | |
| 74 | - const int length = string->Write(out(), 0, storage, flags); | ||
| 75 | + const int length = string->Write(isolate, out(), 0, storage, flags); | ||
| 75 | 76 | SetLengthAndZeroTerminate(length); | |
| 76 | 77 | } | |
| 77 | 78 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments