Commit 69fabd05 authored by Michaël Zasso's avatar Michaël Zasso Committed by Commit Bot

[api] Add tests for Integer type

Since there is no `Value::IsInteger` method in the API, we in the
Node.js project are going to rely on what looks like an implementation
detail of the Integer class. It is currently possible to to call
`Integer::Value` on any Number and the value is cast to an integer.
This commit adds tests for this behavior.

Change-Id: I4de09e7c6e0beac7909e5477f7bfe2ed4c9415b9
Reviewed-on: https://chromium-review.googlesource.com/1200983
Commit-Queue: Michaël Zasso <mic.besace@gmail.com>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55629}
parent 66604f2e
......@@ -5656,13 +5656,44 @@ THREADED_TEST(isNumberType) {
obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
CHECK(obj->IsInt32());
CHECK(obj->IsUint32());
// Positive zero
// Negative zero
CompileRun("var obj = -0.0;");
obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
CHECK(!obj->IsInt32());
CHECK(!obj->IsUint32());
}
THREADED_TEST(IntegerType) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
Local<Value> result;
// Small positive integer
result = CompileRun("42;");
CHECK(result->IsNumber());
CHECK_EQ(42, result.As<v8::Integer>()->Value());
// Small negative integer
result = CompileRun("-42;");
CHECK(result->IsNumber());
CHECK_EQ(-42, result.As<v8::Integer>()->Value());
// Positive non-int32 integer
result = CompileRun("1099511627776;");
CHECK(result->IsNumber());
CHECK_EQ(1099511627776, result.As<v8::Integer>()->Value());
// Negative non-int32 integer
result = CompileRun("-1099511627776;");
CHECK(result->IsNumber());
CHECK_EQ(-1099511627776, result.As<v8::Integer>()->Value());
// Positive non-integer
result = CompileRun("3.14;");
CHECK(result->IsNumber());
CHECK_EQ(3, result.As<v8::Integer>()->Value());
// Negative non-integer
result = CompileRun("-3.14;");
CHECK(result->IsNumber());
CHECK_EQ(-3, result.As<v8::Integer>()->Value());
}
static void CheckUncle(v8::Isolate* isolate, v8::TryCatch* try_catch) {
CHECK(try_catch->HasCaught());
String::Utf8Value str_value(isolate, try_catch->Exception());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment