1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This file has been auto-generated from the Jinja2 template
6 // third_party/blink/renderer/bindings/templates/union_container.h.tmpl
7 // by the script code_generator_v8.py.
8 // DO NOT MODIFY!
9 
10 // clang-format off
11 #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_TEST_INTERFACE_2_OR_UINT_8_ARRAY_H_
12 #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_TEST_INTERFACE_2_OR_UINT_8_ARRAY_H_
13 
14 #include "base/optional.h"
15 #include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
16 #include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
17 #include "third_party/blink/renderer/bindings/core/v8/v8_array_buffer_view.h"
18 #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
19 #include "third_party/blink/renderer/bindings/core/v8/v8_uint8_array.h"
20 #include "third_party/blink/renderer/core/core_export.h"
21 #include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
22 #include "third_party/blink/renderer/core/typed_arrays/flexible_array_buffer_view.h"
23 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
24 #include "third_party/blink/renderer/platform/heap/handle.h"
25 
26 namespace blink {
27 
28 class TestInterface2;
29 
30 class CORE_EXPORT TestInterface2OrUint8Array final {
31   DISALLOW_NEW();
32  public:
33   TestInterface2OrUint8Array();
IsNull()34   bool IsNull() const { return type_ == SpecificType::kNone; }
35 
IsTestInterface2()36   bool IsTestInterface2() const { return type_ == SpecificType::kTestInterface2; }
37   TestInterface2* GetAsTestInterface2() const;
38   void SetTestInterface2(TestInterface2*);
39   static TestInterface2OrUint8Array FromTestInterface2(TestInterface2*);
40 
IsUint8Array()41   bool IsUint8Array() const { return type_ == SpecificType::kUint8Array; }
42   NotShared<DOMUint8Array> GetAsUint8Array() const;
43   void SetUint8Array(NotShared<DOMUint8Array>);
44   static TestInterface2OrUint8Array FromUint8Array(NotShared<DOMUint8Array>);
45 
46   TestInterface2OrUint8Array(const TestInterface2OrUint8Array&);
47   ~TestInterface2OrUint8Array();
48   TestInterface2OrUint8Array& operator=(const TestInterface2OrUint8Array&);
49   void Trace(Visitor*) const;
50 
51  private:
52   enum class SpecificType {
53     kNone,
54     kTestInterface2,
55     kUint8Array,
56   };
57   SpecificType type_;
58 
59   Member<TestInterface2> test_interface_2_;
60   NotShared<DOMUint8Array> uint8_array_;
61 
62   friend CORE_EXPORT v8::Local<v8::Value> ToV8(const TestInterface2OrUint8Array&, v8::Local<v8::Object>, v8::Isolate*);
63 };
64 
65 class V8TestInterface2OrUint8Array final {
66  public:
67   CORE_EXPORT static void ToImpl(v8::Isolate*, v8::Local<v8::Value>, TestInterface2OrUint8Array&, UnionTypeConversionMode, ExceptionState&);
68 };
69 
70 CORE_EXPORT v8::Local<v8::Value> ToV8(const TestInterface2OrUint8Array&, v8::Local<v8::Object>, v8::Isolate*);
71 
72 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,TestInterface2OrUint8Array & impl)73 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, TestInterface2OrUint8Array& impl) {
74   V8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
75 }
76 
77 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,TestInterface2OrUint8Array & impl,v8::Local<v8::Object> creationContext)78 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, TestInterface2OrUint8Array& impl, v8::Local<v8::Object> creationContext) {
79   V8SetReturnValue(callbackInfo, ToV8(impl, creationContext, callbackInfo.GetIsolate()));
80 }
81 
82 template <>
83 struct NativeValueTraits<TestInterface2OrUint8Array> : public NativeValueTraitsBase<TestInterface2OrUint8Array> {
84   CORE_EXPORT static TestInterface2OrUint8Array NativeValue(v8::Isolate*, v8::Local<v8::Value>, ExceptionState&);
85   CORE_EXPORT static TestInterface2OrUint8Array NullValue() { return TestInterface2OrUint8Array(); }
86 };
87 
88 template <>
89 struct V8TypeOf<TestInterface2OrUint8Array> {
90   typedef V8TestInterface2OrUint8Array Type;
91 };
92 
93 }  // namespace blink
94 
95 // We need to set canInitializeWithMemset=true because HeapVector supports
96 // items that can initialize with memset or have a vtable. It is safe to
97 // set canInitializeWithMemset=true for a union type object in practice.
98 // See https://codereview.chromium.org/1118993002/#msg5 for more details.
99 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::TestInterface2OrUint8Array)
100 
101 #endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_TEST_INTERFACE_2_OR_UINT_8_ARRAY_H_
102