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

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

Issue 854113002: IDL: Enumeration support in union types (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 5ecb2411384e2bf784056a3930ad3edcf4915a12..e3dc8c68fb603d619b360c5ae94df68475179539 100644
--- a/Source/bindings/tests/results/core/UnionTypesCore.cpp
+++ b/Source/bindings/tests/results/core/UnionTypesCore.cpp
@@ -605,6 +605,88 @@ StringOrStringSequence NativeValueTraits<StringOrStringSequence>::nativeValue(co
return impl;
}
+TestEnumOrDouble::TestEnumOrDouble()
+ : m_type(SpecificTypeNone)
+{
+}
+
+String TestEnumOrDouble::getAsTestEnum() const
+{
+ ASSERT(isTestEnum());
+ return m_testEnum;
+}
+
+void TestEnumOrDouble::setTestEnum(String value)
+{
+ ASSERT(isNull());
+ String string = value;
+ if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ m_testEnum = value;
+ m_type = SpecificTypeTestEnum;
+}
+
+double TestEnumOrDouble::getAsDouble() const
+{
+ ASSERT(isDouble());
+ return m_double;
+}
+
+void TestEnumOrDouble::setDouble(double value)
+{
+ ASSERT(isNull());
+ m_double = value;
+ m_type = SpecificTypeDouble;
+}
+
+void V8TestEnumOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, TestEnumOrDouble& impl, ExceptionState& exceptionState)
+{
+ if (v8Value.IsEmpty())
+ return;
+
+ if (v8Value->IsNumber()) {
+ TONATIVE_VOID_EXCEPTIONSTATE(double, cppValue, toDouble(v8Value, exceptionState), exceptionState);
+ impl.setDouble(cppValue);
+ return;
+ }
+
+ {
+ TOSTRING_VOID_EXCEPTIONSTATE(V8StringResource<>, cppValue, v8Value, exceptionState);
+ String string = cppValue;
+ if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
+ exceptionState.throwTypeError("'" + string + "' is not a valid enum value.");
+ return;
+ }
+ impl.setTestEnum(cppValue);
+ return;
+ }
+
+}
+
+v8::Local<v8::Value> toV8(const TestEnumOrDouble& impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
+{
+ switch (impl.m_type) {
+ case TestEnumOrDouble::SpecificTypeNone:
+ return v8::Null(isolate);
+ case TestEnumOrDouble::SpecificTypeTestEnum:
+ return v8String(isolate, impl.getAsTestEnum());
+ case TestEnumOrDouble::SpecificTypeDouble:
+ return v8::Number::New(isolate, impl.getAsDouble());
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return v8::Local<v8::Value>();
+}
+
+TestEnumOrDouble NativeValueTraits<TestEnumOrDouble>::nativeValue(const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState)
+{
+ TestEnumOrDouble impl;
+ V8TestEnumOrDouble::toImpl(isolate, value, impl, exceptionState);
+ return impl;
+}
+
TestInterface2OrUint8Array::TestInterface2OrUint8Array()
: m_type(SpecificTypeNone)
{
« no previous file with comments | « Source/bindings/tests/results/core/UnionTypesCore.h ('k') | Source/bindings/tests/results/core/V8TestObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698