From da9bd2fc48e1e0d65b62765d9750b43669f0ca20 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 13 Jun 2016 11:37:39 +0200 Subject: [PATCH] src: alias BINARY to LATIN1 Make BINARY an alias for LATIN1 rather than a distinct enum value. PR-URL: https://github.com/nodejs/node/pull/7284 Refs: https://github.com/nodejs/node/pull/7262 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Sakthipriyan Vairamani --- src/node.cc | 2 +- src/node.h | 4 +++- src/string_bytes.cc | 10 ++-------- test/addons/parse-encoding/binding.cc | 2 ++ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index f9bbc24eac..64bbfaac48 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1454,7 +1454,7 @@ enum encoding ParseEncoding(const char* encoding, } else if (StringEqualNoCase(encoding, "latin1")) { return LATIN1; } else if (StringEqualNoCase(encoding, "binary")) { - return BINARY; + return LATIN1; // BINARY is a deprecated alias of LATIN1. } else if (StringEqualNoCase(encoding, "buffer")) { return BUFFER; } else if (StringEqualNoCase(encoding, "hex")) { diff --git a/src/node.h b/src/node.h index 4a1eac0644..c744c3e1d2 100644 --- a/src/node.h +++ b/src/node.h @@ -284,7 +284,9 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local recv, } #define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD -enum encoding {ASCII, UTF8, BASE64, UCS2, LATIN1, BINARY, HEX, BUFFER}; +// BINARY is a deprecated alias of LATIN1. +enum encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER, LATIN1 = BINARY}; + NODE_EXTERN enum encoding ParseEncoding( v8::Isolate* isolate, v8::Local encoding_v, diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 11b072adc2..668a3b1efe 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -283,7 +283,6 @@ size_t StringBytes::Write(Isolate* isolate, switch (encoding) { case ASCII: case LATIN1: - case BINARY: if (is_extern && str->IsOneByte()) { memcpy(buf, data, nbytes); } else { @@ -388,8 +387,7 @@ size_t StringBytes::StorageSize(Isolate* isolate, size_t data_size = 0; bool is_buffer = Buffer::HasInstance(val); - if (is_buffer && - (encoding == BUFFER || encoding == BINARY || encoding == LATIN1)) { + if (is_buffer && (encoding == BUFFER || encoding == LATIN1)) { return Buffer::Length(val); } @@ -398,7 +396,6 @@ size_t StringBytes::StorageSize(Isolate* isolate, switch (encoding) { case ASCII: case LATIN1: - case BINARY: data_size = str->Length(); break; @@ -439,8 +436,7 @@ size_t StringBytes::Size(Isolate* isolate, size_t data_size = 0; bool is_buffer = Buffer::HasInstance(val); - if (is_buffer && - (encoding == BUFFER || encoding == BINARY || encoding == LATIN1)) + if (is_buffer && (encoding == BUFFER || encoding == LATIN1)) return Buffer::Length(val); const char* data; @@ -452,7 +448,6 @@ size_t StringBytes::Size(Isolate* isolate, switch (encoding) { case ASCII: case LATIN1: - case BINARY: data_size = str->Length(); break; @@ -656,7 +651,6 @@ Local StringBytes::Encode(Isolate* isolate, break; case LATIN1: - case BINARY: if (buflen < EXTERN_APEX) val = OneByteString(isolate, buf, buflen); else diff --git a/test/addons/parse-encoding/binding.cc b/test/addons/parse-encoding/binding.cc index def91901f0..062e9cb275 100644 --- a/test/addons/parse-encoding/binding.cc +++ b/test/addons/parse-encoding/binding.cc @@ -12,6 +12,8 @@ namespace { V(UCS2) \ V(UTF8) \ +static_assert(node::BINARY == node::LATIN1, "BINARY == LATIN1"); + void ParseEncoding(const v8::FunctionCallbackInfo& args) { const node::encoding encoding = node::ParseEncoding(args.GetIsolate(), args[0],