chore: remove native_mate (Part 7) (#20561)

* refactor: use gin converters in api::Protocol

* refactor: convert JS constructor impl to gin

* refactor: use InitWithArgs helper

* fix: gin_helper::Dictionary should behave the same with mate

* fix cpplint warnings

* refactor: no more need to patch gin/dictionary.h
This commit is contained in:
Cheng Zhao 2019-10-15 10:15:23 +09:00 committed by GitHub
parent 6c6bff81ac
commit 1ecfcc8c70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 274 additions and 368 deletions

View file

@ -61,22 +61,4 @@ class KeyWeakMap : public mate::Wrappable<KeyWeakMap<K>> {
} // namespace electron
namespace gin {
// TODO(zcbenz): Remove this after converting KeyWeakMap to gin::Wrapper.
template <typename T>
struct Converter<electron::api::KeyWeakMap<T>*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::KeyWeakMap<T>** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::KeyWeakMap<T>* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_

View file

@ -8,7 +8,6 @@
#include "base/hash/hash.h"
#include "electron/buildflags/buildflags.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/native_mate_handle_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
#include "url/origin.h"

View file

@ -1,30 +0,0 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_GIN_CONVERTERS_NATIVE_MATE_HANDLE_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_NATIVE_MATE_HANDLE_CONVERTER_H_
#include "gin/converter.h"
#include "native_mate/handle.h"
namespace gin {
// TODO(zcbenz): Remove this converter after native_mate is removed.
template <typename T>
struct Converter<mate::Handle<T>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const mate::Handle<T>& in) {
return mate::ConvertToV8(isolate, in);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<T>* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_NATIVE_MATE_HANDLE_CONVERTER_H_

View file

@ -27,6 +27,23 @@ class Dictionary : public gin::Dictionary {
Dictionary(const gin::Dictionary& dict) // NOLINT(runtime/explicit)
: gin::Dictionary(dict) {}
// Difference from the Get method in gin::Dictionary:
// 1. This is a const method;
// 2. It checks whether the key exists before reading.
template <typename T>
bool Get(base::StringPiece key, T* out) const {
// Check for existence before getting, otherwise this method will always
// returns true when T == v8::Local<v8::Value>.
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
v8::Local<v8::String> v8_key = gin::StringToV8(isolate(), key);
v8::Local<v8::Value> value;
v8::Maybe<bool> result = GetHandle()->Has(context, v8_key);
if (result.IsJust() && result.FromJust() &&
GetHandle()->Get(context, v8_key).ToLocal(&value))
return gin::ConvertFromV8(isolate(), value, out);
return false;
}
template <typename T>
bool GetHidden(base::StringPiece key, T* out) const {
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
@ -80,6 +97,8 @@ class Dictionary : public gin::Dictionary {
return !result.IsNothing() && result.FromJust();
}
bool IsEmpty() const { return isolate() == nullptr || GetHandle().IsEmpty(); }
v8::Local<v8::Object> GetHandle() const {
return gin::ConvertToV8(isolate(),
*static_cast<const gin::Dictionary*>(this))