Reviewers: Mads Sig Ager,
Description:
Fix handling of -0.0 in IsInt32/IsUInt32
[email protected]
BUG=
TEST=
Please review this at http://codereview.chromium.org/9169009/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/api.cc
M test/cctest/test-api.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
ad655b6a25975859612b2c9fa4514d57c95d0656..8c17e62729b58ebc819a4979d5beea48aaa300d5
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -2165,6 +2165,11 @@ bool Value::IsInt32() const {
if (obj->IsSmi()) return true;
if (obj->IsNumber()) {
double value = obj->Number();
+ static const i::DoubleRepresentation minus_zero(-0.0);
+ i::DoubleRepresentation rep(value);
+ if (rep.bits == minus_zero.bits) {
+ return false;
+ }
return i::FastI2D(i::FastD2I(value)) == value;
}
return false;
@@ -2174,9 +2179,16 @@ bool Value::IsInt32() const {
bool Value::IsUint32() const {
if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return
false;
i::Handle<i::Object> obj = Utils::OpenHandle(this);
- if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
+ if (obj->IsSmi()) {
+ return i::Smi::cast(*obj)->value() >= 0;
+ }
if (obj->IsNumber()) {
double value = obj->Number();
+ static const i::DoubleRepresentation minus_zero(-0.0);
+ i::DoubleRepresentation rep(value);
+ if (rep.bits == minus_zero.bits) {
+ return false;
+ }
return i::FastUI2D(i::FastD2UI(value)) == value;
}
return false;
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
69d08b23e246d449dfb7b6e6aff2d33ebac6a4b8..0c191c34c810109d6fa15e115803e9478ff413cc
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1,4 +1,4 @@
-// Copyright 2011 the V8 project authors. All rights reserved.
+// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -2867,6 +2867,16 @@ THREADED_TEST(isNumberType) {
obj = env->Global()->Get(v8_str("obj"));
CHECK(!obj->IsInt32());
CHECK(!obj->IsUint32());
+ // Positive zero
+ CompileRun("var obj = 0.0;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(obj->IsInt32());
+ CHECK(obj->IsUint32());
+ // Positive zero
+ CompileRun("var obj = -0.0;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(!obj->IsUint32());
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev