Commit 98b02768 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

CodeGen: Define bindings::UnionBase for generated union type definitions

Bug: 839389
Change-Id: I916e7fa8ec6e39a3637090aaef3a24b4c45dcf57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012361Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733947}
parent 10aef525
...@@ -27,6 +27,7 @@ struct WrapperTypeInfo; ...@@ -27,6 +27,7 @@ struct WrapperTypeInfo;
namespace bindings { namespace bindings {
class DictionaryBase; class DictionaryBase;
class UnionBase;
CORE_EXPORT ScriptWrappable* NativeValueTraitsInterfaceNativeValue( CORE_EXPORT ScriptWrappable* NativeValueTraitsInterfaceNativeValue(
v8::Isolate* isolate, v8::Isolate* isolate,
...@@ -789,6 +790,19 @@ struct NativeValueTraits< ...@@ -789,6 +790,19 @@ struct NativeValueTraits<
} }
}; };
// Union type
template <typename T>
struct NativeValueTraits<
T,
typename std::enable_if_t<std::is_base_of<bindings::UnionBase, T>::value>>
: public NativeValueTraitsBase<T*> {
static T NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state) {
return T::Create(isolate, value, exception_state);
}
};
// Nullable // Nullable
template <typename InnerType> template <typename InnerType>
struct NativeValueTraits< struct NativeValueTraits<
......
...@@ -434,6 +434,7 @@ jumbo_component("platform") { ...@@ -434,6 +434,7 @@ jumbo_component("platform") {
"bindings/trace_wrapper_v8_reference.h", "bindings/trace_wrapper_v8_reference.h",
"bindings/trace_wrapper_v8_string.cc", "bindings/trace_wrapper_v8_string.cc",
"bindings/trace_wrapper_v8_string.h", "bindings/trace_wrapper_v8_string.h",
"bindings/union_base.h",
"bindings/v0_custom_element_binding.cc", "bindings/v0_custom_element_binding.cc",
"bindings/v0_custom_element_binding.h", "bindings/v0_custom_element_binding.h",
"bindings/v8_binding.cc", "bindings/v8_binding.cc",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#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"
#include "third_party/blink/renderer/platform/bindings/union_base.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h" #include "third_party/blink/renderer/platform/bindings/v8_binding.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
...@@ -85,6 +86,17 @@ inline v8::Local<v8::Value> ToV8(CallbackInterfaceBase* callback, ...@@ -85,6 +86,17 @@ inline v8::Local<v8::Value> ToV8(CallbackInterfaceBase* callback,
: v8::Null(isolate).As<v8::Value>(); : v8::Null(isolate).As<v8::Value>();
} }
// Union type
inline v8::Local<v8::Value> ToV8(const bindings::UnionBase& value,
v8::Local<v8::Object> creation_context,
v8::Isolate* isolate) {
v8::Local<v8::Value> v8_value =
value.CreateV8Object(isolate, creation_context);
DCHECK(!v8_value.IsEmpty());
return v8_value;
}
// Primitives // Primitives
inline v8::Local<v8::Value> ToV8(const String& value, inline v8::Local<v8::Value> ToV8(const String& value,
......
// Copyright 2020 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_UNION_BASE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_UNION_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 {
class Visitor;
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 UnionBase {
DISALLOW_NEW();
public:
virtual ~UnionBase() = default;
virtual v8::Local<v8::Value> CreateV8Object(
v8::Isolate* isolate,
v8::Local<v8::Object> creation_context) const = 0;
void Trace(Visitor*) {}
protected:
UnionBase() = default;
UnionBase(const UnionBase&) = default;
UnionBase(UnionBase&&) = default;
UnionBase& operator=(const UnionBase&) = default;
UnionBase& operator=(UnionBase&&) = default;
};
} // namespace bindings
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_UNION_BASE_H_
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