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.cc.tmpl
7 // by the script code_generator_v8.py.
8 // DO NOT MODIFY!
9 
10 // clang-format off
11 #include "third_party/blink/renderer/bindings/tests/results/core/unsigned_long_long_or_boolean_or_test_callback_interface.h"
12 
13 #include "base/stl_util.h"
14 #include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
15 #include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
16 #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h"
17 #include "third_party/blink/renderer/bindings/core/v8/v8_test_callback_interface.h"
18 
19 namespace blink {
20 
UnsignedLongLongOrBooleanOrTestCallbackInterface()21 UnsignedLongLongOrBooleanOrTestCallbackInterface::UnsignedLongLongOrBooleanOrTestCallbackInterface() : type_(SpecificType::kNone) {}
22 
GetAsBoolean() const23 bool UnsignedLongLongOrBooleanOrTestCallbackInterface::GetAsBoolean() const {
24   DCHECK(IsBoolean());
25   return boolean_;
26 }
27 
SetBoolean(bool value)28 void UnsignedLongLongOrBooleanOrTestCallbackInterface::SetBoolean(bool value) {
29   DCHECK(IsNull());
30   boolean_ = value;
31   type_ = SpecificType::kBoolean;
32 }
33 
FromBoolean(bool value)34 UnsignedLongLongOrBooleanOrTestCallbackInterface UnsignedLongLongOrBooleanOrTestCallbackInterface::FromBoolean(bool value) {
35   UnsignedLongLongOrBooleanOrTestCallbackInterface container;
36   container.SetBoolean(value);
37   return container;
38 }
39 
GetAsTestCallbackInterface() const40 V8TestCallbackInterface* UnsignedLongLongOrBooleanOrTestCallbackInterface::GetAsTestCallbackInterface() const {
41   DCHECK(IsTestCallbackInterface());
42   return test_callback_interface_;
43 }
44 
SetTestCallbackInterface(V8TestCallbackInterface * value)45 void UnsignedLongLongOrBooleanOrTestCallbackInterface::SetTestCallbackInterface(V8TestCallbackInterface* value) {
46   DCHECK(IsNull());
47   test_callback_interface_ = value;
48   type_ = SpecificType::kTestCallbackInterface;
49 }
50 
FromTestCallbackInterface(V8TestCallbackInterface * value)51 UnsignedLongLongOrBooleanOrTestCallbackInterface UnsignedLongLongOrBooleanOrTestCallbackInterface::FromTestCallbackInterface(V8TestCallbackInterface* value) {
52   UnsignedLongLongOrBooleanOrTestCallbackInterface container;
53   container.SetTestCallbackInterface(value);
54   return container;
55 }
56 
GetAsUnsignedLongLong() const57 uint64_t UnsignedLongLongOrBooleanOrTestCallbackInterface::GetAsUnsignedLongLong() const {
58   DCHECK(IsUnsignedLongLong());
59   return unsigned_long_long_;
60 }
61 
SetUnsignedLongLong(uint64_t value)62 void UnsignedLongLongOrBooleanOrTestCallbackInterface::SetUnsignedLongLong(uint64_t value) {
63   DCHECK(IsNull());
64   unsigned_long_long_ = value;
65   type_ = SpecificType::kUnsignedLongLong;
66 }
67 
FromUnsignedLongLong(uint64_t value)68 UnsignedLongLongOrBooleanOrTestCallbackInterface UnsignedLongLongOrBooleanOrTestCallbackInterface::FromUnsignedLongLong(uint64_t value) {
69   UnsignedLongLongOrBooleanOrTestCallbackInterface container;
70   container.SetUnsignedLongLong(value);
71   return container;
72 }
73 
74 UnsignedLongLongOrBooleanOrTestCallbackInterface::UnsignedLongLongOrBooleanOrTestCallbackInterface(const UnsignedLongLongOrBooleanOrTestCallbackInterface&) = default;
75 UnsignedLongLongOrBooleanOrTestCallbackInterface::~UnsignedLongLongOrBooleanOrTestCallbackInterface() = default;
76 UnsignedLongLongOrBooleanOrTestCallbackInterface& UnsignedLongLongOrBooleanOrTestCallbackInterface::operator=(const UnsignedLongLongOrBooleanOrTestCallbackInterface&) = default;
77 
Trace(Visitor * visitor) const78 void UnsignedLongLongOrBooleanOrTestCallbackInterface::Trace(Visitor* visitor) const {
79   visitor->Trace(test_callback_interface_);
80 }
81 
ToImpl(v8::Isolate * isolate,v8::Local<v8::Value> v8_value,UnsignedLongLongOrBooleanOrTestCallbackInterface & impl,UnionTypeConversionMode conversion_mode,ExceptionState & exception_state)82 void V8UnsignedLongLongOrBooleanOrTestCallbackInterface::ToImpl(
83     v8::Isolate* isolate,
84     v8::Local<v8::Value> v8_value,
85     UnsignedLongLongOrBooleanOrTestCallbackInterface& impl,
86     UnionTypeConversionMode conversion_mode,
87     ExceptionState& exception_state) {
88   if (v8_value.IsEmpty())
89     return;
90 
91   if (conversion_mode == UnionTypeConversionMode::kNullable && IsUndefinedOrNull(v8_value))
92     return;
93 
94   if (V8TestCallbackInterface::HasInstance(v8_value, isolate)) {
95     V8TestCallbackInterface* cpp_value = V8TestCallbackInterface::ToImpl(v8::Local<v8::Object>::Cast(v8_value));
96     impl.SetTestCallbackInterface(cpp_value);
97     return;
98   }
99 
100   if (v8_value->IsBoolean()) {
101     impl.SetBoolean(v8_value.As<v8::Boolean>()->Value());
102     return;
103   }
104 
105   if (v8_value->IsNumber()) {
106     uint64_t cpp_value{ NativeValueTraits<IDLUnsignedLongLong>::NativeValue(isolate, v8_value, exception_state) };
107     if (exception_state.HadException())
108       return;
109     impl.SetUnsignedLongLong(cpp_value);
110     return;
111   }
112 
113   {
114     uint64_t cpp_value{ NativeValueTraits<IDLUnsignedLongLong>::NativeValue(isolate, v8_value, exception_state) };
115     if (exception_state.HadException())
116       return;
117     impl.SetUnsignedLongLong(cpp_value);
118     return;
119   }
120 }
121 
ToV8(const UnsignedLongLongOrBooleanOrTestCallbackInterface & impl,v8::Local<v8::Object> creationContext,v8::Isolate * isolate)122 v8::Local<v8::Value> ToV8(const UnsignedLongLongOrBooleanOrTestCallbackInterface& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) {
123   switch (impl.type_) {
124     case UnsignedLongLongOrBooleanOrTestCallbackInterface::SpecificType::kNone:
125       return v8::Null(isolate);
126     case UnsignedLongLongOrBooleanOrTestCallbackInterface::SpecificType::kBoolean:
127       return v8::Boolean::New(isolate, impl.GetAsBoolean());
128     case UnsignedLongLongOrBooleanOrTestCallbackInterface::SpecificType::kTestCallbackInterface:
129       return ToV8(impl.GetAsTestCallbackInterface(), creationContext, isolate);
130     case UnsignedLongLongOrBooleanOrTestCallbackInterface::SpecificType::kUnsignedLongLong:
131       return v8::Number::New(isolate, static_cast<double>(impl.GetAsUnsignedLongLong()));
132     default:
133       NOTREACHED();
134   }
135   return v8::Local<v8::Value>();
136 }
137 
NativeValue(v8::Isolate * isolate,v8::Local<v8::Value> value,ExceptionState & exception_state)138 UnsignedLongLongOrBooleanOrTestCallbackInterface NativeValueTraits<UnsignedLongLongOrBooleanOrTestCallbackInterface>::NativeValue(
139     v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exception_state) {
140   UnsignedLongLongOrBooleanOrTestCallbackInterface impl;
141   V8UnsignedLongLongOrBooleanOrTestCallbackInterface::ToImpl(isolate, value, impl, UnionTypeConversionMode::kNotNullable, exception_state);
142   return impl;
143 }
144 
145 }  // namespace blink
146 
147