From 3c8a79cabadeaa8c356b7789a8b621464d643b2d Mon Sep 17 00:00:00 2001 From: "dcarney@chromium.org" Date: Fri, 7 Jun 2013 07:34:25 +0000 Subject: [PATCH] ReturnValue::Set(uint32_t) is wrong R=svenpanne@chromium.org BUG= Review URL: https://codereview.chromium.org/16365008 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14990 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 4 ++-- test/cctest/test-api.cc | 37 +++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/v8.h b/include/v8.h index b270e76..32908fc 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5682,8 +5682,8 @@ void ReturnValue::Set(int32_t i) { template void ReturnValue::Set(uint32_t i) { typedef internal::Internals I; - if (V8_LIKELY(I::IsValidSmi(i))) { - *value_ = I::IntToSmi(i); + if (V8_LIKELY(i <= INT32_MAX)) { + Set(static_cast(i)); return; } Set(Integer::NewFromUnsigned(i, GetIsolate())); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index d514b1e..22b9378 100755 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -1025,8 +1025,8 @@ template void FastReturnValueCallback(const v8::FunctionCallbackInfo& info); // constant return values -static const int32_t kFastReturnValueInt32 = 471; -static const uint32_t kFastReturnValueUint32 = 571; +static int32_t fast_return_value_int32 = 471; +static uint32_t fast_return_value_uint32 = 571; static const double kFastReturnValueDouble = 2.7; // variable return values static bool fast_return_value_bool = false; @@ -1037,14 +1037,14 @@ template<> void FastReturnValueCallback( const v8::FunctionCallbackInfo& info) { CheckReturnValue(info); - info.GetReturnValue().Set(kFastReturnValueInt32); + info.GetReturnValue().Set(fast_return_value_int32); } template<> void FastReturnValueCallback( const v8::FunctionCallbackInfo& info) { CheckReturnValue(info); - info.GetReturnValue().Set(kFastReturnValueUint32); + info.GetReturnValue().Set(fast_return_value_uint32); } template<> @@ -1093,16 +1093,29 @@ Handle TestFastReturnValues() { } THREADED_TEST(FastReturnValues) { + LocalContext env; v8::HandleScope scope(v8::Isolate::GetCurrent()); v8::Handle value; - // check int_32 - value = TestFastReturnValues(); - CHECK(value->IsInt32()); - CHECK_EQ(kFastReturnValueInt32, value->Int32Value()); - // check uint32_t - value = TestFastReturnValues(); - CHECK(value->IsInt32()); - CHECK_EQ(kFastReturnValueUint32, value->Int32Value()); + // check int32_t and uint32_t + int32_t int_values[] = { + 0, 234, -723, + i::Smi::kMinValue, i::Smi::kMaxValue, INT32_MAX, INT32_MIN + }; + for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) { + for (int modifier = -1; modifier <= 1; modifier++) { + int int_value = int_values[i] + modifier; + // check int32_t + fast_return_value_int32 = int_value; + value = TestFastReturnValues(); + CHECK(value->IsInt32()); + CHECK(fast_return_value_int32 == value->Int32Value()); + // check uint32_t + fast_return_value_uint32 = static_cast(int_value); + value = TestFastReturnValues(); + CHECK(value->IsUint32()); + CHECK(fast_return_value_uint32 == value->Uint32Value()); + } + } // check double value = TestFastReturnValues(); CHECK(value->IsNumber()); -- 2.7.4