refactor: ginify desktopCapturer (#22746)

This commit is contained in:
Jeremy Apthorp 2020-03-19 11:35:11 -07:00 committed by GitHub
parent 9aa27e1709
commit a824e12275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 28 deletions

View file

@ -9,6 +9,7 @@
#include <vector>
#include "gin/converter.h"
#include "gin/wrappable.h"
namespace gin_helper {
@ -63,6 +64,28 @@ v8::Local<v8::Value> CustomEmit(v8::Isolate* isolate,
&converted_args);
}
template <typename T, typename... Args>
v8::Local<v8::Value> CallMethod(v8::Isolate* isolate,
gin::Wrappable<T>* object,
const char* method_name,
Args&&... args) {
v8::HandleScope scope(isolate);
v8::Local<v8::Object> v8_object;
if (object->GetWrapper(isolate).ToLocal(&v8_object))
return CustomEmit(isolate, v8_object, method_name,
std::forward<Args>(args)...);
else
return v8::Local<v8::Value>();
}
template <typename T, typename... Args>
v8::Local<v8::Value> CallMethod(gin::Wrappable<T>* object,
const char* method_name,
Args&&... args) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
return CallMethod(isolate, object, method_name, std::forward<Args>(args)...);
}
} // namespace gin_helper
#endif // SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_