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

Minor fixups #1148

Merged
merged 2 commits into from
Mar 16, 2015
Merged
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
37 changes: 19 additions & 18 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What alternative is there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-byte strings or if you want more radical, buffers or typed arrays. It also depends on the platform: file paths are untyped binary blobs on most Unices, but on OS X (i.e. HFS+) and Windows, they're Unicode.

I'm not sure yet what the right answer is, just that our current approach is wrong. :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about different data formats. I was only thinking about string encoding.

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 Expand Up @@ -1931,10 +1932,10 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
HeapStatistics v8_heap_stats;
env->isolate()->GetHeapStatistics(&v8_heap_stats);

Local<Integer> heap_total =
Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.total_heap_size());
Local<Integer> heap_used =
Integer::NewFromUnsigned(env->isolate(), v8_heap_stats.used_heap_size());
Local<Number> heap_total =
Number::New(env->isolate(), v8_heap_stats.total_heap_size());
Local<Number> heap_used =
Number::New(env->isolate(), v8_heap_stats.used_heap_size());

Local<Object> info = Object::New(env->isolate());
info->Set(env->rss_string(), Number::New(env->isolate(), rss));
Expand Down