Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: Source/bindings/tests/results/core/UnionTypesCore.cpp

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/tests/results/core/UnionTypesCore.cpp
diff --git a/Source/bindings/tests/results/core/UnionTypesCore.cpp b/Source/bindings/tests/results/core/UnionTypesCore.cpp
index d3523387f89a93d6f1a4de2575ba5b8a8293128b..37ca49de8fc8ccd2a4ee5d64f5b448aca97a6b1d 100644
--- a/Source/bindings/tests/results/core/UnionTypesCore.cpp
+++ b/Source/bindings/tests/results/core/UnionTypesCore.cpp
@@ -2,4 +2,517 @@
// 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_v8.py. DO NOT MODIFY!
+
+#include "config.h"
+#include "bindings/core/v8/UnionTypesCore.h"
+
+#include "bindings/core/v8/V8Node.h"
+#include "bindings/core/v8/V8NodeList.h"
+#include "bindings/core/v8/V8TestDictionary.h"
+#include "bindings/core/v8/V8TestInterface.h"
+#include "bindings/core/v8/V8TestInterfaceEmpty.h"
+#include "bindings/core/v8/V8TestInterfaceGarbageCollected.h"
+#include "bindings/core/v8/V8TestInterfaceWillBeGarbageCollected.h"
+#include "bindings/tests/idls/core/TestImplements2.h"
+#include "bindings/tests/idls/core/TestImplements3Implementation.h"
+#include "bindings/tests/idls/core/TestPartialInterface.h"
+#include "bindings/tests/idls/core/TestPartialInterfaceImplementation.h"
+#include "core/dom/NameNodeList.h"
+#include "core/dom/NodeList.h"
+#include "core/dom/StaticNodeList.h"
+#include "core/html/LabelsNodeList.h"
+
+namespace blink {
+
+BooleanOrStringOrUnrestrictedDouble::BooleanOrStringOrUnrestrictedDouble()
+ : m_type(SpecificTypeNone)
+{
+}
+
+bool BooleanOrStringOrUnrestrictedDouble::getAsBoolean()
+{
+ ASSERT(isBoolean());
+ return m_boolean;
+}
+
+void BooleanOrStringOrUnrestrictedDouble::setBoolean(bool value)
+{
+ ASSERT(isNull());
+ m_boolean = value;
+ m_type = SpecificTypeBoolean;
+}
+
+String BooleanOrStringOrUnrestrictedDouble::getAsString()
+{
+ ASSERT(isString());
+ return m_string;
+}
+
+void BooleanOrStringOrUnrestrictedDouble::setString(String value)
+{
+ ASSERT(isNull());
+ m_string = value;
+ m_type = SpecificTypeString;
+}
+
+double BooleanOrStringOrUnrestrictedDouble::getAsUnrestrictedDouble()
+{
+ ASSERT(isUnrestrictedDouble());
+ return m_unrestrictedDouble;
+}
+
+void BooleanOrStringOrUnrestrictedDouble::setUnrestrictedDouble(double value)
+{
+ ASSERT(isNull());
+ m_unrestrictedDouble = value;
+ m_type = SpecificTypeUnrestrictedDouble;
+}
+
+void V8BooleanOrStringOrUnrestrictedDouble::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, BooleanOrStringOrUnrestrictedDouble& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (v8Value->IsBoolean()) {
+ impl.setBoolean(v8Value->ToBoolean()->Value());
+ return;
+ }
+
+ if (v8Value->IsNumber()) {
+ TONATIVE_VOID_EXCEPTIONSTATE(double, cppValue, toDouble(v8Value, exceptionState), exceptionState);
+ impl.setUnrestrictedDouble(cppValue);
+ return;
+ }
+
+ {
+ TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exceptionState);
+ impl.setString(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(BooleanOrStringOrUnrestrictedDouble& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isBoolean())
+ return v8Boolean(impl.getAsBoolean(), isolate);
+
+ if (impl.isString())
+ return v8String(isolate, impl.getAsString());
+
+ if (impl.isUnrestrictedDouble())
+ return v8::Number::New(isolate, impl.getAsUnrestrictedDouble());
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+NodeOrNodeList::NodeOrNodeList()
+ : m_type(SpecificTypeNone)
+{
+}
+
+PassRefPtrWillBeRawPtr<Node> NodeOrNodeList::getAsNode()
+{
+ ASSERT(isNode());
+ return m_node;
+}
+
+void NodeOrNodeList::setNode(PassRefPtrWillBeRawPtr<Node> value)
+{
+ ASSERT(isNull());
+ m_node = value;
+ m_type = SpecificTypeNode;
+}
+
+PassRefPtrWillBeRawPtr<NodeList> NodeOrNodeList::getAsNodeList()
+{
+ ASSERT(isNodeList());
+ return m_nodeList;
+}
+
+void NodeOrNodeList::setNodeList(PassRefPtrWillBeRawPtr<NodeList> value)
+{
+ ASSERT(isNull());
+ m_nodeList = value;
+ m_type = SpecificTypeNodeList;
+}
+
+void V8NodeOrNodeList::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, NodeOrNodeList& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (V8Node::hasInstance(v8Value, isolate)) {
+ RefPtrWillBeRawPtr<Node> cppValue = V8Node::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setNode(cppValue);
+ return;
+ }
+
+ if (V8NodeList::hasInstance(v8Value, isolate)) {
+ RefPtrWillBeRawPtr<NodeList> cppValue = V8NodeList::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setNodeList(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(NodeOrNodeList& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isNode())
+ return toV8(impl.getAsNode(), creationContext, isolate);
+
+ if (impl.isNodeList())
+ return toV8(impl.getAsNodeList(), creationContext, isolate);
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+StringOrDouble::StringOrDouble()
+ : m_type(SpecificTypeNone)
+{
+}
+
+String StringOrDouble::getAsString()
+{
+ ASSERT(isString());
+ return m_string;
+}
+
+void StringOrDouble::setString(String value)
+{
+ ASSERT(isNull());
+ m_string = value;
+ m_type = SpecificTypeString;
+}
+
+double StringOrDouble::getAsDouble()
+{
+ ASSERT(isDouble());
+ return m_double;
+}
+
+void StringOrDouble::setDouble(double value)
+{
+ ASSERT(isNull());
+ m_double = value;
+ m_type = SpecificTypeDouble;
+}
+
+void V8StringOrDouble::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, StringOrDouble& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (v8Value->IsNumber()) {
+ TONATIVE_VOID_EXCEPTIONSTATE(double, cppValue, toDouble(v8Value, exceptionState), exceptionState);
+ impl.setDouble(cppValue);
+ return;
+ }
+
+ {
+ TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exceptionState);
+ impl.setString(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(StringOrDouble& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isString())
+ return v8String(isolate, impl.getAsString());
+
+ if (impl.isDouble())
+ return v8::Number::New(isolate, impl.getAsDouble());
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+TestInterfaceGarbageCollectedOrString::TestInterfaceGarbageCollectedOrString()
+ : m_type(SpecificTypeNone)
+{
+}
+
+RawPtr<TestInterfaceGarbageCollected> TestInterfaceGarbageCollectedOrString::getAsTestInterfaceGarbageCollected()
+{
+ ASSERT(isTestInterfaceGarbageCollected());
+ return m_testInterfaceGarbageCollected;
+}
+
+void TestInterfaceGarbageCollectedOrString::setTestInterfaceGarbageCollected(RawPtr<TestInterfaceGarbageCollected> value)
+{
+ ASSERT(isNull());
+ m_testInterfaceGarbageCollected = value;
+ m_type = SpecificTypeTestInterfaceGarbageCollected;
+}
+
+String TestInterfaceGarbageCollectedOrString::getAsString()
+{
+ ASSERT(isString());
+ return m_string;
+}
+
+void TestInterfaceGarbageCollectedOrString::setString(String value)
+{
+ ASSERT(isNull());
+ m_string = value;
+ m_type = SpecificTypeString;
+}
+
+void V8TestInterfaceGarbageCollectedOrString::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, TestInterfaceGarbageCollectedOrString& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (V8TestInterfaceGarbageCollected::hasInstance(v8Value, isolate)) {
+ RawPtr<TestInterfaceGarbageCollected> cppValue = V8TestInterfaceGarbageCollected::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setTestInterfaceGarbageCollected(cppValue);
+ return;
+ }
+
+ {
+ TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exceptionState);
+ impl.setString(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(TestInterfaceGarbageCollectedOrString& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isTestInterfaceGarbageCollected())
+ return toV8(impl.getAsTestInterfaceGarbageCollected(), creationContext, isolate);
+
+ if (impl.isString())
+ return v8String(isolate, impl.getAsString());
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+TestInterfaceOrLong::TestInterfaceOrLong()
+ : m_type(SpecificTypeNone)
+{
+}
+
+PassRefPtr<TestInterfaceImplementation> TestInterfaceOrLong::getAsTestInterface()
+{
+ ASSERT(isTestInterface());
+ return m_testInterface;
+}
+
+void TestInterfaceOrLong::setTestInterface(PassRefPtr<TestInterfaceImplementation> value)
+{
+ ASSERT(isNull());
+ m_testInterface = value;
+ m_type = SpecificTypeTestInterface;
+}
+
+int TestInterfaceOrLong::getAsLong()
+{
+ ASSERT(isLong());
+ return m_long;
+}
+
+void TestInterfaceOrLong::setLong(int value)
+{
+ ASSERT(isNull());
+ m_long = value;
+ m_type = SpecificTypeLong;
+}
+
+void V8TestInterfaceOrLong::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, TestInterfaceOrLong& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (V8TestInterface::hasInstance(v8Value, isolate)) {
+ RefPtr<TestInterfaceImplementation> cppValue = V8TestInterface::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setTestInterface(cppValue);
+ return;
+ }
+
+ if (v8Value->IsNumber()) {
bashi 2014/10/30 23:19:18 As Jens suggested, we should be able to remove thi
+ TONATIVE_VOID_EXCEPTIONSTATE(int, cppValue, toInt32(v8Value, exceptionState), exceptionState);
+ impl.setLong(cppValue);
+ return;
+ }
+
+ {
+ TONATIVE_VOID_EXCEPTIONSTATE(int, cppValue, toInt32(v8Value, exceptionState), exceptionState);
+ impl.setLong(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(TestInterfaceOrLong& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isTestInterface())
+ return toV8(impl.getAsTestInterface(), creationContext, isolate);
+
+ if (impl.isLong())
+ return v8::Integer::New(isolate, impl.getAsLong());
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+TestInterfaceOrTestInterfaceEmpty::TestInterfaceOrTestInterfaceEmpty()
+ : m_type(SpecificTypeNone)
+{
+}
+
+PassRefPtr<TestInterfaceImplementation> TestInterfaceOrTestInterfaceEmpty::getAsTestInterface()
+{
+ ASSERT(isTestInterface());
+ return m_testInterface;
+}
+
+void TestInterfaceOrTestInterfaceEmpty::setTestInterface(PassRefPtr<TestInterfaceImplementation> value)
+{
+ ASSERT(isNull());
+ m_testInterface = value;
+ m_type = SpecificTypeTestInterface;
+}
+
+PassRefPtr<TestInterfaceEmpty> TestInterfaceOrTestInterfaceEmpty::getAsTestInterfaceEmpty()
+{
+ ASSERT(isTestInterfaceEmpty());
+ return m_testInterfaceEmpty;
+}
+
+void TestInterfaceOrTestInterfaceEmpty::setTestInterfaceEmpty(PassRefPtr<TestInterfaceEmpty> value)
+{
+ ASSERT(isNull());
+ m_testInterfaceEmpty = value;
+ m_type = SpecificTypeTestInterfaceEmpty;
+}
+
+void V8TestInterfaceOrTestInterfaceEmpty::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, TestInterfaceOrTestInterfaceEmpty& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (V8TestInterface::hasInstance(v8Value, isolate)) {
+ RefPtr<TestInterfaceImplementation> cppValue = V8TestInterface::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setTestInterface(cppValue);
+ return;
+ }
+
+ if (V8TestInterfaceEmpty::hasInstance(v8Value, isolate)) {
+ RefPtr<TestInterfaceEmpty> cppValue = V8TestInterfaceEmpty::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setTestInterfaceEmpty(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(TestInterfaceOrTestInterfaceEmpty& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isTestInterface())
+ return toV8(impl.getAsTestInterface(), creationContext, isolate);
+
+ if (impl.isTestInterfaceEmpty())
+ return toV8(impl.getAsTestInterfaceEmpty(), creationContext, isolate);
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+TestInterfaceWillBeGarbageCollectedOrTestDictionary::TestInterfaceWillBeGarbageCollectedOrTestDictionary()
+ : m_type(SpecificTypeNone)
+{
+}
+
+PassRefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> TestInterfaceWillBeGarbageCollectedOrTestDictionary::getAsTestInterfaceWillBeGarbageCollected()
+{
+ ASSERT(isTestInterfaceWillBeGarbageCollected());
+ return m_testInterfaceWillBeGarbageCollected;
+}
+
+void TestInterfaceWillBeGarbageCollectedOrTestDictionary::setTestInterfaceWillBeGarbageCollected(PassRefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> value)
+{
+ ASSERT(isNull());
+ m_testInterfaceWillBeGarbageCollected = value;
+ m_type = SpecificTypeTestInterfaceWillBeGarbageCollected;
+}
+
+TestDictionary TestInterfaceWillBeGarbageCollectedOrTestDictionary::getAsTestDictionary()
+{
+ ASSERT(isTestDictionary());
+ return m_testDictionary;
+}
+
+void TestInterfaceWillBeGarbageCollectedOrTestDictionary::setTestDictionary(TestDictionary value)
+{
+ ASSERT(isNull());
+ m_testDictionary = value;
+ m_type = SpecificTypeTestDictionary;
+}
+
+void V8TestInterfaceWillBeGarbageCollectedOrTestDictionary::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, TestInterfaceWillBeGarbageCollectedOrTestDictionary& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty() || isUndefinedOrNull(v8Value))
+ return;
+
+ if (V8TestInterfaceWillBeGarbageCollected::hasInstance(v8Value, isolate)) {
+ RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> cppValue = V8TestInterfaceWillBeGarbageCollected::toImpl(v8::Handle<v8::Object>::Cast(v8Value));
+ impl.setTestInterfaceWillBeGarbageCollected(cppValue);
+ return;
+ }
+
+ if (v8Value->IsObject()) {
+ TestDictionary cppValue = V8TestDictionary::toImpl(isolate, v8Value, exceptionState);
+ if (!exceptionState.hadException())
+ impl.setTestDictionary(cppValue);
+ return;
+ }
+
+ exceptionState.throwTypeError("Not a valid union member.");
+}
+
+v8::Handle<v8::Value> toV8(TestInterfaceWillBeGarbageCollectedOrTestDictionary& impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ if (impl.isNull())
+ return v8::Null(isolate);
+
+ if (impl.isTestInterfaceWillBeGarbageCollected())
+ return toV8(impl.getAsTestInterfaceWillBeGarbageCollected(), creationContext, isolate);
+
+ if (impl.isTestDictionary())
+ return toV8(impl.getAsTestDictionary(), creationContext, isolate);
+
+ ASSERT_NOT_REACHED();
+ return v8::Handle<v8::Value>();
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698