Modified: trunk/Source/WebCore/ChangeLog (146364 => 146365)
--- trunk/Source/WebCore/ChangeLog 2013-03-20 18:06:12 UTC (rev 146364)
+++ trunk/Source/WebCore/ChangeLog 2013-03-20 18:17:36 UTC (rev 146365)
@@ -1,3 +1,26 @@
+2013-03-20 Michael Pruett <mich...@68k.org>
+
+ [V8] Simplify implementation of EnforceRange conversions
+ https://bugs.webkit.org/show_bug.cgi?id=112758
+
+ Reviewed by Kentaro Hara.
+
+ Factor out EnforceRange conversion into a helper function.
+ Simplify calculation for truncation.
+
+ Tests: fast/js/webidl-type-mapping.html
+ storage/indexeddb/cursor-advance.html
+ storage/indexeddb/cursor-advance-workers.html
+ storage/indexeddb/intversion-bad-parameters.html
+
+ * bindings/v8/V8Binding.cpp:
+ (WebCore::enforceRange):
+ (WebCore):
+ (WebCore::toInt32):
+ (WebCore::toUInt32):
+ (WebCore::toInt64):
+ (WebCore::toUInt64):
+
2013-03-20 Harald Alvestrand <h...@google.com>
Remove Local/Remote and RTCStatsElement from WebRTCStats API
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (146364 => 146365)
--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2013-03-20 18:06:12 UTC (rev 146364)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2013-03-20 18:17:36 UTC (rev 146365)
@@ -108,6 +108,20 @@
const uint32_t kMaxUInt32 = 0xffffffff;
const int64_t kJSMaxInteger = 0x20000000000000LL - 1; // 2^53 - 1, maximum integer exactly representable in ECMAScript.
+static double enforceRange(double x, double minimum, double maximum, bool& ok)
+{
+ if (std::isnan(x) || std::isinf(x)) {
+ ok = false;
+ return 0;
+ }
+ x = trunc(x);
+ if (x < minimum || x > maximum) {
+ ok = false;
+ return 0;
+ }
+ return x;
+}
+
int32_t toInt32(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, bool& ok)
{
ok = true;
@@ -123,21 +137,9 @@
return 0;
}
- if (configuration == EnforceRange) {
- double x = numberObject->Value();
- if (std::isnan(x) || std::isinf(x)) {
- ok = false;
- return 0;
- }
- x = (x < 0 ? -1 : 1) * floor(fabs(x));
- if (x < kMinInt32 || x > kMaxInt32) {
- ok = false;
- return 0;
- }
+ if (configuration == EnforceRange)
+ return enforceRange(numberObject->Value(), kMinInt32, kMaxInt32, ok);
- return x;
- }
-
// Does the value convert to nan or to an infinity?
double numberValue = numberObject->Value();
if (std::isnan(numberValue) || std::isinf(numberValue))
@@ -172,21 +174,9 @@
return 0;
}
- if (configuration == EnforceRange) {
- double x = numberObject->Value();
- if (std::isnan(x) || std::isinf(x)) {
- ok = false;
- return 0;
- }
- x = (x < 0 ? -1 : 1) * floor(fabs(x));
- if (x < 0 || x > kMaxUInt32) {
- ok = false;
- return 0;
- }
+ if (configuration == EnforceRange)
+ return enforceRange(numberObject->Value(), 0, kMaxUInt32, ok);
- return x;
- }
-
// Does the value convert to nan or to an infinity?
double numberValue = numberObject->Value();
if (std::isnan(numberValue) || std::isinf(numberValue))
@@ -211,18 +201,8 @@
double x = numberObject->Value();
- if (configuration == EnforceRange) {
- if (std::isnan(x) || std::isinf(x)) {
- ok = false;
- return 0;
- }
- x = (x < 0 ? -1 : 1) * floor(fabs(x));
- if (x < -kJSMaxInteger || x > kJSMaxInteger) {
- ok = false;
- return 0;
- }
- return x;
- }
+ if (configuration == EnforceRange)
+ return enforceRange(x, -kJSMaxInteger, kJSMaxInteger, ok);
// NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
unsigned long long integer;
@@ -259,18 +239,8 @@
double x = numberObject->Value();
- if (configuration == EnforceRange) {
- if (std::isnan(x) || std::isinf(x)) {
- ok = false;
- return 0;
- }
- x = (x < 0 ? -1 : 1) * floor(fabs(x));
- if (x < 0 || x > kJSMaxInteger) {
- ok = false;
- return 0;
- }
- return x;
- }
+ if (configuration == EnforceRange)
+ return enforceRange(x, 0, kJSMaxInteger, ok);
// NaNs and +/-Infinity should be 0, otherwise modulo 2^64.
unsigned long long integer;