Browse Source

src: use v8::String::NewFrom*() functions

* Change calls to String::New() and String::NewSymbol() to their
  respective one-byte, two-byte and UTF-8 counterparts.

* Add a FIXED_ONE_BYTE_STRING macro that takes a string literal and
  turns it into a v8::Local<v8::String>.

* Add helper functions that make v8::String::NewFromOneByte() easier to
  work with. Said function expects a `const uint8_t*` but almost every
  call site deals with `const char*` or `const unsigned char*`. Helps
  us avoid doing reinterpret_casts all over the place.

* Code that handles file system paths keeps using UTF-8 for backwards
  compatibility reasons. At least now the use of UTF-8 is explicit.

* Remove v8::String::NewSymbol() entirely. Almost all call sites were
  effectively minor de-optimizations. If you create a string only once,
  there is no point in making it a symbol. If you are create the same
  string repeatedly, it should probably be cached in a persistent
  handle.
v0.11.6-release
Ben Noordhuis 12 years ago
parent
commit
f674b09f40
  1. 77
      src/cares_wrap.cc
  2. 12
      src/fs_event_wrap.cc
  3. 4
      src/handle_wrap.cc
  4. 333
      src/node.cc
  5. 27
      src/node.h
  6. 11
      src/node_buffer.cc
  7. 2
      src/node_counters.cc
  8. 225
      src/node_crypto.cc
  9. 12
      src/node_dtrace.cc
  10. 44
      src/node_file.cc
  11. 66
      src/node_http_parser.cc
  12. 47
      src/node_internals.h
  13. 10
      src/node_javascript.cc
  14. 47
      src/node_os.cc
  15. 25
      src/node_script.cc
  16. 9
      src/node_stat_watcher.cc
  17. 13
      src/node_zlib.cc
  18. 10
      src/pipe_wrap.cc
  19. 71
      src/process_wrap.cc
  20. 7
      src/signal_wrap.cc
  21. 4
      src/smalloc.cc
  22. 12
      src/stream_wrap.cc
  23. 25
      src/string_bytes.cc
  24. 24
      src/tcp_wrap.cc
  25. 7
      src/timer_wrap.cc
  26. 110
      src/tls_wrap.cc
  27. 8
      src/tty_wrap.cc
  28. 12
      src/udp_wrap.cc
  29. 9
      src/uv.cc

77
src/cares_wrap.cc

@ -206,7 +206,7 @@ static Local<Array> HostentToAddresses(struct hostent* host) {
for (int i = 0; host->h_addr_list[i]; ++i) {
uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip));
Local<String> address = String::New(ip);
Local<String> address = OneByteString(node_isolate, ip);
addresses->Set(Integer::New(i, node_isolate), address);
}
@ -219,7 +219,7 @@ static Local<Array> HostentToNames(struct hostent* host) {
Local<Array> names = Array::New();
for (int i = 0; host->h_aliases[i]; ++i) {
Local<String> address = String::New(host->h_aliases[i]);
Local<String> address = OneByteString(node_isolate, host->h_aliases[i]);
names->Set(Integer::New(i, node_isolate), address);
}
@ -426,7 +426,7 @@ class QueryCnameWrap: public QueryWrap {
// A cname lookup always returns a single record but we follow the
// common API here.
Local<Array> result = Array::New(1);
result->Set(0, String::New(host->h_name));
result->Set(0, OneByteString(node_isolate, host->h_name));
ares_free_hostent(host);
this->CallOnComplete(result);
@ -456,14 +456,18 @@ class QueryMxWrap: public QueryWrap {
}
Local<Array> mx_records = Array::New();
Local<String> exchange_symbol = String::NewSymbol("exchange");
Local<String> priority_symbol = String::NewSymbol("priority");
Local<String> exchange_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "exchange");
Local<String> priority_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "priority");
int i = 0;
for (struct ares_mx_reply* mx_current = mx_start;
mx_current;
mx_current = mx_current->next) {
Local<Object> mx_record = Object::New();
mx_record->Set(exchange_symbol, String::New(mx_current->host));
mx_record->Set(exchange_symbol,
OneByteString(node_isolate, mx_current->host));
mx_record->Set(priority_symbol,
Integer::New(mx_current->priority, node_isolate));
mx_records->Set(Integer::New(i++, node_isolate), mx_record);
@ -528,7 +532,7 @@ class QueryTxtWrap: public QueryWrap {
struct ares_txt_reply *current = txt_out;
for (int i = 0; current; ++i, current = current->next) {
Local<String> txt = String::New(reinterpret_cast<char*>(current->txt));
Local<String> txt = OneByteString(node_isolate, current->txt);
txt_records->Set(Integer::New(i, node_isolate), txt);
}
@ -566,16 +570,22 @@ class QuerySrvWrap: public QueryWrap {
}
Local<Array> srv_records = Array::New();
Local<String> name_symbol = String::NewSymbol("name");
Local<String> port_symbol = String::NewSymbol("port");
Local<String> priority_symbol = String::NewSymbol("priority");
Local<String> weight_symbol = String::NewSymbol("weight");
Local<String> name_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "name");
Local<String> port_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "port");
Local<String> priority_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "priority");
Local<String> weight_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "weight");
int i = 0;
for (struct ares_srv_reply* srv_current = srv_start;
srv_current;
srv_current = srv_current->next) {
Local<Object> srv_record = Object::New();
srv_record->Set(name_symbol, String::New(srv_current->host));
srv_record->Set(name_symbol,
OneByteString(node_isolate, srv_current->host));
srv_record->Set(port_symbol,
Integer::New(srv_current->port, node_isolate));
srv_record->Set(priority_symbol,
@ -620,12 +630,18 @@ class QueryNaptrWrap: public QueryWrap {
}
Local<Array> naptr_records = Array::New();
Local<String> flags_symbol = String::NewSymbol("flags");
Local<String> service_symbol = String::NewSymbol("service");
Local<String> regexp_symbol = String::NewSymbol("regexp");
Local<String> replacement_symbol = String::NewSymbol("replacement");
Local<String> order_symbol = String::NewSymbol("order");
Local<String> preference_symbol = String::NewSymbol("preference");
Local<String> flags_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "flags");
Local<String> service_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "service");
Local<String> regexp_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "regexp");
Local<String> replacement_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "replacement");
Local<String> order_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "order");
Local<String> preference_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "preference");
int i = 0;
for (ares_naptr_reply* naptr_current = naptr_start;
@ -634,13 +650,14 @@ class QueryNaptrWrap: public QueryWrap {
Local<Object> naptr_record = Object::New();
naptr_record->Set(flags_symbol,
String::New(reinterpret_cast<char*>(naptr_current->flags)));
OneByteString(node_isolate, naptr_current->flags));
naptr_record->Set(service_symbol,
String::New(reinterpret_cast<char*>(naptr_current->service)));
OneByteString(node_isolate, naptr_current->service));
naptr_record->Set(regexp_symbol,
String::New(reinterpret_cast<char*>(naptr_current->regexp)));
OneByteString(node_isolate, naptr_current->regexp));
naptr_record->Set(replacement_symbol,
String::New(naptr_current->replacement));
OneByteString(node_isolate,
naptr_current->replacement));
naptr_record->Set(order_symbol, Integer::New(naptr_current->order,
node_isolate));
naptr_record->Set(preference_symbol,
@ -814,7 +831,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
continue;
// Create JavaScript string
Local<String> s = String::New(ip);
Local<String> s = OneByteString(node_isolate, ip);
results->Set(n, s);
n++;
}
@ -841,7 +858,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
continue;
// Create JavaScript string
Local<String> s = String::New(ip);
Local<String> s = OneByteString(node_isolate, ip);
results->Set(n, s);
n++;
}
@ -943,7 +960,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
int err = uv_inet_ntop(cur->family, caddr, ip, sizeof(ip));
assert(err == 0);
Local<String> addr = String::New(ip);
Local<String> addr = OneByteString(node_isolate, ip);
server_array->Set(i, addr);
}
@ -1024,7 +1041,7 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
static void StrError(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
const char* errmsg = ares_strerror(args[0]->Int32Value());
args.GetReturnValue().Set(String::New(errmsg));
args.GetReturnValue().Set(OneByteString(node_isolate, errmsg));
}
@ -1069,14 +1086,14 @@ static void Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "getServers", GetServers);
NODE_SET_METHOD(target, "setServers", SetServers);
target->Set(String::NewSymbol("AF_INET"),
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "AF_INET"),
Integer::New(AF_INET, node_isolate));
target->Set(String::NewSymbol("AF_INET6"),
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "AF_INET6"),
Integer::New(AF_INET6, node_isolate));
target->Set(String::NewSymbol("AF_UNSPEC"),
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "AF_UNSPEC"),
Integer::New(AF_UNSPEC, node_isolate));
oncomplete_sym = String::New("oncomplete");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
}
} // namespace cares_wrap

12
src/fs_event_wrap.cc

@ -75,16 +75,16 @@ void FSEventWrap::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("FSEvent"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "FSEvent"));
NODE_SET_PROTOTYPE_METHOD(t, "start", Start);
NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
target->Set(String::New("FSEvent"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "FSEvent"), t->GetFunction());
change_sym = String::New("change");
onchange_sym = String::New("onchange");
rename_sym = String::New("rename");
change_sym = FIXED_ONE_BYTE_STRING(node_isolate, "change");
onchange_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onchange");
rename_sym = FIXED_ONE_BYTE_STRING(node_isolate, "rename");
}
@ -161,7 +161,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
};
if (filename != NULL) {
argv[2] = String::New(filename);
argv[2] = OneByteString(node_isolate, filename);
}
MakeCallback(wrap->object(), onchange_sym, ARRAY_SIZE(argv), argv);

4
src/handle_wrap.cc

@ -76,7 +76,9 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
wrap->handle__ = NULL;
if (args[0]->IsFunction()) {
if (close_sym.IsEmpty() == true) close_sym = String::New("close");
if (close_sym.IsEmpty() == true) {
close_sym = FIXED_ONE_BYTE_STRING(node_isolate, "close");
}
wrap->object()->Set(close_sym, args[0]);
wrap->flags_ |= kCloseCallback;
}

333
src/node.cc

