Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: alias BINARY to LATIN1 #7284

Merged
merged 1 commit into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
4 changes: 3 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand All @@ -387,7 +385,6 @@ size_t StringBytes::StorageSize(Isolate* isolate,
switch (encoding) {
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;

Expand Down Expand Up @@ -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;
Expand All @@ -441,7 +437,6 @@ size_t StringBytes::Size(Isolate* isolate,
switch (encoding) {
case ASCII:
case LATIN1:
case BINARY:
data_size = str->Length();
break;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/addons/parse-encoding/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down