From ca406637af5ca6a91dcbd3bff7c0ce7d9061d10a Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 17 Apr 2018 18:47:12 -0400 Subject: [PATCH] add converters for base::BindOnce and base::BindRepeating --- atom/common/native_mate_converters/callback.h | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/atom/common/native_mate_converters/callback.h b/atom/common/native_mate_converters/callback.h index fc93e83d312b..3631e53de1e6 100644 --- a/atom/common/native_mate_converters/callback.h +++ b/atom/common/native_mate_converters/callback.h @@ -133,24 +133,38 @@ struct NativeFunctionInvoker { } // namespace internal -template -struct Converter> { +template +struct Converter> { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + base::OnceCallback* out) { + if (!val->IsFunction()) + return false; + + *out = base::BindOnce(&internal::V8FunctionInvoker::Go, isolate, + internal::SafeV8Function(isolate, val)); + return true; + } +}; + +template +struct Converter> { static v8::Local ToV8(v8::Isolate* isolate, - const base::Callback& val) { + const base::RepeatingCallback& 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::Go, val); + internal::Translater translater = + base::BindRepeating(&internal::NativeFunctionInvoker::Go, val); return internal::CreateFunctionFromTranslater(isolate, translater); } static bool FromV8(v8::Isolate* isolate, v8::Local val, - base::Callback* out) { + base::RepeatingCallback* out) { if (!val->IsFunction()) return false; - *out = base::Bind(&internal::V8FunctionInvoker::Go, - isolate, internal::SafeV8Function(isolate, val)); + *out = base::BindRepeating(&internal::V8FunctionInvoker::Go, isolate, + internal::SafeV8Function(isolate, val)); return true; } };