Index: Source/bindings/templates/union.cpp |
diff --git a/Source/bindings/templates/union.cpp b/Source/bindings/templates/union.cpp |
index d3523387f89a93d6f1a4de2575ba5b8a8293128b..a6ba469192dbf14e9b714cfbbe31ca28db1db917 100644 |
--- a/Source/bindings/templates/union.cpp |
+++ b/Source/bindings/templates/union.cpp |
@@ -2,4 +2,108 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// FIXME: Implement |
+// This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! |
+ |
+#include "config.h" |
+#include "{{header_filename}}" |
+ |
+{% for filename in cpp_includes %} |
+#include "{{filename}}" |
+{% endfor %} |
+ |
+namespace blink { |
+ |
+{% for container in containers %} |
+{{container.cpp_class}}::{{container.cpp_class}}() |
+ : m_specificTypeFlag(0) |
+{ |
+} |
+ |
+{% for member in container.members %} |
+{{member.rvalue_cpp_type}} {{container.cpp_class}}::getAs{{member.type_name}}() |
+{ |
+ ASSERT(is{{member.type_name}}()); |
+ return m_{{member.cpp_name}}; |
+} |
+ |
+void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value) |
+{ |
+ ASSERT(isNull()); |
+ m_{{member.cpp_name}} = value; |
+ m_specificTypeFlag = {{member.index}}; |
+} |
+ |
+{% endfor %} |
+void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState) |
+{ |
+ 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
|
+ return; |
+ |
+ {# The numbers in the following comments refer the steps described in |
+ http://heycam.github.io/webidl/#es-union |
+ FIXME: Implement all necessary steps #} |
+ {# 3. Platform objects (interfaces) #} |
+ {% for platform_object in container.platform_objects %} |
+ if (V8{{platform_object.type_name}}::hasInstance(v8Value, isolate)) { |
+ {{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.
|
+ impl.set{{platform_object.type_name}}(cppValue); |
+ return; |
+ } |
+ |
+ {% endfor %} |
+ {% if container.dictionary_type %} |
+ {# 12. Dictionaries #} |
+ 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.
|
+ {{container.dictionary_type.cpp_type}} cppValue = V8{{container.dictionary_type.type_name}}::toImpl(isolate, v8Value, exceptionState); |
+ if (!exceptionState.hadException()) |
+ impl.set{{container.dictionary_type.type_name}}(cppValue); |
+ return; |
+ } |
+ |
+ {% endif %} |
+ {% if container.boolean_type %} |
+ {# 14. Boolean #} |
+ if (v8Value->IsBoolean()) { |
+ impl.setBoolean(v8Value->ToBoolean()->Value()); |
+ return; |
+ } |
+ |
+ {% endif %} |
+ {% if container.numeric_type %} |
+ {# 15. Number #} |
+ 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.
|
+ {{container.numeric_type.v8_value_to_local_cpp_value}}; |
+ impl.set{{container.numeric_type.type_name}}(cppValue); |
+ return; |
+ } |
+ |
+ {% endif %} |
+ {% if container.string_type %} |
+ {# 16. String #} |
+ { |
+ {{container.string_type.v8_value_to_local_cpp_value}}; |
+ impl.set{{container.string_type.type_name}}(cppValue); |
+ return; |
+ } |
+ |
+ {% endif %} |
+ {# 19. TypeError #} |
+ exceptionState.throwTypeError("Not a valid union member."); |
+} |
+ |
+v8::Handle<v8::Value> toV8({{container.cpp_class}}& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
+{ |
+ if (impl.isNull()) |
+ return v8::Undefined(isolate); |
+ |
+ {% for member in container.members %} |
+ if (impl.is{{member.type_name}}()) |
+ return {{member.cpp_value_to_v8_value}}; |
+ |
+ {% endfor %} |
+ ASSERT_NOT_REACHED(); |
+ return v8::Undefined(isolate); |
+} |
+ |
+{% endfor %} |
+} // namespace blink |