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_OR_LONG_H_
12 #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_TEST_INTERFACE_OR_LONG_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_binding_for_core.h"
18 #include "third_party/blink/renderer/core/core_export.h"
19 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
20 #include "third_party/blink/renderer/platform/heap/handle.h"
21
22 namespace blink {
23
24 class TestInterfaceImplementation;
25
26 class CORE_EXPORT TestInterfaceOrLong final {
27 DISALLOW_NEW();
28 public:
29 TestInterfaceOrLong();
IsNull()30 bool IsNull() const { return type_ == SpecificType::kNone; }
31
IsLong()32 bool IsLong() const { return type_ == SpecificType::kLong; }
33 int32_t GetAsLong() const;
34 void SetLong(int32_t);
35 static TestInterfaceOrLong FromLong(int32_t);
36
IsTestInterface()37 bool IsTestInterface() const { return type_ == SpecificType::kTestInterface; }
38 TestInterfaceImplementation* GetAsTestInterface() const;
39 void SetTestInterface(TestInterfaceImplementation*);
40 static TestInterfaceOrLong FromTestInterface(TestInterfaceImplementation*);
41
42 TestInterfaceOrLong(const TestInterfaceOrLong&);
43 ~TestInterfaceOrLong();
44 TestInterfaceOrLong& operator=(const TestInterfaceOrLong&);
45 void Trace(Visitor*) const;
46
47 private:
48 enum class SpecificType {
49 kNone,
50 kLong,
51 kTestInterface,
52 };
53 SpecificType type_;
54
55 int32_t long_;
56 Member<TestInterfaceImplementation> test_interface_;
57
58 friend CORE_EXPORT v8::Local<v8::Value> ToV8(const TestInterfaceOrLong&, v8::Local<v8::Object>, v8::Isolate*);
59 };
60
61 class V8TestInterfaceOrLong final {
62 public:
63 CORE_EXPORT static void ToImpl(v8::Isolate*, v8::Local<v8::Value>, TestInterfaceOrLong&, UnionTypeConversionMode, ExceptionState&);
64 };
65
66 CORE_EXPORT v8::Local<v8::Value> ToV8(const TestInterfaceOrLong&, v8::Local<v8::Object>, v8::Isolate*);
67
68 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,TestInterfaceOrLong & impl)69 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, TestInterfaceOrLong& impl) {
70 V8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
71 }
72
73 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,TestInterfaceOrLong & impl,v8::Local<v8::Object> creationContext)74 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, TestInterfaceOrLong& impl, v8::Local<v8::Object> creationContext) {
75 V8SetReturnValue(callbackInfo, ToV8(impl, creationContext, callbackInfo.GetIsolate()));
76 }
77
78 template <>
79 struct NativeValueTraits<TestInterfaceOrLong> : public NativeValueTraitsBase<TestInterfaceOrLong> {
80 CORE_EXPORT static TestInterfaceOrLong NativeValue(v8::Isolate*, v8::Local<v8::Value>, ExceptionState&);
81 CORE_EXPORT static TestInterfaceOrLong NullValue() { return TestInterfaceOrLong(); }
82 };
83
84 template <>
85 struct V8TypeOf<TestInterfaceOrLong> {
86 typedef V8TestInterfaceOrLong Type;
87 };
88
89 } // namespace blink
90
91 // We need to set canInitializeWithMemset=true because HeapVector supports
92 // items that can initialize with memset or have a vtable. It is safe to
93 // set canInitializeWithMemset=true for a union type object in practice.
94 // See https://codereview.chromium.org/1118993002/#msg5 for more details.
95 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::TestInterfaceOrLong)
96
97 #endif // THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_TEST_INTERFACE_OR_LONG_H_
98