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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 using ::v8::Script; | 66 using ::v8::Script; |
67 using ::v8::StackTrace; | 67 using ::v8::StackTrace; |
68 using ::v8::String; | 68 using ::v8::String; |
69 using ::v8::TryCatch; | 69 using ::v8::TryCatch; |
70 using ::v8::Undefined; | 70 using ::v8::Undefined; |
71 using ::v8::UniqueId; | 71 using ::v8::UniqueId; |
72 using ::v8::V8; | 72 using ::v8::V8; |
73 using ::v8::Value; | 73 using ::v8::Value; |
74 | 74 |
75 | 75 |
| 76 #define THREADED_PROFILED_TEST(Name) \ |
| 77 static void Test##Name(); \ |
| 78 TEST(Name##WithProfiler) { \ |
| 79 RunWithProfiler(&Test##Name); \ |
| 80 } \ |
| 81 THREADED_TEST(Name) |
| 82 |
| 83 void RunWithProfiler(void (*test)()) { |
| 84 LocalContext env; |
| 85 v8::HandleScope scope(env->GetIsolate()); |
| 86 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); |
| 87 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 88 |
| 89 cpu_profiler->StartCpuProfiling(profile_name); |
| 90 (*test)(); |
| 91 cpu_profiler->DeleteAllCpuProfiles(); |
| 92 } |
| 93 |
| 94 |
76 static void ExpectString(const char* code, const char* expected) { | 95 static void ExpectString(const char* code, const char* expected) { |
77 Local<Value> result = CompileRun(code); | 96 Local<Value> result = CompileRun(code); |
78 CHECK(result->IsString()); | 97 CHECK(result->IsString()); |
79 String::Utf8Value utf8(result); | 98 String::Utf8Value utf8(result); |
80 CHECK_EQ(expected, *utf8); | 99 CHECK_EQ(expected, *utf8); |
81 } | 100 } |
82 | 101 |
83 static void ExpectInt32(const char* code, int expected) { | 102 static void ExpectInt32(const char* code, int expected) { |
84 Local<Value> result = CompileRun(code); | 103 Local<Value> result = CompileRun(code); |
85 CHECK(result->IsInt32()); | 104 CHECK(result->IsInt32()); |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 ApiTestFuzzer::Fuzz(); | 950 ApiTestFuzzer::Fuzz(); |
932 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); | 951 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); |
933 info.GetReturnValue().Set(v8_str("bad value")); | 952 info.GetReturnValue().Set(v8_str("bad value")); |
934 info.GetReturnValue().Set(v8_num(239)); | 953 info.GetReturnValue().Set(v8_num(239)); |
935 } | 954 } |
936 | 955 |
937 | 956 |
938 template<typename Handler> | 957 template<typename Handler> |
939 static void TestFunctionTemplateInitializer(Handler handler, | 958 static void TestFunctionTemplateInitializer(Handler handler, |
940 Handler handler_2) { | 959 Handler handler_2) { |
941 for (int i = 0; i < 2; i++) { | 960 // Test constructor calls. |
942 bool is_profiling = (i > 0); | 961 { |
943 // Test constructor calls. | 962 LocalContext env; |
944 { | 963 v8::HandleScope scope(env->GetIsolate()); |
945 LocalContext env; | |
946 v8::HandleScope scope(env->GetIsolate()); | |
947 | 964 |
948 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); | 965 Local<v8::FunctionTemplate> fun_templ = |
949 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 966 v8::FunctionTemplate::New(handler); |
950 if (is_profiling) { | 967 Local<Function> fun = fun_templ->GetFunction(); |
951 cpu_profiler->StartCpuProfiling(profile_name); | 968 env->Global()->Set(v8_str("obj"), fun); |
952 } | 969 Local<Script> script = v8_compile("obj()"); |
| 970 for (int i = 0; i < 30; i++) { |
| 971 CHECK_EQ(102, script->Run()->Int32Value()); |
| 972 } |
| 973 } |
| 974 // Use SetCallHandler to initialize a function template, should work like |
| 975 // the previous one. |
| 976 { |
| 977 LocalContext env; |
| 978 v8::HandleScope scope(env->GetIsolate()); |
953 | 979 |
954 Local<v8::FunctionTemplate> fun_templ = | 980 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
955 v8::FunctionTemplate::New(handler); | 981 fun_templ->SetCallHandler(handler_2); |
956 Local<Function> fun = fun_templ->GetFunction(); | 982 Local<Function> fun = fun_templ->GetFunction(); |
957 env->Global()->Set(v8_str("obj"), fun); | 983 env->Global()->Set(v8_str("obj"), fun); |
958 Local<Script> script = v8_compile("obj()"); | 984 Local<Script> script = v8_compile("obj()"); |
959 for (int i = 0; i < 30; i++) { | 985 for (int i = 0; i < 30; i++) { |
960 CHECK_EQ(102, script->Run()->Int32Value()); | 986 CHECK_EQ(102, script->Run()->Int32Value()); |
961 } | |
962 | |
963 if (is_profiling) { | |
964 cpu_profiler->StopCpuProfiling(profile_name); | |
965 } | |
966 } | |
967 // Use SetCallHandler to initialize a function template, should work like | |
968 // the previous one. | |
969 { | |
970 LocalContext env; | |
971 v8::HandleScope scope(env->GetIsolate()); | |
972 | |
973 v8::Local<v8::String> profile_name = v8::String::New("my_profile2"); | |
974 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
975 if (is_profiling) { | |
976 cpu_profiler->StartCpuProfiling(profile_name); | |
977 } | |
978 | |
979 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | |
980 fun_templ->SetCallHandler(handler_2); | |
981 Local<Function> fun = fun_templ->GetFunction(); | |
982 env->Global()->Set(v8_str("obj"), fun); | |
983 Local<Script> script = v8_compile("obj()"); | |
984 for (int i = 0; i < 30; i++) { | |
985 CHECK_EQ(102, script->Run()->Int32Value()); | |
986 } | |
987 | |
988 if (is_profiling) { | |
989 cpu_profiler->DeleteAllCpuProfiles(); | |
990 } | |
991 } | 987 } |
992 } | 988 } |
993 } | 989 } |
994 | 990 |
995 | 991 |
996 template<typename Constructor, typename Accessor> | 992 template<typename Constructor, typename Accessor> |
997 static void TestFunctionTemplateAccessor(Constructor constructor, | 993 static void TestFunctionTemplateAccessor(Constructor constructor, |
998 Accessor accessor) { | 994 Accessor accessor) { |
999 for (int i = 0; i < 2; i++) { | 995 LocalContext env; |
1000 bool is_profiling = (i > 0); | 996 v8::HandleScope scope(env->GetIsolate()); |
1001 LocalContext env; | |
1002 v8::HandleScope scope(env->GetIsolate()); | |
1003 | 997 |
1004 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 998 Local<v8::FunctionTemplate> fun_templ = |
1005 if (is_profiling) { | 999 v8::FunctionTemplate::New(constructor); |
1006 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); | 1000 fun_templ->SetClassName(v8_str("funky")); |
1007 cpu_profiler->StartCpuProfiling(profile_name); | 1001 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); |
1008 } | 1002 Local<Function> fun = fun_templ->GetFunction(); |
1009 | 1003 env->Global()->Set(v8_str("obj"), fun); |
1010 Local<v8::FunctionTemplate> fun_templ = | 1004 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
1011 v8::FunctionTemplate::New(constructor); | 1005 CHECK_EQ(v8_str("[object funky]"), result); |
1012 fun_templ->SetClassName(v8_str("funky")); | 1006 CompileRun("var obj_instance = new obj();"); |
1013 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); | 1007 Local<Script> script; |
1014 Local<Function> fun = fun_templ->GetFunction(); | 1008 script = v8_compile("obj_instance.x"); |
1015 env->Global()->Set(v8_str("obj"), fun); | 1009 for (int i = 0; i < 30; i++) { |
1016 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 1010 CHECK_EQ(1, script->Run()->Int32Value()); |
1017 CHECK_EQ(v8_str("[object funky]"), result); | 1011 } |
1018 CompileRun("var obj_instance = new obj();"); | 1012 script = v8_compile("obj_instance.m"); |
1019 Local<Script> script; | 1013 for (int i = 0; i < 30; i++) { |
1020 script = v8_compile("obj_instance.x"); | 1014 CHECK_EQ(239, script->Run()->Int32Value()); |
1021 for (int i = 0; i < 30; i++) { | |
1022 CHECK_EQ(1, script->Run()->Int32Value()); | |
1023 } | |
1024 script = v8_compile("obj_instance.m"); | |
1025 for (int i = 0; i < 30; i++) { | |
1026 CHECK_EQ(239, script->Run()->Int32Value()); | |
1027 } | |
1028 | |
1029 if (is_profiling) { | |
1030 cpu_profiler->DeleteAllCpuProfiles(); | |
1031 } | |
1032 } | 1015 } |
1033 } | 1016 } |
1034 | 1017 |
1035 | 1018 |
1036 THREADED_TEST(FunctionTemplate) { | 1019 THREADED_PROFILED_TEST(FunctionTemplate) { |
1037 TestFunctionTemplateInitializer(handle_call, handle_call_2); | 1020 TestFunctionTemplateInitializer(handle_call, handle_call_2); |
1038 TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2); | 1021 TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2); |
1039 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); | 1022 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); |
1040 | 1023 |
1041 TestFunctionTemplateAccessor(construct_call, Return239); | 1024 TestFunctionTemplateAccessor(construct_call, Return239); |
1042 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect); | 1025 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect); |
1043 TestFunctionTemplateAccessor(construct_callback, Return239Callback); | 1026 TestFunctionTemplateAccessor(construct_callback, Return239Callback); |
1044 } | 1027 } |
1045 | 1028 |
1046 | 1029 |
(...skipping 13 matching lines...) Expand all Loading... |
1060 | 1043 |
1061 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1044 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
1062 ApiTestFuzzer::Fuzz(); | 1045 ApiTestFuzzer::Fuzz(); |
1063 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); | 1046 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); |
1064 info.GetReturnValue().Set(v8_num(51423 + info.Length())); | 1047 info.GetReturnValue().Set(v8_num(51423 + info.Length())); |
1065 } | 1048 } |
1066 | 1049 |
1067 | 1050 |
1068 template<typename Callback> | 1051 template<typename Callback> |
1069 static void TestSimpleCallback(Callback callback) { | 1052 static void TestSimpleCallback(Callback callback) { |
1070 for (int i = 0; i < 2; i++) { | 1053 LocalContext env; |
1071 bool is_profiling = i; | 1054 v8::HandleScope scope(env->GetIsolate()); |
1072 LocalContext env; | |
1073 v8::HandleScope scope(env->GetIsolate()); | |
1074 | 1055 |
1075 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1056 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
1076 if (is_profiling) { | 1057 object_template->Set("callback", v8::FunctionTemplate::New(callback)); |
1077 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); | 1058 v8::Local<v8::Object> object = object_template->NewInstance(); |
1078 cpu_profiler->StartCpuProfiling(profile_name); | 1059 (*env)->Global()->Set(v8_str("callback_object"), object); |
1079 } | 1060 v8::Handle<v8::Script> script; |
1080 | 1061 script = v8_compile("callback_object.callback(17)"); |
1081 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1062 for (int i = 0; i < 30; i++) { |
1082 object_template->Set("callback", v8::FunctionTemplate::New(callback)); | 1063 CHECK_EQ(51424, script->Run()->Int32Value()); |
1083 v8::Local<v8::Object> object = object_template->NewInstance(); | 1064 } |
1084 (*env)->Global()->Set(v8_str("callback_object"), object); | 1065 script = v8_compile("callback_object.callback(17, 24)"); |
1085 v8::Handle<v8::Script> script; | 1066 for (int i = 0; i < 30; i++) { |
1086 script = v8_compile("callback_object.callback(17)"); | 1067 CHECK_EQ(51425, script->Run()->Int32Value()); |
1087 for (int i = 0; i < 30; i++) { | |
1088 CHECK_EQ(51424, script->Run()->Int32Value()); | |
1089 } | |
1090 script = v8_compile("callback_object.callback(17, 24)"); | |
1091 for (int i = 0; i < 30; i++) { | |
1092 CHECK_EQ(51425, script->Run()->Int32Value()); | |
1093 } | |
1094 | |
1095 if (is_profiling) { | |
1096 cpu_profiler->DeleteAllCpuProfiles(); | |
1097 } | |
1098 } | 1068 } |
1099 } | 1069 } |
1100 | 1070 |
1101 | 1071 |
1102 THREADED_TEST(SimpleCallback) { | 1072 THREADED_PROFILED_TEST(SimpleCallback) { |
1103 TestSimpleCallback(SimpleDirectCallback); | 1073 TestSimpleCallback(SimpleDirectCallback); |
1104 TestSimpleCallback(SimpleIndirectCallback); | 1074 TestSimpleCallback(SimpleIndirectCallback); |
1105 TestSimpleCallback(SimpleCallback); | 1075 TestSimpleCallback(SimpleCallback); |
1106 } | 1076 } |
1107 | 1077 |
1108 | 1078 |
1109 template<typename T> | 1079 template<typename T> |
1110 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); | 1080 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); |
1111 | 1081 |
1112 // constant return values | 1082 // constant return values |
(...skipping 18340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19453 i::Semaphore* sem_; | 19423 i::Semaphore* sem_; |
19454 volatile int sem_value_; | 19424 volatile int sem_value_; |
19455 }; | 19425 }; |
19456 | 19426 |
19457 | 19427 |
19458 THREADED_TEST(SemaphoreInterruption) { | 19428 THREADED_TEST(SemaphoreInterruption) { |
19459 ThreadInterruptTest().RunTest(); | 19429 ThreadInterruptTest().RunTest(); |
19460 } | 19430 } |
19461 | 19431 |
19462 #endif // WIN32 | 19432 #endif // WIN32 |
OLD | NEW |