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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 LocalContext env; | 797 LocalContext env; |
798 v8::HandleScope scope(env->GetIsolate()); | 798 v8::HandleScope scope(env->GetIsolate()); |
799 v8::Handle<v8::Object> global = env->Global(); | 799 v8::Handle<v8::Object> global = env->Global(); |
800 global->Set(v8_str("pi"), v8_num(3.1415926)); | 800 global->Set(v8_str("pi"), v8_num(3.1415926)); |
801 Local<Value> pi = global->Get(v8_str("pi")); | 801 Local<Value> pi = global->Get(v8_str("pi")); |
802 CHECK_EQ(3.1415926, pi->NumberValue()); | 802 CHECK_EQ(3.1415926, pi->NumberValue()); |
803 } | 803 } |
804 | 804 |
805 | 805 |
806 template<typename T> | 806 template<typename T> |
807 static void CheckReturnValue(const T& t) { | 807 static void CheckReturnValue(const T& t, i::Address callback) { |
808 v8::ReturnValue<v8::Value> rv = t.GetReturnValue(); | 808 v8::ReturnValue<v8::Value> rv = t.GetReturnValue(); |
809 i::Object** o = *reinterpret_cast<i::Object***>(&rv); | 809 i::Object** o = *reinterpret_cast<i::Object***>(&rv); |
810 CHECK_EQ(v8::Isolate::GetCurrent(), t.GetIsolate()); | 810 CHECK_EQ(v8::Isolate::GetCurrent(), t.GetIsolate()); |
811 CHECK_EQ(t.GetIsolate(), rv.GetIsolate()); | 811 CHECK_EQ(t.GetIsolate(), rv.GetIsolate()); |
812 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); | 812 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); |
813 // Verify reset | 813 // Verify reset |
814 bool is_runtime = (*o)->IsTheHole(); | 814 bool is_runtime = (*o)->IsTheHole(); |
815 rv.Set(true); | 815 rv.Set(true); |
816 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined()); | 816 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined()); |
817 rv.Set(v8::Handle<v8::Object>()); | 817 rv.Set(v8::Handle<v8::Object>()); |
818 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); | 818 CHECK((*o)->IsTheHole() || (*o)->IsUndefined()); |
819 CHECK_EQ(is_runtime, (*o)->IsTheHole()); | 819 CHECK_EQ(is_runtime, (*o)->IsTheHole()); |
| 820 |
| 821 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate()); |
| 822 // If CPU profiler is active check that when API callback is invoked |
| 823 // VMState is set to EXTERNAL. |
| 824 if (isolate->cpu_profiler()->is_profiling()) { |
| 825 CHECK_EQ(i::EXTERNAL, isolate->current_vm_state()); |
| 826 CHECK(isolate->external_callback()); |
| 827 CHECK_EQ(callback, isolate->external_callback()); |
| 828 } |
820 } | 829 } |
821 | 830 |
822 static v8::Handle<Value> handle_call(const v8::Arguments& args) { | 831 static v8::Handle<Value> handle_call_impl( |
| 832 const v8::Arguments& args, |
| 833 i::Address callback) { |
823 ApiTestFuzzer::Fuzz(); | 834 ApiTestFuzzer::Fuzz(); |
824 CheckReturnValue(args); | 835 CheckReturnValue(args, callback); |
825 args.GetReturnValue().Set(v8_str("bad value")); | 836 args.GetReturnValue().Set(v8_str("bad value")); |
826 return v8_num(102); | 837 return v8_num(102); |
827 } | 838 } |
828 | 839 |
829 static v8::Handle<Value> handle_call_2(const v8::Arguments& args) { | 840 static v8::Handle<Value> handle_call(const v8::Arguments& args) { |
830 return handle_call(args); | 841 return handle_call_impl(args, FUNCTION_ADDR(handle_call)); |
831 } | 842 } |
832 | 843 |
833 static v8::Handle<Value> handle_call_indirect(const v8::Arguments& args) { | 844 static v8::Handle<Value> handle_call_2(const v8::Arguments& args) { |
| 845 return handle_call_impl(args, FUNCTION_ADDR(handle_call_2)); |
| 846 } |
| 847 |
| 848 static v8::Handle<Value> handle_call_indirect_impl(const v8::Arguments& args, |
| 849 i::Address callback) { |
834 ApiTestFuzzer::Fuzz(); | 850 ApiTestFuzzer::Fuzz(); |
835 CheckReturnValue(args); | 851 CheckReturnValue(args, callback); |
836 args.GetReturnValue().Set(v8_str("bad value")); | 852 args.GetReturnValue().Set(v8_str("bad value")); |
837 args.GetReturnValue().Set(v8_num(102)); | 853 args.GetReturnValue().Set(v8_num(102)); |
838 return v8::Handle<Value>(); | 854 return v8::Handle<Value>(); |
839 } | 855 } |
840 | 856 |
841 static v8::Handle<Value> handle_call_indirect_2(const v8::Arguments& args) { | 857 static v8::Handle<Value> handle_call_indirect(const v8::Arguments& args) { |
842 return handle_call_indirect(args); | 858 return handle_call_indirect_impl(args, FUNCTION_ADDR(handle_call_indirect)); |
843 } | 859 } |
844 | 860 |
845 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { | 861 static v8::Handle<Value> handle_call_indirect_2(const v8::Arguments& args) { |
| 862 return handle_call_indirect_impl(args, FUNCTION_ADDR(handle_call_indirect_2)); |
| 863 } |
| 864 |
| 865 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info, |
| 866 i::Address callback) { |
846 ApiTestFuzzer::Fuzz(); | 867 ApiTestFuzzer::Fuzz(); |
847 CheckReturnValue(info); | 868 CheckReturnValue(info, callback); |
848 info.GetReturnValue().Set(v8_str("bad value")); | 869 info.GetReturnValue().Set(v8_str("bad value")); |
849 info.GetReturnValue().Set(v8_num(102)); | 870 info.GetReturnValue().Set(v8_num(102)); |
850 } | 871 } |
851 | 872 |
| 873 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { |
| 874 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback)); |
| 875 } |
| 876 |
852 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { | 877 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { |
853 return handle_callback(info); | 878 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2)); |
854 } | 879 } |
855 | 880 |
856 static v8::Handle<Value> construct_call(const v8::Arguments& args) { | 881 static v8::Handle<Value> construct_call(const v8::Arguments& args) { |
857 ApiTestFuzzer::Fuzz(); | 882 ApiTestFuzzer::Fuzz(); |
858 CheckReturnValue(args); | 883 CheckReturnValue(args, FUNCTION_ADDR(construct_call)); |
859 args.This()->Set(v8_str("x"), v8_num(1)); | 884 args.This()->Set(v8_str("x"), v8_num(1)); |
860 args.This()->Set(v8_str("y"), v8_num(2)); | 885 args.This()->Set(v8_str("y"), v8_num(2)); |
861 args.GetReturnValue().Set(v8_str("bad value")); | 886 args.GetReturnValue().Set(v8_str("bad value")); |
862 return args.This(); | 887 return args.This(); |
863 } | 888 } |
864 | 889 |
865 static v8::Handle<Value> construct_call_indirect(const v8::Arguments& args) { | 890 static v8::Handle<Value> construct_call_indirect(const v8::Arguments& args) { |
866 ApiTestFuzzer::Fuzz(); | 891 ApiTestFuzzer::Fuzz(); |
867 CheckReturnValue(args); | 892 CheckReturnValue(args, FUNCTION_ADDR(construct_call_indirect)); |
868 args.This()->Set(v8_str("x"), v8_num(1)); | 893 args.This()->Set(v8_str("x"), v8_num(1)); |
869 args.This()->Set(v8_str("y"), v8_num(2)); | 894 args.This()->Set(v8_str("y"), v8_num(2)); |
870 args.GetReturnValue().Set(v8_str("bad value")); | 895 args.GetReturnValue().Set(v8_str("bad value")); |
871 args.GetReturnValue().Set(args.This()); | 896 args.GetReturnValue().Set(args.This()); |
872 return v8::Handle<Value>(); | 897 return v8::Handle<Value>(); |
873 } | 898 } |
874 | 899 |
875 static void construct_callback( | 900 static void construct_callback( |
876 const v8::FunctionCallbackInfo<Value>& info) { | 901 const v8::FunctionCallbackInfo<Value>& info) { |
877 ApiTestFuzzer::Fuzz(); | 902 ApiTestFuzzer::Fuzz(); |
878 CheckReturnValue(info); | 903 CheckReturnValue(info, FUNCTION_ADDR(construct_callback)); |
879 info.This()->Set(v8_str("x"), v8_num(1)); | 904 info.This()->Set(v8_str("x"), v8_num(1)); |
880 info.This()->Set(v8_str("y"), v8_num(2)); | 905 info.This()->Set(v8_str("y"), v8_num(2)); |
881 info.GetReturnValue().Set(v8_str("bad value")); | 906 info.GetReturnValue().Set(v8_str("bad value")); |
882 info.GetReturnValue().Set(info.This()); | 907 info.GetReturnValue().Set(info.This()); |
883 } | 908 } |
884 | 909 |
885 | 910 |
886 static v8::Handle<Value> Return239( | 911 static v8::Handle<Value> Return239( |
887 Local<String> name, const AccessorInfo& info) { | 912 Local<String> name, const AccessorInfo& info) { |
888 ApiTestFuzzer::Fuzz(); | 913 ApiTestFuzzer::Fuzz(); |
889 CheckReturnValue(info); | 914 CheckReturnValue(info, FUNCTION_ADDR(Return239)); |
890 info.GetReturnValue().Set(v8_str("bad value")); | 915 info.GetReturnValue().Set(v8_str("bad value")); |
891 return v8_num(239); | 916 return v8_num(239); |
892 } | 917 } |
893 | 918 |
894 static v8::Handle<Value> Return239Indirect( | 919 static v8::Handle<Value> Return239Indirect( |
895 Local<String> name, const AccessorInfo& info) { | 920 Local<String> name, const AccessorInfo& info) { |
896 ApiTestFuzzer::Fuzz(); | 921 ApiTestFuzzer::Fuzz(); |
897 CheckReturnValue(info); | 922 CheckReturnValue(info, FUNCTION_ADDR(Return239Indirect)); |
898 Handle<Value> value = v8_num(239); | 923 Handle<Value> value = v8_num(239); |
899 info.GetReturnValue().Set(v8_str("bad value")); | 924 info.GetReturnValue().Set(v8_str("bad value")); |
900 info.GetReturnValue().Set(value); | 925 info.GetReturnValue().Set(value); |
901 return v8::Handle<Value>(); | 926 return v8::Handle<Value>(); |
902 } | 927 } |
903 | 928 |
904 static void Return239Callback( | 929 static void Return239Callback( |
905 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { | 930 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { |
906 ApiTestFuzzer::Fuzz(); | 931 ApiTestFuzzer::Fuzz(); |
907 CheckReturnValue(info); | 932 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); |
908 info.GetReturnValue().Set(v8_str("bad value")); | 933 info.GetReturnValue().Set(v8_str("bad value")); |
909 info.GetReturnValue().Set(v8_num(239)); | 934 info.GetReturnValue().Set(v8_num(239)); |
910 } | 935 } |
911 | 936 |
912 | 937 |
913 template<typename Handler> | 938 template<typename Handler> |
914 static void TestFunctionTemplateInitializer(Handler handler, | 939 static void TestFunctionTemplateInitializer(Handler handler, |
915 Handler handler_2) { | 940 Handler handler_2) { |
916 // Test constructor calls. | 941 for (int i = 0; i < 2; i++) { |
917 { | 942 bool is_profiling = (i > 0); |
918 LocalContext env; | 943 // Test constructor calls. |
919 v8::HandleScope scope(env->GetIsolate()); | 944 { |
920 Local<v8::FunctionTemplate> fun_templ = | 945 LocalContext env; |
921 v8::FunctionTemplate::New(handler); | 946 v8::HandleScope scope(env->GetIsolate()); |
922 Local<Function> fun = fun_templ->GetFunction(); | 947 |
923 env->Global()->Set(v8_str("obj"), fun); | 948 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); |
924 Local<Script> script = v8_compile("obj()"); | 949 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
925 for (int i = 0; i < 30; i++) { | 950 if (is_profiling) { |
926 CHECK_EQ(102, script->Run()->Int32Value()); | 951 cpu_profiler->StartCpuProfiling(profile_name); |
| 952 } |
| 953 |
| 954 Local<v8::FunctionTemplate> fun_templ = |
| 955 v8::FunctionTemplate::New(handler); |
| 956 Local<Function> fun = fun_templ->GetFunction(); |
| 957 env->Global()->Set(v8_str("obj"), fun); |
| 958 Local<Script> script = v8_compile("obj()"); |
| 959 for (int i = 0; i < 30; i++) { |
| 960 CHECK_EQ(102, script->Run()->Int32Value()); |
| 961 } |
| 962 |
| 963 if (is_profiling) { |
| 964 cpu_profiler->StopCpuProfiling(profile_name); |
| 965 } |
927 } | 966 } |
928 } | 967 // Use SetCallHandler to initialize a function template, should work like |
929 // Use SetCallHandler to initialize a function template, should work like the | 968 // the previous one. |
930 // previous one. | 969 { |
931 { | 970 LocalContext env; |
932 LocalContext env; | 971 v8::HandleScope scope(env->GetIsolate()); |
933 v8::HandleScope scope(env->GetIsolate()); | 972 |
934 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 973 v8::Local<v8::String> profile_name = v8::String::New("my_profile2"); |
935 fun_templ->SetCallHandler(handler_2); | 974 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
936 Local<Function> fun = fun_templ->GetFunction(); | 975 if (is_profiling) { |
937 env->Global()->Set(v8_str("obj"), fun); | 976 cpu_profiler->StartCpuProfiling(profile_name); |
938 Local<Script> script = v8_compile("obj()"); | 977 } |
939 for (int i = 0; i < 30; i++) { | 978 |
940 CHECK_EQ(102, script->Run()->Int32Value()); | 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 } |
941 } | 991 } |
942 } | 992 } |
943 } | 993 } |
944 | 994 |
945 | 995 |
946 template<typename Constructor, typename Accessor> | 996 template<typename Constructor, typename Accessor> |
947 static void TestFunctionTemplateAccessor(Constructor constructor, | 997 static void TestFunctionTemplateAccessor(Constructor constructor, |
948 Accessor accessor) { | 998 Accessor accessor) { |
949 LocalContext env; | 999 for (int i = 0; i < 2; i++) { |
950 v8::HandleScope scope(env->GetIsolate()); | 1000 bool is_profiling = (i > 0); |
951 Local<v8::FunctionTemplate> fun_templ = | 1001 LocalContext env; |
952 v8::FunctionTemplate::New(constructor); | 1002 v8::HandleScope scope(env->GetIsolate()); |
953 fun_templ->SetClassName(v8_str("funky")); | 1003 |
954 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); | 1004 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
955 Local<Function> fun = fun_templ->GetFunction(); | 1005 if (is_profiling) { |
956 env->Global()->Set(v8_str("obj"), fun); | 1006 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); |
957 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 1007 cpu_profiler->StartCpuProfiling(profile_name); |
958 CHECK_EQ(v8_str("[object funky]"), result); | 1008 } |
959 CompileRun("var obj_instance = new obj();"); | 1009 |
960 Local<Script> script; | 1010 Local<v8::FunctionTemplate> fun_templ = |
961 script = v8_compile("obj_instance.x"); | 1011 v8::FunctionTemplate::New(constructor); |
962 for (int i = 0; i < 30; i++) { | 1012 fun_templ->SetClassName(v8_str("funky")); |
963 CHECK_EQ(1, script->Run()->Int32Value()); | 1013 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); |
964 } | 1014 Local<Function> fun = fun_templ->GetFunction(); |
965 script = v8_compile("obj_instance.m"); | 1015 env->Global()->Set(v8_str("obj"), fun); |
966 for (int i = 0; i < 30; i++) { | 1016 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
967 CHECK_EQ(239, script->Run()->Int32Value()); | 1017 CHECK_EQ(v8_str("[object funky]"), result); |
| 1018 CompileRun("var obj_instance = new obj();"); |
| 1019 Local<Script> script; |
| 1020 script = v8_compile("obj_instance.x"); |
| 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 } |
968 } | 1032 } |
969 } | 1033 } |
970 | 1034 |
971 | 1035 |
972 THREADED_TEST(FunctionTemplate) { | 1036 THREADED_TEST(FunctionTemplate) { |
973 TestFunctionTemplateInitializer(handle_call, handle_call_2); | 1037 TestFunctionTemplateInitializer(handle_call, handle_call_2); |
974 TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2); | 1038 TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2); |
975 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); | 1039 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); |
976 | 1040 |
977 TestFunctionTemplateAccessor(construct_call, Return239); | 1041 TestFunctionTemplateAccessor(construct_call, Return239); |
978 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect); | 1042 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect); |
979 TestFunctionTemplateAccessor(construct_callback, Return239Callback); | 1043 TestFunctionTemplateAccessor(construct_callback, Return239Callback); |
980 } | 1044 } |
981 | 1045 |
982 | 1046 |
983 static v8::Handle<v8::Value> SimpleDirectCallback(const v8::Arguments& args) { | 1047 static v8::Handle<v8::Value> SimpleDirectCallback(const v8::Arguments& args) { |
984 ApiTestFuzzer::Fuzz(); | 1048 ApiTestFuzzer::Fuzz(); |
985 CheckReturnValue(args); | 1049 CheckReturnValue(args, FUNCTION_ADDR(SimpleDirectCallback)); |
986 args.GetReturnValue().Set(v8_str("bad value")); | 1050 args.GetReturnValue().Set(v8_str("bad value")); |
987 return v8_num(51423 + args.Length()); | 1051 return v8_num(51423 + args.Length()); |
988 } | 1052 } |
989 | 1053 |
990 static v8::Handle<v8::Value> SimpleIndirectCallback(const v8::Arguments& args) { | 1054 static v8::Handle<v8::Value> SimpleIndirectCallback(const v8::Arguments& args) { |
991 ApiTestFuzzer::Fuzz(); | 1055 ApiTestFuzzer::Fuzz(); |
992 CheckReturnValue(args); | 1056 CheckReturnValue(args, FUNCTION_ADDR(SimpleIndirectCallback)); |
993 args.GetReturnValue().Set(v8_num(51423 + args.Length())); | 1057 args.GetReturnValue().Set(v8_num(51423 + args.Length())); |
994 return v8::Handle<v8::Value>(); | 1058 return v8::Handle<v8::Value>(); |
995 } | 1059 } |
996 | 1060 |
997 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1061 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
998 ApiTestFuzzer::Fuzz(); | 1062 ApiTestFuzzer::Fuzz(); |
999 CheckReturnValue(info); | 1063 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); |
1000 info.GetReturnValue().Set(v8_num(51423 + info.Length())); | 1064 info.GetReturnValue().Set(v8_num(51423 + info.Length())); |
1001 } | 1065 } |
1002 | 1066 |
1003 | 1067 |
1004 template<typename Callback> | 1068 template<typename Callback> |
1005 static void TestSimpleCallback(Callback callback) { | 1069 static void TestSimpleCallback(Callback callback) { |
1006 LocalContext env; | 1070 for (int i = 0; i < 2; i++) { |
1007 v8::HandleScope scope(env->GetIsolate()); | 1071 bool is_profiling = i; |
1008 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1072 LocalContext env; |
1009 object_template->Set("callback", v8::FunctionTemplate::New(callback)); | 1073 v8::HandleScope scope(env->GetIsolate()); |
1010 v8::Local<v8::Object> object = object_template->NewInstance(); | 1074 |
1011 (*env)->Global()->Set(v8_str("callback_object"), object); | 1075 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
1012 v8::Handle<v8::Script> script; | 1076 if (is_profiling) { |
1013 script = v8_compile("callback_object.callback(17)"); | 1077 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); |
1014 for (int i = 0; i < 30; i++) { | 1078 cpu_profiler->StartCpuProfiling(profile_name); |
1015 CHECK_EQ(51424, script->Run()->Int32Value()); | 1079 } |
1016 } | 1080 |
1017 script = v8_compile("callback_object.callback(17, 24)"); | 1081 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
1018 for (int i = 0; i < 30; i++) { | 1082 object_template->Set("callback", v8::FunctionTemplate::New(callback)); |
1019 CHECK_EQ(51425, script->Run()->Int32Value()); | 1083 v8::Local<v8::Object> object = object_template->NewInstance(); |
| 1084 (*env)->Global()->Set(v8_str("callback_object"), object); |
| 1085 v8::Handle<v8::Script> script; |
| 1086 script = v8_compile("callback_object.callback(17)"); |
| 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 } |
1020 } | 1098 } |
1021 } | 1099 } |
1022 | 1100 |
1023 | 1101 |
1024 THREADED_TEST(SimpleCallback) { | 1102 THREADED_TEST(SimpleCallback) { |
1025 TestSimpleCallback(SimpleDirectCallback); | 1103 TestSimpleCallback(SimpleDirectCallback); |
1026 TestSimpleCallback(SimpleIndirectCallback); | 1104 TestSimpleCallback(SimpleIndirectCallback); |
1027 TestSimpleCallback(SimpleCallback); | 1105 TestSimpleCallback(SimpleCallback); |
1028 } | 1106 } |
1029 | 1107 |
(...skipping 11 matching lines...) Expand all Loading... |
1041 kNullReturnValue, | 1119 kNullReturnValue, |
1042 kUndefinedReturnValue, | 1120 kUndefinedReturnValue, |
1043 kEmptyStringReturnValue | 1121 kEmptyStringReturnValue |
1044 }; | 1122 }; |
1045 static ReturnValueOddball fast_return_value_void; | 1123 static ReturnValueOddball fast_return_value_void; |
1046 static bool fast_return_value_object_is_empty = false; | 1124 static bool fast_return_value_object_is_empty = false; |
1047 | 1125 |
1048 template<> | 1126 template<> |
1049 void FastReturnValueCallback<int32_t>( | 1127 void FastReturnValueCallback<int32_t>( |
1050 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1128 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1051 CheckReturnValue(info); | 1129 CheckReturnValue(info, FUNCTION_ADDR(FastReturnValueCallback<int32_t>)); |
1052 info.GetReturnValue().Set(fast_return_value_int32); | 1130 info.GetReturnValue().Set(fast_return_value_int32); |
1053 } | 1131 } |
1054 | 1132 |
1055 template<> | 1133 template<> |
1056 void FastReturnValueCallback<uint32_t>( | 1134 void FastReturnValueCallback<uint32_t>( |
1057 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1135 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1058 CheckReturnValue(info); | 1136 CheckReturnValue(info, FUNCTION_ADDR(FastReturnValueCallback<uint32_t>)); |
1059 info.GetReturnValue().Set(fast_return_value_uint32); | 1137 info.GetReturnValue().Set(fast_return_value_uint32); |
1060 } | 1138 } |
1061 | 1139 |
1062 template<> | 1140 template<> |
1063 void FastReturnValueCallback<double>( | 1141 void FastReturnValueCallback<double>( |
1064 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1142 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1065 CheckReturnValue(info); | 1143 CheckReturnValue(info, FUNCTION_ADDR(FastReturnValueCallback<double>)); |
1066 info.GetReturnValue().Set(kFastReturnValueDouble); | 1144 info.GetReturnValue().Set(kFastReturnValueDouble); |
1067 } | 1145 } |
1068 | 1146 |
1069 template<> | 1147 template<> |
1070 void FastReturnValueCallback<bool>( | 1148 void FastReturnValueCallback<bool>( |
1071 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1149 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1072 CheckReturnValue(info); | 1150 CheckReturnValue(info, FUNCTION_ADDR(FastReturnValueCallback<bool>)); |
1073 info.GetReturnValue().Set(fast_return_value_bool); | 1151 info.GetReturnValue().Set(fast_return_value_bool); |
1074 } | 1152 } |
1075 | 1153 |
1076 template<> | 1154 template<> |
1077 void FastReturnValueCallback<void>( | 1155 void FastReturnValueCallback<void>( |
1078 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1156 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1079 CheckReturnValue(info); | 1157 CheckReturnValue(info, FUNCTION_ADDR(FastReturnValueCallback<void>)); |
1080 switch (fast_return_value_void) { | 1158 switch (fast_return_value_void) { |
1081 case kNullReturnValue: | 1159 case kNullReturnValue: |
1082 info.GetReturnValue().SetNull(); | 1160 info.GetReturnValue().SetNull(); |
1083 break; | 1161 break; |
1084 case kUndefinedReturnValue: | 1162 case kUndefinedReturnValue: |
1085 info.GetReturnValue().SetUndefined(); | 1163 info.GetReturnValue().SetUndefined(); |
1086 break; | 1164 break; |
1087 case kEmptyStringReturnValue: | 1165 case kEmptyStringReturnValue: |
1088 info.GetReturnValue().SetEmptyString(); | 1166 info.GetReturnValue().SetEmptyString(); |
1089 break; | 1167 break; |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 Local<Script> script = v8_compile("obj[900]"); | 2124 Local<Script> script = v8_compile("obj[900]"); |
2047 CHECK_EQ(script->Run()->Int32Value(), 900); | 2125 CHECK_EQ(script->Run()->Int32Value(), 900); |
2048 } | 2126 } |
2049 | 2127 |
2050 | 2128 |
2051 v8::Handle<v8::Object> bottom; | 2129 v8::Handle<v8::Object> bottom; |
2052 | 2130 |
2053 static void CheckThisIndexedPropertyHandler( | 2131 static void CheckThisIndexedPropertyHandler( |
2054 uint32_t index, | 2132 uint32_t index, |
2055 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2133 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2056 CheckReturnValue(info); | 2134 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyHandler)); |
2057 ApiTestFuzzer::Fuzz(); | 2135 ApiTestFuzzer::Fuzz(); |
2058 CHECK(info.This()->Equals(bottom)); | 2136 CHECK(info.This()->Equals(bottom)); |
2059 } | 2137 } |
2060 | 2138 |
2061 static void CheckThisNamedPropertyHandler( | 2139 static void CheckThisNamedPropertyHandler( |
2062 Local<String> name, | 2140 Local<String> name, |
2063 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2141 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2064 CheckReturnValue(info); | 2142 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); |
2065 ApiTestFuzzer::Fuzz(); | 2143 ApiTestFuzzer::Fuzz(); |
2066 CHECK(info.This()->Equals(bottom)); | 2144 CHECK(info.This()->Equals(bottom)); |
2067 } | 2145 } |
2068 | 2146 |
2069 void CheckThisIndexedPropertySetter( | 2147 void CheckThisIndexedPropertySetter( |
2070 uint32_t index, | 2148 uint32_t index, |
2071 Local<Value> value, | 2149 Local<Value> value, |
2072 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2150 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2073 CheckReturnValue(info); | 2151 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); |
2074 ApiTestFuzzer::Fuzz(); | 2152 ApiTestFuzzer::Fuzz(); |
2075 CHECK(info.This()->Equals(bottom)); | 2153 CHECK(info.This()->Equals(bottom)); |
2076 } | 2154 } |
2077 | 2155 |
2078 | 2156 |
2079 void CheckThisNamedPropertySetter( | 2157 void CheckThisNamedPropertySetter( |
2080 Local<String> property, | 2158 Local<String> property, |
2081 Local<Value> value, | 2159 Local<Value> value, |
2082 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2160 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2083 CheckReturnValue(info); | 2161 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertySetter)); |
2084 ApiTestFuzzer::Fuzz(); | 2162 ApiTestFuzzer::Fuzz(); |
2085 CHECK(info.This()->Equals(bottom)); | 2163 CHECK(info.This()->Equals(bottom)); |
2086 } | 2164 } |
2087 | 2165 |
2088 void CheckThisIndexedPropertyQuery( | 2166 void CheckThisIndexedPropertyQuery( |
2089 uint32_t index, | 2167 uint32_t index, |
2090 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2168 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
2091 CheckReturnValue(info); | 2169 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyQuery)); |
2092 ApiTestFuzzer::Fuzz(); | 2170 ApiTestFuzzer::Fuzz(); |
2093 CHECK(info.This()->Equals(bottom)); | 2171 CHECK(info.This()->Equals(bottom)); |
2094 } | 2172 } |
2095 | 2173 |
2096 | 2174 |
2097 void CheckThisNamedPropertyQuery( | 2175 void CheckThisNamedPropertyQuery( |
2098 Local<String> property, | 2176 Local<String> property, |
2099 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2177 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
2100 CheckReturnValue(info); | 2178 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyQuery)); |
2101 ApiTestFuzzer::Fuzz(); | 2179 ApiTestFuzzer::Fuzz(); |
2102 CHECK(info.This()->Equals(bottom)); | 2180 CHECK(info.This()->Equals(bottom)); |
2103 } | 2181 } |
2104 | 2182 |
2105 | 2183 |
2106 void CheckThisIndexedPropertyDeleter( | 2184 void CheckThisIndexedPropertyDeleter( |
2107 uint32_t index, | 2185 uint32_t index, |
2108 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 2186 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
2109 CheckReturnValue(info); | 2187 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyDeleter)); |
2110 ApiTestFuzzer::Fuzz(); | 2188 ApiTestFuzzer::Fuzz(); |
2111 CHECK(info.This()->Equals(bottom)); | 2189 CHECK(info.This()->Equals(bottom)); |
2112 } | 2190 } |
2113 | 2191 |
2114 | 2192 |
2115 void CheckThisNamedPropertyDeleter( | 2193 void CheckThisNamedPropertyDeleter( |
2116 Local<String> property, | 2194 Local<String> property, |
2117 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 2195 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
2118 CheckReturnValue(info); | 2196 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyDeleter)); |
2119 ApiTestFuzzer::Fuzz(); | 2197 ApiTestFuzzer::Fuzz(); |
2120 CHECK(info.This()->Equals(bottom)); | 2198 CHECK(info.This()->Equals(bottom)); |
2121 } | 2199 } |
2122 | 2200 |
2123 | 2201 |
2124 void CheckThisIndexedPropertyEnumerator( | 2202 void CheckThisIndexedPropertyEnumerator( |
2125 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2203 const v8::PropertyCallbackInfo<v8::Array>& info) { |
2126 CheckReturnValue(info); | 2204 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyEnumerator)); |
2127 ApiTestFuzzer::Fuzz(); | 2205 ApiTestFuzzer::Fuzz(); |
2128 CHECK(info.This()->Equals(bottom)); | 2206 CHECK(info.This()->Equals(bottom)); |
2129 } | 2207 } |
2130 | 2208 |
2131 | 2209 |
2132 void CheckThisNamedPropertyEnumerator( | 2210 void CheckThisNamedPropertyEnumerator( |
2133 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2211 const v8::PropertyCallbackInfo<v8::Array>& info) { |
2134 CheckReturnValue(info); | 2212 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); |
2135 ApiTestFuzzer::Fuzz(); | 2213 ApiTestFuzzer::Fuzz(); |
2136 CHECK(info.This()->Equals(bottom)); | 2214 CHECK(info.This()->Equals(bottom)); |
2137 } | 2215 } |
2138 | 2216 |
2139 | 2217 |
2140 THREADED_TEST(PropertyHandlerInPrototype) { | 2218 THREADED_TEST(PropertyHandlerInPrototype) { |
2141 LocalContext env; | 2219 LocalContext env; |
2142 v8::HandleScope scope(env->GetIsolate()); | 2220 v8::HandleScope scope(env->GetIsolate()); |
2143 | 2221 |
2144 // Set up a prototype chain with three interceptors. | 2222 // Set up a prototype chain with three interceptors. |
(...skipping 8485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10630 " result" | 10708 " result" |
10631 "} catch(e) {" | 10709 "} catch(e) {" |
10632 " e" | 10710 " e" |
10633 "};"); | 10711 "};"); |
10634 CHECK_EQ(239 * 10, value->Int32Value()); | 10712 CHECK_EQ(239 * 10, value->Int32Value()); |
10635 } | 10713 } |
10636 | 10714 |
10637 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, | 10715 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, |
10638 const AccessorInfo& info) { | 10716 const AccessorInfo& info) { |
10639 ApiTestFuzzer::Fuzz(); | 10717 ApiTestFuzzer::Fuzz(); |
10640 CheckReturnValue(info); | 10718 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); |
10641 int* call_count = | 10719 int* call_count = |
10642 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); | 10720 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); |
10643 ++(*call_count); | 10721 ++(*call_count); |
10644 if ((*call_count) % 20 == 0) { | 10722 if ((*call_count) % 20 == 0) { |
10645 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 10723 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
10646 } | 10724 } |
10647 return v8::Handle<Value>(); | 10725 return v8::Handle<Value>(); |
10648 } | 10726 } |
10649 | 10727 |
10650 static v8::Handle<Value> FastApiCallback_TrivialSignature( | 10728 static v8::Handle<Value> FastApiCallback_TrivialSignature( |
10651 const v8::Arguments& args) { | 10729 const v8::Arguments& args) { |
10652 ApiTestFuzzer::Fuzz(); | 10730 ApiTestFuzzer::Fuzz(); |
10653 CheckReturnValue(args); | 10731 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); |
10654 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 10732 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
10655 CHECK_EQ(isolate, args.GetIsolate()); | 10733 CHECK_EQ(isolate, args.GetIsolate()); |
10656 CHECK_EQ(args.This(), args.Holder()); | 10734 CHECK_EQ(args.This(), args.Holder()); |
10657 CHECK(args.Data()->Equals(v8_str("method_data"))); | 10735 CHECK(args.Data()->Equals(v8_str("method_data"))); |
10658 return v8::Integer::New(args[0]->Int32Value() + 1); | 10736 return v8::Integer::New(args[0]->Int32Value() + 1); |
10659 } | 10737 } |
10660 | 10738 |
10661 static v8::Handle<Value> FastApiCallback_SimpleSignature( | 10739 static v8::Handle<Value> FastApiCallback_SimpleSignature( |
10662 const v8::Arguments& args) { | 10740 const v8::Arguments& args) { |
10663 ApiTestFuzzer::Fuzz(); | 10741 ApiTestFuzzer::Fuzz(); |
10664 CheckReturnValue(args); | 10742 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); |
10665 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 10743 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
10666 CHECK_EQ(isolate, args.GetIsolate()); | 10744 CHECK_EQ(isolate, args.GetIsolate()); |
10667 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); | 10745 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); |
10668 CHECK(args.Data()->Equals(v8_str("method_data"))); | 10746 CHECK(args.Data()->Equals(v8_str("method_data"))); |
10669 // Note, we're using HasRealNamedProperty instead of Has to avoid | 10747 // Note, we're using HasRealNamedProperty instead of Has to avoid |
10670 // invoking the interceptor again. | 10748 // invoking the interceptor again. |
10671 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); | 10749 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); |
10672 return v8::Integer::New(args[0]->Int32Value() + 1); | 10750 return v8::Integer::New(args[0]->Int32Value() + 1); |
10673 } | 10751 } |
10674 | 10752 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10742 static Handle<Value> DoDirectGetter() { | 10820 static Handle<Value> DoDirectGetter() { |
10743 if (++p_getter_count % 3 == 0) { | 10821 if (++p_getter_count % 3 == 0) { |
10744 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 10822 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
10745 GenerateSomeGarbage(); | 10823 GenerateSomeGarbage(); |
10746 } | 10824 } |
10747 return v8_str("Direct Getter Result"); | 10825 return v8_str("Direct Getter Result"); |
10748 } | 10826 } |
10749 | 10827 |
10750 static v8::Handle<v8::Value> DirectGetter(Local<String> name, | 10828 static v8::Handle<v8::Value> DirectGetter(Local<String> name, |
10751 const v8::AccessorInfo& info) { | 10829 const v8::AccessorInfo& info) { |
10752 CheckReturnValue(info); | 10830 CheckReturnValue(info, FUNCTION_ADDR(DirectGetter)); |
10753 info.GetReturnValue().Set(v8_str("Garbage")); | 10831 info.GetReturnValue().Set(v8_str("Garbage")); |
10754 return DoDirectGetter(); | 10832 return DoDirectGetter(); |
10755 } | 10833 } |
10756 | 10834 |
10757 static v8::Handle<v8::Value> DirectGetterIndirect( | 10835 static v8::Handle<v8::Value> DirectGetterIndirect( |
10758 Local<String> name, | 10836 Local<String> name, |
10759 const v8::AccessorInfo& info) { | 10837 const v8::AccessorInfo& info) { |
10760 CheckReturnValue(info); | 10838 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterIndirect)); |
10761 info.GetReturnValue().Set(DoDirectGetter()); | 10839 info.GetReturnValue().Set(DoDirectGetter()); |
10762 return v8::Handle<v8::Value>(); | 10840 return v8::Handle<v8::Value>(); |
10763 } | 10841 } |
10764 | 10842 |
10765 static void DirectGetterCallback( | 10843 static void DirectGetterCallback( |
10766 Local<String> name, | 10844 Local<String> name, |
10767 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10845 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10768 CheckReturnValue(info); | 10846 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); |
10769 info.GetReturnValue().Set(DoDirectGetter()); | 10847 info.GetReturnValue().Set(DoDirectGetter()); |
10770 } | 10848 } |
10771 | 10849 |
10772 | 10850 |
10773 template<typename Accessor> | 10851 template<typename Accessor> |
10774 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { | 10852 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { |
10775 LocalContext context; | 10853 LocalContext context; |
10776 v8::HandleScope scope(context->GetIsolate()); | 10854 v8::HandleScope scope(context->GetIsolate()); |
10777 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); | 10855 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); |
10778 obj->SetAccessor(v8_str("p1"), accessor); | 10856 obj->SetAccessor(v8_str("p1"), accessor); |
(...skipping 8591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19370 i::Semaphore* sem_; | 19448 i::Semaphore* sem_; |
19371 volatile int sem_value_; | 19449 volatile int sem_value_; |
19372 }; | 19450 }; |
19373 | 19451 |
19374 | 19452 |
19375 THREADED_TEST(SemaphoreInterruption) { | 19453 THREADED_TEST(SemaphoreInterruption) { |
19376 ThreadInterruptTest().RunTest(); | 19454 ThreadInterruptTest().RunTest(); |
19377 } | 19455 } |
19378 | 19456 |
19379 #endif // WIN32 | 19457 #endif // WIN32 |
OLD | NEW |