Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/bindings/tests/results/core/UnionTypesCore.cpp

Issue 1961883002: Generate separate files for union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 by code_generator_v8.py. DO NOT MODIFY!
6
7 #include "bindings/core/v8/UnionTypesCore.h"
8
9 #include "bindings/core/v8/Dictionary.h"
10 #include "bindings/core/v8/UnionTypesCore.h"
11 #include "bindings/core/v8/V8ArrayBuffer.h"
12 #include "bindings/core/v8/V8ArrayBufferView.h"
13 #include "bindings/core/v8/V8Node.h"
14 #include "bindings/core/v8/V8NodeList.h"
15 #include "bindings/core/v8/V8TestInterface.h"
16 #include "bindings/core/v8/V8TestInterface2.h"
17 #include "bindings/core/v8/V8TestInterfaceEmpty.h"
18 #include "bindings/core/v8/V8TestInterfaceGarbageCollected.h"
19 #include "bindings/core/v8/V8Uint8Array.h"
20 #include "bindings/tests/idls/core/TestImplements2.h"
21 #include "bindings/tests/idls/core/TestImplements3Implementation.h"
22 #include "bindings/tests/idls/core/TestPartialInterface.h"
23 #include "bindings/tests/idls/core/TestPartialInterfaceImplementation.h"
24 #include "core/dom/FlexibleArrayBufferView.h"
25 #include "core/dom/NameNodeList.h"
26 #include "core/dom/NodeList.h"
27 #include "core/dom/StaticNodeList.h"
28 #include "core/html/LabelsNodeList.h"
29
30 namespace blink {
31
32 ArrayBufferOrArrayBufferViewOrDictionary::ArrayBufferOrArrayBufferViewOrDictiona ry()
33 : m_type(SpecificTypeNone)
34 {
35 }
36
37 TestArrayBuffer* ArrayBufferOrArrayBufferViewOrDictionary::getAsArrayBuffer() co nst
38 {
39 ASSERT(isArrayBuffer());
40 return m_arrayBuffer;
41 }
42
43 void ArrayBufferOrArrayBufferViewOrDictionary::setArrayBuffer(TestArrayBuffer* v alue)
44 {
45 ASSERT(isNull());
46 m_arrayBuffer = value;
47 m_type = SpecificTypeArrayBuffer;
48 }
49
50 ArrayBufferOrArrayBufferViewOrDictionary ArrayBufferOrArrayBufferViewOrDictionar y::fromArrayBuffer(TestArrayBuffer* value)
51 {
52 ArrayBufferOrArrayBufferViewOrDictionary container;
53 container.setArrayBuffer(value);
54 return container;
55 }
56
57 TestArrayBufferView* ArrayBufferOrArrayBufferViewOrDictionary::getAsArrayBufferV iew() const
58 {
59 ASSERT(isArrayBufferView());
60 return m_arrayBufferView;
61 }
62
63 void ArrayBufferOrArrayBufferViewOrDictionary::setArrayBufferView(TestArrayBuffe rView* value)
64 {
65 ASSERT(isNull());
66 m_arrayBufferView = value;
67 m_type = SpecificTypeArrayBufferView;
68 }
69
70 ArrayBufferOrArrayBufferViewOrDictionary ArrayBufferOrArrayBufferViewOrDictionar y::fromArrayBufferView(TestArrayBufferView* value)
71 {
72 ArrayBufferOrArrayBufferViewOrDictionary container;
73 container.setArrayBufferView(value);
74 return container;
75 }
76
77 Dictionary ArrayBufferOrArrayBufferViewOrDictionary::getAsDictionary() const
78 {
79 ASSERT(isDictionary());
80 return m_dictionary;
81 }
82
83 void ArrayBufferOrArrayBufferViewOrDictionary::setDictionary(Dictionary value)
84 {
85 ASSERT(isNull());
86 m_dictionary = value;
87 m_type = SpecificTypeDictionary;
88 }
89
90 ArrayBufferOrArrayBufferViewOrDictionary ArrayBufferOrArrayBufferViewOrDictionar y::fromDictionary(Dictionary value)
91 {
92 ArrayBufferOrArrayBufferViewOrDictionary container;
93 container.setDictionary(value);
94 return container;
95 }
96
97 ArrayBufferOrArrayBufferViewOrDictionary::ArrayBufferOrArrayBufferViewOrDictiona ry(const ArrayBufferOrArrayBufferViewOrDictionary&) = default;
98 ArrayBufferOrArrayBufferViewOrDictionary::~ArrayBufferOrArrayBufferViewOrDiction ary() = default;
99 ArrayBufferOrArrayBufferViewOrDictionary& ArrayBufferOrArrayBufferViewOrDictiona ry::operator=(const ArrayBufferOrArrayBufferViewOrDictionary&) = default;
100
101 DEFINE_TRACE(ArrayBufferOrArrayBufferViewOrDictionary)
102 {
103 visitor->trace(m_arrayBuffer);
104 visitor->trace(m_arrayBufferView);
105 }
106
107 void V8ArrayBufferOrArrayBufferViewOrDictionary::toImpl(v8::Isolate* isolate, v8 ::Local<v8::Value> v8Value, ArrayBufferOrArrayBufferViewOrDictionary& impl, Unio nTypeConversionMode conversionMode, ExceptionState& exceptionState)
108 {
109 if (v8Value.IsEmpty())
110 return;
111
112 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
113 return;
114
115 if (V8ArrayBuffer::hasInstance(v8Value, isolate)) {
116 TestArrayBuffer* cppValue = V8ArrayBuffer::toImpl(v8::Local<v8::Object>: :Cast(v8Value));
117 impl.setArrayBuffer(cppValue);
118 return;
119 }
120
121 if (V8ArrayBufferView::hasInstance(v8Value, isolate)) {
122 TestArrayBufferView* cppValue = V8ArrayBufferView::toImpl(v8::Local<v8:: Object>::Cast(v8Value));
123 impl.setArrayBufferView(cppValue);
124 return;
125 }
126
127 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
128 Dictionary cppValue = Dictionary(v8Value, isolate, exceptionState);
129 if (exceptionState.hadException())
130 return;
131 impl.setDictionary(cppValue);
132 return;
133 }
134
135 exceptionState.throwTypeError("The provided value is not of type '(ArrayBuff er or ArrayBufferView or Dictionary)'");
136 }
137
138 v8::Local<v8::Value> toV8(const ArrayBufferOrArrayBufferViewOrDictionary& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
139 {
140 switch (impl.m_type) {
141 case ArrayBufferOrArrayBufferViewOrDictionary::SpecificTypeNone:
142 return v8::Null(isolate);
143 case ArrayBufferOrArrayBufferViewOrDictionary::SpecificTypeArrayBuffer:
144 return toV8(impl.getAsArrayBuffer(), creationContext, isolate);
145 case ArrayBufferOrArrayBufferViewOrDictionary::SpecificTypeArrayBufferView:
146 return toV8(impl.getAsArrayBufferView(), creationContext, isolate);
147 case ArrayBufferOrArrayBufferViewOrDictionary::SpecificTypeDictionary:
148 return impl.getAsDictionary().v8Value();
149 default:
150 ASSERT_NOT_REACHED();
151 }
152 return v8::Local<v8::Value>();
153 }
154
155 ArrayBufferOrArrayBufferViewOrDictionary NativeValueTraits<ArrayBufferOrArrayBuf ferViewOrDictionary>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> val ue, ExceptionState& exceptionState)
156 {
157 ArrayBufferOrArrayBufferViewOrDictionary impl;
158 V8ArrayBufferOrArrayBufferViewOrDictionary::toImpl(isolate, value, impl, Uni onTypeConversionMode::NotNullable, exceptionState);
159 return impl;
160 }
161
162 BooleanOrStringOrUnrestrictedDouble::BooleanOrStringOrUnrestrictedDouble()
163 : m_type(SpecificTypeNone)
164 {
165 }
166
167 bool BooleanOrStringOrUnrestrictedDouble::getAsBoolean() const
168 {
169 ASSERT(isBoolean());
170 return m_boolean;
171 }
172
173 void BooleanOrStringOrUnrestrictedDouble::setBoolean(bool value)
174 {
175 ASSERT(isNull());
176 m_boolean = value;
177 m_type = SpecificTypeBoolean;
178 }
179
180 BooleanOrStringOrUnrestrictedDouble BooleanOrStringOrUnrestrictedDouble::fromBoo lean(bool value)
181 {
182 BooleanOrStringOrUnrestrictedDouble container;
183 container.setBoolean(value);
184 return container;
185 }
186
187 String BooleanOrStringOrUnrestrictedDouble::getAsString() const
188 {
189 ASSERT(isString());
190 return m_string;
191 }
192
193 void BooleanOrStringOrUnrestrictedDouble::setString(String value)
194 {
195 ASSERT(isNull());
196 m_string = value;
197 m_type = SpecificTypeString;
198 }
199
200 BooleanOrStringOrUnrestrictedDouble BooleanOrStringOrUnrestrictedDouble::fromStr ing(String value)
201 {
202 BooleanOrStringOrUnrestrictedDouble container;
203 container.setString(value);
204 return container;
205 }
206
207 double BooleanOrStringOrUnrestrictedDouble::getAsUnrestrictedDouble() const
208 {
209 ASSERT(isUnrestrictedDouble());
210 return m_unrestrictedDouble;
211 }
212
213 void BooleanOrStringOrUnrestrictedDouble::setUnrestrictedDouble(double value)
214 {
215 ASSERT(isNull());
216 m_unrestrictedDouble = value;
217 m_type = SpecificTypeUnrestrictedDouble;
218 }
219
220 BooleanOrStringOrUnrestrictedDouble BooleanOrStringOrUnrestrictedDouble::fromUnr estrictedDouble(double value)
221 {
222 BooleanOrStringOrUnrestrictedDouble container;
223 container.setUnrestrictedDouble(value);
224 return container;
225 }
226
227 BooleanOrStringOrUnrestrictedDouble::BooleanOrStringOrUnrestrictedDouble(const B ooleanOrStringOrUnrestrictedDouble&) = default;
228 BooleanOrStringOrUnrestrictedDouble::~BooleanOrStringOrUnrestrictedDouble() = de fault;
229 BooleanOrStringOrUnrestrictedDouble& BooleanOrStringOrUnrestrictedDouble::operat or=(const BooleanOrStringOrUnrestrictedDouble&) = default;
230
231 DEFINE_TRACE(BooleanOrStringOrUnrestrictedDouble)
232 {
233 }
234
235 void V8BooleanOrStringOrUnrestrictedDouble::toImpl(v8::Isolate* isolate, v8::Loc al<v8::Value> v8Value, BooleanOrStringOrUnrestrictedDouble& impl, UnionTypeConve rsionMode conversionMode, ExceptionState& exceptionState)
236 {
237 if (v8Value.IsEmpty())
238 return;
239
240 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
241 return;
242
243 if (v8Value->IsBoolean()) {
244 impl.setBoolean(v8Value.As<v8::Boolean>()->Value());
245 return;
246 }
247
248 if (v8Value->IsNumber()) {
249 double cppValue = toDouble(isolate, v8Value, exceptionState);
250 if (exceptionState.hadException())
251 return;
252 impl.setUnrestrictedDouble(cppValue);
253 return;
254 }
255
256 {
257 V8StringResource<> cppValue = v8Value;
258 if (!cppValue.prepare(exceptionState))
259 return;
260 impl.setString(cppValue);
261 return;
262 }
263
264 }
265
266 v8::Local<v8::Value> toV8(const BooleanOrStringOrUnrestrictedDouble& impl, v8::L ocal<v8::Object> creationContext, v8::Isolate* isolate)
267 {
268 switch (impl.m_type) {
269 case BooleanOrStringOrUnrestrictedDouble::SpecificTypeNone:
270 return v8::Null(isolate);
271 case BooleanOrStringOrUnrestrictedDouble::SpecificTypeBoolean:
272 return v8Boolean(impl.getAsBoolean(), isolate);
273 case BooleanOrStringOrUnrestrictedDouble::SpecificTypeString:
274 return v8String(isolate, impl.getAsString());
275 case BooleanOrStringOrUnrestrictedDouble::SpecificTypeUnrestrictedDouble:
276 return v8::Number::New(isolate, impl.getAsUnrestrictedDouble());
277 default:
278 ASSERT_NOT_REACHED();
279 }
280 return v8::Local<v8::Value>();
281 }
282
283 BooleanOrStringOrUnrestrictedDouble NativeValueTraits<BooleanOrStringOrUnrestric tedDouble>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Except ionState& exceptionState)
284 {
285 BooleanOrStringOrUnrestrictedDouble impl;
286 V8BooleanOrStringOrUnrestrictedDouble::toImpl(isolate, value, impl, UnionTyp eConversionMode::NotNullable, exceptionState);
287 return impl;
288 }
289
290 DoubleOrString::DoubleOrString()
291 : m_type(SpecificTypeNone)
292 {
293 }
294
295 double DoubleOrString::getAsDouble() const
296 {
297 ASSERT(isDouble());
298 return m_double;
299 }
300
301 void DoubleOrString::setDouble(double value)
302 {
303 ASSERT(isNull());
304 m_double = value;
305 m_type = SpecificTypeDouble;
306 }
307
308 DoubleOrString DoubleOrString::fromDouble(double value)
309 {
310 DoubleOrString container;
311 container.setDouble(value);
312 return container;
313 }
314
315 String DoubleOrString::getAsString() const
316 {
317 ASSERT(isString());
318 return m_string;
319 }
320
321 void DoubleOrString::setString(String value)
322 {
323 ASSERT(isNull());
324 m_string = value;
325 m_type = SpecificTypeString;
326 }
327
328 DoubleOrString DoubleOrString::fromString(String value)
329 {
330 DoubleOrString container;
331 container.setString(value);
332 return container;
333 }
334
335 DoubleOrString::DoubleOrString(const DoubleOrString&) = default;
336 DoubleOrString::~DoubleOrString() = default;
337 DoubleOrString& DoubleOrString::operator=(const DoubleOrString&) = default;
338
339 DEFINE_TRACE(DoubleOrString)
340 {
341 }
342
343 void V8DoubleOrString::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value , DoubleOrString& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
344 {
345 if (v8Value.IsEmpty())
346 return;
347
348 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
349 return;
350
351 if (v8Value->IsNumber()) {
352 double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState);
353 if (exceptionState.hadException())
354 return;
355 impl.setDouble(cppValue);
356 return;
357 }
358
359 {
360 V8StringResource<> cppValue = v8Value;
361 if (!cppValue.prepare(exceptionState))
362 return;
363 impl.setString(cppValue);
364 return;
365 }
366
367 }
368
369 v8::Local<v8::Value> toV8(const DoubleOrString& impl, v8::Local<v8::Object> crea tionContext, v8::Isolate* isolate)
370 {
371 switch (impl.m_type) {
372 case DoubleOrString::SpecificTypeNone:
373 return v8::Null(isolate);
374 case DoubleOrString::SpecificTypeDouble:
375 return v8::Number::New(isolate, impl.getAsDouble());
376 case DoubleOrString::SpecificTypeString:
377 return v8String(isolate, impl.getAsString());
378 default:
379 ASSERT_NOT_REACHED();
380 }
381 return v8::Local<v8::Value>();
382 }
383
384 DoubleOrString NativeValueTraits<DoubleOrString>::nativeValue(v8::Isolate* isola te, v8::Local<v8::Value> value, ExceptionState& exceptionState)
385 {
386 DoubleOrString impl;
387 V8DoubleOrString::toImpl(isolate, value, impl, UnionTypeConversionMode::NotN ullable, exceptionState);
388 return impl;
389 }
390
391 LongOrTestDictionary::LongOrTestDictionary()
392 : m_type(SpecificTypeNone)
393 {
394 }
395
396 int LongOrTestDictionary::getAsLong() const
397 {
398 ASSERT(isLong());
399 return m_long;
400 }
401
402 void LongOrTestDictionary::setLong(int value)
403 {
404 ASSERT(isNull());
405 m_long = value;
406 m_type = SpecificTypeLong;
407 }
408
409 LongOrTestDictionary LongOrTestDictionary::fromLong(int value)
410 {
411 LongOrTestDictionary container;
412 container.setLong(value);
413 return container;
414 }
415
416 TestDictionary LongOrTestDictionary::getAsTestDictionary() const
417 {
418 ASSERT(isTestDictionary());
419 return m_testDictionary;
420 }
421
422 void LongOrTestDictionary::setTestDictionary(TestDictionary value)
423 {
424 ASSERT(isNull());
425 m_testDictionary = value;
426 m_type = SpecificTypeTestDictionary;
427 }
428
429 LongOrTestDictionary LongOrTestDictionary::fromTestDictionary(TestDictionary val ue)
430 {
431 LongOrTestDictionary container;
432 container.setTestDictionary(value);
433 return container;
434 }
435
436 LongOrTestDictionary::LongOrTestDictionary(const LongOrTestDictionary&) = defaul t;
437 LongOrTestDictionary::~LongOrTestDictionary() = default;
438 LongOrTestDictionary& LongOrTestDictionary::operator=(const LongOrTestDictionary &) = default;
439
440 DEFINE_TRACE(LongOrTestDictionary)
441 {
442 visitor->trace(m_testDictionary);
443 }
444
445 void V8LongOrTestDictionary::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v 8Value, LongOrTestDictionary& impl, UnionTypeConversionMode conversionMode, Exce ptionState& exceptionState)
446 {
447 if (v8Value.IsEmpty())
448 return;
449
450 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
451 return;
452
453 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
454 TestDictionary cppValue;
455 V8TestDictionary::toImpl(isolate, v8Value, cppValue, exceptionState);
456 if (exceptionState.hadException())
457 return;
458 impl.setTestDictionary(cppValue);
459 return;
460 }
461
462 if (v8Value->IsNumber()) {
463 int cppValue = toInt32(isolate, v8Value, NormalConversion, exceptionStat e);
464 if (exceptionState.hadException())
465 return;
466 impl.setLong(cppValue);
467 return;
468 }
469
470 {
471 int cppValue = toInt32(isolate, v8Value, NormalConversion, exceptionStat e);
472 if (exceptionState.hadException())
473 return;
474 impl.setLong(cppValue);
475 return;
476 }
477
478 }
479
480 v8::Local<v8::Value> toV8(const LongOrTestDictionary& impl, v8::Local<v8::Object > creationContext, v8::Isolate* isolate)
481 {
482 switch (impl.m_type) {
483 case LongOrTestDictionary::SpecificTypeNone:
484 return v8::Null(isolate);
485 case LongOrTestDictionary::SpecificTypeLong:
486 return v8::Integer::New(isolate, impl.getAsLong());
487 case LongOrTestDictionary::SpecificTypeTestDictionary:
488 return toV8(impl.getAsTestDictionary(), creationContext, isolate);
489 default:
490 ASSERT_NOT_REACHED();
491 }
492 return v8::Local<v8::Value>();
493 }
494
495 LongOrTestDictionary NativeValueTraits<LongOrTestDictionary>::nativeValue(v8::Is olate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState)
496 {
497 LongOrTestDictionary impl;
498 V8LongOrTestDictionary::toImpl(isolate, value, impl, UnionTypeConversionMode ::NotNullable, exceptionState);
499 return impl;
500 }
501
502 NodeOrNodeList::NodeOrNodeList()
503 : m_type(SpecificTypeNone)
504 {
505 }
506
507 Node* NodeOrNodeList::getAsNode() const
508 {
509 ASSERT(isNode());
510 return m_node;
511 }
512
513 void NodeOrNodeList::setNode(Node* value)
514 {
515 ASSERT(isNull());
516 m_node = value;
517 m_type = SpecificTypeNode;
518 }
519
520 NodeOrNodeList NodeOrNodeList::fromNode(Node* value)
521 {
522 NodeOrNodeList container;
523 container.setNode(value);
524 return container;
525 }
526
527 NodeList* NodeOrNodeList::getAsNodeList() const
528 {
529 ASSERT(isNodeList());
530 return m_nodeList;
531 }
532
533 void NodeOrNodeList::setNodeList(NodeList* value)
534 {
535 ASSERT(isNull());
536 m_nodeList = value;
537 m_type = SpecificTypeNodeList;
538 }
539
540 NodeOrNodeList NodeOrNodeList::fromNodeList(NodeList* value)
541 {
542 NodeOrNodeList container;
543 container.setNodeList(value);
544 return container;
545 }
546
547 NodeOrNodeList::NodeOrNodeList(const NodeOrNodeList&) = default;
548 NodeOrNodeList::~NodeOrNodeList() = default;
549 NodeOrNodeList& NodeOrNodeList::operator=(const NodeOrNodeList&) = default;
550
551 DEFINE_TRACE(NodeOrNodeList)
552 {
553 visitor->trace(m_node);
554 visitor->trace(m_nodeList);
555 }
556
557 void V8NodeOrNodeList::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value , NodeOrNodeList& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
558 {
559 if (v8Value.IsEmpty())
560 return;
561
562 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
563 return;
564
565 if (V8Node::hasInstance(v8Value, isolate)) {
566 Node* cppValue = V8Node::toImpl(v8::Local<v8::Object>::Cast(v8Value));
567 impl.setNode(cppValue);
568 return;
569 }
570
571 if (V8NodeList::hasInstance(v8Value, isolate)) {
572 NodeList* cppValue = V8NodeList::toImpl(v8::Local<v8::Object>::Cast(v8Va lue));
573 impl.setNodeList(cppValue);
574 return;
575 }
576
577 exceptionState.throwTypeError("The provided value is not of type '(Node or N odeList)'");
578 }
579
580 v8::Local<v8::Value> toV8(const NodeOrNodeList& impl, v8::Local<v8::Object> crea tionContext, v8::Isolate* isolate)
581 {
582 switch (impl.m_type) {
583 case NodeOrNodeList::SpecificTypeNone:
584 return v8::Null(isolate);
585 case NodeOrNodeList::SpecificTypeNode:
586 return toV8(impl.getAsNode(), creationContext, isolate);
587 case NodeOrNodeList::SpecificTypeNodeList:
588 return toV8(impl.getAsNodeList(), creationContext, isolate);
589 default:
590 ASSERT_NOT_REACHED();
591 }
592 return v8::Local<v8::Value>();
593 }
594
595 NodeOrNodeList NativeValueTraits<NodeOrNodeList>::nativeValue(v8::Isolate* isola te, v8::Local<v8::Value> value, ExceptionState& exceptionState)
596 {
597 NodeOrNodeList impl;
598 V8NodeOrNodeList::toImpl(isolate, value, impl, UnionTypeConversionMode::NotN ullable, exceptionState);
599 return impl;
600 }
601
602 StringOrArrayBufferOrArrayBufferView::StringOrArrayBufferOrArrayBufferView()
603 : m_type(SpecificTypeNone)
604 {
605 }
606
607 String StringOrArrayBufferOrArrayBufferView::getAsString() const
608 {
609 ASSERT(isString());
610 return m_string;
611 }
612
613 void StringOrArrayBufferOrArrayBufferView::setString(String value)
614 {
615 ASSERT(isNull());
616 m_string = value;
617 m_type = SpecificTypeString;
618 }
619
620 StringOrArrayBufferOrArrayBufferView StringOrArrayBufferOrArrayBufferView::fromS tring(String value)
621 {
622 StringOrArrayBufferOrArrayBufferView container;
623 container.setString(value);
624 return container;
625 }
626
627 TestArrayBuffer* StringOrArrayBufferOrArrayBufferView::getAsArrayBuffer() const
628 {
629 ASSERT(isArrayBuffer());
630 return m_arrayBuffer;
631 }
632
633 void StringOrArrayBufferOrArrayBufferView::setArrayBuffer(TestArrayBuffer* value )
634 {
635 ASSERT(isNull());
636 m_arrayBuffer = value;
637 m_type = SpecificTypeArrayBuffer;
638 }
639
640 StringOrArrayBufferOrArrayBufferView StringOrArrayBufferOrArrayBufferView::fromA rrayBuffer(TestArrayBuffer* value)
641 {
642 StringOrArrayBufferOrArrayBufferView container;
643 container.setArrayBuffer(value);
644 return container;
645 }
646
647 TestArrayBufferView* StringOrArrayBufferOrArrayBufferView::getAsArrayBufferView( ) const
648 {
649 ASSERT(isArrayBufferView());
650 return m_arrayBufferView;
651 }
652
653 void StringOrArrayBufferOrArrayBufferView::setArrayBufferView(TestArrayBufferVie w* value)
654 {
655 ASSERT(isNull());
656 m_arrayBufferView = value;
657 m_type = SpecificTypeArrayBufferView;
658 }
659
660 StringOrArrayBufferOrArrayBufferView StringOrArrayBufferOrArrayBufferView::fromA rrayBufferView(TestArrayBufferView* value)
661 {
662 StringOrArrayBufferOrArrayBufferView container;
663 container.setArrayBufferView(value);
664 return container;
665 }
666
667 StringOrArrayBufferOrArrayBufferView::StringOrArrayBufferOrArrayBufferView(const StringOrArrayBufferOrArrayBufferView&) = default;
668 StringOrArrayBufferOrArrayBufferView::~StringOrArrayBufferOrArrayBufferView() = default;
669 StringOrArrayBufferOrArrayBufferView& StringOrArrayBufferOrArrayBufferView::oper ator=(const StringOrArrayBufferOrArrayBufferView&) = default;
670
671 DEFINE_TRACE(StringOrArrayBufferOrArrayBufferView)
672 {
673 visitor->trace(m_arrayBuffer);
674 visitor->trace(m_arrayBufferView);
675 }
676
677 void V8StringOrArrayBufferOrArrayBufferView::toImpl(v8::Isolate* isolate, v8::Lo cal<v8::Value> v8Value, StringOrArrayBufferOrArrayBufferView& impl, UnionTypeCon versionMode conversionMode, ExceptionState& exceptionState)
678 {
679 if (v8Value.IsEmpty())
680 return;
681
682 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
683 return;
684
685 if (V8ArrayBuffer::hasInstance(v8Value, isolate)) {
686 TestArrayBuffer* cppValue = V8ArrayBuffer::toImpl(v8::Local<v8::Object>: :Cast(v8Value));
687 impl.setArrayBuffer(cppValue);
688 return;
689 }
690
691 if (V8ArrayBufferView::hasInstance(v8Value, isolate)) {
692 TestArrayBufferView* cppValue = V8ArrayBufferView::toImpl(v8::Local<v8:: Object>::Cast(v8Value));
693 impl.setArrayBufferView(cppValue);
694 return;
695 }
696
697 {
698 V8StringResource<> cppValue = v8Value;
699 if (!cppValue.prepare(exceptionState))
700 return;
701 impl.setString(cppValue);
702 return;
703 }
704
705 }
706
707 v8::Local<v8::Value> toV8(const StringOrArrayBufferOrArrayBufferView& impl, v8:: Local<v8::Object> creationContext, v8::Isolate* isolate)
708 {
709 switch (impl.m_type) {
710 case StringOrArrayBufferOrArrayBufferView::SpecificTypeNone:
711 return v8::Null(isolate);
712 case StringOrArrayBufferOrArrayBufferView::SpecificTypeString:
713 return v8String(isolate, impl.getAsString());
714 case StringOrArrayBufferOrArrayBufferView::SpecificTypeArrayBuffer:
715 return toV8(impl.getAsArrayBuffer(), creationContext, isolate);
716 case StringOrArrayBufferOrArrayBufferView::SpecificTypeArrayBufferView:
717 return toV8(impl.getAsArrayBufferView(), creationContext, isolate);
718 default:
719 ASSERT_NOT_REACHED();
720 }
721 return v8::Local<v8::Value>();
722 }
723
724 StringOrArrayBufferOrArrayBufferView NativeValueTraits<StringOrArrayBufferOrArra yBufferView>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Exce ptionState& exceptionState)
725 {
726 StringOrArrayBufferOrArrayBufferView impl;
727 V8StringOrArrayBufferOrArrayBufferView::toImpl(isolate, value, impl, UnionTy peConversionMode::NotNullable, exceptionState);
728 return impl;
729 }
730
731 StringOrDouble::StringOrDouble()
732 : m_type(SpecificTypeNone)
733 {
734 }
735
736 String StringOrDouble::getAsString() const
737 {
738 ASSERT(isString());
739 return m_string;
740 }
741
742 void StringOrDouble::setString(String value)
743 {
744 ASSERT(isNull());
745 m_string = value;
746 m_type = SpecificTypeString;
747 }
748
749 StringOrDouble StringOrDouble::fromString(String value)
750 {
751 StringOrDouble container;
752 container.setString(value);
753 return container;
754 }
755
756 double StringOrDouble::getAsDouble() const
757 {
758 ASSERT(isDouble());
759 return m_double;
760 }
761
762 void StringOrDouble::setDouble(double value)
763 {
764 ASSERT(isNull());
765 m_double = value;
766 m_type = SpecificTypeDouble;
767 }
768
769 StringOrDouble StringOrDouble::fromDouble(double value)
770 {
771 StringOrDouble container;
772 container.setDouble(value);
773 return container;
774 }
775
776 StringOrDouble::StringOrDouble(const StringOrDouble&) = default;
777 StringOrDouble::~StringOrDouble() = default;
778 StringOrDouble& StringOrDouble::operator=(const StringOrDouble&) = default;
779
780 DEFINE_TRACE(StringOrDouble)
781 {
782 }
783
784 void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value , StringOrDouble& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
785 {
786 if (v8Value.IsEmpty())
787 return;
788
789 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
790 return;
791
792 if (v8Value->IsNumber()) {
793 double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState);
794 if (exceptionState.hadException())
795 return;
796 impl.setDouble(cppValue);
797 return;
798 }
799
800 {
801 V8StringResource<> cppValue = v8Value;
802 if (!cppValue.prepare(exceptionState))
803 return;
804 impl.setString(cppValue);
805 return;
806 }
807
808 }
809
810 v8::Local<v8::Value> toV8(const StringOrDouble& impl, v8::Local<v8::Object> crea tionContext, v8::Isolate* isolate)
811 {
812 switch (impl.m_type) {
813 case StringOrDouble::SpecificTypeNone:
814 return v8::Null(isolate);
815 case StringOrDouble::SpecificTypeString:
816 return v8String(isolate, impl.getAsString());
817 case StringOrDouble::SpecificTypeDouble:
818 return v8::Number::New(isolate, impl.getAsDouble());
819 default:
820 ASSERT_NOT_REACHED();
821 }
822 return v8::Local<v8::Value>();
823 }
824
825 StringOrDouble NativeValueTraits<StringOrDouble>::nativeValue(v8::Isolate* isola te, v8::Local<v8::Value> value, ExceptionState& exceptionState)
826 {
827 StringOrDouble impl;
828 V8StringOrDouble::toImpl(isolate, value, impl, UnionTypeConversionMode::NotN ullable, exceptionState);
829 return impl;
830 }
831
832 StringOrStringSequence::StringOrStringSequence()
833 : m_type(SpecificTypeNone)
834 {
835 }
836
837 String StringOrStringSequence::getAsString() const
838 {
839 ASSERT(isString());
840 return m_string;
841 }
842
843 void StringOrStringSequence::setString(String value)
844 {
845 ASSERT(isNull());
846 m_string = value;
847 m_type = SpecificTypeString;
848 }
849
850 StringOrStringSequence StringOrStringSequence::fromString(String value)
851 {
852 StringOrStringSequence container;
853 container.setString(value);
854 return container;
855 }
856
857 const Vector<String>& StringOrStringSequence::getAsStringSequence() const
858 {
859 ASSERT(isStringSequence());
860 return m_stringSequence;
861 }
862
863 void StringOrStringSequence::setStringSequence(const Vector<String>& value)
864 {
865 ASSERT(isNull());
866 m_stringSequence = value;
867 m_type = SpecificTypeStringSequence;
868 }
869
870 StringOrStringSequence StringOrStringSequence::fromStringSequence(const Vector<S tring>& value)
871 {
872 StringOrStringSequence container;
873 container.setStringSequence(value);
874 return container;
875 }
876
877 StringOrStringSequence::StringOrStringSequence(const StringOrStringSequence&) = default;
878 StringOrStringSequence::~StringOrStringSequence() = default;
879 StringOrStringSequence& StringOrStringSequence::operator=(const StringOrStringSe quence&) = default;
880
881 DEFINE_TRACE(StringOrStringSequence)
882 {
883 }
884
885 void V8StringOrStringSequence::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, StringOrStringSequence& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
886 {
887 if (v8Value.IsEmpty())
888 return;
889
890 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
891 return;
892
893 if (v8Value->IsArray()) {
894 Vector<String> cppValue = toImplArray<Vector<String>>(v8Value, 0, isolat e, exceptionState);
895 if (exceptionState.hadException())
896 return;
897 impl.setStringSequence(cppValue);
898 return;
899 }
900
901 {
902 V8StringResource<> cppValue = v8Value;
903 if (!cppValue.prepare(exceptionState))
904 return;
905 impl.setString(cppValue);
906 return;
907 }
908
909 }
910
911 v8::Local<v8::Value> toV8(const StringOrStringSequence& impl, v8::Local<v8::Obje ct> creationContext, v8::Isolate* isolate)
912 {
913 switch (impl.m_type) {
914 case StringOrStringSequence::SpecificTypeNone:
915 return v8::Null(isolate);
916 case StringOrStringSequence::SpecificTypeString:
917 return v8String(isolate, impl.getAsString());
918 case StringOrStringSequence::SpecificTypeStringSequence:
919 return toV8(impl.getAsStringSequence(), creationContext, isolate);
920 default:
921 ASSERT_NOT_REACHED();
922 }
923 return v8::Local<v8::Value>();
924 }
925
926 StringOrStringSequence NativeValueTraits<StringOrStringSequence>::nativeValue(v8 ::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState)
927 {
928 StringOrStringSequence impl;
929 V8StringOrStringSequence::toImpl(isolate, value, impl, UnionTypeConversionMo de::NotNullable, exceptionState);
930 return impl;
931 }
932
933 TestEnumOrDouble::TestEnumOrDouble()
934 : m_type(SpecificTypeNone)
935 {
936 }
937
938 String TestEnumOrDouble::getAsTestEnum() const
939 {
940 ASSERT(isTestEnum());
941 return m_testEnum;
942 }
943
944 void TestEnumOrDouble::setTestEnum(String value)
945 {
946 ASSERT(isNull());
947 NonThrowableExceptionState exceptionState;
948 const char* validValues[] = {
949 "",
950 "EnumValue1",
951 "EnumValue2",
952 "EnumValue3",
953 };
954 if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), "TestEnu m", exceptionState)) {
955 ASSERT_NOT_REACHED();
956 return;
957 }
958 m_testEnum = value;
959 m_type = SpecificTypeTestEnum;
960 }
961
962 TestEnumOrDouble TestEnumOrDouble::fromTestEnum(String value)
963 {
964 TestEnumOrDouble container;
965 container.setTestEnum(value);
966 return container;
967 }
968
969 double TestEnumOrDouble::getAsDouble() const
970 {
971 ASSERT(isDouble());
972 return m_double;
973 }
974
975 void TestEnumOrDouble::setDouble(double value)
976 {
977 ASSERT(isNull());
978 m_double = value;
979 m_type = SpecificTypeDouble;
980 }
981
982 TestEnumOrDouble TestEnumOrDouble::fromDouble(double value)
983 {
984 TestEnumOrDouble container;
985 container.setDouble(value);
986 return container;
987 }
988
989 TestEnumOrDouble::TestEnumOrDouble(const TestEnumOrDouble&) = default;
990 TestEnumOrDouble::~TestEnumOrDouble() = default;
991 TestEnumOrDouble& TestEnumOrDouble::operator=(const TestEnumOrDouble&) = default ;
992
993 DEFINE_TRACE(TestEnumOrDouble)
994 {
995 }
996
997 void V8TestEnumOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Val ue, TestEnumOrDouble& impl, UnionTypeConversionMode conversionMode, ExceptionSta te& exceptionState)
998 {
999 if (v8Value.IsEmpty())
1000 return;
1001
1002 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1003 return;
1004
1005 if (v8Value->IsNumber()) {
1006 double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState);
1007 if (exceptionState.hadException())
1008 return;
1009 impl.setDouble(cppValue);
1010 return;
1011 }
1012
1013 {
1014 V8StringResource<> cppValue = v8Value;
1015 if (!cppValue.prepare(exceptionState))
1016 return;
1017 const char* validValues[] = {
1018 "",
1019 "EnumValue1",
1020 "EnumValue2",
1021 "EnumValue3",
1022 };
1023 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), " TestEnum", exceptionState))
1024 return;
1025 impl.setTestEnum(cppValue);
1026 return;
1027 }
1028
1029 }
1030
1031 v8::Local<v8::Value> toV8(const TestEnumOrDouble& impl, v8::Local<v8::Object> cr eationContext, v8::Isolate* isolate)
1032 {
1033 switch (impl.m_type) {
1034 case TestEnumOrDouble::SpecificTypeNone:
1035 return v8::Null(isolate);
1036 case TestEnumOrDouble::SpecificTypeTestEnum:
1037 return v8String(isolate, impl.getAsTestEnum());
1038 case TestEnumOrDouble::SpecificTypeDouble:
1039 return v8::Number::New(isolate, impl.getAsDouble());
1040 default:
1041 ASSERT_NOT_REACHED();
1042 }
1043 return v8::Local<v8::Value>();
1044 }
1045
1046 TestEnumOrDouble NativeValueTraits<TestEnumOrDouble>::nativeValue(v8::Isolate* i solate, v8::Local<v8::Value> value, ExceptionState& exceptionState)
1047 {
1048 TestEnumOrDouble impl;
1049 V8TestEnumOrDouble::toImpl(isolate, value, impl, UnionTypeConversionMode::No tNullable, exceptionState);
1050 return impl;
1051 }
1052
1053 TestInterface2OrUint8Array::TestInterface2OrUint8Array()
1054 : m_type(SpecificTypeNone)
1055 {
1056 }
1057
1058 TestInterface2* TestInterface2OrUint8Array::getAsTestInterface2() const
1059 {
1060 ASSERT(isTestInterface2());
1061 return m_testInterface2;
1062 }
1063
1064 void TestInterface2OrUint8Array::setTestInterface2(TestInterface2* value)
1065 {
1066 ASSERT(isNull());
1067 m_testInterface2 = value;
1068 m_type = SpecificTypeTestInterface2;
1069 }
1070
1071 TestInterface2OrUint8Array TestInterface2OrUint8Array::fromTestInterface2(TestIn terface2* value)
1072 {
1073 TestInterface2OrUint8Array container;
1074 container.setTestInterface2(value);
1075 return container;
1076 }
1077
1078 DOMUint8Array* TestInterface2OrUint8Array::getAsUint8Array() const
1079 {
1080 ASSERT(isUint8Array());
1081 return m_uint8Array;
1082 }
1083
1084 void TestInterface2OrUint8Array::setUint8Array(DOMUint8Array* value)
1085 {
1086 ASSERT(isNull());
1087 m_uint8Array = value;
1088 m_type = SpecificTypeUint8Array;
1089 }
1090
1091 TestInterface2OrUint8Array TestInterface2OrUint8Array::fromUint8Array(DOMUint8Ar ray* value)
1092 {
1093 TestInterface2OrUint8Array container;
1094 container.setUint8Array(value);
1095 return container;
1096 }
1097
1098 TestInterface2OrUint8Array::TestInterface2OrUint8Array(const TestInterface2OrUin t8Array&) = default;
1099 TestInterface2OrUint8Array::~TestInterface2OrUint8Array() = default;
1100 TestInterface2OrUint8Array& TestInterface2OrUint8Array::operator=(const TestInte rface2OrUint8Array&) = default;
1101
1102 DEFINE_TRACE(TestInterface2OrUint8Array)
1103 {
1104 visitor->trace(m_testInterface2);
1105 visitor->trace(m_uint8Array);
1106 }
1107
1108 void V8TestInterface2OrUint8Array::toImpl(v8::Isolate* isolate, v8::Local<v8::Va lue> v8Value, TestInterface2OrUint8Array& impl, UnionTypeConversionMode conversi onMode, ExceptionState& exceptionState)
1109 {
1110 if (v8Value.IsEmpty())
1111 return;
1112
1113 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1114 return;
1115
1116 if (V8TestInterface2::hasInstance(v8Value, isolate)) {
1117 TestInterface2* cppValue = V8TestInterface2::toImpl(v8::Local<v8::Object >::Cast(v8Value));
1118 impl.setTestInterface2(cppValue);
1119 return;
1120 }
1121
1122 if (V8Uint8Array::hasInstance(v8Value, isolate)) {
1123 DOMUint8Array* cppValue = V8Uint8Array::toImpl(v8::Local<v8::Object>::Ca st(v8Value));
1124 impl.setUint8Array(cppValue);
1125 return;
1126 }
1127
1128 exceptionState.throwTypeError("The provided value is not of type '(TestInter face2 or Uint8Array)'");
1129 }
1130
1131 v8::Local<v8::Value> toV8(const TestInterface2OrUint8Array& impl, v8::Local<v8:: Object> creationContext, v8::Isolate* isolate)
1132 {
1133 switch (impl.m_type) {
1134 case TestInterface2OrUint8Array::SpecificTypeNone:
1135 return v8::Null(isolate);
1136 case TestInterface2OrUint8Array::SpecificTypeTestInterface2:
1137 return toV8(impl.getAsTestInterface2(), creationContext, isolate);
1138 case TestInterface2OrUint8Array::SpecificTypeUint8Array:
1139 return toV8(impl.getAsUint8Array(), creationContext, isolate);
1140 default:
1141 ASSERT_NOT_REACHED();
1142 }
1143 return v8::Local<v8::Value>();
1144 }
1145
1146 TestInterface2OrUint8Array NativeValueTraits<TestInterface2OrUint8Array>::native Value(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptio nState)
1147 {
1148 TestInterface2OrUint8Array impl;
1149 V8TestInterface2OrUint8Array::toImpl(isolate, value, impl, UnionTypeConversi onMode::NotNullable, exceptionState);
1150 return impl;
1151 }
1152
1153 TestInterfaceGarbageCollectedOrString::TestInterfaceGarbageCollectedOrString()
1154 : m_type(SpecificTypeNone)
1155 {
1156 }
1157
1158 TestInterfaceGarbageCollected* TestInterfaceGarbageCollectedOrString::getAsTestI nterfaceGarbageCollected() const
1159 {
1160 ASSERT(isTestInterfaceGarbageCollected());
1161 return m_testInterfaceGarbageCollected;
1162 }
1163
1164 void TestInterfaceGarbageCollectedOrString::setTestInterfaceGarbageCollected(Tes tInterfaceGarbageCollected* value)
1165 {
1166 ASSERT(isNull());
1167 m_testInterfaceGarbageCollected = value;
1168 m_type = SpecificTypeTestInterfaceGarbageCollected;
1169 }
1170
1171 TestInterfaceGarbageCollectedOrString TestInterfaceGarbageCollectedOrString::fro mTestInterfaceGarbageCollected(TestInterfaceGarbageCollected* value)
1172 {
1173 TestInterfaceGarbageCollectedOrString container;
1174 container.setTestInterfaceGarbageCollected(value);
1175 return container;
1176 }
1177
1178 String TestInterfaceGarbageCollectedOrString::getAsString() const
1179 {
1180 ASSERT(isString());
1181 return m_string;
1182 }
1183
1184 void TestInterfaceGarbageCollectedOrString::setString(String value)
1185 {
1186 ASSERT(isNull());
1187 m_string = value;
1188 m_type = SpecificTypeString;
1189 }
1190
1191 TestInterfaceGarbageCollectedOrString TestInterfaceGarbageCollectedOrString::fro mString(String value)
1192 {
1193 TestInterfaceGarbageCollectedOrString container;
1194 container.setString(value);
1195 return container;
1196 }
1197
1198 TestInterfaceGarbageCollectedOrString::TestInterfaceGarbageCollectedOrString(con st TestInterfaceGarbageCollectedOrString&) = default;
1199 TestInterfaceGarbageCollectedOrString::~TestInterfaceGarbageCollectedOrString() = default;
1200 TestInterfaceGarbageCollectedOrString& TestInterfaceGarbageCollectedOrString::op erator=(const TestInterfaceGarbageCollectedOrString&) = default;
1201
1202 DEFINE_TRACE(TestInterfaceGarbageCollectedOrString)
1203 {
1204 visitor->trace(m_testInterfaceGarbageCollected);
1205 }
1206
1207 void V8TestInterfaceGarbageCollectedOrString::toImpl(v8::Isolate* isolate, v8::L ocal<v8::Value> v8Value, TestInterfaceGarbageCollectedOrString& impl, UnionTypeC onversionMode conversionMode, ExceptionState& exceptionState)
1208 {
1209 if (v8Value.IsEmpty())
1210 return;
1211
1212 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1213 return;
1214
1215 if (V8TestInterfaceGarbageCollected::hasInstance(v8Value, isolate)) {
1216 TestInterfaceGarbageCollected* cppValue = V8TestInterfaceGarbageCollecte d::toImpl(v8::Local<v8::Object>::Cast(v8Value));
1217 impl.setTestInterfaceGarbageCollected(cppValue);
1218 return;
1219 }
1220
1221 {
1222 V8StringResource<> cppValue = v8Value;
1223 if (!cppValue.prepare(exceptionState))
1224 return;
1225 impl.setString(cppValue);
1226 return;
1227 }
1228
1229 }
1230
1231 v8::Local<v8::Value> toV8(const TestInterfaceGarbageCollectedOrString& impl, v8: :Local<v8::Object> creationContext, v8::Isolate* isolate)
1232 {
1233 switch (impl.m_type) {
1234 case TestInterfaceGarbageCollectedOrString::SpecificTypeNone:
1235 return v8::Null(isolate);
1236 case TestInterfaceGarbageCollectedOrString::SpecificTypeTestInterfaceGarbage Collected:
1237 return toV8(impl.getAsTestInterfaceGarbageCollected(), creationContext, isolate);
1238 case TestInterfaceGarbageCollectedOrString::SpecificTypeString:
1239 return v8String(isolate, impl.getAsString());
1240 default:
1241 ASSERT_NOT_REACHED();
1242 }
1243 return v8::Local<v8::Value>();
1244 }
1245
1246 TestInterfaceGarbageCollectedOrString NativeValueTraits<TestInterfaceGarbageColl ectedOrString>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, Ex ceptionState& exceptionState)
1247 {
1248 TestInterfaceGarbageCollectedOrString impl;
1249 V8TestInterfaceGarbageCollectedOrString::toImpl(isolate, value, impl, UnionT ypeConversionMode::NotNullable, exceptionState);
1250 return impl;
1251 }
1252
1253 TestInterfaceOrLong::TestInterfaceOrLong()
1254 : m_type(SpecificTypeNone)
1255 {
1256 }
1257
1258 TestInterfaceImplementation* TestInterfaceOrLong::getAsTestInterface() const
1259 {
1260 ASSERT(isTestInterface());
1261 return m_testInterface;
1262 }
1263
1264 void TestInterfaceOrLong::setTestInterface(TestInterfaceImplementation* value)
1265 {
1266 ASSERT(isNull());
1267 m_testInterface = value;
1268 m_type = SpecificTypeTestInterface;
1269 }
1270
1271 TestInterfaceOrLong TestInterfaceOrLong::fromTestInterface(TestInterfaceImplemen tation* value)
1272 {
1273 TestInterfaceOrLong container;
1274 container.setTestInterface(value);
1275 return container;
1276 }
1277
1278 int TestInterfaceOrLong::getAsLong() const
1279 {
1280 ASSERT(isLong());
1281 return m_long;
1282 }
1283
1284 void TestInterfaceOrLong::setLong(int value)
1285 {
1286 ASSERT(isNull());
1287 m_long = value;
1288 m_type = SpecificTypeLong;
1289 }
1290
1291 TestInterfaceOrLong TestInterfaceOrLong::fromLong(int value)
1292 {
1293 TestInterfaceOrLong container;
1294 container.setLong(value);
1295 return container;
1296 }
1297
1298 TestInterfaceOrLong::TestInterfaceOrLong(const TestInterfaceOrLong&) = default;
1299 TestInterfaceOrLong::~TestInterfaceOrLong() = default;
1300 TestInterfaceOrLong& TestInterfaceOrLong::operator=(const TestInterfaceOrLong&) = default;
1301
1302 DEFINE_TRACE(TestInterfaceOrLong)
1303 {
1304 visitor->trace(m_testInterface);
1305 }
1306
1307 void V8TestInterfaceOrLong::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8 Value, TestInterfaceOrLong& impl, UnionTypeConversionMode conversionMode, Except ionState& exceptionState)
1308 {
1309 if (v8Value.IsEmpty())
1310 return;
1311
1312 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1313 return;
1314
1315 if (V8TestInterface::hasInstance(v8Value, isolate)) {
1316 TestInterfaceImplementation* cppValue = V8TestInterface::toImpl(v8::Loca l<v8::Object>::Cast(v8Value));
1317 impl.setTestInterface(cppValue);
1318 return;
1319 }
1320
1321 if (v8Value->IsNumber()) {
1322 int cppValue = toInt32(isolate, v8Value, NormalConversion, exceptionStat e);
1323 if (exceptionState.hadException())
1324 return;
1325 impl.setLong(cppValue);
1326 return;
1327 }
1328
1329 {
1330 int cppValue = toInt32(isolate, v8Value, NormalConversion, exceptionStat e);
1331 if (exceptionState.hadException())
1332 return;
1333 impl.setLong(cppValue);
1334 return;
1335 }
1336
1337 }
1338
1339 v8::Local<v8::Value> toV8(const TestInterfaceOrLong& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
1340 {
1341 switch (impl.m_type) {
1342 case TestInterfaceOrLong::SpecificTypeNone:
1343 return v8::Null(isolate);
1344 case TestInterfaceOrLong::SpecificTypeTestInterface:
1345 return toV8(impl.getAsTestInterface(), creationContext, isolate);
1346 case TestInterfaceOrLong::SpecificTypeLong:
1347 return v8::Integer::New(isolate, impl.getAsLong());
1348 default:
1349 ASSERT_NOT_REACHED();
1350 }
1351 return v8::Local<v8::Value>();
1352 }
1353
1354 TestInterfaceOrLong NativeValueTraits<TestInterfaceOrLong>::nativeValue(v8::Isol ate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState)
1355 {
1356 TestInterfaceOrLong impl;
1357 V8TestInterfaceOrLong::toImpl(isolate, value, impl, UnionTypeConversionMode: :NotNullable, exceptionState);
1358 return impl;
1359 }
1360
1361 TestInterfaceOrTestInterfaceEmpty::TestInterfaceOrTestInterfaceEmpty()
1362 : m_type(SpecificTypeNone)
1363 {
1364 }
1365
1366 TestInterfaceImplementation* TestInterfaceOrTestInterfaceEmpty::getAsTestInterfa ce() const
1367 {
1368 ASSERT(isTestInterface());
1369 return m_testInterface;
1370 }
1371
1372 void TestInterfaceOrTestInterfaceEmpty::setTestInterface(TestInterfaceImplementa tion* value)
1373 {
1374 ASSERT(isNull());
1375 m_testInterface = value;
1376 m_type = SpecificTypeTestInterface;
1377 }
1378
1379 TestInterfaceOrTestInterfaceEmpty TestInterfaceOrTestInterfaceEmpty::fromTestInt erface(TestInterfaceImplementation* value)
1380 {
1381 TestInterfaceOrTestInterfaceEmpty container;
1382 container.setTestInterface(value);
1383 return container;
1384 }
1385
1386 TestInterfaceEmpty* TestInterfaceOrTestInterfaceEmpty::getAsTestInterfaceEmpty() const
1387 {
1388 ASSERT(isTestInterfaceEmpty());
1389 return m_testInterfaceEmpty;
1390 }
1391
1392 void TestInterfaceOrTestInterfaceEmpty::setTestInterfaceEmpty(TestInterfaceEmpty * value)
1393 {
1394 ASSERT(isNull());
1395 m_testInterfaceEmpty = value;
1396 m_type = SpecificTypeTestInterfaceEmpty;
1397 }
1398
1399 TestInterfaceOrTestInterfaceEmpty TestInterfaceOrTestInterfaceEmpty::fromTestInt erfaceEmpty(TestInterfaceEmpty* value)
1400 {
1401 TestInterfaceOrTestInterfaceEmpty container;
1402 container.setTestInterfaceEmpty(value);
1403 return container;
1404 }
1405
1406 TestInterfaceOrTestInterfaceEmpty::TestInterfaceOrTestInterfaceEmpty(const TestI nterfaceOrTestInterfaceEmpty&) = default;
1407 TestInterfaceOrTestInterfaceEmpty::~TestInterfaceOrTestInterfaceEmpty() = defaul t;
1408 TestInterfaceOrTestInterfaceEmpty& TestInterfaceOrTestInterfaceEmpty::operator=( const TestInterfaceOrTestInterfaceEmpty&) = default;
1409
1410 DEFINE_TRACE(TestInterfaceOrTestInterfaceEmpty)
1411 {
1412 visitor->trace(m_testInterface);
1413 visitor->trace(m_testInterfaceEmpty);
1414 }
1415
1416 void V8TestInterfaceOrTestInterfaceEmpty::toImpl(v8::Isolate* isolate, v8::Local <v8::Value> v8Value, TestInterfaceOrTestInterfaceEmpty& impl, UnionTypeConversio nMode conversionMode, ExceptionState& exceptionState)
1417 {
1418 if (v8Value.IsEmpty())
1419 return;
1420
1421 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1422 return;
1423
1424 if (V8TestInterface::hasInstance(v8Value, isolate)) {
1425 TestInterfaceImplementation* cppValue = V8TestInterface::toImpl(v8::Loca l<v8::Object>::Cast(v8Value));
1426 impl.setTestInterface(cppValue);
1427 return;
1428 }
1429
1430 if (V8TestInterfaceEmpty::hasInstance(v8Value, isolate)) {
1431 TestInterfaceEmpty* cppValue = V8TestInterfaceEmpty::toImpl(v8::Local<v8 ::Object>::Cast(v8Value));
1432 impl.setTestInterfaceEmpty(cppValue);
1433 return;
1434 }
1435
1436 exceptionState.throwTypeError("The provided value is not of type '(TestInter face or TestInterfaceEmpty)'");
1437 }
1438
1439 v8::Local<v8::Value> toV8(const TestInterfaceOrTestInterfaceEmpty& impl, v8::Loc al<v8::Object> creationContext, v8::Isolate* isolate)
1440 {
1441 switch (impl.m_type) {
1442 case TestInterfaceOrTestInterfaceEmpty::SpecificTypeNone:
1443 return v8::Null(isolate);
1444 case TestInterfaceOrTestInterfaceEmpty::SpecificTypeTestInterface:
1445 return toV8(impl.getAsTestInterface(), creationContext, isolate);
1446 case TestInterfaceOrTestInterfaceEmpty::SpecificTypeTestInterfaceEmpty:
1447 return toV8(impl.getAsTestInterfaceEmpty(), creationContext, isolate);
1448 default:
1449 ASSERT_NOT_REACHED();
1450 }
1451 return v8::Local<v8::Value>();
1452 }
1453
1454 TestInterfaceOrTestInterfaceEmpty NativeValueTraits<TestInterfaceOrTestInterface Empty>::nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionS tate& exceptionState)
1455 {
1456 TestInterfaceOrTestInterfaceEmpty impl;
1457 V8TestInterfaceOrTestInterfaceEmpty::toImpl(isolate, value, impl, UnionTypeC onversionMode::NotNullable, exceptionState);
1458 return impl;
1459 }
1460
1461 UnrestrictedDoubleOrString::UnrestrictedDoubleOrString()
1462 : m_type(SpecificTypeNone)
1463 {
1464 }
1465
1466 double UnrestrictedDoubleOrString::getAsUnrestrictedDouble() const
1467 {
1468 ASSERT(isUnrestrictedDouble());
1469 return m_unrestrictedDouble;
1470 }
1471
1472 void UnrestrictedDoubleOrString::setUnrestrictedDouble(double value)
1473 {
1474 ASSERT(isNull());
1475 m_unrestrictedDouble = value;
1476 m_type = SpecificTypeUnrestrictedDouble;
1477 }
1478
1479 UnrestrictedDoubleOrString UnrestrictedDoubleOrString::fromUnrestrictedDouble(do uble value)
1480 {
1481 UnrestrictedDoubleOrString container;
1482 container.setUnrestrictedDouble(value);
1483 return container;
1484 }
1485
1486 String UnrestrictedDoubleOrString::getAsString() const
1487 {
1488 ASSERT(isString());
1489 return m_string;
1490 }
1491
1492 void UnrestrictedDoubleOrString::setString(String value)
1493 {
1494 ASSERT(isNull());
1495 m_string = value;
1496 m_type = SpecificTypeString;
1497 }
1498
1499 UnrestrictedDoubleOrString UnrestrictedDoubleOrString::fromString(String value)
1500 {
1501 UnrestrictedDoubleOrString container;
1502 container.setString(value);
1503 return container;
1504 }
1505
1506 UnrestrictedDoubleOrString::UnrestrictedDoubleOrString(const UnrestrictedDoubleO rString&) = default;
1507 UnrestrictedDoubleOrString::~UnrestrictedDoubleOrString() = default;
1508 UnrestrictedDoubleOrString& UnrestrictedDoubleOrString::operator=(const Unrestri ctedDoubleOrString&) = default;
1509
1510 DEFINE_TRACE(UnrestrictedDoubleOrString)
1511 {
1512 }
1513
1514 void V8UnrestrictedDoubleOrString::toImpl(v8::Isolate* isolate, v8::Local<v8::Va lue> v8Value, UnrestrictedDoubleOrString& impl, UnionTypeConversionMode conversi onMode, ExceptionState& exceptionState)
1515 {
1516 if (v8Value.IsEmpty())
1517 return;
1518
1519 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
1520 return;
1521
1522 if (v8Value->IsNumber()) {
1523 double cppValue = toDouble(isolate, v8Value, exceptionState);
1524 if (exceptionState.hadException())
1525 return;
1526 impl.setUnrestrictedDouble(cppValue);
1527 return;
1528 }
1529
1530 {
1531 V8StringResource<> cppValue = v8Value;
1532 if (!cppValue.prepare(exceptionState))
1533 return;
1534 impl.setString(cppValue);
1535 return;
1536 }
1537
1538 }
1539
1540 v8::Local<v8::Value> toV8(const UnrestrictedDoubleOrString& impl, v8::Local<v8:: Object> creationContext, v8::Isolate* isolate)
1541 {
1542 switch (impl.m_type) {
1543 case UnrestrictedDoubleOrString::SpecificTypeNone:
1544 return v8::Null(isolate);
1545 case UnrestrictedDoubleOrString::SpecificTypeUnrestrictedDouble:
1546 return v8::Number::New(isolate, impl.getAsUnrestrictedDouble());
1547 case UnrestrictedDoubleOrString::SpecificTypeString:
1548 return v8String(isolate, impl.getAsString());
1549 default:
1550 ASSERT_NOT_REACHED();
1551 }
1552 return v8::Local<v8::Value>();
1553 }
1554
1555 UnrestrictedDoubleOrString NativeValueTraits<UnrestrictedDoubleOrString>::native Value(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptio nState)
1556 {
1557 UnrestrictedDoubleOrString impl;
1558 V8UnrestrictedDoubleOrString::toImpl(isolate, value, impl, UnionTypeConversi onMode::NotNullable, exceptionState);
1559 return impl;
1560 }
1561
1562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698