@ -242,7 +242,8 @@ static void CheckImmediate(uv_check_t* handle, int status) {
HandleScope scope(node_isolate);
if (immediate_callback_sym.IsEmpty()) {
immediate_callback_sym = String::New("_immediateCallback");
immediate_callback_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "_immediateCallback");
}
MakeCallback(process_p, immediate_callback_sym, 0, NULL);
@ -738,26 +739,30 @@ Local<Value> ErrnoException(int errorno,
const char *msg,
const char *path) {
Local<Value> e;
Local<String> estring = String::NewSymbol(errno_string(errorno));
Local<String> estring = OneByteString(node_isolate, errno_string(errorno));
if (msg == NULL || msg[0] == '\0') {
msg = strerror(errorno);
}
Local<String> message = String::NewSymbol(msg);
Local<String> message = OneByteString(node_isolate, msg);
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
Local<String> cons1 =
String::Concat(estring, FIXED_ONE_BYTE_STRING(node_isolate, ", "));
Local<String> cons2 = String::Concat(cons1, message);
if (syscall_symbol.IsEmpty()) {
syscall_symbol = String::New("syscall");
errno_symbol = String::New("errno");
errpath_symbol = String::New("path");
code_symbol = String::New("code");
syscall_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "syscall");
errno_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "errno");
errpath_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "path");
code_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "code");
}
if (path) {
Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
Local<String> cons4 = String::Concat(cons3, String::New(path));
Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
Local<String> cons3 =
String::Concat(cons2, FIXED_ONE_BYTE_STRING(node_isolate, " '"));
Local<String> cons4 =
String::Concat(cons3, String::NewFromUtf8(node_isolate, path));
Local<String> cons5 =
String::Concat(cons4, FIXED_ONE_BYTE_STRING(node_isolate, "'"));
e = Exception::Error(cons5);
} else {
e = Exception::Error(cons2);
@ -767,8 +772,8 @@ Local<Value> ErrnoException(int errorno,
obj->Set(errno_symbol, Integer::New(errorno, node_isolate));
obj->Set(code_symbol, estring);
if (path) obj->Set(errpath_symbol, String::New(path));
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
if (path) obj->Set(errpath_symbol, String::NewFromUtf8(node_isolate, path));
if (syscall) obj->Set(syscall_symbol, OneByteString(node_isolate, syscall));
return e;
}
@ -779,18 +784,19 @@ Local<Value> UVException(int errorno,
const char *msg,
const char *path) {
if (syscall_symbol.IsEmpty()) {
syscall_symbol = String::New("syscall");
errno_symbol = String::New("errno");
errpath_symbol = String::New("path");
code_symbol = String::New("code");
syscall_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "syscall");
errno_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "errno");
errpath_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "path");
code_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "code");
}
if (!msg || !msg[0])
msg = uv_strerror(errorno);
Local<String> estring = String::NewSymbol(uv_err_name(errorno));
Local<String> message = String::NewSymbol(msg);
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
Local<String> estring = OneByteString(node_isolate, uv_err_name(errorno));
Local<String> message = OneByteString(node_isolate, msg);
Local<String> cons1 =
String::Concat(estring, FIXED_ONE_BYTE_STRING(node_isolate, ", "));
Local<String> cons2 = String::Concat(cons1, message);
Local<Value> e;
@ -800,19 +806,23 @@ Local<Value> UVException(int errorno,
if (path) {
#ifdef _WIN32
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
path_str = String::Concat(String::New("\\\\"), String::New(path + 8));
path_str = String::Concat(FIXED_ONE_BYTE_STRING(node_isolate, "\\\\"),
String::NewFromUtf8(node_isolate, path + 8));
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
path_str = String::New(path + 4);
path_str = String::NewFromUtf8(node_isolate, path + 4);
} else {
path_str = String::New(path);
path_str = String::NewFromUtf8(node_isolate, path);
}
#else
path_str = String::New(path);
path_str = String::NewFromUtf8(node_isolate, path);
#endif
Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
Local<String> cons4 = String::Concat(cons3, path_str);
Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
Local<String> cons3 =
String::Concat(cons2, FIXED_ONE_BYTE_STRING(node_isolate, " '"));
Local<String> cons4 =
String::Concat(cons3, path_str);
Local<String> cons5 =
String::Concat(cons4, FIXED_ONE_BYTE_STRING(node_isolate, "'"));
e = Exception::Error(cons5);
} else {
e = Exception::Error(cons2);
@ -824,7 +834,7 @@ Local<Value> UVException(int errorno,
obj->Set(errno_symbol, Integer::New(errorno, node_isolate));
obj->Set(code_symbol, estring);
if (path) obj->Set(errpath_symbol, path_str);
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
if (syscall) obj->Set(syscall_symbol, OneByteString(node_isolate, syscall));
return e;
}
@ -862,19 +872,22 @@ Local<Value> WinapiErrnoException(int errorno,
if (!msg || !msg[0]) {
msg = winapi_strerror(errorno);
}
Local<String> message = String::NewSymbol(msg);
Local<String> message = OneByteString(node_isolate, msg);
if (syscall_symbol.IsEmpty()) {
syscall_symbol = String::New("syscall");
errno_symbol = String::New("errno");
errpath_symbol = String::New("path");
code_symbol = String::New("code");
syscall_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "syscall");
errno_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "errno");
errpath_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "path");
code_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "code");
}
if (path) {
Local<String> cons1 = String::Concat(message, String::NewSymbol(" '"));
Local<String> cons2 = String::Concat(cons1, String::New(path));
Local<String> cons3 = String::Concat(cons2, String::NewSymbol("'"));
Local<String> cons1 =
String::Concat(message, FIXED_ONE_BYTE_STRING(node_isolate, " '"));
Local<String> cons2 =
String::Concat(cons1, String::NewFromUtf8(node_isolate, path));
Local<String> cons3 =
String::Concat(cons2, FIXED_ONE_BYTE_STRING(node_isolate, "'"));
e = Exception::Error(cons3);
} else {
e = Exception::Error(message);
@ -883,8 +896,8 @@ Local<Value> WinapiErrnoException(int errorno,
Local<Object> obj = e->ToObject();
obj->Set(errno_symbol, Integer::New(errorno, node_isolate));
if (path) obj->Set(errpath_symbol, String::New(path));
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
if (path) obj->Set(errpath_symbol, String::NewFromUtf8(node_isolate, path));
if (syscall) obj->Set(syscall_symbol, OneByteString(node_isolate, syscall));
return e;
}
#endif
@ -895,8 +908,10 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
using_domains = true;
Local<Object> process = PersistentToLocal(node_isolate, process_p);
Local<Value> tdc_v = process->Get(String::New("_tickDomainCallback"));
Local<Value> ndt_v = process->Get(String::New("_nextDomainTick"));
Local<Value> tdc_v =
process->Get(FIXED_ONE_BYTE_STRING(node_isolate, "_tickDomainCallback"));
Local<Value> ndt_v =
process->Get(FIXED_ONE_BYTE_STRING(node_isolate, "_nextDomainTick"));
if (!tdc_v->IsFunction()) {
fprintf(stderr, "process._tickDomainCallback assigned to non-function\n");
abort();
@ -907,8 +922,8 @@ void SetupDomainUse(const FunctionCallbackInfo<Value>& args) {
}
Local<Function> tdc = tdc_v.As<Function>();
Local<Function> ndt = ndt_v.As<Function>();
process->Set(String::New("_tickCallback"), tdc);
process->Set(String::New("nextTick"), ndt);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "_tickCallback"), tdc);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "nextTick"), ndt);
process_tickCallback.Reset(node_isolate, tdc);
}
@ -922,9 +937,9 @@ MakeDomainCallback(const Handle<Object> object,
// lazy load domain specific symbols
if (enter_symbol.IsEmpty()) {
enter_symbol = String::New("enter");
exit_symbol = String::New("exit");
disposed_symbol = String::New("_disposed");
enter_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "enter");
exit_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "exit");
disposed_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "_disposed");
}
Local<Value> domain_v = object->Get(domain_symbol);
@ -1008,7 +1023,8 @@ MakeCallback(const Handle<Object> object,
// lazy load no domain next tick callbacks
if (process_tickCallback.IsEmpty()) {
Local<Value> cb_v = process->Get(String::New("_tickCallback"));
Local<Value> cb_v =
process->Get(FIXED_ONE_BYTE_STRING(node_isolate, "_tickCallback"));
if (!cb_v->IsFunction()) {
fprintf(stderr, "process._tickCallback assigned to non-function\n");
abort();
@ -1069,8 +1085,8 @@ MakeCallback(const Handle<Object> object,
Handle<Value> argv[]) {
HandleScope scope(node_isolate);
Handle<Value> ret =
MakeCallback(object, String::NewSymbol(method), argc, argv);
Local<String> method_string = OneByteString(node_isolate, method);
Handle<Value> ret = MakeCallback(object, method_string, argc, argv);
return scope.Close(ret);
}
@ -1219,7 +1235,8 @@ static void ReportException(Handle<Value> er, Handle<Message> message) {
DisplayExceptionLine(message);
Local<Value> trace_value(er->ToObject()->Get(String::New("stack")));
Local<Value> trace_value(
er->ToObject()->Get(FIXED_ONE_BYTE_STRING(node_isolate, "stack")));
String::Utf8Value trace(trace_value);
// range errors have a trace member set to undefined
@ -1229,18 +1246,27 @@ static void ReportException(Handle<Value> er, Handle<Message> message) {
// this really only happens for RangeErrors, since they're the only
// kind that won't have all this info in the trace, or when non-Error
// objects are thrown manually.
bool isErrorObject = er->IsObject() &&
!(er->ToObject()->Get(String::New("message"))->IsUndefined()) &&
!(er->ToObject()->Get(String::New("name"))->IsUndefined());
Local<Value> message;
Local<Value> name;
if (isErrorObject) {
String::Utf8Value name(er->ToObject()->Get(String::New("name")));
fprintf(stderr, "%s: ", *name);
if (er->IsObject()) {
Local<Object> err_obj = er.As<Object>();
message = err_obj->Get(FIXED_ONE_BYTE_STRING(node_isolate, "message"));
name = err_obj->Get(FIXED_ONE_BYTE_STRING(node_isolate, "name"));
}
String::Utf8Value msg(!isErrorObject ? er
: er->ToObject()->Get(String::New("message")));
fprintf(stderr, "%s\n", *msg);
if (message.IsEmpty() ||
message->IsUndefined() ||
name.IsEmpty() ||
name->IsUndefined()) {
// Not an error object. Just print as-is.
String::Utf8Value message(er);
fprintf(stderr, "%s\n", *message);
} else {
String::Utf8Value name_string(name);
String::Utf8Value message_string(message);
fprintf(stderr, "%s: %s\n", *name_string, *message_string);
}
}
fflush(stderr);
@ -1303,7 +1329,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
QUEUE* q = NULL;
int i = 0;
Local<String> owner_sym = String::New("owner");
Local<String> owner_sym = FIXED_ONE_BYTE_STRING(node_isolate, "owner");
QUEUE_FOREACH(q, &handle_wrap_queue) {
HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_);
@ -1353,7 +1379,7 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) {
}
buf[ARRAY_SIZE(buf) - 1] = '\0';
Local<String> cwd = String::New(buf);
Local<String> cwd = String::NewFromUtf8(node_isolate, buf);
args.GetReturnValue().Set(cwd);
}
@ -1687,9 +1713,9 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
Local<Object> info = Object::New();
if (rss_symbol.IsEmpty()) {
rss_symbol = String::New("rss");
heap_total_symbol = String::New("heapTotal");
heap_used_symbol = String::New("heapUsed");
rss_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "rss");
heap_total_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "heapTotal");
heap_used_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "heapUsed");
}
info->Set(rss_symbol, Number::New(rss));
@ -1770,12 +1796,12 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
String::Utf8Value filename(args[1]); // Cast
if (exports_symbol.IsEmpty()) {
exports_symbol = String::New("exports");
exports_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "exports");
}
Local<Object> exports = module->Get(exports_symbol)->ToObject();
if (uv_dlopen(*filename, &lib)) {
Local<String> errmsg = String::New(uv_dlerror(&lib));
Local<String> errmsg = OneByteString(node_isolate, uv_dlerror(&lib));
#ifdef _WIN32
// Windows needs to add the filename into the error message
errmsg = String::Concat(errmsg, args[1]->ToString());
@ -1870,8 +1896,10 @@ NO_RETURN void FatalError(const char* location, const char* message) {
void FatalException(Handle<Value> error, Handle<Message> message) {
HandleScope scope(node_isolate);
if (fatal_exception_symbol.IsEmpty())
fatal_exception_symbol = String::New("_fatalException");
if (fatal_exception_symbol.IsEmpty()) {
fatal_exception_symbol =
FIXED_ONE_BYTE_STRING(node_isolate, "_fatalException");
}
Local<Object> process = PersistentToLocal(node_isolate, process_p);
Local<Value> fatal_v = process->Get(fatal_exception_symbol);
@ -1943,7 +1971,7 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
Local<Array> modules = PersistentToLocal(node_isolate, module_load_list);
uint32_t l = modules->Length();
modules->Set(l, String::New(buf));
modules->Set(l, OneByteString(node_isolate, buf));
if ((modp = get_builtin_module(*module_v)) != NULL) {
exports = Object::New();
@ -1972,7 +2000,7 @@ static void ProcessTitleGetter(Local<String> property,
HandleScope scope(node_isolate);
char buffer[512];
uv_get_process_title(buffer, sizeof(buffer));
info.GetReturnValue().Set(String::New(buffer));
info.GetReturnValue().Set(String::NewFromUtf8(node_isolate, buffer));
}
@ -1993,7 +2021,7 @@ static void EnvGetter(Local<String> property,
String::Utf8Value key(property);
const char* val = getenv(*key);
if (val) {
return info.GetReturnValue().Set(String::New(val));
return info.GetReturnValue().Set(String::NewFromUtf8(node_isolate, val));
}
#else // _WIN32
String::Value key(property);
@ -2006,8 +2034,9 @@ static void EnvGetter(Local<String> property,
// not found.
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
result < ARRAY_SIZE(buffer)) {
return info.GetReturnValue().Set(
String::New(reinterpret_cast<uint16_t*>(buffer), result));
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
Local<String> rc = String::NewFromTwoByte(node_isolate, two_byte_buffer);
return info.GetReturnValue().Set(rc);
}
#endif
// Not found. Fetch from prototype.
@ -2097,7 +2126,11 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
const char* var = environ[i];
const char* s = strchr(var, '=');
const int length = s ? s - var : strlen(var);
env->Set(i, String::New(var, length));
Local<String> name = String::NewFromUtf8(node_isolate,
var,
String::kNormalString,
length);
env->Set(i, name);
}
#else // _WIN32
WCHAR* environment = GetEnvironmentStringsW();
@ -2117,7 +2150,8 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
if (!s) {
s = p + wcslen(p);
}
env->Set(i++, String::New(reinterpret_cast<uint16_t*>(p), s - p));
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(p);
env->Set(i++, TWO_BYTE_STRING(node_isolate, two_byte_buffer, s - p));
p = s + wcslen(s) + 1;
}
FreeEnvironmentStringsW(environment);
@ -2137,15 +2171,18 @@ static Handle<Object> GetFeatures() {
Local<Value> debug = False(node_isolate);
#endif // defined(DEBUG) && DEBUG
obj->Set(String::NewSymbol("debug"), debug);
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "debug"), debug);
obj->Set(String::NewSymbol("uv"), True(node_isolate));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "uv"), True(node_isolate));
// TODO(bnoordhuis) ping libuv
obj->Set(String::NewSymbol("ipv6"), True(node_isolate));
obj->Set(String::NewSymbol("tls_npn"), Boolean::New(use_npn));
obj->Set(String::NewSymbol("tls_sni"), Boolean::New(use_sni));
obj->Set(String::NewSymbol("tls"),
Boolean::New(get_builtin_module("crypto") != NULL));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "ipv6"), True(node_isolate));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "tls_npn"),
Boolean::New(use_npn));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "tls_sni"),
Boolean::New(use_sni));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "tls"),
Boolean::New(get_builtin_module("crypto") != NULL));
return scope.Close(obj);
}
@ -2201,7 +2238,7 @@ static void NeedImmediateCallbackSetter(Local<String> property,
#define READONLY_PROPERTY(obj, str, var) \
do { \
obj->Set(String::New(str), var, v8::ReadOnly); \
obj->Set(OneByteString(node_isolate, str), var, v8::ReadOnly); \
} while (0)
@ -2211,7 +2248,8 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
int i, j;
Local<FunctionTemplate> process_template = FunctionTemplate::New();
process_template->SetClassName(String::New("process"));
process_template->SetClassName(
FIXED_ONE_BYTE_STRING(node_isolate, "process"));
Local<Object> process = process_template->GetFunction()->NewInstance();
assert(process.IsEmpty() == false);
@ -2219,12 +2257,14 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
process_p.Reset(node_isolate, process);
process->SetAccessor(String::New("title"),
process->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "title"),
ProcessTitleGetter,
ProcessTitleSetter);
// process.version
READONLY_PROPERTY(process, "version", String::New(NODE_VERSION));
READONLY_PROPERTY(process,
"version",
FIXED_ONE_BYTE_STRING(node_isolate, NODE_VERSION));
// process.moduleLoadList
Local<Array> modules = Array::New();
@ -2234,17 +2274,33 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
// process.versions
Local<Object> versions = Object::New();
READONLY_PROPERTY(process, "versions", versions);
READONLY_PROPERTY(versions, "http_parser", String::New(
NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) "."
NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR)));
const char http_parser_version[] = NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR)
"."
NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR);
READONLY_PROPERTY(versions,
"http_parser",
FIXED_ONE_BYTE_STRING(node_isolate, http_parser_version));
// +1 to get rid of the leading 'v'
READONLY_PROPERTY(versions, "node", String::New(NODE_VERSION+1));
READONLY_PROPERTY(versions, "v8", String::New(V8::GetVersion()));
READONLY_PROPERTY(versions, "uv", String::New(uv_version_string()));
READONLY_PROPERTY(versions, "zlib", String::New(ZLIB_VERSION));
READONLY_PROPERTY(versions,
"node",
OneByteString(node_isolate, NODE_VERSION + 1));
READONLY_PROPERTY(versions,
"v8",
OneByteString(node_isolate, V8::GetVersion()));
READONLY_PROPERTY(versions,
"uv",
OneByteString(node_isolate, uv_version_string()));
READONLY_PROPERTY(versions,
"zlib",
FIXED_ONE_BYTE_STRING(node_isolate, ZLIB_VERSION));
const char node_modules_version[] = NODE_STRINGIFY(NODE_MODULE_VERSION);
READONLY_PROPERTY(versions,
"modules",
String::New(NODE_STRINGIFY(NODE_MODULE_VERSION)));
FIXED_ONE_BYTE_STRING(node_isolate, node_modules_version));
#if HAVE_OPENSSL
// Stupid code to slice out the version string.
int c, l = strlen(OPENSSL_VERSION_TEXT);
@ -2258,37 +2314,36 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
break;
}
}
READONLY_PROPERTY(versions,
"openssl",
String::New(&OPENSSL_VERSION_TEXT[i], j - i));
READONLY_PROPERTY(
versions,
"openssl",
OneByteString(node_isolate, &OPENSSL_VERSION_TEXT[i], j - i));
#endif
// process.arch
READONLY_PROPERTY(process, "arch", String::New(ARCH));
READONLY_PROPERTY(process, "arch", OneByteString(node_isolate, ARCH));
// process.platform
READONLY_PROPERTY(process, "platform", String::New(PLATFORM));
READONLY_PROPERTY(process,
"platform",
OneByteString(node_isolate, PLATFORM));
// process.argv
Local<Array> arguments = Array::New(argc - option_end_index + 1);
arguments->Set(Integer::New(0, node_isolate), String::New(argv[0]));
arguments->Set(0, String::NewFromUtf8(node_isolate, argv[0]));
for (j = 1, i = option_end_index; i < argc; j++, i++) {
Local<String> arg = String::New(argv[i]);
arguments->Set(Integer::New(j, node_isolate), arg);
arguments->Set(j, String::NewFromUtf8(node_isolate, argv[i]));
}
// assign it
process->Set(String::NewSymbol("argv"), arguments);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "argv"), arguments);
// process.execArgv
Local<Array> execArgv = Array::New(option_end_index - 1);
Local<Array> exec_argv = Array::New(option_end_index - 1);
for (j = 1, i = 0; j < option_end_index; j++, i++) {
execArgv->Set(Integer::New(i, node_isolate), String::New(argv[j]));
exec_argv->Set(i, String::NewFromUtf8(node_isolate, argv[j]));
}
// assign it
process->Set(String::NewSymbol("execArgv"), execArgv);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "execArgv"), exec_argv);
// create process.env
Local<ObjectTemplate> envTemplate = ObjectTemplate::New();
@ -2299,17 +2354,20 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
EnvEnumerator,
Object::New());
Local<Object> env = envTemplate->NewInstance();
process->Set(String::NewSymbol("env"), env);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "env"), env);
READONLY_PROPERTY(process, "pid", Integer::New(getpid(), node_isolate));
READONLY_PROPERTY(process, "features", GetFeatures());
process->SetAccessor(String::New("_needImmediateCallback"),
NeedImmediateCallbackGetter,
NeedImmediateCallbackSetter);
process->SetAccessor(
FIXED_ONE_BYTE_STRING(node_isolate, "_needImmediateCallback"),
NeedImmediateCallbackGetter,
NeedImmediateCallbackSetter);
// -e, --eval
if (eval_string) {
READONLY_PROPERTY(process, "_eval", String::New(eval_string));
READONLY_PROPERTY(process,
"_eval",
String::NewFromUtf8(node_isolate, eval_string));
}
// -p, --print
@ -2337,21 +2395,25 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
READONLY_PROPERTY(process, "traceDeprecation", True(node_isolate));
}
size_t size = 2*PATH_MAX;
char* execPath = new char[size];
if (uv_exepath(execPath, &size) != 0) {
// as a last ditch effort, fallback on argv[0] ?
process->Set(String::NewSymbol("execPath"), String::New(argv[0]));
size_t exec_path_len = 2 * PATH_MAX;
char* exec_path = new char[exec_path_len];
Local<String> exec_path_value;
if (uv_exepath(exec_path, &exec_path_len) == 0) {
exec_path_value = String::NewFromUtf8(node_isolate,
exec_path,
String::kNormalString,
exec_path_len);
} else {
process->Set(String::NewSymbol("execPath"), String::New(execPath, size));
exec_path_value = String::NewFromUtf8(node_isolate, argv[0]);
}
delete [] execPath;
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "execPath"),
exec_path_value);
delete[] exec_path;
process->SetAccessor(String::New("debugPort"),
process->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "debugPort"),
DebugPortGetter,
DebugPortSetter);
// define various internal methods
NODE_SET_METHOD(process, "_getActiveRequests", GetActiveRequests);
NODE_SET_METHOD(process, "_getActiveHandles", GetActiveHandles);
@ -2396,10 +2458,10 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
info_box->SetIndexedPropertiesToExternalArrayData(&tick_infobox,
kExternalUnsignedIntArray,
4);
process->Set(String::NewSymbol("_tickInfoBox"), info_box);
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "_tickInfoBox"), info_box);
// pre-set _events object for faster emit checks
process->Set(String::NewSymbol("_events"), Object::New());
process->Set(FIXED_ONE_BYTE_STRING(node_isolate, "_events"), Object::New());
return scope.Close(process);
}
@ -2422,8 +2484,8 @@ static void SignalExit(int signal) {
void Load(Handle<Object> process_l) {
HandleScope handle_scope(node_isolate);
process_symbol = String::New("process");
domain_symbol = String::New("domain");
process_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "process");
domain_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "domain");
// Compile, execute the src/node.js file. (Which was included as static C
// string in node_natives.h. 'natve_node' is the string containing that
@ -2439,7 +2501,8 @@ void Load(Handle<Object> process_l) {
// are not safe to ignore.
try_catch.SetVerbose(false);
Local<Value> f_value = ExecuteString(MainSource(), String::New("node.js"));
Local<String> script_name = FIXED_ONE_BYTE_STRING(node_isolate, "node.js");
Local<Value> f_value = ExecuteString(MainSource(), script_name);
if (try_catch.HasCaught()) {
ReportException(try_catch);
exit(10);
@ -2632,8 +2695,12 @@ static void DispatchMessagesDebugAgentCallback() {
static void EmitDebugEnabledAsyncCallback(uv_async_t* handle, int status) {
HandleScope handle_scope(node_isolate);
Local<Object> obj = Object::New();
obj->Set(String::New("cmd"), String::New("NODE_DEBUG_ENABLED"));
Local<Value> args[] = { String::New("internalMessage"), obj };
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "cmd"),
FIXED_ONE_BYTE_STRING(node_isolate, "NODE_DEBUG_ENABLED"));
Local<Value> args[] = {
FIXED_ONE_BYTE_STRING(node_isolate, "internalMessage"),
obj
};
MakeCallback(process_p, "emit", ARRAY_SIZE(args), args);
}
@ -3001,8 +3068,12 @@ void AtExit(void (*cb)(void* arg), void* arg) {
void EmitExit(v8::Handle<v8::Object> process_l) {
// process.emit('exit')
process_l->Set(String::NewSymbol("_exiting"), True(node_isolate));
Local<Value> args[] = { String::New("exit"), Integer::New(0, node_isolate) };
process_l->Set(FIXED_ONE_BYTE_STRING(node_isolate, "_exiting"),
True(node_isolate));
Local<Value> args[] = {
FIXED_ONE_BYTE_STRING(node_isolate, "exit"),
Integer::New(0, node_isolate)
};
MakeCallback(process_l, "emit", ARRAY_SIZE(args), args);
}

27
src/node.h

@ -129,20 +129,30 @@ void EmitExit(v8::Handle<v8::Object> process);
#define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
#define NODE_V8_UNIXTIME(v) (static_cast<double>((v)->NumberValue())/1000.0);
#define NODE_DEFINE_CONSTANT(target, constant) \
(target)->Set(v8::String::NewSymbol(#constant), \
v8::Number::New(constant), \
static_cast<v8::PropertyAttribute>( \
v8::ReadOnly|v8::DontDelete))
// Used to be a macro, hence the uppercase name.
#define NODE_DEFINE_CONSTANT(target, constant) \
do { \
v8::Isolate* isolate = v8::Isolate::GetCurrent(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, #constant); \
v8::Local<v8::Number> constant_value = \
v8::Number::New(isolate, static_cast<double>(constant)); \
v8::PropertyAttribute constant_attributes = \
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
(target)->Set(constant_name, constant_value, constant_attributes); \
} \
while (0)
// Used to be a macro, hence the uppercase name.
template <typename TypeName>
inline void NODE_SET_METHOD(const TypeName& recv,
const char* name,
v8::FunctionCallback callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback);
v8::Local<v8::Function> fn = t->GetFunction();
v8::Local<v8::String> fn_name = v8::String::New(name);
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
fn->SetName(fn_name);
recv->Set(fn_name, fn);
}
@ -153,8 +163,11 @@ inline void NODE_SET_METHOD(const TypeName& recv,
inline void NODE_SET_PROTOTYPE_METHOD(v8::Handle<v8::FunctionTemplate> recv,
const char* name,
v8::FunctionCallback callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(callback);
recv->PrototypeTemplate()->Set(v8::String::New(name), t->GetFunction());
recv->PrototypeTemplate()->Set(v8::String::NewFromUtf8(isolate, name),
t->GetFunction());
}
#define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD

11
src/node_buffer.cc

@ -559,13 +559,14 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
Local<Function> bv = args[0].As<Function>();
p_buffer_fn.Reset(node_isolate, bv);
Local<Value> proto_v = bv->Get(String::New("prototype"));
Local<Value> proto_v =
bv->Get(FIXED_ONE_BYTE_STRING(node_isolate, "prototype"));
assert(proto_v->IsObject());
Local<Object> proto = proto_v.As<Object>();
bv->Set(String::New("byteLength"),
bv->Set(FIXED_ONE_BYTE_STRING(node_isolate, "byteLength"),
FunctionTemplate::New(ByteLength)->GetFunction());
NODE_SET_METHOD(proto, "asciiSlice", AsciiSlice);
@ -596,14 +597,16 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
NODE_SET_METHOD(proto, "fill", Fill);
// for backwards compatibility
proto->Set(String::New("offset"), Uint32::New(0, node_isolate), v8::ReadOnly);
proto->Set(FIXED_ONE_BYTE_STRING(node_isolate, "offset"),
Uint32::New(0, node_isolate),
v8::ReadOnly);
}
void Initialize(Handle<Object> target) {
HandleScope scope(node_isolate);
target->Set(String::New("setupBufferJS"),
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "setupBufferJS"),
FunctionTemplate::New(SetupBufferJS)->GetFunction());
}

2
src/node_counters.cc

@ -114,7 +114,7 @@ void InitPerfCounters(Handle<Object> target) {
};
for (int i = 0; i < ARRAY_SIZE(tab); i++) {
Local<String> key = String::New(tab[i].name);
Local<String> key = OneByteString(node_isolate, tab[i].name);
Local<Value> val = FunctionTemplate::New(tab[i].func)->GetFunction();
target->Set(key, val);
}

225
src/node_crypto.cc

@ -179,7 +179,7 @@ void SecureContext::Initialize(Handle<Object> target) {
secure_context_constructor.Reset(node_isolate, t);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("SecureContext"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "SecureContext"));
NODE_SET_PROTOTYPE_METHOD(t, "init", SecureContext::Init);
NODE_SET_PROTOTYPE_METHOD(t, "setKey", SecureContext::SetKey);
@ -198,7 +198,8 @@ void SecureContext::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "getTicketKeys", SecureContext::GetTicketKeys);
NODE_SET_PROTOTYPE_METHOD(t, "setTicketKeys", SecureContext::SetTicketKeys);
target->Set(String::NewSymbol("SecureContext"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "SecureContext"),
t->GetFunction());
}
@ -312,7 +313,7 @@ int SecureContext::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
};
if (onnewsession_sym.IsEmpty()) {
onnewsession_sym = String::New("onnewsession");
onnewsession_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onnewsession");
}
MakeCallback(p->handle(node_isolate),
@ -647,11 +648,12 @@ void SecureContext::SetSessionIdContext(
bio = BIO_new(BIO_s_mem());
if (bio == NULL) {
message = String::New("SSL_CTX_set_session_id_context error");
message = FIXED_ONE_BYTE_STRING(node_isolate,
"SSL_CTX_set_session_id_context error");
} else {
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
message = String::New(mem->data, mem->length);
message = OneByteString(node_isolate, mem->data, mem->length);
BIO_free_all(bio);
}
@ -800,9 +802,9 @@ void Connection::OnClientHello(void* arg,
Connection* c = static_cast<Connection*>(arg);
if (onclienthello_sym.IsEmpty())
onclienthello_sym = String::New("onclienthello");
onclienthello_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onclienthello");
if (sessionid_sym.IsEmpty())
sessionid_sym = String::New("sessionId");
sessionid_sym = FIXED_ONE_BYTE_STRING(node_isolate, "sessionId");
Local<Object> obj = Object::New();
obj->Set(sessionid_sym,
@ -858,8 +860,10 @@ int Connection::HandleBIOError(BIO *bio, const char* func, int rv) {
ERR_error_string_n(rv, ssl_error_buf, sizeof(ssl_error_buf));
HandleScope scope(node_isolate);
Local<Value> e = Exception::Error(String::New(ssl_error_buf));
handle(node_isolate)->Set(String::New("error"), e);
Local<Value> exception =
Exception::Error(OneByteString(node_isolate, ssl_error_buf));
handle(node_isolate)->Set(
FIXED_ONE_BYTE_STRING(node_isolate, "error"), exception);
DEBUG_PRINT("[%p] BIO: %s failed: (%d) %s\n",
ssl_,
@ -898,8 +902,10 @@ int Connection::HandleSSLError(const char* func,
return 0;
} else if (err == SSL_ERROR_ZERO_RETURN) {
handle(node_isolate)->Set(String::New("error"),
Exception::Error(String::New("ZERO_RETURN")));
Local<Value> exception =
Exception::Error(FIXED_ONE_BYTE_STRING(node_isolate, "ZERO_RETURN"));
handle(node_isolate)->Set(
FIXED_ONE_BYTE_STRING(node_isolate, "error"), exception);
return rv;
} else if ((err == SSL_ERROR_SYSCALL) && (ss == kIgnoreSyscall)) {
@ -920,8 +926,10 @@ int Connection::HandleSSLError(const char* func,
if ((bio = BIO_new(BIO_s_mem()))) {
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
Local<Value> e = Exception::Error(String::New(mem->data, mem->length));
handle(node_isolate)->Set(String::New("error"), e);
Local<Value> exception =
Exception::Error(OneByteString(node_isolate, mem->data, mem->length));
handle(node_isolate)->Set(
FIXED_ONE_BYTE_STRING(node_isolate, "error"), exception);
BIO_free_all(bio);
}
@ -937,8 +945,9 @@ void Connection::ClearError() {
HandleScope scope(node_isolate);
// We should clear the error in JS-land
assert(
handle(node_isolate)->Get(String::New("error"))->BooleanValue() == false);
Local<String> error_key = FIXED_ONE_BYTE_STRING(node_isolate, "error");
Local<Value> error = handle(node_isolate)->Get(error_key);
assert(error->BooleanValue() == false);
#endif // NDEBUG
}
@ -949,12 +958,15 @@ void Connection::SetShutdownFlags() {
int flags = SSL_get_shutdown(ssl_);
if (flags & SSL_SENT_SHUTDOWN) {
handle(node_isolate)->Set(String::New("sentShutdown"), True(node_isolate));
Local<String> sent_shutdown_key =
FIXED_ONE_BYTE_STRING(node_isolate, "sentShutdown");
handle(node_isolate)->Set(sent_shutdown_key, True(node_isolate));
}
if (flags & SSL_RECEIVED_SHUTDOWN) {
handle(node_isolate)->Set(String::New("receivedShutdown"),
True(node_isolate));
Local<String> received_shutdown_key =
FIXED_ONE_BYTE_STRING(node_isolate, "receivedShutdown");
handle(node_isolate)->Set(received_shutdown_key, True(node_isolate));
}
}
@ -964,7 +976,7 @@ void Connection::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(Connection::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("Connection"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Connection"));
NODE_SET_PROTOTYPE_METHOD(t, "encIn", Connection::EncIn);
NODE_SET_PROTOTYPE_METHOD(t, "clearOut", Connection::ClearOut);
@ -1006,7 +1018,8 @@ void Connection::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setSNICallback", Connection::SetSNICallback);
#endif
target->Set(String::NewSymbol("Connection"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Connection"),
t->GetFunction());
}
@ -1109,10 +1122,11 @@ int Connection::SelectNextProtoCallback_(SSL *s,
p->selectedNPNProto_.Reset(node_isolate, Null(node_isolate));
break;
case OPENSSL_NPN_NEGOTIATED:
p->selectedNPNProto_.Reset(
node_isolate,
String::New(reinterpret_cast<const char*>(*out), *outlen));
break;
{
Local<String> string = OneByteString(node_isolate, *out, *outlen);
p->selectedNPNProto_.Reset(node_isolate, string);
break;
}
case OPENSSL_NPN_NO_OVERLAP:
p->selectedNPNProto_.Reset(node_isolate, False(node_isolate));
break;
@ -1133,7 +1147,8 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) {
const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
if (servername) {
p->servername_.Reset(node_isolate, String::New(servername));
p->servername_.Reset(node_isolate,
OneByteString(node_isolate, servername));
// Call the SNI callback and use its return value as context
if (!p->sniObject_.IsEmpty()) {
@ -1247,7 +1262,8 @@ void Connection::SSLInfoCallback(const SSL *ssl_, int where, int ret) {
HandleScope scope(node_isolate);
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
if (onhandshakestart_sym.IsEmpty()) {
onhandshakestart_sym = String::New("onhandshakestart");
onhandshakestart_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onhandshakestart");
}
MakeCallback(c->handle(node_isolate), onhandshakestart_sym, 0, NULL);
}
@ -1255,7 +1271,8 @@ void Connection::SSLInfoCallback(const SSL *ssl_, int where, int ret) {
HandleScope scope(node_isolate);
Connection* c = static_cast<Connection*>(SSL_get_app_data(ssl));
if (onhandshakedone_sym.IsEmpty()) {
onhandshakedone_sym = String::New("onhandshakedone");
onhandshakedone_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onhandshakedone");
}
MakeCallback(c->handle(node_isolate), onhandshakedone_sym, 0, NULL);
}
@ -1483,14 +1500,16 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
if (X509_NAME_print_ex(bio, X509_get_subject_name(peer_cert), 0,
X509_NAME_FLAGS) > 0) {
BIO_get_mem_ptr(bio, &mem);
info->Set(subject_symbol, String::New(mem->data, mem->length));
info->Set(subject_symbol,
OneByteString(node_isolate, mem->data, mem->length));
}
(void) BIO_reset(bio);
if (X509_NAME_print_ex(bio, X509_get_issuer_name(peer_cert), 0,
X509_NAME_FLAGS) > 0) {
BIO_get_mem_ptr(bio, &mem);
info->Set(issuer_symbol, String::New(mem->data, mem->length));
info->Set(issuer_symbol,
OneByteString(node_isolate, mem->data, mem->length));
}
(void) BIO_reset(bio);
@ -1506,7 +1525,8 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
assert(rv == 1);
BIO_get_mem_ptr(bio, &mem);
info->Set(subjectaltname_symbol, String::New(mem->data, mem->length));
info->Set(subjectaltname_symbol,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
}
@ -1517,12 +1537,14 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
NULL != (rsa = EVP_PKEY_get1_RSA(pkey))) {
BN_print(bio, rsa->n);
BIO_get_mem_ptr(bio, &mem);
info->Set(modulus_symbol, String::New(mem->data, mem->length) );
info->Set(modulus_symbol,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
BN_print(bio, rsa->e);
BIO_get_mem_ptr(bio, &mem);
info->Set(exponent_symbol, String::New(mem->data, mem->length) );
info->Set(exponent_symbol,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
}
@ -1537,12 +1559,14 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
ASN1_TIME_print(bio, X509_get_notBefore(peer_cert));
BIO_get_mem_ptr(bio, &mem);
info->Set(valid_from_symbol, String::New(mem->data, mem->length));
info->Set(valid_from_symbol,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
ASN1_TIME_print(bio, X509_get_notAfter(peer_cert));
BIO_get_mem_ptr(bio, &mem);
info->Set(valid_to_symbol, String::New(mem->data, mem->length));
info->Set(valid_to_symbol,
OneByteString(node_isolate, mem->data, mem->length));
BIO_free_all(bio);
unsigned int md_size, i;
@ -1563,7 +1587,7 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
fingerprint[0] = '\0';
}
info->Set(fingerprint_symbol, String::New(fingerprint));
info->Set(fingerprint_symbol, OneByteString(node_isolate, fingerprint));
}
STACK_OF(ASN1_OBJECT) *eku = (STACK_OF(ASN1_OBJECT) *)X509_get_ext_d2i(
@ -1575,7 +1599,8 @@ void Connection::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
for (int i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
memset(buf, 0, sizeof(buf));
OBJ_obj2txt(buf, sizeof(buf) - 1, sk_ASN1_OBJECT_value(eku, i), 1);
ext_key_usage->Set(Integer::New(i, node_isolate), String::New(buf));
ext_key_usage->Set(Integer::New(i, node_isolate),
OneByteString(node_isolate, buf));
}
sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
@ -1748,8 +1773,10 @@ void Connection::VerifyError(const FunctionCallbackInfo<Value>& args) {
// We requested a certificate and they did not send us one.
// Definitely an error.
// XXX is this the right error message?
return args.GetReturnValue().Set(
Exception::Error(String::New("UNABLE_TO_GET_ISSUER_CERT")));
Local<String> error_message =
FIXED_ONE_BYTE_STRING(node_isolate, "UNABLE_TO_GET_ISSUER_CERT");
Local<Value> exception = Exception::Error(error_message);
return args.GetReturnValue().Set(exception);
}
X509_free(peer_cert);
@ -1762,115 +1789,121 @@ void Connection::VerifyError(const FunctionCallbackInfo<Value>& args) {
break;
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
s = String::New("UNABLE_TO_GET_ISSUER_CERT");
s = FIXED_ONE_BYTE_STRING(node_isolate, "UNABLE_TO_GET_ISSUER_CERT");
break;
case X509_V_ERR_UNABLE_TO_GET_CRL:
s = String::New("UNABLE_TO_GET_CRL");
s = FIXED_ONE_BYTE_STRING(node_isolate, "UNABLE_TO_GET_CRL");
break;
case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
s = String::New("UNABLE_TO_DECRYPT_CERT_SIGNATURE");
s = FIXED_ONE_BYTE_STRING(node_isolate,
"UNABLE_TO_DECRYPT_CERT_SIGNATURE");
break;
case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
s = String::New("UNABLE_TO_DECRYPT_CRL_SIGNATURE");
s = FIXED_ONE_BYTE_STRING(node_isolate,
"UNABLE_TO_DECRYPT_CRL_SIGNATURE");
break;
case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
s = String::New("UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY");
s = FIXED_ONE_BYTE_STRING(node_isolate,
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY");
break;
case X509_V_ERR_CERT_SIGNATURE_FAILURE:
s = String::New("CERT_SIGNATURE_FAILURE");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_SIGNATURE_FAILURE");
break;
case X509_V_ERR_CRL_SIGNATURE_FAILURE:
s = String::New("CRL_SIGNATURE_FAILURE");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CRL_SIGNATURE_FAILURE");
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
s = String::New("CERT_NOT_YET_VALID");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_NOT_YET_VALID");
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
s = String::New("CERT_HAS_EXPIRED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_HAS_EXPIRED");
break;
case X509_V_ERR_CRL_NOT_YET_VALID:
s = String::New("CRL_NOT_YET_VALID");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CRL_NOT_YET_VALID");
break;
case X509_V_ERR_CRL_HAS_EXPIRED:
s = String::New("CRL_HAS_EXPIRED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CRL_HAS_EXPIRED");
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
s = String::New("ERROR_IN_CERT_NOT_BEFORE_FIELD");
s = FIXED_ONE_BYTE_STRING(node_isolate, "ERROR_IN_CERT_NOT_BEFORE_FIELD");
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
s = String::New("ERROR_IN_CERT_NOT_AFTER_FIELD");
s = FIXED_ONE_BYTE_STRING(node_isolate, "ERROR_IN_CERT_NOT_AFTER_FIELD");
break;
case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
s = String::New("ERROR_IN_CRL_LAST_UPDATE_FIELD");
s = FIXED_ONE_BYTE_STRING(node_isolate, "ERROR_IN_CRL_LAST_UPDATE_FIELD");
break;
case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
s = String::New("ERROR_IN_CRL_NEXT_UPDATE_FIELD");
s = FIXED_ONE_BYTE_STRING(node_isolate, "ERROR_IN_CRL_NEXT_UPDATE_FIELD");
break;
case X509_V_ERR_OUT_OF_MEM:
s = String::New("OUT_OF_MEM");
s = FIXED_ONE_BYTE_STRING(node_isolate, "OUT_OF_MEM");
break;
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
s = String::New("DEPTH_ZERO_SELF_SIGNED_CERT");
s = FIXED_ONE_BYTE_STRING(node_isolate, "DEPTH_ZERO_SELF_SIGNED_CERT");
break;
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
s = String::New("SELF_SIGNED_CERT_IN_CHAIN");
s = FIXED_ONE_BYTE_STRING(node_isolate, "SELF_SIGNED_CERT_IN_CHAIN");
break;
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
s = String::New("UNABLE_TO_GET_ISSUER_CERT_LOCALLY");
s = FIXED_ONE_BYTE_STRING(node_isolate,
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY");
break;
case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
s = String::New("UNABLE_TO_VERIFY_LEAF_SIGNATURE");
s = FIXED_ONE_BYTE_STRING(node_isolate,
"UNABLE_TO_VERIFY_LEAF_SIGNATURE");
break;
case X509_V_ERR_CERT_CHAIN_TOO_LONG:
s = String::New("CERT_CHAIN_TOO_LONG");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_CHAIN_TOO_LONG");
break;
case X509_V_ERR_CERT_REVOKED:
s = String::New("CERT_REVOKED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_REVOKED");
break;
case X509_V_ERR_INVALID_CA:
s = String::New("INVALID_CA");
s = FIXED_ONE_BYTE_STRING(node_isolate, "INVALID_CA");
break;
case X509_V_ERR_PATH_LENGTH_EXCEEDED:
s = String::New("PATH_LENGTH_EXCEEDED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "PATH_LENGTH_EXCEEDED");
break;
case X509_V_ERR_INVALID_PURPOSE:
s = String::New("INVALID_PURPOSE");
s = FIXED_ONE_BYTE_STRING(node_isolate, "INVALID_PURPOSE");
break;
case X509_V_ERR_CERT_UNTRUSTED:
s = String::New("CERT_UNTRUSTED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_UNTRUSTED");
break;
case X509_V_ERR_CERT_REJECTED:
s = String::New("CERT_REJECTED");
s = FIXED_ONE_BYTE_STRING(node_isolate, "CERT_REJECTED");
break;
default:
s = String::New(X509_verify_cert_error_string(x509_verify_error));
s = OneByteString(node_isolate,
X509_verify_cert_error_string(x509_verify_error));
break;
}
@ -1893,9 +1926,9 @@ void Connection::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
if (c == NULL) return;
Local<Object> info = Object::New();
const char* cipher_name = SSL_CIPHER_get_name(c);
info->Set(name_symbol, String::New(cipher_name));
info->Set(name_symbol, OneByteString(node_isolate, cipher_name));
const char* cipher_version = SSL_CIPHER_get_version(c);
info->Set(version_symbol, String::New(cipher_version));
info->Set(version_symbol, OneByteString(node_isolate, cipher_version));
args.GetReturnValue().Set(info);
}
@ -1929,7 +1962,7 @@ void Connection::GetNegotiatedProto(const FunctionCallbackInfo<Value>& args) {
}
args.GetReturnValue().Set(
String::New(reinterpret_cast<const char*>(npn_proto), npn_proto_len));
OneByteString(node_isolate, npn_proto, npn_proto_len));
} else {
args.GetReturnValue().Set(ss->selectedNPNProto_);
}
@ -1974,7 +2007,7 @@ void Connection::SetSNICallback(const FunctionCallbackInfo<Value>& args) {
}
Local<Object> obj = Object::New();
obj->Set(String::New("onselect"), args[0]);
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "onselect"), args[0]);
ss->sniObject_.Reset(node_isolate, obj);
}
#endif
@ -1993,7 +2026,8 @@ void CipherBase::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "final", Final);
NODE_SET_PROTOTYPE_METHOD(t, "setAutoPadding", SetAutoPadding);
target->Set(String::NewSymbol("CipherBase"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "CipherBase"),
t->GetFunction());
}
@ -2232,7 +2266,7 @@ void Hmac::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "update", HmacUpdate);
NODE_SET_PROTOTYPE_METHOD(t, "digest", HmacDigest);
target->Set(String::NewSymbol("Hmac"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Hmac"), t->GetFunction());
}
@ -2363,7 +2397,7 @@ void Hash::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "update", HashUpdate);
NODE_SET_PROTOTYPE_METHOD(t, "digest", HashDigest);
target->Set(String::NewSymbol("Hash"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Hash"), t->GetFunction());
}
@ -2473,7 +2507,7 @@ void Sign::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "update", SignUpdate);
NODE_SET_PROTOTYPE_METHOD(t, "sign", SignFinal);
target->Set(String::NewSymbol("Sign"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Sign"), t->GetFunction());
}
@ -2618,7 +2652,7 @@ void Verify::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "update", VerifyUpdate);
NODE_SET_PROTOTYPE_METHOD(t, "verify", VerifyFinal);
target->Set(String::NewSymbol("Verify"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Verify"), t->GetFunction());
}
@ -2826,7 +2860,8 @@ void DiffieHellman::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setPublicKey", SetPublicKey);
NODE_SET_PROTOTYPE_METHOD(t, "setPrivateKey", SetPrivateKey);
target->Set(String::NewSymbol("DiffieHellman"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "DiffieHellman"),
t->GetFunction());
Local<FunctionTemplate> t2 = FunctionTemplate::New(DiffieHellmanGroup);
t2->InstanceTemplate()->SetInternalFieldCount(1);
@ -2838,7 +2873,8 @@ void DiffieHellman::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(t2, "getPublicKey", GetPublicKey);
NODE_SET_PROTOTYPE_METHOD(t2, "getPrivateKey", GetPrivateKey);
target->Set(String::NewSymbol("DiffieHellmanGroup"), t2->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "DiffieHellmanGroup"),
t2->GetFunction());
}
@ -3201,7 +3237,8 @@ void EIO_PBKDF2After(pbkdf2_req* req, Local<Value> argv[2]) {
argv[1] = Encode(req->key, req->keylen, BUFFER);
memset(req->key, 0, req->keylen);
} else {
argv[0] = Exception::Error(String::New("PBKDF2 error"));
argv[0] = Exception::Error(
FIXED_ONE_BYTE_STRING(node_isolate, "PBKDF2 error"));
argv[1] = Undefined(node_isolate);
}
@ -3302,7 +3339,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
if (args[4]->IsFunction()) {
Local<Object> obj = Object::New();
obj->Set(String::New("ondone"), args[4]);
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "ondone"), args[4]);
req->obj.Reset(node_isolate, obj);
uv_queue_work(uv_default_loop(),
&req->work_req,
@ -3373,7 +3410,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
if (req->error_ != (unsigned long) -1)
ERR_error_string_n(req->error_, errmsg, sizeof errmsg);
argv[0] = Exception::Error(String::New(errmsg));
argv[0] = Exception::Error(OneByteString(node_isolate, errmsg));
argv[1] = Null(node_isolate);
} else {
argv[0] = Null(node_isolate);
@ -3417,7 +3454,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
if (args[1]->IsFunction()) {
Local<Object> obj = Object::New();
obj->Set(String::New("ondone"), args[1]);
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "ondone"), args[1]);
req->obj_.Reset(node_isolate, obj);
uv_queue_work(uv_default_loop(),
@ -3458,7 +3495,7 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
for (int i = 0; i < sk_SSL_CIPHER_num(ciphers); ++i) {
SSL_CIPHER* cipher = sk_SSL_CIPHER_value(ciphers, i);
arr->Set(i, String::New(SSL_CIPHER_get_name(cipher)));
arr->Set(i, OneByteString(node_isolate, SSL_CIPHER_get_name(cipher)));
}
SSL_free(ssl);
@ -3474,7 +3511,7 @@ static void array_push_back(const TypeName* md,
const char* to,
void* arg) {
Local<Array>& arr = *static_cast<Local<Array>*>(arg);
arr->Set(arr->Length(), String::New(from));
arr->Set(arr->Length(), OneByteString(node_isolate, from));
}
@ -3534,17 +3571,17 @@ void InitCrypto(Handle<Object> target) {
NODE_SET_METHOD(target, "getCiphers", GetCiphers);
NODE_SET_METHOD(target, "getHashes", GetHashes);
subject_symbol = String::New("subject");
issuer_symbol = String::New("issuer");
valid_from_symbol = String::New("valid_from");
valid_to_symbol = String::New("valid_to");
subjectaltname_symbol = String::New("subjectaltname");
modulus_symbol = String::New("modulus");
exponent_symbol = String::New("exponent");
fingerprint_symbol = String::New("fingerprint");
name_symbol = String::New("name");
version_symbol = String::New("version");
ext_key_usage_symbol = String::New("ext_key_usage");
subject_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "subject");
issuer_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "issuer");
valid_from_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "valid_from");
valid_to_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "valid_to");
subjectaltname_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "subjectaltname");
modulus_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "modulus");
exponent_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "exponent");
fingerprint_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "fingerprint");
name_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "name");
version_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "version");
ext_key_usage_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "ext_key_usage");
}
} // namespace crypto

