Browse Source

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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v7.x
Ben Noordhuis 9 years ago
parent
commit
a92089b6bd
  1. 2
      src/node.cc
  2. 4
      src/node.h
  3. 10
      src/string_bytes.cc
  4. 2
      test/addons/parse-encoding/binding.cc

2
src/node.cc

@ -1358,7 +1358,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")) {

4
src/node.h

@ -278,7 +278,9 @@ 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, 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<v8::Value> encoding_v,

10
src/string_bytes.cc

@ -272,7 +272,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 {
@ -377,8 +376,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);
}
@ -387,7 +385,6 @@ size_t StringBytes::StorageSize(Isolate* isolate,
switch (encoding) {
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;
@ -428,8 +425,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;
@ -441,7 +437,6 @@ size_t StringBytes::Size(Isolate* isolate,
switch (encoding) {
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;
@ -645,7 +640,6 @@ Local<Value> StringBytes::Encode(Isolate* isolate,
break;
case LATIN1:
case BINARY:
if (buflen < EXTERN_APEX)
val = OneByteString(isolate, buf, buflen);
else

2
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<v8::Value>& args) {
const node::encoding encoding =
node::ParseEncoding(args.GetIsolate(), args[0],

Loading…
Cancel
Save