add converters for base::BindOnce and base::BindRepeating
This commit is contained in:
parent
7a8a0f6b4b
commit
ca406637af
1 changed files with 22 additions and 8 deletions
|
@ -134,23 +134,37 @@ struct NativeFunctionInvoker<ReturnType(ArgTypes...)> {
|
|||
} // namespace internal
|
||||
|
||||
template <typename Sig>
|
||||
struct Converter<base::Callback<Sig>> {
|
||||
struct Converter<base::OnceCallback<Sig>> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::OnceCallback<Sig>* out) {
|
||||
if (!val->IsFunction())
|
||||
return false;
|
||||
|
||||
*out = base::BindOnce(&internal::V8FunctionInvoker<Sig>::Go, isolate,
|
||||
internal::SafeV8Function(isolate, val));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Sig>
|
||||
struct Converter<base::RepeatingCallback<Sig>> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::Callback<Sig>& val) {
|
||||
const base::RepeatingCallback<Sig>& val) {
|
||||
// We don't use CreateFunctionTemplate here because it creates a new
|
||||
// FunctionTemplate everytime, which is cached by V8 and causes leaks.
|
||||
internal::Translater translater = base::Bind(
|
||||
&internal::NativeFunctionInvoker<Sig>::Go, val);
|
||||
internal::Translater translater =
|
||||
base::BindRepeating(&internal::NativeFunctionInvoker<Sig>::Go, val);
|
||||
return internal::CreateFunctionFromTranslater(isolate, translater);
|
||||
}
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Callback<Sig>* out) {
|
||||
base::RepeatingCallback<Sig>* out) {
|
||||
if (!val->IsFunction())
|
||||
return false;
|
||||
|
||||
*out = base::Bind(&internal::V8FunctionInvoker<Sig>::Go,
|
||||
isolate, internal::SafeV8Function(isolate, val));
|
||||
*out = base::BindRepeating(&internal::V8FunctionInvoker<Sig>::Go, isolate,
|
||||
internal::SafeV8Function(isolate, val));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue