Reviewers: Mads Ager,
Message:
Small review.
Description:
Added implementation if Uint32::Value.
Please review this at http://codereview.chromium.org/661275
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
cb97e7fdcf77c6fc899359a8bf36bba48cbd3169..ec00ded55144db79a9424cc34ceafbe9e417a9c5
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2728,6 +2728,17 @@ int32_t Int32::Value() const {
}
+uint32_t Uint32::Value() const {
+ if (IsDeadCheck("v8::Uint32::Value()")) return 0;
+ i::Handle<i::Object> obj = Utils::OpenHandle(this);
+ if (obj->IsSmi()) {
+ return i::Smi::cast(*obj)->value();
+ } else {
+ return static_cast<uint32_t>(obj->Number());
+ }
+}
+
+
int v8::Object::InternalFieldCount() {
if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0;
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
e1223c1dbd032892ddd2d0c24b68c6c970ebf90b..a6d8f3735b9d00bffb3ef82cb782e4c16dac9eab
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1947,6 +1947,55 @@ 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());
+ // 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());
+ // 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());
+ // 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());
+ // 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());
+ // 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());
+ // 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());
+}
+
+
+
THREADED_TEST(ConversionException) {
v8::HandleScope scope;
LocalContext env;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev