| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 enum IntegerConversionConfiguration { | 368 enum IntegerConversionConfiguration { |
| 369 NormalConversion, | 369 NormalConversion, |
| 370 EnforceRange, | 370 EnforceRange, |
| 371 Clamp | 371 Clamp |
| 372 }; | 372 }; |
| 373 | 373 |
| 374 // Convert a value to a 8-bit signed integer. The conversion fails if the | 374 // Convert a value to a 8-bit signed integer. The conversion fails if the |
| 375 // value cannot be converted to a number or the range violated per WebIDL: | 375 // value cannot be converted to a number or the range violated per WebIDL: |
| 376 // http://www.w3.org/TR/WebIDL/#es-byte | 376 // http://www.w3.org/TR/WebIDL/#es-byte |
| 377 int8_t toInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfiguratio
n, ExceptionState&); | 377 int8_t toInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfiguratio
n, ExceptionState&); |
| 378 inline int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exceptio
nState& exceptionState) | |
| 379 { | |
| 380 return toInt8(isolate, value, NormalConversion, exceptionState); | |
| 381 } | |
| 382 | |
| 383 // Convert a value to a 8-bit integer assuming the conversion cannot fail. | |
| 384 int8_t toInt8(v8::Isolate*, v8::Handle<v8::Value>); | |
| 385 | 378 |
| 386 // Convert a value to a 8-bit unsigned integer. The conversion fails if the | 379 // Convert a value to a 8-bit unsigned integer. The conversion fails if the |
| 387 // value cannot be converted to a number or the range violated per WebIDL: | 380 // value cannot be converted to a number or the range violated per WebIDL: |
| 388 // http://www.w3.org/TR/WebIDL/#es-octet | 381 // http://www.w3.org/TR/WebIDL/#es-octet |
| 389 uint8_t toUInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigurat
ion, ExceptionState&); | 382 uint8_t toUInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigurat
ion, ExceptionState&); |
| 390 inline uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | |
| 391 { | |
| 392 return toUInt8(isolate, value, NormalConversion, exceptionState); | |
| 393 } | |
| 394 | |
| 395 // Convert a value to a 8-bit unsigned integer assuming the conversion cannot fa
il. | |
| 396 uint8_t toUInt8(v8::Isolate*, v8::Handle<v8::Value>); | |
| 397 | 383 |
| 398 // Convert a value to a 16-bit signed integer. The conversion fails if the | 384 // Convert a value to a 16-bit signed integer. The conversion fails if the |
| 399 // value cannot be converted to a number or the range violated per WebIDL: | 385 // value cannot be converted to a number or the range violated per WebIDL: |
| 400 // http://www.w3.org/TR/WebIDL/#es-short | 386 // http://www.w3.org/TR/WebIDL/#es-short |
| 401 int16_t toInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigurat
ion, ExceptionState&); | 387 int16_t toInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigurat
ion, ExceptionState&); |
| 402 inline int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | |
| 403 { | |
| 404 return toInt16(isolate, value, NormalConversion, exceptionState); | |
| 405 } | |
| 406 | |
| 407 // Convert a value to a 16-bit integer assuming the conversion cannot fail. | |
| 408 int16_t toInt16(v8::Isolate*, v8::Handle<v8::Value>); | |
| 409 | 388 |
| 410 // Convert a value to a 16-bit unsigned integer. The conversion fails if the | 389 // Convert a value to a 16-bit unsigned integer. The conversion fails if the |
| 411 // value cannot be converted to a number or the range violated per WebIDL: | 390 // value cannot be converted to a number or the range violated per WebIDL: |
| 412 // http://www.w3.org/TR/WebIDL/#es-unsigned-short | 391 // http://www.w3.org/TR/WebIDL/#es-unsigned-short |
| 413 uint16_t toUInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigur
ation, ExceptionState&); | 392 uint16_t toUInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversionConfigur
ation, ExceptionState&); |
| 414 inline uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exce
ptionState& exceptionState) | |
| 415 { | |
| 416 return toUInt16(isolate, value, NormalConversion, exceptionState); | |
| 417 } | |
| 418 | |
| 419 // Convert a value to a 16-bit unsigned integer assuming the conversion cannot f
ail. | |
| 420 uint16_t toUInt16(v8::Isolate*, v8::Handle<v8::Value>); | |
| 421 | |
| 422 | |
| 423 CORE_EXPORT int32_t toInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); | |
| 424 | 393 |
| 425 // Convert a value to a 32-bit signed integer. The conversion fails if the | 394 // Convert a value to a 32-bit signed integer. The conversion fails if the |
| 426 // value cannot be converted to a number or the range violated per WebIDL: | 395 // value cannot be converted to a number or the range violated per WebIDL: |
| 427 // http://www.w3.org/TR/WebIDL/#es-long | 396 // http://www.w3.org/TR/WebIDL/#es-long |
| 397 CORE_EXPORT int32_t toInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); |
| 428 inline int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) | 398 inline int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) |
| 429 { | 399 { |
| 430 // Fast case. The value is already a 32-bit integer. | 400 // Fast case. The value is already a 32-bit integer. |
| 431 if (value->IsInt32()) | 401 if (value->IsInt32()) |
| 432 return value->Int32Value(); | 402 return value->Int32Value(); |
| 433 return toInt32Slow(isolate, value, configuration, exceptionState); | 403 return toInt32Slow(isolate, value, configuration, exceptionState); |
| 434 } | 404 } |
| 435 | 405 |
| 436 inline int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | |
| 437 { | |
| 438 return toInt32(isolate, value, NormalConversion, exceptionState); | |
| 439 } | |
| 440 | |
| 441 // Convert a value to a 32-bit integer assuming the conversion cannot fail. | |
| 442 int32_t toInt32(v8::Isolate*, v8::Handle<v8::Value>); | |
| 443 | |
| 444 // Convert a value to a 32-bit unsigned integer. The conversion fails if the | 406 // Convert a value to a 32-bit unsigned integer. The conversion fails if the |
| 445 // value cannot be converted to a number or the range violated per WebIDL: | 407 // value cannot be converted to a number or the range violated per WebIDL: |
| 446 // http://www.w3.org/TR/WebIDL/#es-unsigned-long | 408 // http://www.w3.org/TR/WebIDL/#es-unsigned-long |
| 447 CORE_EXPORT uint32_t toUInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); | 409 CORE_EXPORT uint32_t toUInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); |
| 448 inline uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) | 410 inline uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) |
| 449 { | 411 { |
| 450 // Fast case. The value is already a 32-bit unsigned integer. | 412 // Fast case. The value is already a 32-bit unsigned integer. |
| 451 if (value->IsUint32()) | 413 if (value->IsUint32()) |
| 452 return value->Uint32Value(); | 414 return value->Uint32Value(); |
| 453 | 415 |
| 454 // Fast case. The value is a 32-bit signed integer with NormalConversion con
figuration. | 416 // Fast case. The value is a 32-bit signed integer with NormalConversion con
figuration. |
| 455 if (value->IsInt32() && configuration == NormalConversion) | 417 if (value->IsInt32() && configuration == NormalConversion) |
| 456 return value->Int32Value(); | 418 return value->Int32Value(); |
| 457 | 419 |
| 458 return toUInt32Slow(isolate, value, configuration, exceptionState); | 420 return toUInt32Slow(isolate, value, configuration, exceptionState); |
| 459 } | 421 } |
| 460 | 422 |
| 461 inline uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exce
ptionState& exceptionState) | |
| 462 { | |
| 463 return toUInt32(isolate, value, NormalConversion, exceptionState); | |
| 464 } | |
| 465 | |
| 466 // Convert a value to a 32-bit unsigned integer assuming the conversion cannot f
ail. | |
| 467 uint32_t toUInt32(v8::Isolate*, v8::Handle<v8::Value>); | |
| 468 | |
| 469 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); | |
| 470 | |
| 471 // Convert a value to a 64-bit signed integer. The conversion fails if the | 423 // Convert a value to a 64-bit signed integer. The conversion fails if the |
| 472 // value cannot be converted to a number or the range violated per WebIDL: | 424 // value cannot be converted to a number or the range violated per WebIDL: |
| 473 // http://www.w3.org/TR/WebIDL/#es-long-long | 425 // http://www.w3.org/TR/WebIDL/#es-long-long |
| 426 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); |
| 474 inline int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) | 427 inline int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) |
| 475 { | 428 { |
| 476 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr
as.h. | 429 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr
as.h. |
| 477 ASSERT(configuration != Clamp); | 430 ASSERT(configuration != Clamp); |
| 478 | 431 |
| 479 // Fast case. The value is a 32-bit integer. | 432 // Fast case. The value is a 32-bit integer. |
| 480 if (value->IsInt32()) | 433 if (value->IsInt32()) |
| 481 return value->Int32Value(); | 434 return value->Int32Value(); |
| 482 | 435 |
| 483 return toInt64Slow(isolate, value, configuration, exceptionState); | 436 return toInt64Slow(isolate, value, configuration, exceptionState); |
| 484 } | 437 } |
| 485 | 438 |
| 486 inline int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | |
| 487 { | |
| 488 return toInt64(isolate, value, NormalConversion, exceptionState); | |
| 489 } | |
| 490 | |
| 491 // Convert a value to a 64-bit integer assuming the conversion cannot fail. | |
| 492 int64_t toInt64(v8::Isolate*, v8::Handle<v8::Value>); | |
| 493 | |
| 494 CORE_EXPORT uint64_t toUInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); | |
| 495 | |
| 496 // Convert a value to a 64-bit unsigned integer. The conversion fails if the | 439 // Convert a value to a 64-bit unsigned integer. The conversion fails if the |
| 497 // value cannot be converted to a number or the range violated per WebIDL: | 440 // value cannot be converted to a number or the range violated per WebIDL: |
| 498 // http://www.w3.org/TR/WebIDL/#es-unsigned-long-long | 441 // http://www.w3.org/TR/WebIDL/#es-unsigned-long-long |
| 442 CORE_EXPORT uint64_t toUInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); |
| 499 inline uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) | 443 inline uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) |
| 500 { | 444 { |
| 501 // Fast case. The value is a 32-bit unsigned integer. | 445 // Fast case. The value is a 32-bit unsigned integer. |
| 502 if (value->IsUint32()) | 446 if (value->IsUint32()) |
| 503 return value->Uint32Value(); | 447 return value->Uint32Value(); |
| 504 | 448 |
| 505 if (value->IsInt32() && configuration == NormalConversion) | 449 if (value->IsInt32() && configuration == NormalConversion) |
| 506 return value->Int32Value(); | 450 return value->Int32Value(); |
| 507 | 451 |
| 508 return toUInt64Slow(isolate, value, configuration, exceptionState); | 452 return toUInt64Slow(isolate, value, configuration, exceptionState); |
| 509 } | 453 } |
| 510 | 454 |
| 511 inline uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exce
ptionState& exceptionState) | |
| 512 { | |
| 513 return toUInt64(isolate, value, NormalConversion, exceptionState); | |
| 514 } | |
| 515 | |
| 516 // Convert a value to a 64-bit unsigned integer assuming the conversion cannot f
ail. | |
| 517 uint64_t toUInt64(v8::Isolate*, v8::Handle<v8::Value>); | |
| 518 | |
| 519 // Convert a value to a double precision float, which might fail. | 455 // Convert a value to a double precision float, which might fail. |
| 520 CORE_EXPORT double toDoubleSlow(v8::Isolate*, v8::Handle<v8::Value>, ExceptionSt
ate&); | 456 CORE_EXPORT double toDoubleSlow(v8::Isolate*, v8::Handle<v8::Value>, ExceptionSt
ate&); |
| 521 | |
| 522 inline double toDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | 457 inline double toDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) |
| 523 { | 458 { |
| 524 if (value->IsNumber()) | 459 if (value->IsNumber()) |
| 525 return value->NumberValue(); | 460 return value->NumberValue(); |
| 526 return toDoubleSlow(isolate, value, exceptionState); | 461 return toDoubleSlow(isolate, value, exceptionState); |
| 527 } | 462 } |
| 528 | 463 |
| 529 // Convert a value to a double precision float, throwing on non-finite values. | 464 // Convert a value to a double precision float, throwing on non-finite values. |
| 530 CORE_EXPORT double toRestrictedDouble(v8::Isolate*, v8::Handle<v8::Value>, Excep
tionState&); | 465 CORE_EXPORT double toRestrictedDouble(v8::Isolate*, v8::Handle<v8::Value>, Excep
tionState&); |
| 531 | 466 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (!stringValue.prepare(exceptionState)) | 782 if (!stringValue.prepare(exceptionState)) |
| 848 return String(); | 783 return String(); |
| 849 return stringValue; | 784 return stringValue; |
| 850 } | 785 } |
| 851 }; | 786 }; |
| 852 | 787 |
| 853 template<> | 788 template<> |
| 854 struct NativeValueTraits<int> { | 789 struct NativeValueTraits<int> { |
| 855 static inline int nativeValue(v8::Local<v8::Value> value, v8::Isolate* isola
te, ExceptionState& exceptionState) | 790 static inline int nativeValue(v8::Local<v8::Value> value, v8::Isolate* isola
te, ExceptionState& exceptionState) |
| 856 { | 791 { |
| 857 return toInt32(isolate, value, exceptionState); | 792 return toInt32(isolate, value, NormalConversion, exceptionState); |
| 858 } | 793 } |
| 859 }; | 794 }; |
| 860 | 795 |
| 861 template<> | 796 template<> |
| 862 struct NativeValueTraits<unsigned> { | 797 struct NativeValueTraits<unsigned> { |
| 863 static inline unsigned nativeValue(v8::Local<v8::Value> value, v8::Isolate*
isolate, ExceptionState& exceptionState) | 798 static inline unsigned nativeValue(v8::Local<v8::Value> value, v8::Isolate*
isolate, ExceptionState& exceptionState) |
| 864 { | 799 { |
| 865 return toUInt32(isolate, value, exceptionState); | 800 return toUInt32(isolate, value, NormalConversion, exceptionState); |
| 866 } | 801 } |
| 867 }; | 802 }; |
| 868 | 803 |
| 869 template<> | 804 template<> |
| 870 struct NativeValueTraits<float> { | 805 struct NativeValueTraits<float> { |
| 871 static inline float nativeValue(v8::Local<v8::Value> value, v8::Isolate* iso
late, ExceptionState& exceptionState) | 806 static inline float nativeValue(v8::Local<v8::Value> value, v8::Isolate* iso
late, ExceptionState& exceptionState) |
| 872 { | 807 { |
| 873 return toFloat(isolate, value, exceptionState); | 808 return toFloat(isolate, value, exceptionState); |
| 874 } | 809 } |
| 875 }; | 810 }; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 | 994 |
| 1060 // Callback functions used by generated code. | 995 // Callback functions used by generated code. |
| 1061 void v8ConstructorAttributeGetterAsProperty(v8::Local<v8::Name> propertyName, co
nst v8::PropertyCallbackInfo<v8::Value>&); | 996 void v8ConstructorAttributeGetterAsProperty(v8::Local<v8::Name> propertyName, co
nst v8::PropertyCallbackInfo<v8::Value>&); |
| 1062 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
alue>&); | 997 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
alue>&); |
| 1063 | 998 |
| 1064 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); | 999 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); |
| 1065 | 1000 |
| 1066 } // namespace blink | 1001 } // namespace blink |
| 1067 | 1002 |
| 1068 #endif // V8Binding_h | 1003 #endif // V8Binding_h |
| OLD | NEW |