| 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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 global->Set(v8_str("pi"), v8_num(3.1415926)); | 803 global->Set(v8_str("pi"), v8_num(3.1415926)); |
| 804 Local<Value> pi = global->Get(v8_str("pi")); | 804 Local<Value> pi = global->Get(v8_str("pi")); |
| 805 CHECK_EQ(3.1415926, pi->NumberValue()); | 805 CHECK_EQ(3.1415926, pi->NumberValue()); |
| 806 } | 806 } |
| 807 | 807 |
| 808 | 808 |
| 809 template<typename T> | 809 template<typename T> |
| 810 static void CheckReturnValue(const T& t) { | 810 static void CheckReturnValue(const T& t) { |
| 811 v8::ReturnValue<v8::Value> rv = t.GetReturnValue(); | 811 v8::ReturnValue<v8::Value> rv = t.GetReturnValue(); |
| 812 i::Object** o = *reinterpret_cast<i::Object***>(&rv); | 812 i::Object** o = *reinterpret_cast<i::Object***>(&rv); |
| 813 CHECK_EQ(t.GetIsolate(), v8::Isolate::GetCurrent()); | 813 CHECK_EQ(v8::Isolate::GetCurrent(), t.GetIsolate()); |
| 814 CHECK_EQ(t.GetIsolate(), rv.GetIsolate()); |
| 814 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); | 815 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); |
| 815 } | 816 } |
| 816 | 817 |
| 817 static v8::Handle<Value> handle_call(const v8::Arguments& args) { | 818 static v8::Handle<Value> handle_call(const v8::Arguments& args) { |
| 818 ApiTestFuzzer::Fuzz(); | 819 ApiTestFuzzer::Fuzz(); |
| 819 CheckReturnValue(args); | 820 CheckReturnValue(args); |
| 820 args.GetReturnValue().Set(v8_str("bad value")); | 821 args.GetReturnValue().Set(v8_str("bad value")); |
| 821 return v8_num(102); | 822 return v8_num(102); |
| 822 } | 823 } |
| 823 | 824 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 for (int i = 0; i < 30; i++) { | 921 for (int i = 0; i < 30; i++) { |
| 921 CHECK_EQ(102, script->Run()->Int32Value()); | 922 CHECK_EQ(102, script->Run()->Int32Value()); |
| 922 } | 923 } |
| 923 } | 924 } |
| 924 // Use SetCallHandler to initialize a function template, should work like the | 925 // Use SetCallHandler to initialize a function template, should work like the |
| 925 // previous one. | 926 // previous one. |
| 926 { | 927 { |
| 927 LocalContext env; | 928 LocalContext env; |
| 928 v8::HandleScope scope(env->GetIsolate()); | 929 v8::HandleScope scope(env->GetIsolate()); |
| 929 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 930 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 930 fun_templ->SetCallHandler(handler); | 931 fun_templ->SetCallHandler(handler_2); |
| 931 Local<Function> fun = fun_templ->GetFunction(); | 932 Local<Function> fun = fun_templ->GetFunction(); |
| 932 env->Global()->Set(v8_str("obj"), fun); | 933 env->Global()->Set(v8_str("obj"), fun); |
| 933 Local<Script> script = v8_compile("obj()"); | 934 Local<Script> script = v8_compile("obj()"); |
| 934 for (int i = 0; i < 30; i++) { | 935 for (int i = 0; i < 30; i++) { |
| 935 CHECK_EQ(102, script->Run()->Int32Value()); | 936 CHECK_EQ(102, script->Run()->Int32Value()); |
| 936 } | 937 } |
| 937 } | 938 } |
| 938 } | 939 } |
| 939 | 940 |
| 940 | 941 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 static const int32_t kFastReturnValueInt32 = 471; | 1031 static const int32_t kFastReturnValueInt32 = 471; |
| 1031 static const uint32_t kFastReturnValueUint32 = 571; | 1032 static const uint32_t kFastReturnValueUint32 = 571; |
| 1032 static const double kFastReturnValueDouble = 2.7; | 1033 static const double kFastReturnValueDouble = 2.7; |
| 1033 // variable return values | 1034 // variable return values |
| 1034 static bool fast_return_value_bool = false; | 1035 static bool fast_return_value_bool = false; |
| 1035 static bool fast_return_value_void_is_null = false; | 1036 static bool fast_return_value_void_is_null = false; |
| 1036 | 1037 |
| 1037 template<> | 1038 template<> |
| 1038 void FastReturnValueCallback<int32_t>( | 1039 void FastReturnValueCallback<int32_t>( |
| 1039 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1040 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1040 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueInt32); | 1041 CheckReturnValue(info); |
| 1042 info.GetReturnValue().Set(kFastReturnValueInt32); |
| 1041 } | 1043 } |
| 1042 | 1044 |
| 1043 template<> | 1045 template<> |
| 1044 void FastReturnValueCallback<uint32_t>( | 1046 void FastReturnValueCallback<uint32_t>( |
| 1045 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1047 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1046 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueUint32); | 1048 CheckReturnValue(info); |
| 1049 info.GetReturnValue().Set(kFastReturnValueUint32); |
| 1047 } | 1050 } |
| 1048 | 1051 |
| 1049 template<> | 1052 template<> |
| 1050 void FastReturnValueCallback<double>( | 1053 void FastReturnValueCallback<double>( |
| 1051 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1054 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1052 info.GetReturnValue().Set(info.GetIsolate(), kFastReturnValueDouble); | 1055 CheckReturnValue(info); |
| 1056 info.GetReturnValue().Set(kFastReturnValueDouble); |
| 1053 } | 1057 } |
| 1054 | 1058 |
| 1055 template<> | 1059 template<> |
| 1056 void FastReturnValueCallback<bool>( | 1060 void FastReturnValueCallback<bool>( |
| 1057 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1061 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1058 info.GetReturnValue().Set(info.GetIsolate(), fast_return_value_bool); | 1062 CheckReturnValue(info); |
| 1063 info.GetReturnValue().Set(fast_return_value_bool); |
| 1059 } | 1064 } |
| 1060 | 1065 |
| 1061 template<> | 1066 template<> |
| 1062 void FastReturnValueCallback<void>( | 1067 void FastReturnValueCallback<void>( |
| 1063 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1068 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1069 CheckReturnValue(info); |
| 1064 if (fast_return_value_void_is_null) { | 1070 if (fast_return_value_void_is_null) { |
| 1065 info.GetReturnValue().SetNull(info.GetIsolate()); | 1071 info.GetReturnValue().SetNull(); |
| 1066 } else { | 1072 } else { |
| 1067 info.GetReturnValue().SetUndefined(info.GetIsolate()); | 1073 info.GetReturnValue().SetUndefined(); |
| 1068 } | 1074 } |
| 1069 } | 1075 } |
| 1070 | 1076 |
| 1071 template<typename T> | 1077 template<typename T> |
| 1072 Handle<Value> TestFastReturnValues() { | 1078 Handle<Value> TestFastReturnValues() { |
| 1073 LocalContext env; | 1079 LocalContext env; |
| 1074 v8::HandleScope scope(env->GetIsolate()); | 1080 v8::HandleScope scope(env->GetIsolate()); |
| 1075 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1081 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
| 1076 v8::FunctionCallback callback = &FastReturnValueCallback<T>; | 1082 v8::FunctionCallback callback = &FastReturnValueCallback<T>; |
| 1077 object_template->Set("callback", v8::FunctionTemplate::New(callback)); | 1083 object_template->Set("callback", v8::FunctionTemplate::New(callback)); |
| (...skipping 18236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19314 i::Semaphore* sem_; | 19320 i::Semaphore* sem_; |
| 19315 volatile int sem_value_; | 19321 volatile int sem_value_; |
| 19316 }; | 19322 }; |
| 19317 | 19323 |
| 19318 | 19324 |
| 19319 THREADED_TEST(SemaphoreInterruption) { | 19325 THREADED_TEST(SemaphoreInterruption) { |
| 19320 ThreadInterruptTest().RunTest(); | 19326 ThreadInterruptTest().RunTest(); |
| 19321 } | 19327 } |
| 19322 | 19328 |
| 19323 #endif // WIN32 | 19329 #endif // WIN32 |
| OLD | NEW |