| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2  * Copyright (C) 2006, 2007, 2008, 2009 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 are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * 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  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 274 | 274 | 
| 275     numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
      rValue)); | 275     numberValue = numberValue < 0 ? -floor(fabs(numberValue)) : floor(fabs(numbe
      rValue)); | 
| 276     return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); | 276     return static_cast<T>(fmod(numberValue, LimitsTrait::numberOfValues)); | 
| 277 } | 277 } | 
| 278 | 278 | 
| 279 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversi
      onConfiguration configuration, ExceptionState& exceptionState) | 279 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConversi
      onConfiguration configuration, ExceptionState& exceptionState) | 
| 280 { | 280 { | 
| 281     return toSmallerInt<int8_t>(isolate, value, configuration, "byte", exception
      State); | 281     return toSmallerInt<int8_t>(isolate, value, configuration, "byte", exception
      State); | 
| 282 } | 282 } | 
| 283 | 283 | 
| 284 int8_t toInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 285 { |  | 
| 286     NonThrowableExceptionState exceptionState; |  | 
| 287     return toInt8(isolate, value, NormalConversion, exceptionState); |  | 
| 288 } |  | 
| 289 |  | 
| 290 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
      sionConfiguration configuration, ExceptionState& exceptionState) | 284 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
      sionConfiguration configuration, ExceptionState& exceptionState) | 
| 291 { | 285 { | 
| 292     return toSmallerUInt<uint8_t>(isolate, value, configuration, "octet", except
      ionState); | 286     return toSmallerUInt<uint8_t>(isolate, value, configuration, "octet", except
      ionState); | 
| 293 } | 287 } | 
| 294 | 288 | 
| 295 uint8_t toUInt8(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 296 { |  | 
| 297     NonThrowableExceptionState exceptionState; |  | 
| 298     return toUInt8(isolate, value, NormalConversion, exceptionState); |  | 
| 299 } |  | 
| 300 |  | 
| 301 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
      sionConfiguration configuration, ExceptionState& exceptionState) | 289 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConver
      sionConfiguration configuration, ExceptionState& exceptionState) | 
| 302 { | 290 { | 
| 303     return toSmallerInt<int16_t>(isolate, value, configuration, "short", excepti
      onState); | 291     return toSmallerInt<int16_t>(isolate, value, configuration, "short", excepti
      onState); | 
| 304 } | 292 } | 
| 305 | 293 | 
| 306 int16_t toInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 307 { |  | 
| 308     NonThrowableExceptionState exceptionState; |  | 
| 309     return toInt16(isolate, value, NormalConversion, exceptionState); |  | 
| 310 } |  | 
| 311 |  | 
| 312 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv
      ersionConfiguration configuration, ExceptionState& exceptionState) | 294 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerConv
      ersionConfiguration configuration, ExceptionState& exceptionState) | 
| 313 { | 295 { | 
| 314     return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor
      t", exceptionState); | 296     return toSmallerUInt<uint16_t>(isolate, value, configuration, "unsigned shor
      t", exceptionState); | 
| 315 } | 297 } | 
| 316 | 298 | 
| 317 uint16_t toUInt16(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 318 { |  | 
| 319     NonThrowableExceptionState exceptionState; |  | 
| 320     return toUInt16(isolate, value, NormalConversion, exceptionState); |  | 
| 321 } |  | 
| 322 |  | 
| 323 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
      nversionConfiguration configuration, ExceptionState& exceptionState) | 299 int32_t toInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
      nversionConfiguration configuration, ExceptionState& exceptionState) | 
