src: fix Context::Scope usage
authorBen Noordhuis <info@bnoordhuis.nl>
Mon, 11 Nov 2013 09:53:00 +0000 (10:53 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Tue, 12 Nov 2013 21:06:48 +0000 (22:06 +0100)
env->context() may or may not create a new Local.  It currently does
not but don't depend on that behavior, create a HandleScope first.

17 files changed:
src/cares_wrap.cc
src/env-inl.h
src/fs_event_wrap.cc
src/handle_wrap.cc
src/node.cc
src/node_crypto.cc
src/node_file.cc
src/node_stat_watcher.cc
src/node_zlib.cc
src/pipe_wrap.cc
src/process_wrap.cc
src/signal_wrap.cc
src/stream_wrap.cc
src/tcp_wrap.cc
src/timer_wrap.cc
src/tls_wrap.cc
src/udp_wrap.cc

index 8145c59..5cc19f4 100644 (file)
@@ -276,8 +276,8 @@ class QueryWrap : public AsyncWrap {
   }
 
   void CallOnComplete(Local<Value> answer) {
-    Context::Scope context_scope(env()->context());
     HandleScope handle_scope(env()->isolate());
+    Context::Scope context_scope(env()->context());
     Local<Value> argv[] = {
       Integer::New(0, env()->isolate()),
       answer
@@ -286,8 +286,8 @@ class QueryWrap : public AsyncWrap {
   }
 
   void CallOnComplete(Local<Value> answer, Local<Value> family) {
-    Context::Scope context_scope(env()->context());
     HandleScope handle_scope(env()->isolate());
+    Context::Scope context_scope(env()->context());
     Local<Value> argv[] = {
       Integer::New(0, env()->isolate()),
       answer,
@@ -298,8 +298,8 @@ class QueryWrap : public AsyncWrap {
 
   void ParseError(int status) {
     assert(status != ARES_SUCCESS);
-    Context::Scope context_scope(env()->context());
     HandleScope handle_scope(env()->isolate());
+    Context::Scope context_scope(env()->context());
     Local<Value> arg;
     switch (status) {
 #define V(code)                                                               \
@@ -800,8 +800,8 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
   GetAddrInfoReqWrap* req_wrap = static_cast<GetAddrInfoReqWrap*>(req->data);
   Environment* env = req_wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   Local<Value> argv[] = {
     Integer::New(status, node_isolate),
index d9aed32..4578f6e 100644 (file)
@@ -165,8 +165,8 @@ inline Environment::Environment(v8::Local<v8::Context> context)
       using_smalloc_alloc_cb_(false),
       context_(context->GetIsolate(), context) {
   // We'll be creating new objects so make sure we've entered the context.
-  v8::Context::Scope context_scope(context);
   v8::HandleScope handle_scope(isolate());
+  v8::Context::Scope context_scope(context);
   set_binding_cache_object(v8::Object::New());
   set_module_load_list_array(v8::Array::New());
   RB_INIT(&cares_task_list_);
index 8563b40..79538b7 100644 (file)
@@ -137,8 +137,8 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
   FSEventWrap* wrap = static_cast<FSEventWrap*>(handle->data);
   Environment* env = wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   assert(wrap->persistent().IsEmpty() == false);
 
index be37d63..553cf79 100644 (file)
@@ -117,8 +117,8 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
   // But the handle pointer should be gone.
   assert(wrap->handle__ == NULL);
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
   Local<Object> object = wrap->object();
 
   if (wrap->flags_ & kCloseCallback) {
index 3153392..0d8985f 100644 (file)
@@ -3155,8 +3155,8 @@ void AtExit(void (*cb)(void* arg), void* arg) {
 
 void EmitExit(Environment* env) {
   // process.emit('exit')
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
   Local<Object> process_object = env->process_object();
   process_object->Set(FIXED_ONE_BYTE_STRING(node_isolate, "_exiting"),
                       True(node_isolate));
index f116232..c1dc616 100644 (file)
@@ -1789,8 +1789,8 @@ void Connection::SSLInfoCallback(const SSL *ssl_, int where, int ret) {
   SSL* ssl = const_cast<SSL*>(ssl_);
   Connection* conn = static_cast<Connection*>(SSL_get_app_data(ssl));
   Environment* env = conn->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   if (where & SSL_CB_HANDSHAKE_START) {
     conn->MakeCallback(env->onhandshakestart_string(), 0, NULL);
@@ -3447,8 +3447,8 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
   assert(status == 0);
   PBKDF2Request* req = CONTAINER_OF(work_req, PBKDF2Request, work_req_);
   Environment* env = req->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
   Local<Value> argv[2];
   EIO_PBKDF2After(req, argv);
   req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
index 80f8573..f829fb5 100644 (file)
@@ -109,8 +109,8 @@ static void After(uv_fs_t *req) {
   req_wrap->ReleaseEarly();  // Free memory that's no longer used now.
 
   Environment* env = req_wrap->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // there is always at least one argument. "error"
   int argc = 1;
index 2f35d55..df896fa 100644 (file)
@@ -86,8 +86,8 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
   StatWatcher* wrap = static_cast<StatWatcher*>(handle->data);
   assert(wrap->watcher_ == handle);
   Environment* env = wrap->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
   Local<Value> argv[] = {
     BuildStatsObject(env, curr),
     BuildStatsObject(env, prev),
@@ -124,8 +124,8 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
 void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
   StatWatcher* wrap = Unwrap<StatWatcher>(args.This());
   Environment* env = wrap->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
   wrap->MakeCallback(env->onstop_string(), 0, NULL);
   wrap->Stop();
 }
index 43bec55..c4da32e 100644 (file)
@@ -255,8 +255,8 @@ class ZCtx : public WeakObject {
     ZCtx* ctx = CONTAINER_OF(work_req, ZCtx, work_req_);
     Environment* env = ctx->env();
 
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
 
     // Acceptable error states depend on the type of zlib stream.
     switch (ctx->err_) {
index e5b6836..d4f01eb 100644 (file)
@@ -181,8 +181,8 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
   assert(&pipe_wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle));
 
   Environment* env = pipe_wrap->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // We should not be getting this callback if someone as already called
   // uv_close() on the handle.
@@ -220,8 +220,8 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
   assert(req_wrap->env() == wrap->env());
   Environment* env = wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // The wrap and request objects should still be there.
   assert(req_wrap->persistent().IsEmpty() == false);
index 83126be..2ced3de 100644 (file)
@@ -276,8 +276,8 @@ class ProcessWrap : public HandleWrap {
     assert(&wrap->process_ == handle);
 
     Environment* env = wrap->env();
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
 
     Local<Value> argv[] = {
       Number::New(node_isolate, static_cast<double>(exit_status)),
index 1eade0b..821b6dc 100644 (file)
@@ -100,8 +100,8 @@ class SignalWrap : public HandleWrap {
   static void OnSignal(uv_signal_t* handle, int signum) {
     SignalWrap* wrap = CONTAINER_OF(handle, SignalWrap, handle_);
     Environment* env = wrap->env();
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
 
     Local<Value> arg = Integer::New(signum, env->isolate());
     wrap->MakeCallback(env->onsignal_string(), 1, &arg);
index 2274eff..7779762 100644 (file)
@@ -431,8 +431,8 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
   StreamWrap* wrap = req_wrap->wrap();
   Environment* env = wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // The wrap and request objects should still be there.
   assert(req_wrap->persistent().IsEmpty() == false);
@@ -483,8 +483,8 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
   assert(req_wrap->persistent().IsEmpty() == false);
   assert(wrap->persistent().IsEmpty() == false);
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   Local<Object> req_wrap_obj = req_wrap->object();
   Local<Value> argv[3] = {
@@ -552,8 +552,8 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
                                  const uv_buf_t* buf,
                                  uv_handle_type pending) {
   Environment* env = wrap()->env();
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   Local<Value> argv[] = {
     Integer::New(nread, node_isolate),
index be05a29..dad505d 100644 (file)
@@ -297,8 +297,8 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
   assert(&tcp_wrap->handle_ == reinterpret_cast<uv_tcp_t*>(handle));
   Environment* env = tcp_wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // We should not be getting this callback if someone as already called
   // uv_close() on the handle.
@@ -333,8 +333,8 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
   assert(req_wrap->env() == wrap->env());
   Environment* env = wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   // The wrap and request objects should still be there.
   assert(req_wrap->persistent().IsEmpty() == false);
index 01a50f0..7a0116e 100644 (file)
@@ -137,8 +137,8 @@ class TimerWrap : public HandleWrap {
   static void OnTimeout(uv_timer_t* handle, int status) {
     TimerWrap* wrap = static_cast<TimerWrap*>(handle->data);
     Environment* env = wrap->env();
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
     Local<Value> argv[1] = { Integer::New(status, node_isolate) };
     wrap->MakeCallback(kOnTimeout, ARRAY_SIZE(argv), argv);
   }
index 5c837fa..287c90c 100644 (file)
@@ -308,8 +308,8 @@ void TLSCallbacks::EncOutCb(uv_write_t* req, int status) {
       return;
 
     // Notify about error
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
     Local<Value> arg = String::Concat(
         FIXED_ONE_BYTE_STRING(node_isolate, "write cb error, status: "),
         Integer::New(status, node_isolate)->ToString());
@@ -367,8 +367,8 @@ void TLSCallbacks::ClearOut() {
   if (!hello_parser_.IsEnded())
     return;
 
-  Context::Scope context_scope(env()->context());
   HandleScope handle_scope(env()->isolate());
+  Context::Scope context_scope(env()->context());
 
   assert(ssl_ != NULL);
 
@@ -418,8 +418,8 @@ bool TLSCallbacks::ClearIn() {
     return true;
   }
 
-  Context::Scope context_scope(env()->context());
   HandleScope handle_scope(env()->isolate());
+  Context::Scope context_scope(env()->context());
 
   // Error or partial write
   int err;
@@ -484,8 +484,8 @@ int TLSCallbacks::DoWrite(WriteWrap* w,
 
   if (i != count) {
     int err;
-    Context::Scope context_scope(env()->context());
     HandleScope handle_scope(env()->isolate());
+    Context::Scope context_scope(env()->context());
     Handle<Value> arg = GetSSLError(written, &err);
     if (!arg.IsEmpty()) {
       MakeCallback(env()->onerror_string(), 1, &arg);
@@ -524,8 +524,8 @@ void TLSCallbacks::DoRead(uv_stream_t* handle,
   if (nread < 0)  {
     // Error should be emitted only after all data was read
     ClearOut();
-    Context::Scope context_scope(env()->context());
     HandleScope handle_scope(env()->isolate());
+    Context::Scope context_scope(env()->context());
     Local<Value> arg = Integer::New(nread, node_isolate);
     wrap()->MakeCallback(env()->onread_string(), 1, &arg);
     return;
index 8424ff0..a563a7e 100644 (file)
@@ -364,8 +364,8 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
   SendWrap* req_wrap = static_cast<SendWrap*>(req->data);
   if (req_wrap->have_callback()) {
     Environment* env = req_wrap->env();
-    Context::Scope context_scope(env->context());
     HandleScope handle_scope(env->isolate());
+    Context::Scope context_scope(env->context());
     Local<Value> arg = Integer::New(status, node_isolate);
     req_wrap->MakeCallback(env->oncomplete_string(), 1, &arg);
   }
@@ -400,8 +400,8 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
   UDPWrap* wrap = static_cast<UDPWrap*>(handle->data);
   Environment* env = wrap->env();
 
-  Context::Scope context_scope(env->context());
   HandleScope handle_scope(env->isolate());
+  Context::Scope context_scope(env->context());
 
   Local<Object> wrap_obj = wrap->object();
   Local<Value> argv[] = {