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

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

Issue 16365008: ReturnValue::Set(uint32_t) is wrong (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « include/v8.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 TestSimpleCallback(SimpleDirectCallback); 1018 TestSimpleCallback(SimpleDirectCallback);
1019 TestSimpleCallback(SimpleIndirectCallback); 1019 TestSimpleCallback(SimpleIndirectCallback);
1020 TestSimpleCallback(SimpleCallback); 1020 TestSimpleCallback(SimpleCallback);
1021 } 1021 }
1022 1022
1023 1023
1024 template<typename T> 1024 template<typename T>
1025 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); 1025 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
1026 1026
1027 // constant return values 1027 // constant return values
1028 static const int32_t kFastReturnValueInt32 = 471; 1028 static int32_t fast_return_value_int32 = 471;
1029 static const uint32_t kFastReturnValueUint32 = 571; 1029 static uint32_t fast_return_value_uint32 = 571;
1030 static const double kFastReturnValueDouble = 2.7; 1030 static const double kFastReturnValueDouble = 2.7;
1031 // variable return values 1031 // variable return values
1032 static bool fast_return_value_bool = false; 1032 static bool fast_return_value_bool = false;
1033 static bool fast_return_value_void_is_null = false; 1033 static bool fast_return_value_void_is_null = false;
1034 static bool fast_return_value_object_is_empty = false; 1034 static bool fast_return_value_object_is_empty = false;
1035 1035
1036 template<> 1036 template<>
1037 void FastReturnValueCallback<int32_t>( 1037 void FastReturnValueCallback<int32_t>(
1038 const v8::FunctionCallbackInfo<v8::Value>& info) { 1038 const v8::FunctionCallbackInfo<v8::Value>& info) {
1039 CheckReturnValue(info); 1039 CheckReturnValue(info);
1040 info.GetReturnValue().Set(kFastReturnValueInt32); 1040 info.GetReturnValue().Set(fast_return_value_int32);
1041 } 1041 }
1042 1042
1043 template<> 1043 template<>
1044 void FastReturnValueCallback<uint32_t>( 1044 void FastReturnValueCallback<uint32_t>(
1045 const v8::FunctionCallbackInfo<v8::Value>& info) { 1045 const v8::FunctionCallbackInfo<v8::Value>& info) {
1046 CheckReturnValue(info); 1046 CheckReturnValue(info);
1047 info.GetReturnValue().Set(kFastReturnValueUint32); 1047 info.GetReturnValue().Set(fast_return_value_uint32);
1048 } 1048 }
1049 1049
1050 template<> 1050 template<>
1051 void FastReturnValueCallback<double>( 1051 void FastReturnValueCallback<double>(
1052 const v8::FunctionCallbackInfo<v8::Value>& info) { 1052 const v8::FunctionCallbackInfo<v8::Value>& info) {
1053 CheckReturnValue(info); 1053 CheckReturnValue(info);
1054 info.GetReturnValue().Set(kFastReturnValueDouble); 1054 info.GetReturnValue().Set(kFastReturnValueDouble);
1055 } 1055 }
1056 1056
1057 template<> 1057 template<>
(...skipping 28 matching lines...) Expand all
1086 v8::HandleScope scope(env->GetIsolate()); 1086 v8::HandleScope scope(env->GetIsolate());
1087 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1087 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1088 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1088 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1089 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1089 object_template->Set("callback", v8::FunctionTemplate::New(callback));
1090 v8::Local<v8::Object> object = object_template->NewInstance(); 1090 v8::Local<v8::Object> object = object_template->NewInstance();
1091 (*env)->Global()->Set(v8_str("callback_object"), object); 1091 (*env)->Global()->Set(v8_str("callback_object"), object);
1092 return scope.Close(CompileRun("callback_object.callback()")); 1092 return scope.Close(CompileRun("callback_object.callback()"));
1093 } 1093 }
1094 1094
1095 THREADED_TEST(FastReturnValues) { 1095 THREADED_TEST(FastReturnValues) {
1096 LocalContext env;
1096 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1097 v8::HandleScope scope(v8::Isolate::GetCurrent());
1097 v8::Handle<v8::Value> value; 1098 v8::Handle<v8::Value> value;
1098 // check int_32 1099 // check int32_t and uint32_t
1099 value = TestFastReturnValues<int32_t>(); 1100 int32_t int_values[] = {
1100 CHECK(value->IsInt32()); 1101 0, 234, -723,
1101 CHECK_EQ(kFastReturnValueInt32, value->Int32Value()); 1102 i::Smi::kMinValue, i::Smi::kMaxValue, INT32_MAX, INT32_MIN
1102 // check uint32_t 1103 };
1103 value = TestFastReturnValues<uint32_t>(); 1104 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) {
1104 CHECK(value->IsInt32()); 1105 for (int modifier = -1; modifier <= 1; modifier++) {
1105 CHECK_EQ(kFastReturnValueUint32, value->Int32Value()); 1106 int int_value = int_values[i] + modifier;
1107 // check int32_t
1108 fast_return_value_int32 = int_value;
1109 value = TestFastReturnValues<int32_t>();
1110 CHECK(value->IsInt32());
1111 CHECK(fast_return_value_int32 == value->Int32Value());
1112 // check uint32_t
1113 fast_return_value_uint32 = static_cast<uint32_t>(int_value);
1114 value = TestFastReturnValues<uint32_t>();
1115 CHECK(value->IsUint32());
1116 CHECK(fast_return_value_uint32 == value->Uint32Value());
1117 }
1118 }
1106 // check double 1119 // check double
1107 value = TestFastReturnValues<double>(); 1120 value = TestFastReturnValues<double>();
1108 CHECK(value->IsNumber()); 1121 CHECK(value->IsNumber());
1109 CHECK_EQ(kFastReturnValueDouble, value->ToNumber()->Value()); 1122 CHECK_EQ(kFastReturnValueDouble, value->ToNumber()->Value());
1110 // check bool values 1123 // check bool values
1111 for (int i = 0; i < 2; i++) { 1124 for (int i = 0; i < 2; i++) {
1112 fast_return_value_bool = i == 0; 1125 fast_return_value_bool = i == 0;
1113 value = TestFastReturnValues<bool>(); 1126 value = TestFastReturnValues<bool>();
1114 CHECK(value->IsBoolean()); 1127 CHECK(value->IsBoolean());
1115 CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value()); 1128 CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value());
(...skipping 18037 matching lines...) Expand 10 before | Expand all | Expand 10 after
19153 i::Semaphore* sem_; 19166 i::Semaphore* sem_;
19154 volatile int sem_value_; 19167 volatile int sem_value_;
19155 }; 19168 };
19156 19169
19157 19170
19158 THREADED_TEST(SemaphoreInterruption) { 19171 THREADED_TEST(SemaphoreInterruption) {
19159 ThreadInterruptTest().RunTest(); 19172 ThreadInterruptTest().RunTest();
19160 } 19173 }
19161 19174
19162 #endif // WIN32 19175 #endif // WIN32
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698