Fix Node crash from calling function with empty this

This commit is contained in:
Scott Kyle 2016-04-27 10:42:42 -07:00
parent 8602787fc9
commit ca87f5a3e0
1 changed files with 3 additions and 1 deletions

View File

@ -26,7 +26,9 @@ namespace js {
template<>
inline v8::Local<v8::Value> node::Function::call(v8::Isolate* isolate, const v8::Local<v8::Function> &function, const v8::Local<v8::Object> &this_object, size_t argc, const v8::Local<v8::Value> arguments[]) {
Nan::TryCatch trycatch;
auto result = Nan::Call(function, this_object, (int)argc, const_cast<v8::Local<v8::Value>*>(arguments));
auto recv = this_object.IsEmpty() ? isolate->GetCurrentContext()->Global() : this_object;
auto result = Nan::Call(function, recv, (int)argc, const_cast<v8::Local<v8::Value>*>(arguments));
if (trycatch.HasCaught()) {
throw node::Exception(isolate, trycatch.Exception());