Skip to content

Commit

Permalink
src: remove unnecessary HandleScopes
Browse files Browse the repository at this point in the history
API callback functions don't need to create a v8::HandleScope instance
because V8 already creates one in the JS->C++ adapter frame.

PR-URL: node-forward/node#16
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
bnoordhuis authored and indutny committed Oct 11, 2014
1 parent b2e5199 commit 97585b0
Show file tree
Hide file tree
Showing 26 changed files with 0 additions and 386 deletions.
7 changes: 0 additions & 7 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,6 @@ class GetHostByNameWrap: public QueryWrap {

template <class Wrap>
static void Query(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

assert(!args.IsConstructCall());
Expand Down Expand Up @@ -992,7 +991,6 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,

static void IsIP(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

node::Utf8Value ip(args[0]);
char address_buffer[sizeof(struct in6_addr)];
Expand All @@ -1008,7 +1006,6 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {


static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

assert(args[0]->IsObject());
Expand Down Expand Up @@ -1062,7 +1059,6 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {

static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope handle_scope(env->isolate());

CHECK(args[0]->IsObject());
CHECK(args[1]->IsString());
Expand Down Expand Up @@ -1094,7 +1090,6 @@ static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {


static void GetServers(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

Local<Array> server_array = Array::New(env->isolate());
Expand Down Expand Up @@ -1124,7 +1119,6 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {


static void SetServers(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

assert(args[0]->IsArray());
Expand Down Expand Up @@ -1194,7 +1188,6 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {

static void StrError(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
const char* errmsg = ares_strerror(args[0]->Int32Value());
args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg));
}
Expand Down
5 changes: 0 additions & 5 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ 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());
}


void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());

Expand Down Expand Up @@ -186,9 +184,6 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,


void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());

if (wrap == NULL || wrap->initialized_ == false)
Expand Down
7 changes: 0 additions & 7 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ using v8::Value;


void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

if (wrap != NULL && wrap->handle__ != NULL) {
Expand All @@ -54,9 +51,6 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {


void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

if (wrap != NULL && wrap->handle__ != NULL) {
Expand All @@ -68,7 +62,6 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {

void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

Expand Down
26 changes: 0 additions & 26 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,6 @@ Local<Value> WinapiErrnoException(Isolate* isolate,


void SetupAsyncListener(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

assert(args[0]->IsObject());
Expand Down Expand Up @@ -979,7 +978,6 @@ void RunMicrotasks(const FunctionCallbackInfo<Value>& args) {


void SetupNextTick(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

assert(args[0]->IsObject());
Expand Down Expand Up @@ -1552,7 +1550,6 @@ static Local<Value> ExecuteString(Environment* env,

static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

Local<Array> ary = Array::New(args.GetIsolate());
QUEUE* q = NULL;
Expand All @@ -1573,7 +1570,6 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
// implemented here for consistency with GetActiveRequests().
void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

Local<Array> ary = Array::New(env->isolate());
QUEUE* q = NULL;
Expand Down Expand Up @@ -1603,7 +1599,6 @@ static void Abort(const FunctionCallbackInfo<Value>& args) {

static void Chdir(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (args.Length() != 1 || !args[0]->IsString()) {
// FIXME(bnoordhuis) ThrowTypeError?
Expand All @@ -1620,7 +1615,6 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {

static void Cwd(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
char buf[MAX_PATH * 4];
Expand All @@ -1644,7 +1638,6 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) {

static void Umask(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
uint32_t old;

if (args.Length() < 1 || args[0]->IsUndefined()) {
Expand Down Expand Up @@ -1793,7 +1786,6 @@ static void GetGid(const FunctionCallbackInfo<Value>& args) {

static void SetGid(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsUint32() && !args[0]->IsString()) {
return env->ThrowTypeError("setgid argument must be a number or a string");
Expand All @@ -1813,7 +1805,6 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) {

static void SetUid(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsUint32() && !args[0]->IsString()) {
return env->ThrowTypeError("setuid argument must be a number or a string");
Expand All @@ -1833,7 +1824,6 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) {

static void GetGroups(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

int ngroups = getgroups(0, NULL);

Expand Down Expand Up @@ -1872,7 +1862,6 @@ static void GetGroups(const FunctionCallbackInfo<Value>& args) {

static void SetGroups(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsArray()) {
return env->ThrowTypeError("argument 1 must be an array");
Expand Down Expand Up @@ -1904,7 +1893,6 @@ static void SetGroups(const FunctionCallbackInfo<Value>& args) {

static void InitGroups(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsUint32() && !args[0]->IsString()) {
return env->ThrowTypeError("argument 1 must be a number or a string");
Expand Down Expand Up @@ -1954,15 +1942,12 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {


void Exit(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
exit(args[0]->Int32Value());
}


static void Uptime(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
double uptime;

uv_update_time(env->event_loop());
Expand All @@ -1974,7 +1959,6 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {

void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

size_t rss;
int err = uv_resident_set_memory(&rss);
Expand Down Expand Up @@ -2002,7 +1986,6 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {

void Kill(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (args.Length() != 2) {
return env->ThrowError("Bad argument.");
Expand All @@ -2024,7 +2007,6 @@ void Kill(const FunctionCallbackInfo<Value>& args) {
// Pass in an Array from a previous hrtime() call to instead get a time diff.
void Hrtime(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

uint64_t t = uv_hrtime();

Expand Down Expand Up @@ -2079,7 +2061,6 @@ 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) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());
struct node_module* mp;
uv_lib_t lib;
Expand Down Expand Up @@ -2223,7 +2204,6 @@ void OnMessage(Handle<Message> message, Handle<Value> error) {


static void Binding(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());

Local<String> module = args[0]->ToString();
Expand Down Expand Up @@ -2528,7 +2508,6 @@ 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(
Expand Down Expand Up @@ -2589,14 +2568,12 @@ void StopProfilerIdleNotifier(Environment* env) {


void StartProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());
StartProfilerIdleNotifier(env);
}


void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());
StopProfilerIdleNotifier(env);
}
Expand Down Expand Up @@ -2847,7 +2824,6 @@ static void SignalExit(int signo) {
// function, it is useful to bypass JavaScript entirely.
static void RawDebug(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

assert(args.Length() == 1 && args[0]->IsString() &&
"must be called with a single string");
Expand Down Expand Up @@ -3217,7 +3193,6 @@ static void RegisterSignalHandler(int signal,

void DebugProcess(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (args.Length() != 1) {
return env->ThrowError("Invalid number of arguments.");
Expand Down Expand Up @@ -3306,7 +3281,6 @@ static int RegisterDebugSignalHandler() {
static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Environment* env = Environment::GetCurrent(isolate);
HandleScope scope(isolate);
DWORD pid;
HANDLE process = NULL;
HANDLE thread = NULL;
Expand Down
5 changes: 0 additions & 5 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ Local<Object> Use(Environment* env, char* data, uint32_t length) {
template <encoding encoding>
void StringSlice(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

ARGS_THIS(args.This())
SLICE_START_END(args[0], args[1], obj_length)
Expand Down Expand Up @@ -300,7 +299,6 @@ void Base64Slice(const FunctionCallbackInfo<Value>& args) {
// bytesCopied = buffer.copy(target[, targetStart][, sourceStart][, sourceEnd]);
void Copy(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

Local<Object> target = args[0]->ToObject();

Expand Down Expand Up @@ -381,7 +379,6 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
template <encoding encoding>
void StringWrite(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

ARGS_THIS(args.This())

Expand Down Expand Up @@ -546,7 +543,6 @@ void WriteDoubleBE(const FunctionCallbackInfo<Value>& args) {

void ByteLength(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsString())
return env->ThrowTypeError("Argument must be a string");
Expand Down Expand Up @@ -595,7 +591,6 @@ void Compare(const FunctionCallbackInfo<Value> &args) {
// pass Buffer object to load prototype methods
void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

assert(args[0]->IsFunction());

Expand Down
6 changes: 0 additions & 6 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class ContextifyContext {


static void RunInDebugContext(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(args.GetIsolate());
Local<String> script_source(args[0]->ToString());
if (script_source.IsEmpty())
return; // Exception pending.
Expand All @@ -267,7 +266,6 @@ class ContextifyContext {

static void MakeContext(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsObject()) {
return env->ThrowTypeError("sandbox argument must be an object.");
Expand Down Expand Up @@ -298,7 +296,6 @@ class ContextifyContext {

static void IsContext(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args[0]->IsObject()) {
env->ThrowTypeError("sandbox must be an object");
Expand Down Expand Up @@ -473,7 +470,6 @@ class ContextifyScript : public BaseObject {
// args: code, [options]
static void New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

if (!args.IsConstructCall()) {
return env->ThrowError("Must call vm.Script as a constructor.");
Expand Down Expand Up @@ -516,7 +512,6 @@ class ContextifyScript : public BaseObject {
// args: [options]
static void RunInThisContext(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);

// Assemble arguments
TryCatch try_catch;
Expand All @@ -535,7 +530,6 @@ class ContextifyScript : public BaseObject {
// args: sandbox, [options]
static void RunInContext(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

int64_t timeout;
bool display_errors;
Expand Down
Loading

0 comments on commit 97585b0

Please sign in to comment.