|
@ -280,67 +280,44 @@ ExecuteNativeJS (const char *filename, const char *data) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
static Local<Object> |
|
|
main (int argc, char *argv[]) |
|
|
Load (int argc, char *argv[]) |
|
|
{ |
|
|
{ |
|
|
ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop.
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
// start eio thread pool
|
|
|
|
|
|
ev_async_init(&eio_watcher, node_eio_cb); |
|
|
|
|
|
eio_init(eio_want_poll, NULL); |
|
|
|
|
|
|
|
|
|
|
|
V8::SetFlagsFromCommandLine(&argc, argv, true); |
|
|
|
|
|
V8::Initialize(); |
|
|
|
|
|
|
|
|
|
|
|
if(argc < 2) { |
|
|
|
|
|
fprintf(stderr, "No script was specified.\n"); |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string filename(argv[1]); |
|
|
|
|
|
|
|
|
|
|
|
HandleScope handle_scope; |
|
|
|
|
|
|
|
|
|
|
|
Persistent<Context> context = Context::New(NULL, ObjectTemplate::New()); |
|
|
|
|
|
Context::Scope context_scope(context); |
|
|
|
|
|
V8::SetFatalErrorHandler(OnFatalError); |
|
|
|
|
|
|
|
|
|
|
|
Local<Object> g = Context::GetCurrent()->Global(); |
|
|
|
|
|
|
|
|
|
|
|
V8::PauseProfiler(); // to be resumed in Connection::on_read
|
|
|
|
|
|
|
|
|
|
|
|
Local<Object> node = Object::New(); |
|
|
Local<Object> global_obj = Context::GetCurrent()->Global(); |
|
|
g->Set(String::New("node"), node); |
|
|
Local<Object> node_obj = Object::New(); |
|
|
|
|
|
|
|
|
NODE_SET_METHOD(node, "compile", compile); // internal
|
|
|
global_obj->Set(String::NewSymbol("node"), node_obj); |
|
|
NODE_SET_METHOD(node, "debug", debug); |
|
|
|
|
|
NODE_SET_METHOD(node, "reallyExit", node_exit); |
|
|
|
|
|
|
|
|
|
|
|
Local<Array> arguments = Array::New(argc); |
|
|
Local<Array> arguments = Array::New(argc); |
|
|
for (int i = 0; i < argc; i++) { |
|
|
for (int i = 0; i < argc; i++) { |
|
|
Local<String> arg = String::New(argv[i]); |
|
|
Local<String> arg = String::New(argv[i]); |
|
|
arguments->Set(Integer::New(i), arg); |
|
|
arguments->Set(Integer::New(i), arg); |
|
|
} |
|
|
} |
|
|
g->Set(String::New("ARGV"), arguments); |
|
|
global_obj->Set(String::NewSymbol("ARGV"), arguments); |
|
|
|
|
|
|
|
|
// BUILT-IN MODULES
|
|
|
NODE_SET_METHOD(node_obj, "compile", compile); |
|
|
Timer::Initialize(node); |
|
|
NODE_SET_METHOD(node_obj, "debug", debug); |
|
|
|
|
|
NODE_SET_METHOD(node_obj, "reallyExit", node_exit); |
|
|
|
|
|
|
|
|
|
|
|
Timer::Initialize(node_obj); |
|
|
|
|
|
|
|
|
Local<Object> constants = Object::New(); |
|
|
Local<Object> constants = Object::New(); |
|
|
node->Set(String::New("constants"), constants); |
|
|
node_obj->Set(String::NewSymbol("constants"), constants); |
|
|
DefineConstants(constants); |
|
|
DefineConstants(constants); |
|
|
|
|
|
|
|
|
Local<Object> fs = Object::New(); |
|
|
Local<Object> fs = Object::New(); |
|
|
node->Set(String::New("fs"), fs); |
|
|
node_obj->Set(String::NewSymbol("fs"), fs); |
|
|
File::Initialize(fs); |
|
|
File::Initialize(fs); |
|
|
|
|
|
|
|
|
Local<Object> tcp = Object::New(); |
|
|
Local<Object> tcp = Object::New(); |
|
|
node->Set(String::New("tcp"), tcp); |
|
|
node_obj->Set(String::New("tcp"), tcp); |
|
|
Acceptor::Initialize(tcp); |
|
|
Acceptor::Initialize(tcp); |
|
|
Connection::Initialize(tcp); |
|
|
Connection::Initialize(tcp); |
|
|
|
|
|
|
|
|
Local<Object> http = Object::New(); |
|
|
Local<Object> http = Object::New(); |
|
|
node->Set(String::New("http"), http); |
|
|
node_obj->Set(String::New("http"), http); |
|
|
HTTPServer::Initialize(http); |
|
|
HTTPServer::Initialize(http); |
|
|
HTTPConnection::Initialize(http); |
|
|
HTTPConnection::Initialize(http); |
|
|
|
|
|
|
|
@ -348,25 +325,52 @@ main (int argc, char *argv[]) |
|
|
ExecuteNativeJS("file.js", native_file); |
|
|
ExecuteNativeJS("file.js", native_file); |
|
|
ExecuteNativeJS("node.js", native_node); |
|
|
ExecuteNativeJS("node.js", native_node); |
|
|
|
|
|
|
|
|
ev_loop(EV_DEFAULT_UC_ 0); |
|
|
return scope.Close(node_obj); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// call node.exit()
|
|
|
static void |
|
|
Local<Value> exit_v = node->Get(String::New("exit")); |
|
|
CallExitHandler (Handle<Object> node_obj) |
|
|
|
|
|
{ |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
Local<Value> exit_v = node_obj->Get(String::New("exit")); |
|
|
assert(exit_v->IsFunction()); |
|
|
assert(exit_v->IsFunction()); |
|
|
Handle<Function> exit_f = Handle<Function>::Cast(exit_v); |
|
|
Handle<Function> exit_f = Handle<Function>::Cast(exit_v); |
|
|
TryCatch try_catch; |
|
|
TryCatch try_catch; |
|
|
exit_f->Call(g, 0, NULL); |
|
|
exit_f->Call(Context::GetCurrent()->Global(), 0, NULL); |
|
|
if (try_catch.HasCaught()) |
|
|
if (try_catch.HasCaught()) |
|
|
node::FatalException(try_catch); |
|
|
node::FatalException(try_catch); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
|
main (int argc, char *argv[]) |
|
|
|
|
|
{ |
|
|
|
|
|
ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop.
|
|
|
|
|
|
|
|
|
|
|
|
// start eio thread pool
|
|
|
|
|
|
ev_async_init(&eio_watcher, node_eio_cb); |
|
|
|
|
|
eio_init(eio_want_poll, NULL); |
|
|
|
|
|
|
|
|
|
|
|
V8::SetFlagsFromCommandLine(&argc, argv, true); |
|
|
|
|
|
V8::Initialize(); |
|
|
|
|
|
V8::SetFatalErrorHandler(OnFatalError); |
|
|
|
|
|
|
|
|
|
|
|
if(argc < 2) { |
|
|
|
|
|
fprintf(stderr, "No script was specified.\n"); |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HandleScope handle_scope; |
|
|
|
|
|
Persistent<Context> context = Context::New(NULL, ObjectTemplate::New()); |
|
|
|
|
|
Context::Scope context_scope(context); |
|
|
|
|
|
|
|
|
|
|
|
Local<Object> node_obj = Load(argc, argv); |
|
|
|
|
|
|
|
|
|
|
|
ev_loop(EV_DEFAULT_UC_ 0); // main event loop
|
|
|
|
|
|
|
|
|
|
|
|
CallExitHandler(node_obj); |
|
|
|
|
|
|
|
|
context.Dispose(); |
|
|
context.Dispose(); |
|
|
// The following line when uncommented causes an error.
|
|
|
V8::Dispose(); |
|
|
// To reproduce do this:
|
|
|
|
|
|
// > node --prof test-http_simple.js
|
|
|
|
|
|
//
|
|
|
|
|
|
// > curl http://localhost:8000/quit/
|
|
|
|
|
|
//
|
|
|
|
|
|
//V8::Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|