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