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_XML_HTTP_REQUEST_OR_STRING_H_
12 #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_XML_HTTP_REQUEST_OR_STRING_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 XMLHttpRequest;
25 
26 class CORE_EXPORT XMLHttpRequestOrString final {
27   DISALLOW_NEW();
28  public:
29   XMLHttpRequestOrString();
IsNull()30   bool IsNull() const { return type_ == SpecificType::kNone; }
31 
IsString()32   bool IsString() const { return type_ == SpecificType::kString; }
33   const String& GetAsString() const;
34   void SetString(const String&);
35   static XMLHttpRequestOrString FromString(const String&);
36 
IsXMLHttpRequest()37   bool IsXMLHttpRequest() const { return type_ == SpecificType::kXMLHttpRequest; }
38   XMLHttpRequest* GetAsXMLHttpRequest() const;
39   void SetXMLHttpRequest(XMLHttpRequest*);
40   static XMLHttpRequestOrString FromXMLHttpRequest(XMLHttpRequest*);
41 
42   XMLHttpRequestOrString(const XMLHttpRequestOrString&);
43   ~XMLHttpRequestOrString();
44   XMLHttpRequestOrString& operator=(const XMLHttpRequestOrString&);
45   void Trace(Visitor*) const;
46 
47  private:
48   enum class SpecificType {
49     kNone,
50     kString,
51     kXMLHttpRequest,
52   };
53   SpecificType type_;
54 
55   String string_;
56   Member<XMLHttpRequest> xml_http_request_;
57 
58   friend CORE_EXPORT v8::Local<v8::Value> ToV8(const XMLHttpRequestOrString&, v8::Local<v8::Object>, v8::Isolate*);
59 };
60 
61 class V8XMLHttpRequestOrString final {
62  public:
63   CORE_EXPORT static void ToImpl(v8::Isolate*, v8::Local<v8::Value>, XMLHttpRequestOrString&, UnionTypeConversionMode, ExceptionState&);
64 };
65 
66 CORE_EXPORT v8::Local<v8::Value> ToV8(const XMLHttpRequestOrString&, v8::Local<v8::Object>, v8::Isolate*);
67 
68 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,XMLHttpRequestOrString & impl)69 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, XMLHttpRequestOrString& impl) {
70   V8SetReturnValue(callbackInfo, ToV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
71 }
72 
73 template <class CallbackInfo>
V8SetReturnValue(const CallbackInfo & callbackInfo,XMLHttpRequestOrString & impl,v8::Local<v8::Object> creationContext)74 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, XMLHttpRequestOrString& impl, v8::Local<v8::Object> creationContext) {
75   V8SetReturnValue(callbackInfo, ToV8(impl, creationContext, callbackInfo.GetIsolate()));
76 }
77 
78 template <>
79 struct NativeValueTraits<XMLHttpRequestOrString> : public NativeValueTraitsBase<XMLHttpRequestOrString> {
80   CORE_EXPORT static XMLHttpRequestOrString NativeValue(v8::Isolate*, v8::Local<v8::Value>, ExceptionState&);
81   CORE_EXPORT static XMLHttpRequestOrString NullValue() { return XMLHttpRequestOrString(); }
82 };
83 
84 template <>
85 struct V8TypeOf<XMLHttpRequestOrString> {
86   typedef V8XMLHttpRequestOrString 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::XMLHttpRequestOrString)
96 
97 #endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_TESTS_RESULTS_CORE_XML_HTTP_REQUEST_OR_STRING_H_
98