| 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 |
| 1030 | 1108 |
| 1031 template<typename T> | 1109 template<typename T> |
| 1032 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); | 1110 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); |
| 1033 | 1111 |
| 1034 // constant return values | 1112 // constant return values |
| 1035 static int32_t fast_return_value_int32 = 471; | 1113 static int32_t fast_return_value_int32 = 471; |
| 1036 static uint32_t fast_return_value_uint32 = 571; | 1114 static uint32_t fast_return_value_uint32 = 571; |
| 1037 static const double kFastReturnValueDouble = 2.7; | 1115 static const double kFastReturnValueDouble = 2.7; |
| 1038 // variable return values | 1116 // variable return values |
| 1039 static bool fast_return_value_bool = false; | 1117 static bool fast_return_value_bool = false; |
| 1040 enum ReturnValueOddball { | 1118 enum ReturnValueOddball { |
| 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 |
| 1126 // Helper function to avoid compiler error: insufficient contextual information |
| 1127 // to determine type when applying FUNCTION_ADDR to a template function. |
| 1128 static i::Address address_of(v8::FunctionCallback callback) { |
| 1129 return FUNCTION_ADDR(callback); |
| 1130 } |
| 1131 |
| 1048 template<> | 1132 template<> |
| 1049 void FastReturnValueCallback<int32_t>( | 1133 void FastReturnValueCallback<int32_t>( |
| 1050 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1134 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1051 CheckReturnValue(info); | 1135 CheckReturnValue(info, address_of(FastReturnValueCallback<int32_t>)); |
| 1052 info.GetReturnValue().Set(fast_return_value_int32); | 1136 info.GetReturnValue().Set(fast_return_value_int32); |
| 1053 } | 1137 } |
| 1054 | 1138 |
| 1055 template<> | 1139 template<> |
| 1056 void FastReturnValueCallback<uint32_t>( | 1140 void FastReturnValueCallback<uint32_t>( |
| 1057 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1141 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1058 CheckReturnValue(info); | 1142 CheckReturnValue(info, address_of(FastReturnValueCallback<uint32_t>)); |
| 1059 info.GetReturnValue().Set(fast_return_value_uint32); | 1143 info.GetReturnValue().Set(fast_return_value_uint32); |
| 1060 } | 1144 } |
| 1061 | 1145 |
| 1062 template<> | 1146 template<> |
| 1063 void FastReturnValueCallback<double>( | 1147 void FastReturnValueCallback<double>( |
| 1064 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1148 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1065 CheckReturnValue(info); | 1149 CheckReturnValue(info, address_of(FastReturnValueCallback<double>)); |
| 1066 info.GetReturnValue().Set(kFastReturnValueDouble); | 1150 info.GetReturnValue().Set(kFastReturnValueDouble); |
| 1067 } | 1151 } |
| 1068 | 1152 |
| 1069 template<> | 1153 template<> |
| 1070 void FastReturnValueCallback<bool>( | 1154 void FastReturnValueCallback<bool>( |
| 1071 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1155 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1072 CheckReturnValue(info); | 1156 CheckReturnValue(info, address_of(FastReturnValueCallback<bool>)); |
| 1073 info.GetReturnValue().Set(fast_return_value_bool); | 1157 info.GetReturnValue().Set(fast_return_value_bool); |
| 1074 } | 1158 } |
| 1075 | 1159 |
| 1076 template<> | 1160 template<> |
| 1077 void FastReturnValueCallback<void>( | 1161 void FastReturnValueCallback<void>( |
| 1078 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1162 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1079 CheckReturnValue(info); | 1163 CheckReturnValue(info, address_of(FastReturnValueCallback<void>)); |
| 1080 switch (fast_return_value_void) { | 1164 switch (fast_return_value_void) { |
| 1081 case kNullReturnValue: | 1165 case kNullReturnValue: |
| 1082 info.GetReturnValue().SetNull(); | 1166 info.GetReturnValue().SetNull(); |
| 1083 break; | 1167 break; |
| 1084 case kUndefinedReturnValue: | 1168 case kUndefinedReturnValue: |
| 1085 info.GetReturnValue().SetUndefined(); | 1169 info.GetReturnValue().SetUndefined(); |
| 1086 break; | 1170 break; |
| 1087 case kEmptyStringReturnValue: | 1171 case kEmptyStringReturnValue: |
| 1088 info.GetReturnValue().SetEmptyString(); | 1172 info.GetReturnValue().SetEmptyString(); |
| 1089 break; | 1173 break; |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 Local<Script> script = v8_compile("obj[900]"); | 2130 Local<Script> script = v8_compile("obj[900]"); |
| 2047 CHECK_EQ(script->Run()->Int32Value(), 900); | 2131 CHECK_EQ(script->Run()->Int32Value(), 900); |
| 2048 } | 2132 } |
| 2049 | 2133 |
| 2050 | 2134 |
| 2051 v8::Handle<v8::Object> bottom; | 2135 v8::Handle<v8::Object> bottom; |
| 2052 | 2136 |
| 2053 static void CheckThisIndexedPropertyHandler( | 2137 static void CheckThisIndexedPropertyHandler( |
| 2054 uint32_t index, | 2138 uint32_t index, |
| 2055 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2139 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2056 CheckReturnValue(info); | 2140 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyHandler)); |
| 2057 ApiTestFuzzer::Fuzz(); | 2141 ApiTestFuzzer::Fuzz(); |
| 2058 CHECK(info.This()->Equals(bottom)); | 2142 CHECK(info.This()->Equals(bottom)); |
| 2059 } | 2143 } |
| 2060 | 2144 |
| 2061 static void CheckThisNamedPropertyHandler( | 2145 static void CheckThisNamedPropertyHandler( |
| 2062 Local<String> name, | 2146 Local<String> name, |
| 2063 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2147 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2064 CheckReturnValue(info); | 2148 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyHandler)); |
| 2065 ApiTestFuzzer::Fuzz(); | 2149 ApiTestFuzzer::Fuzz(); |
| 2066 CHECK(info.This()->Equals(bottom)); | 2150 CHECK(info.This()->Equals(bottom)); |
| 2067 } | 2151 } |
| 2068 | 2152 |
| 2069 void CheckThisIndexedPropertySetter( | 2153 void CheckThisIndexedPropertySetter( |
| 2070 uint32_t index, | 2154 uint32_t index, |
| 2071 Local<Value> value, | 2155 Local<Value> value, |
| 2072 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2156 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2073 CheckReturnValue(info); | 2157 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertySetter)); |
| 2074 ApiTestFuzzer::Fuzz(); | 2158 ApiTestFuzzer::Fuzz(); |
| 2075 CHECK(info.This()->Equals(bottom)); | 2159 CHECK(info.This()->Equals(bottom)); |
| 2076 } | 2160 } |
| 2077 | 2161 |
| 2078 | 2162 |
| 2079 void CheckThisNamedPropertySetter( | 2163 void CheckThisNamedPropertySetter( |
| 2080 Local<String> property, | 2164 Local<String> property, |
| 2081 Local<Value> value, | 2165 Local<Value> value, |
| 2082 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2166 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2083 CheckReturnValue(info); | 2167 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertySetter)); |
| 2084 ApiTestFuzzer::Fuzz(); | 2168 ApiTestFuzzer::Fuzz(); |
| 2085 CHECK(info.This()->Equals(bottom)); | 2169 CHECK(info.This()->Equals(bottom)); |
| 2086 } | 2170 } |
| 2087 | 2171 |
| 2088 void CheckThisIndexedPropertyQuery( | 2172 void CheckThisIndexedPropertyQuery( |
| 2089 uint32_t index, | 2173 uint32_t index, |
| 2090 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2174 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 2091 CheckReturnValue(info); | 2175 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyQuery)); |
| 2092 ApiTestFuzzer::Fuzz(); | 2176 ApiTestFuzzer::Fuzz(); |
| 2093 CHECK(info.This()->Equals(bottom)); | 2177 CHECK(info.This()->Equals(bottom)); |
| 2094 } | 2178 } |
| 2095 | 2179 |
| 2096 | 2180 |
| 2097 void CheckThisNamedPropertyQuery( | 2181 void CheckThisNamedPropertyQuery( |
| 2098 Local<String> property, | 2182 Local<String> property, |
| 2099 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2183 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 2100 CheckReturnValue(info); | 2184 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyQuery)); |
| 2101 ApiTestFuzzer::Fuzz(); | 2185 ApiTestFuzzer::Fuzz(); |
| 2102 CHECK(info.This()->Equals(bottom)); | 2186 CHECK(info.This()->Equals(bottom)); |
| 2103 } | 2187 } |
| 2104 | 2188 |
| 2105 | 2189 |
| 2106 void CheckThisIndexedPropertyDeleter( | 2190 void CheckThisIndexedPropertyDeleter( |
| 2107 uint32_t index, | 2191 uint32_t index, |
| 2108 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 2192 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 2109 CheckReturnValue(info); | 2193 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyDeleter)); |
| 2110 ApiTestFuzzer::Fuzz(); | 2194 ApiTestFuzzer::Fuzz(); |
| 2111 CHECK(info.This()->Equals(bottom)); | 2195 CHECK(info.This()->Equals(bottom)); |
| 2112 } | 2196 } |
| 2113 | 2197 |
| 2114 | 2198 |
| 2115 void CheckThisNamedPropertyDeleter( | 2199 void CheckThisNamedPropertyDeleter( |
| 2116 Local<String> property, | 2200 Local<String> property, |
| 2117 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 2201 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 2118 CheckReturnValue(info); | 2202 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyDeleter)); |
| 2119 ApiTestFuzzer::Fuzz(); | 2203 ApiTestFuzzer::Fuzz(); |
| 2120 CHECK(info.This()->Equals(bottom)); | 2204 CHECK(info.This()->Equals(bottom)); |
| 2121 } | 2205 } |
| 2122 | 2206 |
| 2123 | 2207 |
| 2124 void CheckThisIndexedPropertyEnumerator( | 2208 void CheckThisIndexedPropertyEnumerator( |
| 2125 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2209 const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 2126 CheckReturnValue(info); | 2210 CheckReturnValue(info, FUNCTION_ADDR(CheckThisIndexedPropertyEnumerator)); |
| 2127 ApiTestFuzzer::Fuzz(); | 2211 ApiTestFuzzer::Fuzz(); |
| 2128 CHECK(info.This()->Equals(bottom)); | 2212 CHECK(info.This()->Equals(bottom)); |
| 2129 } | 2213 } |
| 2130 | 2214 |
| 2131 | 2215 |
| 2132 void CheckThisNamedPropertyEnumerator( | 2216 void CheckThisNamedPropertyEnumerator( |
| 2133 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2217 const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 2134 CheckReturnValue(info); | 2218 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); |
| 2135 ApiTestFuzzer::Fuzz(); | 2219 ApiTestFuzzer::Fuzz(); |
| 2136 CHECK(info.This()->Equals(bottom)); | 2220 CHECK(info.This()->Equals(bottom)); |
| 2137 } | 2221 } |
| 2138 | 2222 |
| 2139 | 2223 |
| 2140 THREADED_TEST(PropertyHandlerInPrototype) { | 2224 THREADED_TEST(PropertyHandlerInPrototype) { |
| 2141 LocalContext env; | 2225 LocalContext env; |
| 2142 v8::HandleScope scope(env->GetIsolate()); | 2226 v8::HandleScope scope(env->GetIsolate()); |
| 2143 | 2227 |
| 2144 // Set up a prototype chain with three interceptors. | 2228 // Set up a prototype chain with three interceptors. |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2623 | 2707 |
| 2624 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { | 2708 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { |
| 2625 i::FLAG_harmony_array_buffer = true; | 2709 i::FLAG_harmony_array_buffer = true; |
| 2626 i::FLAG_harmony_typed_arrays = true; | 2710 i::FLAG_harmony_typed_arrays = true; |
| 2627 | 2711 |
| 2628 LocalContext env; | 2712 LocalContext env; |
| 2629 v8::Isolate* isolate = env->GetIsolate(); | 2713 v8::Isolate* isolate = env->GetIsolate(); |
| 2630 v8::HandleScope handle_scope(isolate); | 2714 v8::HandleScope handle_scope(isolate); |
| 2631 | 2715 |
| 2632 | 2716 |
| 2633 v8::Handle<v8::Value> result = | 2717 v8::Local<v8::Value> result = |
| 2634 CompileRun("var ab1 = new ArrayBuffer(2);" | 2718 CompileRun("var ab1 = new ArrayBuffer(2);" |
| 2635 "var u8_a = new Uint8Array(ab1);" | 2719 "var u8_a = new Uint8Array(ab1);" |
| 2636 "u8_a[0] = 0xAA;" | 2720 "u8_a[0] = 0xAA;" |
| 2637 "u8_a[1] = 0xFF; u8_a.buffer"); | 2721 "u8_a[1] = 0xFF; u8_a.buffer"); |
| 2638 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); | 2722 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); |
| 2639 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); | 2723 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
| 2640 CHECK(!ab1->IsExternal()); | 2724 CHECK(!ab1->IsExternal()); |
| 2641 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); | 2725 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); |
| 2642 CHECK(ab1->IsExternal()); | 2726 CHECK(ab1->IsExternal()); |
| 2643 | 2727 |
| 2644 result = CompileRun("ab1.byteLength"); | 2728 result = CompileRun("ab1.byteLength"); |
| 2645 CHECK_EQ(2, result->Int32Value()); | 2729 CHECK_EQ(2, result->Int32Value()); |
| 2646 result = CompileRun("u8_a[0]"); | 2730 result = CompileRun("u8_a[0]"); |
| 2647 CHECK_EQ(0xAA, result->Int32Value()); | 2731 CHECK_EQ(0xAA, result->Int32Value()); |
| 2648 result = CompileRun("u8_a[1]"); | 2732 result = CompileRun("u8_a[1]"); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2769 "var u8a = new Uint8Array(ab, 1, 1023);" | 2853 "var u8a = new Uint8Array(ab, 1, 1023);" |
| 2770 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" | 2854 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" |
| 2771 "var i8a = new Int8Array(ab, 1, 1023);" | 2855 "var i8a = new Int8Array(ab, 1, 1023);" |
| 2772 "var u16a = new Uint16Array(ab, 2, 511);" | 2856 "var u16a = new Uint16Array(ab, 2, 511);" |
| 2773 "var i16a = new Int16Array(ab, 2, 511);" | 2857 "var i16a = new Int16Array(ab, 2, 511);" |
| 2774 "var u32a = new Uint32Array(ab, 4, 255);" | 2858 "var u32a = new Uint32Array(ab, 4, 255);" |
| 2775 "var i32a = new Int32Array(ab, 4, 255);" | 2859 "var i32a = new Int32Array(ab, 4, 255);" |
| 2776 "var f32a = new Float32Array(ab, 4, 255);" | 2860 "var f32a = new Float32Array(ab, 4, 255);" |
| 2777 "var f64a = new Float64Array(ab, 8, 127);"); | 2861 "var f64a = new Float64Array(ab, 8, 127);"); |
| 2778 | 2862 |
| 2779 v8::Handle<v8::ArrayBuffer> ab(v8::ArrayBuffer::Cast(*CompileRun("ab"))); | 2863 v8::Handle<v8::ArrayBuffer> ab = |
| 2864 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 2780 | 2865 |
| 2781 v8::Handle<v8::Uint8Array> u8a(v8::Uint8Array::Cast(*CompileRun("u8a"))); | 2866 v8::Handle<v8::Uint8Array> u8a = |
| 2782 v8::Handle<v8::Uint8ClampedArray> u8c( | 2867 v8::Handle<v8::Uint8Array>::Cast(CompileRun("u8a")); |
| 2783 v8::Uint8ClampedArray::Cast(*CompileRun("u8c"))); | 2868 v8::Handle<v8::Uint8ClampedArray> u8c = |
| 2784 v8::Handle<v8::Int8Array> i8a(v8::Int8Array::Cast(*CompileRun("i8a"))); | 2869 v8::Handle<v8::Uint8ClampedArray>::Cast(CompileRun("u8c")); |
| 2870 v8::Handle<v8::Int8Array> i8a = |
| 2871 v8::Handle<v8::Int8Array>::Cast(CompileRun("i8a")); |
| 2785 | 2872 |
| 2786 v8::Handle<v8::Uint16Array> u16a( | 2873 v8::Handle<v8::Uint16Array> u16a = |
| 2787 v8::Uint16Array::Cast(*CompileRun("u16a"))); | 2874 v8::Handle<v8::Uint16Array>::Cast(CompileRun("u16a")); |
| 2788 v8::Handle<v8::Int16Array> i16a( | 2875 v8::Handle<v8::Int16Array> i16a = |
| 2789 v8::Int16Array::Cast(*CompileRun("i16a"))); | 2876 v8::Handle<v8::Int16Array>::Cast(CompileRun("i16a")); |
| 2790 v8::Handle<v8::Uint32Array> u32a( | 2877 v8::Handle<v8::Uint32Array> u32a = |
| 2791 v8::Uint32Array::Cast(*CompileRun("u32a"))); | 2878 v8::Handle<v8::Uint32Array>::Cast(CompileRun("u32a")); |
| 2792 v8::Handle<v8::Int32Array> i32a( | 2879 v8::Handle<v8::Int32Array> i32a = |
| 2793 v8::Int32Array::Cast(*CompileRun("i32a"))); | 2880 v8::Handle<v8::Int32Array>::Cast(CompileRun("i32a")); |
| 2794 v8::Handle<v8::Float32Array> f32a( | 2881 v8::Handle<v8::Float32Array> f32a = |
| 2795 v8::Float32Array::Cast(*CompileRun("f32a"))); | 2882 v8::Handle<v8::Float32Array>::Cast(CompileRun("f32a")); |
| 2796 v8::Handle<v8::Float64Array> f64a( | 2883 v8::Handle<v8::Float64Array> f64a = |
| 2797 v8::Float64Array::Cast(*CompileRun("f64a"))); | 2884 v8::Handle<v8::Float64Array>::Cast(CompileRun("f64a")); |
| 2798 | 2885 |
| 2799 ScopedArrayBufferContents contents(ab->Externalize()); | 2886 ScopedArrayBufferContents contents(ab->Externalize()); |
| 2800 ab->Neuter(); | 2887 ab->Neuter(); |
| 2801 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); | 2888 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); |
| 2802 CheckIsNeutered(u8a); | 2889 CheckIsNeutered(u8a); |
| 2803 CheckIsNeutered(u8c); | 2890 CheckIsNeutered(u8c); |
| 2804 CheckIsNeutered(i8a); | 2891 CheckIsNeutered(i8a); |
| 2805 CheckIsNeutered(u16a); | 2892 CheckIsNeutered(u16a); |
| 2806 CheckIsNeutered(i16a); | 2893 CheckIsNeutered(i16a); |
| 2807 CheckIsNeutered(u32a); | 2894 CheckIsNeutered(u32a); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3039 Local<String> str = v8_str("str"); | 3126 Local<String> str = v8_str("str"); |
| 3040 global_handles = | 3127 global_handles = |
| 3041 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); | 3128 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
| 3042 initial_handle_count = global_handles->NumberOfGlobalHandles(); | 3129 initial_handle_count = global_handles->NumberOfGlobalHandles(); |
| 3043 global.Reset(isolate, str); | 3130 global.Reset(isolate, str); |
| 3044 } | 3131 } |
| 3045 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); | 3132 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); |
| 3046 String* str = global.ClearAndLeak(); | 3133 String* str = global.ClearAndLeak(); |
| 3047 CHECK(global.IsEmpty()); | 3134 CHECK(global.IsEmpty()); |
| 3048 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); | 3135 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); |
| 3049 v8::Persistent<String>* new_global = | 3136 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); |
| 3050 reinterpret_cast<v8::Persistent<String>*>(&str); | |
| 3051 new_global->Dispose(); | |
| 3052 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count); | 3137 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count); |
| 3053 } | 3138 } |
| 3054 | 3139 |
| 3055 | 3140 |
| 3056 THREADED_TEST(GlobalHandleUpcast) { | 3141 THREADED_TEST(GlobalHandleUpcast) { |
| 3057 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3142 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 3058 v8::HandleScope scope(isolate); | 3143 v8::HandleScope scope(isolate); |
| 3059 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); | 3144 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); |
| 3060 v8::Persistent<String> global_string(isolate, local); | 3145 v8::Persistent<String> global_string(isolate, local); |
| 3061 #ifdef V8_USE_UNSAFE_HANDLES | 3146 #ifdef V8_USE_UNSAFE_HANDLES |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3095 | 3180 |
| 3096 static void WeakPointerCallback(v8::Isolate* isolate, | 3181 static void WeakPointerCallback(v8::Isolate* isolate, |
| 3097 Persistent<Value>* handle, | 3182 Persistent<Value>* handle, |
| 3098 WeakCallCounter* counter) { | 3183 WeakCallCounter* counter) { |
| 3099 CHECK_EQ(1234, counter->id()); | 3184 CHECK_EQ(1234, counter->id()); |
| 3100 counter->increment(); | 3185 counter->increment(); |
| 3101 handle->Dispose(isolate); | 3186 handle->Dispose(isolate); |
| 3102 } | 3187 } |
| 3103 | 3188 |
| 3104 | 3189 |
| 3190 static UniqueId MakeUniqueId(const Persistent<Value>& p) { |
| 3191 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p))); |
| 3192 } |
| 3193 |
| 3194 |
| 3105 THREADED_TEST(ApiObjectGroups) { | 3195 THREADED_TEST(ApiObjectGroups) { |
| 3106 LocalContext env; | 3196 LocalContext env; |
| 3107 v8::Isolate* iso = env->GetIsolate(); | 3197 v8::Isolate* iso = env->GetIsolate(); |
| 3108 HandleScope scope(iso); | 3198 HandleScope scope(iso); |
| 3109 | 3199 |
| 3110 Persistent<Value> g1s1; | 3200 Persistent<Value> g1s1; |
| 3111 Persistent<Value> g1s2; | 3201 Persistent<Value> g1s2; |
| 3112 Persistent<Value> g1c1; | 3202 Persistent<Value> g1c1; |
| 3113 Persistent<Value> g2s1; | 3203 Persistent<Value> g2s1; |
| 3114 Persistent<Value> g2s2; | 3204 Persistent<Value> g2s2; |
| 3115 Persistent<Value> g2c1; | 3205 Persistent<Value> g2c1; |
| 3116 | 3206 |
| 3117 WeakCallCounter counter(1234); | 3207 WeakCallCounter counter(1234); |
| 3118 | 3208 |
| 3119 { | 3209 { |
| 3120 HandleScope scope(iso); | 3210 HandleScope scope(iso); |
| 3121 g1s1.Reset(iso, Object::New()); | 3211 g1s1.Reset(iso, Object::New()); |
| 3122 g1s2.Reset(iso, Object::New()); | 3212 g1s2.Reset(iso, Object::New()); |
| 3123 g1c1.Reset(iso, Object::New()); | 3213 g1c1.Reset(iso, Object::New()); |
| 3124 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3214 g1s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3125 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3215 g1s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3126 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3216 g1c1.MakeWeak(&counter, &WeakPointerCallback); |
| 3127 | 3217 |
| 3128 g2s1.Reset(iso, Object::New()); | 3218 g2s1.Reset(iso, Object::New()); |
| 3129 g2s2.Reset(iso, Object::New()); | 3219 g2s2.Reset(iso, Object::New()); |
| 3130 g2c1.Reset(iso, Object::New()); | 3220 g2c1.Reset(iso, Object::New()); |
| 3131 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3221 g2s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3132 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3222 g2s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3133 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3223 g2c1.MakeWeak(&counter, &WeakPointerCallback); |
| 3134 } | 3224 } |
| 3135 | 3225 |
| 3136 Persistent<Value> root(iso, g1s1); // make a root. | 3226 Persistent<Value> root(iso, g1s1); // make a root. |
| 3137 | 3227 |
| 3138 // Connect group 1 and 2, make a cycle. | 3228 // Connect group 1 and 2, make a cycle. |
| 3139 { | 3229 { |
| 3140 HandleScope scope(iso); | 3230 HandleScope scope(iso); |
| 3141 CHECK(Local<Object>::New(iso, g1s2.As<Object>())-> | 3231 CHECK(Local<Object>::New(iso, g1s2.As<Object>())-> |
| 3142 Set(0, Local<Value>(*g2s2))); | 3232 Set(0, Local<Value>::New(iso, g2s2))); |
| 3143 CHECK(Local<Object>::New(iso, g2s1.As<Object>())-> | 3233 CHECK(Local<Object>::New(iso, g2s1.As<Object>())-> |
| 3144 Set(0, Local<Value>(*g1s1))); | 3234 Set(0, Local<Value>::New(iso, g1s1))); |
| 3145 } | 3235 } |
| 3146 | 3236 |
| 3147 { | 3237 { |
| 3148 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3238 UniqueId id1 = MakeUniqueId(g1s1); |
| 3149 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); | 3239 UniqueId id2 = MakeUniqueId(g2s2); |
| 3150 iso->SetObjectGroupId(g1s1, id1); | 3240 iso->SetObjectGroupId(g1s1, id1); |
| 3151 iso->SetObjectGroupId(g1s2, id1); | 3241 iso->SetObjectGroupId(g1s2, id1); |
| 3152 iso->SetReferenceFromGroup(id1, g1c1); | 3242 iso->SetReferenceFromGroup(id1, g1c1); |
| 3153 iso->SetObjectGroupId(g2s1, id2); | 3243 iso->SetObjectGroupId(g2s1, id2); |
| 3154 iso->SetObjectGroupId(g2s2, id2); | 3244 iso->SetObjectGroupId(g2s2, id2); |
| 3155 iso->SetReferenceFromGroup(id2, g2c1); | 3245 iso->SetReferenceFromGroup(id2, g2c1); |
| 3156 } | 3246 } |
| 3157 // Do a single full GC, ensure incremental marking is stopped. | 3247 // Do a single full GC, ensure incremental marking is stopped. |
| 3158 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3248 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
| 3159 iso)->heap(); | 3249 iso)->heap(); |
| 3160 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3250 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 3161 | 3251 |
| 3162 // All object should be alive. | 3252 // All object should be alive. |
| 3163 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3253 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3164 | 3254 |
| 3165 // Weaken the root. | 3255 // Weaken the root. |
| 3166 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3256 root.MakeWeak(&counter, &WeakPointerCallback); |
| 3167 // But make children strong roots---all the objects (except for children) | 3257 // But make children strong roots---all the objects (except for children) |
| 3168 // should be collectable now. | 3258 // should be collectable now. |
| 3169 g1c1.ClearWeak(iso); | 3259 g1c1.ClearWeak(iso); |
| 3170 g2c1.ClearWeak(iso); | 3260 g2c1.ClearWeak(iso); |
| 3171 | 3261 |
| 3172 // Groups are deleted, rebuild groups. | 3262 // Groups are deleted, rebuild groups. |
| 3173 { | 3263 { |
| 3174 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3264 UniqueId id1 = MakeUniqueId(g1s1); |
| 3175 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); | 3265 UniqueId id2 = MakeUniqueId(g2s2); |
| 3176 iso->SetObjectGroupId(g1s1, id1); | 3266 iso->SetObjectGroupId(g1s1, id1); |
| 3177 iso->SetObjectGroupId(g1s2, id1); | 3267 iso->SetObjectGroupId(g1s2, id1); |
| 3178 iso->SetReferenceFromGroup(id1, g1c1); | 3268 iso->SetReferenceFromGroup(id1, g1c1); |
| 3179 iso->SetObjectGroupId(g2s1, id2); | 3269 iso->SetObjectGroupId(g2s1, id2); |
| 3180 iso->SetObjectGroupId(g2s2, id2); | 3270 iso->SetObjectGroupId(g2s2, id2); |
| 3181 iso->SetReferenceFromGroup(id2, g2c1); | 3271 iso->SetReferenceFromGroup(id2, g2c1); |
| 3182 } | 3272 } |
| 3183 | 3273 |
| 3184 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3274 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 3185 | 3275 |
| 3186 // All objects should be gone. 5 global handles in total. | 3276 // All objects should be gone. 5 global handles in total. |
| 3187 CHECK_EQ(5, counter.NumberOfWeakCalls()); | 3277 CHECK_EQ(5, counter.NumberOfWeakCalls()); |
| 3188 | 3278 |
| 3189 // And now make children weak again and collect them. | 3279 // And now make children weak again and collect them. |
| 3190 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3280 g1c1.MakeWeak(&counter, &WeakPointerCallback); |
| 3191 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3281 g2c1.MakeWeak(&counter, &WeakPointerCallback); |
| 3192 | 3282 |
| 3193 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3283 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 3194 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3284 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3195 } | 3285 } |
| 3196 | 3286 |
| 3197 | 3287 |
| 3198 THREADED_TEST(ApiObjectGroupsCycle) { | 3288 THREADED_TEST(ApiObjectGroupsCycle) { |
| 3199 LocalContext env; | 3289 LocalContext env; |
| 3200 v8::Isolate* iso = env->GetIsolate(); | 3290 v8::Isolate* iso = env->GetIsolate(); |
| 3201 HandleScope scope(iso); | 3291 HandleScope scope(iso); |
| 3202 | 3292 |
| 3203 WeakCallCounter counter(1234); | 3293 WeakCallCounter counter(1234); |
| 3204 | 3294 |
| 3205 Persistent<Value> g1s1; | 3295 Persistent<Value> g1s1; |
| 3206 Persistent<Value> g1s2; | 3296 Persistent<Value> g1s2; |
| 3207 Persistent<Value> g2s1; | 3297 Persistent<Value> g2s1; |
| 3208 Persistent<Value> g2s2; | 3298 Persistent<Value> g2s2; |
| 3209 Persistent<Value> g3s1; | 3299 Persistent<Value> g3s1; |
| 3210 Persistent<Value> g3s2; | 3300 Persistent<Value> g3s2; |
| 3211 Persistent<Value> g4s1; | 3301 Persistent<Value> g4s1; |
| 3212 Persistent<Value> g4s2; | 3302 Persistent<Value> g4s2; |
| 3213 | 3303 |
| 3214 { | 3304 { |
| 3215 HandleScope scope(iso); | 3305 HandleScope scope(iso); |
| 3216 g1s1.Reset(iso, Object::New()); | 3306 g1s1.Reset(iso, Object::New()); |
| 3217 g1s2.Reset(iso, Object::New()); | 3307 g1s2.Reset(iso, Object::New()); |
| 3218 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3308 g1s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3219 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3309 g1s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3220 CHECK(g1s1.IsWeak(iso)); | 3310 CHECK(g1s1.IsWeak(iso)); |
| 3221 CHECK(g1s2.IsWeak(iso)); | 3311 CHECK(g1s2.IsWeak(iso)); |
| 3222 | 3312 |
| 3223 g2s1.Reset(iso, Object::New()); | 3313 g2s1.Reset(iso, Object::New()); |
| 3224 g2s2.Reset(iso, Object::New()); | 3314 g2s2.Reset(iso, Object::New()); |
| 3225 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3315 g2s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3226 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3316 g2s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3227 CHECK(g2s1.IsWeak(iso)); | 3317 CHECK(g2s1.IsWeak(iso)); |
| 3228 CHECK(g2s2.IsWeak(iso)); | 3318 CHECK(g2s2.IsWeak(iso)); |
| 3229 | 3319 |
| 3230 g3s1.Reset(iso, Object::New()); | 3320 g3s1.Reset(iso, Object::New()); |
| 3231 g3s2.Reset(iso, Object::New()); | 3321 g3s2.Reset(iso, Object::New()); |
| 3232 g3s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3322 g3s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3233 g3s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3323 g3s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3234 CHECK(g3s1.IsWeak(iso)); | 3324 CHECK(g3s1.IsWeak(iso)); |
| 3235 CHECK(g3s2.IsWeak(iso)); | 3325 CHECK(g3s2.IsWeak(iso)); |
| 3236 | 3326 |
| 3237 g4s1.Reset(iso, Object::New()); | 3327 g4s1.Reset(iso, Object::New()); |
| 3238 g4s2.Reset(iso, Object::New()); | 3328 g4s2.Reset(iso, Object::New()); |
| 3239 g4s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3329 g4s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3240 g4s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3330 g4s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3241 CHECK(g4s1.IsWeak(iso)); | 3331 CHECK(g4s1.IsWeak(iso)); |
| 3242 CHECK(g4s2.IsWeak(iso)); | 3332 CHECK(g4s2.IsWeak(iso)); |
| 3243 } | 3333 } |
| 3244 | 3334 |
| 3245 Persistent<Value> root(iso, g1s1); // make a root. | 3335 Persistent<Value> root(iso, g1s1); // make a root. |
| 3246 | 3336 |
| 3247 // Connect groups. We're building the following cycle: | 3337 // Connect groups. We're building the following cycle: |
| 3248 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | 3338 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other |
| 3249 // groups. | 3339 // groups. |
| 3250 { | 3340 { |
| 3251 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3341 UniqueId id1 = MakeUniqueId(g1s1); |
| 3252 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); | 3342 UniqueId id2 = MakeUniqueId(g2s1); |
| 3253 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); | 3343 UniqueId id3 = MakeUniqueId(g3s1); |
| 3254 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); | 3344 UniqueId id4 = MakeUniqueId(g4s1); |
| 3255 iso->SetObjectGroupId(g1s1, id1); | 3345 iso->SetObjectGroupId(g1s1, id1); |
| 3256 iso->SetObjectGroupId(g1s2, id1); | 3346 iso->SetObjectGroupId(g1s2, id1); |
| 3257 iso->SetReferenceFromGroup(id1, g2s1); | 3347 iso->SetReferenceFromGroup(id1, g2s1); |
| 3258 iso->SetObjectGroupId(g2s1, id2); | 3348 iso->SetObjectGroupId(g2s1, id2); |
| 3259 iso->SetObjectGroupId(g2s2, id2); | 3349 iso->SetObjectGroupId(g2s2, id2); |
| 3260 iso->SetReferenceFromGroup(id2, g3s1); | 3350 iso->SetReferenceFromGroup(id2, g3s1); |
| 3261 iso->SetObjectGroupId(g3s1, id3); | 3351 iso->SetObjectGroupId(g3s1, id3); |
| 3262 iso->SetObjectGroupId(g3s2, id3); | 3352 iso->SetObjectGroupId(g3s2, id3); |
| 3263 iso->SetReferenceFromGroup(id3, g4s1); | 3353 iso->SetReferenceFromGroup(id3, g4s1); |
| 3264 iso->SetObjectGroupId(g4s1, id4); | 3354 iso->SetObjectGroupId(g4s1, id4); |
| 3265 iso->SetObjectGroupId(g4s2, id4); | 3355 iso->SetObjectGroupId(g4s2, id4); |
| 3266 iso->SetReferenceFromGroup(id4, g1s1); | 3356 iso->SetReferenceFromGroup(id4, g1s1); |
| 3267 } | 3357 } |
| 3268 // Do a single full GC | 3358 // Do a single full GC |
| 3269 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3359 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
| 3270 iso)->heap(); | 3360 iso)->heap(); |
| 3271 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3361 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 3272 | 3362 |
| 3273 // All object should be alive. | 3363 // All object should be alive. |
| 3274 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3364 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3275 | 3365 |
| 3276 // Weaken the root. | 3366 // Weaken the root. |
| 3277 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3367 root.MakeWeak(&counter, &WeakPointerCallback); |
| 3278 | 3368 |
| 3279 // Groups are deleted, rebuild groups. | 3369 // Groups are deleted, rebuild groups. |
| 3280 { | 3370 { |
| 3281 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3371 UniqueId id1 = MakeUniqueId(g1s1); |
| 3282 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); | 3372 UniqueId id2 = MakeUniqueId(g2s1); |
| 3283 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); | 3373 UniqueId id3 = MakeUniqueId(g3s1); |
| 3284 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); | 3374 UniqueId id4 = MakeUniqueId(g4s1); |
| 3285 iso->SetObjectGroupId(g1s1, id1); | 3375 iso->SetObjectGroupId(g1s1, id1); |
| 3286 iso->SetObjectGroupId(g1s2, id1); | 3376 iso->SetObjectGroupId(g1s2, id1); |
| 3287 iso->SetReferenceFromGroup(id1, g2s1); | 3377 iso->SetReferenceFromGroup(id1, g2s1); |
| 3288 iso->SetObjectGroupId(g2s1, id2); | 3378 iso->SetObjectGroupId(g2s1, id2); |
| 3289 iso->SetObjectGroupId(g2s2, id2); | 3379 iso->SetObjectGroupId(g2s2, id2); |
| 3290 iso->SetReferenceFromGroup(id2, g3s1); | 3380 iso->SetReferenceFromGroup(id2, g3s1); |
| 3291 iso->SetObjectGroupId(g3s1, id3); | 3381 iso->SetObjectGroupId(g3s1, id3); |
| 3292 iso->SetObjectGroupId(g3s2, id3); | 3382 iso->SetObjectGroupId(g3s2, id3); |
| 3293 iso->SetReferenceFromGroup(id3, g4s1); | 3383 iso->SetReferenceFromGroup(id3, g4s1); |
| 3294 iso->SetObjectGroupId(g4s1, id4); | 3384 iso->SetObjectGroupId(g4s1, id4); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3318 Persistent<Value> g1s2; | 3408 Persistent<Value> g1s2; |
| 3319 Persistent<Value> g2s1; | 3409 Persistent<Value> g2s1; |
| 3320 Persistent<Value> g2s2; | 3410 Persistent<Value> g2s2; |
| 3321 Persistent<Value> g3s1; | 3411 Persistent<Value> g3s1; |
| 3322 Persistent<Value> g3s2; | 3412 Persistent<Value> g3s2; |
| 3323 | 3413 |
| 3324 { | 3414 { |
| 3325 HandleScope scope(iso); | 3415 HandleScope scope(iso); |
| 3326 g1s1.Reset(iso, Object::New()); | 3416 g1s1.Reset(iso, Object::New()); |
| 3327 g1s2.Reset(iso, Object::New()); | 3417 g1s2.Reset(iso, Object::New()); |
| 3328 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3418 g1s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3329 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3419 g1s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3330 | 3420 |
| 3331 g2s1.Reset(iso, Object::New()); | 3421 g2s1.Reset(iso, Object::New()); |
| 3332 g2s2.Reset(iso, Object::New()); | 3422 g2s2.Reset(iso, Object::New()); |
| 3333 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3423 g2s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3334 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3424 g2s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3335 | 3425 |
| 3336 g3s1.Reset(iso, Object::New()); | 3426 g3s1.Reset(iso, Object::New()); |
| 3337 g3s2.Reset(iso, Object::New()); | 3427 g3s2.Reset(iso, Object::New()); |
| 3338 g3s1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3428 g3s1.MakeWeak(&counter, &WeakPointerCallback); |
| 3339 g3s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3429 g3s2.MakeWeak(&counter, &WeakPointerCallback); |
| 3340 } | 3430 } |
| 3341 | 3431 |
| 3342 // Make a root. | 3432 // Make a root. |
| 3343 Persistent<Value> root(iso, g1s1); | 3433 Persistent<Value> root(iso, g1s1); |
| 3344 root.MarkPartiallyDependent(iso); | 3434 root.MarkPartiallyDependent(iso); |
| 3345 | 3435 |
| 3346 // Connect groups. We're building the following cycle: | 3436 // Connect groups. We're building the following cycle: |
| 3347 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | 3437 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other |
| 3348 // groups. | 3438 // groups. |
| 3349 { | 3439 { |
| 3350 HandleScope handle_scope(iso); | 3440 HandleScope handle_scope(iso); |
| 3351 g1s1.MarkPartiallyDependent(iso); | 3441 g1s1.MarkPartiallyDependent(iso); |
| 3352 g1s2.MarkPartiallyDependent(iso); | 3442 g1s2.MarkPartiallyDependent(iso); |
| 3353 g2s1.MarkPartiallyDependent(iso); | 3443 g2s1.MarkPartiallyDependent(iso); |
| 3354 g2s2.MarkPartiallyDependent(iso); | 3444 g2s2.MarkPartiallyDependent(iso); |
| 3355 g3s1.MarkPartiallyDependent(iso); | 3445 g3s1.MarkPartiallyDependent(iso); |
| 3356 g3s2.MarkPartiallyDependent(iso); | 3446 g3s2.MarkPartiallyDependent(iso); |
| 3357 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3447 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
| 3358 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3448 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
| 3359 Local<Object>::New(iso, g1s1.As<Object>())->Set(v8_str("x"), | 3449 Local<Object>::New(iso, g1s1.As<Object>())->Set( |
| 3360 Local<Value>(*g2s1)); | 3450 v8_str("x"), Local<Value>::New(iso, g2s1)); |
| 3361 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3451 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
| 3362 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3452 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
| 3363 Local<Object>::New(iso, g2s1.As<Object>())->Set(v8_str("x"), | 3453 Local<Object>::New(iso, g2s1.As<Object>())->Set( |
| 3364 Local<Value>(*g3s1)); | 3454 v8_str("x"), Local<Value>::New(iso, g3s1)); |
| 3365 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3455 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
| 3366 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3456 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
| 3367 Local<Object>::New(iso, g3s1.As<Object>())->Set(v8_str("x"), | 3457 Local<Object>::New(iso, g3s1.As<Object>())->Set( |
| 3368 Local<Value>(*g1s1)); | 3458 v8_str("x"), Local<Value>::New(iso, g1s1)); |
| 3369 } | 3459 } |
| 3370 | 3460 |
| 3371 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3461 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
| 3372 iso)->heap(); | 3462 iso)->heap(); |
| 3373 heap->CollectGarbage(i::NEW_SPACE); | 3463 heap->CollectGarbage(i::NEW_SPACE); |
| 3374 | 3464 |
| 3375 // All objects should be alive. | 3465 // All objects should be alive. |
| 3376 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3466 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
| 3377 | 3467 |
| 3378 // Weaken the root. | 3468 // Weaken the root. |
| 3379 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3469 root.MakeWeak(&counter, &WeakPointerCallback); |
| 3380 root.MarkPartiallyDependent(iso); | 3470 root.MarkPartiallyDependent(iso); |
| 3381 | 3471 |
| 3382 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3472 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 3383 // Groups are deleted, rebuild groups. | 3473 // Groups are deleted, rebuild groups. |
| 3384 { | 3474 { |
| 3385 HandleScope handle_scope(iso); | 3475 HandleScope handle_scope(iso); |
| 3386 g1s1.MarkPartiallyDependent(isolate); | 3476 g1s1.MarkPartiallyDependent(isolate); |
| 3387 g1s2.MarkPartiallyDependent(isolate); | 3477 g1s2.MarkPartiallyDependent(isolate); |
| 3388 g2s1.MarkPartiallyDependent(isolate); | 3478 g2s1.MarkPartiallyDependent(isolate); |
| 3389 g2s2.MarkPartiallyDependent(isolate); | 3479 g2s2.MarkPartiallyDependent(isolate); |
| 3390 g3s1.MarkPartiallyDependent(isolate); | 3480 g3s1.MarkPartiallyDependent(isolate); |
| 3391 g3s2.MarkPartiallyDependent(isolate); | 3481 g3s2.MarkPartiallyDependent(isolate); |
| 3392 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3482 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
| 3393 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3483 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
| 3394 Local<Object>::New(iso, g1s1.As<Object>())->Set(v8_str("x"), | 3484 Local<Object>::New(iso, g1s1.As<Object>())->Set( |
| 3395 Local<Value>(*g2s1)); | 3485 v8_str("x"), Local<Value>::New(iso, g2s1)); |
| 3396 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3486 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
| 3397 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3487 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
| 3398 Local<Object>::New(iso, g2s1.As<Object>())->Set(v8_str("x"), | 3488 Local<Object>::New(iso, g2s1.As<Object>())->Set( |
| 3399 Local<Value>(*g3s1)); | 3489 v8_str("x"), Local<Value>::New(iso, g3s1)); |
| 3400 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3490 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
| 3401 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3491 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
| 3402 Local<Object>::New(iso, g3s1.As<Object>())->Set(v8_str("x"), | 3492 Local<Object>::New(iso, g3s1.As<Object>())->Set( |
| 3403 Local<Value>(*g1s1)); | 3493 v8_str("x"), Local<Value>::New(iso, g1s1)); |
| 3404 } | 3494 } |
| 3405 | 3495 |
| 3406 heap->CollectGarbage(i::NEW_SPACE); | 3496 heap->CollectGarbage(i::NEW_SPACE); |
| 3407 | 3497 |
| 3408 // All objects should be gone. 7 global handles in total. | 3498 // All objects should be gone. 7 global handles in total. |
| 3409 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3499 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
| 3410 } | 3500 } |
| 3411 | 3501 |
| 3412 | 3502 |
| 3413 THREADED_TEST(ScriptException) { | 3503 THREADED_TEST(ScriptException) { |
| (...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4846 THREADED_TEST(SimplePropertyWrite) { | 4936 THREADED_TEST(SimplePropertyWrite) { |
| 4847 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4937 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4848 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4938 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4849 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 4939 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
| 4850 LocalContext context; | 4940 LocalContext context; |
| 4851 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4941 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 4852 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 4942 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); |
| 4853 for (int i = 0; i < 10; i++) { | 4943 for (int i = 0; i < 10; i++) { |
| 4854 CHECK(xValue.IsEmpty()); | 4944 CHECK(xValue.IsEmpty()); |
| 4855 script->Run(); | 4945 script->Run(); |
| 4856 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); | 4946 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); |
| 4857 xValue.Dispose(context->GetIsolate()); | 4947 xValue.Dispose(context->GetIsolate()); |
| 4858 xValue.Clear(); | 4948 xValue.Clear(); |
| 4859 } | 4949 } |
| 4860 } | 4950 } |
| 4861 | 4951 |
| 4862 | 4952 |
| 4863 THREADED_TEST(SetterOnly) { | 4953 THREADED_TEST(SetterOnly) { |
| 4864 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4954 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4865 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4955 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4866 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 4956 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
| 4867 LocalContext context; | 4957 LocalContext context; |
| 4868 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4958 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 4869 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 4959 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
| 4870 for (int i = 0; i < 10; i++) { | 4960 for (int i = 0; i < 10; i++) { |
| 4871 CHECK(xValue.IsEmpty()); | 4961 CHECK(xValue.IsEmpty()); |
| 4872 script->Run(); | 4962 script->Run(); |
| 4873 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); | 4963 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); |
| 4874 xValue.Dispose(context->GetIsolate()); | 4964 xValue.Dispose(context->GetIsolate()); |
| 4875 xValue.Clear(); | 4965 xValue.Clear(); |
| 4876 } | 4966 } |
| 4877 } | 4967 } |
| 4878 | 4968 |
| 4879 | 4969 |
| 4880 THREADED_TEST(NoAccessors) { | 4970 THREADED_TEST(NoAccessors) { |
| 4881 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4971 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 4882 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4972 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4883 templ->SetAccessor(v8_str("x"), | 4973 templ->SetAccessor(v8_str("x"), |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5088 | 5178 |
| 5089 | 5179 |
| 5090 Handle<v8::Array> UnboxedDoubleIndexedPropertyEnumerator( | 5180 Handle<v8::Array> UnboxedDoubleIndexedPropertyEnumerator( |
| 5091 const AccessorInfo& info) { | 5181 const AccessorInfo& info) { |
| 5092 // Force the list of returned keys to be stored in a FastDoubleArray. | 5182 // Force the list of returned keys to be stored in a FastDoubleArray. |
| 5093 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 5183 Local<Script> indexed_property_names_script = Script::Compile(v8_str( |
| 5094 "keys = new Array(); keys[125000] = 1;" | 5184 "keys = new Array(); keys[125000] = 1;" |
| 5095 "for(i = 0; i < 80000; i++) { keys[i] = i; };" | 5185 "for(i = 0; i < 80000; i++) { keys[i] = i; };" |
| 5096 "keys.length = 25; keys;")); | 5186 "keys.length = 25; keys;")); |
| 5097 Local<Value> result = indexed_property_names_script->Run(); | 5187 Local<Value> result = indexed_property_names_script->Run(); |
| 5098 return Local<v8::Array>(::v8::Array::Cast(*result)); | 5188 return Local<v8::Array>::Cast(result); |
| 5099 } | 5189 } |
| 5100 | 5190 |
| 5101 | 5191 |
| 5102 // Make sure that the the interceptor code in the runtime properly handles | 5192 // Make sure that the the interceptor code in the runtime properly handles |
| 5103 // merging property name lists for double-array-backed arrays. | 5193 // merging property name lists for double-array-backed arrays. |
| 5104 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { | 5194 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { |
| 5105 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 5195 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 5106 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5196 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5107 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, | 5197 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, |
| 5108 UnboxedDoubleIndexedPropertySetter, | 5198 UnboxedDoubleIndexedPropertySetter, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5128 | 5218 |
| 5129 Handle<v8::Array> NonStrictArgsIndexedPropertyEnumerator( | 5219 Handle<v8::Array> NonStrictArgsIndexedPropertyEnumerator( |
| 5130 const AccessorInfo& info) { | 5220 const AccessorInfo& info) { |
| 5131 // Force the list of returned keys to be stored in a Arguments object. | 5221 // Force the list of returned keys to be stored in a Arguments object. |
| 5132 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 5222 Local<Script> indexed_property_names_script = Script::Compile(v8_str( |
| 5133 "function f(w,x) {" | 5223 "function f(w,x) {" |
| 5134 " return arguments;" | 5224 " return arguments;" |
| 5135 "}" | 5225 "}" |
| 5136 "keys = f(0, 1, 2, 3);" | 5226 "keys = f(0, 1, 2, 3);" |
| 5137 "keys;")); | 5227 "keys;")); |
| 5138 Local<Value> result = indexed_property_names_script->Run(); | 5228 Local<Object> result = |
| 5139 return Local<v8::Array>(static_cast<v8::Array*>(::v8::Object::Cast(*result))); | 5229 Local<Object>::Cast(indexed_property_names_script->Run()); |
| 5230 // Have to populate the handle manually, as it's not Cast-able. |
| 5231 i::Handle<i::JSObject> o = |
| 5232 v8::Utils::OpenHandle<Object, i::JSObject>(result); |
| 5233 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o)); |
| 5234 return v8::Utils::ToLocal(array); |
| 5140 } | 5235 } |
| 5141 | 5236 |
| 5142 | 5237 |
| 5143 static v8::Handle<Value> NonStrictIndexedPropertyGetter( | 5238 static v8::Handle<Value> NonStrictIndexedPropertyGetter( |
| 5144 uint32_t index, | 5239 uint32_t index, |
| 5145 const AccessorInfo& info) { | 5240 const AccessorInfo& info) { |
| 5146 ApiTestFuzzer::Fuzz(); | 5241 ApiTestFuzzer::Fuzz(); |
| 5147 if (index < 4) { | 5242 if (index < 4) { |
| 5148 return v8::Handle<Value>(v8_num(index)); | 5243 return v8::Handle<Value>(v8_num(index)); |
| 5149 } | 5244 } |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6240 Snorkel() { index_ = global_index++; } | 6335 Snorkel() { index_ = global_index++; } |
| 6241 int index_; | 6336 int index_; |
| 6242 }; | 6337 }; |
| 6243 | 6338 |
| 6244 class Whammy { | 6339 class Whammy { |
| 6245 public: | 6340 public: |
| 6246 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } | 6341 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } |
| 6247 ~Whammy() { script_.Dispose(isolate_); } | 6342 ~Whammy() { script_.Dispose(isolate_); } |
| 6248 v8::Handle<Script> getScript() { | 6343 v8::Handle<Script> getScript() { |
| 6249 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); | 6344 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); |
| 6250 return Local<Script>(*script_); | 6345 return Local<Script>::New(isolate_, script_); |
| 6251 } | 6346 } |
| 6252 | 6347 |
| 6253 public: | 6348 public: |
| 6254 static const int kObjectCount = 256; | 6349 static const int kObjectCount = 256; |
| 6255 int cursor_; | 6350 int cursor_; |
| 6256 v8::Isolate* isolate_; | 6351 v8::Isolate* isolate_; |
| 6257 v8::Persistent<v8::Object> objects_[kObjectCount]; | 6352 v8::Persistent<v8::Object> objects_[kObjectCount]; |
| 6258 v8::Persistent<Script> script_; | 6353 v8::Persistent<Script> script_; |
| 6259 }; | 6354 }; |
| 6260 | 6355 |
| 6261 static void HandleWeakReference(v8::Isolate* isolate, | 6356 static void HandleWeakReference(v8::Isolate* isolate, |
| 6262 v8::Persistent<v8::Value>* obj, | 6357 v8::Persistent<v8::Value>* obj, |
| 6263 Snorkel* snorkel) { | 6358 Snorkel* snorkel) { |
| 6264 delete snorkel; | 6359 delete snorkel; |
| 6265 obj->ClearWeak(isolate); | 6360 obj->ClearWeak(isolate); |
| 6266 } | 6361 } |
| 6267 | 6362 |
| 6268 v8::Handle<Value> WhammyPropertyGetter(Local<String> name, | 6363 v8::Handle<Value> WhammyPropertyGetter(Local<String> name, |
| 6269 const AccessorInfo& info) { | 6364 const AccessorInfo& info) { |
| 6270 Whammy* whammy = | 6365 Whammy* whammy = |
| 6271 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 6366 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
| 6272 | 6367 |
| 6273 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; | 6368 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; |
| 6274 | 6369 |
| 6275 v8::Handle<v8::Object> obj = v8::Object::New(); | 6370 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 6276 if (!prev.IsEmpty()) { | 6371 if (!prev.IsEmpty()) { |
| 6277 v8::Local<v8::Object>::New(info.GetIsolate(), prev) | 6372 v8::Local<v8::Object>::New(info.GetIsolate(), prev) |
| 6278 ->Set(v8_str("next"), obj); | 6373 ->Set(v8_str("next"), obj); |
| 6279 prev.MakeWeak<Value, Snorkel>(info.GetIsolate(), | 6374 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference); |
| 6280 new Snorkel(), | |
| 6281 &HandleWeakReference); | |
| 6282 whammy->objects_[whammy->cursor_].Clear(); | 6375 whammy->objects_[whammy->cursor_].Clear(); |
| 6283 } | 6376 } |
| 6284 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); | 6377 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); |
| 6285 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; | 6378 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; |
| 6286 return whammy->getScript()->Run(); | 6379 return whammy->getScript()->Run(); |
| 6287 } | 6380 } |
| 6288 | 6381 |
| 6289 THREADED_TEST(WeakReference) { | 6382 THREADED_TEST(WeakReference) { |
| 6290 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); | 6383 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); |
| 6291 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); | 6384 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6333 v8::Persistent<v8::Object> object_a, object_b; | 6426 v8::Persistent<v8::Object> object_a, object_b; |
| 6334 | 6427 |
| 6335 { | 6428 { |
| 6336 v8::HandleScope handle_scope(iso); | 6429 v8::HandleScope handle_scope(iso); |
| 6337 object_a.Reset(iso, v8::Object::New()); | 6430 object_a.Reset(iso, v8::Object::New()); |
| 6338 object_b.Reset(iso, v8::Object::New()); | 6431 object_b.Reset(iso, v8::Object::New()); |
| 6339 } | 6432 } |
| 6340 | 6433 |
| 6341 bool object_a_disposed = false; | 6434 bool object_a_disposed = false; |
| 6342 bool object_b_disposed = false; | 6435 bool object_b_disposed = false; |
| 6343 object_a.MakeWeak(iso, &object_a_disposed, &DisposeAndSetFlag); | 6436 object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag); |
| 6344 object_b.MakeWeak(iso, &object_b_disposed, &DisposeAndSetFlag); | 6437 object_b.MakeWeak(&object_b_disposed, &DisposeAndSetFlag); |
| 6345 CHECK(!object_b.IsIndependent(iso)); | 6438 CHECK(!object_b.IsIndependent(iso)); |
| 6346 object_a.MarkIndependent(iso); | 6439 object_a.MarkIndependent(iso); |
| 6347 object_b.MarkIndependent(iso); | 6440 object_b.MarkIndependent(iso); |
| 6348 CHECK(object_b.IsIndependent(iso)); | 6441 CHECK(object_b.IsIndependent(iso)); |
| 6349 HEAP->PerformScavenge(); | 6442 HEAP->PerformScavenge(); |
| 6350 CHECK(object_a_disposed); | 6443 CHECK(object_a_disposed); |
| 6351 CHECK(object_b_disposed); | 6444 CHECK(object_b_disposed); |
| 6352 } | 6445 } |
| 6353 | 6446 |
| 6354 | 6447 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6395 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | 6488 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; |
| 6396 | 6489 |
| 6397 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | 6490 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { |
| 6398 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { | 6491 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { |
| 6399 v8::Persistent<v8::Object> object; | 6492 v8::Persistent<v8::Object> object; |
| 6400 { | 6493 { |
| 6401 v8::HandleScope handle_scope(isolate); | 6494 v8::HandleScope handle_scope(isolate); |
| 6402 object.Reset(isolate, v8::Object::New()); | 6495 object.Reset(isolate, v8::Object::New()); |
| 6403 } | 6496 } |
| 6404 bool disposed = false; | 6497 bool disposed = false; |
| 6405 object.MakeWeak(isolate, &disposed, gc_forcing_callback[inner_gc]); | 6498 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]); |
| 6406 object.MarkIndependent(isolate); | 6499 object.MarkIndependent(isolate); |
| 6407 invoke_gc[outer_gc](); | 6500 invoke_gc[outer_gc](); |
| 6408 CHECK(disposed); | 6501 CHECK(disposed); |
| 6409 } | 6502 } |
| 6410 } | 6503 } |
| 6411 } | 6504 } |
| 6412 | 6505 |
| 6413 | 6506 |
| 6414 static void RevivingCallback(v8::Isolate* isolate, | 6507 static void RevivingCallback(v8::Isolate* isolate, |
| 6415 v8::Persistent<v8::Object>* obj, | 6508 v8::Persistent<v8::Object>* obj, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6428 v8::Persistent<v8::Object> object; | 6521 v8::Persistent<v8::Object> object; |
| 6429 { | 6522 { |
| 6430 v8::HandleScope handle_scope(isolate); | 6523 v8::HandleScope handle_scope(isolate); |
| 6431 v8::Local<v8::Object> o = v8::Object::New(); | 6524 v8::Local<v8::Object> o = v8::Object::New(); |
| 6432 object.Reset(isolate, o); | 6525 object.Reset(isolate, o); |
| 6433 o->Set(v8_str("x"), v8::Integer::New(1)); | 6526 o->Set(v8_str("x"), v8::Integer::New(1)); |
| 6434 v8::Local<String> y_str = v8_str("y"); | 6527 v8::Local<String> y_str = v8_str("y"); |
| 6435 o->Set(y_str, y_str); | 6528 o->Set(y_str, y_str); |
| 6436 } | 6529 } |
| 6437 bool revived = false; | 6530 bool revived = false; |
| 6438 object.MakeWeak(isolate, &revived, &RevivingCallback); | 6531 object.MakeWeak(&revived, &RevivingCallback); |
| 6439 object.MarkIndependent(isolate); | 6532 object.MarkIndependent(isolate); |
| 6440 HEAP->PerformScavenge(); | 6533 HEAP->PerformScavenge(); |
| 6441 CHECK(revived); | 6534 CHECK(revived); |
| 6442 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 6535 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 6443 { | 6536 { |
| 6444 v8::HandleScope handle_scope(isolate); | 6537 v8::HandleScope handle_scope(isolate); |
| 6445 v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, object); | 6538 v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, object); |
| 6446 v8::Local<String> y_str = v8_str("y"); | 6539 v8::Local<String> y_str = v8_str("y"); |
| 6447 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); | 6540 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); |
| 6448 CHECK(o->Get(y_str)->Equals(y_str)); | 6541 CHECK(o->Get(y_str)->Equals(y_str)); |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7204 Handle<String> sym2 = v8::String::NewSymbol("\360\220\220\210"); | 7297 Handle<String> sym2 = v8::String::NewSymbol("\360\220\220\210"); |
| 7205 Handle<String> sym3 = v8::String::NewSymbol("x\355\240\201\355\260\207"); | 7298 Handle<String> sym3 = v8::String::NewSymbol("x\355\240\201\355\260\207"); |
| 7206 Handle<String> sym4 = v8::String::NewSymbol("x\360\220\220\210"); | 7299 Handle<String> sym4 = v8::String::NewSymbol("x\360\220\220\210"); |
| 7207 v8::Local<v8::Object> global = context->Global(); | 7300 v8::Local<v8::Object> global = context->Global(); |
| 7208 Local<Value> s0 = global->Get(v8_str("sym0")); | 7301 Local<Value> s0 = global->Get(v8_str("sym0")); |
| 7209 Local<Value> s0b = global->Get(v8_str("sym0b")); | 7302 Local<Value> s0b = global->Get(v8_str("sym0b")); |
| 7210 Local<Value> s1 = global->Get(v8_str("sym1")); | 7303 Local<Value> s1 = global->Get(v8_str("sym1")); |
| 7211 Local<Value> s2 = global->Get(v8_str("sym2")); | 7304 Local<Value> s2 = global->Get(v8_str("sym2")); |
| 7212 Local<Value> s3 = global->Get(v8_str("sym3")); | 7305 Local<Value> s3 = global->Get(v8_str("sym3")); |
| 7213 Local<Value> s4 = global->Get(v8_str("sym4")); | 7306 Local<Value> s4 = global->Get(v8_str("sym4")); |
| 7214 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0)))); | 7307 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); |
| 7215 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b)))); | 7308 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); |
| 7216 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1)))); | 7309 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); |
| 7217 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2)))); | 7310 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); |
| 7218 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3)))); | 7311 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); |
| 7219 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4)))); | 7312 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); |
| 7220 } | 7313 } |
| 7221 | 7314 |
| 7222 | 7315 |
| 7223 THREADED_TEST(ToArrayIndex) { | 7316 THREADED_TEST(ToArrayIndex) { |
| 7224 LocalContext context; | 7317 LocalContext context; |
| 7225 v8::HandleScope scope(context->GetIsolate()); | 7318 v8::HandleScope scope(context->GetIsolate()); |
| 7226 | 7319 |
| 7227 v8::Handle<String> str = v8_str("42"); | 7320 v8::Handle<String> str = v8_str("42"); |
| 7228 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 7321 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
| 7229 CHECK(!index.IsEmpty()); | 7322 CHECK(!index.IsEmpty()); |
| (...skipping 3389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10619 " result" | 10712 " result" |
| 10620 "} catch(e) {" | 10713 "} catch(e) {" |
| 10621 " e" | 10714 " e" |
| 10622 "};"); | 10715 "};"); |
| 10623 CHECK_EQ(239 * 10, value->Int32Value()); | 10716 CHECK_EQ(239 * 10, value->Int32Value()); |
| 10624 } | 10717 } |
| 10625 | 10718 |
| 10626 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, | 10719 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, |
| 10627 const AccessorInfo& info) { | 10720 const AccessorInfo& info) { |
| 10628 ApiTestFuzzer::Fuzz(); | 10721 ApiTestFuzzer::Fuzz(); |
| 10629 CheckReturnValue(info); | 10722 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); |
| 10630 int* call_count = | 10723 int* call_count = |
| 10631 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); | 10724 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); |
| 10632 ++(*call_count); | 10725 ++(*call_count); |
| 10633 if ((*call_count) % 20 == 0) { | 10726 if ((*call_count) % 20 == 0) { |
| 10634 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 10727 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 10635 } | 10728 } |
| 10636 return v8::Handle<Value>(); | 10729 return v8::Handle<Value>(); |
| 10637 } | 10730 } |
| 10638 | 10731 |
| 10639 static v8::Handle<Value> FastApiCallback_TrivialSignature( | 10732 static v8::Handle<Value> FastApiCallback_TrivialSignature( |
| 10640 const v8::Arguments& args) { | 10733 const v8::Arguments& args) { |
| 10641 ApiTestFuzzer::Fuzz(); | 10734 ApiTestFuzzer::Fuzz(); |
| 10642 CheckReturnValue(args); | 10735 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); |
| 10643 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 10736 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 10644 CHECK_EQ(isolate, args.GetIsolate()); | 10737 CHECK_EQ(isolate, args.GetIsolate()); |
| 10645 CHECK_EQ(args.This(), args.Holder()); | 10738 CHECK_EQ(args.This(), args.Holder()); |
| 10646 CHECK(args.Data()->Equals(v8_str("method_data"))); | 10739 CHECK(args.Data()->Equals(v8_str("method_data"))); |
| 10647 return v8::Integer::New(args[0]->Int32Value() + 1); | 10740 return v8::Integer::New(args[0]->Int32Value() + 1); |
| 10648 } | 10741 } |
| 10649 | 10742 |
| 10650 static v8::Handle<Value> FastApiCallback_SimpleSignature( | 10743 static v8::Handle<Value> FastApiCallback_SimpleSignature( |
| 10651 const v8::Arguments& args) { | 10744 const v8::Arguments& args) { |
| 10652 ApiTestFuzzer::Fuzz(); | 10745 ApiTestFuzzer::Fuzz(); |
| 10653 CheckReturnValue(args); | 10746 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); |
| 10654 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 10747 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 10655 CHECK_EQ(isolate, args.GetIsolate()); | 10748 CHECK_EQ(isolate, args.GetIsolate()); |
| 10656 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); | 10749 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); |
| 10657 CHECK(args.Data()->Equals(v8_str("method_data"))); | 10750 CHECK(args.Data()->Equals(v8_str("method_data"))); |
| 10658 // Note, we're using HasRealNamedProperty instead of Has to avoid | 10751 // Note, we're using HasRealNamedProperty instead of Has to avoid |
| 10659 // invoking the interceptor again. | 10752 // invoking the interceptor again. |
| 10660 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); | 10753 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); |
| 10661 return v8::Integer::New(args[0]->Int32Value() + 1); | 10754 return v8::Integer::New(args[0]->Int32Value() + 1); |
| 10662 } | 10755 } |
| 10663 | 10756 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10731 static Handle<Value> DoDirectGetter() { | 10824 static Handle<Value> DoDirectGetter() { |
| 10732 if (++p_getter_count % 3 == 0) { | 10825 if (++p_getter_count % 3 == 0) { |
| 10733 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 10826 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 10734 GenerateSomeGarbage(); | 10827 GenerateSomeGarbage(); |
| 10735 } | 10828 } |
| 10736 return v8_str("Direct Getter Result"); | 10829 return v8_str("Direct Getter Result"); |
| 10737 } | 10830 } |
| 10738 | 10831 |
| 10739 static v8::Handle<v8::Value> DirectGetter(Local<String> name, | 10832 static v8::Handle<v8::Value> DirectGetter(Local<String> name, |
| 10740 const v8::AccessorInfo& info) { | 10833 const v8::AccessorInfo& info) { |
| 10741 CheckReturnValue(info); | 10834 CheckReturnValue(info, FUNCTION_ADDR(DirectGetter)); |
| 10742 info.GetReturnValue().Set(v8_str("Garbage")); | 10835 info.GetReturnValue().Set(v8_str("Garbage")); |
| 10743 return DoDirectGetter(); | 10836 return DoDirectGetter(); |
| 10744 } | 10837 } |
| 10745 | 10838 |
| 10746 static v8::Handle<v8::Value> DirectGetterIndirect( | 10839 static v8::Handle<v8::Value> DirectGetterIndirect( |
| 10747 Local<String> name, | 10840 Local<String> name, |
| 10748 const v8::AccessorInfo& info) { | 10841 const v8::AccessorInfo& info) { |
| 10749 CheckReturnValue(info); | 10842 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterIndirect)); |
| 10750 info.GetReturnValue().Set(DoDirectGetter()); | 10843 info.GetReturnValue().Set(DoDirectGetter()); |
| 10751 return v8::Handle<v8::Value>(); | 10844 return v8::Handle<v8::Value>(); |
| 10752 } | 10845 } |
| 10753 | 10846 |
| 10754 static void DirectGetterCallback( | 10847 static void DirectGetterCallback( |
| 10755 Local<String> name, | 10848 Local<String> name, |
| 10756 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10849 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 10757 CheckReturnValue(info); | 10850 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); |
| 10758 info.GetReturnValue().Set(DoDirectGetter()); | 10851 info.GetReturnValue().Set(DoDirectGetter()); |
| 10759 } | 10852 } |
| 10760 | 10853 |
| 10761 | 10854 |
| 10762 template<typename Accessor> | 10855 template<typename Accessor> |
| 10763 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { | 10856 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { |
| 10764 LocalContext context; | 10857 LocalContext context; |
| 10765 v8::HandleScope scope(context->GetIsolate()); | 10858 v8::HandleScope scope(context->GetIsolate()); |
| 10766 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); | 10859 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); |
| 10767 obj->SetAccessor(v8_str("p1"), accessor); | 10860 obj->SetAccessor(v8_str("p1"), accessor); |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12154 { | 12247 { |
| 12155 v8::HandleScope scope(isolate); | 12248 v8::HandleScope scope(isolate); |
| 12156 some_object.Reset(isolate, v8::Object::New()); | 12249 some_object.Reset(isolate, v8::Object::New()); |
| 12157 handle1.Reset(isolate, v8::Object::New()); | 12250 handle1.Reset(isolate, v8::Object::New()); |
| 12158 handle2.Reset(isolate, v8::Object::New()); | 12251 handle2.Reset(isolate, v8::Object::New()); |
| 12159 } | 12252 } |
| 12160 // Note: order is implementation dependent alas: currently | 12253 // Note: order is implementation dependent alas: currently |
| 12161 // global handle nodes are processed by PostGarbageCollectionProcessing | 12254 // global handle nodes are processed by PostGarbageCollectionProcessing |
| 12162 // in reverse allocation order, so if second allocated handle is deleted, | 12255 // in reverse allocation order, so if second allocated handle is deleted, |
| 12163 // weak callback of the first handle would be able to 'reallocate' it. | 12256 // weak callback of the first handle would be able to 'reallocate' it. |
| 12164 handle1.MakeWeak<v8::Value, void>(isolate, | 12257 handle1.MakeWeak<v8::Value, void>(NULL, NewPersistentHandleCallback); |
| 12165 NULL, | |
| 12166 NewPersistentHandleCallback); | |
| 12167 handle2.Dispose(isolate); | 12258 handle2.Dispose(isolate); |
| 12168 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12259 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12169 } | 12260 } |
| 12170 | 12261 |
| 12171 | 12262 |
| 12172 v8::Persistent<v8::Object> to_be_disposed; | 12263 v8::Persistent<v8::Object> to_be_disposed; |
| 12173 | 12264 |
| 12174 void DisposeAndForceGcCallback(v8::Isolate* isolate, | 12265 void DisposeAndForceGcCallback(v8::Isolate* isolate, |
| 12175 v8::Persistent<v8::Value>* handle, | 12266 v8::Persistent<v8::Value>* handle, |
| 12176 void*) { | 12267 void*) { |
| 12177 to_be_disposed.Dispose(isolate); | 12268 to_be_disposed.Dispose(isolate); |
| 12178 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12269 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12179 handle->Dispose(isolate); | 12270 handle->Dispose(isolate); |
| 12180 } | 12271 } |
| 12181 | 12272 |
| 12182 | 12273 |
| 12183 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { | 12274 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { |
| 12184 LocalContext context; | 12275 LocalContext context; |
| 12185 v8::Isolate* isolate = context->GetIsolate(); | 12276 v8::Isolate* isolate = context->GetIsolate(); |
| 12186 | 12277 |
| 12187 v8::Persistent<v8::Object> handle1, handle2; | 12278 v8::Persistent<v8::Object> handle1, handle2; |
| 12188 { | 12279 { |
| 12189 v8::HandleScope scope(isolate); | 12280 v8::HandleScope scope(isolate); |
| 12190 handle1.Reset(isolate, v8::Object::New()); | 12281 handle1.Reset(isolate, v8::Object::New()); |
| 12191 handle2.Reset(isolate, v8::Object::New()); | 12282 handle2.Reset(isolate, v8::Object::New()); |
| 12192 } | 12283 } |
| 12193 handle1.MakeWeak<v8::Value, void>(isolate, NULL, DisposeAndForceGcCallback); | 12284 handle1.MakeWeak<v8::Value, void>(NULL, DisposeAndForceGcCallback); |
| 12194 to_be_disposed.Reset(isolate, handle2); | 12285 to_be_disposed.Reset(isolate, handle2); |
| 12195 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12286 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12196 } | 12287 } |
| 12197 | 12288 |
| 12198 void DisposingCallback(v8::Isolate* isolate, | 12289 void DisposingCallback(v8::Isolate* isolate, |
| 12199 v8::Persistent<v8::Value>* handle, | 12290 v8::Persistent<v8::Value>* handle, |
| 12200 void*) { | 12291 void*) { |
| 12201 handle->Dispose(isolate); | 12292 handle->Dispose(isolate); |
| 12202 } | 12293 } |
| 12203 | 12294 |
| 12204 void HandleCreatingCallback(v8::Isolate* isolate, | 12295 void HandleCreatingCallback(v8::Isolate* isolate, |
| 12205 v8::Persistent<v8::Value>* handle, | 12296 v8::Persistent<v8::Value>* handle, |
| 12206 void*) { | 12297 void*) { |
| 12207 v8::HandleScope scope(isolate); | 12298 v8::HandleScope scope(isolate); |
| 12208 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); | 12299 v8::Persistent<v8::Object>(isolate, v8::Object::New()); |
| 12209 handle->Dispose(isolate); | 12300 handle->Dispose(isolate); |
| 12210 } | 12301 } |
| 12211 | 12302 |
| 12212 | 12303 |
| 12213 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { | 12304 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { |
| 12214 LocalContext context; | 12305 LocalContext context; |
| 12215 v8::Isolate* isolate = context->GetIsolate(); | 12306 v8::Isolate* isolate = context->GetIsolate(); |
| 12216 | 12307 |
| 12217 v8::Persistent<v8::Object> handle1, handle2, handle3; | 12308 v8::Persistent<v8::Object> handle1, handle2, handle3; |
| 12218 { | 12309 { |
| 12219 v8::HandleScope scope(isolate); | 12310 v8::HandleScope scope(isolate); |
| 12220 handle3.Reset(isolate, v8::Object::New()); | 12311 handle3.Reset(isolate, v8::Object::New()); |
| 12221 handle2.Reset(isolate, v8::Object::New()); | 12312 handle2.Reset(isolate, v8::Object::New()); |
| 12222 handle1.Reset(isolate, v8::Object::New()); | 12313 handle1.Reset(isolate, v8::Object::New()); |
| 12223 } | 12314 } |
| 12224 handle2.MakeWeak<v8::Value, void>(isolate, NULL, DisposingCallback); | 12315 handle2.MakeWeak<v8::Value, void>(NULL, DisposingCallback); |
| 12225 handle3.MakeWeak<v8::Value, void>(isolate, NULL, HandleCreatingCallback); | 12316 handle3.MakeWeak<v8::Value, void>(NULL, HandleCreatingCallback); |
| 12226 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 12317 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 12227 } | 12318 } |
| 12228 | 12319 |
| 12229 | 12320 |
| 12230 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 12321 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
| 12231 v8::V8::Initialize(); | 12322 v8::V8::Initialize(); |
| 12232 | 12323 |
| 12233 const int nof = 2; | 12324 const int nof = 2; |
| 12234 const char* sources[nof] = { | 12325 const char* sources[nof] = { |
| 12235 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", | 12326 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12665 v8::Isolate* isolate = outer->GetIsolate(); | 12756 v8::Isolate* isolate = outer->GetIsolate(); |
| 12666 v8::Persistent<v8::Context> inner; | 12757 v8::Persistent<v8::Context> inner; |
| 12667 { | 12758 { |
| 12668 v8::HandleScope scope(isolate); | 12759 v8::HandleScope scope(isolate); |
| 12669 inner.Reset(isolate, v8::Context::New(isolate)); | 12760 inner.Reset(isolate, v8::Context::New(isolate)); |
| 12670 } | 12761 } |
| 12671 v8::HandleScope scope(isolate); | 12762 v8::HandleScope scope(isolate); |
| 12672 { | 12763 { |
| 12673 // Don't want a handle here, so do this unsafely | 12764 // Don't want a handle here, so do this unsafely |
| 12674 v8::Handle<v8::Context> inner_local = | 12765 v8::Handle<v8::Context> inner_local = |
| 12675 *reinterpret_cast<v8::Handle<v8::Context>*>(&inner); | 12766 v8::Utils::Convert<i::Object, v8::Context>( |
| 12767 v8::Utils::OpenPersistent(inner)); |
| 12676 inner_local->Enter(); | 12768 inner_local->Enter(); |
| 12677 inner.Dispose(); | 12769 inner.Dispose(); |
| 12678 inner.Clear(); | 12770 inner.Clear(); |
| 12679 inner_local->Exit(); | 12771 inner_local->Exit(); |
| 12680 } | 12772 } |
| 12681 } | 12773 } |
| 12682 | 12774 |
| 12683 | 12775 |
| 12684 // Regression test for issue 54, object templates with internal fields | 12776 // Regression test for issue 54, object templates with internal fields |
| 12685 // but no accessors or interceptors did not get their internal field | 12777 // but no accessors or interceptors did not get their internal field |
| (...skipping 6604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19290 obj->GetIdentityHash(); | 19382 obj->GetIdentityHash(); |
| 19291 obj->DeleteHiddenValue(v8_str("Bug")); | 19383 obj->DeleteHiddenValue(v8_str("Bug")); |
| 19292 } | 19384 } |
| 19293 | 19385 |
| 19294 | 19386 |
| 19295 THREADED_TEST(Regress2535) { | 19387 THREADED_TEST(Regress2535) { |
| 19296 i::FLAG_harmony_collections = true; | 19388 i::FLAG_harmony_collections = true; |
| 19297 LocalContext context; | 19389 LocalContext context; |
| 19298 v8::HandleScope scope(context->GetIsolate()); | 19390 v8::HandleScope scope(context->GetIsolate()); |
| 19299 Local<Value> set_value = CompileRun("new Set();"); | 19391 Local<Value> set_value = CompileRun("new Set();"); |
| 19300 Local<Object> set_object(Object::Cast(*set_value)); | 19392 Local<Object> set_object(Local<Object>::Cast(set_value)); |
| 19301 CHECK_EQ(0, set_object->InternalFieldCount()); | 19393 CHECK_EQ(0, set_object->InternalFieldCount()); |
| 19302 Local<Value> map_value = CompileRun("new Map();"); | 19394 Local<Value> map_value = CompileRun("new Map();"); |
| 19303 Local<Object> map_object(Object::Cast(*map_value)); | 19395 Local<Object> map_object(Local<Object>::Cast(map_value)); |
| 19304 CHECK_EQ(0, map_object->InternalFieldCount()); | 19396 CHECK_EQ(0, map_object->InternalFieldCount()); |
| 19305 } | 19397 } |
| 19306 | 19398 |
| 19307 | 19399 |
| 19308 #ifndef WIN32 | 19400 #ifndef WIN32 |
| 19309 class ThreadInterruptTest { | 19401 class ThreadInterruptTest { |
| 19310 public: | 19402 public: |
| 19311 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } | 19403 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } |
| 19312 ~ThreadInterruptTest() { delete sem_; } | 19404 ~ThreadInterruptTest() { delete sem_; } |
| 19313 | 19405 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19361 i::Semaphore* sem_; | 19453 i::Semaphore* sem_; |
| 19362 volatile int sem_value_; | 19454 volatile int sem_value_; |
| 19363 }; | 19455 }; |
| 19364 | 19456 |
| 19365 | 19457 |
| 19366 THREADED_TEST(SemaphoreInterruption) { | 19458 THREADED_TEST(SemaphoreInterruption) { |
| 19367 ThreadInterruptTest().RunTest(); | 19459 ThreadInterruptTest().RunTest(); |
| 19368 } | 19460 } |
| 19369 | 19461 |
| 19370 #endif // WIN32 | 19462 #endif // WIN32 |
| OLD | NEW |