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_specificTypeFlag(0) | |
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_specificTypeFlag = {{member.index}}; | |
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 if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value)) | |
Jens Widell
2014/10/28 11:31:38
Null or undefined isn't treated this way in the sp
bashi
2014/10/29 01:34:33
Yes, this is tentative, and I should have added a
| |
40 return; | |
41 | |
42 {# The numbers in the following comments refer the steps described in | |
43 http://heycam.github.io/webidl/#es-union | |
44 FIXME: Implement all necessary steps #} | |
45 {# 3. Platform objects (interfaces) #} | |
46 {% for platform_object in container.platform_objects %} | |
47 if (V8{{platform_object.type_name}}::hasInstance(v8Value, isolate)) { | |
48 {{platform_object.cpp_type}} cppValue = V8{{platform_object.type_name}}: :toImplWithTypeCheck(isolate, v8Value); | |
Jens Widell
2014/10/28 11:31:38
No need to use *WithTypeCheck() here; you just typ
bashi
2014/10/29 01:34:32
Done.
| |
49 impl.set{{platform_object.type_name}}(cppValue); | |
50 return; | |
51 } | |
52 | |
53 {% endfor %} | |
54 {% if container.dictionary_type %} | |
55 {# 12. Dictionaries #} | |
56 if (v8Value->IsObject()) { | |
Jens Widell
2014/10/28 11:31:38
Spec says "object but not Date or RegExp". If we d
bashi
2014/10/29 01:34:33
Added a FIXME comment.
| |
57 {{container.dictionary_type.cpp_type}} cppValue = V8{{container.dictiona ry_type.type_name}}::toImpl(isolate, v8Value, exceptionState); | |
58 if (!exceptionState.hadException()) | |
59 impl.set{{container.dictionary_type.type_name}}(cppValue); | |
60 return; | |
61 } | |
62 | |
63 {% endif %} | |
64 {% if container.boolean_type %} | |
65 {# 14. Boolean #} | |
66 if (v8Value->IsBoolean()) { | |
67 impl.setBoolean(v8Value->ToBoolean()->Value()); | |
68 return; | |
69 } | |
70 | |
71 {% endif %} | |
72 {% if container.numeric_type %} | |
73 {# 15. Number #} | |
74 if (v8Value->IsNumber()) { | |
Jens Widell
2014/10/28 11:31:38
You never convert to number (or boolean). If there
bashi
2014/10/29 01:34:32
Good catch! Done.
| |
75 {{container.numeric_type.v8_value_to_local_cpp_value}}; | |
76 impl.set{{container.numeric_type.type_name}}(cppValue); | |
77 return; | |
78 } | |
79 | |
80 {% endif %} | |
81 {% if container.string_type %} | |
82 {# 16. String #} | |
83 { | |
84 {{container.string_type.v8_value_to_local_cpp_value}}; | |
85 impl.set{{container.string_type.type_name}}(cppValue); | |
86 return; | |
87 } | |
88 | |
89 {% endif %} | |
90 {# 19. TypeError #} | |
91 exceptionState.throwTypeError("Not a valid union member."); | |
92 } | |
93 | |
94 v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
95 { | |
96 if (impl.isNull()) | |
97 return v8::Undefined(isolate); | |
98 | |
99 {% for member in container.members %} | |
100 if (impl.is{{member.type_name}}()) | |
101 return {{member.cpp_value_to_v8_value}}; | |
102 | |
103 {% endfor %} | |
104 ASSERT_NOT_REACHED(); | |
105 return v8::Undefined(isolate); | |
106 } | |
107 | |
108 {% endfor %} | |
109 } // namespace blink | |
OLD | NEW |