Fix accessing empty vector in V8FunctionInvoker

This commit is contained in:
Cheng Zhao 2017-07-31 16:47:14 +09:00
parent 4b46eca329
commit 0ee2ab8a6e

View file

@ -56,7 +56,8 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> ret(holder->Call(holder, args.size(), &args.front()));
v8::Local<v8::Value> ret(holder->Call(
holder, args.size(), args.empty() ? nullptr : &args.front()));
return handle_scope.Escape(ret);
}
};
@ -76,7 +77,8 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... };
holder->Call(holder, args.size(), &args.front());
holder->Call(
holder, args.size(), args.empty() ? nullptr : &args.front());
}
};
@ -97,8 +99,8 @@ struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> result;
auto maybe_result =
holder->Call(context, holder, args.size(), &args.front());
auto maybe_result = holder->Call(
context, holder, args.size(), args.empty() ? nullptr : &args.front());
if (maybe_result.ToLocal(&result))
Converter<ReturnType>::FromV8(isolate, result, &ret);
return ret;