Commit 0c2fd9a3 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

bindings: Define DictionaryBase class

Defines bindings::DictionaryBase as a base class for IDL dictionaries
generated by the new code generator.
This CL also prepares some basic APIs; NativeValueTraits and ToV8.


Bug: 839389
Change-Id: I47012911933c9bd6a8934f4d18f27e4a86e80974
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898893
Auto-Submit: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720902}
parent e35503e9
...@@ -17,6 +17,10 @@ namespace blink { ...@@ -17,6 +17,10 @@ namespace blink {
class CallbackFunctionBase; class CallbackFunctionBase;
namespace bindings {
class DictionaryBase;
} // namespace bindings
// Boolean // Boolean
template <> template <>
struct CORE_EXPORT NativeValueTraits<IDLBoolean> struct CORE_EXPORT NativeValueTraits<IDLBoolean>
...@@ -658,6 +662,20 @@ struct NativeValueTraits<IDLRecord<K, V>> ...@@ -658,6 +662,20 @@ struct NativeValueTraits<IDLRecord<K, V>>
} }
}; };
// Dictionary
template <typename T>
struct NativeValueTraits<
T,
typename std::enable_if<
std::is_base_of<bindings::DictionaryBase, T>::value>::type>
: public NativeValueTraitsBase<T> {
static T* NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return T::Create(isolate, value, exception_state);
}
};
// Callback functions // Callback functions
template <typename T> template <typename T>
struct NativeValueTraits< struct NativeValueTraits<
......
...@@ -401,6 +401,7 @@ jumbo_component("platform") { ...@@ -401,6 +401,7 @@ jumbo_component("platform") {
"bindings/callback_method_retriever.cc", "bindings/callback_method_retriever.cc",
"bindings/callback_method_retriever.h", "bindings/callback_method_retriever.h",
"bindings/custom_wrappable.h", "bindings/custom_wrappable.h",
"bindings/dictionary_base.h",
"bindings/dom_data_store.cc", "bindings/dom_data_store.cc",
"bindings/dom_data_store.h", "bindings/dom_data_store.h",
"bindings/dom_wrapper_world.cc", "bindings/dom_wrapper_world.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DICTIONARY_BASE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DICTIONARY_BASE_H_
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "v8/include/v8.h"
namespace blink {
namespace bindings {
// This class is the base class for all IDL dictionary implementations. This is
// designed to collaborate with NativeValueTraits and ToV8 with supporting type
// dispatching (SFINAE, etc.).
class PLATFORM_EXPORT DictionaryBase : public GarbageCollected<DictionaryBase> {
public:
virtual ~DictionaryBase() = default;
v8::Local<v8::Value> CreateV8Object(
v8::Isolate* isolate,
v8::Local<v8::Object> creation_context) const {
v8::Local<v8::Context> context = creation_context->CreationContext();
DCHECK(!context.IsEmpty());
v8::Local<v8::Object> v8_object;
{
v8::Context::Scope context_scope(context);
v8_object = v8::Object::New(isolate);
}
FillWithMembers(isolate, creation_context, v8_object);
return v8_object;
}
protected:
DictionaryBase() = default;
DictionaryBase(const DictionaryBase&) = delete;
DictionaryBase(const DictionaryBase&&) = delete;
DictionaryBase& operator=(const DictionaryBase&) = delete;
DictionaryBase& operator=(const DictionaryBase&&) = delete;
virtual void FillWithMembers(v8::Isolate* isolate,
v8::Local<v8::Object> creation_context,
v8::Local<v8::Object> v8_object) const = 0;
};
} // namespace bindings
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DICTIONARY_BASE_H_
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/blink/renderer/platform/bindings/callback_function_base.h" #include "third_party/blink/renderer/platform/bindings/callback_function_base.h"
#include "third_party/blink/renderer/platform/bindings/callback_interface_base.h" #include "third_party/blink/renderer/platform/bindings/callback_interface_base.h"
#include "third_party/blink/renderer/platform/bindings/dictionary_base.h"
#include "third_party/blink/renderer/platform/bindings/dom_data_store.h" #include "third_party/blink/renderer/platform/bindings/dom_data_store.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -41,6 +42,19 @@ inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl, ...@@ -41,6 +42,19 @@ inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl,
return wrapper; return wrapper;
} }
// Dictionary
inline v8::Local<v8::Value> ToV8(bindings::DictionaryBase* dictionary,
v8::Local<v8::Object> creation_context,
v8::Isolate* isolate) {
if (UNLIKELY(!dictionary))
return v8::Null(isolate);
v8::Local<v8::Value> v8_value =
dictionary->CreateV8Object(isolate, creation_context);
DCHECK(!v8_value.IsEmpty());
return v8_value;
}
// Callback function // Callback function
inline v8::Local<v8::Value> ToV8(CallbackFunctionBase* callback, inline v8::Local<v8::Value> ToV8(CallbackFunctionBase* callback,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment