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

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
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 return dictionary.get(key, value); 59 return dictionary.get(key, value);
60 } 60 }
61 61
62 template <> 62 template <>
63 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, bool & value) 63 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, bool & value)
64 { 64 {
65 v8::Local<v8::Value> v8Value; 65 v8::Local<v8::Value> v8Value;
66 if (!dictionary.get(key, v8Value)) 66 if (!dictionary.get(key, v8Value))
67 return false; 67 return false;
68 68
69 v8::Local<v8::Boolean> v8Bool = v8Value->ToBoolean(dictionary.isolate()); 69 v8::MaybeLocal<v8::Boolean> maybeBool = v8Value->ToBoolean(dictionary.contex t());
70 if (v8Bool.IsEmpty()) 70 v8::Local<v8::Boolean> v8Bool;
71 if (!maybeBool.ToLocal(&v8Bool) || v8Bool.IsEmpty())
71 return false; 72 return false;
72 value = v8Bool->Value(); 73 value = v8Bool->Value();
73 return true; 74 return true;
74 } 75 }
75 76
76 template <> 77 template <>
77 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, bool& value) 78 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers ionContext& context, const String& key, bool& value)
78 { 79 {
79 Dictionary::ConversionContextScope scope(context); 80 Dictionary::ConversionContextScope scope(context);
80 DictionaryHelper::get(dictionary, key, value); 81 DictionaryHelper::get(dictionary, key, value);
81 return true; 82 return true;
82 } 83 }
83 84
84 template <> 85 template <>
85 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, int3 2_t& value) 86 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, int3 2_t& value)
86 { 87 {
87 v8::Local<v8::Value> v8Value; 88 v8::Local<v8::Value> v8Value;
88 if (!dictionary.get(key, v8Value)) 89 if (!dictionary.get(key, v8Value))
89 return false; 90 return false;
90 91
91 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(dictionary.isolate()); 92 v8::MaybeLocal<v8::Int32> maybeInt32 = v8Value->ToInt32(dictionary.context() );
92 if (v8Int32.IsEmpty()) 93 v8::Local<v8::Int32> v8Int32;
94 if (!maybeInt32.ToLocal(&v8Int32) || v8Int32.IsEmpty())
93 return false; 95 return false;
94 value = v8Int32->Value(); 96 value = v8Int32->Value();
95 return true; 97 return true;
96 } 98 }
97 99
98 template <> 100 template <>
99 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value, bool& hasValue) 101 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub le& value, bool& hasValue)
100 { 102 {
101 v8::Local<v8::Value> v8Value; 103 v8::Local<v8::Value> v8Value;
102 if (!dictionary.get(key, v8Value)) { 104 if (!dictionary.get(key, v8Value)) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return true; 199 return true;
198 } 200 }
199 201
200 template<typename NumericType> 202 template<typename NumericType>
201 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType & value) 203 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType & value)
202 { 204 {
203 v8::Local<v8::Value> v8Value; 205 v8::Local<v8::Value> v8Value;
204 if (!dictionary.get(key, v8Value)) 206 if (!dictionary.get(key, v8Value))
205 return false; 207 return false;
206 208
207 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(dictionary.isolate()); 209 v8::MaybeLocal<v8::Int32> maybeInt32 = v8Value->ToInt32(dictionary.context() );
208 if (v8Int32.IsEmpty()) 210 v8::Local<v8::Int32> v8Int32;
211 if (!maybeInt32.ToLocal(&v8Int32) || v8Int32.IsEmpty())
209 return false; 212 return false;
210 value = static_cast<NumericType>(v8Int32->Value()); 213 value = static_cast<NumericType>(v8Int32->Value());
211 return true; 214 return true;
212 } 215 }
213 216
214 template <> 217 template <>
215 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor t& value) 218 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor t& value)
216 { 219 {
217 return getNumericType<short>(dictionary, key, value); 220 return getNumericType<short>(dictionary, key, value);
218 } 221 }
(...skipping 10 matching lines...) Expand all
229 return getNumericType<unsigned>(dictionary, key, value); 232 return getNumericType<unsigned>(dictionary, key, value);
230 } 233 }
231 234
232 template <> 235 template <>
233 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long& value) 236 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long& value)
234 { 237 {
235 v8::Local<v8::Value> v8Value; 238 v8::Local<v8::Value> v8Value;
236 if (!dictionary.get(key, v8Value)) 239 if (!dictionary.get(key, v8Value))
237 return false; 240 return false;
238 241
239 v8::Local<v8::Integer> v8Integer = v8Value->ToInteger(dictionary.isolate()); 242 v8::MaybeLocal<v8::Integer> maybeInteger = v8Value->ToInteger(dictionary.con text());
240 if (v8Integer.IsEmpty()) 243 v8::Local<v8::Integer> v8Integer;
dcarney 2015/03/06 07:42:44 same here - macros everywhere
244 if (!maybeInteger.ToLocal(&v8Integer) || v8Integer.IsEmpty())
241 return false; 245 return false;
242 value = static_cast<unsigned long>(v8Integer->Value()); 246 value = static_cast<unsigned long>(v8Integer->Value());
243 return true; 247 return true;
244 } 248 }
245 249
246 template <> 250 template <>
247 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long long& value) 251 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi gned long long& value)
248 { 252 {
249 v8::Local<v8::Value> v8Value; 253 v8::Local<v8::Value> v8Value;
250 if (!dictionary.get(key, v8Value)) 254 if (!dictionary.get(key, v8Value))
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 569
566 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), context.exceptionState()); 570 value = toRefPtrWillBeMemberNativeArray<MessagePort, V8MessagePort>(v8Value, key, dictionary.isolate(), context.exceptionState());
567 571
568 if (context.exceptionState().throwIfNeeded()) 572 if (context.exceptionState().throwIfNeeded())
569 return false; 573 return false;
570 574
571 return true; 575 return true;
572 } 576 }
573 577
574 } // namespace blink 578 } // namespace blink
OLDNEW
« Source/bindings/core/v8/Dictionary.cpp ('K') | « Source/bindings/core/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698