12
src/node_dtrace.cc

@ -77,7 +77,7 @@ using v8::Value;
return ThrowError( \
"expected object for " #obj " to contain string member " #member); \
} \
String::Utf8Value _##member(obj->Get(String::New(#member))); \
String::Utf8Value _##member(obj->Get(OneByteString(node_isolate, #member))); \
if ((*(const char **)valp = *_##member) == NULL) \
*(const char **)valp = "<unknown>";
@ -86,14 +86,14 @@ using v8::Value;
return ThrowError( \
"expected object for " #obj " to contain integer member " #member); \
} \
*valp = obj->Get(String::New(#member))->ToInteger()->Value();
*valp = obj->Get(OneByteString(node_isolate, #member))->ToInteger()->Value();
#define SLURP_OBJECT(obj, member, valp) \
if (!(obj)->IsObject()) { \
return ThrowError( \
"expected object for " #obj " to contain object member " #member); \
} \
*valp = Local<Object>::Cast(obj->Get(String::New(#member)));
*valp = Local<Object>::Cast(obj->Get(OneByteString(node_isolate, #member)));
#define SLURP_CONNECTION(arg, conn) \
if (!(arg)->IsObject()) { \
@ -102,7 +102,7 @@ using v8::Value;
} \
node_dtrace_connection_t conn; \
Local<Object> _##conn = Local<Object>::Cast(arg); \
Local<Value> _handle = (_##conn)->Get(String::New("_handle")); \
Local<Value> _handle = (_##conn)->Get(FIXED_ONE_BYTE_STRING(node_isolate, "_handle")); \
if (_handle->IsObject()) { \
SLURP_INT(_handle.As<Object>(), fd, &conn.fd); \
} else { \
@ -221,7 +221,7 @@ void DTRACE_HTTP_SERVER_REQUEST(const FunctionCallbackInfo<Value>& args) {
"expected object for request to contain string member headers");
}
Local<Value> strfwdfor = headers->Get(String::New("x-forwarded-for"));
Local<Value> strfwdfor = headers->Get(FIXED_ONE_BYTE_STRING(node_isolate, "x-forwarded-for"));
String::Utf8Value fwdfor(strfwdfor);
if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == NULL)
@ -332,7 +332,7 @@ void InitDTrace(Handle<Object> target) {
};
for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
Local<String> key = String::New(tab[i].name);
Local<String> key = OneByteString(node_isolate, tab[i].name);
Local<Value> val = FunctionTemplate::New(tab[i].func)->GetFunction();
target->Set(key, val);
}

44
src/node_file.cc

@ -169,7 +169,8 @@ static void After(uv_fs_t *req) {
break;
case UV_FS_READLINK:
argv[1] = String::New(static_cast<char*>(req->ptr));
argv[1] = String::NewFromUtf8(node_isolate,
static_cast<const char*>(req->ptr));
break;
case UV_FS_READ:
@ -185,7 +186,7 @@ static void After(uv_fs_t *req) {
Local<Array> names = Array::New(nnames);
for (int i = 0; i < nnames; i++) {
Local<String> name = String::New(namebuf);
Local<String> name = String::NewFromUtf8(node_isolate, namebuf);
names->Set(Integer::New(i, node_isolate), name);
#ifndef NDEBUG
namebuf += strlen(namebuf);
@ -206,7 +207,7 @@ static void After(uv_fs_t *req) {
}
if (oncomplete_sym.IsEmpty()) {
oncomplete_sym = String::New("oncomplete");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
}
MakeCallback(req_wrap->object(), oncomplete_sym, argc, argv);
@ -290,19 +291,19 @@ Local<Object> BuildStatsObject(const uv_stat_t* s) {
HandleScope scope(node_isolate);
if (dev_symbol.IsEmpty()) {
dev_symbol = String::New("dev");
ino_symbol = String::New("ino");
mode_symbol = String::New("mode");
nlink_symbol = String::New("nlink");
uid_symbol = String::New("uid");
gid_symbol = String::New("gid");
rdev_symbol = String::New("rdev");
size_symbol = String::New("size");
blksize_symbol = String::New("blksize");
blocks_symbol = String::New("blocks");
atime_symbol = String::New("atime");
mtime_symbol = String::New("mtime");
ctime_symbol = String::New("ctime");
dev_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "dev");
ino_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "ino");
mode_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "mode");
nlink_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "nlink");
uid_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "uid");
gid_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "gid");
rdev_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "rdev");
size_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "size");
blksize_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "blksize");
blocks_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "blocks");
atime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "atime");
mtime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "mtime");
ctime_symbol = FIXED_ONE_BYTE_STRING(node_isolate, "ctime");
}
Local<Function> constructor =
@ -481,8 +482,9 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
ASYNC_CALL(readlink, args[1], *path)
} else {
SYNC_CALL(readlink, *path, *path)
args.GetReturnValue().Set(
String::New(static_cast<const char*>(SYNC_REQ.ptr)));
const char* link_path = static_cast<const char*>(SYNC_REQ.ptr);
Local<String> rc = String::NewFromUtf8(node_isolate, link_path);
args.GetReturnValue().Set(rc);
}
}
@ -621,7 +623,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
Local<Array> names = Array::New(nnames);
for (int i = 0; i < nnames; i++) {
Local<String> name = String::New(namebuf);
Local<String> name = String::NewFromUtf8(node_isolate, namebuf);
names->Set(Integer::New(i, node_isolate), name);
#ifndef NDEBUG
namebuf += strlen(namebuf);
@ -1005,12 +1007,12 @@ void InitFs(Handle<Object> target) {
// Initialize the stats object
Local<Function> constructor = FunctionTemplate::New()->GetFunction();
target->Set(String::NewSymbol("Stats"), constructor);
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Stats"), constructor);
stats_constructor.Reset(node_isolate, constructor);
File::Initialize(target);
oncomplete_sym = String::New("oncomplete");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
StatWatcher::Initialize(target);
}

66
src/node_http_parser.cc

@ -179,7 +179,7 @@ struct StringPtr {
Local<String> ToString() const {
if (str_)
return String::New(str_, size_);
return OneByteString(node_isolate, str_, size_);
else
return String::Empty(node_isolate);
}
@ -433,10 +433,12 @@ class Parser : public ObjectWrap {
if (!parser->parser_.upgrade && nparsed != buffer_len) {
enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_);
Local<Value> e = Exception::Error(String::NewSymbol("Parse Error"));
Local<Value> e = Exception::Error(
FIXED_ONE_BYTE_STRING(node_isolate, "Parse Error"));
Local<Object> obj = e->ToObject();
obj->Set(String::NewSymbol("bytesParsed"), nparsed_obj);
obj->Set(String::NewSymbol("code"), String::New(http_errno_name(err)));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "bytesParsed"), nparsed_obj);
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "code"),
OneByteString(node_isolate, http_errno_name(err)));
args.GetReturnValue().Set(e);
} else {
args.GetReturnValue().Set(nparsed_obj);
@ -459,10 +461,13 @@ class Parser : public ObjectWrap {
if (rv != 0) {
enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_);
Local<Value> e = Exception::Error(String::NewSymbol("Parse Error"));
Local<Value> e = Exception::Error(
FIXED_ONE_BYTE_STRING(node_isolate, "Parse Error"));
Local<Object> obj = e->ToObject();
obj->Set(String::NewSymbol("bytesParsed"), Integer::New(0, node_isolate));
obj->Set(String::NewSymbol("code"), String::New(http_errno_name(err)));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "bytesParsed"),
Integer::New(0, node_isolate));
obj->Set(FIXED_ONE_BYTE_STRING(node_isolate, "code"),
OneByteString(node_isolate, http_errno_name(err)));
args.GetReturnValue().Set(e);
}
}
@ -547,38 +552,45 @@ void InitHttpParser(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(Parser::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("HTTPParser"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "HTTPParser"));
t->Set(String::NewSymbol("REQUEST"),
t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "REQUEST"),
Integer::New(HTTP_REQUEST, node_isolate));
t->Set(String::NewSymbol("RESPONSE"),
t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "RESPONSE"),
Integer::New(HTTP_RESPONSE, node_isolate));
NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute);
NODE_SET_PROTOTYPE_METHOD(t, "finish", Parser::Finish);
NODE_SET_PROTOTYPE_METHOD(t, "reinitialize", Parser::Reinitialize);
target->Set(String::NewSymbol("HTTPParser"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "HTTPParser"),
t->GetFunction());
on_headers_sym = String::New("onHeaders");
on_headers_complete_sym = String::New("onHeadersComplete");
on_body_sym = String::New("onBody");
on_message_complete_sym = String::New("onMessageComplete");
on_headers_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onHeaders");
on_headers_complete_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onHeadersComplete");
on_body_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onBody");
on_message_complete_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onMessageComplete");
#define X(num, name, string) name##_sym = String::New(#string);
#define X(num, name, string) \
name ## _sym = OneByteString(node_isolate, #string);
HTTP_METHOD_MAP(X)
#undef X
unknown_method_sym = String::New("UNKNOWN_METHOD");
method_sym = String::New("method");
status_code_sym = String::New("statusCode");
http_version_sym = String::New("httpVersion");
version_major_sym = String::New("versionMajor");
version_minor_sym = String::New("versionMinor");
should_keep_alive_sym = String::New("shouldKeepAlive");
upgrade_sym = String::New("upgrade");
headers_sym = String::New("headers");
url_sym = String::New("url");
unknown_method_sym = FIXED_ONE_BYTE_STRING(node_isolate, "UNKNOWN_METHOD");
method_sym = FIXED_ONE_BYTE_STRING(node_isolate, "method");
status_code_sym = FIXED_ONE_BYTE_STRING(node_isolate, "statusCode");
http_version_sym = FIXED_ONE_BYTE_STRING(node_isolate, "httpVersion");
version_major_sym = FIXED_ONE_BYTE_STRING(node_isolate, "versionMajor");
version_minor_sym = FIXED_ONE_BYTE_STRING(node_isolate, "versionMinor");
should_keep_alive_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "shouldKeepAlive");
upgrade_sym = FIXED_ONE_BYTE_STRING(node_isolate, "upgrade");
headers_sym = FIXED_ONE_BYTE_STRING(node_isolate, "headers");
url_sym = FIXED_ONE_BYTE_STRING(node_isolate, "url");
settings.on_message_begin = Parser::on_message_begin;
settings.on_url = Parser::on_url;

