#include <assert.h>
#include <node.h>
#include <req_wrap.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <uv.h>
#include <string.h>
if (status) {
// Error
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
argv[0] = Local<Value>::New(Null());
} else {
// Success
hints.ai_family = fam;
hints.ai_socktype = SOCK_STREAM;
- int r = uv_getaddrinfo(NODE_LOOP(),
+ int r = uv_getaddrinfo(Loop(),
&req_wrap->req_,
AfterGetAddrInfo,
*hostname,
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
assert(r == ARES_SUCCESS);
struct ares_options options;
- uv_ares_init_options(NODE_LOOP(), &ares_channel, &options, 0);
+ uv_ares_init_options(Loop(), &ares_channel, &options, 0);
assert(r == 0);
NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>);
#include <node.h>
#include <handle_wrap.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <stdlib.h>
String::Utf8Value path(args[0]->ToString());
- int r = uv_fs_event_init(NODE_LOOP(), &wrap->handle_, *path, OnEvent, 0);
+ int r = uv_fs_event_init(Loop(), &wrap->handle_, *path, OnEvent, 0);
if (r == 0) {
// Check for persistent argument
if (!args[1]->IsTrue()) {
- uv_unref(NODE_LOOP());
+ uv_unref(Loop());
}
wrap->initialized_ = true;
} else {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(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(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
eventStr = String::Empty();
}
else if (events & UV_RENAME) {
#include <node.h>
#include <handle_wrap.h>
-#include <node_isolate.h>
+#include <node_vars.h>
namespace node {
}
wrap->unref = true;
- uv_unref(NODE_LOOP());
+ uv_unref(Loop());
return v8::Undefined();
}
char** argv);
+uv_loop_t* Loop() {
+#if defined(HAVE_ISOLATES) && HAVE_ISOLATES
+ return Isolate::GetCurrent()->GetLoop();
+#else
+ return uv_default_loop();
+#endif
+}
+
+
static void StartGCTimer () {
if (!uv_is_active((uv_handle_t*) &gc_timer)) {
uv_timer_start(&gc_timer, node::CheckStatus, 5000, 5000);
static void Check(uv_check_t* watcher, int status) {
assert(watcher == &gc_check);
- tick_times[tick_time_head] = uv_now(NODE_LOOP());
+ tick_times[tick_time_head] = uv_now(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(NODE_LOOP());
+ uv_unref(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(NODE_LOOP());
+ uv_ref(Loop());
}
return Undefined();
}
}
}
- double d = uv_now(NODE_LOOP()) - TICK_TIME(3);
+ double d = uv_now(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 = &NODE_LOOP()->counters;
+ uv_counters_t* c = &Loop()->counters;
Local<Object> obj = Object::New();
#define NODE_STRINGIFY_HELPER(n) #n
#endif
-#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop())
-
namespace node {
int Start(int argc, char *argv[]);
void Load(v8::Handle<v8::Object> process);
void EmitExit(v8::Handle<v8::Object> process);
+// Returns the loop for the current isolate. If compiled with
+// --without-isolates then this will always return uv_default_loop();
+uv_loop_t* Loop();
+
#define NODE_PSYMBOL(s) \
v8::Persistent<v8::String>::New(v8::String::NewSymbol(s))
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <node_root_certs.h>
#include <string.h>
req = new uv_work_t();
req->data = request;
- uv_queue_work(NODE_LOOP(), req, EIO_PBKDF2, EIO_PBKDF2After);
+ uv_queue_work(Loop(), req, EIO_PBKDF2, EIO_PBKDF2After);
return Undefined();
Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
req->callback_ = Persistent<Function>::New(callback_v);
- uv_queue_work(NODE_LOOP(),
+ uv_queue_work(Loop(),
&req->work_req_,
RandomBytesWork<generator>,
RandomBytesAfter<generator>);
#include "node.h"
#include "node_file.h"
#include "node_buffer.h"
-#include <node_isolate.h>
+#include <node_vars.h>
#ifdef __POSIX__
# include "node_stat_watcher.h"
#endif
#define ASYNC_CALL(func, callback, ...) \
FSReqWrap* req_wrap = new FSReqWrap(); \
- int r = uv_fs_##func(NODE_LOOP(), &req_wrap->req_, \
+ int r = uv_fs_##func(Loop(), &req_wrap->req_, \
__VA_ARGS__, After); \
assert(r == 0); \
req_wrap->object_->Set(oncomplete_sym, callback); \
#define SYNC_CALL(func, path, ...) \
fs_req_wrap req_wrap; \
- int result = uv_fs_##func(NODE_LOOP(), &req_wrap.req, __VA_ARGS__, NULL); \
+ int result = uv_fs_##func(Loop(), &req_wrap.req, __VA_ARGS__, NULL); \
if (result < 0) { \
- int code = uv_last_error(NODE_LOOP()).code; \
+ int code = uv_last_error(Loop()).code; \
return ThrowException(UVException(code, #func, "", path)); \
}
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <req_wrap.h>
#include <node_vars.h>
uv_work_t* work_req = new uv_work_t();
work_req->data = req_wrap;
- uv_queue_work(NODE_LOOP(),
+ uv_queue_work(Loop(),
work_req,
ZCtx<mode>::Process,
ZCtx<mode>::After);
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <req_wrap.h>
#include <handle_wrap.h>
#include <stream_wrap.h>
PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
: StreamWrap(object, (uv_stream_t*) &handle_) {
- int r = uv_pipe_init(NODE_LOOP(), &handle_, ipc);
+ int r = uv_pipe_init(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(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(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(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
Local<Value> argv[3] = {
#include <node.h>
#include <handle_wrap.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <pipe_wrap.h>
#include <string.h>
#include <stdlib.h>
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif
- int r = uv_spawn(NODE_LOOP(), &wrap->process_, options);
+ int r = uv_spawn(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(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
int r = uv_process_kill(&wrap->process_, signal);
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <handle_wrap.h>
#include <stream_wrap.h>
#include <tcp_wrap.h>
}
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
int r = uv_read_stop(wrap->stream_);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
slab_used -= buf.len;
}
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
MakeCallback(wrap->object_, "onread", 0, NULL);
return;
}
wrap->UpdateWriteQueueSize();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
wrap->UpdateWriteQueueSize();
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
HandleScope scope;
if (status) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
Local<Value> argv[3] = {
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <req_wrap.h>
#include <handle_wrap.h>
#include <stream_wrap.h>
TCPWrap::TCPWrap(Handle<Object> object)
: StreamWrap(object, (uv_stream_t*) &handle_) {
- int r = uv_tcp_init(NODE_LOOP(), &handle_);
+ int r = uv_tcp_init(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(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
} else {
family = address.ss_family;
Local<Object> sockname = Object::New();
if (r != 0) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
} else {
family = address.ss_family;
int r = uv_tcp_nodelay(&wrap->handle_, 1);
if (r)
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return Undefined();
}
int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
if (r)
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return Undefined();
}
int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0);
if (r)
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return Undefined();
}
int r = uv_tcp_bind(&wrap->handle_, address);
// Error starting the tcp.
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(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(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(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(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(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(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
argv[0] = v8::Null();
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
Local<Value> argv[3] = {
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
delete req_wrap;
return scope.Close(v8::Null());
} else {
#include <node.h>
#include <handle_wrap.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#define UNWRAP \
assert(!args.Holder().IsEmpty()); \
: HandleWrap(object, (uv_handle_t*) &handle_) {
active_ = false;
- int r = uv_timer_init(NODE_LOOP(), &handle_);
+ int r = uv_timer_init(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(NODE_LOOP());
+ uv_unref(Loop());
}
~TimerWrap() {
- if (!active_) uv_ref(NODE_LOOP());
+ if (!active_) uv_ref(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(NODE_LOOP());
+ uv_ref(Loop());
} else if (was_active && !active_) {
// If our state is changing from active to inactive, we
// decrease the loop's reference count.
- uv_unref(NODE_LOOP());
+ uv_unref(Loop());
}
}
int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat);
// Error starting the timer.
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
wrap->StateChange();
int r = uv_timer_stop(&wrap->handle_);
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
wrap->StateChange();
int r = uv_timer_again(&wrap->handle_);
- if (r) SetErrno(uv_last_error(NODE_LOOP()));
+ if (r) SetErrno(uv_last_error(Loop()));
wrap->StateChange();
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
- if (repeat < 0) SetErrno(uv_last_error(NODE_LOOP()));
+ if (repeat < 0) SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(repeat));
}
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <req_wrap.h>
#include <handle_wrap.h>
#include <stream_wrap.h>
int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return v8::Undefined();
}
int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
return scope.Close(Integer::New(r));
TTYWrap(Handle<Object> object, int fd, bool readable)
: StreamWrap(object, (uv_stream_t*)&handle_) {
- uv_tty_init(NODE_LOOP(), &handle_, fd, readable);
+ uv_tty_init(Loop(), &handle_, fd, readable);
}
uv_tty_t handle_;
#include <node.h>
#include <node_buffer.h>
-#include <node_isolate.h>
+#include <node_vars.h>
#include <req_wrap.h>
#include <handle_wrap.h>
UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) {
- int r = uv_udp_init(NODE_LOOP(), &handle_);
+ int r = uv_udp_init(Loop(), &handle_);
assert(r == 0); // can't fail anyway
handle_.data = reinterpret_cast<void*>(this);
}
}
if (r)
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return scope.Close(Integer::New(r));
}
req_wrap->Dispatched();
if (r) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(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(NODE_LOOP()).code != UV_EALREADY) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ if (r && uv_last_error(Loop()).code != UV_EALREADY) {
+ SetErrno(uv_last_error(Loop()));
return False();
}
return scope.Close(sockname);
}
else {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
return Null();
}
}
assert(wrap->object_.IsEmpty() == false);
if (status) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
Local<Value> argv[4] = {
};
if (nread == -1) {
- SetErrno(uv_last_error(NODE_LOOP()));
+ SetErrno(uv_last_error(Loop()));
}
else {
Local<Object> rinfo = Object::New();