Skip to content

Commit

Permalink
Add Function::Call wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Oct 22, 2015
1 parent 9f42b4c commit 798f1e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nan_maybe_43_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,12 @@ NAN_INLINE MaybeLocal<v8::Object> CloneElementAt(
return array->CloneElementAt(GetCurrentContext(), index);
}

NAN_INLINE MaybeLocal<v8::Value> Call(
v8::Local<v8::Function> fun
, v8::Local<v8::Value> recv
, int argc
, v8::Local<v8::Value> argv[]) {
return fun->Call(GetCurrentContext(), recv, argc, argv);
}

#endif // NAN_MAYBE_43_INL_H_
19 changes: 19 additions & 0 deletions nan_maybe_pre_43_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,23 @@ NAN_INLINE MaybeLocal<v8::Object> CloneElementAt(
return MaybeLocal<v8::Object>(array->CloneElementAt(index));
}

NAN_INLINE MaybeLocal<v8::Value> Call(
v8::Local<v8::Function> fun
, v8::Local<v8::Value> recv
, int argc
, v8::Local<v8::Value> argv[]) {
#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION
return MaybeLocal<v8::Value>(fun->Call(recv, argc, argv));
#else
v8::HandleScope scope;
v8::Local<v8::Object> recv_obj;
if (recv->IsUndefined() || recv->IsNull()) {
recv_obj = v8::Context::GetCurrent()->Global();
} else {
recv_obj = recv->ToObject();
}
return MaybeLocal<v8::Value>(scope.Close(fun->Call(recv_obj, argc, argv)));
#endif
}

#endif // NAN_MAYBE_PRE_43_INL_H_

0 comments on commit 798f1e3

Please sign in to comment.