summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2016-06-02 10:55:36 -0600
committerTrevor Norris <trev.norris@gmail.com>2016-06-07 13:51:14 -0600
commit54cc7212df320f1e489edf8dbeabb167a71cbe67 (patch)
tree19764d4f8f0d84373bb9de96844043fad342c9c0 /src
parentc300ba22128ce8e675650adcd1f6b869dc1b5126 (diff)
downloadandroid-node-v8-54cc7212df320f1e489edf8dbeabb167a71cbe67.tar.gz
android-node-v8-54cc7212df320f1e489edf8dbeabb167a71cbe67.tar.bz2
android-node-v8-54cc7212df320f1e489edf8dbeabb167a71cbe67.zip
buffer: introduce latin1 encoding term
When node began using the OneByte API (f150d56) it also switched to officially supporting ISO-8859-1. Though at the time no new encoding string was introduced. Introduce the new encoding string 'latin1' to be more explicit. The previous 'binary' and documented as an alias to 'latin1'. While many tests have switched to use 'latin1', there are still plenty that do both 'binary' and 'latin1' checks side-by-side to ensure there is no regression. PR-URL: https://github.com/nodejs/node/pull/7111 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node.cc12
-rw-r--r--src/node.h18
-rw-r--r--src/node_buffer.cc14
-rw-r--r--src/stream_base-inl.h4
-rw-r--r--src/stream_base.cc2
-rw-r--r--src/string_bytes.cc14
6 files changed, 39 insertions, 25 deletions
diff --git a/src/node.cc b/src/node.cc
index a6f5325cb6..da514787a3 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1312,11 +1312,17 @@ enum encoding ParseEncoding(const char* encoding,
return UCS2;
}
break;
+ case 'l':
+ // latin1
+ if (encoding[1] == 'a') {
+ if (strncmp(encoding + 2, "tin1", 4) == 0)
+ return LATIN1;
+ }
case 'b':
// binary
if (encoding[1] == 'i') {
if (strncmp(encoding + 2, "nary", 4) == 0)
- return BINARY;
+ return LATIN1;
// buffer
} else if (encoding[1] == 'u') {
@@ -1346,6 +1352,8 @@ enum encoding ParseEncoding(const char* encoding,
return UCS2;
} else if (StringEqualNoCase(encoding, "utf-16le")) {
return UCS2;
+ } else if (StringEqualNoCase(encoding, "latin1")) {
+ return LATIN1;
} else if (StringEqualNoCase(encoding, "binary")) {
return BINARY;
} else if (StringEqualNoCase(encoding, "buffer")) {
@@ -1389,7 +1397,7 @@ ssize_t DecodeBytes(Isolate* isolate,
if (val->IsArray()) {
fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
- "Use 'binary'.\n");
+ "Use 'latin1'.\n");
UNREACHABLE();
return -1;
}
diff --git a/src/node.h b/src/node.h
index c1c149cdc3..d813b45a0c 100644
--- a/src/node.h
+++ b/src/node.h
@@ -278,15 +278,15 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv,
}
#define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD
-enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER};
+enum encoding {ASCII, UTF8, BASE64, UCS2, LATIN1, BINARY, HEX, BUFFER};
NODE_EXTERN enum encoding ParseEncoding(
v8::Isolate* isolate,
v8::Local<v8::Value> encoding_v,
- enum encoding default_encoding = BINARY);
+ enum encoding default_encoding = LATIN1);
NODE_DEPRECATED("Use ParseEncoding(isolate, ...)",
inline enum encoding ParseEncoding(
v8::Local<v8::Value> encoding_v,
- enum encoding default_encoding = BINARY) {
+ enum encoding default_encoding = LATIN1) {
return ParseEncoding(v8::Isolate::GetCurrent(), encoding_v, default_encoding);
})
@@ -302,7 +302,7 @@ NODE_DEPRECATED("Use FatalException(isolate, ...)",
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
const char* buf,
size_t len,
- enum encoding encoding = BINARY);
+ enum encoding encoding = LATIN1);
// The input buffer should be in host endianness.
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
@@ -313,7 +313,7 @@ NODE_DEPRECATED("Use Encode(isolate, ...)",
inline v8::Local<v8::Value> Encode(
const void* buf,
size_t len,
- enum encoding encoding = BINARY) {
+ enum encoding encoding = LATIN1) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (encoding == UCS2) {
assert(reinterpret_cast<uintptr_t>(buf) % sizeof(uint16_t) == 0 &&
@@ -327,11 +327,11 @@ NODE_DEPRECATED("Use Encode(isolate, ...)",
// Returns -1 if the handle was not valid for decoding
NODE_EXTERN ssize_t DecodeBytes(v8::Isolate* isolate,
v8::Local<v8::Value>,
- enum encoding encoding = BINARY);
+ enum encoding encoding = LATIN1);
NODE_DEPRECATED("Use DecodeBytes(isolate, ...)",
inline ssize_t DecodeBytes(
v8::Local<v8::Value> val,
- enum encoding encoding = BINARY) {
+ enum encoding encoding = LATIN1) {
return DecodeBytes(v8::Isolate::GetCurrent(), val, encoding);
})
@@ -340,12 +340,12 @@ NODE_EXTERN ssize_t DecodeWrite(v8::Isolate* isolate,
char* buf,
size_t buflen,
v8::Local<v8::Value>,
- enum encoding encoding = BINARY);
+ enum encoding encoding = LATIN1);
NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
inline ssize_t DecodeWrite(char* buf,
size_t buflen,
v8::Local<v8::Value> val,
- enum encoding encoding = BINARY) {
+ enum encoding encoding = LATIN1) {
return DecodeWrite(v8::Isolate::GetCurrent(), buf, buflen, val, encoding);
})
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 388decac4a..2472c0bb82 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -491,8 +491,8 @@ void StringSlice<UCS2>(const FunctionCallbackInfo<Value>& args) {
}
-void BinarySlice(const FunctionCallbackInfo<Value>& args) {
- StringSlice<BINARY>(args);
+void Latin1Slice(const FunctionCallbackInfo<Value>& args) {
+ StringSlice<LATIN1>(args);
}
@@ -692,8 +692,8 @@ void Base64Write(const FunctionCallbackInfo<Value>& args) {
}
-void BinaryWrite(const FunctionCallbackInfo<Value>& args) {
- StringWrite<BINARY>(args);
+void Latin1Write(const FunctionCallbackInfo<Value>& args) {
+ StringWrite<LATIN1>(args);
}
@@ -1035,7 +1035,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
needle_length,
offset,
is_forward);
- } else if (enc == BINARY) {
+ } else if (enc == LATIN1) {
uint8_t* needle_data = static_cast<uint8_t*>(malloc(needle_length));
if (needle_data == nullptr) {
return args.GetReturnValue().Set(-1);
@@ -1183,14 +1183,14 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
env->SetMethod(proto, "asciiSlice", AsciiSlice);
env->SetMethod(proto, "base64Slice", Base64Slice);
- env->SetMethod(proto, "binarySlice", BinarySlice);
+ env->SetMethod(proto, "latin1Slice", Latin1Slice);
env->SetMethod(proto, "hexSlice", HexSlice);
env->SetMethod(proto, "ucs2Slice", Ucs2Slice);
env->SetMethod(proto, "utf8Slice", Utf8Slice);
env->SetMethod(proto, "asciiWrite", AsciiWrite);
env->SetMethod(proto, "base64Write", Base64Write);
- env->SetMethod(proto, "binaryWrite", BinaryWrite);
+ env->SetMethod(proto, "latin1Write", Latin1Write);
env->SetMethod(proto, "hexWrite", HexWrite);
env->SetMethod(proto, "ucs2Write", Ucs2Write);
env->SetMethod(proto, "utf8Write", Utf8Write);
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index a34c01082d..da636909b6 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -71,8 +71,8 @@ void StreamBase::AddMethods(Environment* env,
"writeUcs2String",
JSMethod<Base, &StreamBase::WriteString<UCS2> >);
env->SetProtoMethod(t,
- "writeBinaryString",
- JSMethod<Base, &StreamBase::WriteString<BINARY> >);
+ "writeLatin1String",
+ JSMethod<Base, &StreamBase::WriteString<LATIN1> >);
}
diff --git a/src/stream_base.cc b/src/stream_base.cc
index 8db127dff6..105c4ad458 100644
--- a/src/stream_base.cc
+++ b/src/stream_base.cc
@@ -33,7 +33,7 @@ template int StreamBase::WriteString<UTF8>(
const FunctionCallbackInfo<Value>& args);
template int StreamBase::WriteString<UCS2>(
const FunctionCallbackInfo<Value>& args);
-template int StreamBase::WriteString<BINARY>(
+template int StreamBase::WriteString<LATIN1>(
const FunctionCallbackInfo<Value>& args);
diff --git a/src/string_bytes.cc b/src/string_bytes.cc
index 8a327deac2..6454e11323 100644
--- a/src/string_bytes.cc
+++ b/src/string_bytes.cc
@@ -271,6 +271,7 @@ size_t StringBytes::Write(Isolate* isolate,
switch (encoding) {
case ASCII:
+ case LATIN1:
case BINARY:
if (is_extern && str->IsOneByte()) {
memcpy(buf, data, nbytes);
@@ -376,15 +377,17 @@ size_t StringBytes::StorageSize(Isolate* isolate,
size_t data_size = 0;
bool is_buffer = Buffer::HasInstance(val);
- if (is_buffer && (encoding == BUFFER || encoding == BINARY)) {
+ if (is_buffer &&
+ (encoding == BUFFER || encoding == BINARY || encoding == LATIN1)) {
return Buffer::Length(val);
}
Local<String> str = val->ToString(isolate);
switch (encoding) {
- case BINARY:
case ASCII:
+ case LATIN1:
+ case BINARY:
data_size = str->Length();
break;
@@ -425,7 +428,8 @@ size_t StringBytes::Size(Isolate* isolate,
size_t data_size = 0;
bool is_buffer = Buffer::HasInstance(val);
- if (is_buffer && (encoding == BUFFER || encoding == BINARY))
+ if (is_buffer &&
+ (encoding == BUFFER || encoding == BINARY || encoding == LATIN1))
return Buffer::Length(val);
const char* data;
@@ -435,8 +439,9 @@ size_t StringBytes::Size(Isolate* isolate,
Local<String> str = val->ToString(isolate);
switch (encoding) {
- case BINARY:
case ASCII:
+ case LATIN1:
+ case BINARY:
data_size = str->Length();
break;
@@ -639,6 +644,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
buflen);
break;
+ case LATIN1:
case BINARY:
if (buflen < EXTERN_APEX)
val = OneByteString(isolate, buf, buflen);