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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 doubleToInteger(numberValue, integer); | 444 doubleToInteger(numberValue, integer); |
445 return integer; | 445 return integer; |
446 } | 446 } |
447 | 447 |
448 int64_t toInt64(v8::Handle<v8::Value> value) | 448 int64_t toInt64(v8::Handle<v8::Value> value) |
449 { | 449 { |
450 NonThrowableExceptionState exceptionState; | 450 NonThrowableExceptionState exceptionState; |
451 return toInt64(value, NormalConversion, exceptionState); | 451 return toInt64(value, NormalConversion, exceptionState); |
452 } | 452 } |
453 | 453 |
454 uint64_t toUInt64(v8::Handle<v8::Value> value, IntegerConversionConfiguration co
nfiguration, ExceptionState& exceptionState) | 454 uint64_t toUInt64Slow(v8::Handle<v8::Value> value, IntegerConversionConfiguratio
n configuration, ExceptionState& exceptionState) |
455 { | 455 { |
456 // Fast case. The value is a 32-bit unsigned integer. | 456 ASSERT(!value->IsUint32()); |
457 if (value->IsUint32()) | |
458 return value->Uint32Value(); | |
459 | |
460 // Fast case. The value is a 32-bit integer. | |
461 if (value->IsInt32()) { | 457 if (value->IsInt32()) { |
| 458 ASSERT(configuration != NormalConversion); |
462 int32_t result = value->Int32Value(); | 459 int32_t result = value->Int32Value(); |
463 if (result >= 0) | 460 if (result >= 0) |
464 return result; | 461 return result; |
465 if (configuration == EnforceRange) { | 462 if (configuration == EnforceRange) { |
466 exceptionState.throwTypeError("Value is outside the 'unsigned long l
ong' value range."); | 463 exceptionState.throwTypeError("Value is outside the 'unsigned long l
ong' value range."); |
467 return 0; | 464 return 0; |
468 } | 465 } |
469 if (configuration == Clamp) | 466 ASSERT(configuration == Clamp); |
470 return clampTo<uint64_t>(result); | 467 return clampTo<uint64_t>(result); |
471 return result; | |
472 } | 468 } |
473 | 469 |
474 v8::Local<v8::Number> numberObject; | 470 v8::Local<v8::Number> numberObject; |
475 if (value->IsNumber()) { | 471 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
476 numberObject = value.As<v8::Number>(); | 472 // Can the value be converted to a number? |
477 } else { | 473 v8::TryCatch block(isolate); |
478 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 474 numberObject = value->ToNumber(isolate); |
479 // Can the value be converted to a number? | 475 if (block.HasCaught()) { |
480 v8::TryCatch block(isolate); | 476 exceptionState.rethrowV8Exception(block.Exception()); |
481 numberObject = value->ToNumber(isolate); | 477 return 0; |
482 if (block.HasCaught()) { | |
483 exceptionState.rethrowV8Exception(block.Exception()); | |
484 return 0; | |
485 } | |
486 } | 478 } |
487 ASSERT(!numberObject.IsEmpty()); | 479 ASSERT(!numberObject.IsEmpty()); |
488 | 480 |
489 double numberValue = numberObject->Value(); | 481 double numberValue = numberObject->Value(); |
490 | 482 |
491 if (configuration == EnforceRange) | 483 if (configuration == EnforceRange) |
492 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long",
exceptionState); | 484 return enforceRange(numberValue, 0, kJSMaxInteger, "unsigned long long",
exceptionState); |
493 | 485 |
494 if (std::isnan(numberValue)) | 486 if (std::isnan(numberValue)) |
495 return 0; | 487 return 0; |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 { | 1043 { |
1052 v8ConstructorAttributeGetter(info); | 1044 v8ConstructorAttributeGetter(info); |
1053 } | 1045 } |
1054 | 1046 |
1055 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
alue>& info) | 1047 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V
alue>& info) |
1056 { | 1048 { |
1057 v8ConstructorAttributeGetter(info); | 1049 v8ConstructorAttributeGetter(info); |
1058 } | 1050 } |
1059 | 1051 |
1060 } // namespace blink | 1052 } // namespace blink |
OLD | NEW |