47
src/node_internals.h

@ -25,8 +25,12 @@
#include "v8.h"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#define FIXED_ONE_BYTE_STRING(isolate, string) \
(node::OneByteString((isolate), (string), sizeof(string) - 1))
struct sockaddr;
namespace node {
@ -95,6 +99,20 @@ inline v8::Local<v8::Object> NewInstance(
int argc = 0,
v8::Handle<v8::Value>* argv = NULL);
// Convenience wrapper around v8::String::NewFromOneByte().
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const char* data,
int length = -1);
// For the people that compile with -funsigned-char.
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const signed char* data,
int length = -1);
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const unsigned char* data,
int length = -1);
// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
// Sets address and port properties on the info object and returns it.
// If |info| is omitted, a new object is returned.
@ -157,7 +175,7 @@ inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) {
#define THROW_ERROR(fun) \
do { \
v8::HandleScope scope(node_isolate); \
v8::ThrowException(fun(v8::String::New(errmsg))); \
v8::ThrowException(fun(OneByteString(node_isolate, errmsg))); \
} \
while (0)
@ -333,6 +351,33 @@ inline v8::Local<v8::Object> NewInstance(
return constructor_handle->NewInstance(argc, argv);
}
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::String::kNormalString,
length);
}
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const signed char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::String::kNormalString,
length);
}
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const unsigned char* data,
int length) {
return v8::String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
v8::String::kNormalString,
length);
}
} // namespace node
#endif // SRC_NODE_INTERNALS_H_

