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

Side by Side Diff: third_party/WebKit/Source/bindings/tests/results/core/StringOrDouble.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 "StringOrDouble.h"
8
9 #include "bindings/core/v8/ToV8.h"
10
11 namespace blink {
12
13 StringOrDouble::StringOrDouble()
14 : m_type(SpecificTypeNone)
15 {
16 }
17
18 String StringOrDouble::getAsString() const
19 {
20 ASSERT(isString());
21 return m_string;
22 }
23
24 void StringOrDouble::setString(String value)
25 {
26 ASSERT(isNull());
27 m_string = value;
28 m_type = SpecificTypeString;
29 }
30
31 StringOrDouble StringOrDouble::fromString(String value)
32 {
33 StringOrDouble container;
34 container.setString(value);
35 return container;
36 }
37
38 double StringOrDouble::getAsDouble() const
39 {
40 ASSERT(isDouble());
41 return m_double;
42 }
43
44 void StringOrDouble::setDouble(double value)
45 {
46 ASSERT(isNull());
47 m_double = value;
48 m_type = SpecificTypeDouble;
49 }
50
51 StringOrDouble StringOrDouble::fromDouble(double value)
52 {
53 StringOrDouble container;
54 container.setDouble(value);
55 return container;
56 }
57
58 StringOrDouble::StringOrDouble(const StringOrDouble&) = default;
59 StringOrDouble::~StringOrDouble() = default;
60 StringOrDouble& StringOrDouble::operator=(const StringOrDouble&) = default;
61
62 DEFINE_TRACE(StringOrDouble)
63 {
64 }
65
66 void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value , StringOrDouble& impl, UnionTypeConversionMode conversionMode, ExceptionState& exceptionState)
67 {
68 if (v8Value.IsEmpty())
69 return;
70
71 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull (v8Value))
72 return;
73
74 if (v8Value->IsNumber()) {
75 double cppValue = toRestrictedDouble(isolate, v8Value, exceptionState);
76 if (exceptionState.hadException())
77 return;
78 impl.setDouble(cppValue);
79 return;
80 }
81
82 {
83 V8StringResource<> cppValue = v8Value;
84 if (!cppValue.prepare(exceptionState))
85 return;
86 impl.setString(cppValue);
87 return;
88 }
89
90 }
91
92 v8::Local<v8::Value> toV8(const StringOrDouble& impl, v8::Local<v8::Object> crea tionContext, v8::Isolate* isolate)
93 {
94 switch (impl.m_type) {
95 case StringOrDouble::SpecificTypeNone:
96 return v8::Null(isolate);
97 case StringOrDouble::SpecificTypeString:
98 return v8String(isolate, impl.getAsString());
99 case StringOrDouble::SpecificTypeDouble:
100 return v8::Number::New(isolate, impl.getAsDouble());
101 default:
102 ASSERT_NOT_REACHED();
103 }
104 return v8::Local<v8::Value>();
105 }
106
107 StringOrDouble NativeValueTraits<StringOrDouble>::nativeValue(v8::Isolate* isola te, v8::Local<v8::Value> value, ExceptionState& exceptionState)
108 {
109 StringOrDouble impl;
110 V8StringOrDouble::toImpl(isolate, value, impl, UnionTypeConversionMode::NotN ullable, exceptionState);
111 return impl;
112 }
113
114 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698