| 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 "sky/engine/config.h" | |
| 27 | |
| 28 #include "bindings/core/v8/V8DOMError.h" | |
| 29 #include "bindings/core/v8/V8Element.h" | |
| 30 #include "bindings/core/v8/V8EventTarget.h" | |
| 31 #include "bindings/core/v8/V8Path2D.h" | |
| 32 #include "bindings/core/v8/V8VoidCallback.h" | |
| 33 #include "bindings/core/v8/V8Window.h" | |
| 34 #include "sky/engine/bindings/core/v8/ArrayValue.h" | |
| 35 #include "sky/engine/bindings/core/v8/DictionaryHelperForBindings.h" | |
| 36 #include "sky/engine/bindings/core/v8/ExceptionMessages.h" | |
| 37 #include "sky/engine/bindings/core/v8/ExceptionState.h" | |
| 38 #include "sky/engine/bindings/core/v8/V8Binding.h" | |
| 39 #include "sky/engine/bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | |
| 40 #include "sky/engine/bindings/core/v8/custom/V8Uint8ArrayCustom.h" | |
| 41 #include "sky/engine/wtf/MathExtras.h" | |
| 42 | |
| 43 namespace blink { | |
| 44 | |
| 45 template <> | |
| 46 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, v8::
Local<v8::Value>& value) | |
| 47 { | |
| 48 return dictionary.get(key, value); | |
| 49 } | |
| 50 | |
| 51 template <> | |
| 52 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Dict
ionary& value) | |
| 53 { | |
| 54 return dictionary.get(key, value); | |
| 55 } | |
| 56 | |
| 57 template <> | |
| 58 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, bool
& value) | |
| 59 { | |
| 60 v8::Local<v8::Value> v8Value; | |
| 61 if (!dictionary.get(key, v8Value)) | |
| 62 return false; | |
| 63 | |
| 64 v8::Local<v8::Boolean> v8Bool = v8Value->ToBoolean(); | |
| 65 if (v8Bool.IsEmpty()) | |
| 66 return false; | |
| 67 value = v8Bool->Value(); | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 template <> | |
| 72 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, bool& value) | |
| 73 { | |
| 74 Dictionary::ConversionContextScope scope(context); | |
| 75 DictionaryHelper::get(dictionary, key, value); | |
| 76 return true; | |
| 77 } | |
| 78 | |
| 79 template <> | |
| 80 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, int3
2_t& value) | |
| 81 { | |
| 82 v8::Local<v8::Value> v8Value; | |
| 83 if (!dictionary.get(key, v8Value)) | |
| 84 return false; | |
| 85 | |
| 86 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(); | |
| 87 if (v8Int32.IsEmpty()) | |
| 88 return false; | |
| 89 value = v8Int32->Value(); | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 template <> | |
| 94 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub
le& value, bool& hasValue) | |
| 95 { | |
| 96 v8::Local<v8::Value> v8Value; | |
| 97 if (!dictionary.get(key, v8Value)) { | |
| 98 hasValue = false; | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 hasValue = true; | |
| 103 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false
); | |
| 104 if (v8Number.IsEmpty()) | |
| 105 return false; | |
| 106 value = v8Number->Value(); | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 110 template <> | |
| 111 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, doub
le& value) | |
| 112 { | |
| 113 bool unused; | |
| 114 return DictionaryHelper::get(dictionary, key, value, unused); | |
| 115 } | |
| 116 | |
| 117 template <> | |
| 118 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, double& value) | |
| 119 { | |
| 120 Dictionary::ConversionContextScope scope(context); | |
| 121 | |
| 122 bool hasValue = false; | |
| 123 if (!DictionaryHelper::get(dictionary, key, value, hasValue) && hasValue) { | |
| 124 context.throwTypeError(ExceptionMessages::incorrectPropertyType(key, "is
not of type 'double'.")); | |
| 125 return false; | |
| 126 } | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 130 template<typename StringType> | |
| 131 bool getStringType(const Dictionary& dictionary, const String& key, StringType&
value) | |
| 132 { | |
| 133 v8::Local<v8::Value> v8Value; | |
| 134 if (!dictionary.get(key, v8Value)) | |
| 135 return false; | |
| 136 | |
| 137 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false); | |
| 138 value = stringValue; | |
| 139 return true; | |
| 140 } | |
| 141 | |
| 142 template <> | |
| 143 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Stri
ng& value) | |
| 144 { | |
| 145 return getStringType(dictionary, key, value); | |
| 146 } | |
| 147 | |
| 148 template <> | |
| 149 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Atom
icString& value) | |
| 150 { | |
| 151 return getStringType(dictionary, key, value); | |
| 152 } | |
| 153 | |
| 154 template <> | |
| 155 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, String& value) | |
| 156 { | |
| 157 Dictionary::ConversionContextScope scope(context); | |
| 158 | |
| 159 v8::Local<v8::Value> v8Value; | |
| 160 if (!dictionary.get(key, v8Value)) | |
| 161 return true; | |
| 162 | |
| 163 TOSTRING_DEFAULT(V8StringResource<>, stringValue, v8Value, false); | |
| 164 value = stringValue; | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 168 template <> | |
| 169 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Scri
ptValue& value) | |
| 170 { | |
| 171 v8::Local<v8::Value> v8Value; | |
| 172 if (!dictionary.get(key, v8Value)) | |
| 173 return false; | |
| 174 | |
| 175 value = ScriptValue(ScriptState::current(dictionary.isolate()), v8Value); | |
| 176 return true; | |
| 177 } | |
| 178 | |
| 179 template <> | |
| 180 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, ScriptValue& value) | |
| 181 { | |
| 182 Dictionary::ConversionContextScope scope(context); | |
| 183 | |
| 184 DictionaryHelper::get(dictionary, key, value); | |
| 185 return true; | |
| 186 } | |
| 187 | |
| 188 template<typename NumericType> | |
| 189 bool getNumericType(const Dictionary& dictionary, const String& key, NumericType
& value) | |
| 190 { | |
| 191 v8::Local<v8::Value> v8Value; | |
| 192 if (!dictionary.get(key, v8Value)) | |
| 193 return false; | |
| 194 | |
| 195 v8::Local<v8::Int32> v8Int32 = v8Value->ToInt32(); | |
| 196 if (v8Int32.IsEmpty()) | |
| 197 return false; | |
| 198 value = static_cast<NumericType>(v8Int32->Value()); | |
| 199 return true; | |
| 200 } | |
| 201 | |
| 202 template <> | |
| 203 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, shor
t& value) | |
| 204 { | |
| 205 return getNumericType<short>(dictionary, key, value); | |
| 206 } | |
| 207 | |
| 208 template <> | |
| 209 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
gned short& value) | |
| 210 { | |
| 211 return getNumericType<unsigned short>(dictionary, key, value); | |
| 212 } | |
| 213 | |
| 214 template <> | |
| 215 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
gned& value) | |
| 216 { | |
| 217 return getNumericType<unsigned>(dictionary, key, value); | |
| 218 } | |
| 219 | |
| 220 template <> | |
| 221 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
gned long& value) | |
| 222 { | |
| 223 v8::Local<v8::Value> v8Value; | |
| 224 if (!dictionary.get(key, v8Value)) | |
| 225 return false; | |
| 226 | |
| 227 v8::Local<v8::Integer> v8Integer = v8Value->ToInteger(); | |
| 228 if (v8Integer.IsEmpty()) | |
| 229 return false; | |
| 230 value = static_cast<unsigned long>(v8Integer->Value()); | |
| 231 return true; | |
| 232 } | |
| 233 | |
| 234 template <> | |
| 235 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, unsi
gned long long& value) | |
| 236 { | |
| 237 v8::Local<v8::Value> v8Value; | |
| 238 if (!dictionary.get(key, v8Value)) | |
| 239 return false; | |
| 240 | |
| 241 TONATIVE_DEFAULT(v8::Local<v8::Number>, v8Number, v8Value->ToNumber(), false
); | |
| 242 if (v8Number.IsEmpty()) | |
| 243 return false; | |
| 244 double d = v8Number->Value(); | |
| 245 doubleToInteger(d, value); | |
| 246 return true; | |
| 247 } | |
| 248 | |
| 249 template <> | |
| 250 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP
tr<LocalDOMWindow>& value) | |
| 251 { | |
| 252 v8::Local<v8::Value> v8Value; | |
| 253 if (!dictionary.get(key, v8Value)) | |
| 254 return false; | |
| 255 | |
| 256 // We need to handle a DOMWindow specially, because a DOMWindow wrapper | |
| 257 // exists on a prototype chain of v8Value. | |
| 258 value = toDOMWindow(v8Value, dictionary.isolate()); | |
| 259 return true; | |
| 260 } | |
| 261 | |
| 262 template <> | |
| 263 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Hash
Set<AtomicString>& value) | |
| 264 { | |
| 265 v8::Local<v8::Value> v8Value; | |
| 266 if (!dictionary.get(key, v8Value)) | |
| 267 return false; | |
| 268 | |
| 269 // FIXME: Support array-like objects | |
| 270 if (!v8Value->IsArray()) | |
| 271 return false; | |
| 272 | |
| 273 ASSERT(dictionary.isolate()); | |
| 274 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent()); | |
| 275 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); | |
| 276 for (size_t i = 0; i < v8Array->Length(); ++i) { | |
| 277 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(dictio
nary.isolate(), i)); | |
| 278 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false); | |
| 279 value.add(stringValue); | |
| 280 } | |
| 281 | |
| 282 return true; | |
| 283 } | |
| 284 | |
| 285 template <> | |
| 286 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, HashSet<AtomicString>& value) | |
| 287 { | |
| 288 Dictionary::ConversionContextScope scope(context); | |
| 289 | |
| 290 v8::Local<v8::Value> v8Value; | |
| 291 if (!dictionary.get(key, v8Value)) | |
| 292 return true; | |
| 293 | |
| 294 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
| 295 return true; | |
| 296 | |
| 297 if (!v8Value->IsArray()) { | |
| 298 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key))
; | |
| 299 return false; | |
| 300 } | |
| 301 | |
| 302 return DictionaryHelper::get(dictionary, key, value); | |
| 303 } | |
| 304 | |
| 305 template <> | |
| 306 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, RefP
tr<EventTarget>& value) | |
| 307 { | |
| 308 v8::Local<v8::Value> v8Value; | |
| 309 if (!dictionary.get(key, v8Value)) | |
| 310 return false; | |
| 311 | |
| 312 value = nullptr; | |
| 313 // We need to handle a LocalDOMWindow specially, because a LocalDOMWindow wr
apper | |
| 314 // exists on a prototype chain of v8Value. | |
| 315 if (v8Value->IsObject()) { | |
| 316 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value); | |
| 317 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(w
rapper, dictionary.isolate()); | |
| 318 if (!window.IsEmpty()) { | |
| 319 value = toWrapperTypeInfo(window)->toEventTarget(window); | |
| 320 return true; | |
| 321 } | |
| 322 } | |
| 323 | |
| 324 if (V8DOMWrapper::isDOMWrapper(v8Value)) { | |
| 325 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(v8Value); | |
| 326 value = toWrapperTypeInfo(wrapper)->toEventTarget(wrapper); | |
| 327 } | |
| 328 return true; | |
| 329 } | |
| 330 | |
| 331 template <> | |
| 332 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Vect
or<String>& value) | |
| 333 { | |
| 334 v8::Local<v8::Value> v8Value; | |
| 335 if (!dictionary.get(key, v8Value)) | |
| 336 return false; | |
| 337 | |
| 338 if (!v8Value->IsArray()) | |
| 339 return false; | |
| 340 | |
| 341 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); | |
| 342 for (size_t i = 0; i < v8Array->Length(); ++i) { | |
| 343 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Uint32::New(diction
ary.isolate(), i)); | |
| 344 TOSTRING_DEFAULT(V8StringResource<>, stringValue, indexedValue, false); | |
| 345 value.append(stringValue); | |
| 346 } | |
| 347 | |
| 348 return true; | |
| 349 } | |
| 350 | |
| 351 template <> | |
| 352 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Vector<String>& value) | |
| 353 { | |
| 354 Dictionary::ConversionContextScope scope(context); | |
| 355 | |
| 356 v8::Local<v8::Value> v8Value; | |
| 357 if (!dictionary.get(key, v8Value)) | |
| 358 return true; | |
| 359 | |
| 360 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
| 361 return true; | |
| 362 | |
| 363 if (!v8Value->IsArray()) { | |
| 364 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key))
; | |
| 365 return false; | |
| 366 } | |
| 367 | |
| 368 return DictionaryHelper::get(dictionary, key, value); | |
| 369 } | |
| 370 | |
| 371 template <> | |
| 372 bool DictionaryHelper::get(const Dictionary& dictionary, const String& key, Arra
yValue& value) | |
| 373 { | |
| 374 v8::Local<v8::Value> v8Value; | |
| 375 if (!dictionary.get(key, v8Value)) | |
| 376 return false; | |
| 377 | |
| 378 if (!v8Value->IsArray()) | |
| 379 return false; | |
| 380 | |
| 381 ASSERT(dictionary.isolate()); | |
| 382 ASSERT(dictionary.isolate() == v8::Isolate::GetCurrent()); | |
| 383 value = ArrayValue(v8::Local<v8::Array>::Cast(v8Value), dictionary.isolate()
); | |
| 384 return true; | |
| 385 } | |
| 386 | |
| 387 template <> | |
| 388 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, ArrayValue& value) | |
| 389 { | |
| 390 Dictionary::ConversionContextScope scope(context); | |
| 391 | |
| 392 v8::Local<v8::Value> v8Value; | |
| 393 if (!dictionary.get(key, v8Value)) | |
| 394 return true; | |
| 395 | |
| 396 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) | |
| 397 return true; | |
| 398 | |
| 399 if (!v8Value->IsArray()) { | |
| 400 context.throwTypeError(ExceptionMessages::notASequenceTypeProperty(key))
; | |
| 401 return false; | |
| 402 } | |
| 403 | |
| 404 return DictionaryHelper::get(dictionary, key, value); | |
| 405 } | |
| 406 | |
| 407 template <> | |
| 408 struct DictionaryHelperTraits<Uint8Array> { | |
| 409 typedef V8Uint8Array type; | |
| 410 }; | |
| 411 | |
| 412 template <> | |
| 413 struct DictionaryHelperTraits<ArrayBufferView> { | |
| 414 typedef V8ArrayBufferView type; | |
| 415 }; | |
| 416 | |
| 417 template <> | |
| 418 struct DictionaryHelperTraits<DOMError> { | |
| 419 typedef V8DOMError type; | |
| 420 }; | |
| 421 | |
| 422 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr
<Uint8Array>& value); | |
| 423 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr
<ArrayBufferView>& value); | |
| 424 template bool DictionaryHelper::get(const Dictionary&, const String& key, RefPtr
<DOMError>& value); | |
| 425 | |
| 426 template <typename T> | |
| 427 struct IntegralTypeTraits { | |
| 428 }; | |
| 429 | |
| 430 template <> | |
| 431 struct IntegralTypeTraits<uint8_t> { | |
| 432 static inline uint8_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) | |
| 433 { | |
| 434 return toUInt8(value, configuration, exceptionState); | |
| 435 } | |
| 436 static const String typeName() { return "UInt8"; } | |
| 437 }; | |
| 438 | |
| 439 template <> | |
| 440 struct IntegralTypeTraits<int8_t> { | |
| 441 static inline int8_t toIntegral(v8::Handle<v8::Value> value, IntegerConversi
onConfiguration configuration, ExceptionState& exceptionState) | |
| 442 { | |
| 443 return toInt8(value, configuration, exceptionState); | |
| 444 } | |
| 445 static const String typeName() { return "Int8"; } | |
| 446 }; | |
| 447 | |
| 448 template <> | |
| 449 struct IntegralTypeTraits<unsigned short> { | |
| 450 static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) | |
| 451 { | |
| 452 return toUInt16(value, configuration, exceptionState); | |
| 453 } | |
| 454 static const String typeName() { return "UInt16"; } | |
| 455 }; | |
| 456 | |
| 457 template <> | |
| 458 struct IntegralTypeTraits<short> { | |
| 459 static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) | |
| 460 { | |
| 461 return toInt16(value, configuration, exceptionState); | |
| 462 } | |
| 463 static const String typeName() { return "Int16"; } | |
| 464 }; | |
| 465 | |
| 466 template <> | |
| 467 struct IntegralTypeTraits<unsigned> { | |
| 468 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) | |
| 469 { | |
| 470 return toUInt32(value, configuration, exceptionState); | |
| 471 } | |
| 472 static const String typeName() { return "UInt32"; } | |
| 473 }; | |
| 474 | |
| 475 template <> | |
| 476 struct IntegralTypeTraits<unsigned long> { | |
| 477 static inline uint32_t toIntegral(v8::Handle<v8::Value> value, IntegerConver
sionConfiguration configuration, ExceptionState& exceptionState) | |
| 478 { | |
| 479 return toUInt32(value, configuration, exceptionState); | |
| 480 } | |
| 481 static const String typeName() { return "UInt32"; } | |
| 482 }; | |
| 483 | |
| 484 template <> | |
| 485 struct IntegralTypeTraits<int> { | |
| 486 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) | |
| 487 { | |
| 488 return toInt32(value, configuration, exceptionState); | |
| 489 } | |
| 490 static const String typeName() { return "Int32"; } | |
| 491 }; | |
| 492 | |
| 493 template <> | |
| 494 struct IntegralTypeTraits<long> { | |
| 495 static inline int32_t toIntegral(v8::Handle<v8::Value> value, IntegerConvers
ionConfiguration configuration, ExceptionState& exceptionState) | |
| 496 { | |
| 497 return toInt32(value, configuration, exceptionState); | |
| 498 } | |
| 499 static const String typeName() { return "Int32"; } | |
| 500 }; | |
| 501 | |
| 502 template <> | |
| 503 struct IntegralTypeTraits<unsigned long long> { | |
| 504 static inline unsigned long long toIntegral(v8::Handle<v8::Value> value, Int
egerConversionConfiguration configuration, ExceptionState& exceptionState) | |
| 505 { | |
| 506 return toUInt64(value, configuration, exceptionState); | |
| 507 } | |
| 508 static const String typeName() { return "UInt64"; } | |
| 509 }; | |
| 510 | |
| 511 template <> | |
| 512 struct IntegralTypeTraits<long long> { | |
| 513 static inline long long toIntegral(v8::Handle<v8::Value> value, IntegerConve
rsionConfiguration configuration, ExceptionState& exceptionState) | |
| 514 { | |
| 515 return toInt64(value, configuration, exceptionState); | |
| 516 } | |
| 517 static const String typeName() { return "Int64"; } | |
| 518 }; | |
| 519 | |
| 520 template<typename T> | |
| 521 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, T& value) | |
| 522 { | |
| 523 Dictionary::ConversionContextScope scope(context); | |
| 524 | |
| 525 v8::Local<v8::Value> v8Value; | |
| 526 if (!dictionary.get(key, v8Value)) | |
| 527 return true; | |
| 528 | |
| 529 value = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, context
.exceptionState()); | |
| 530 if (context.exceptionState().throwIfNeeded()) | |
| 531 return false; | |
| 532 | |
| 533 return true; | |
| 534 } | |
| 535 | |
| 536 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, uint8_t& value); | |
| 537 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, int8_t& value); | |
| 538 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned short& value); | |
| 539 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, short& value); | |
| 540 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned& value); | |
| 541 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned long& value); | |
| 542 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, int& value); | |
| 543 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, long& value); | |
| 544 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, long long& value); | |
| 545 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, unsigned long long& value); | |
| 546 | |
| 547 template<typename T> | |
| 548 bool DictionaryHelper::convert(const Dictionary& dictionary, Dictionary::Convers
ionContext& context, const String& key, Nullable<T>& value) | |
| 549 { | |
| 550 Dictionary::ConversionContextScope scope(context); | |
| 551 | |
| 552 v8::Local<v8::Value> v8Value; | |
| 553 if (!dictionary.get(key, v8Value)) | |
| 554 return true; | |
| 555 | |
| 556 if (context.isNullable() && blink::isUndefinedOrNull(v8Value)) { | |
| 557 value = Nullable<T>(); | |
| 558 return true; | |
| 559 } | |
| 560 | |
| 561 T converted = IntegralTypeTraits<T>::toIntegral(v8Value, NormalConversion, c
ontext.exceptionState()); | |
| 562 | |
| 563 if (context.exceptionState().throwIfNeeded()) | |
| 564 return false; | |
| 565 | |
| 566 value = Nullable<T>(converted); | |
| 567 return true; | |
| 568 } | |
| 569 | |
| 570 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<uint8_t>& value); | |
| 571 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<int8_t>& value); | |
| 572 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<unsigned short>& value); | |
| 573 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<short>& value); | |
| 574 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<unsigned>& value); | |
| 575 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<unsigned long>& value); | |
| 576 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<int>& value); | |
| 577 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<long>& value); | |
| 578 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<long long>& value); | |
| 579 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, Nullable<unsigned long long>& value); | |
| 580 | |
| 581 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, RefPtr<LocalDOMWindow>& value); | |
| 582 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, RefPtr<Uint8Array>& value); | |
| 583 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, RefPtr<ArrayBufferView>& value); | |
| 584 template bool DictionaryHelper::convert(const Dictionary&, Dictionary::Conversio
nContext&, const String& key, RefPtr<EventTarget>& value); | |
| 585 | |
| 586 } // namespace blink | |
| OLD | NEW |