10
src/node_javascript.cc

@ -37,7 +37,7 @@ using v8::Object;
using v8::String;
Handle<String> MainSource() {
return String::New(node_native, sizeof(node_native) - 1);
return OneByteString(node_isolate, node_native, sizeof(node_native) - 1);
}
void DefineJavaScript(Handle<Object> target) {
@ -45,9 +45,11 @@ void DefineJavaScript(Handle<Object> target) {
for (int i = 0; natives[i].name; i++) {
if (natives[i].source != node_native) {
Local<String> name = String::New(natives[i].name);
Handle<String> source = String::New(natives[i].source,
natives[i].source_len);
Local<String> name = String::NewFromUtf8(node_isolate, natives[i].name);
Handle<String> source = String::NewFromUtf8(node_isolate,
natives[i].source,
String::kNormalString,
natives[i].source_len);
target->Set(name, source);
}
}

47
src/node_os.cc

@ -59,7 +59,7 @@ using v8::Value;
static void GetEndianness(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
const char* rval = IsBigEndian() ? "BE" : "LE";
args.GetReturnValue().Set(String::New(rval));
args.GetReturnValue().Set(OneByteString(node_isolate, rval));
}
@ -77,7 +77,7 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) {
}
buf[sizeof(buf) - 1] = '\0';
args.GetReturnValue().Set(String::New(buf));
args.GetReturnValue().Set(OneByteString(node_isolate, buf));
}
@ -95,7 +95,7 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
rval ="Windows_NT";
#endif // __POSIX__
args.GetReturnValue().Set(String::New(rval));
args.GetReturnValue().Set(OneByteString(node_isolate, rval));
}
@ -125,7 +125,7 @@ static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
rval = release;
#endif // __POSIX__
args.GetReturnValue().Set(String::New(rval));
args.GetReturnValue().Set(OneByteString(node_isolate, rval));
}
@ -142,21 +142,23 @@ static void GetCPUInfo(const FunctionCallbackInfo<Value>& args) {
uv_cpu_info_t* ci = cpu_infos + i;
Local<Object> times_info = Object::New();
times_info->Set(String::New("user"),
times_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "user"),
Number::New(node_isolate, ci->cpu_times.user));
times_info->Set(String::New("nice"),
times_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "nice"),
Number::New(node_isolate, ci->cpu_times.nice));
times_info->Set(String::New("sys"),
times_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "sys"),
Number::New(node_isolate, ci->cpu_times.sys));
times_info->Set(String::New("idle"),
times_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "idle"),
Number::New(node_isolate, ci->cpu_times.idle));
times_info->Set(String::New("irq"),
times_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "irq"),
Number::New(node_isolate, ci->cpu_times.irq));
Local<Object> cpu_info = Object::New();
cpu_info->Set(String::New("model"), String::New(ci->model));
cpu_info->Set(String::New("speed"), Number::New(node_isolate, ci->speed));
cpu_info->Set(String::New("times"), times_info);
cpu_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "model"),
OneByteString(node_isolate, ci->model));
cpu_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "speed"),
Number::New(node_isolate, ci->speed));
cpu_info->Set(FIXED_ONE_BYTE_STRING(node_isolate, "times"), times_info);
(*cpus)->Set(i, cpu_info);
}
@ -221,7 +223,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
ret = Object::New();
for (i = 0; i < count; i++) {
name = String::New(interfaces[i].name);
name = OneByteString(node_isolate, interfaces[i].name);
if (ret->Has(name)) {
ifarr = Local<Array>::Cast(ret->Get(name));
} else {
@ -242,24 +244,27 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
if (interfaces[i].address.address4.sin_family == AF_INET) {
uv_ip4_name(&interfaces[i].address.address4, ip, sizeof(ip));
uv_ip4_name(&interfaces[i].netmask.netmask4, netmask, sizeof(netmask));
family = String::New("IPv4");
family = FIXED_ONE_BYTE_STRING(node_isolate, "IPv4");
} else if (interfaces[i].address.address4.sin_family == AF_INET6) {
uv_ip6_name(&interfaces[i].address.address6, ip, sizeof(ip));
uv_ip6_name(&interfaces[i].netmask.netmask6, netmask, sizeof(netmask));
family = String::New("IPv6");
family = FIXED_ONE_BYTE_STRING(node_isolate, "IPv6");
} else {
strncpy(ip, "<unknown sa family>", INET6_ADDRSTRLEN);
family = String::New("<unknown>");
family = FIXED_ONE_BYTE_STRING(node_isolate, "<unknown>");
}
o = Object::New();
o->Set(String::New("address"), String::New(ip));
o->Set(String::New("netmask"), String::New(netmask));
o->Set(String::New("family"), family);
o->Set(String::New("mac"), String::New(mac));
o->Set(FIXED_ONE_BYTE_STRING(node_isolate, "address"),
OneByteString(node_isolate, ip));
o->Set(FIXED_ONE_BYTE_STRING(node_isolate, "netmask"),
OneByteString(node_isolate, netmask));
o->Set(FIXED_ONE_BYTE_STRING(node_isolate, "family"), family);
o->Set(FIXED_ONE_BYTE_STRING(node_isolate, "mac"),
FIXED_ONE_BYTE_STRING(node_isolate, mac));
const bool internal = interfaces[i].is_internal;
o->Set(String::New("internal"),
o->Set(FIXED_ONE_BYTE_STRING(node_isolate, "internal"),
internal ? True(node_isolate) : False(node_isolate));
ifarr->Set(ifarr->Length(), o);

25
src/node_script.cc

@ -118,9 +118,10 @@ void CloneObject(Handle<Object> recv,
"}); \n";
Local<String> script_source =
String::New(raw_script_source, sizeof(raw_script_source) - 1);
Local<Script> script =
Script::Compile(script_source, String::New("binding:script"));
FIXED_ONE_BYTE_STRING(node_isolate, raw_script_source);
Local<String> script_name =
FIXED_ONE_BYTE_STRING(node_isolate, "binding:script");
Local<Script> script = Script::Compile(script_source, script_name);
Local<Function> fun = script->Run().As<Function>();
assert(fun.IsEmpty() == false);
@ -137,9 +138,9 @@ void WrappedContext::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(WrappedContext::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("Context"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Context"));
target->Set(String::NewSymbol("Context"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Context"), t->GetFunction());
constructor_template.Reset(node_isolate, t);
}
@ -186,7 +187,7 @@ void WrappedScript::Initialize(Handle<Object> target) {
// Note: We use 'NodeScript' instead of 'Script' so that we do not
// conflict with V8's Script class defined in v8/src/messages.js
// See GH-203 https://github.com/joyent/node/issues/203
t->SetClassName(String::NewSymbol("NodeScript"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "NodeScript"));
NODE_SET_PROTOTYPE_METHOD(t,
"createContext",
@ -220,7 +221,8 @@ void WrappedScript::Initialize(Handle<Object> target) {
"runInNewContext",
WrappedScript::CompileRunInNewContext);
target->Set(String::NewSymbol("NodeScript"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "NodeScript"),
t->GetFunction());
}
@ -328,9 +330,12 @@ void WrappedScript::EvalMachine(const FunctionCallbackInfo<Value>& args) {
const int filename_index = sandbox_index +
(context_flag == thisContext? 0 : 1);
Local<String> filename = args.Length() > filename_index
? args[filename_index]->ToString()
: String::New("evalmachine.<anonymous>");
Local<String> filename;
if (args.Length() > filename_index) {
filename = args[filename_index]->ToString();
} else {
filename = FIXED_ONE_BYTE_STRING(node_isolate, "evalmachine.<anonymous>");
}
uint64_t timeout = 0;
const int timeout_index = filename_index + 1;

9
src/node_stat_watcher.cc

@ -46,12 +46,13 @@ void StatWatcher::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("StatWatcher"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "StatWatcher"));
NODE_SET_PROTOTYPE_METHOD(t, "start", StatWatcher::Start);
NODE_SET_PROTOTYPE_METHOD(t, "stop", StatWatcher::Stop);
target->Set(String::NewSymbol("StatWatcher"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "StatWatcher"),
t->GetFunction());
}
@ -85,7 +86,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
argv[1] = BuildStatsObject(prev);
argv[2] = Integer::New(status, node_isolate);
if (onchange_sym.IsEmpty()) {
onchange_sym = String::New("onchange");
onchange_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onchange");
}
MakeCallback(wrap->handle(node_isolate),
onchange_sym,
@ -121,7 +122,7 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.This());
if (onstop_sym.IsEmpty()) {
onstop_sym = String::New("onstop");
onstop_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onstop");
}
MakeCallback(wrap->handle(node_isolate), onstop_sym, 0, NULL);
wrap->Stop();

13
src/node_zlib.cc

@ -294,7 +294,7 @@ class ZCtx : public ObjectWrap {
assert(handle->Get(onerror_sym)->IsFunction() && "Invalid error handler");
HandleScope scope(node_isolate);
Local<Value> args[2] = {
String::New(msg),
OneByteString(node_isolate, msg),
Number::New(ctx->err_)
};
MakeCallback(handle, onerror_sym, ARRAY_SIZE(args), args);
@ -543,11 +543,11 @@ void InitZlib(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(z, "params", ZCtx::Params);
NODE_SET_PROTOTYPE_METHOD(z, "reset", ZCtx::Reset);
z->SetClassName(String::NewSymbol("Zlib"));
target->Set(String::NewSymbol("Zlib"), z->GetFunction());
z->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Zlib"));
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Zlib"), z->GetFunction());
callback_sym = String::New("callback");
onerror_sym = String::New("onerror");
callback_sym = FIXED_ONE_BYTE_STRING(node_isolate, "callback");
onerror_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onerror");
// valid flush values.
NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH);
@ -587,7 +587,8 @@ void InitZlib(Handle<Object> target) {
NODE_DEFINE_CONSTANT(target, INFLATERAW);
NODE_DEFINE_CONSTANT(target, UNZIP);
target->Set(String::NewSymbol("ZLIB_VERSION"), String::New(ZLIB_VERSION));
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "ZLIB_VERSION"),
FIXED_ONE_BYTE_STRING(node_isolate, ZLIB_VERSION));
}
} // namespace node

10
src/pipe_wrap.cc

@ -78,13 +78,13 @@ void PipeWrap::Initialize(Handle<Object> target) {
HandleScope scope(node_isolate);
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->SetClassName(String::NewSymbol("Pipe"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Pipe"));
t->InstanceTemplate()->SetInternalFieldCount(1);
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
t->InstanceTemplate()->SetAccessor(String::New("fd"),
t->InstanceTemplate()->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "fd"),
StreamWrap::GetFD,
NULL,
Handle<Value>(),
@ -117,7 +117,7 @@ void PipeWrap::Initialize(Handle<Object> target) {
pipeConstructorTmpl.Reset(node_isolate, t);
pipeConstructor.Reset(node_isolate, t->GetFunction());
target->Set(String::NewSymbol("Pipe"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Pipe"), t->GetFunction());
}
@ -214,7 +214,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
// Successful accept. Call the onconnection callback in JavaScript land.
argv[1] = client_obj;
if (onconnection_sym.IsEmpty()) {
onconnection_sym = String::New("onconnection");
onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection");
}
MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
}
@ -249,7 +249,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
};
if (oncomplete_sym.IsEmpty()) {
oncomplete_sym = String::New("oncomplete");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
}
MakeCallback(req_wrap_obj, oncomplete_sym, ARRAY_SIZE(argv), argv);

71
src/process_wrap.cc

@ -50,7 +50,7 @@ class ProcessWrap : public HandleWrap {
Local<FunctionTemplate> constructor = FunctionTemplate::New(New);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Process"));
constructor->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Process"));
NODE_SET_PROTOTYPE_METHOD(constructor, "close", HandleWrap::Close);
@ -60,7 +60,8 @@ class ProcessWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(constructor, "unref", HandleWrap::Unref);
target->Set(String::NewSymbol("Process"), constructor->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Process"),
constructor->GetFunction());
}
private:
@ -82,34 +83,41 @@ class ProcessWrap : public HandleWrap {
static void ParseStdioOptions(Local<Object> js_options,
uv_process_options_t* options) {
Local<Array> stdios = js_options
->Get(String::NewSymbol("stdio")).As<Array>();
Local<String> stdio_key =
FIXED_ONE_BYTE_STRING(node_isolate, "stdio");
Local<Array> stdios = js_options->Get(stdio_key).As<Array>();
uint32_t len = stdios->Length();
options->stdio = new uv_stdio_container_t[len];
options->stdio_count = len;
for (uint32_t i = 0; i < len; i++) {
Local<Object> stdio = stdios->Get(i).As<Object>();
Local<Value> type = stdio->Get(String::NewSymbol("type"));
Local<Value> type =
stdio->Get(FIXED_ONE_BYTE_STRING(node_isolate, "type"));
if (type->Equals(String::NewSymbol("ignore"))) {
if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "ignore"))) {
options->stdio[i].flags = UV_IGNORE;
} else if (type->Equals(String::NewSymbol("pipe"))) {
} else if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "pipe"))) {
options->stdio[i].flags = static_cast<uv_stdio_flags>(
UV_CREATE_PIPE | UV_READABLE_PIPE | UV_WRITABLE_PIPE);
options->stdio[i].data.stream = reinterpret_cast<uv_stream_t*>(
PipeWrap::Unwrap(stdio
->Get(String::NewSymbol("handle")).As<Object>())->UVHandle());
} else if (type->Equals(String::NewSymbol("wrap"))) {
uv_stream_t* stream = HandleToStream(
stdio->Get(String::NewSymbol("handle")).As<Object>());
Local<String> handle_key =
FIXED_ONE_BYTE_STRING(node_isolate, "handle");
Local<Object> handle = stdio->Get(handle_key).As<Object>();
options->stdio[i].data.stream =
reinterpret_cast<uv_stream_t*>(
PipeWrap::Unwrap(handle)->UVHandle());
} else if (type->Equals(FIXED_ONE_BYTE_STRING(node_isolate, "wrap"))) {
Local<String> handle_key =
FIXED_ONE_BYTE_STRING(node_isolate, "handle");
Local<Object> handle = stdio->Get(handle_key).As<Object>();
uv_stream_t* stream = HandleToStream(handle);
assert(stream != NULL);
options->stdio[i].flags = UV_INHERIT_STREAM;
options->stdio[i].data.stream = stream;
} else {
int fd = static_cast<int>(
stdio->Get(String::NewSymbol("fd"))->IntegerValue());
Local<String> fd_key = FIXED_ONE_BYTE_STRING(node_isolate, "fd");
int fd = static_cast<int>(stdio->Get(fd_key)->IntegerValue());
options->stdio[i].flags = UV_INHERIT_FD;
options->stdio[i].data.fd = fd;
@ -130,7 +138,8 @@ class ProcessWrap : public HandleWrap {
options.exit_cb = OnExit;
// options.uid
Local<Value> uid_v = js_options->Get(String::NewSymbol("uid"));
Local<Value> uid_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "uid"));
if (uid_v->IsInt32()) {
int32_t uid = uid_v->Int32Value();
if (uid & ~((uv_uid_t) ~0)) {
@ -143,7 +152,8 @@ class ProcessWrap : public HandleWrap {
}
// options.gid
Local<Value> gid_v = js_options->Get(String::NewSymbol("gid"));
Local<Value> gid_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "gid"));
if (gid_v->IsInt32()) {
int32_t gid = gid_v->Int32Value();
if (gid & ~((uv_gid_t) ~0)) {
@ -158,7 +168,8 @@ class ProcessWrap : public HandleWrap {
// TODO(bnoordhuis) is this possible to do without mallocing ?
// options.file
Local<Value> file_v = js_options->Get(String::NewSymbol("file"));
Local<Value> file_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "file"));
String::Utf8Value file(file_v->IsString() ? file_v : Local<Value>());
if (file.length() > 0) {
options.file = *file;
@ -167,7 +178,8 @@ class ProcessWrap : public HandleWrap {
}
// options.args
Local<Value> argv_v = js_options->Get(String::NewSymbol("args"));
Local<Value> argv_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "args"));
if (!argv_v.IsEmpty() && argv_v->IsArray()) {
Local<Array> js_argv = Local<Array>::Cast(argv_v);
int argc = js_argv->Length();
@ -181,14 +193,16 @@ class ProcessWrap : public HandleWrap {
}
// options.cwd
Local<Value> cwd_v = js_options->Get(String::NewSymbol("cwd"));
Local<Value> cwd_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "cwd"));
String::Utf8Value cwd(cwd_v->IsString() ? cwd_v : Local<Value>());
if (cwd.length() > 0) {
options.cwd = *cwd;
}
// options.env
Local<Value> env_v = js_options->Get(String::NewSymbol("envPairs"));
Local<Value> env_v =
js_options->Get(FIXED_ONE_BYTE_STRING(node_isolate, "envPairs"));
if (!env_v.IsEmpty() && env_v->IsArray()) {
Local<Array> env = Local<Array>::Cast(env_v);
int envc = env->Length();
@ -204,13 +218,16 @@ class ProcessWrap : public HandleWrap {
ParseStdioOptions(js_options, &options);
// options.windows_verbatim_arguments
if (js_options->Get(String::NewSymbol("windowsVerbatimArguments"))->
IsTrue()) {
Local<String> windows_verbatim_arguments_key =
FIXED_ONE_BYTE_STRING(node_isolate, "windowsVerbatimArguments");
if (js_options->Get(windows_verbatim_arguments_key)->IsTrue()) {
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
}
// options.detached
if (js_options->Get(String::NewSymbol("detached"))->IsTrue()) {
Local<String> detached_key =
FIXED_ONE_BYTE_STRING(node_isolate, "detached");
if (js_options->Get(detached_key)->IsTrue()) {
options.flags |= UV_PROCESS_DETACHED;
}
@ -218,7 +235,7 @@ class ProcessWrap : public HandleWrap {
if (err == 0) {
assert(wrap->process_.data == wrap);
wrap->object()->Set(String::New("pid"),
wrap->object()->Set(FIXED_ONE_BYTE_STRING(node_isolate, "pid"),
Integer::New(wrap->process_.pid, node_isolate));
}
@ -255,11 +272,11 @@ class ProcessWrap : public HandleWrap {
Local<Value> argv[] = {
Integer::New(exit_status, node_isolate),
String::New(signo_string(term_signal))
OneByteString(node_isolate, signo_string(term_signal))
};
if (onexit_sym.IsEmpty()) {
onexit_sym = String::New("onexit");
onexit_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onexit");
}
MakeCallback(wrap->object(), onexit_sym, ARRAY_SIZE(argv), argv);

7
src/signal_wrap.cc

@ -46,7 +46,7 @@ class SignalWrap : public HandleWrap {
Local<FunctionTemplate> constructor = FunctionTemplate::New(New);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Signal"));
constructor->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Signal"));
NODE_SET_PROTOTYPE_METHOD(constructor, "close", HandleWrap::Close);
NODE_SET_PROTOTYPE_METHOD(constructor, "ref", HandleWrap::Ref);
@ -54,9 +54,10 @@ class SignalWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "start", Start);
NODE_SET_PROTOTYPE_METHOD(constructor, "stop", Stop);
onsignal_sym = String::New("onsignal");
onsignal_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onsignal");
target->Set(String::NewSymbol("Signal"), constructor->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Signal"),
constructor->GetFunction());
}
private:

4
src/smalloc.cc

@ -359,7 +359,7 @@ void Alloc(Handle<Object> obj,
assert(!obj->HasIndexedPropertiesInExternalArrayData());
if (smalloc_sym.IsEmpty()) {
smalloc_sym = String::New("_smalloc_p");
smalloc_sym = FIXED_ONE_BYTE_STRING(node_isolate, "_smalloc_p");
using_alloc_cb = true;
}
@ -466,7 +466,7 @@ void Initialize(Handle<Object> exports) {
NODE_SET_METHOD(exports, "alloc", Alloc);
NODE_SET_METHOD(exports, "dispose", AllocDispose);
exports->Set(String::New("kMaxLength"),
exports->Set(FIXED_ONE_BYTE_STRING(node_isolate, "kMaxLength"),
Uint32::NewFromUnsigned(kMaxLength, node_isolate));
// for performance, begin checking if allocation object may contain

12
src/stream_wrap.cc

@ -63,11 +63,11 @@ void StreamWrap::Initialize(Handle<Object> target) {
initialized = true;
HandleScope scope(node_isolate);
buffer_sym = String::New("buffer");
bytes_sym = String::New("bytes");
write_queue_size_sym = String::New("writeQueueSize");
onread_sym = String::New("onread");
oncomplete_sym = String::New("oncomplete");
buffer_sym = FIXED_ONE_BYTE_STRING(node_isolate, "buffer");
bytes_sym = FIXED_ONE_BYTE_STRING(node_isolate, "bytes");
write_queue_size_sym = FIXED_ONE_BYTE_STRING(node_isolate, "writeQueueSize");
onread_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onread");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
}
@ -299,7 +299,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
// Reference StreamWrap instance to prevent it from being garbage
// collected before `AfterWrite` is called.
if (handle_sym.IsEmpty()) {
handle_sym = String::New("handle");
handle_sym = FIXED_ONE_BYTE_STRING(node_isolate, "handle");
}
assert(!req_wrap->persistent().IsEmpty());
req_wrap->object()->Set(handle_sym, send_handle_obj);

25
src/string_bytes.cc

@ -645,20 +645,14 @@ Local<Value> StringBytes::Encode(const char* buf,
char* out = new char[buflen];
force_ascii(buf, out, buflen);
if (buflen < EXTERN_APEX) {
val = String::NewFromOneByte(node_isolate,
reinterpret_cast<const uint8_t*>(out),
String::kNormalString,
buflen);
val = OneByteString(node_isolate, out, buflen);
delete[] out;
} else {
val = ExternOneByteString::New(out, buflen);
}
} else {
if (buflen < EXTERN_APEX)
val = String::NewFromOneByte(node_isolate,
reinterpret_cast<const uint8_t*>(buf),
String::kNormalString,
buflen);
val = OneByteString(node_isolate, buf, buflen);
else
val = ExternOneByteString::NewFromCopy(buf, buflen);
}
@ -673,10 +667,7 @@ Local<Value> StringBytes::Encode(const char* buf,
case BINARY:
if (buflen < EXTERN_APEX)
val = String::NewFromOneByte(node_isolate,
reinterpret_cast<const uint8_t*>(buf),
String::kNormalString,
buflen);
val = OneByteString(node_isolate, buf, buflen);
else
val = ExternOneByteString::NewFromCopy(buf, buflen);
break;
@ -689,10 +680,7 @@ Local<Value> StringBytes::Encode(const char* buf,
assert(written == dlen);
if (dlen < EXTERN_APEX) {
val = String::NewFromOneByte(node_isolate,
reinterpret_cast<const uint8_t*>(dst),
String::kNormalString,
dlen);
val = OneByteString(node_isolate, dst, dlen);
delete[] dst;
} else {
val = ExternOneByteString::New(dst, dlen);
@ -719,10 +707,7 @@ Local<Value> StringBytes::Encode(const char* buf,
assert(written == dlen);
if (dlen < EXTERN_APEX) {
val = String::NewFromOneByte(node_isolate,
reinterpret_cast<const uint8_t*>(dst),
String::kNormalString,
dlen);
val = OneByteString(node_isolate, dst, dlen);
delete[] dst;
} else {
val = ExternOneByteString::New(dst, dlen);

24
src/tcp_wrap.cc

@ -72,13 +72,13 @@ void TCPWrap::Initialize(Handle<Object> target) {
HandleScope scope(node_isolate);
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->SetClassName(String::NewSymbol("TCP"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "TCP"));
t->InstanceTemplate()->SetInternalFieldCount(1);
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
t->InstanceTemplate()->SetAccessor(String::New("fd"),
t->InstanceTemplate()->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "fd"),
StreamWrap::GetFD,
NULL,
Handle<Value>(),
@ -119,12 +119,12 @@ void TCPWrap::Initialize(Handle<Object> target) {
SetSimultaneousAccepts);
#endif
onconnection_sym = String::New("onconnection");
oncomplete_sym = String::New("oncomplete");
onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
tcpConstructorTmpl.Reset(node_isolate, t);
tcpConstructor.Reset(node_isolate, t->GetFunction());
target->Set(String::NewSymbol("TCP"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "TCP"), t->GetFunction());
}
@ -431,11 +431,11 @@ Local<Object> AddressToJS(const sockaddr* addr, Handle<Object> info) {
int port;
if (address_sym.IsEmpty()) {
address_sym = String::New("address");
family_sym = String::New("family");
port_sym = String::New("port");
ipv4_sym = String::New("IPv4");
ipv6_sym = String::New("IPv6");
address_sym = FIXED_ONE_BYTE_STRING(node_isolate, "address");
family_sym = FIXED_ONE_BYTE_STRING(node_isolate, "family");
port_sym = FIXED_ONE_BYTE_STRING(node_isolate, "port");
ipv4_sym = FIXED_ONE_BYTE_STRING(node_isolate, "IPv4");
ipv6_sym = FIXED_ONE_BYTE_STRING(node_isolate, "IPv6");
}
if (info.IsEmpty()) info = Object::New();
@ -445,7 +445,7 @@ Local<Object> AddressToJS(const sockaddr* addr, Handle<Object> info) {
a6 = reinterpret_cast<const sockaddr_in6*>(addr);
uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
port = ntohs(a6->sin6_port);
info->Set(address_sym, String::New(ip));
info->Set(address_sym, OneByteString(node_isolate, ip));
info->Set(family_sym, ipv6_sym);
info->Set(port_sym, Integer::New(port, node_isolate));
break;
@ -454,7 +454,7 @@ Local<Object> AddressToJS(const sockaddr* addr, Handle<Object> info) {
a4 = reinterpret_cast<const sockaddr_in*>(addr);
uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip);
port = ntohs(a4->sin_port);
info->Set(address_sym, String::New(ip));
info->Set(address_sym, OneByteString(node_isolate, ip));
info->Set(family_sym, ipv4_sym);
info->Set(port_sym, Integer::New(port, node_isolate));
break;

7
src/timer_wrap.cc

@ -44,7 +44,7 @@ class TimerWrap : public HandleWrap {
Local<FunctionTemplate> constructor = FunctionTemplate::New(New);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Timer"));
constructor->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Timer"));
NODE_SET_METHOD(constructor, "now", Now);
@ -58,9 +58,10 @@ class TimerWrap : public HandleWrap {
NODE_SET_PROTOTYPE_METHOD(constructor, "getRepeat", GetRepeat);
NODE_SET_PROTOTYPE_METHOD(constructor, "again", Again);
ontimeout_sym = String::New("ontimeout");
ontimeout_sym = FIXED_ONE_BYTE_STRING(node_isolate, "ontimeout");
target->Set(String::NewSymbol("Timer"), constructor->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Timer"),
constructor->GetFunction());
}
private:

110
src/tls_wrap.cc

@ -420,7 +420,7 @@ void TLSCallbacks::EncOutCb(uv_write_t* req, int status) {
// Notify about error
Local<Value> arg = String::Concat(
String::New("write cb error, status: "),
FIXED_ONE_BYTE_STRING(node_isolate, "write cb error, status: "),
Integer::New(status, node_isolate)->ToString());
MakeCallback(callbacks->object(), onerror_sym, 1, &arg);
callbacks->InvokeQueued(status);
@ -446,7 +446,7 @@ Handle<Value> TLSCallbacks::GetSSLError(int status, int* err) {
case SSL_ERROR_WANT_WRITE:
break;
case SSL_ERROR_ZERO_RETURN:
return scope.Close(String::NewSymbol("ZERO_RETURN"));
return scope.Close(FIXED_ONE_BYTE_STRING(node_isolate, "ZERO_RETURN"));
break;
default:
{
@ -459,10 +459,12 @@ Handle<Value> TLSCallbacks::GetSSLError(int status, int* err) {
assert(bio != NULL);
ERR_print_errors(bio);
BIO_get_mem_ptr(bio, &mem);
Handle<Value> r = Exception::Error(String::New(mem->data, mem->length));
Local<String> message =
OneByteString(node_isolate, mem->data, mem->length);
Local<Value> exception = Exception::Error(message);
BIO_free_all(bio);
return scope.Close(r);
return scope.Close(exception);
}
}
return Handle<Value>();
@ -672,7 +674,8 @@ void TLSCallbacks::VerifyError(const FunctionCallbackInfo<Value>& args) {
// We requested a certificate and they did not send us one.
// Definitely an error.
// XXX is this the right error message?
Local<String> s = String::New("UNABLE_TO_GET_ISSUER_CERT");
Local<String> s =
FIXED_ONE_BYTE_STRING(node_isolate, "UNABLE_TO_GET_ISSUER_CERT");
return args.GetReturnValue().Set(Exception::Error(s));
}
X509_free(peer_cert);
@ -712,12 +715,13 @@ void TLSCallbacks::VerifyError(const FunctionCallbackInfo<Value>& args) {
CASE_X509_ERR(CERT_UNTRUSTED)
CASE_X509_ERR(CERT_REJECTED)
default:
s = String::New(X509_verify_cert_error_string(x509_verify_error));
s = OneByteString(node_isolate,
X509_verify_cert_error_string(x509_verify_error));
break;
}
if (s.IsEmpty()) {
s = String::New(reason);
s = OneByteString(node_isolate, reason);
}
args.GetReturnValue().Set(Exception::Error(s));
@ -797,9 +801,9 @@ void TLSCallbacks::OnClientHello(void* arg,
if (hello.servername() == NULL) {
hello_obj->Set(servername_sym, String::Empty(node_isolate));
} else {
Local<String> servername = String::New(
reinterpret_cast<const char*>(hello.servername()),
hello.servername_size());
Local<String> servername = OneByteString(node_isolate,
hello.servername(),
hello.servername_size());
hello_obj->Set(servername_sym, servername);
}
hello_obj->Set(tls_ticket_sym, Boolean::New(hello.has_ticket()));
@ -830,7 +834,8 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
0,
X509_NAME_FLAGS) > 0) {
BIO_get_mem_ptr(bio, &mem);
info->Set(subject_sym, String::New(mem->data, mem->length));
info->Set(subject_sym,
OneByteString(node_isolate, mem->data, mem->length));
}
(void) BIO_reset(bio);
@ -839,7 +844,8 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
0,
X509_NAME_FLAGS) > 0) {
BIO_get_mem_ptr(bio, &mem);
info->Set(issuer_sym, String::New(mem->data, mem->length));
info->Set(issuer_sym,
OneByteString(node_isolate, mem->data, mem->length));
}
(void) BIO_reset(bio);
@ -855,7 +861,8 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
assert(rv == 1);
BIO_get_mem_ptr(bio, &mem);
info->Set(subjectaltname_sym, String::New(mem->data, mem->length));
info->Set(subjectaltname_sym,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
}
@ -866,12 +873,14 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
NULL != (rsa = EVP_PKEY_get1_RSA(pkey))) {
BN_print(bio, rsa->n);
BIO_get_mem_ptr(bio, &mem);
info->Set(modulus_sym, String::New(mem->data, mem->length) );
info->Set(modulus_sym,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
BN_print(bio, rsa->e);
BIO_get_mem_ptr(bio, &mem);
info->Set(exponent_sym, String::New(mem->data, mem->length) );
info->Set(exponent_sym,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
}
@ -886,12 +895,14 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
ASN1_TIME_print(bio, X509_get_notBefore(peer_cert));
BIO_get_mem_ptr(bio, &mem);
info->Set(valid_from_sym, String::New(mem->data, mem->length));
info->Set(valid_from_sym,
OneByteString(node_isolate, mem->data, mem->length));
(void) BIO_reset(bio);
ASN1_TIME_print(bio, X509_get_notAfter(peer_cert));
BIO_get_mem_ptr(bio, &mem);
info->Set(valid_to_sym, String::New(mem->data, mem->length));
info->Set(valid_to_sym,
OneByteString(node_isolate, mem->data, mem->length));
BIO_free_all(bio);
unsigned int md_size, i;
@ -911,7 +922,7 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
else
fingerprint[0] = '\0';
info->Set(fingerprint_sym, String::New(fingerprint));
info->Set(fingerprint_sym, OneByteString(node_isolate, fingerprint));
}
STACK_OF(ASN1_OBJECT)* eku = static_cast<STACK_OF(ASN1_OBJECT)*>(
@ -926,7 +937,8 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
for (int i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
memset(buf, 0, sizeof(buf));
OBJ_obj2txt(buf, sizeof(buf) - 1, sk_ASN1_OBJECT_value(eku, i), 1);
ext_key_usage->Set(Integer::New(i, node_isolate), String::New(buf));
ext_key_usage->Set(Integer::New(i, node_isolate),
OneByteString(node_isolate, buf));
}
sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
@ -1022,7 +1034,8 @@ void TLSCallbacks::LoadSession(const FunctionCallbackInfo<Value>& args) {
if (sess->tlsext_hostname == NULL) {
info->Set(servername_sym, False(node_isolate));
} else {
info->Set(servername_sym, String::New(sess->tlsext_hostname));
info->Set(servername_sym,
OneByteString(node_isolate, sess->tlsext_hostname));
}
#endif
args.GetReturnValue().Set(info);
@ -1053,8 +1066,8 @@ void TLSCallbacks::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
const char* cipher_version = SSL_CIPHER_get_version(c);
Local<Object> info = Object::New();
info->Set(name_sym, String::New(cipher_name));
info->Set(version_sym, String::New(cipher_version));
info->Set(name_sym, OneByteString(node_isolate, cipher_name));
info->Set(version_sym, OneByteString(node_isolate, cipher_version));
args.GetReturnValue().Set(info);
}
@ -1115,7 +1128,7 @@ int TLSCallbacks::SelectNextProtoCallback(SSL* s,
result = Null(node_isolate);
break;
case OPENSSL_NPN_NEGOTIATED:
result = String::New(reinterpret_cast<const char*>(*out), *outlen);
result = OneByteString(node_isolate, *out, *outlen);
break;
case OPENSSL_NPN_NO_OVERLAP:
result = False(node_isolate);
@ -1153,7 +1166,7 @@ void TLSCallbacks::GetNegotiatedProto(const FunctionCallbackInfo<Value>& args) {
}
args.GetReturnValue().Set(
String::New(reinterpret_cast<const char*>(npn_proto), npn_proto_len));
OneByteString(node_isolate, npn_proto, npn_proto_len));
}
@ -1179,7 +1192,7 @@ void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
const char* servername = SSL_get_servername(wrap->ssl_,
TLSEXT_NAMETYPE_host_name);
if (servername != NULL) {
args.GetReturnValue().Set(String::New(servername));
args.GetReturnValue().Set(OneByteString(node_isolate, servername));
} else {
args.GetReturnValue().Set(false);
}
@ -1244,7 +1257,7 @@ void TLSCallbacks::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New();
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("TLSWrap"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "TLSWrap"));
NODE_SET_PROTOTYPE_METHOD(t, "start", Start);
NODE_SET_PROTOTYPE_METHOD(t, "getPeerCertificate", GetPeerCertificate);
@ -1275,28 +1288,29 @@ void TLSCallbacks::Initialize(Handle<Object> target) {
tlsWrap.Reset(node_isolate, t->GetFunction());
onread_sym = String::New("onread");
onerror_sym = String::New("onerror");
onhandshakestart_sym = String::New("onhandshakestart");
onhandshakedone_sym = String::New("onhandshakedone");
onclienthello_sym = String::New("onclienthello");
onnewsession_sym = String::New("onnewsession");
subject_sym = String::New("subject");
issuer_sym = String::New("issuer");
valid_from_sym = String::New("valid_from");
valid_to_sym = String::New("valid_to");
subjectaltname_sym = String::New("subjectaltname");
modulus_sym = String::New("modulus");
exponent_sym = String::New("exponent");
fingerprint_sym = String::New("fingerprint");
name_sym = String::New("name");
version_sym = String::New("version");
ext_key_usage_sym = String::New("ext_key_usage");
sessionid_sym = String::New("sessionId");
tls_ticket_sym = String::New("tlsTicket");
servername_sym = String::New("servername");
sni_context_sym = String::New("sni_context");
onread_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onread");
onerror_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onerror");
onhandshakestart_sym =
FIXED_ONE_BYTE_STRING(node_isolate, "onhandshakestart");
onhandshakedone_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onhandshakedone");
onclienthello_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onclienthello");
onnewsession_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onnewsession");
subject_sym = FIXED_ONE_BYTE_STRING(node_isolate, "subject");
issuer_sym = FIXED_ONE_BYTE_STRING(node_isolate, "issuer");
valid_from_sym = FIXED_ONE_BYTE_STRING(node_isolate, "valid_from");
valid_to_sym = FIXED_ONE_BYTE_STRING(node_isolate, "valid_to");
subjectaltname_sym = FIXED_ONE_BYTE_STRING(node_isolate, "subjectaltname");
modulus_sym = FIXED_ONE_BYTE_STRING(node_isolate, "modulus");
exponent_sym = FIXED_ONE_BYTE_STRING(node_isolate, "exponent");
fingerprint_sym = FIXED_ONE_BYTE_STRING(node_isolate, "fingerprint");
name_sym = FIXED_ONE_BYTE_STRING(node_isolate, "name");
version_sym = FIXED_ONE_BYTE_STRING(node_isolate, "version");
ext_key_usage_sym = FIXED_ONE_BYTE_STRING(node_isolate, "ext_key_usage");
sessionid_sym = FIXED_ONE_BYTE_STRING(node_isolate, "sessionId");
tls_ticket_sym = FIXED_ONE_BYTE_STRING(node_isolate, "tlsTicket");
servername_sym = FIXED_ONE_BYTE_STRING(node_isolate, "servername");
sni_context_sym = FIXED_ONE_BYTE_STRING(node_isolate, "sni_context");
}
} // namespace node

8
src/tty_wrap.cc

@ -49,13 +49,13 @@ void TTYWrap::Initialize(Handle<Object> target) {
HandleScope scope(node_isolate);
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->SetClassName(String::NewSymbol("TTY"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "TTY"));
t->InstanceTemplate()->SetInternalFieldCount(1);
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
t->InstanceTemplate()->SetAccessor(String::New("fd"),
t->InstanceTemplate()->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "fd"),
StreamWrap::GetFD,
NULL,
Handle<Value>(),
@ -82,7 +82,7 @@ void TTYWrap::Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "guessHandleType", GuessHandleType);
ttyConstructorTmpl.Reset(node_isolate, t);
target->Set(String::NewSymbol("TTY"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "TTY"), t->GetFunction());
}
@ -117,7 +117,7 @@ void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) {
abort();
}
args.GetReturnValue().Set(String::New(type));
args.GetReturnValue().Set(OneByteString(node_isolate, type));
}

12
src/udp_wrap.cc

@ -68,17 +68,17 @@ UDPWrap::~UDPWrap() {
void UDPWrap::Initialize(Handle<Object> target) {
HandleScope scope(node_isolate);
buffer_sym = String::New("buffer");
oncomplete_sym = String::New("oncomplete");
onmessage_sym = String::New("onmessage");
buffer_sym = FIXED_ONE_BYTE_STRING(node_isolate, "buffer");
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
onmessage_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onmessage");
Local<FunctionTemplate> t = FunctionTemplate::New(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(String::NewSymbol("UDP"));
t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "UDP"));
enum PropertyAttribute attributes =
static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
t->InstanceTemplate()->SetAccessor(String::New("fd"),
t->InstanceTemplate()->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "fd"),
UDPWrap::GetFD,
NULL,
Handle<Value>(),
@ -104,7 +104,7 @@ void UDPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
constructor.Reset(node_isolate, t->GetFunction());
target->Set(String::NewSymbol("UDP"), t->GetFunction());
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "UDP"), t->GetFunction());
}

9
src/uv.cc

@ -40,16 +40,17 @@ void ErrName(const FunctionCallbackInfo<Value>& args) {
int err = args[0]->Int32Value();
if (err >= 0) return ThrowError("err >= 0");
const char* name = uv_err_name(err);
args.GetReturnValue().Set(String::New(name));
args.GetReturnValue().Set(OneByteString(node_isolate, name));
}
void Initialize(Handle<Object> target) {
v8::HandleScope handle_scope(node_isolate);
target->Set(String::New("errname"),
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "errname"),
FunctionTemplate::New(ErrName)->GetFunction());
#define V(name, _) target->Set(String::New("UV_" # name), \
Integer::New(UV_ ## name, node_isolate));
#define V(name, _) \
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "UV_" # name), \
Integer::New(UV_ ## name, node_isolate));
UV_ERRNO_MAP(V)
#undef V
}

Loading…
Cancel
Save