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. 4 5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! 6 7 #include "config.h" 8 #include "V8TestDictionary.h" 9 10 #include "bindings/core/v8/Dictionary.h" 11 #include "bindings/core/v8/ExceptionState.h" 12 #include "bindings/core/v8/ScriptValue.h" 13 #include "bindings/core/v8/V8Element.h" 14 #include "bindings/core/v8/V8TestInterface.h" 15 #include "bindings/core/v8/V8TestInterfaceGarbageCollected.h" 16 #include "bindings/core/v8/V8TestInterfaceWillBeGarbageCollected.h" 17 18 namespace blink { 19 20 TestDictionary* V8TestDictionary::toImpl(v8::Isolate* isolate, v8::Handle<v8::Value> v8Value, ExceptionState& exceptionState) 21 { 22 ASSERT(isUndefinedOrNull(v8Value) || v8Value->IsObject()); 23 24 TestDictionary* impl = TestDictionary::create(); 25 // FIXME: Do not use Dictionary and DictionaryHelper 26 // https://crbug.com/321462 27 Dictionary dictionary(v8Value, isolate); 28 // FIXME: Remove this v8::TryCatch once the code is switched from 29 // Dictionary/DictionaryHelper to something that uses ExceptionState. 30 v8::TryCatch block; 31 bool booleanMember; 32 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "booleanMember", booleanMember)) { 33 impl->setBooleanMember(booleanMember); 34 } else if (block.HasCaught()) { 35 exceptionState.rethrowV8Exception(block.Exception()); 36 return 0; 37 } 38 double doubleOrNullMember; 39 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "doubleOrNullMember", doubleOrNullMember)) { 40 impl->setDoubleOrNullMember(doubleOrNullMember); 41 } else if (block.HasCaught()) { 42 exceptionState.rethrowV8Exception(block.Exception()); 43 return 0; 44 } 45 RefPtrWillBeRawPtr<Element> elementOrNullMember; 46 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "elementOrNullMember", elementOrNullMember)) { 47 impl->setElementOrNullMember(elementOrNullMember); 48 } else if (block.HasCaught()) { 49 exceptionState.rethrowV8Exception(block.Exception()); 50 return 0; 51 } 52 String enumMember; 53 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "enumMember", enumMember)) { 54 String string = enumMember; 55 if (!(string == "foo" || string == "bar" || string == "baz")) { 56 exceptionState.throwTypeError("member enumMember ('" + string + "') is not a valid enum value."); 57 return 0; 58 } 59 impl->setEnumMember(enumMember); 60 } else if (block.HasCaught()) { 61 exceptionState.rethrowV8Exception(block.Exception()); 62 return 0; 63 } 64 int longMember; 65 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "longMember", longMember)) { 66 impl->setLongMember(longMember); 67 } else if (block.HasCaught()) { 68 exceptionState.rethrowV8Exception(block.Exception()); 69 return 0; 70 } 71 ScriptValue objectMember; 72 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "objectMember", objectMember)) { 73 if (!objectMember.isObject()) { 74 exceptionState.throwTypeError("member objectMember is not an object."); 75 return 0; 76 } 77 impl->setObjectMember(objectMember); 78 } else if (block.HasCaught()) { 79 exceptionState.rethrowV8Exception(block.Exception()); 80 return 0; 81 } 82 ScriptValue objectOrNullMember; 83 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "objectOrNullMember", objectOrNullMember)) { 84 if (!objectOrNullMember.isObject()) { 85 exceptionState.throwTypeError("member objectOrNullMember is not an object."); 86 return 0; 87 } 88 impl->setObjectOrNullMember(objectOrNullMember); 89 } else if (block.HasCaught()) { 90 exceptionState.rethrowV8Exception(block.Exception()); 91 return 0; 92 } 93 Vector<String> stringArrayMember; 94 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringArrayMember", stringArrayMember)) { 95 impl->setStringArrayMember(stringArrayMember); 96 } else if (block.HasCaught()) { 97 exceptionState.rethrowV8Exception(block.Exception()); 98 return 0; 99 } 100 String stringMember; 101 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringMember", stringMember)) { 102 impl->setStringMember(stringMember); 103 } else if (block.HasCaught()) { 104 exceptionState.rethrowV8Exception(block.Exception()); 105 return 0; 106 } 107 String stringOrNullMember; 108 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringOrNullMember", stringOrNullMember)) { 109 impl->setStringOrNullMember(stringOrNullMember); 110 } else if (block.HasCaught()) { 111 exceptionState.rethrowV8Exception(block.Exception()); 112 return 0; 113 } 114 Vector<String> stringSequenceMember; 115 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "stringSequenceMember", stringSequenceMember)) { 116 impl->setStringSequenceMember(stringSequenceMember); 117 } else if (block.HasCaught()) { 118 exceptionState.rethrowV8Exception(block.Exception()); 119 return 0; 120 } 121 RawPtr<TestInterfaceGarbageCollected> testInterfaceGarbageCollectedMember; 122 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceGarbageCollectedMember", testInterfaceGarbageCollectedMember)) { 123 impl->setTestInterfaceGarbageCollectedMember(testInterfaceGarbageCollectedMember); 124 } else if (block.HasCaught()) { 125 exceptionState.rethrowV8Exception(block.Exception()); 126 return 0; 127 } 128 RawPtr<TestInterfaceGarbageCollected> testInterfaceGarbageCollectedOrNullMember; 129 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceGarbageCollectedOrNullMember", testInterfaceGarbageCollectedOrNullMember)) { 130 impl->setTestInterfaceGarbageCollectedOrNullMember(testInterfaceGarbageCollectedOrNullMember); 131 } else if (block.HasCaught()) { 132 exceptionState.rethrowV8Exception(block.Exception()); 133 return 0; 134 } 135 RefPtr<TestInterfaceImplementation> testInterfaceMember; 136 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceMember", testInterfaceMember)) { 137 impl->setTestInterfaceMember(testInterfaceMember); 138 } else if (block.HasCaught()) { 139 exceptionState.rethrowV8Exception(block.Exception()); 140 return 0; 141 } 142 RefPtr<TestInterfaceImplementation> testInterfaceOrNullMember; 143 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceOrNullMember", testInterfaceOrNullMember)) { 144 impl->setTestInterfaceOrNullMember(testInterfaceOrNullMember); 145 } else if (block.HasCaught()) { 146 exceptionState.rethrowV8Exception(block.Exception()); 147 return 0; 148 } 149 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> testInterfaceWillBeGarbageCollectedMember; 150 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceWillBeGarbageCollectedMember", testInterfaceWillBeGarbageCollectedMember)) { 151 impl->setTestInterfaceWillBeGarbageCollectedMember(testInterfaceWillBeGarbageCollectedMember); 152 } else if (block.HasCaught()) { 153 exceptionState.rethrowV8Exception(block.Exception()); 154 return 0; 155 } 156 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> testInterfaceWillBeGarbageCollectedOrNullMember; 157 if (DictionaryHelper::getWithUndefinedOrNullCheck(dictionary, "testInterfaceWillBeGarbageCollectedOrNullMember", testInterfaceWillBeGarbageCollectedOrNullMember)) { 158 impl->setTestInterfaceWillBeGarbageCollectedOrNullMember(testInterfaceWillBeGarbageCollectedOrNullMember); 159 } else if (block.HasCaught()) { 160 exceptionState.rethrowV8Exception(block.Exception()); 161 return 0; 162 } 163 return impl; 164 } 165 166 v8::Handle<v8::Value> toV8(TestDictionary* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 167 { 168 v8::Handle<v8::Object> v8Object = v8::Object::New(isolate); 169 if (impl->hasBooleanMember()) { 170 v8Object->Set(v8String(isolate, "booleanMember"), v8Boolean(impl->booleanMember(), isolate)); 171 } 172 if (impl->hasDoubleOrNullMember()) { 173 v8Object->Set(v8String(isolate, "doubleOrNullMember"), v8::Number::New(isolate, impl->doubleOrNullMember())); 174 } else { 175 v8Object->Set(v8String(isolate, "doubleOrNullMember"), v8::Null(isolate)); 176 } 177 if (impl->hasElementOrNullMember()) { 178 v8Object->Set(v8String(isolate, "elementOrNullMember"), toV8(impl->elementOrNullMember(), creationContext, isolate)); 179 } 180 if (impl->hasEnumMember()) { 181 v8Object->Set(v8String(isolate, "enumMember"), v8String(isolate, impl->enumMember())); 182 } else { 183 v8Object->Set(v8String(isolate, "enumMember"), v8String(isolate, String("foo"))); 184 } 185 if (impl->hasLongMember()) { 186 v8Object->Set(v8String(isolate, "longMember"), v8::Integer::New(isolate, impl->longMember())); 187 } else { 188 v8Object->Set(v8String(isolate, "longMember"), v8::Integer::New(isolate, 1)); 189 } 190 if (impl->hasObjectMember()) { 191 ASSERT(impl->objectMember().isObject()); 192 v8Object->Set(v8String(isolate, "objectMember"), impl->objectMember().v8Value()); 193 } 194 if (impl->hasObjectOrNullMember()) { 195 ASSERT(impl->objectOrNullMember().isObject()); 196 v8Object->Set(v8String(isolate, "objectOrNullMember"), impl->objectOrNullMember().v8Value()); 197 } 198 if (impl->hasStringArrayMember()) { 199 v8Object->Set(v8String(isolate, "stringArrayMember"), v8Array(impl->stringArrayMember(), creationContext, isolate)); 200 } 201 if (impl->hasStringMember()) { 202 v8Object->Set(v8String(isolate, "stringMember"), v8String(isolate, impl->stringMember())); 203 } 204 if (impl->hasStringOrNullMember()) { 205 v8Object->Set(v8String(isolate, "stringOrNullMember"), v8String(isolate, impl->stringOrNullMember())); 206 } else { 207 v8Object->Set(v8String(isolate, "stringOrNullMember"), v8String(isolate, String("default string value"))); 208 } 209 if (impl->hasStringSequenceMember()) { 210 v8Object->Set(v8String(isolate, "stringSequenceMember"), v8Array(impl->stringSequenceMember(), creationContext, isolate)); 211 } 212 if (impl->hasTestInterfaceGarbageCollectedMember()) { 213 v8Object->Set(v8String(isolate, "testInterfaceGarbageCollectedMember"), toV8(impl->testInterfaceGarbageCollectedMember(), creationContext, isolate)); 214 } 215 if (impl->hasTestInterfaceGarbageCollectedOrNullMember()) { 216 v8Object->Set(v8String(isolate, "testInterfaceGarbageCollectedOrNullMember"), toV8(impl->testInterfaceGarbageCollectedOrNullMember(), creationContext, isolate)); 217 } 218 if (impl->hasTestInterfaceMember()) { 219 v8Object->Set(v8String(isolate, "testInterfaceMember"), toV8(impl->testInterfaceMember(), creationContext, isolate)); 220 } 221 if (impl->hasTestInterfaceOrNullMember()) { 222 v8Object->Set(v8String(isolate, "testInterfaceOrNullMember"), toV8(impl->testInterfaceOrNullMember(), creationContext, isolate)); 223 } 224 if (impl->hasTestInterfaceWillBeGarbageCollectedMember()) { 225 v8Object->Set(v8String(isolate, "testInterfaceWillBeGarbageCollectedMember"), toV8(impl->testInterfaceWillBeGarbageCollectedMember(), creationContext, isolate)); 226 } 227 if (impl->hasTestInterfaceWillBeGarbageCollectedOrNullMember()) { 228 v8Object->Set(v8String(isolate, "testInterfaceWillBeGarbageCollectedOrNullMember"), toV8(impl->testInterfaceWillBeGarbageCollectedOrNullMember(), creationContext, isolate)); 229 } 230 return v8Object; 231 } 232 233 } // namespace blink 234