Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: test/cctest/test-api.cc

Issue 661275: Added implementation if Uint32::Value. (Closed)
Patch Set: Added IsUint32 Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/conversions-inl.h ('K') | « src/conversions-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index e1223c1dbd032892ddd2d0c24b68c6c970ebf90b..d5462af4f207583928aae3a5fc2ecb44f4912837 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1947,6 +1947,95 @@ static void CheckUncle(v8::TryCatch* try_catch) {
}
+THREADED_TEST(ConversionNumber) {
+ v8::HandleScope scope;
+ LocalContext env;
+ // Very large number.
+ CompileRun("var obj = Math.pow(2,32) * 1237;");
+ Local<Value> obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
+ CHECK_EQ(0, obj->ToInt32()->Value());
+ CHECK(0u == obj->ToUint32()->Value()); // NOLINT - no CHECK_EQ for unsigned.
+ // Large number.
+ CompileRun("var obj = -1234567890123;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
+ CHECK_EQ(-1912276171, obj->ToInt32()->Value());
+ CHECK(2382691125u == obj->ToUint32()->Value()); // NOLINT
+ // Small positive integer.
+ CompileRun("var obj = 42;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(42.0, obj->ToNumber()->Value());
+ CHECK_EQ(42, obj->ToInt32()->Value());
+ CHECK(42u == obj->ToUint32()->Value()); // NOLINT
+ // Negative integer.
+ CompileRun("var obj = -37;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(-37.0, obj->ToNumber()->Value());
+ CHECK_EQ(-37, obj->ToInt32()->Value());
+ CHECK(4294967259u == obj->ToUint32()->Value()); // NOLINT
+ // Positive non-int32 integer.
+ CompileRun("var obj = 0x81234567;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(2166572391.0, obj->ToNumber()->Value());
+ CHECK_EQ(-2128394905, obj->ToInt32()->Value());
+ CHECK(2166572391u == obj->ToUint32()->Value()); // NOLINT
+ // Fraction.
+ CompileRun("var obj = 42.3;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(42.3, obj->ToNumber()->Value());
+ CHECK_EQ(42, obj->ToInt32()->Value());
+ CHECK(42u == obj->ToUint32()->Value()); // NOLINT
+ // Large negative fraction.
+ CompileRun("var obj = -5726623061.75;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
+ CHECK_EQ(-1431655765, obj->ToInt32()->Value());
+ CHECK(2863311531u == obj->ToUint32()->Value()); // NOLINT
+}
+
+
+THREADED_TEST(isNumberType) {
+ v8::HandleScope scope;
+ LocalContext env;
+ // Very large number.
+ CompileRun("var obj = Math.pow(2,32) * 1237;");
+ Local<Value> obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(!obj->IsUint32());
+ // Large negative number.
+ CompileRun("var obj = -1234567890123;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(!obj->IsUint32());
+ // Small positive integer.
+ CompileRun("var obj = 42;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(obj->IsInt32());
+ CHECK(obj->IsUint32());
+ // Negative integer.
+ CompileRun("var obj = -37;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(obj->IsInt32());
+ CHECK(!obj->IsUint32());
+ // Positive non-int32 integer.
+ CompileRun("var obj = 0x81234567;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(obj->IsUint32());
+ // Fraction.
+ CompileRun("var obj = 42.3;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(!obj->IsUint32());
+ // Large negative fraction.
+ CompileRun("var obj = -5726623061.75;");
+ obj = env->Global()->Get(v8_str("obj"));
+ CHECK(!obj->IsInt32());
+ CHECK(!obj->IsUint32());
+}
+
+
THREADED_TEST(ConversionException) {
v8::HandleScope scope;
LocalContext env;
« src/conversions-inl.h ('K') | « src/conversions-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698