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.
5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
8 #include "{{header_filename}}"
10 {% macro assign_and_return_if_hasinstance(member) %}
11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) {
12 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
13 impl.set{{member.type_name}}(cppValue);
17 {% for filename in cpp_includes %}
18 #include "{{filename}}"
23 {% for container in containers %}
24 {{container.cpp_class}}::{{container.cpp_class}}()
25 : m_type(SpecificTypeNone)
29 {% for member in container.members %}
30 {{member.rvalue_cpp_type}} {{container.cpp_class}}::getAs{{member.type_name}}() const
32 ASSERT(is{{member.type_name}}());
33 return m_{{member.cpp_name}};
36 void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value)
39 m_{{member.cpp_name}} = value;
40 m_type = {{member.specific_type_enum}};
44 {% if container.needs_trace %}
45 void {{container.cpp_class}}::trace(Visitor* visitor)
47 {% for member in container.members if member.is_traceable %}
48 visitor->trace(m_{{member.cpp_name}});
53 void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState)
55 {# FIXME: We don't follow the spec on handling null and undefined at this
56 moment. Should be fixed once we implement all necessary conversion steps
58 if (v8Value.IsEmpty())
61 {# The numbers in the following comments refer to the steps described in
62 http://heycam.github.io/webidl/#es-union
63 FIXME: Implement all necessary steps #}
64 {# 3. Platform objects (interfaces) #}
65 {% for interface in container.interface_types %}
66 {{assign_and_return_if_hasinstance(interface) | indent}}
70 {% if container.array_buffer_type %}
71 {{assign_and_return_if_hasinstance(container.array_buffer_type) | indent}}
74 {# 9., 10. ArrayBufferView #}
75 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #}
76 {% if container.array_buffer_view_type %}
77 {{assign_and_return_if_hasinstance(container.array_buffer_view_type) | indent}}
80 {% if container.dictionary_type %}
81 {# 12. Dictionaries #}
82 {# FIXME: This should also check "object but not Date or RegExp". Add checks
83 when we implement conversions for Date and RegExp. #}
84 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
85 {{container.dictionary_type.cpp_local_type}} cppValue = V8{{container.dictionary_type.type_name}}::toImpl(isolate, v8Value, exceptionState);
86 if (!exceptionState.hadException())
87 impl.set{{container.dictionary_type.type_name}}(cppValue);
92 {# FIXME: In some cases, we can omit boolean and numeric type checks because
93 we have fallback conversions. (step 17 and 18) #}
94 {% if container.boolean_type %}
96 if (v8Value->IsBoolean()) {
97 impl.setBoolean(v8Value->ToBoolean()->Value());
102 {% if container.numeric_type %}
104 if (v8Value->IsNumber()) {
105 {{container.numeric_type.v8_value_to_local_cpp_value}};
106 impl.set{{container.numeric_type.type_name}}(cppValue);
111 {% if container.string_type %}
114 {{container.string_type.v8_value_to_local_cpp_value}};
115 impl.set{{container.string_type.type_name}}(cppValue);
119 {# 17. Number (fallback) #}
120 {% elif container.numeric_type %}
122 {{container.numeric_type.v8_value_to_local_cpp_value}};
123 impl.set{{container.numeric_type.type_name}}(cppValue);
127 {# 18. Boolean (fallback) #}
128 {% elif container.boolean_type %}
130 impl.setBoolean(v8Value->ToBoolean()->Value());
136 exceptionState.throwTypeError("Not a valid union member.");
139 v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
141 switch (impl.m_type) {
142 case {{container.cpp_class}}::SpecificTypeNone:
143 {# FIXME: We might want to return undefined in some cases #}
144 return v8::Null(isolate);
145 {% for member in container.members %}
146 case {{container.cpp_class}}::{{member.specific_type_enum}}:
147 return {{member.cpp_value_to_v8_value}};
150 ASSERT_NOT_REACHED();
152 return v8::Handle<v8::Value>();