Skip to content

Commit

Permalink
src: don't create js string twice on error
Browse files Browse the repository at this point in the history
Rewrite ErrnoException() so that it doesn't turn the file path into a
string twice.

PR-URL: #1148
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Mar 16, 2015
1 parent eb995d6 commit 4f39499
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,28 +724,29 @@ Local<Value> ErrnoException(Isolate* isolate,
}
Local<String> message = OneByteString(env->isolate(), msg);

Local<String> cons1 =
Local<String> cons =
String::Concat(estring, FIXED_ONE_BYTE_STRING(env->isolate(), ", "));
Local<String> cons2 = String::Concat(cons1, message);
cons = String::Concat(cons, message);

if (path) {
Local<String> cons3 =
String::Concat(cons2, FIXED_ONE_BYTE_STRING(env->isolate(), " '"));
Local<String> cons4 =
String::Concat(cons3, String::NewFromUtf8(env->isolate(), path));
Local<String> cons5 =
String::Concat(cons4, FIXED_ONE_BYTE_STRING(env->isolate(), "'"));
e = Exception::Error(cons5);
} else {
e = Exception::Error(cons2);
Local<String> path_string;
if (path != nullptr) {
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
path_string = String::NewFromUtf8(env->isolate(), path);
}

if (path_string.IsEmpty() == false) {
cons = String::Concat(cons, FIXED_ONE_BYTE_STRING(env->isolate(), " '"));
cons = String::Concat(cons, path_string);
cons = String::Concat(cons, FIXED_ONE_BYTE_STRING(env->isolate(), "'"));
}
e = Exception::Error(cons);

Local<Object> obj = e->ToObject(env->isolate());
obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno));
obj->Set(env->code_string(), estring);

if (path != nullptr) {
obj->Set(env->path_string(), String::NewFromUtf8(env->isolate(), path));
if (path_string.IsEmpty() == false) {
obj->Set(env->path_string(), path_string);
}

if (syscall != nullptr) {
Expand Down

0 comments on commit 4f39499

Please sign in to comment.