OLD | NEW |
---|---|
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_type(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_type = {{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 don't follow the spec on handling null and undefined at this | |
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_local_type}} cppValue = V8{{interface.type_name}}::toImp l(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_local_type}} cppValue = V8{{container.di ctionary_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 {# 17. Number (fallback) #} | |
95 {% elif container.numeric_type %} | |
96 { | |
97 {{container.numeric_type.v8_value_to_local_cpp_value}}; | |
98 return; | |
99 } | |
100 | |
101 {# 18. Boolean (fallback) #} | |
102 {% elif container.boolean_type %} | |
103 { | |
104 impl.setBoolean(v8Value->ToBoolean()->Value()); | |
105 return; | |
106 } | |
107 | |
108 {% endif %} | |
109 {# 19. TypeError #} | |
110 exceptionState.throwTypeError("Not a valid union member."); | |
111 } | |
112 | |
113 v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
114 { | |
115 if (impl.isNull()) | |
116 return v8::Null(isolate); | |
Jens Widell
2014/10/29 11:40:45
It's possible we should sometimes convert to undef
bashi
2014/10/30 01:34:37
I missed the statement, thank you for pointing thi
| |
117 | |
118 {% for member in container.members %} | |
119 if (impl.is{{member.type_name}}()) | |
120 return {{member.cpp_value_to_v8_value}}; | |
121 | |
122 {% endfor %} | |
123 ASSERT_NOT_REACHED(); | |
124 return v8::Handle<v8::Value>(); | |
125 } | |
126 | |
127 {% endfor %} | |
128 } // namespace blink | |
OLD | NEW |