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

Side by Side Diff: Source/bindings/templates/union.cpp

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // FIXME: Implement 5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
6
7 #include "config.h"
8 #include "{{header_filename}}"
9
10 {% for filename in cpp_includes %}
11 #include "{{filename}}"
12 {% endfor %}
13
14 namespace blink {
15
16 {% for container in containers %}
17 {{container.cpp_class}}::{{container.cpp_class}}()
18 : m_specificType(SpecificTypeNone)
19 {
20 }
21
22 {% for member in container.members %}
23 {{member.rvalue_cpp_type}} {{container.cpp_class}}::getAs{{member.type_name}}()
24 {
25 ASSERT(is{{member.type_name}}());
26 return m_{{member.cpp_name}};
27 }
28
29 void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value)
30 {
31 ASSERT(isNull());
32 m_{{member.cpp_name}} = value;
33 m_specificType = {{member.specific_type_enum}};
34 }
35
36 {% endfor %}
37 void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Valu e> v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState)
38 {
39 {# FIXME: We doesn't follow the spec on handling null and undefined at this
Jens Widell 2014/10/29 07:18:51 "We don't" :-)
bashi 2014/10/29 09:57:36 Done. Thank you for always correcting my poor Engl
40 moment. Should be fixed once we implement all necessary conversion steps
41 below. #}
42 if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
43 return;
44
45 {# The numbers in the following comments refer the steps described in
46 http://heycam.github.io/webidl/#es-union
47 FIXME: Implement all necessary steps #}
48 {# 3. Platform objects (interfaces) #}
49 {% for interface in container.interface_types %}
50 if (V8{{interface.type_name}}::hasInstance(v8Value, isolate)) {
51 {{interface.cpp_type}} cppValue = V8{{interface.type_name}}::toImpl(v8:: Handle<v8::Object>::Cast(v8Value));
52 impl.set{{interface.type_name}}(cppValue);
53 return;
54 }
55
56 {% endfor %}
57 {% if container.dictionary_type %}
58 {# 12. Dictionaries #}
59 {# FIXME: This should be "object but not Date or RegExp". Adds checks when
60 we implement conversions for Date and RegExp. #}
61 if (v8Value->IsObject()) {
62 {{container.dictionary_type.cpp_type}} cppValue = V8{{container.dictiona ry_type.type_name}}::toImpl(isolate, v8Value, exceptionState);
63 if (!exceptionState.hadException())
64 impl.set{{container.dictionary_type.type_name}}(cppValue);
65 return;
66 }
67
68 {% endif %}
69 {% if container.boolean_type %}
70 {# 14. Boolean #}
71 if (v8Value->IsBoolean()) {
72 impl.setBoolean(v8Value->ToBoolean()->Value());
73 return;
74 }
75
76 {% endif %}
77 {% if container.numeric_type %}
78 {# 15. Number #}
79 if (v8Value->IsNumber()) {
80 {{container.numeric_type.v8_value_to_local_cpp_value}};
81 impl.set{{container.numeric_type.type_name}}(cppValue);
82 return;
83 }
84
85 {% endif %}
86 {% if container.string_type %}
87 {# 16. String #}
88 {
89 {{container.string_type.v8_value_to_local_cpp_value}};
90 impl.set{{container.string_type.type_name}}(cppValue);
91 return;
92 }
93
94 {% endif %}
95 {# 17. Number (fallback) #}
96 {% if container.numeric_type %}
Jens Widell 2014/10/29 07:18:51 Use "elif" instead here (and for boolean)? We only
bashi 2014/10/29 09:57:36 Done. I'd like to keep fallback logic at this time
97 {
98 {{container.numeric_type.v8_value_to_local_cpp_value}};
99 return;
100 }
101
102 {% endif %}
103 {# 18. Boolean (fallback) #}
104 {% if container.boolean_type %}
105 {
106 impl.setBoolean(v8Value->ToBoolean()->Value());
107 return;
108 }
109
110 {% endif %}
111 {# 19. TypeError #}
112 exceptionState.throwTypeError("Not a valid union member.");
113 }
114
115 v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
116 {
117 if (impl.isNull())
118 return v8::Null(isolate);
119
120 {% for member in container.members %}
121 if (impl.is{{member.type_name}}())
122 return {{member.cpp_value_to_v8_value}};
123
124 {% endfor %}
125 ASSERT_NOT_REACHED();
126 return v8::Null(isolate);
127 }
128
129 {% endfor %}
130 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698