chore: remove native_mate (Part 9) (#20645)

* refactor: remove a few uses of native_mate/gfx_converter.h

* refactor: deprecate mate::EventEmitter

* refactor: add gin_helper::EventEmitter

* refactor: convert a few classes to use gin_helper::EventEmitter

* refactor: get rid of native_mate_converters/gfx_converter.h

* fix: follow native_mate on reporting errors

* fix: gin is weak at guessing parameter types

* fix: incorrect full class name

* fix: gin::Handle does not accept null
This commit is contained in:
Cheng Zhao 2019-10-21 16:05:40 +09:00 committed by GitHub
parent b155ebeeb3
commit eb0e55c514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 532 additions and 326 deletions

View file

@ -8,19 +8,18 @@
#include <utility>
#include <vector>
#include "native_mate/dictionary.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace mate {
namespace gin {
template <>
struct Converter<in_app_purchase::Payment> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const in_app_purchase::Payment& payment) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
// TODO(zcbenz): Just call SetHidden when this file is converted to gin.
gin_helper::Dictionary(isolate, dict.GetHandle()).SetHidden("simple", true);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
dict.Set("productIdentifier", payment.productIdentifier);
dict.Set("quantity", payment.quantity);
return dict.GetHandle();
@ -31,9 +30,8 @@ template <>
struct Converter<in_app_purchase::Transaction> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const in_app_purchase::Transaction& val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
// TODO(zcbenz): Just call SetHidden when this file is converted to gin.
gin_helper::Dictionary(isolate, dict.GetHandle()).SetHidden("simple", true);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
dict.Set("transactionIdentifier", val.transactionIdentifier);
dict.Set("transactionDate", val.transactionDate);
dict.Set("originalTransactionIdentifier",
@ -50,9 +48,8 @@ template <>
struct Converter<in_app_purchase::Product> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const in_app_purchase::Product& val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
// TODO(zcbenz): Just call SetHidden when this file is converted to gin.
gin_helper::Dictionary(isolate, dict.GetHandle()).SetHidden("simple", true);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
dict.Set("productIdentifier", val.productIdentifier);
dict.Set("localizedDescription", val.localizedDescription);
dict.Set("localizedTitle", val.localizedTitle);
@ -70,7 +67,7 @@ struct Converter<in_app_purchase::Product> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -78,15 +75,15 @@ namespace api {
#if defined(OS_MACOSX)
// static
mate::Handle<InAppPurchase> InAppPurchase::Create(v8::Isolate* isolate) {
return mate::CreateHandle(isolate, new InAppPurchase(isolate));
gin::Handle<InAppPurchase> InAppPurchase::Create(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new InAppPurchase(isolate));
}
// static
void InAppPurchase::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "InAppPurchase"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "InAppPurchase"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("canMakePayments", &in_app_purchase::CanMakePayments)
.SetMethod("getReceiptURL", &in_app_purchase::GetReceiptURL)
.SetMethod("purchaseProduct", &InAppPurchase::PurchaseProduct)
@ -105,7 +102,7 @@ InAppPurchase::~InAppPurchase() {}
v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
const std::string& product_id,
mate::Arguments* args) {
gin::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise<bool> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -115,15 +112,14 @@ v8::Local<v8::Promise> InAppPurchase::PurchaseProduct(
in_app_purchase::PurchaseProduct(
product_id, quantity,
base::BindOnce(electron::util::Promise<bool>::ResolvePromise,
std::move(promise)));
base::BindOnce(util::Promise<bool>::ResolvePromise, std::move(promise)));
return handle;
}
v8::Local<v8::Promise> InAppPurchase::GetProducts(
const std::vector<std::string>& productIDs,
mate::Arguments* args) {
gin::Arguments* args) {
v8::Isolate* isolate = args->isolate();
electron::util::Promise<std::vector<in_app_purchase::Product>> promise(
isolate);
@ -131,9 +127,9 @@ v8::Local<v8::Promise> InAppPurchase::GetProducts(
in_app_purchase::GetProducts(
productIDs,
base::BindOnce(electron::util::Promise<
std::vector<in_app_purchase::Product>>::ResolvePromise,
std::move(promise)));
base::BindOnce(
util::Promise<std::vector<in_app_purchase::Product>>::ResolvePromise,
std::move(promise)));
return handle;
}
@ -158,7 +154,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
#if defined(OS_MACOSX)
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict(isolate, exports);
dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
dict.Set("InAppPurchase", InAppPurchase::GetConstructor(isolate)
->GetFunction(context)