1 // Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
9 #include <limits.h> /* PATH_MAX */
13 #include <dlfcn.h> /* dlopen(), dlsym() */
14 #include <sys/types.h>
15 #include <unistd.h> /* setuid, getuid */
17 #include <node_buffer.h>
18 #include <node_io_watcher.h>
19 #include <node_net2.h>
20 #include <node_events.h>
21 #include <node_cares.h>
23 #include <node_file.h>
26 # include <node_idle_watcher.h>
28 #include <node_http.h>
29 #include <node_http_parser.h>
30 #include <node_signal_watcher.h>
31 #include <node_stat_watcher.h>
32 #include <node_timer.h>
33 #include <node_child_process.h>
34 #include <node_constants.h>
35 #include <node_stdio.h>
36 #include <node_natives.h>
37 #include <node_version.h>
39 #include <node_crypto.h>
41 #include <node_script.h>
47 extern char **environ;
51 static Persistent<Object> process;
53 static Persistent<String> dev_symbol;
54 static Persistent<String> ino_symbol;
55 static Persistent<String> mode_symbol;
56 static Persistent<String> nlink_symbol;
57 static Persistent<String> uid_symbol;
58 static Persistent<String> gid_symbol;
59 static Persistent<String> rdev_symbol;
60 static Persistent<String> size_symbol;
61 static Persistent<String> blksize_symbol;
62 static Persistent<String> blocks_symbol;
63 static Persistent<String> atime_symbol;
64 static Persistent<String> mtime_symbol;
65 static Persistent<String> ctime_symbol;
67 static Persistent<String> rss_symbol;
68 static Persistent<String> vsize_symbol;
69 static Persistent<String> heap_total_symbol;
70 static Persistent<String> heap_used_symbol;
72 static Persistent<String> listeners_symbol;
73 static Persistent<String> uncaught_exception_symbol;
74 static Persistent<String> emit_symbol;
76 static int option_end_index = 0;
77 static bool use_debug_agent = false;
78 static bool debug_wait_connect = false;
79 static int debug_port=5858;
81 static ev_prepare next_tick_watcher;
82 static ev_idle tick_spinner;
83 static bool need_tick_cb;
84 static Persistent<String> tick_callback_sym;
86 static ev_async eio_want_poll_notifier;
87 static ev_async eio_done_poll_notifier;
88 static ev_idle eio_poller;
90 // We need to notify V8 when we're idle so that it can run the garbage
91 // collector. The interface to this is V8::IdleNotification(). It returns
92 // true if the heap hasn't be fully compacted, and needs to be run again.
93 // Returning false means that it doesn't have anymore work to do.
95 // We try to wait for a period of GC_INTERVAL (2 seconds) of idleness, where
96 // idleness means that no libev watchers have been executed. Since
97 // everything in node uses libev watchers, this is a pretty good measure of
98 // idleness. This is done with gc_check, which records the timestamp
99 // last_active on every tick of the event loop, and with gc_timer which
100 // executes every few seconds to measure if
101 // last_active + GC_INTERVAL < ev_now()
102 // If we do find a period of idleness, then we start the gc_idle timer which
103 // will very repaidly call IdleNotification until the heap is fully
105 static ev_tstamp last_active;
106 static ev_timer gc_timer;
107 static ev_check gc_check;
108 static ev_idle gc_idle;
109 #define GC_INTERVAL 1.0
111 static void gc_timer_start () {
112 if (!ev_is_active(&gc_timer)) {
113 ev_timer_start(EV_DEFAULT_UC_ &gc_timer);
114 ev_unref(EV_DEFAULT_UC);
118 static void gc_timer_stop () {
119 if (ev_is_active(&gc_timer)) {
120 ev_ref(EV_DEFAULT_UC);
121 ev_timer_stop(EV_DEFAULT_UC_ &gc_timer);
126 static void CheckIdleness(EV_P_ ev_timer *watcher, int revents) {
127 assert(watcher == &gc_timer);
128 assert(revents == EV_TIMER);
130 //fprintf(stderr, "check idle\n");
132 ev_tstamp idle_time = ev_now(EV_DEFAULT_UC) - last_active;
134 if (idle_time > GC_INTERVAL) {
135 if (!V8::IdleNotification()) {
136 ev_idle_start(EV_DEFAULT_UC_ &gc_idle);
143 static void NotifyIdleness(EV_P_ ev_idle *watcher, int revents) {
144 assert(watcher == &gc_idle);
145 assert(revents == EV_IDLE);
147 //fprintf(stderr, "notify idle\n");
149 if (V8::IdleNotification()) {
150 ev_idle_stop(EV_A_ watcher);
156 static void Activity(EV_P_ ev_check *watcher, int revents) {
157 assert(watcher == &gc_check);
158 assert(revents == EV_CHECK);
160 int pending = ev_pending_count(EV_DEFAULT_UC);
162 // Don't count GC watchers as activity.
164 if (ev_is_pending(&gc_timer)) pending--;
165 if (ev_is_pending(&gc_idle)) pending--;
166 if (ev_is_pending(&gc_check)) pending--;
168 assert(pending >= 0);
170 //fprintf(stderr, "activity, pending: %d\n", pending);
173 last_active = ev_now(EV_DEFAULT_UC);
174 ev_idle_stop(EV_DEFAULT_UC_ &gc_idle);
180 static Handle<Value> NeedTickCallback(const Arguments& args) {
183 ev_idle_start(EV_DEFAULT_UC_ &tick_spinner);
188 static void Spin(EV_P_ ev_idle *watcher, int revents) {
189 assert(watcher == &tick_spinner);
190 assert(revents == EV_IDLE);
194 static void Tick(EV_P_ ev_prepare *watcher, int revents) {
195 assert(watcher == &next_tick_watcher);
196 assert(revents == EV_PREPARE);
198 // Avoid entering a V8 scope.
199 if (!need_tick_cb) return;
201 need_tick_cb = false;
202 ev_idle_stop(EV_DEFAULT_UC_ &tick_spinner);
206 if (tick_callback_sym.IsEmpty()) {
207 // Lazily set the symbol
209 Persistent<String>::New(String::NewSymbol("_tickCallback"));
212 Local<Value> cb_v = process->Get(tick_callback_sym);
213 if (!cb_v->IsFunction()) return;
214 Local<Function> cb = Local<Function>::Cast(cb_v);
218 cb->Call(process, 0, NULL);
220 if (try_catch.HasCaught()) {
221 FatalException(try_catch);
226 static void DoPoll(EV_P_ ev_idle *watcher, int revents) {
227 assert(watcher == &eio_poller);
228 assert(revents == EV_IDLE);
230 //printf("eio_poller\n");
232 if (eio_poll() != -1) {
233 //printf("eio_poller stop\n");
234 ev_idle_stop(EV_DEFAULT_UC_ watcher);
239 // Called from the main thread.
240 static void WantPollNotifier(EV_P_ ev_async *watcher, int revents) {
241 assert(watcher == &eio_want_poll_notifier);
242 assert(revents == EV_ASYNC);
244 //printf("want poll notifier\n");
246 if (eio_poll() == -1) {
247 //printf("eio_poller start\n");
248 ev_idle_start(EV_DEFAULT_UC_ &eio_poller);
253 static void DonePollNotifier(EV_P_ ev_async *watcher, int revents) {
254 assert(watcher == &eio_done_poll_notifier);
255 assert(revents == EV_ASYNC);
257 //printf("done poll notifier\n");
259 if (eio_poll() != -1) {
260 //printf("eio_poller stop\n");
261 ev_idle_stop(EV_DEFAULT_UC_ &eio_poller);
266 // EIOWantPoll() is called from the EIO thread pool each time an EIO
267 // request (that is, one of the node.fs.* functions) has completed.
268 static void EIOWantPoll(void) {
269 // Signal the main thread that eio_poll need to be processed.
270 ev_async_send(EV_DEFAULT_UC_ &eio_want_poll_notifier);
274 static void EIODonePoll(void) {
275 // Signal the main thread that we should stop calling eio_poll().
276 // from the idle watcher.
277 ev_async_send(EV_DEFAULT_UC_ &eio_done_poll_notifier);
281 enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
284 if (!encoding_v->IsString()) return _default;
286 String::Utf8Value encoding(encoding_v->ToString());
288 if (strcasecmp(*encoding, "utf8") == 0) {
290 } else if (strcasecmp(*encoding, "utf-8") == 0) {
292 } else if (strcasecmp(*encoding, "ascii") == 0) {
294 } else if (strcasecmp(*encoding, "binary") == 0) {
296 } else if (strcasecmp(*encoding, "raw") == 0) {
297 fprintf(stderr, "'raw' (array of integers) has been removed. "
300 } else if (strcasecmp(*encoding, "raws") == 0) {
301 fprintf(stderr, "'raws' encoding has been renamed to 'binary'. "
302 "Please update your code.\n");
309 Local<Value> Encode(const void *buf, size_t len, enum encoding encoding) {
312 if (!len) return scope.Close(String::Empty());
314 if (encoding == BINARY) {
315 const unsigned char *cbuf = static_cast<const unsigned char*>(buf);
316 uint16_t * twobytebuf = new uint16_t[len];
317 for (size_t i = 0; i < len; i++) {
318 // XXX is the following line platform independent?
319 twobytebuf[i] = cbuf[i];
321 Local<String> chunk = String::New(twobytebuf, len);
322 delete [] twobytebuf; // TODO use ExternalTwoByteString?
323 return scope.Close(chunk);
326 // utf8 or ascii encoding
327 Local<String> chunk = String::New((const char*)buf, len);
328 return scope.Close(chunk);
331 // Returns -1 if the handle was not valid for decoding
332 ssize_t DecodeBytes(v8::Handle<v8::Value> val, enum encoding encoding) {
335 if (val->IsArray()) {
336 fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
342 Local<String> str = val->ToString();
344 if (encoding == UTF8) return str->Utf8Length();
346 return str->Length();
350 # define MIN(a, b) ((a) < (b) ? (a) : (b))
353 // Returns number of bytes written.
354 ssize_t DecodeWrite(char *buf,
356 v8::Handle<v8::Value> val,
357 enum encoding encoding) {
361 // A lot of improvement can be made here. See:
362 // http://code.google.com/p/v8/issues/detail?id=270
363 // http://groups.google.com/group/v8-dev/browse_thread/thread/dba28a81d9215291/ece2b50a3b4022c
364 // http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611
366 if (val->IsArray()) {
367 fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
373 Local<String> str = val->ToString();
375 if (encoding == UTF8) {
376 str->WriteUtf8(buf, buflen, NULL, String::HINT_MANY_WRITES_EXPECTED);
380 if (encoding == ASCII) {
381 str->WriteAscii(buf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
385 // THIS IS AWFUL!!! FIXME
387 assert(encoding == BINARY);
389 uint16_t * twobytebuf = new uint16_t[buflen];
391 str->Write(twobytebuf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
393 for (size_t i = 0; i < buflen; i++) {
394 unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
399 delete [] twobytebuf;
404 static Persistent<FunctionTemplate> stats_constructor_template;
406 Local<Object> BuildStatsObject(struct stat * s) {
409 if (dev_symbol.IsEmpty()) {
410 dev_symbol = NODE_PSYMBOL("dev");
411 ino_symbol = NODE_PSYMBOL("ino");
412 mode_symbol = NODE_PSYMBOL("mode");
413 nlink_symbol = NODE_PSYMBOL("nlink");
414 uid_symbol = NODE_PSYMBOL("uid");
415 gid_symbol = NODE_PSYMBOL("gid");
416 rdev_symbol = NODE_PSYMBOL("rdev");
417 size_symbol = NODE_PSYMBOL("size");
418 blksize_symbol = NODE_PSYMBOL("blksize");
419 blocks_symbol = NODE_PSYMBOL("blocks");
420 atime_symbol = NODE_PSYMBOL("atime");
421 mtime_symbol = NODE_PSYMBOL("mtime");
422 ctime_symbol = NODE_PSYMBOL("ctime");
425 Local<Object> stats =
426 stats_constructor_template->GetFunction()->NewInstance();
428 /* ID of device containing file */
429 stats->Set(dev_symbol, Integer::New(s->st_dev));
432 stats->Set(ino_symbol, Integer::New(s->st_ino));
435 stats->Set(mode_symbol, Integer::New(s->st_mode));
437 /* number of hard links */
438 stats->Set(nlink_symbol, Integer::New(s->st_nlink));
440 /* user ID of owner */
441 stats->Set(uid_symbol, Integer::New(s->st_uid));
443 /* group ID of owner */
444 stats->Set(gid_symbol, Integer::New(s->st_gid));
446 /* device ID (if special file) */
447 stats->Set(rdev_symbol, Integer::New(s->st_rdev));
449 /* total size, in bytes */
450 stats->Set(size_symbol, Integer::New(s->st_size));
452 /* blocksize for filesystem I/O */
453 stats->Set(blksize_symbol, Integer::New(s->st_blksize));
455 /* number of blocks allocated */
456 stats->Set(blocks_symbol, Integer::New(s->st_blocks));
458 /* time of last access */
459 stats->Set(atime_symbol, NODE_UNIXTIME_V8(s->st_atime));
461 /* time of last modification */
462 stats->Set(mtime_symbol, NODE_UNIXTIME_V8(s->st_mtime));
464 /* time of last status change */
465 stats->Set(ctime_symbol, NODE_UNIXTIME_V8(s->st_ctime));
467 return scope.Close(stats);
471 // Extracts a C str from a V8 Utf8Value.
472 const char* ToCString(const v8::String::Utf8Value& value) {
473 return *value ? *value : "<str conversion failed>";
476 static void ReportException(TryCatch &try_catch, bool show_line = false) {
477 Handle<Message> message = try_catch.Message();
479 Handle<Value> error = try_catch.Exception();
480 Handle<String> stack;
482 if (error->IsObject()) {
483 Handle<Object> obj = Handle<Object>::Cast(error);
484 Handle<Value> raw_stack = obj->Get(String::New("stack"));
485 if (raw_stack->IsString()) stack = Handle<String>::Cast(raw_stack);
488 if (show_line && !message.IsEmpty()) {
489 // Print (filename):(line number): (message).
490 String::Utf8Value filename(message->GetScriptResourceName());
491 const char* filename_string = ToCString(filename);
492 int linenum = message->GetLineNumber();
493 fprintf(stderr, "%s:%i\n", filename_string, linenum);
494 // Print line of source code.
495 String::Utf8Value sourceline(message->GetSourceLine());
496 const char* sourceline_string = ToCString(sourceline);
497 fprintf(stderr, "%s\n", sourceline_string);
498 // Print wavy underline (GetUnderline is deprecated).
499 int start = message->GetStartColumn();
500 for (int i = 0; i < start; i++) {
501 fprintf(stderr, " ");
503 int end = message->GetEndColumn();
504 for (int i = start; i < end; i++) {
505 fprintf(stderr, "^");
507 fprintf(stderr, "\n");
510 if (stack.IsEmpty()) {
511 message->PrintCurrentStackTrace(stderr);
513 String::Utf8Value trace(stack);
514 fprintf(stderr, "%s\n", *trace);
519 // Executes a str within the current v8 context.
520 Local<Value> ExecuteString(Local<String> source, Local<Value> filename) {
524 Local<v8::Script> script = v8::Script::Compile(source, filename);
525 if (script.IsEmpty()) {
526 ReportException(try_catch);
530 Local<Value> result = script->Run();
531 if (result.IsEmpty()) {
532 ReportException(try_catch);
536 return scope.Close(result);
539 static Handle<Value> ByteLength(const Arguments& args) {
542 if (args.Length() < 1 || !args[0]->IsString()) {
543 return ThrowException(Exception::Error(String::New("Bad argument.")));
546 Local<Integer> length = Integer::New(DecodeBytes(args[0], ParseEncoding(args[1], UTF8)));
548 return scope.Close(length);
551 static Handle<Value> Loop(const Arguments& args) {
553 assert(args.Length() == 0);
555 // TODO Probably don't need to start this each time.
556 // Avoids failing on test/mjsunit/test-eio-race3.js though
557 ev_idle_start(EV_DEFAULT_UC_ &eio_poller);
559 ev_loop(EV_DEFAULT_UC_ 0);
563 static Handle<Value> Unloop(const Arguments& args) {
564 fprintf(stderr, "Deprecation: Don't use process.unloop(). It will be removed soon.\n");
566 int how = EVUNLOOP_ONE;
567 if (args[0]->IsString()) {
568 String::Utf8Value how_s(args[0]->ToString());
569 if (0 == strcmp(*how_s, "all")) {
573 ev_unloop(EV_DEFAULT_ how);
577 static Handle<Value> Chdir(const Arguments& args) {
580 if (args.Length() != 1 || !args[0]->IsString()) {
581 return ThrowException(Exception::Error(String::New("Bad argument.")));
584 String::Utf8Value path(args[0]->ToString());
586 int r = chdir(*path);
589 return ThrowException(Exception::Error(String::New(strerror(errno))));
595 static Handle<Value> Cwd(const Arguments& args) {
597 assert(args.Length() == 0);
599 char output[PATH_MAX];
600 char *r = getcwd(output, PATH_MAX);
602 return ThrowException(Exception::Error(String::New(strerror(errno))));
604 Local<String> cwd = String::New(output);
606 return scope.Close(cwd);
609 static Handle<Value> Umask(const Arguments& args){
612 if(args.Length() < 1) {
616 else if(!args[0]->IsInt32()) {
617 return ThrowException(Exception::TypeError(
618 String::New("argument must be an integer.")));
621 old = umask((mode_t)args[0]->Uint32Value());
623 return scope.Close(Uint32::New(old));
627 static Handle<Value> GetUid(const Arguments& args) {
629 assert(args.Length() == 0);
631 return scope.Close(Integer::New(uid));
634 static Handle<Value> GetGid(const Arguments& args) {
636 assert(args.Length() == 0);
638 return scope.Close(Integer::New(gid));
642 static Handle<Value> SetGid(const Arguments& args) {
645 if (args.Length() < 1) {
646 return ThrowException(Exception::Error(
647 String::New("setgid requires 1 argument")));
650 Local<Integer> given_gid = args[0]->ToInteger();
651 int gid = given_gid->Int32Value();
653 if ((result = setgid(gid)) != 0) {
654 return ThrowException(Exception::Error(String::New(strerror(errno))));
659 static Handle<Value> SetUid(const Arguments& args) {
662 if (args.Length() < 1) {
663 return ThrowException(Exception::Error(
664 String::New("setuid requires 1 argument")));
667 Local<Integer> given_uid = args[0]->ToInteger();
668 int uid = given_uid->Int32Value();
670 if ((result = setuid(uid)) != 0) {
671 return ThrowException(Exception::Error(String::New(strerror(errno))));
677 v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
681 exit(args[0]->IntegerValue());
686 #define HAVE_GETMEM 1
687 #include <unistd.h> /* getpagesize() */
689 #if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
690 #define PROCFS_FILE_OFFSET_BITS_HACK 1
691 #undef _FILE_OFFSET_BITS
693 #define PROCFS_FILE_OFFSET_BITS_HACK 0
698 #if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
699 #define _FILE_OFFSET_BITS 64
702 int getmem(size_t *rss, size_t *vsize) {
703 pid_t pid = getpid();
705 size_t page_size = getpagesize();
707 sprintf(pidpath, "/proc/%d/psinfo", pid);
710 FILE *f = fopen(pidpath, "r");
713 if (fread(&psinfo, sizeof(psinfo_t), 1, f) != 1) {
720 *vsize = (size_t) psinfo.pr_size * page_size;
721 *rss = (size_t) psinfo.pr_rssize * 1024;
731 #define HAVE_GETMEM 1
733 #include <sys/param.h>
734 #include <sys/sysctl.h>
735 #include <sys/user.h>
740 int getmem(size_t *rss, size_t *vsize) {
742 struct kinfo_proc *kinfo = NULL;
745 size_t page_size = getpagesize();
749 kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
750 if (kd == NULL) goto error;
752 kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs);
753 if (kinfo == NULL) goto error;
755 *rss = kinfo->ki_rssize * page_size;
756 *vsize = kinfo->ki_size;
763 if (kd) kvm_close(kd);
766 #endif // __FreeBSD__
770 #define HAVE_GETMEM 1
771 /* Researched by Tim Becker and Michael Knight
772 * http://blog.kuriositaet.de/?p=257
775 #include <mach/task.h>
776 #include <mach/mach_init.h>
778 int getmem(size_t *rss, size_t *vsize) {
779 struct task_basic_info t_info;
780 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
782 int r = task_info(mach_task_self(),
784 (task_info_t)&t_info,
787 if (r != KERN_SUCCESS) return -1;
789 *rss = t_info.resident_size;
790 *vsize = t_info.virtual_size;
797 # define HAVE_GETMEM 1
798 # include <sys/param.h> /* for MAXPATHLEN */
800 int getmem(size_t *rss, size_t *vsize) {
801 FILE *f = fopen("/proc/self/stat", "r");
806 char buffer[MAXPATHLEN];
807 size_t page_size = getpagesize();
810 if (fscanf(f, "%d ", &itmp) == 0) goto error;
812 if (fscanf (f, "%s ", &buffer[0]) == 0) goto error;
814 if (fscanf (f, "%c ", &ctmp) == 0) goto error;
816 if (fscanf (f, "%d ", &itmp) == 0) goto error;
818 if (fscanf (f, "%d ", &itmp) == 0) goto error;
820 if (fscanf (f, "%d ", &itmp) == 0) goto error;
822 if (fscanf (f, "%d ", &itmp) == 0) goto error;
823 /* TTY owner process group */
824 if (fscanf (f, "%d ", &itmp) == 0) goto error;
826 if (fscanf (f, "%u ", &itmp) == 0) goto error;
827 /* Minor faults (no memory page) */
828 if (fscanf (f, "%u ", &itmp) == 0) goto error;
829 /* Minor faults, children */
830 if (fscanf (f, "%u ", &itmp) == 0) goto error;
831 /* Major faults (memory page faults) */
832 if (fscanf (f, "%u ", &itmp) == 0) goto error;
833 /* Major faults, children */
834 if (fscanf (f, "%u ", &itmp) == 0) goto error;
836 if (fscanf (f, "%d ", &itmp) == 0) goto error;
838 if (fscanf (f, "%d ", &itmp) == 0) goto error;
839 /* utime, children */
840 if (fscanf (f, "%d ", &itmp) == 0) goto error;
841 /* stime, children */
842 if (fscanf (f, "%d ", &itmp) == 0) goto error;
843 /* jiffies remaining in current time slice */
844 if (fscanf (f, "%d ", &itmp) == 0) goto error;
846 if (fscanf (f, "%d ", &itmp) == 0) goto error;
847 /* jiffies until next timeout */
848 if (fscanf (f, "%u ", &itmp) == 0) goto error;
849 /* jiffies until next SIGALRM */
850 if (fscanf (f, "%u ", &itmp) == 0) goto error;
851 /* start time (jiffies since system boot) */
852 if (fscanf (f, "%d ", &itmp) == 0) goto error;
854 /* Virtual memory size */
855 if (fscanf (f, "%u ", &itmp) == 0) goto error;
856 *vsize = (size_t) itmp;
858 /* Resident set size */
859 if (fscanf (f, "%u ", &itmp) == 0) goto error;
860 *rss = (size_t) itmp * page_size;
863 if (fscanf (f, "%u ", &itmp) == 0) goto error;
865 if (fscanf (f, "%u ", &itmp) == 0) goto error;
867 if (fscanf (f, "%u ", &itmp) == 0) goto error;
869 if (fscanf (f, "%u ", &itmp) == 0) goto error;
881 v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
883 assert(args.Length() == 0);
886 return ThrowException(Exception::Error(String::New("Not support on your platform. (Talk to Ryan.)")));
890 int r = getmem(&rss, &vsize);
893 return ThrowException(Exception::Error(String::New(strerror(errno))));
896 Local<Object> info = Object::New();
898 if (rss_symbol.IsEmpty()) {
899 rss_symbol = NODE_PSYMBOL("rss");
900 vsize_symbol = NODE_PSYMBOL("vsize");
901 heap_total_symbol = NODE_PSYMBOL("heapTotal");
902 heap_used_symbol = NODE_PSYMBOL("heapUsed");
905 info->Set(rss_symbol, Integer::NewFromUnsigned(rss));
906 info->Set(vsize_symbol, Integer::NewFromUnsigned(vsize));
909 HeapStatistics v8_heap_stats;
910 V8::GetHeapStatistics(&v8_heap_stats);
911 info->Set(heap_total_symbol,
912 Integer::NewFromUnsigned(v8_heap_stats.total_heap_size()));
913 info->Set(heap_used_symbol,
914 Integer::NewFromUnsigned(v8_heap_stats.used_heap_size()));
916 return scope.Close(info);
921 v8::Handle<v8::Value> Kill(const v8::Arguments& args) {
924 if (args.Length() < 1 || !args[0]->IsNumber()) {
925 return ThrowException(Exception::Error(String::New("Bad argument.")));
928 pid_t pid = args[0]->IntegerValue();
932 if (args.Length() >= 2) {
933 if (args[1]->IsNumber()) {
934 sig = args[1]->Int32Value();
935 } else if (args[1]->IsString()) {
936 Local<String> signame = args[1]->ToString();
938 Local<Value> sig_v = process->Get(signame);
939 if (!sig_v->IsNumber()) {
940 return ThrowException(Exception::Error(String::New("Unknown signal")));
942 sig = sig_v->Int32Value();
946 int r = kill(pid, sig);
949 return ThrowException(Exception::Error(String::New(strerror(errno))));
955 typedef void (*extInit)(Handle<Object> exports);
957 // DLOpen is node.dlopen(). Used to load 'module.node' dynamically shared
959 Handle<Value> DLOpen(const v8::Arguments& args) {
962 if (args.Length() < 2) return Undefined();
964 String::Utf8Value filename(args[0]->ToString()); // Cast
965 Local<Object> target = args[1]->ToObject(); // Cast
967 // Actually call dlopen().
968 // FIXME: This is a blocking function and should be called asynchronously!
969 // This function should be moved to file.cc and use libeio to make this
971 void *handle = dlopen(*filename, RTLD_LAZY);
974 if (handle == NULL) {
975 Local<Value> exception = Exception::Error(String::New(dlerror()));
976 return ThrowException(exception);
979 // Get the init() function from the dynamically shared object.
980 void *init_handle = dlsym(handle, "init");
981 // Error out if not found.
982 if (init_handle == NULL) {
983 Local<Value> exception =
984 Exception::Error(String::New("No 'init' symbol found in module."));
985 return ThrowException(exception);
987 extInit init = (extInit)(init_handle); // Cast
989 // Execute the C++ module
996 Handle<Value> Compile(const Arguments& args) {
999 if (args.Length() < 2) {
1000 return ThrowException(Exception::TypeError(
1001 String::New("needs two arguments.")));
1004 Local<String> source = args[0]->ToString();
1005 Local<String> filename = args[1]->ToString();
1009 Local<v8::Script> script = v8::Script::Compile(source, filename);
1010 if (try_catch.HasCaught()) {
1011 // Hack because I can't get a proper stacktrace on SyntaxError
1012 ReportException(try_catch, true);
1016 Local<Value> result = script->Run();
1017 if (try_catch.HasCaught()) return try_catch.ReThrow();
1019 return scope.Close(result);
1022 static void OnFatalError(const char* location, const char* message) {
1024 fprintf(stderr, "FATAL ERROR: %s %s\n", location, message);
1026 fprintf(stderr, "FATAL ERROR: %s\n", message);
1031 static int uncaught_exception_counter = 0;
1033 void FatalException(TryCatch &try_catch) {
1036 // Check if uncaught_exception_counter indicates a recursion
1037 if (uncaught_exception_counter > 0) {
1038 ReportException(try_catch);
1042 if (listeners_symbol.IsEmpty()) {
1043 listeners_symbol = NODE_PSYMBOL("listeners");
1044 uncaught_exception_symbol = NODE_PSYMBOL("uncaughtException");
1045 emit_symbol = NODE_PSYMBOL("emit");
1048 Local<Value> listeners_v = process->Get(listeners_symbol);
1049 assert(listeners_v->IsFunction());
1051 Local<Function> listeners = Local<Function>::Cast(listeners_v);
1053 Local<String> uncaught_exception_symbol_l = Local<String>::New(uncaught_exception_symbol);
1054 Local<Value> argv[1] = { uncaught_exception_symbol_l };
1055 Local<Value> ret = listeners->Call(process, 1, argv);
1057 assert(ret->IsArray());
1059 Local<Array> listener_array = Local<Array>::Cast(ret);
1061 uint32_t length = listener_array->Length();
1062 // Report and exit if process has no "uncaughtException" listener
1064 ReportException(try_catch);
1068 // Otherwise fire the process "uncaughtException" event
1069 Local<Value> emit_v = process->Get(emit_symbol);
1070 assert(emit_v->IsFunction());
1072 Local<Function> emit = Local<Function>::Cast(emit_v);
1074 Local<Value> error = try_catch.Exception();
1075 Local<Value> event_argv[2] = { uncaught_exception_symbol_l, error };
1077 uncaught_exception_counter++;
1078 emit->Call(process, 2, event_argv);
1079 // Decrement so we know if the next exception is a recursion or not
1080 uncaught_exception_counter--;
1084 static ev_async debug_watcher;
1085 volatile static bool debugger_msg_pending = false;
1087 static void DebugMessageCallback(EV_P_ ev_async *watcher, int revents) {
1089 assert(watcher == &debug_watcher);
1090 assert(revents == EV_ASYNC);
1091 Debug::ProcessDebugMessages();
1094 static void DebugMessageDispatch(void) {
1095 // This function is called from V8's debug thread when a debug TCP client
1096 // has sent a message.
1098 // Send a signal to our main thread saying that it should enter V8 to
1099 // handle the message.
1100 debugger_msg_pending = true;
1101 ev_async_send(EV_DEFAULT_UC_ &debug_watcher);
1104 static Handle<Value> CheckBreak(const Arguments& args) {
1106 assert(args.Length() == 0);
1108 // TODO FIXME This function is a hack to wait until V8 is ready to accept
1109 // commands. There seems to be a bug in EnableAgent( _ , _ , true) which
1110 // makes it unusable here. Ideally we'd be able to bind EnableAgent and
1111 // get it to halt until Eclipse connects.
1113 if (!debug_wait_connect)
1116 printf("Waiting for remote debugger connection...\n");
1118 const int halfSecond = 50;
1119 const int tenMs=10000;
1120 debugger_msg_pending = false;
1122 if (debugger_msg_pending) {
1123 Debug::DebugBreak();
1124 Debug::ProcessDebugMessages();
1125 debugger_msg_pending = false;
1127 // wait for 500 msec of silence from remote debugger
1128 int cnt = halfSecond;
1130 debugger_msg_pending = false;
1132 if (debugger_msg_pending) {
1133 debugger_msg_pending = false;
1144 Persistent<Object> binding_cache;
1146 static Handle<Value> Binding(const Arguments& args) {
1149 Local<String> module = args[0]->ToString();
1150 String::Utf8Value module_v(module);
1152 if (binding_cache.IsEmpty()) {
1153 binding_cache = Persistent<Object>::New(Object::New());
1156 Local<Object> exports;
1158 // TODO DRY THIS UP!
1160 if (!strcmp(*module_v, "stdio")) {
1161 if (binding_cache->Has(module)) {
1162 exports = binding_cache->Get(module)->ToObject();
1164 exports = Object::New();
1165 Stdio::Initialize(exports);
1166 binding_cache->Set(module, exports);
1169 } else if (!strcmp(*module_v, "http")) {
1170 if (binding_cache->Has(module)) {
1171 exports = binding_cache->Get(module)->ToObject();
1173 // Warning: When calling requireBinding('http') from javascript then
1174 // be sure that you call requireBinding('tcp') before it.
1175 assert(binding_cache->Has(String::New("tcp")));
1176 exports = Object::New();
1177 HTTPServer::Initialize(exports);
1178 HTTPConnection::Initialize(exports);
1179 binding_cache->Set(module, exports);
1182 } else if (!strcmp(*module_v, "tcp")) {
1183 if (binding_cache->Has(module)) {
1184 exports = binding_cache->Get(module)->ToObject();
1186 exports = Object::New();
1187 Server::Initialize(exports);
1188 Connection::Initialize(exports);
1189 binding_cache->Set(module, exports);
1192 } else if (!strcmp(*module_v, "cares")) {
1193 if (binding_cache->Has(module)) {
1194 exports = binding_cache->Get(module)->ToObject();
1196 exports = Object::New();
1197 Cares::Initialize(exports);
1198 binding_cache->Set(module, exports);
1201 } else if (!strcmp(*module_v, "fs")) {
1202 if (binding_cache->Has(module)) {
1203 exports = binding_cache->Get(module)->ToObject();
1205 exports = Object::New();
1207 // Initialize the stats object
1208 Local<FunctionTemplate> stat_templ = FunctionTemplate::New();
1209 stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
1210 exports->Set(String::NewSymbol("Stats"),
1211 stats_constructor_template->GetFunction());
1212 StatWatcher::Initialize(exports);
1213 File::Initialize(exports);
1214 binding_cache->Set(module, exports);
1217 } else if (!strcmp(*module_v, "signal_watcher")) {
1218 if (binding_cache->Has(module)) {
1219 exports = binding_cache->Get(module)->ToObject();
1221 exports = Object::New();
1222 SignalWatcher::Initialize(exports);
1223 binding_cache->Set(module, exports);
1226 } else if (!strcmp(*module_v, "net")) {
1227 if (binding_cache->Has(module)) {
1228 exports = binding_cache->Get(module)->ToObject();
1230 exports = Object::New();
1232 binding_cache->Set(module, exports);
1235 } else if (!strcmp(*module_v, "http_parser")) {
1236 if (binding_cache->Has(module)) {
1237 exports = binding_cache->Get(module)->ToObject();
1239 exports = Object::New();
1240 InitHttpParser(exports);
1241 binding_cache->Set(module, exports);
1244 } else if (!strcmp(*module_v, "child_process")) {
1245 if (binding_cache->Has(module)) {
1246 exports = binding_cache->Get(module)->ToObject();
1248 exports = Object::New();
1249 ChildProcess::Initialize(exports);
1250 binding_cache->Set(module, exports);
1253 } else if (!strcmp(*module_v, "buffer")) {
1254 if (binding_cache->Has(module)) {
1255 exports = binding_cache->Get(module)->ToObject();
1257 exports = Object::New();
1258 Buffer::Initialize(exports);
1259 binding_cache->Set(module, exports);
1262 } else if (!strcmp(*module_v, "crypto")) {
1263 if (binding_cache->Has(module)) {
1264 exports = binding_cache->Get(module)->ToObject();
1266 exports = Object::New();
1267 InitCrypto(exports);
1268 binding_cache->Set(module, exports);
1271 } else if (!strcmp(*module_v, "evals")) {
1272 if (binding_cache->Has(module)) {
1273 exports = binding_cache->Get(module)->ToObject();
1275 exports = Object::New();
1276 node::Script::Initialize(exports);
1277 binding_cache->Set(module, exports);
1280 } else if (!strcmp(*module_v, "natives")) {
1281 if (binding_cache->Has(module)) {
1282 exports = binding_cache->Get(module)->ToObject();
1284 exports = Object::New();
1285 // Explicitly define native sources.
1286 // TODO DRY/automate this?
1287 exports->Set(String::New("assert"), String::New(native_assert));
1288 exports->Set(String::New("buffer"), String::New(native_buffer));
1289 exports->Set(String::New("child_process"),String::New(native_child_process));
1290 exports->Set(String::New("dns"), String::New(native_dns));
1291 exports->Set(String::New("events"), String::New(native_events));
1292 exports->Set(String::New("file"), String::New(native_file));
1293 exports->Set(String::New("freelist"), String::New(native_freelist));
1294 exports->Set(String::New("fs"), String::New(native_fs));
1295 exports->Set(String::New("http"), String::New(native_http));
1296 exports->Set(String::New("http_old"), String::New(native_http_old));
1297 exports->Set(String::New("crypto"), String::New(native_crypto));
1298 exports->Set(String::New("ini"), String::New(native_ini));
1299 exports->Set(String::New("mjsunit"), String::New(native_mjsunit));
1300 exports->Set(String::New("net"), String::New(native_net));
1301 exports->Set(String::New("posix"), String::New(native_posix));
1302 exports->Set(String::New("querystring"), String::New(native_querystring));
1303 exports->Set(String::New("repl"), String::New(native_repl));
1304 exports->Set(String::New("sys"), String::New(native_sys));
1305 exports->Set(String::New("tcp"), String::New(native_tcp));
1306 exports->Set(String::New("tcp_old"), String::New(native_tcp_old));
1307 exports->Set(String::New("uri"), String::New(native_uri));
1308 exports->Set(String::New("url"), String::New(native_url));
1309 exports->Set(String::New("utils"), String::New(native_utils));
1310 exports->Set(String::New("path"), String::New(native_path));
1311 exports->Set(String::New("module"), String::New(native_module));
1312 binding_cache->Set(module, exports);
1316 return ThrowException(Exception::Error(String::New("No such module")));
1319 return scope.Close(exports);
1323 static void Load(int argc, char *argv[]) {
1326 Local<FunctionTemplate> process_template = FunctionTemplate::New();
1327 node::EventEmitter::Initialize(process_template);
1329 process = Persistent<Object>::New(process_template->GetFunction()->NewInstance());
1331 // Add a reference to the global object
1332 Local<Object> global = Context::GetCurrent()->Global();
1333 process->Set(String::NewSymbol("global"), global);
1336 process->Set(String::NewSymbol("version"), String::New(NODE_VERSION));
1337 // process.installPrefix
1338 process->Set(String::NewSymbol("installPrefix"), String::New(NODE_PREFIX));
1341 #define xstr(s) str(s)
1343 process->Set(String::NewSymbol("platform"), String::New(xstr(PLATFORM)));
1347 Local<Array> arguments = Array::New(argc - option_end_index + 1);
1348 arguments->Set(Integer::New(0), String::New(argv[0]));
1349 for (j = 1, i = option_end_index + 1; i < argc; j++, i++) {
1350 Local<String> arg = String::New(argv[i]);
1351 arguments->Set(Integer::New(j), arg);
1354 process->Set(String::NewSymbol("ARGV"), arguments);
1355 process->Set(String::NewSymbol("argv"), arguments);
1357 // create process.env
1358 Local<Object> env = Object::New();
1359 for (i = 0; environ[i]; i++) {
1360 // skip entries without a '=' character
1361 for (j = 0; environ[i][j] && environ[i][j] != '='; j++) { ; }
1362 // create the v8 objects
1363 Local<String> field = String::New(environ[i], j);
1364 Local<String> value = Local<String>();
1365 if (environ[i][j] == '=') {
1366 value = String::New(environ[i]+j+1);
1369 env->Set(field, value);
1371 // assign process.ENV
1372 process->Set(String::NewSymbol("ENV"), env);
1373 process->Set(String::NewSymbol("env"), env);
1375 process->Set(String::NewSymbol("pid"), Integer::New(getpid()));
1377 // define various internal methods
1378 NODE_SET_METHOD(process, "loop", Loop);
1379 NODE_SET_METHOD(process, "unloop", Unloop);
1380 NODE_SET_METHOD(process, "compile", Compile);
1381 NODE_SET_METHOD(process, "_byteLength", ByteLength);
1382 NODE_SET_METHOD(process, "_needTickCallback", NeedTickCallback);
1383 NODE_SET_METHOD(process, "reallyExit", Exit);
1384 NODE_SET_METHOD(process, "chdir", Chdir);
1385 NODE_SET_METHOD(process, "cwd", Cwd);
1386 NODE_SET_METHOD(process, "getuid", GetUid);
1387 NODE_SET_METHOD(process, "setuid", SetUid);
1389 NODE_SET_METHOD(process, "setgid", SetGid);
1390 NODE_SET_METHOD(process, "getgid", GetGid);
1392 NODE_SET_METHOD(process, "umask", Umask);
1393 NODE_SET_METHOD(process, "dlopen", DLOpen);
1394 NODE_SET_METHOD(process, "kill", Kill);
1395 NODE_SET_METHOD(process, "memoryUsage", MemoryUsage);
1396 NODE_SET_METHOD(process, "checkBreak", CheckBreak);
1398 NODE_SET_METHOD(process, "binding", Binding);
1400 // Assign the EventEmitter. It was created in main().
1401 process->Set(String::NewSymbol("EventEmitter"),
1402 EventEmitter::constructor_template->GetFunction());
1405 // Initialize the C++ modules..................filename of module
1406 IOWatcher::Initialize(process); // io_watcher.cc
1407 // Not in use at the moment.
1408 //IdleWatcher::Initialize(process); // idle_watcher.cc
1409 Timer::Initialize(process); // timer.cc
1410 DefineConstants(process); // constants.cc
1412 // Compile, execute the src/node.js file. (Which was included as static C
1413 // string in node_natives.h. 'natve_node' is the string containing that
1416 // The node.js file returns a function 'f'
1422 Local<Value> f_value = ExecuteString(String::New(native_node),
1423 String::New("node.js"));
1425 if (try_catch.HasCaught()) {
1426 ReportException(try_catch);
1430 assert(f_value->IsFunction());
1431 Local<Function> f = Local<Function>::Cast(f_value);
1433 // Now we call 'f' with the 'process' variable that we've built up with
1434 // all our bindings. Inside node.js we'll take care of assigning things to
1437 // We start the process this way in order to be more modular. Developers
1438 // who do not like how 'src/node.js' setups the module system but do like
1439 // Node's I/O bindings may want to replace 'f' with their own function.
1441 Local<Value> args[1] = { Local<Value>::New(process) };
1443 f->Call(global, 1, args);
1446 if (try_catch.HasCaught()) {
1447 ReportException(try_catch);
1453 static void PrintHelp();
1455 static void ParseDebugOpt(const char* arg) {
1458 use_debug_agent = true;
1459 if (!strcmp (arg, "--debug-brk")) {
1460 debug_wait_connect = true;
1462 } else if (!strcmp(arg, "--debug")) {
1464 } else if (strstr(arg, "--debug-brk=") == arg) {
1465 debug_wait_connect = true;
1466 p = 1 + strchr(arg, '=');
1467 debug_port = atoi(p);
1468 } else if (strstr(arg, "--debug=") == arg) {
1469 p = 1 + strchr(arg, '=');
1470 debug_port = atoi(p);
1472 if (p && debug_port > 1024 && debug_port < 65536)
1475 fprintf(stderr, "Bad debug option.\n");
1476 if (p) fprintf(stderr, "Debug port must be in range 1025 to 65535.\n");
1482 static void PrintHelp() {
1483 printf("Usage: node [options] script.js [arguments] \n"
1485 " -v, --version print node's version\n"
1486 " --debug[=port] enable remote debugging via given TCP port\n"
1487 " without stopping the execution\n"
1488 " --debug-brk[=port] as above, but break in script.js and\n"
1489 " wait for remote debugger to connect\n"
1490 " --v8-options print v8 command line options\n"
1491 " --vars print various compiled-in variables\n"
1493 "Enviromental variables:\n"
1494 "NODE_PATH ':'-separated list of directories\n"
1495 " prefixed to the module search path,\n"
1497 "NODE_DEBUG Print additional debugging output.\n"
1499 "Documentation can be found at http://nodejs.org/api.html"
1500 " or with 'man node'\n");
1503 // Parse node command line arguments.
1504 static void ParseArgs(int *argc, char **argv) {
1505 // TODO use parse opts
1506 for (int i = 1; i < *argc; i++) {
1507 const char *arg = argv[i];
1508 if (strstr(arg, "--debug") == arg) {
1510 argv[i] = const_cast<char*>("");
1511 option_end_index = i;
1512 } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
1513 printf("%s\n", NODE_VERSION);
1515 } else if (strcmp(arg, "--vars") == 0) {
1516 printf("NODE_PREFIX: %s\n", NODE_PREFIX);
1517 printf("NODE_CFLAGS: %s\n", NODE_CFLAGS);
1519 } else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
1522 } else if (strcmp(arg, "--v8-options") == 0) {
1523 argv[i] = const_cast<char*>("--help");
1524 option_end_index = i+1;
1525 } else if (argv[i][0] != '-') {
1526 option_end_index = i-1;
1535 int main(int argc, char *argv[]) {
1536 // Parse a few arguments which are specific to Node.
1537 node::ParseArgs(&argc, argv);
1538 // Parse the rest of the args (up to the 'option_end_index' (where '--' was
1539 // in the command line))
1540 V8::SetFlagsFromCommandLine(&node::option_end_index, argv, false);
1542 // Error out if we don't have a script argument.
1544 fprintf(stderr, "No script was specified.\n");
1549 // Ignore the SIGPIPE
1550 evcom_ignore_sigpipe();
1552 // Initialize the default ev loop.
1554 // TODO(Ryan) I'm experiencing abnormally high load using Solaris's
1555 // EVBACKEND_PORT. Temporarally forcing select() until I debug.
1556 ev_default_loop(EVBACKEND_SELECT);
1558 ev_default_loop(EVFLAG_AUTO);
1561 ev_prepare_init(&node::next_tick_watcher, node::Tick);
1562 ev_prepare_start(EV_DEFAULT_UC_ &node::next_tick_watcher);
1563 ev_unref(EV_DEFAULT_UC);
1565 ev_idle_init(&node::tick_spinner, node::Spin);
1567 ev_timer_init(&node::gc_timer, node::CheckIdleness, 2*GC_INTERVAL, 2*GC_INTERVAL);
1569 ev_check_init(&node::gc_check, node::Activity);
1570 ev_check_start(EV_DEFAULT_UC_ &node::gc_check);
1571 ev_unref(EV_DEFAULT_UC);
1573 ev_idle_init(&node::gc_idle, node::NotifyIdleness);
1576 // Setup the EIO thread pool
1577 { // It requires 3, yes 3, watchers.
1578 ev_idle_init(&node::eio_poller, node::DoPoll);
1580 ev_async_init(&node::eio_want_poll_notifier, node::WantPollNotifier);
1581 ev_async_start(EV_DEFAULT_UC_ &node::eio_want_poll_notifier);
1582 ev_unref(EV_DEFAULT_UC);
1584 ev_async_init(&node::eio_done_poll_notifier, node::DonePollNotifier);
1585 ev_async_start(EV_DEFAULT_UC_ &node::eio_done_poll_notifier);
1586 ev_unref(EV_DEFAULT_UC);
1588 eio_init(node::EIOWantPoll, node::EIODonePoll);
1589 // Don't handle more than 10 reqs on each eio_poll(). This is to avoid
1590 // race conditions. See test/mjsunit/test-eio-race.js
1591 eio_set_max_poll_reqs(10);
1595 HandleScope handle_scope;
1597 V8::SetFatalErrorHandler(node::OnFatalError);
1599 // If the --debug flag was specified then initialize the debug thread.
1600 if (node::use_debug_agent) {
1601 // Initialize the async watcher for receiving messages from the debug
1602 // thread and marshal it into the main thread. DebugMessageCallback()
1603 // is called from the main thread to execute a random bit of javascript
1604 // - which will give V8 control so it can handle whatever new message
1605 // had been received on the debug thread.
1606 ev_async_init(&node::debug_watcher, node::DebugMessageCallback);
1607 ev_set_priority(&node::debug_watcher, EV_MAXPRI);
1608 // Set the callback DebugMessageDispatch which is called from the debug
1610 Debug::SetDebugMessageDispatchHandler(node::DebugMessageDispatch);
1611 // Start the async watcher.
1612 ev_async_start(EV_DEFAULT_UC_ &node::debug_watcher);
1613 // unref it so that we exit the event loop despite it being active.
1614 ev_unref(EV_DEFAULT_UC);
1616 // Start the debug thread and it's associated TCP server on port 5858.
1617 bool r = Debug::EnableAgent("node " NODE_VERSION, node::debug_port);
1619 // Crappy check that everything went well. FIXME
1621 // Print out some information.
1622 printf("debugger listening on port %d\n", node::debug_port);
1625 // Create the one and only Context.
1626 Persistent<Context> context = Context::New();
1627 Context::Scope context_scope(context);
1629 // Create all the objects, load modules, do everything.
1630 // so your next reading stop should be node::Load()!
1631 node::Load(argc, argv);
1633 node::Stdio::Flush();