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

Side by Side Diff: Source/bindings/core/v8/DictionaryHelperForCore.cpp

Issue 964553003: bindings: Use V8 MaybeLocal<> APIs in Dictionary class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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
« no previous file with comments | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/core/v8/V8BindingMacros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return dictionary.get(key, value); 58 return dictionary.get(key, value);
59 } 59 }
60 60
61 template <> 61 template <>
62 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, bool& value) 62 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, bool& value)
63 { 63 {
64 v8::Local<v8::Value> v8Value; 64 v8::Local<v8::Value> v8Value;
65 if (!dictionary.get(key, v8Value)) 65 if (!dictionary.get(key, v8Value))
66 return false; 66 return false;
67 67
68 v8::Local<v8::Boolean> v8Bool = v8Value->ToBoolean(dictionary.isolate()); 68 return v8Call(v8Value->BooleanValue(dictionary.v8Context()), value);
69 if (v8Bool.IsEmpty())
70 return false;
71 value = v8Bool->Value();
72 return true;
73 } 69 }
74 70
75 template <> 71 template <>
76 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, bool& value) 72 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, bool& value)
77 { 73 {
78 Dictionary::ConversionContextScope scope(context); 74 Dictionary::ConversionContextScope scope(context);
79 DictionaryHelper::get(dictionary, key, value); 75 DictionaryHelper::get(dictionary, key, value);
80 return true; 76 return true;
81 } 77 }
82 78
83 template <> 79 template <>
84 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, int32_t& value) 80 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, int32_t& value)
85 { 81 {
86 v8::Local<v8::Value> v8Value; 82 v8::Local<v8::Value> v8Value;
87 if (!dictionary.get(key, v8Value)) 83 if (!dictionary.get(key, v8Value))
88 return false; 84 return false;
89 85
90 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(dictionary.isolate()); 86 return v8Call(v8Value->Int32Value(dictionary.v8Context()), value);
91 if (v8Int32.IsEmpty())
92 return false;
93 value = v8Int32->Value();
94 return true;
95 } 87 }
96 88
97 template <> 89 template <>
98 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, double& value, bool& hasValue) 90 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, double& value, bool& hasValue)
99 { 91 {
100 v8::Local<v8::Value> v8Value; 92 v8::Local<v8::Value> v8Value;
101 if (!dictionary.get(key, v8Value)) { 93 if (!dictionary.get(key, v8Value)) {
102 hasValue = false; 94 hasValue = false;
103 return false; 95 return false;
104 } 96 }
105 97
106 hasValue = true; 98 hasValue = true;
107 99 return v8Call(v8Value->NumberValue(dictionary.v8Context()), value);
108 v8::TryCatch block;
109 value = v8Value->NumberValue();
110 if (UNLIKELY(block.HasCaught())) {
111 block.ReThrow();
112 return false;
113 }
114 return true;
115 } 100 }
116 101
117 template <> 102 template <>
118 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value) 103 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value)
119 { 104 {
120 bool unused; 105 bool unused;
121 return DictionaryHelper::get(dictionary, key, value, unused); 106 return DictionaryHelper::get(dictionary, key, value, unused);
122 } 107 }
123 108
124 template <> 109 template <>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 { 177 {
193 Dictionary::ConversionContextScope scope(context); 178 Dictionary::ConversionContextScope scope(context);
194 179
195 DictionaryHelper::get(dictionary, key, value); 180 DictionaryHelper::get(dictionary, key, value);
196 return true; 181 return true;
197 } 182 }
198 183
199 template<typename NumericType> 184 template<typename NumericType>
200 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType & value) 185 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType & value)
201 { 186 {
202 v8::Local<v8::Value> v8Value; 187 int32_t int32Value;
203 if (!dictionary.get(key, v8Value)) 188 if (!DictionaryHelper::get(dictionary, key, int32Value))
204 return false; 189 return false;
205 190 value = static_cast<NumericType>(int32Value);
206 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(dictionary.isolate());
207 if (v8Int32.IsEmpty())
208 return false;
209 value = static_cast<NumericType>(v8Int32->Value());
210 return true; 191 return true;
211 } 192 }
212 193
213 template <> 194 template <>
214 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor t& value) 195 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor t& value)
215 { 196 {
216 return getNumericType<short>(dictionary, key, value); 197 return getNumericType<short>(dictionary, key, value);
217 } 198 }
218 199
219 template <> 200 template <>
220 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, unsigned short& value) 201 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, unsigned short& value)
221 { 202 {
222 return getNumericType<unsigned short>(dictionary, key, value); 203 return getNumericType<unsigned short>(dictionary, key, value);
223 } 204 }
224 205
225 template <> 206 template <>
226 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned& value) 207 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned& value)
227 { 208 {
228 return getNumericType<unsigned>(dictionary, key, value); 209 return getNumericType<unsigned>(dictionary, key, value);
229 } 210 }
230 211
231 template <> 212 template <>
232 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long& value) 213 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long& value)
233 { 214 {
234 v8::Local<v8::Value> v8Value; 215 v8::Local<v8::Value> v8Value;
235 if (!dictionary.get(key, v8Value)) 216 if (!dictionary.get(key, v8Value))
236 return false; 217 return false;
237 218
238 v8::Local<v8::Integer> v8Integer = v8Value->ToInteger(dictionary.isolate()); 219 int64_t int64Value;
239 if (v8Integer.IsEmpty()) 220 if (!v8Call(v8Value->IntegerValue(dictionary.v8Context()), int64Value))
240 return false; 221 return false;
241 value = static_cast<unsigned long>(v8Integer->Value()); 222 value = int64Value;
242 return true; 223 return true;
243 } 224 }
244 225
245 template <> 226 template <>
246 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long long& value) 227 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long long& value)
247 { 228 {
248 v8::Local<v8::Value> v8Value; 229 v8::Local<v8::Value> v8Value;
249 if (!dictionary.get(key, v8Value)) 230 if (!dictionary.get(key, v8Value))
250 return false; 231 return false;
251 232
252 v8::TryCatch block; 233 double doubleValue;
253 double d = v8Value->NumberValue(); 234 if (!v8Call(v8Value->NumberValue(dictionary.v8Context()), doubleValue))
254 if (UNLIKELY(block.HasCaught())) {
255 block.ReThrow();
256 return false; 235 return false;
257 } 236 doubleToInteger(doubleValue, value);
258 doubleToInteger(d, value);
259 return true; 237 return true;
260 } 238 }
261 239
262 template <> 240 template <>
263 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<DOMWindow>& value) 241 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP trWillBeMember<DOMWindow>& value)
264 { 242 {
265 v8::Local<v8::Value> v8Value; 243 v8::Local<v8::Value> v8Value;
266 if (!dictionary.get(key, v8Value)) 244 if (!dictionary.get(key, v8Value))
267 return false; 245 return false;
268 246
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 302 {
325 v8::Local<v8::Value> v8Value; 303 v8::Local<v8::Value> v8Value;
326 if (!dictionary.get(key, v8Value)) 304 if (!dictionary.get(key, v8Value))
327 return false; 305 return false;
328 306
329 if (!v8Value->IsArray()) 307 if (!v8Value->IsArray())
330 return false; 308 return false;
331 309
332 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 310 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
333 for (size_t i = 0; i < v8Array->Length(); ++i) { 311 for (size_t i = 0; i < v8Array->Length(); ++i) {
334 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(diction ary.isolate(), i)); 312 v8::Local<v8::Value> indexedValue;
313 if (!v8Array->Get(dictionary.v8Context(), v8::Uint32::New(dictionary.iso late(), i)).ToLocal(&indexedValue))
314 return false;
335 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false); 315 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false);
336 value.append(stringValue); 316 value.append(stringValue);
337 } 317 }
338 318
339 return true; 319 return true;
340 } 320 }
341 321
342 template <> 322 template <>
343 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, Vector<Vector<String>>& value, ExceptionState& exceptionState) 323 CORE_EXPORT bool DictionaryHelper::get(const Dictionary& dictionary, const Strin g& key, Vector<Vector<String>>& value, ExceptionState& exceptionState)
344 { 324 {
345 v8::Local<v8::Value> v8Value; 325 v8::Local<v8::Value> v8Value;
346 if (!dictionary.get(key, v8Value)) 326 if (!dictionary.get(key, v8Value))
347 return false; 327 return false;
348 328
349 if (!v8Value->IsArray()) 329 if (!v8Value->IsArray())
350 return false; 330 return false;
351 331
352 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 332 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
353 for (size_t i = 0; i < v8Array->Length(); ++i) { 333 for (size_t i = 0; i < v8Array->Length(); ++i) {
354 v8::Local<v8::Value> v8IndexedValue = v8Array->Get(v8::Uint32::New(dicti onary.isolate(), i)); 334 v8::Local<v8::Value> v8IndexedValue;
335 if (!v8Array->Get(dictionary.v8Context(), v8::Uint32::New(dictionary.iso late(), i)).ToLocal(&v8IndexedValue))
336 return false;
355 Vector<String> indexedValue = toImplArray<String>(v8IndexedValue, i, dic tionary.isolate(), exceptionState); 337 Vector<String> indexedValue = toImplArray<String>(v8IndexedValue, i, dic tionary.isolate(), exceptionState);
356 if (exceptionState.hadException()) 338 if (exceptionState.hadException())
357 return false; 339 return false;
358 value.append(indexedValue); 340 value.append(indexedValue);
359 } 341 }
360 342
361 return true; 343 return true;
362 } 344 }
363 345
364 template <> 346 template <>
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 546
565 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), context.exceptionState()); 547 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), context.exceptionState());
566 548
567 if (context.exceptionState().throwIfNeeded()) 549 if (context.exceptionState().throwIfNeeded())
568 return false; 550 return false;
569 551
570 return true; 552 return true;
571 } 553 }
572 554
573 } // namespace blink 555 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/core/v8/V8BindingMacros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698