OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. |
| 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ |
| 25 |
| 26 #include "config.h" |
| 27 #include "bindings/core/v8/DictionaryHelper.h" |
| 28 |
| 29 #include "bindings/core/v8/ExceptionMessages.h" |
| 30 #include "bindings/core/v8/ExceptionState.h" |
| 31 #include "bindings/core/v8/V8Binding.h" |
| 32 #include "bindings/modules/v8/V8Gamepad.h" |
| 33 #include "bindings/modules/v8/V8HeaderMap.h" |
| 34 #include "bindings/modules/v8/V8Headers.h" |
| 35 #include "bindings/modules/v8/V8MIDIPort.h" |
| 36 #include "bindings/modules/v8/V8MediaStream.h" |
| 37 #include "bindings/modules/v8/V8SpeechRecognitionResult.h" |
| 38 #include "bindings/modules/v8/V8SpeechRecognitionResultList.h" |
| 39 #include "modules/gamepad/Gamepad.h" |
| 40 #include "modules/mediastream/MediaStream.h" |
| 41 #include "modules/speech/SpeechRecognitionResult.h" |
| 42 #include "modules/speech/SpeechRecognitionResultList.h" |
| 43 |
| 44 namespace WebCore { |
| 45 |
| 46 template <typename T> |
| 47 bool convertInternal(const Dictionary& dictionary, Dictionary::ConversionContext
& context, const String& key, T& value) |
| 48 { |
| 49 Dictionary::ConversionContextScope scope(context); |
| 50 |
| 51 if (!DictionaryHelper::get(dictionary, key, value)) |
| 52 return true; |
| 53 |
| 54 if (value) |
| 55 return true; |
| 56 |
| 57 v8::Local<v8::Value> v8Value; |
| 58 dictionary.get(key, v8Value); |
| 59 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value)) |
| 60 return true; |
| 61 |
| 62 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n
ot have a " + context.typeName() + " type.")); |
| 63 return false; |
| 64 } |
| 65 |
| 66 template <> |
| 67 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
er<MIDIPort>& value) |
| 68 { |
| 69 v8::Local<v8::Value> v8Value; |
| 70 if (!dictionary.get(key, v8Value)) |
| 71 return false; |
| 72 |
| 73 value = V8MIDIPort::toNativeWithTypeCheck(dictionary.isolate(), v8Value); |
| 74 return true; |
| 75 } |
| 76 |
| 77 template <> |
| 78 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Member<MIDIPort>& value) |
| 79 { |
| 80 return convertInternal<Member<MIDIPort> >(dictionary, context, key, value); |
| 81 } |
| 82 |
| 83 template <> |
| 84 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
er<SpeechRecognitionResult>& value) |
| 85 { |
| 86 v8::Local<v8::Value> v8Value; |
| 87 if (!dictionary.get(key, v8Value)) |
| 88 return false; |
| 89 |
| 90 value = V8SpeechRecognitionResult::toNativeWithTypeCheck(dictionary.isolate(
), v8Value); |
| 91 return true; |
| 92 } |
| 93 |
| 94 template <> |
| 95 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Member<SpeechRecognitionResult>& value) |
| 96 { |
| 97 return convertInternal<Member<SpeechRecognitionResult> >(dictionary, context
, key, value); |
| 98 } |
| 99 |
| 100 template <> |
| 101 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
er<SpeechRecognitionResultList>& value) |
| 102 { |
| 103 v8::Local<v8::Value> v8Value; |
| 104 if (!dictionary.get(key, v8Value)) |
| 105 return false; |
| 106 |
| 107 value = V8SpeechRecognitionResultList::toNativeWithTypeCheck(dictionary.isol
ate(), v8Value); |
| 108 return true; |
| 109 } |
| 110 |
| 111 template <> |
| 112 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Member<SpeechRecognitionResultList>& val
ue) |
| 113 { |
| 114 return convertInternal<Member<SpeechRecognitionResultList> >(dictionary, con
text, key, value); |
| 115 } |
| 116 |
| 117 template <> |
| 118 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
er<Gamepad>& value) |
| 119 { |
| 120 v8::Local<v8::Value> v8Value; |
| 121 if (!dictionary.get(key, v8Value)) |
| 122 return false; |
| 123 |
| 124 value = V8Gamepad::toNativeWithTypeCheck(dictionary.isolate(), v8Value); |
| 125 return true; |
| 126 } |
| 127 |
| 128 template <> |
| 129 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Member<Gamepad>& value) |
| 130 { |
| 131 return convertInternal<Member<Gamepad> >(dictionary, context, key, value); |
| 132 } |
| 133 |
| 134 template <> |
| 135 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb
er<MediaStream>& value) |
| 136 { |
| 137 v8::Local<v8::Value> v8Value; |
| 138 if (!dictionary.get(key, v8Value)) |
| 139 return false; |
| 140 |
| 141 value = V8MediaStream::toNativeWithTypeCheck(dictionary.isolate(), v8Value); |
| 142 return true; |
| 143 } |
| 144 |
| 145 template <> |
| 146 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Member<MediaStream>& value) |
| 147 { |
| 148 return convertInternal<Member<MediaStream> >(dictionary, context, key, value
); |
| 149 } |
| 150 |
| 151 |
| 152 template <> |
| 153 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP
tr<HeaderMap>& value) |
| 154 { |
| 155 v8::Local<v8::Value> v8Value; |
| 156 if (!dictionary.get(key, v8Value)) |
| 157 return false; |
| 158 |
| 159 value = V8HeaderMap::toNativeWithTypeCheck(dictionary.isolate(), v8Value); |
| 160 return true; |
| 161 } |
| 162 |
| 163 template <> |
| 164 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, RefPtr<HeaderMap>& value) |
| 165 { |
| 166 return convertInternal<RefPtr<HeaderMap> >(dictionary, context, key, value); |
| 167 } |
| 168 |
| 169 template <> |
| 170 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP
tr<Headers>& value) |
| 171 { |
| 172 v8::Local<v8::Value> v8Value; |
| 173 if (!dictionary.get(key, v8Value)) |
| 174 return false; |
| 175 |
| 176 value = V8Headers::toNativeWithTypeCheck(dictionary.isolate(), v8Value); |
| 177 return true; |
| 178 } |
| 179 |
| 180 template <> |
| 181 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, RefPtr<Headers>& value) |
| 182 { |
| 183 return convertInternal<RefPtr<Headers> >(dictionary, context, key, value); |
| 184 } |
| 185 |
| 186 } // namespace WebCore |
| 187 |
OLD | NEW |