Chromium Code Reviews| 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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 // Convert a value to a 32-bit integer assuming the conversion cannot fail. | 429 // Convert a value to a 32-bit integer assuming the conversion cannot fail. |
| 430 int32_t toInt32(v8::Handle<v8::Value>); | 430 int32_t toInt32(v8::Handle<v8::Value>); |
| 431 | 431 |
| 432 // Convert a value to a 32-bit unsigned integer. The conversion fails if the | 432 // Convert a value to a 32-bit unsigned integer. The conversion fails if the |
| 433 // value cannot be converted to a number or the range violated per WebIDL: | 433 // value cannot be converted to a number or the range violated per WebIDL: |
| 434 // http://www.w3.org/TR/WebIDL/#es-unsigned-long | 434 // http://www.w3.org/TR/WebIDL/#es-unsigned-long |
| 435 uint32_t toUInt32Slow(v8::Handle<v8::Value>, IntegerConversionConfiguration, Exc eptionState&); | 435 uint32_t toUInt32Slow(v8::Handle<v8::Value>, IntegerConversionConfiguration, Exc eptionState&); |
| 436 inline uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfigura tion configuration, ExceptionState& exceptionState) | 436 inline uint32_t toUInt32(v8::Handle<v8::Value> value, IntegerConversionConfigura tion configuration, ExceptionState& exceptionState) |
| 437 { | 437 { |
| 438 // Fast case. The value is already a 32-bit unsigned integer. | 438 // Fast case. The value is already a 32-bit unsigned integer. |
| 439 if (value->IsUint32()) | 439 if (value->IsUint32()) { |
|
bashi
2015/03/11 10:30:37
Now this doesn't look 'fast case'. Should we remov
Jens Widell
2015/03/11 10:56:37
We might want to investigate the performance impac
Yuki
2015/03/11 13:11:53
This reminds me of the following comment on an iss
| |
| 440 return value->Uint32Value(); | 440 uint32_t result; |
| 441 if (!getValueFromMaybe(value->Uint32Value(exceptionState.isolate()->GetC urrentContext()), result)) { | |
| 442 exceptionState.throwTypeError("Cannot convert to a 32 bit unsigned i nteger."); | |
| 443 return 0; | |
| 444 } | |
| 445 return result; | |
| 446 } | |
| 441 | 447 |
| 442 // Fast case. The value is a 32-bit signed integer with NormalConversion con figuration. | 448 // Fast case. The value is a 32-bit signed integer with NormalConversion con figuration. |
| 443 if (value->IsInt32() && configuration == NormalConversion) | 449 if (value->IsInt32() && configuration == NormalConversion) { |
| 444 return value->Int32Value(); | 450 int32_t result; |
| 451 if (!getValueFromMaybe(value->Int32Value(exceptionState.isolate()->GetCu rrentContext()), result)) { | |
| 452 exceptionState.throwTypeError("Cannot convert to a 32 bit integer.") ; | |
| 453 return 0; | |
| 454 } | |
| 455 return result; | |
| 456 } | |
| 445 | 457 |
| 446 return toUInt32Slow(value, configuration, exceptionState); | 458 return toUInt32Slow(value, configuration, exceptionState); |
| 447 } | 459 } |
| 448 | 460 |
| 449 inline uint32_t toUInt32(v8::Handle<v8::Value> value, ExceptionState& exceptionS tate) | 461 inline uint32_t toUInt32(v8::Handle<v8::Value> value, ExceptionState& exceptionS tate) |
| 450 { | 462 { |
| 451 return toUInt32(value, NormalConversion, exceptionState); | 463 return toUInt32(value, NormalConversion, exceptionState); |
| 452 } | 464 } |
| 453 | 465 |
| 454 // Convert a value to a 32-bit unsigned integer assuming the conversion cannot f ail. | 466 // Convert a value to a 32-bit unsigned integer assuming the conversion cannot f ail. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 477 | 489 |
| 478 // Convert a value to a 64-bit unsigned integer assuming the conversion cannot f ail. | 490 // Convert a value to a 64-bit unsigned integer assuming the conversion cannot f ail. |
| 479 uint64_t toUInt64(v8::Handle<v8::Value>); | 491 uint64_t toUInt64(v8::Handle<v8::Value>); |
| 480 | 492 |
| 481 // Convert a value to a double precision float, which might fail. | 493 // Convert a value to a double precision float, which might fail. |
| 482 double toDoubleSlow(v8::Handle<v8::Value>, ExceptionState&); | 494 double toDoubleSlow(v8::Handle<v8::Value>, ExceptionState&); |
| 483 | 495 |
| 484 inline double toDouble(v8::Handle<v8::Value> value, ExceptionState& exceptionSta te) | 496 inline double toDouble(v8::Handle<v8::Value> value, ExceptionState& exceptionSta te) |
| 485 { | 497 { |
| 486 if (value->IsNumber()) | 498 if (value->IsNumber()) |
| 487 return value->NumberValue(); | 499 return value.As<v8::Number>()->Value(); |
| 488 return toDoubleSlow(value, exceptionState); | 500 return toDoubleSlow(value, exceptionState); |
| 489 } | 501 } |
| 490 | 502 |
| 491 // Convert a value to a double precision float, throwing on non-finite values. | 503 // Convert a value to a double precision float, throwing on non-finite values. |
| 492 double toRestrictedDouble(v8::Handle<v8::Value>, ExceptionState&); | 504 double toRestrictedDouble(v8::Handle<v8::Value>, ExceptionState&); |
| 493 | 505 |
| 494 // Convert a value to a single precision float, which might fail. | 506 // Convert a value to a single precision float, which might fail. |
| 495 inline float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState ) | 507 inline float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState ) |
| 496 { | 508 { |
| 497 return static_cast<float>(toDouble(value, exceptionState)); | 509 return static_cast<float>(toDouble(value, exceptionState)); |
| 498 } | 510 } |
| 499 | 511 |
| 500 // Convert a value to a single precision float, throwing on non-finite values. | 512 // Convert a value to a single precision float, throwing on non-finite values. |
| 501 float toRestrictedFloat(v8::Handle<v8::Value>, ExceptionState&); | 513 float toRestrictedFloat(v8::Handle<v8::Value>, ExceptionState&); |
| 502 | 514 |
| 503 // Converts a value to a String, throwing if any code unit is outside 0-255. | 515 // Converts a value to a String, throwing if any code unit is outside 0-255. |
| 504 String toByteString(v8::Handle<v8::Value>, ExceptionState&); | 516 String toByteString(v8::Handle<v8::Value>, ExceptionState&); |
| 505 | 517 |
| 506 // Converts a value to a String, replacing unmatched UTF-16 surrogates with repl acement characters. | 518 // Converts a value to a String, replacing unmatched UTF-16 surrogates with repl acement characters. |
| 507 String toUSVString(v8::Handle<v8::Value>, ExceptionState&); | 519 String toUSVString(v8::Handle<v8::Value>, ExceptionState&); |
| 508 | 520 |
| 509 inline v8::Handle<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) | 521 inline v8::Handle<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) |
| 510 { | 522 { |
| 511 return value ? v8::True(isolate) : v8::False(isolate); | 523 return value ? v8::True(isolate) : v8::False(isolate); |
| 512 } | 524 } |
| 513 | 525 |
| 514 inline double toCoreDate(v8::Handle<v8::Value> object) | 526 inline double toCoreDate(v8::Handle<v8::Value> object) |
| 515 { | 527 { |
| 516 if (object->IsDate()) | 528 if (object->IsDate()) |
| 517 return v8::Handle<v8::Date>::Cast(object)->ValueOf(); | 529 return object.As<v8::Date>()->ValueOf(); |
| 518 if (object->IsNumber()) | 530 if (object->IsNumber()) |
| 519 return object->NumberValue(); | 531 return object.As<v8::Number>()->Value(); |
| 520 return std::numeric_limits<double>::quiet_NaN(); | 532 return std::numeric_limits<double>::quiet_NaN(); |
| 521 } | 533 } |
| 522 | 534 |
| 523 inline v8::Handle<v8::Value> v8DateOrNaN(double value, v8::Isolate* isolate) | 535 inline v8::Handle<v8::Value> v8DateOrNaN(double value, v8::Isolate* isolate) |
| 524 { | 536 { |
| 525 ASSERT(isolate); | 537 ASSERT(isolate); |
| 526 return v8::Date::New(isolate, std::isfinite(value) ? value : std::numeric_li mits<double>::quiet_NaN()); | 538 return v8::Date::New(isolate, std::isfinite(value) ? value : std::numeric_li mits<double>::quiet_NaN()); |
| 527 } | 539 } |
| 528 | 540 |
| 529 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. | 541 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 | 1035 |
| 1024 // Callback functions used by generated code. | 1036 // Callback functions used by generated code. |
| 1025 void v8ConstructorAttributeGetterAsProperty(v8::Local<v8::String> propertyName, const v8::PropertyCallbackInfo<v8::Value>&); | 1037 void v8ConstructorAttributeGetterAsProperty(v8::Local<v8::String> propertyName, const v8::PropertyCallbackInfo<v8::Value>&); |
| 1026 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>&); | 1038 void v8ConstructorAttributeGetterAsAccessor(const v8::FunctionCallbackInfo<v8::V alue>&); |
| 1027 | 1039 |
| 1028 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso late*); | 1040 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso late*); |
| 1029 | 1041 |
| 1030 } // namespace blink | 1042 } // namespace blink |
| 1031 | 1043 |
| 1032 #endif // V8Binding_h | 1044 #endif // V8Binding_h |
| OLD | NEW |