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

Side by Side Diff: Source/bindings/modules/v8/DictionaryHelperForModules.cpp

Issue 373423002: Split Dictionary's get and convert into DictionaryHelper. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/V8Headers.h"
34 #include "bindings/modules/v8/V8MIDIPort.h"
35 #include "bindings/modules/v8/V8MediaStream.h"
36 #include "bindings/modules/v8/V8SpeechRecognitionResult.h"
37 #include "bindings/modules/v8/V8SpeechRecognitionResultList.h"
38 #include "modules/gamepad/Gamepad.h"
39 #include "modules/mediastream/MediaStream.h"
40 #include "modules/speech/SpeechRecognitionResult.h"
41 #include "modules/speech/SpeechRecognitionResultList.h"
42
43 namespace WebCore {
44
45 template <typename T>
46 bool convertInternal(const Dictionary& dictionary, Dictionary::ConversionContext & context, const String& key, T& value)
47 {
48 Dictionary::ConversionContextScope scope(context);
49
50 if (!DictionaryHelper::get(dictionary, key, value))
51 return true;
52
53 if (value)
54 return true;
55
56 v8::Local<v8::Value> v8Value;
57 dictionary.get(key, v8Value);
58 if (context.isNullable() && WebCore::isUndefinedOrNull(v8Value))
59 return true;
60
61 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "does n ot have a " + context.typeName() + " type."));
62 return false;
63 }
64
65 template <>
66 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb er<MIDIPort>& value)
67 {
68 v8::Local<v8::Value> v8Value;
69 if (!dictionary.get(key, v8Value))
70 return false;
71
72 value = V8MIDIPort::toNativeWithTypeCheck(dictionary.isolate(), v8Value);
73 return true;
74 }
75
76 template <>
77 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Member<MIDIPort>& value)
78 {
79 return convertInternal<Member<MIDIPort> >(dictionary, context, key, value);
80 }
81
82 template <>
83 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb er<SpeechRecognitionResult>& value)
84 {
85 v8::Local<v8::Value> v8Value;
86 if (!dictionary.get(key, v8Value))
87 return false;
88
89 value = V8SpeechRecognitionResult::toNativeWithTypeCheck(dictionary.isolate( ), v8Value);
90 return true;
91 }
92
93 template <>
94 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Member<SpeechRecognitionResult>& value)
95 {
96 return convertInternal<Member<SpeechRecognitionResult> >(dictionary, context , key, value);
97 }
98
99 template <>
100 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb er<SpeechRecognitionResultList>& value)
101 {
102 v8::Local<v8::Value> v8Value;
103 if (!dictionary.get(key, v8Value))
104 return false;
105
106 value = V8SpeechRecognitionResultList::toNativeWithTypeCheck(dictionary.isol ate(), v8Value);
107 return true;
108 }
109
110 template <>
111 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Member<SpeechRecognitionResultList>& val ue)
112 {
113 return convertInternal<Member<SpeechRecognitionResultList> >(dictionary, con text, key, value);
114 }
115
116 template <>
117 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb er<Gamepad>& value)
118 {
119 v8::Local<v8::Value> v8Value;
120 if (!dictionary.get(key, v8Value))
121 return false;
122
123 value = V8Gamepad::toNativeWithTypeCheck(dictionary.isolate(), v8Value);
124 return true;
125 }
126
127 template <>
128 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Member<Gamepad>& value)
129 {
130 return convertInternal<Member<Gamepad> >(dictionary, context, key, value);
131 }
132
133 template <>
134 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Memb er<MediaStream>& value)
135 {
136 v8::Local<v8::Value> v8Value;
137 if (!dictionary.get(key, v8Value))
138 return false;
139
140 value = V8MediaStream::toNativeWithTypeCheck(dictionary.isolate(), v8Value);
141 return true;
142 }
143
144 template <>
145 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, Member<MediaStream>& value)
146 {
147 return convertInternal<Member<MediaStream> >(dictionary, context, key, value );
148 }
149
150 template <>
151 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP tr<Headers>& value)
152 {
153 v8::Local<v8::Value> v8Value;
154 if (!dictionary.get(key, v8Value))
155 return false;
156
157 value = V8Headers::toNativeWithTypeCheck(dictionary.isolate(), v8Value);
158 return true;
159 }
160
161 template <>
162 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, RefPtr<Headers>& value)
163 {
164 return convertInternal<RefPtr<Headers> >(dictionary, context, key, value);
165 }
166
167 } // namespace WebCore
168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698