| 324 { | 300 { | 
| 325     ASSERT(!value->IsInt32()); | 301     ASSERT(!value->IsInt32()); | 
| 326     // Can the value be converted to a number? | 302     // Can the value be converted to a number? | 
| 327     v8::TryCatch block(isolate); | 303     v8::TryCatch block(isolate); | 
| 328     v8::Local<v8::Number> numberObject = value->ToNumber(isolate); | 304     v8::Local<v8::Number> numberObject = value->ToNumber(isolate); | 
| 329     if (block.HasCaught()) { | 305     if (block.HasCaught()) { | 
| 330         exceptionState.rethrowV8Exception(block.Exception()); | 306         exceptionState.rethrowV8Exception(block.Exception()); | 
| 331         return 0; | 307         return 0; | 
| 332     } | 308     } | 
| 333 | 309 | 
| 334     ASSERT(!numberObject.IsEmpty()); | 310     ASSERT(!numberObject.IsEmpty()); | 
| 335 | 311 | 
| 336     double numberValue = numberObject->Value(); | 312     double numberValue = numberObject->Value(); | 
| 337     if (configuration == EnforceRange) | 313     if (configuration == EnforceRange) | 
| 338         return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception
      State); | 314         return enforceRange(numberValue, kMinInt32, kMaxInt32, "long", exception
      State); | 
| 339 | 315 | 
| 340     if (std::isnan(numberValue)) | 316     if (std::isnan(numberValue)) | 
| 341         return 0; | 317         return 0; | 
| 342 | 318 | 
| 343     if (configuration == Clamp) | 319     if (configuration == Clamp) | 
| 344         return clampTo<int32_t>(numberValue); | 320         return clampTo<int32_t>(numberValue); | 
| 345 | 321 | 
| 346     if (std::isinf(numberValue)) | 322     if (std::isinf(numberValue)) | 
| 347         return 0; | 323         return 0; | 
| 348 | 324 | 
| 349     return numberObject->Int32Value(); | 325     return numberObject->Int32Value(); | 
| 350 } | 326 } | 
| 351 | 327 | 
| 352 int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 353 { |  | 
| 354     NonThrowableExceptionState exceptionState; |  | 
| 355     return toInt32(isolate, value, NormalConversion, exceptionState); |  | 
| 356 } |  | 
| 357 |  | 
| 358 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
      ConversionConfiguration configuration, ExceptionState& exceptionState) | 328 uint32_t toUInt32Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
      ConversionConfiguration configuration, ExceptionState& exceptionState) | 
| 359 { | 329 { | 
| 360     ASSERT(!value->IsUint32()); | 330     ASSERT(!value->IsUint32()); | 
| 361     if (value->IsInt32()) { | 331     if (value->IsInt32()) { | 
| 362         ASSERT(configuration != NormalConversion); | 332         ASSERT(configuration != NormalConversion); | 
| 363         int32_t result = value->Int32Value(); | 333         int32_t result = value->Int32Value(); | 
| 364         if (result >= 0) | 334         if (result >= 0) | 
| 365             return result; | 335             return result; | 
| 366         if (configuration == EnforceRange) { | 336         if (configuration == EnforceRange) { | 
| 367             exceptionState.throwTypeError("Value is outside the 'unsigned long' 
      value range."); | 337             exceptionState.throwTypeError("Value is outside the 'unsigned long' 
      value range."); | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 390 | 360 | 
| 391     if (configuration == Clamp) | 361     if (configuration == Clamp) | 
| 392         return clampTo<uint32_t>(numberValue); | 362         return clampTo<uint32_t>(numberValue); | 
| 393 | 363 | 
| 394     if (std::isinf(numberValue)) | 364     if (std::isinf(numberValue)) | 
| 395         return 0; | 365         return 0; | 
| 396 | 366 | 
| 397     return numberObject->Uint32Value(); | 367     return numberObject->Uint32Value(); | 
| 398 } | 368 } | 
| 399 | 369 | 
| 400 uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 401 { |  | 
| 402     NonThrowableExceptionState exceptionState; |  | 
| 403     return toUInt32(isolate, value, NormalConversion, exceptionState); |  | 
| 404 } |  | 
| 405 |  | 
| 406 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
      nversionConfiguration configuration, ExceptionState& exceptionState) | 370 int64_t toInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, IntegerCo
      nversionConfiguration configuration, ExceptionState& exceptionState) | 
| 407 { | 371 { | 
| 408     ASSERT(!value->IsInt32()); | 372     ASSERT(!value->IsInt32()); | 
| 409 | 373 | 
| 410     v8::Local<v8::Number> numberObject; | 374     v8::Local<v8::Number> numberObject; | 
| 411     // Can the value be converted to a number? | 375     // Can the value be converted to a number? | 
| 412     v8::TryCatch block(isolate); | 376     v8::TryCatch block(isolate); | 
| 413     numberObject = value->ToNumber(isolate); | 377     numberObject = value->ToNumber(isolate); | 
| 414     if (block.HasCaught()) { | 378     if (block.HasCaught()) { | 
| 415         exceptionState.rethrowV8Exception(block.Exception()); | 379         exceptionState.rethrowV8Exception(block.Exception()); | 
| 416         return 0; | 380         return 0; | 
| 417     } | 381     } | 
| 418     ASSERT(!numberObject.IsEmpty()); | 382     ASSERT(!numberObject.IsEmpty()); | 
| 419 | 383 | 
| 420     double numberValue = numberObject->Value(); | 384     double numberValue = numberObject->Value(); | 
| 421 | 385 | 
| 422     if (configuration == EnforceRange) | 386     if (configuration == EnforceRange) | 
| 423         return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo
      ng", exceptionState); | 387         return enforceRange(numberValue, -kJSMaxInteger, kJSMaxInteger, "long lo
      ng", exceptionState); | 
| 424 | 388 | 
| 425     if (std::isnan(numberValue) || std::isinf(numberValue)) | 389     if (std::isnan(numberValue) || std::isinf(numberValue)) | 
| 426         return 0; | 390         return 0; | 
| 427 | 391 | 
| 428     // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 392     // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 
| 429     unsigned long long integer; | 393     unsigned long long integer; | 
| 430     doubleToInteger(numberValue, integer); | 394     doubleToInteger(numberValue, integer); | 
| 431     return integer; | 395     return integer; | 
| 432 } | 396 } | 
| 433 | 397 | 
| 434 int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 435 { |  | 
| 436     NonThrowableExceptionState exceptionState; |  | 
| 437     return toInt64(isolate, value, NormalConversion, exceptionState); |  | 
| 438 } |  | 
| 439 |  | 
| 440 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
      ConversionConfiguration configuration, ExceptionState& exceptionState) | 398 uint64_t toUInt64Slow(v8::Isolate* isolate, v8::Handle<v8::Value> value, Integer
      ConversionConfiguration configuration, ExceptionState& exceptionState) | 
| 441 { | 399 { | 
| 442     ASSERT(!value->IsUint32()); | 400     ASSERT(!value->IsUint32()); | 
| 443     if (value->IsInt32()) { | 401     if (value->IsInt32()) { | 
| 444         ASSERT(configuration != NormalConversion); | 402         ASSERT(configuration != NormalConversion); | 
| 445         int32_t result = value->Int32Value(); | 403         int32_t result = value->Int32Value(); | 
| 446         if (result >= 0) | 404         if (result >= 0) | 
| 447             return result; | 405             return result; | 
| 448         if (configuration == EnforceRange) { | 406         if (configuration == EnforceRange) { | 
| 449             exceptionState.throwTypeError("Value is outside the 'unsigned long l
      ong' value range."); | 407             exceptionState.throwTypeError("Value is outside the 'unsigned long l
      ong' value range."); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 476 | 434 | 
| 477     if (std::isinf(numberValue)) | 435     if (std::isinf(numberValue)) | 
| 478         return 0; | 436         return 0; | 
| 479 | 437 | 
| 480     // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 438     // NaNs and +/-Infinity should be 0, otherwise modulo 2^64. | 
| 481     unsigned long long integer; | 439     unsigned long long integer; | 
| 482     doubleToInteger(numberValue, integer); | 440     doubleToInteger(numberValue, integer); | 
| 483     return integer; | 441     return integer; | 
| 484 } | 442 } | 
| 485 | 443 | 
| 486 uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value) |  | 
| 487 { |  | 
| 488     NonThrowableExceptionState exceptionState; |  | 
| 489     return toUInt64(isolate, value, NormalConversion, exceptionState); |  | 
| 490 } |  | 
| 491 |  | 
| 492 float toRestrictedFloat(v8::Isolate* isolate, v8::Handle<v8::Value> value, Excep
      tionState& exceptionState) | 444 float toRestrictedFloat(v8::Isolate* isolate, v8::Handle<v8::Value> value, Excep
      tionState& exceptionState) | 
| 493 { | 445 { | 
| 494     float numberValue = toFloat(isolate, value, exceptionState); | 446     float numberValue = toFloat(isolate, value, exceptionState); | 
| 495     if (exceptionState.hadException()) | 447     if (exceptionState.hadException()) | 
| 496         return 0; | 448         return 0; | 
| 497     if (!std::isfinite(numberValue)) { | 449     if (!std::isfinite(numberValue)) { | 
| 498         exceptionState.throwTypeError("The provided float value is non-finite.")
      ; | 450         exceptionState.throwTypeError("The provided float value is non-finite.")
      ; | 
| 499         return 0; | 451         return 0; | 
| 500     } | 452     } | 
| 501     return numberValue; | 453     return numberValue; | 
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1025 { | 977 { | 
| 1026     v8ConstructorAttributeGetter(info); | 978     v8ConstructorAttributeGetter(info); | 
| 1027 } | 979 } | 
| 1028 | 980 | 
| 1029 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
      alue>& info) | 981 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
      alue>& info) | 
| 1030 { | 982 { | 
| 1031     v8ConstructorAttributeGetter(info); | 983     v8ConstructorAttributeGetter(info); | 
| 1032 } | 984 } | 
| 1033 | 985 | 
| 1034 } // namespace blink | 986 } // namespace blink | 
| OLD | NEW | 
|---|