OLD | NEW |
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 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 } | 1003 } |
1004 | 1004 |
1005 | 1005 |
1006 THREADED_TEST(SimpleCallback) { | 1006 THREADED_TEST(SimpleCallback) { |
1007 TestSimpleCallback(SimpleDirectCallback); | 1007 TestSimpleCallback(SimpleDirectCallback); |
1008 TestSimpleCallback(SimpleIndirectCallback); | 1008 TestSimpleCallback(SimpleIndirectCallback); |
1009 TestSimpleCallback(SimpleCallback); | 1009 TestSimpleCallback(SimpleCallback); |
1010 } | 1010 } |
1011 | 1011 |
1012 | 1012 |
| 1013 template<typename T> |
| 1014 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); |
| 1015 |
| 1016 // constant return values |
| 1017 static const int32_t kFastReturnValueInt32 = 471; |
| 1018 static const uint32_t kFastReturnValueUint32 = 571; |
| 1019 static const double kFastReturnValueDouble = 2.7; |
| 1020 // variable return values |
| 1021 static bool fast_return_value_bool = false; |
| 1022 static bool fast_return_value_void_is_null = false; |
| 1023 |
| 1024 template<> |
| 1025 void FastReturnValueCallback<int32_t>( |
| 1026 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1027 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueInt32); |
| 1028 } |
| 1029 |
| 1030 template<> |
| 1031 void FastReturnValueCallback<uint32_t>( |
| 1032 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1033 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueUint32); |
| 1034 } |
| 1035 |
| 1036 template<> |
| 1037 void FastReturnValueCallback<double>( |
| 1038 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1039 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueDouble); |
| 1040 } |
| 1041 |
| 1042 template<> |
| 1043 void FastReturnValueCallback<bool>( |
| 1044 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1045 info.GetReturnValue().Set(info.GetIsolate(), fast_return_value_bool); |
| 1046 } |
| 1047 |
| 1048 template<> |
| 1049 void FastReturnValueCallback<void>( |
| 1050 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1051 if (fast_return_value_void_is_null) { |
| 1052 info.GetReturnValue().SetNull(info.GetIsolate()); |
| 1053 } else { |
| 1054 info.GetReturnValue().SetUndefined(info.GetIsolate()); |
| 1055 } |
| 1056 } |
| 1057 |
| 1058 template<typename T> |
| 1059 Handle<Value> TestFastReturnValues() { |
| 1060 LocalContext env; |
| 1061 v8::HandleScope scope(env->GetIsolate()); |
| 1062 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
| 1063 v8::FunctionCallback callback = &FastReturnValueCallback<T>; |
| 1064 object_template->Set("callback", v8::FunctionTemplate::New(callback)); |
| 1065 v8::Local<v8::Object> object = object_template->NewInstance(); |
| 1066 (*env)->Global()->Set(v8_str("callback_object"), object); |
| 1067 return scope.Close(CompileRun("callback_object.callback()")); |
| 1068 } |
| 1069 |
| 1070 THREADED_TEST(FastReturnValues) { |
| 1071 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 1072 v8::Handle<v8::Value> value; |
| 1073 // check int_32 |
| 1074 value = TestFastReturnValues<int32_t>(); |
| 1075 CHECK(value->IsInt32()); |
| 1076 CHECK_EQ(kFastReturnValueInt32, value->Int32Value()); |
| 1077 // check uint32_t |
| 1078 value = TestFastReturnValues<uint32_t>(); |
| 1079 CHECK(value->IsInt32()); |
| 1080 CHECK_EQ(kFastReturnValueUint32, value->Int32Value()); |
| 1081 // check double |
| 1082 value = TestFastReturnValues<double>(); |
| 1083 CHECK(value->IsNumber()); |
| 1084 CHECK_EQ(kFastReturnValueDouble, value->ToNumber()->Value()); |
| 1085 // check bool values |
| 1086 for (int i = 0; i < 2; i++) { |
| 1087 fast_return_value_bool = i == 0; |
| 1088 value = TestFastReturnValues<bool>(); |
| 1089 CHECK(value->IsBoolean()); |
| 1090 CHECK_EQ(fast_return_value_bool, value->ToBoolean()->Value()); |
| 1091 } |
| 1092 // check oddballs |
| 1093 for (int i = 0; i < 2; i++) { |
| 1094 fast_return_value_void_is_null = i == 0; |
| 1095 value = TestFastReturnValues<void>(); |
| 1096 if (fast_return_value_void_is_null) { |
| 1097 CHECK(value->IsNull()); |
| 1098 } else { |
| 1099 CHECK(value->IsUndefined()); |
| 1100 } |
| 1101 } |
| 1102 } |
| 1103 |
| 1104 |
1013 THREADED_TEST(FunctionTemplateSetLength) { | 1105 THREADED_TEST(FunctionTemplateSetLength) { |
1014 LocalContext env; | 1106 LocalContext env; |
1015 v8::HandleScope scope(env->GetIsolate()); | 1107 v8::HandleScope scope(env->GetIsolate()); |
1016 { | 1108 { |
1017 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( | 1109 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( |
1018 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); | 1110 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); |
1019 Local<Function> fun = fun_templ->GetFunction(); | 1111 Local<Function> fun = fun_templ->GetFunction(); |
1020 env->Global()->Set(v8_str("obj"), fun); | 1112 env->Global()->Set(v8_str("obj"), fun); |
1021 Local<Script> script = v8_compile("obj.length"); | 1113 Local<Script> script = v8_compile("obj.length"); |
1022 CHECK_EQ(23, script->Run()->Int32Value()); | 1114 CHECK_EQ(23, script->Run()->Int32Value()); |
(...skipping 18137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19160 i::Semaphore* sem_; | 19252 i::Semaphore* sem_; |
19161 volatile int sem_value_; | 19253 volatile int sem_value_; |
19162 }; | 19254 }; |
19163 | 19255 |
19164 | 19256 |
19165 THREADED_TEST(SemaphoreInterruption) { | 19257 THREADED_TEST(SemaphoreInterruption) { |
19166 ThreadInterruptTest().RunTest(); | 19258 ThreadInterruptTest().RunTest(); |
19167 } | 19259 } |
19168 | 19260 |
19169 #endif // WIN32 | 19261 #endif // WIN32 |
OLD | NEW |