'src/node.cc',
'src/node_vars.cc',
'src/node_buffer.cc',
+ 'src/node_isolate.cc',
'src/node_constants.cc',
'src/node_extensions.cc',
'src/node_file.cc',
'src/node.h',
'src/node_vars.h',
'src/node_buffer.h',
+ 'src/node_isolate.h',
'src/node_constants.h',
'src/node_crypto.h',
'src/node_extensions.h',
if (status) {
// Error
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = Local<Value>::New(Null());
} else {
// Success
hints.ai_family = fam;
hints.ai_socktype = SOCK_STREAM;
- int r = uv_getaddrinfo(uv_default_loop(),
+ int r = uv_getaddrinfo(NODE_LOOP(),
&req_wrap->req_,
AfterGetAddrInfo,
*hostname,
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
assert(r == ARES_SUCCESS);
struct ares_options options;
- uv_ares_init_options(uv_default_loop(), &ares_channel, &options, 0);
+ uv_ares_init_options(NODE_LOOP(), &ares_channel, &options, 0);
assert(r == 0);
NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>);
String::Utf8Value path(args[0]->ToString());
- int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
+ int r = uv_fs_event_init(NODE_LOOP(), &wrap->handle_, *path, OnEvent, 0);
if (r == 0) {
// Check for persistent argument
if (!args[1]->IsTrue()) {
- uv_unref(uv_default_loop());
+ uv_unref(NODE_LOOP());
}
wrap->initialized_ = true;
} else {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
return scope.Close(Integer::New(r));
// assumption that a rename implicitly means an attribute change. Not too
// unreasonable, right? Still, we should revisit this before v1.0.
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
eventStr = String::Empty();
}
else if (events & UV_RENAME) {
}
wrap->unref = true;
- uv_unref(uv_default_loop());
+ uv_unref(NODE_LOOP());
return v8::Undefined();
}
assert(!wrap->object_.IsEmpty());
uv_close(wrap->handle__, OnClose);
-
HandleWrap::Ref(args);
wrap->StateChange();
static void Check(uv_check_t* watcher, int status) {
assert(watcher == &gc_check);
- tick_times[tick_time_head] = uv_now(uv_default_loop());
+ tick_times[tick_time_head] = uv_now(NODE_LOOP());
tick_time_head = (tick_time_head + 1) % RPM_SAMPLES;
StartGCTimer();
need_tick_cb = false;
if (uv_is_active((uv_handle_t*) &tick_spinner)) {
uv_idle_stop(&tick_spinner);
- uv_unref(uv_default_loop());
+ uv_unref(NODE_LOOP());
}
HandleScope scope;
// tick_spinner to keep the event loop alive long enough to handle it.
if (!uv_is_active((uv_handle_t*) &tick_spinner)) {
uv_idle_start(&tick_spinner, Spin);
- uv_ref(uv_default_loop());
+ uv_ref(NODE_LOOP());
}
return Undefined();
}
}
}
- double d = uv_now(uv_default_loop()) - TICK_TIME(3);
+ double d = uv_now(NODE_LOOP()) - TICK_TIME(3);
//printfb("timer d = %f\n", d);
v8::Handle<v8::Value> UVCounters(const v8::Arguments& args) {
HandleScope scope;
- uv_counters_t* c = &uv_default_loop()->counters;
+ uv_counters_t* c = &NODE_LOOP()->counters;
Local<Object> obj = Object::New();
RegisterSignalHandler(SIGTERM, SignalExit);
#endif // __POSIX__
+ // Don't use NODE_LOOP(), the node::Isolate() has not yet been initialized.
+ uv_loop_t* const loop = uv_default_loop();
+
uv_prepare_init(uv_default_loop(), &prepare_tick_watcher);
uv_prepare_start(&prepare_tick_watcher, PrepareTick);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
uv_check_init(uv_default_loop(), &check_tick_watcher);
uv_check_start(&check_tick_watcher, node::CheckTick);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
uv_idle_init(uv_default_loop(), &tick_spinner);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
uv_check_init(uv_default_loop(), &gc_check);
uv_check_start(&gc_check, node::Check);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
uv_idle_init(uv_default_loop(), &gc_idle);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
uv_timer_init(uv_default_loop(), &gc_timer);
- uv_unref(uv_default_loop());
+ uv_unref(loop);
V8::SetFatalErrorHandler(node::OnFatalError);
// main thread to execute a random bit of javascript - which will give V8
// control so it can handle whatever new message had been received on the
// debug thread.
- uv_async_init(uv_default_loop(), &debug_watcher, node::DebugMessageCallback);
+ uv_async_init(loop, &debug_watcher, node::DebugMessageCallback);
// unref it so that we exit the event loop despite it being active.
- uv_unref(uv_default_loop());
+ uv_unref(loop);
// Fetch a reference to the main isolate, so we have a reference to it
// even when we need it to access it from another (debugger) thread.
- node_isolate = Isolate::GetCurrent();
+ node_isolate = v8::Isolate::GetCurrent();
// If the --debug flag was specified then initialize the debug thread.
if (use_debug_agent) {
Persistent<v8::Context> context = v8::Context::New();
v8::Context::Scope context_scope(context);
+ // Create the main node::Isolate object
+ Isolate::New(uv_default_loop());
+
Handle<Object> process_l = SetupProcessObject(argc, argv);
+
v8_typed_array::AttachBindings(context->Global());
// Create all the objects, load modules, do everything.
// there are no watchers on the loop (except for the ones that were
// uv_unref'd) then this function exits. As long as there are active
// watchers, it blocks.
- uv_run(uv_default_loop());
+ uv_run(NODE_LOOP());
EmitExit(process_l);
#include <sys/stat.h>
#include <assert.h>
+#include <node_isolate.h>
#include <node_object_wrap.h>
#ifndef offset_of
#define NODE_STRINGIFY_HELPER(n) #n
#endif
+#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop())
+
namespace node {
int Start(int argc, char *argv[]);
req = new uv_work_t();
req->data = request;
- uv_queue_work(uv_default_loop(), req, EIO_PBKDF2, EIO_PBKDF2After);
+ uv_queue_work(NODE_LOOP(), req, EIO_PBKDF2, EIO_PBKDF2After);
+
return Undefined();
err:
Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
req->callback_ = Persistent<Function>::New(callback_v);
- uv_queue_work(uv_default_loop(),
+ uv_queue_work(NODE_LOOP(),
&req->work_req_,
RandomBytesWork<generator>,
RandomBytesAfter<generator>);
--- /dev/null
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#include "node_isolate.h"
+#include <assert.h>
+
+
+namespace node {
+
+
+Isolate* Isolate::New(uv_loop_t* loop) {
+ return new Isolate(loop);
+}
+
+
+Isolate::Isolate(uv_loop_t* loop) {
+ loop_ = loop;
+ isolate_ = v8::Isolate::GetCurrent();
+ assert(isolate_->GetData() == NULL);
+ isolate_->SetData(this);
+}
+
+
+} // namespace node
--- /dev/null
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+#ifndef SRC_NODE_ISOLATE_H_
+#define SRC_NODE_ISOLATE_H_
+
+#include <v8.h>
+#include <uv.h>
+
+#ifdef NDEBUG
+# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr))
+#else
+# include <assert.h>
+# define NODE_ISOLATE_CHECK(ptr) \
+ do { \
+ node::Isolate* data_ = node::Isolate::GetCurrent(); \
+ assert(data_ == (ptr)); \
+ } \
+ while (0)
+#endif
+
+
+namespace node {
+
+class Isolate {
+public:
+ static Isolate* New(uv_loop_t* loop);
+
+ static Isolate* GetCurrent() {
+ return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
+ }
+
+ uv_loop_t* GetLoop() {
+ NODE_ISOLATE_CHECK(this);
+ return loop_;
+ }
+
+ operator v8::Isolate*() {
+ NODE_ISOLATE_CHECK(this);
+ return isolate_;
+ }
+
+private:
+ Isolate(uv_loop_t* loop);
+ v8::Isolate* isolate_;
+ uv_loop_t* loop_;
+};
+
+} // namespace node
+
+#endif // SRC_NODE_ISOLATE_H_
uv_work_t* work_req = new uv_work_t();
work_req->data = req_wrap;
- uv_queue_work(uv_default_loop(),
+ uv_queue_work(NODE_LOOP(),
work_req,
ZCtx<mode>::Process,
ZCtx<mode>::After);
PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
: StreamWrap(object, (uv_stream_t*) &handle_) {
- int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
+ int r = uv_pipe_init(NODE_LOOP(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
handle_.data = reinterpret_cast<void*>(this);
int r = uv_pipe_bind(&wrap->handle_, *name);
// Error starting the pipe.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the pipe.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif
- int r = uv_spawn(uv_default_loop(), &wrap->process_, options);
+ int r = uv_spawn(NODE_LOOP(), &wrap->process_, options);
wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap);
delete [] options.env;
}
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
int r = uv_process_kill(&wrap->process_, signal);
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
}
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
int r = uv_read_stop(wrap->stream_);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
slab_used -= buf.len;
}
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
MakeCallback(wrap->object_, "onread", 0, NULL);
return;
}
wrap->UpdateWriteQueueSize();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
wrap->UpdateWriteQueueSize();
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
HandleScope scope;
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {
TCPWrap::TCPWrap(Handle<Object> object)
: StreamWrap(object, (uv_stream_t*) &handle_) {
- int r = uv_tcp_init(uv_default_loop(), &handle_);
+ int r = uv_tcp_init(NODE_LOOP(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void.
UpdateWriteQueueSize();
Local<Object> sockname = Object::New();
if (r != 0) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
} else {
family = address.ss_family;
Local<Object> sockname = Object::New();
if (r != 0) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
} else {
family = address.ss_family;
int r = uv_tcp_nodelay(&wrap->handle_, 1);
if (r)
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
if (r)
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0);
if (r)
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return Undefined();
}
int r = uv_tcp_bind(&wrap->handle_, address);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
int r = uv_tcp_bind6(&wrap->handle_, address);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
// Successful accept. Call the onconnection callback in JavaScript land.
argv[0] = client_obj;
} else {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = v8::Null();
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[3] = {
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
: HandleWrap(object, (uv_handle_t*) &handle_) {
active_ = false;
- int r = uv_timer_init(uv_default_loop(), &handle_);
+ int r = uv_timer_init(NODE_LOOP(), &handle_);
assert(r == 0);
handle_.data = this;
// uv_timer_init adds a loop reference. (That is, it calls uv_ref.) This
// is not the behavior we want in Node. Timers should not increase the
// ref count of the loop except when active.
- uv_unref(uv_default_loop());
+ uv_unref(NODE_LOOP());
}
~TimerWrap() {
- if (!active_) uv_ref(uv_default_loop());
+ if (!active_) uv_ref(NODE_LOOP());
}
void StateChange() {
if (!was_active && active_) {
// If our state is changing from inactive to active, we
// increase the loop's reference count.
- uv_ref(uv_default_loop());
+ uv_ref(NODE_LOOP());
} else if (was_active && !active_) {
// If our state is changing from active to inactive, we
// decrease the loop's reference count.
- uv_unref(uv_default_loop());
+ uv_unref(NODE_LOOP());
}
}
int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat);
// Error starting the timer.
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
int r = uv_timer_stop(&wrap->handle_);
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
int r = uv_timer_again(&wrap->handle_);
- if (r) SetErrno(uv_last_error(uv_default_loop()));
+ if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange();
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
- if (repeat < 0) SetErrno(uv_last_error(uv_default_loop()));
+ if (repeat < 0) SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(repeat));
}
int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return v8::Undefined();
}
int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
return scope.Close(Integer::New(r));
TTYWrap(Handle<Object> object, int fd, bool readable)
: StreamWrap(object, (uv_stream_t*)&handle_) {
- uv_tty_init(uv_default_loop(), &handle_, fd, readable);
+ uv_tty_init(NODE_LOOP(), &handle_, fd, readable);
}
uv_tty_t handle_;
UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) {
- int r = uv_udp_init(uv_default_loop(), &handle_);
+ int r = uv_udp_init(NODE_LOOP(), &handle_);
assert(r == 0); // can't fail anyway
handle_.data = reinterpret_cast<void*>(this);
}
}
if (r)
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r));
}
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap;
return Null();
}
// UV_EALREADY means that the socket is already bound but that's okay
int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
- if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) {
- SetErrno(uv_last_error(uv_default_loop()));
+ if (r && uv_last_error(NODE_LOOP()).code != UV_EALREADY) {
+ SetErrno(uv_last_error(NODE_LOOP()));
return False();
}
return scope.Close(sockname);
}
else {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
return Null();
}
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
Local<Value> argv[4] = {
};
if (nread == -1) {
- SetErrno(uv_last_error(uv_default_loop()));
+ SetErrno(uv_last_error(NODE_LOOP()));
}
else {
Local<Object> rinfo = Object::New();