src: fix Environment::GetCurrent() usage
authorBen Noordhuis <info@bnoordhuis.nl>
Mon, 11 Nov 2013 21:02:03 +0000 (22:02 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 11 Nov 2013 09:40:28 +0000 (10:40 +0100)
Create a HandleScope before calling the Environment::GetCurrent() that
takes a v8::Isolate* as an argument because it creates a handle with
the call to v8::Isolate::CurrentContext().

21 files changed:
src/async-wrap-inl.h
src/cares_wrap.cc
src/fs_event_wrap.cc
src/node.cc
src/node_buffer.cc
src/node_contextify.cc
src/node_crypto.cc
src/node_file.cc
src/node_http_parser.cc
src/node_stat_watcher.cc
src/node_zlib.cc
src/pipe_wrap.cc
src/process_wrap.cc
src/signal_wrap.cc
src/smalloc.cc
src/stream_wrap.cc
src/tcp_wrap.cc
src/timer_wrap.cc
src/tls_wrap.cc
src/tty_wrap.cc
src/udp_wrap.cc

index b342cab..1de2958 100644 (file)
@@ -191,8 +191,8 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(
 template <typename TYPE>
 inline void AsyncWrap::AddAsyncListener(
     const v8::FunctionCallbackInfo<v8::Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   v8::HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   v8::Local<v8::Object> handle = args.This();
   v8::Local<v8::Value> listener = args[0];
@@ -211,8 +211,8 @@ inline void AsyncWrap::AddAsyncListener(
 template <typename TYPE>
 inline void AsyncWrap::RemoveAsyncListener(
     const v8::FunctionCallbackInfo<v8::Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   v8::HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   v8::Local<v8::Object> handle = args.This();
   v8::Local<v8::Value> listener = args[0];
index 7758749..8145c59 100644 (file)
@@ -776,8 +776,8 @@ class GetHostByNameWrap: public QueryWrap {
 
 template <class Wrap>
 static void Query(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(!args.IsConstructCall());
   assert(args[0]->IsObject());
@@ -911,8 +911,8 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
 
 
 static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsString());
@@ -958,8 +958,8 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
 
 
 static void GetServers(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   Local<Array> server_array = Array::New();
 
@@ -988,8 +988,8 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
 
 
 static void SetServers(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(args[0]->IsArray());
 
index 5dbc278..8563b40 100644 (file)
@@ -78,9 +78,6 @@ FSEventWrap::~FSEventWrap() {
 void FSEventWrap::Initialize(Handle<Object> target,
                              Handle<Value> unused,
                              Handle<Context> context) {
-  Environment* env = Environment::GetCurrent(context);
-  HandleScope handle_scope(env->isolate());
-
   Local<FunctionTemplate> t = FunctionTemplate::New(New);
   t->InstanceTemplate()->SetInternalFieldCount(1);
   t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "FSEvent"));
@@ -94,6 +91,7 @@ void FSEventWrap::Initialize(Handle<Object> target,
 
 void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
   assert(args.IsConstructCall());
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new FSEventWrap(env, args.This());
 }
index 3cb6a22..93926cd 100644 (file)
@@ -845,8 +845,8 @@ Local<Value> WinapiErrnoException(int errorno,
 
 
 void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(args[0]->IsObject());
   assert(args[1]->IsFunction());
@@ -875,8 +875,8 @@ void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
 
 
 void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(args[0]->IsObject() && args[1]->IsFunction());
 
@@ -1648,8 +1648,8 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
 
 
 void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   size_t rss;
   int err = uv_resident_set_memory(&rss);
@@ -1728,8 +1728,8 @@ typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);
 // when two contexts try to load the same shared object. Maybe have a shadow
 // cache that's a plain C list or hash table that's shared across contexts?
 void DLOpen(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   char symbol[1024], *base, *pos;
   uv_lib_t lib;
   int r;
@@ -1898,8 +1898,8 @@ void OnMessage(Handle<Message> message, Handle<Value> error) {
 
 
 static void Binding(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   Local<String> module = args[0]->ToString();
   String::Utf8Value module_v(module);
@@ -2181,6 +2181,7 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args);
 
 void NeedImmediateCallbackGetter(Local<String> property,
                                  const PropertyCallbackInfo<Value>& info) {
+  HandleScope handle_scope(info.GetIsolate());
   Environment* env = Environment::GetCurrent(info.GetIsolate());
   const uv_check_t* immediate_check_handle = env->immediate_check_handle();
   bool active = uv_is_active(
@@ -2193,8 +2194,8 @@ static void NeedImmediateCallbackSetter(
     Local<String> property,
     Local<Value> value,
     const PropertyCallbackInfo<void>& info) {
-  Environment* env = Environment::GetCurrent(info.GetIsolate());
   HandleScope handle_scope(info.GetIsolate());
+  Environment* env = Environment::GetCurrent(info.GetIsolate());
 
   uv_check_t* immediate_check_handle = env->immediate_check_handle();
   bool active = uv_is_active(
@@ -2241,12 +2242,16 @@ void StopProfilerIdleNotifier(Environment* env) {
 
 
 void StartProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
-  StartProfilerIdleNotifier(Environment::GetCurrent(args.GetIsolate()));
+  HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
+  StartProfilerIdleNotifier(env);
 }
 
 
 void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
-  StopProfilerIdleNotifier(Environment::GetCurrent(args.GetIsolate()));
+  HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
+  StopProfilerIdleNotifier(env);
 }
 
 
@@ -2761,6 +2766,7 @@ static void EnableDebug(bool wait_connect) {
   assert(debugger_running == false);
   Isolate* isolate = node_isolate;  // TODO(bnoordhuis) Multi-isolate support.
   Isolate::Scope isolate_scope(isolate);
+  HandleScope handle_scope(isolate);
   v8::Debug::SetDebugMessageDispatchHandler(DispatchMessagesDebugAgentCallback,
                                             false);
   debugger_running = v8::Debug::EnableAgent("node " NODE_VERSION,
@@ -2779,7 +2785,6 @@ static void EnableDebug(bool wait_connect) {
     return;  // Still starting up.
 
   Context::Scope context_scope(env->context());
-  HandleScope handle_scope(env->isolate());
   Local<Object> message = Object::New();
   message->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "cmd"),
                FIXED_ONE_BYTE_STRING(env->isolate(), "NODE_DEBUG_ENABLED"));
index 8c5bf33..c16129e 100644 (file)
@@ -127,8 +127,10 @@ Local<Object> New(Handle<String> string, enum encoding enc) {
 
 
 Local<Object> New(size_t length) {
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
-  return Buffer::New(env, length);
+  Local<Object> obj = Buffer::New(env, length);
+  return handle_scope.Close(obj);
 }
 
 
@@ -160,8 +162,10 @@ Local<Object> New(Environment* env, size_t length) {
 
 
 Local<Object> New(const char* data, size_t length) {
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
-  return Buffer::New(env, data, length);
+  Local<Object> obj = Buffer::New(env, data, length);
+  return handle_scope.Close(obj);
 }
 
 
@@ -199,8 +203,10 @@ Local<Object> New(char* data,
                   size_t length,
                   smalloc::FreeCallback callback,
                   void* hint) {
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
-  return Buffer::New(env, data, length, callback, hint);
+  Local<Object> obj = Buffer::New(env, data, length, callback, hint);
+  return handle_scope.Close(obj);
 }
 
 
@@ -223,8 +229,10 @@ Local<Object> New(Environment* env,
 
 
 Local<Object> Use(char* data, uint32_t length) {
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
-  return Buffer::Use(env, data, length);
+  Local<Object> obj = Buffer::Use(env, data, length);
+  return handle_scope.Close(obj);
 }
 
 
@@ -588,8 +596,8 @@ void ByteLength(const FunctionCallbackInfo<Value> &args) {
 
 // pass Buffer object to load prototype methods
 void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   assert(args[0]->IsFunction());
 
@@ -649,7 +657,6 @@ void Initialize(Handle<Object> target,
                 Handle<Value> unused,
                 Handle<Context> context) {
   Environment* env = Environment::GetCurrent(context);
-  HandleScope handle_scope(env->isolate());
   target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "setupBufferJS"),
               FunctionTemplate::New(SetupBufferJS)->GetFunction());
 }
index d1568f8..508e329 100644 (file)
@@ -218,8 +218,8 @@ class ContextifyContext {
 
 
   static void MakeContext(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
 
     if (!args[0]->IsObject()) {
       return ThrowTypeError("sandbox argument must be an object.");
@@ -449,8 +449,8 @@ class ContextifyScript : public WeakObject {
 
   // args: [options]
   static void RunInThisContext(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
 
     // Assemble arguments
     TryCatch try_catch;
index 28ce89c..9527673 100644 (file)
@@ -245,6 +245,7 @@ void SecureContext::Initialize(Environment* env, Handle<Object> target) {
 
 
 void SecureContext::New(const FunctionCallbackInfo<Value>& args) {
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new SecureContext(env, args.This());
 }
@@ -2105,6 +2106,7 @@ void CipherBase::Initialize(Environment* env, Handle<Object> target) {
 
 void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
   assert(args.IsConstructCall() == true);
+  HandleScope handle_scope(args.GetIsolate());
   CipherKind kind = args[0]->IsTrue() ? kCipher : kDecipher;
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new CipherBase(env, args.This(), kind);
@@ -2241,8 +2243,8 @@ bool CipherBase::Update(const char* data,
 
 
 void CipherBase::Update(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   CipherBase* cipher = Unwrap<CipherBase>(args.This());
 
@@ -2310,8 +2312,8 @@ bool CipherBase::Final(unsigned char** out, int *out_len) {
 
 
 void CipherBase::Final(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   CipherBase* cipher = Unwrap<CipherBase>(args.This());
 
@@ -2348,6 +2350,7 @@ void Hmac::Initialize(Environment* env, v8::Handle<v8::Object> target) {
 
 
 void Hmac::New(const FunctionCallbackInfo<Value>& args) {
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new Hmac(env, args.This());
 }
@@ -2586,6 +2589,7 @@ void Sign::Initialize(Environment* env, v8::Handle<v8::Object> target) {
 
 
 void Sign::New(const FunctionCallbackInfo<Value>& args) {
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new Sign(env, args.This());
 }
@@ -2768,6 +2772,7 @@ void Verify::Initialize(Environment* env, v8::Handle<v8::Object> target) {
 
 
 void Verify::New(const FunctionCallbackInfo<Value>& args) {
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new Verify(env, args.This());
 }
@@ -3449,8 +3454,8 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
 
 
 void PBKDF2(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   const char* type_error = NULL;
   char* pass = NULL;
@@ -3655,8 +3660,8 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
                                          RandomBytesRequest,
                                          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];
   RandomBytesCheck(req, argv);
   req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
@@ -3666,8 +3671,8 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
 
 template <bool pseudoRandom>
 void RandomBytes(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   // maybe allow a buffer to write to? cuts down on object creation
   // when generating random data in a loop
@@ -3776,6 +3781,7 @@ void Certificate::Initialize(Handle<Object> target) {
 
 
 void Certificate::New(const FunctionCallbackInfo<Value>& args) {
+  HandleScope handle_scope(args.GetIsolate());
   Environment* env = Environment::GetCurrent(args.GetIsolate());
   new Certificate(env, args.This());
 }
index 5650e4c..80f8573 100644 (file)
@@ -731,8 +731,8 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
 //             if null, write from the current position
 // 3 enc       encoding of string
 static void WriteString(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   if (!args[0]->IsInt32())
     return ThrowTypeError("First argument must be file descriptor");
index 1295701..66c6c7c 100644 (file)
@@ -337,8 +337,8 @@ class Parser : public WeakObject {
 
 
   static void New(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     http_parser_type type =
         static_cast<http_parser_type>(args[0]->Int32Value());
     assert(type == HTTP_REQUEST || type == HTTP_RESPONSE);
@@ -445,8 +445,8 @@ class Parser : public WeakObject {
 
 
   static void Reinitialize(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
 
     http_parser_type type =
         static_cast<http_parser_type>(args[0]->Int32Value());
@@ -461,8 +461,8 @@ class Parser : public WeakObject {
 
   template <bool should_pause>
   static void Pause(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     Parser* parser = Unwrap<Parser>(args.This());
     // Should always be called from the same context.
     assert(env == parser->env());
index b5a04c1..2f35d55 100644 (file)
@@ -99,8 +99,8 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
 
 void StatWatcher::New(const FunctionCallbackInfo<Value>& args) {
   assert(args.IsConstructCall());
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   new StatWatcher(env, args.This());
 }
 
index 5360b7a..43bec55 100644 (file)
@@ -313,8 +313,8 @@ class ZCtx : public WeakObject {
   }
 
   static void New(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
 
     if (args.Length() < 1 || !args[0]->IsInt32()) {
       return ThrowTypeError("Bad argument");
index a522775..e5b6836 100644 (file)
@@ -123,8 +123,8 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
   // Therefore we assert that we are not trying to call this as a
   // normal function.
   assert(args.IsConstructCall());
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   new PipeWrap(env, args.This(), args[0]->IsTrue());
 }
 
@@ -266,8 +266,8 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
 
 
 void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   PipeWrap* wrap = Unwrap<PipeWrap>(args.This());
 
index 7b8125c..83126be 100644 (file)
@@ -72,8 +72,8 @@ class ProcessWrap : public HandleWrap {
     // Therefore we assert that we are not trying to call this as a
     // normal function.
     assert(args.IsConstructCall());
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     new ProcessWrap(env, args.This());
   }
 
@@ -130,8 +130,8 @@ class ProcessWrap : public HandleWrap {
   }
 
   static void Spawn(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
 
     ProcessWrap* wrap = Unwrap<ProcessWrap>(args.This());
 
index b38ca38..1eade0b 100644 (file)
@@ -66,8 +66,8 @@ class SignalWrap : public HandleWrap {
     // Therefore we assert that we are not trying to call this as a
     // normal function.
     assert(args.IsConstructCall());
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     new SignalWrap(env, args.This());
   }
 
index 62a57fa..0e830bb 100644 (file)
@@ -297,8 +297,8 @@ void AllocDispose(const FunctionCallbackInfo<Value>& args) {
 
 
 void AllocDispose(Handle<Object> obj) {
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
-  HandleScope handle_scope(env->isolate());
 
   if (env->using_smalloc_alloc_cb()) {
     Local<Value> ext_v = obj->GetHiddenValue(env->smalloc_p_string());
@@ -360,6 +360,7 @@ void Alloc(Handle<Object> obj,
            enum ExternalArrayType type) {
   assert(!obj->HasIndexedPropertiesInExternalArrayData());
 
+  HandleScope handle_scope(node_isolate);
   Environment* env = Environment::GetCurrent(node_isolate);
   env->set_using_smalloc_alloc_cb(true);
 
index 507819e..69ba23d 100644 (file)
@@ -190,8 +190,8 @@ size_t StreamWrap::WriteBuffer(Handle<Value> val, uv_buf_t* buf) {
 
 
 void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   StreamWrap* wrap = Unwrap<StreamWrap>(args.This());
 
@@ -229,8 +229,8 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
 
 template <enum encoding encoding>
 void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   int err;
 
   StreamWrap* wrap = Unwrap<StreamWrap>(args.This());
@@ -313,8 +313,8 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
 
 
 void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   StreamWrap* wrap = Unwrap<StreamWrap>(args.This());
 
@@ -459,8 +459,8 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
 
 
 void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   StreamWrap* wrap = Unwrap<StreamWrap>(args.This());
 
index 85fff07..be05a29 100644 (file)
@@ -133,8 +133,8 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
   // Therefore we assert that we are not trying to call this as a
   // normal function.
   assert(args.IsConstructCall());
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   TCPWrap* wrap = new TCPWrap(env, args.This());
   assert(wrap);
 }
@@ -155,8 +155,8 @@ TCPWrap::~TCPWrap() {
 
 
 void TCPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   struct sockaddr_storage address;
 
   TCPWrap* wrap = Unwrap<TCPWrap>(args.This());
@@ -178,8 +178,8 @@ void TCPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
 
 
 void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   struct sockaddr_storage address;
 
   TCPWrap* wrap = Unwrap<TCPWrap>(args.This());
@@ -356,8 +356,8 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
 
 
 void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   TCPWrap* wrap = Unwrap<TCPWrap>(args.This());
 
@@ -388,8 +388,8 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
 
 
 void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   TCPWrap* wrap = Unwrap<TCPWrap>(args.This());
 
index 393def3..01a50f0 100644 (file)
@@ -77,8 +77,8 @@ class TimerWrap : public HandleWrap {
     // Therefore we assert that we are not trying to call this as a
     // normal function.
     assert(args.IsConstructCall());
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     new TimerWrap(env, args.This());
   }
 
@@ -144,8 +144,8 @@ class TimerWrap : public HandleWrap {
   }
 
   static void Now(const FunctionCallbackInfo<Value>& args) {
-    Environment* env = Environment::GetCurrent(args.GetIsolate());
     HandleScope handle_scope(args.GetIsolate());
+    Environment* env = Environment::GetCurrent(args.GetIsolate());
     uv_update_time(env->event_loop());
     double now = static_cast<double>(uv_now(env->event_loop()));
     args.GetReturnValue().Set(now);
index a18b6c1..2dd8016 100644 (file)
@@ -181,8 +181,8 @@ void TLSCallbacks::InitSSL() {
 
 
 void TLSCallbacks::Wrap(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   if (args.Length() < 1 || !args[0]->IsObject())
     return ThrowTypeError("First argument should be a StreamWrap instance");
index 6a0b282..0f7e390 100644 (file)
@@ -157,8 +157,8 @@ void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) {
 
 
 void TTYWrap::New(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   // This constructor should not be exposed to public javascript.
   // Therefore we assert that we are not trying to call this as a
index 5a16a55..8424ff0 100644 (file)
@@ -129,8 +129,8 @@ void UDPWrap::Initialize(Handle<Object> target,
 
 void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
   assert(args.IsConstructCall());
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
   new UDPWrap(env, args.This());
 }
 
@@ -243,8 +243,8 @@ void UDPWrap::DropMembership(const FunctionCallbackInfo<Value>& args) {
 
 
 void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   UDPWrap* wrap = Unwrap<UDPWrap>(args.This());
 
@@ -336,8 +336,8 @@ void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
 
 
 void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
-  Environment* env = Environment::GetCurrent(args.GetIsolate());
   HandleScope handle_scope(args.GetIsolate());
+  Environment* env = Environment::GetCurrent(args.GetIsolate());
 
   struct sockaddr_storage address;
   UDPWrap* wrap = Unwrap<UDPWrap>(args.This());