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 to 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". Add 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 {# FIXME: In some cases, we can omit boolean and numeric type checks because |
| 70 we have fallback conversions. (step 17 and 18) #} |
| 71 {% if container.boolean_type %} |
| 72 {# 14. Boolean #} |
| 73 if (v8Value->IsBoolean()) { |
| 74 impl.setBoolean(v8Value->ToBoolean()->Value()); |
| 75 return; |
| 76 } |
| 77 |
| 78 {% endif %} |
| 79 {% if container.numeric_type %} |
| 80 {# 15. Number #} |
| 81 if (v8Value->IsNumber()) { |
| 82 {{container.numeric_type.v8_value_to_local_cpp_value}}; |
| 83 impl.set{{container.numeric_type.type_name}}(cppValue); |
| 84 return; |
| 85 } |
| 86 |
| 87 {% endif %} |
| 88 {% if container.string_type %} |
| 89 {# 16. String #} |
| 90 { |
| 91 {{container.string_type.v8_value_to_local_cpp_value}}; |
| 92 impl.set{{container.string_type.type_name}}(cppValue); |
| 93 return; |
| 94 } |
| 95 |
| 96 {# 17. Number (fallback) #} |
| 97 {% elif container.numeric_type %} |
| 98 { |
| 99 {{container.numeric_type.v8_value_to_local_cpp_value}}; |
| 100 impl.set{{container.numeric_type.type_name}}(cppValue); |
| 101 return; |
| 102 } |
| 103 |
| 104 {# 18. Boolean (fallback) #} |
| 105 {% elif container.boolean_type %} |
| 106 { |
| 107 impl.setBoolean(v8Value->ToBoolean()->Value()); |
| 108 return; |
| 109 } |
| 110 |
| 111 {% endif %} |
| 112 {# 19. TypeError #} |
| 113 exceptionState.throwTypeError("Not a valid union member."); |
| 114 } |
| 115 |
| 116 v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) |
| 117 { |
| 118 {# FIXME: We might want to return undefined in some cases #} |
| 119 if (impl.isNull()) |
| 120 return v8::Null(isolate); |
| 121 |
| 122 {% for member in container.members %} |
| 123 if (impl.is{{member.type_name}}()) |
| 124 return {{member.cpp_value_to_v8_value}}; |
| 125 |
| 126 {% endfor %} |
| 127 ASSERT_NOT_REACHED(); |
| 128 return v8::Handle<v8::Value>(); |
| 129 } |
| 130 |
| 131 {% endfor %} |
| 132 } // namespace blink |
OLD | NEW |