diff --git a/src/node_file.cc b/src/node_file.cc index 7a3be9db541a16..c0343fbf00200d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1099,8 +1099,7 @@ static void WriteString(const FunctionCallbackInfo& args) { FSReqWrap::Ownership ownership = FSReqWrap::COPY; // will assign buf and len if string was external - if (!StringBytes::GetExternalParts(env->isolate(), - string, + if (!StringBytes::GetExternalParts(string, const_cast(&buf), &len)) { enum encoding enc = ParseEncoding(env->isolate(), args[3], UTF8); diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 636d7da25d3291..cbf30afc7af5dd 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -270,8 +270,7 @@ static size_t hex_decode(char* buf, } -bool StringBytes::GetExternalParts(Isolate* isolate, - Local val, +bool StringBytes::GetExternalParts(Local val, const char** data, size_t* len) { if (Buffer::HasInstance(val)) { @@ -306,8 +305,6 @@ bool StringBytes::GetExternalParts(Isolate* isolate, size_t StringBytes::WriteUCS2(char* buf, size_t buflen, - size_t nbytes, - const char* data, Local str, int flags, size_t* chars_written) { @@ -353,7 +350,7 @@ size_t StringBytes::Write(Isolate* isolate, HandleScope scope(isolate); const char* data = nullptr; size_t nbytes = 0; - const bool is_extern = GetExternalParts(isolate, val, &data, &nbytes); + const bool is_extern = GetExternalParts(val, &data, &nbytes); const size_t external_nbytes = nbytes; CHECK(val->IsString() == true); @@ -391,7 +388,7 @@ size_t StringBytes::Write(Isolate* isolate, memcpy(buf, data, nbytes); nchars = nbytes / sizeof(uint16_t); } else { - nbytes = WriteUCS2(buf, buflen, nbytes, data, str, flags, &nchars); + nbytes = WriteUCS2(buf, buflen, str, flags, &nchars); } if (chars_written != nullptr) *chars_written = nchars; @@ -439,8 +436,7 @@ size_t StringBytes::Write(Isolate* isolate, } -bool StringBytes::IsValidString(Isolate* isolate, - Local string, +bool StringBytes::IsValidString(Local string, enum encoding enc) { if (enc == HEX && string->Length() % 2 != 0) return false; @@ -512,7 +508,7 @@ size_t StringBytes::Size(Isolate* isolate, return Buffer::Length(val); const char* data; - if (GetExternalParts(isolate, val, &data, &data_size)) + if (GetExternalParts(val, &data, &data_size)) return data_size; Local str = val->ToString(isolate); diff --git a/src/string_bytes.h b/src/string_bytes.h index e11c16d65f2afb..e46fa8227b7236 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -43,7 +43,7 @@ class StringBytes { v8::Local encoding, enum encoding _default) { enum encoding enc = ParseEncoding(env->isolate(), encoding, _default); - if (!StringBytes::IsValidString(env->isolate(), string, enc)) { + if (!StringBytes::IsValidString(string, enc)) { env->ThrowTypeError("Bad input string"); return false; } @@ -69,8 +69,7 @@ class StringBytes { // Does the string match the encoding? Quick but non-exhaustive. // Example: a HEX string must have a length that's a multiple of two. // FIXME(bnoordhuis) IsMaybeValidString()? Naming things is hard... - static bool IsValidString(v8::Isolate* isolate, - v8::Local string, + static bool IsValidString(v8::Local string, enum encoding enc); // Fast, but can be 2 bytes oversized for Base64, and @@ -87,8 +86,7 @@ class StringBytes { // If the string is external then assign external properties to data and len, // then return true. If not return false. - static bool GetExternalParts(v8::Isolate* isolate, - v8::Local val, + static bool GetExternalParts(v8::Local val, const char** data, size_t* len); @@ -125,8 +123,6 @@ class StringBytes { private: static size_t WriteUCS2(char* buf, size_t buflen, - size_t nbytes, - const char* data, v8::Local str, int flags, size_t* chars_written);