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

Side by Side Diff: test/cctest/test-api.cc

Issue 661275: Added implementation if Uint32::Value. (Closed)
Patch Set: Added IsUint32 Created 10 years, 9 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 unified diff | Download patch
« src/conversions-inl.h ('K') | « src/conversions-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 1940
1941 1941
1942 static void CheckUncle(v8::TryCatch* try_catch) { 1942 static void CheckUncle(v8::TryCatch* try_catch) {
1943 CHECK(try_catch->HasCaught()); 1943 CHECK(try_catch->HasCaught());
1944 String::AsciiValue str_value(try_catch->Exception()); 1944 String::AsciiValue str_value(try_catch->Exception());
1945 CHECK_EQ(*str_value, "uncle?"); 1945 CHECK_EQ(*str_value, "uncle?");
1946 try_catch->Reset(); 1946 try_catch->Reset();
1947 } 1947 }
1948 1948
1949 1949
1950 THREADED_TEST(ConversionNumber) {
1951 v8::HandleScope scope;
1952 LocalContext env;
1953 // Very large number.
1954 CompileRun("var obj = Math.pow(2,32) * 1237;");
1955 Local<Value> obj = env->Global()->Get(v8_str("obj"));
1956 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
1957 CHECK_EQ(0, obj->ToInt32()->Value());
1958 CHECK(0u == obj->ToUint32()->Value()); // NOLINT - no CHECK_EQ for unsigned.
1959 // Large number.
1960 CompileRun("var obj = -1234567890123;");
1961 obj = env->Global()->Get(v8_str("obj"));
1962 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
1963 CHECK_EQ(-1912276171, obj->ToInt32()->Value());
1964 CHECK(2382691125u == obj->ToUint32()->Value()); // NOLINT
1965 // Small positive integer.
1966 CompileRun("var obj = 42;");
1967 obj = env->Global()->Get(v8_str("obj"));
1968 CHECK_EQ(42.0, obj->ToNumber()->Value());
1969 CHECK_EQ(42, obj->ToInt32()->Value());
1970 CHECK(42u == obj->ToUint32()->Value()); // NOLINT
1971 // Negative integer.
1972 CompileRun("var obj = -37;");
1973 obj = env->Global()->Get(v8_str("obj"));
1974 CHECK_EQ(-37.0, obj->ToNumber()->Value());
1975 CHECK_EQ(-37, obj->ToInt32()->Value());
1976 CHECK(4294967259u == obj->ToUint32()->Value()); // NOLINT
1977 // Positive non-int32 integer.
1978 CompileRun("var obj = 0x81234567;");
1979 obj = env->Global()->Get(v8_str("obj"));
1980 CHECK_EQ(2166572391.0, obj->ToNumber()->Value());
1981 CHECK_EQ(-2128394905, obj->ToInt32()->Value());
1982 CHECK(2166572391u == obj->ToUint32()->Value()); // NOLINT
1983 // Fraction.
1984 CompileRun("var obj = 42.3;");
1985 obj = env->Global()->Get(v8_str("obj"));
1986 CHECK_EQ(42.3, obj->ToNumber()->Value());
1987 CHECK_EQ(42, obj->ToInt32()->Value());
1988 CHECK(42u == obj->ToUint32()->Value()); // NOLINT
1989 // Large negative fraction.
1990 CompileRun("var obj = -5726623061.75;");
1991 obj = env->Global()->Get(v8_str("obj"));
1992 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
1993 CHECK_EQ(-1431655765, obj->ToInt32()->Value());
1994 CHECK(2863311531u == obj->ToUint32()->Value()); // NOLINT
1995 }
1996
1997
1998 THREADED_TEST(isNumberType) {
1999 v8::HandleScope scope;
2000 LocalContext env;
2001 // Very large number.
2002 CompileRun("var obj = Math.pow(2,32) * 1237;");
2003 Local<Value> obj = env->Global()->Get(v8_str("obj"));
2004 CHECK(!obj->IsInt32());
2005 CHECK(!obj->IsUint32());
2006 // Large negative number.
2007 CompileRun("var obj = -1234567890123;");
2008 obj = env->Global()->Get(v8_str("obj"));
2009 CHECK(!obj->IsInt32());
2010 CHECK(!obj->IsUint32());
2011 // Small positive integer.
2012 CompileRun("var obj = 42;");
2013 obj = env->Global()->Get(v8_str("obj"));
2014 CHECK(obj->IsInt32());
2015 CHECK(obj->IsUint32());
2016 // Negative integer.
2017 CompileRun("var obj = -37;");
2018 obj = env->Global()->Get(v8_str("obj"));
2019 CHECK(obj->IsInt32());
2020 CHECK(!obj->IsUint32());
2021 // Positive non-int32 integer.
2022 CompileRun("var obj = 0x81234567;");
2023 obj = env->Global()->Get(v8_str("obj"));
2024 CHECK(!obj->IsInt32());
2025 CHECK(obj->IsUint32());
2026 // Fraction.
2027 CompileRun("var obj = 42.3;");
2028 obj = env->Global()->Get(v8_str("obj"));
2029 CHECK(!obj->IsInt32());
2030 CHECK(!obj->IsUint32());
2031 // Large negative fraction.
2032 CompileRun("var obj = -5726623061.75;");
2033 obj = env->Global()->Get(v8_str("obj"));
2034 CHECK(!obj->IsInt32());
2035 CHECK(!obj->IsUint32());
2036 }
2037
2038
1950 THREADED_TEST(ConversionException) { 2039 THREADED_TEST(ConversionException) {
1951 v8::HandleScope scope; 2040 v8::HandleScope scope;
1952 LocalContext env; 2041 LocalContext env;
1953 CompileRun( 2042 CompileRun(
1954 "function TestClass() { };" 2043 "function TestClass() { };"
1955 "TestClass.prototype.toString = function () { throw 'uncle?'; };" 2044 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
1956 "var obj = new TestClass();"); 2045 "var obj = new TestClass();");
1957 Local<Value> obj = env->Global()->Get(v8_str("obj")); 2046 Local<Value> obj = env->Global()->Get(v8_str("obj"));
1958 2047
1959 v8::TryCatch try_catch; 2048 v8::TryCatch try_catch;
(...skipping 7844 matching lines...) Expand 10 before | Expand all | Expand 10 after
9804 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 9893 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value());
9805 } 9894 }
9806 9895
9807 script = v8::Script::Compile(v8_str("new C2();")); 9896 script = v8::Script::Compile(v8_str("new C2();"));
9808 for (int i = 0; i < 10; i++) { 9897 for (int i = 0; i < 10; i++) {
9809 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 9898 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
9810 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); 9899 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value());
9811 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); 9900 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value());
9812 } 9901 }
9813 } 9902 }
OLDNEW
« 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