Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: test/cctest/test-api.cc

Issue 142813003: A64: Synchronize with r15358. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 using ::v8::Script; 66 using ::v8::Script;
67 using ::v8::StackTrace; 67 using ::v8::StackTrace;
68 using ::v8::String; 68 using ::v8::String;
69 using ::v8::TryCatch; 69 using ::v8::TryCatch;
70 using ::v8::Undefined; 70 using ::v8::Undefined;
71 using ::v8::UniqueId; 71 using ::v8::UniqueId;
72 using ::v8::V8; 72 using ::v8::V8;
73 using ::v8::Value; 73 using ::v8::Value;
74 74
75 75
76 #define THREADED_PROFILED_TEST(Name) \
77 static void Test##Name(); \
78 TEST(Name##WithProfiler) { \
79 RunWithProfiler(&Test##Name); \
80 } \
81 THREADED_TEST(Name)
82
83 void RunWithProfiler(void (*test)()) {
84 LocalContext env;
85 v8::HandleScope scope(env->GetIsolate());
86 v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
87 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
88
89 cpu_profiler->StartCpuProfiling(profile_name);
90 (*test)();
91 cpu_profiler->DeleteAllCpuProfiles();
92 }
93
94
76 static void ExpectString(const char* code, const char* expected) { 95 static void ExpectString(const char* code, const char* expected) {
77 Local<Value> result = CompileRun(code); 96 Local<Value> result = CompileRun(code);
78 CHECK(result->IsString()); 97 CHECK(result->IsString());
79 String::Utf8Value utf8(result); 98 String::Utf8Value utf8(result);
80 CHECK_EQ(expected, *utf8); 99 CHECK_EQ(expected, *utf8);
81 } 100 }
82 101
83 static void ExpectInt32(const char* code, int expected) { 102 static void ExpectInt32(const char* code, int expected) {
84 Local<Value> result = CompileRun(code); 103 Local<Value> result = CompileRun(code);
85 CHECK(result->IsInt32()); 104 CHECK(result->IsInt32());
(...skipping 23 matching lines...) Expand all
109 } 128 }
110 129
111 130
112 static void ExpectUndefined(const char* code) { 131 static void ExpectUndefined(const char* code) {
113 Local<Value> result = CompileRun(code); 132 Local<Value> result = CompileRun(code);
114 CHECK(result->IsUndefined()); 133 CHECK(result->IsUndefined());
115 } 134 }
116 135
117 136
118 static int signature_callback_count; 137 static int signature_callback_count;
119 static v8::Handle<Value> IncrementingSignatureCallback( 138 static void IncrementingSignatureCallback(
120 const v8::Arguments& args) { 139 const v8::FunctionCallbackInfo<v8::Value>& args) {
121 ApiTestFuzzer::Fuzz(); 140 ApiTestFuzzer::Fuzz();
122 signature_callback_count++; 141 signature_callback_count++;
123 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 142 v8::Handle<v8::Array> result = v8::Array::New(args.Length());
124 for (int i = 0; i < args.Length(); i++) 143 for (int i = 0; i < args.Length(); i++)
125 result->Set(v8::Integer::New(i), args[i]); 144 result->Set(v8::Integer::New(i), args[i]);
126 return result; 145 args.GetReturnValue().Set(result);
127 } 146 }
128 147
129 148
130 static v8::Handle<Value> SignatureCallback(const v8::Arguments& args) { 149 static void SignatureCallback(
150 const v8::FunctionCallbackInfo<v8::Value>& args) {
131 ApiTestFuzzer::Fuzz(); 151 ApiTestFuzzer::Fuzz();
132 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 152 v8::Handle<v8::Array> result = v8::Array::New(args.Length());
133 for (int i = 0; i < args.Length(); i++) { 153 for (int i = 0; i < args.Length(); i++) {
134 result->Set(v8::Integer::New(i), args[i]); 154 result->Set(v8::Integer::New(i), args[i]);
135 } 155 }
136 return result; 156 args.GetReturnValue().Set(result);
137 } 157 }
138 158
139 159
140 THREADED_TEST(Handles) { 160 THREADED_TEST(Handles) {
141 v8::HandleScope scope(v8::Isolate::GetCurrent()); 161 v8::HandleScope scope(v8::Isolate::GetCurrent());
142 Local<Context> local_env; 162 Local<Context> local_env;
143 { 163 {
144 LocalContext env; 164 LocalContext env;
145 local_env = env.local(); 165 local_env = env.local();
146 } 166 }
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate()); 841 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(t.GetIsolate());
822 // If CPU profiler is active check that when API callback is invoked 842 // If CPU profiler is active check that when API callback is invoked
823 // VMState is set to EXTERNAL. 843 // VMState is set to EXTERNAL.
824 if (isolate->cpu_profiler()->is_profiling()) { 844 if (isolate->cpu_profiler()->is_profiling()) {
825 CHECK_EQ(i::EXTERNAL, isolate->current_vm_state()); 845 CHECK_EQ(i::EXTERNAL, isolate->current_vm_state());
826 CHECK(isolate->external_callback()); 846 CHECK(isolate->external_callback());
827 CHECK_EQ(callback, isolate->external_callback()); 847 CHECK_EQ(callback, isolate->external_callback());
828 } 848 }
829 } 849 }
830 850
831 static v8::Handle<Value> handle_call_impl(
832 const v8::Arguments& args,
833 i::Address callback) {
834 ApiTestFuzzer::Fuzz();
835 CheckReturnValue(args, callback);
836 args.GetReturnValue().Set(v8_str("bad value"));
837 return v8_num(102);
838 }
839
840 static v8::Handle<Value> handle_call(const v8::Arguments& args) {
841 return handle_call_impl(args, FUNCTION_ADDR(handle_call));
842 }
843
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) {
850 ApiTestFuzzer::Fuzz();
851 CheckReturnValue(args, callback);
852 args.GetReturnValue().Set(v8_str("bad value"));
853 args.GetReturnValue().Set(v8_num(102));
854 return v8::Handle<Value>();
855 }
856
857 static v8::Handle<Value> handle_call_indirect(const v8::Arguments& args) {
858 return handle_call_indirect_impl(args, FUNCTION_ADDR(handle_call_indirect));
859 }
860
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 851
865 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info, 852 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info,
866 i::Address callback) { 853 i::Address callback) {
867 ApiTestFuzzer::Fuzz(); 854 ApiTestFuzzer::Fuzz();
868 CheckReturnValue(info, callback); 855 CheckReturnValue(info, callback);
869 info.GetReturnValue().Set(v8_str("bad value")); 856 info.GetReturnValue().Set(v8_str("bad value"));
870 info.GetReturnValue().Set(v8_num(102)); 857 info.GetReturnValue().Set(v8_num(102));
871 } 858 }
872 859
873 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { 860 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) {
874 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback)); 861 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback));
875 } 862 }
876 863
877 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { 864 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) {
878 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2)); 865 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2));
879 } 866 }
880 867
881 static v8::Handle<Value> construct_call(const v8::Arguments& args) {
882 ApiTestFuzzer::Fuzz();
883 CheckReturnValue(args, FUNCTION_ADDR(construct_call));
884 args.This()->Set(v8_str("x"), v8_num(1));
885 args.This()->Set(v8_str("y"), v8_num(2));
886 args.GetReturnValue().Set(v8_str("bad value"));
887 return args.This();
888 }
889
890 static v8::Handle<Value> construct_call_indirect(const v8::Arguments& args) {
891 ApiTestFuzzer::Fuzz();
892 CheckReturnValue(args, FUNCTION_ADDR(construct_call_indirect));
893 args.This()->Set(v8_str("x"), v8_num(1));
894 args.This()->Set(v8_str("y"), v8_num(2));
895 args.GetReturnValue().Set(v8_str("bad value"));
896 args.GetReturnValue().Set(args.This());
897 return v8::Handle<Value>();
898 }
899
900 static void construct_callback( 868 static void construct_callback(
901 const v8::FunctionCallbackInfo<Value>& info) { 869 const v8::FunctionCallbackInfo<Value>& info) {
902 ApiTestFuzzer::Fuzz(); 870 ApiTestFuzzer::Fuzz();
903 CheckReturnValue(info, FUNCTION_ADDR(construct_callback)); 871 CheckReturnValue(info, FUNCTION_ADDR(construct_callback));
904 info.This()->Set(v8_str("x"), v8_num(1)); 872 info.This()->Set(v8_str("x"), v8_num(1));
905 info.This()->Set(v8_str("y"), v8_num(2)); 873 info.This()->Set(v8_str("y"), v8_num(2));
906 info.GetReturnValue().Set(v8_str("bad value")); 874 info.GetReturnValue().Set(v8_str("bad value"));
907 info.GetReturnValue().Set(info.This()); 875 info.GetReturnValue().Set(info.This());
908 } 876 }
909 877
910 878
911 static v8::Handle<Value> Return239(
912 Local<String> name, const AccessorInfo& info) {
913 ApiTestFuzzer::Fuzz();
914 CheckReturnValue(info, FUNCTION_ADDR(Return239));
915 info.GetReturnValue().Set(v8_str("bad value"));
916 return v8_num(239);
917 }
918
919 static v8::Handle<Value> Return239Indirect(
920 Local<String> name, const AccessorInfo& info) {
921 ApiTestFuzzer::Fuzz();
922 CheckReturnValue(info, FUNCTION_ADDR(Return239Indirect));
923 Handle<Value> value = v8_num(239);
924 info.GetReturnValue().Set(v8_str("bad value"));
925 info.GetReturnValue().Set(value);
926 return v8::Handle<Value>();
927 }
928
929 static void Return239Callback( 879 static void Return239Callback(
930 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { 880 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) {
931 ApiTestFuzzer::Fuzz(); 881 ApiTestFuzzer::Fuzz();
932 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); 882 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback));
933 info.GetReturnValue().Set(v8_str("bad value")); 883 info.GetReturnValue().Set(v8_str("bad value"));
934 info.GetReturnValue().Set(v8_num(239)); 884 info.GetReturnValue().Set(v8_num(239));
935 } 885 }
936 886
937 887
938 template<typename Handler> 888 template<typename Handler>
939 static void TestFunctionTemplateInitializer(Handler handler, 889 static void TestFunctionTemplateInitializer(Handler handler,
940 Handler handler_2) { 890 Handler handler_2) {
941 for (int i = 0; i < 2; i++) { 891 // Test constructor calls.
942 bool is_profiling = (i > 0); 892 {
943 // Test constructor calls. 893 LocalContext env;
944 { 894 v8::HandleScope scope(env->GetIsolate());
945 LocalContext env;
946 v8::HandleScope scope(env->GetIsolate());
947 895
948 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 896 Local<v8::FunctionTemplate> fun_templ =
949 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 897 v8::FunctionTemplate::New(handler);
950 if (is_profiling) { 898 Local<Function> fun = fun_templ->GetFunction();
951 cpu_profiler->StartCpuProfiling(profile_name); 899 env->Global()->Set(v8_str("obj"), fun);
952 } 900 Local<Script> script = v8_compile("obj()");
901 for (int i = 0; i < 30; i++) {
902 CHECK_EQ(102, script->Run()->Int32Value());
903 }
904 }
905 // Use SetCallHandler to initialize a function template, should work like
906 // the previous one.
907 {
908 LocalContext env;
909 v8::HandleScope scope(env->GetIsolate());
953 910
954 Local<v8::FunctionTemplate> fun_templ = 911 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
955 v8::FunctionTemplate::New(handler); 912 fun_templ->SetCallHandler(handler_2);
956 Local<Function> fun = fun_templ->GetFunction(); 913 Local<Function> fun = fun_templ->GetFunction();
957 env->Global()->Set(v8_str("obj"), fun); 914 env->Global()->Set(v8_str("obj"), fun);
958 Local<Script> script = v8_compile("obj()"); 915 Local<Script> script = v8_compile("obj()");
959 for (int i = 0; i < 30; i++) { 916 for (int i = 0; i < 30; i++) {
960 CHECK_EQ(102, script->Run()->Int32Value()); 917 CHECK_EQ(102, script->Run()->Int32Value());
961 }
962
963 if (is_profiling) {
964 cpu_profiler->StopCpuProfiling(profile_name);
965 }
966 }
967 // Use SetCallHandler to initialize a function template, should work like
968 // the previous one.
969 {
970 LocalContext env;
971 v8::HandleScope scope(env->GetIsolate());
972
973 v8::Local<v8::String> profile_name = v8::String::New("my_profile2");
974 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
975 if (is_profiling) {
976 cpu_profiler->StartCpuProfiling(profile_name);
977 }
978
979 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
980 fun_templ->SetCallHandler(handler_2);
981 Local<Function> fun = fun_templ->GetFunction();
982 env->Global()->Set(v8_str("obj"), fun);
983 Local<Script> script = v8_compile("obj()");
984 for (int i = 0; i < 30; i++) {
985 CHECK_EQ(102, script->Run()->Int32Value());
986 }
987
988 if (is_profiling) {
989 cpu_profiler->DeleteAllCpuProfiles();
990 }
991 } 918 }
992 } 919 }
993 } 920 }
994 921
995 922
996 template<typename Constructor, typename Accessor> 923 template<typename Constructor, typename Accessor>
997 static void TestFunctionTemplateAccessor(Constructor constructor, 924 static void TestFunctionTemplateAccessor(Constructor constructor,
998 Accessor accessor) { 925 Accessor accessor) {
999 for (int i = 0; i < 2; i++) { 926 LocalContext env;
1000 bool is_profiling = (i > 0); 927 v8::HandleScope scope(env->GetIsolate());
1001 LocalContext env;
1002 v8::HandleScope scope(env->GetIsolate());
1003 928
1004 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 929 Local<v8::FunctionTemplate> fun_templ =
1005 if (is_profiling) { 930 v8::FunctionTemplate::New(constructor);
1006 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 931 fun_templ->SetClassName(v8_str("funky"));
1007 cpu_profiler->StartCpuProfiling(profile_name); 932 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor);
1008 } 933 Local<Function> fun = fun_templ->GetFunction();
1009 934 env->Global()->Set(v8_str("obj"), fun);
1010 Local<v8::FunctionTemplate> fun_templ = 935 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
1011 v8::FunctionTemplate::New(constructor); 936 CHECK_EQ(v8_str("[object funky]"), result);
1012 fun_templ->SetClassName(v8_str("funky")); 937 CompileRun("var obj_instance = new obj();");
1013 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); 938 Local<Script> script;
1014 Local<Function> fun = fun_templ->GetFunction(); 939 script = v8_compile("obj_instance.x");
1015 env->Global()->Set(v8_str("obj"), fun); 940 for (int i = 0; i < 30; i++) {
1016 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 941 CHECK_EQ(1, script->Run()->Int32Value());
1017 CHECK_EQ(v8_str("[object funky]"), result); 942 }
1018 CompileRun("var obj_instance = new obj();"); 943 script = v8_compile("obj_instance.m");
1019 Local<Script> script; 944 for (int i = 0; i < 30; i++) {
1020 script = v8_compile("obj_instance.x"); 945 CHECK_EQ(239, script->Run()->Int32Value());
1021 for (int i = 0; i < 30; i++) {
1022 CHECK_EQ(1, script->Run()->Int32Value());
1023 }
1024 script = v8_compile("obj_instance.m");
1025 for (int i = 0; i < 30; i++) {
1026 CHECK_EQ(239, script->Run()->Int32Value());
1027 }
1028
1029 if (is_profiling) {
1030 cpu_profiler->DeleteAllCpuProfiles();
1031 }
1032 } 946 }
1033 } 947 }
1034 948
1035 949
1036 THREADED_TEST(FunctionTemplate) { 950 THREADED_PROFILED_TEST(FunctionTemplate) {
1037 TestFunctionTemplateInitializer(handle_call, handle_call_2);
1038 TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2);
1039 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); 951 TestFunctionTemplateInitializer(handle_callback, handle_callback_2);
1040
1041 TestFunctionTemplateAccessor(construct_call, Return239);
1042 TestFunctionTemplateAccessor(construct_call_indirect, Return239Indirect);
1043 TestFunctionTemplateAccessor(construct_callback, Return239Callback); 952 TestFunctionTemplateAccessor(construct_callback, Return239Callback);
1044 } 953 }
1045 954
1046 955
1047 static v8::Handle<v8::Value> SimpleDirectCallback(const v8::Arguments& args) {
1048 ApiTestFuzzer::Fuzz();
1049 CheckReturnValue(args, FUNCTION_ADDR(SimpleDirectCallback));
1050 args.GetReturnValue().Set(v8_str("bad value"));
1051 return v8_num(51423 + args.Length());
1052 }
1053
1054 static v8::Handle<v8::Value> SimpleIndirectCallback(const v8::Arguments& args) {
1055 ApiTestFuzzer::Fuzz();
1056 CheckReturnValue(args, FUNCTION_ADDR(SimpleIndirectCallback));
1057 args.GetReturnValue().Set(v8_num(51423 + args.Length()));
1058 return v8::Handle<v8::Value>();
1059 }
1060
1061 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 956 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
1062 ApiTestFuzzer::Fuzz(); 957 ApiTestFuzzer::Fuzz();
1063 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); 958 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback));
1064 info.GetReturnValue().Set(v8_num(51423 + info.Length())); 959 info.GetReturnValue().Set(v8_num(51423 + info.Length()));
1065 } 960 }
1066 961
1067 962
1068 template<typename Callback> 963 template<typename Callback>
1069 static void TestSimpleCallback(Callback callback) { 964 static void TestSimpleCallback(Callback callback) {
1070 for (int i = 0; i < 2; i++) { 965 LocalContext env;
1071 bool is_profiling = i; 966 v8::HandleScope scope(env->GetIsolate());
1072 LocalContext env;
1073 v8::HandleScope scope(env->GetIsolate());
1074 967
1075 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 968 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1076 if (is_profiling) { 969 object_template->Set("callback", v8::FunctionTemplate::New(callback));
1077 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 970 v8::Local<v8::Object> object = object_template->NewInstance();
1078 cpu_profiler->StartCpuProfiling(profile_name); 971 (*env)->Global()->Set(v8_str("callback_object"), object);
1079 } 972 v8::Handle<v8::Script> script;
1080 973 script = v8_compile("callback_object.callback(17)");
1081 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 974 for (int i = 0; i < 30; i++) {
1082 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 975 CHECK_EQ(51424, script->Run()->Int32Value());
1083 v8::Local<v8::Object> object = object_template->NewInstance(); 976 }
1084 (*env)->Global()->Set(v8_str("callback_object"), object); 977 script = v8_compile("callback_object.callback(17, 24)");
1085 v8::Handle<v8::Script> script; 978 for (int i = 0; i < 30; i++) {
1086 script = v8_compile("callback_object.callback(17)"); 979 CHECK_EQ(51425, script->Run()->Int32Value());
1087 for (int i = 0; i < 30; i++) {
1088 CHECK_EQ(51424, script->Run()->Int32Value());
1089 }
1090 script = v8_compile("callback_object.callback(17, 24)");
1091 for (int i = 0; i < 30; i++) {
1092 CHECK_EQ(51425, script->Run()->Int32Value());
1093 }
1094
1095 if (is_profiling) {
1096 cpu_profiler->DeleteAllCpuProfiles();
1097 }
1098 } 980 }
1099 } 981 }
1100 982
1101 983
1102 THREADED_TEST(SimpleCallback) { 984 THREADED_PROFILED_TEST(SimpleCallback) {
1103 TestSimpleCallback(SimpleDirectCallback);
1104 TestSimpleCallback(SimpleIndirectCallback);
1105 TestSimpleCallback(SimpleCallback); 985 TestSimpleCallback(SimpleCallback);
1106 } 986 }
1107 987
1108 988
1109 template<typename T> 989 template<typename T>
1110 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info); 990 void FastReturnValueCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
1111 991
1112 // constant return values 992 // constant return values
1113 static int32_t fast_return_value_int32 = 471; 993 static int32_t fast_return_value_int32 = 471;
1114 static uint32_t fast_return_value_uint32 = 571; 994 static uint32_t fast_return_value_uint32 = 571;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 LocalContext env; 1067 LocalContext env;
1188 v8::HandleScope scope(env->GetIsolate()); 1068 v8::HandleScope scope(env->GetIsolate());
1189 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1069 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1190 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1070 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1191 object_template->Set("callback", v8::FunctionTemplate::New(callback)); 1071 object_template->Set("callback", v8::FunctionTemplate::New(callback));
1192 v8::Local<v8::Object> object = object_template->NewInstance(); 1072 v8::Local<v8::Object> object = object_template->NewInstance();
1193 (*env)->Global()->Set(v8_str("callback_object"), object); 1073 (*env)->Global()->Set(v8_str("callback_object"), object);
1194 return scope.Close(CompileRun("callback_object.callback()")); 1074 return scope.Close(CompileRun("callback_object.callback()"));
1195 } 1075 }
1196 1076
1197 THREADED_TEST(FastReturnValues) { 1077 THREADED_PROFILED_TEST(FastReturnValues) {
1198 LocalContext env; 1078 LocalContext env;
1199 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1079 v8::HandleScope scope(v8::Isolate::GetCurrent());
1200 v8::Handle<v8::Value> value; 1080 v8::Handle<v8::Value> value;
1201 // check int32_t and uint32_t 1081 // check int32_t and uint32_t
1202 int32_t int_values[] = { 1082 int32_t int_values[] = {
1203 0, 234, -723, 1083 0, 234, -723,
1204 i::Smi::kMinValue, i::Smi::kMaxValue 1084 i::Smi::kMinValue, i::Smi::kMaxValue
1205 }; 1085 };
1206 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) { 1086 for (size_t i = 0; i < ARRAY_SIZE(int_values); i++) {
1207 for (int modifier = -1; modifier <= 1; modifier++) { 1087 for (int modifier = -1; modifier <= 1; modifier++) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 value = TestFastReturnValues<Object>(); 1139 value = TestFastReturnValues<Object>();
1260 CHECK(value->IsUndefined()); 1140 CHECK(value->IsUndefined());
1261 } 1141 }
1262 1142
1263 1143
1264 THREADED_TEST(FunctionTemplateSetLength) { 1144 THREADED_TEST(FunctionTemplateSetLength) {
1265 LocalContext env; 1145 LocalContext env;
1266 v8::HandleScope scope(env->GetIsolate()); 1146 v8::HandleScope scope(env->GetIsolate());
1267 { 1147 {
1268 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( 1148 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(
1269 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); 1149 handle_callback, Handle<v8::Value>(), Handle<v8::Signature>(), 23);
1270 Local<Function> fun = fun_templ->GetFunction(); 1150 Local<Function> fun = fun_templ->GetFunction();
1271 env->Global()->Set(v8_str("obj"), fun); 1151 env->Global()->Set(v8_str("obj"), fun);
1272 Local<Script> script = v8_compile("obj.length"); 1152 Local<Script> script = v8_compile("obj.length");
1273 CHECK_EQ(23, script->Run()->Int32Value()); 1153 CHECK_EQ(23, script->Run()->Int32Value());
1274 } 1154 }
1275 { 1155 {
1276 Local<v8::FunctionTemplate> fun_templ = 1156 Local<v8::FunctionTemplate> fun_templ =
1277 v8::FunctionTemplate::New(handle_call); 1157 v8::FunctionTemplate::New(handle_callback);
1278 fun_templ->SetLength(22); 1158 fun_templ->SetLength(22);
1279 Local<Function> fun = fun_templ->GetFunction(); 1159 Local<Function> fun = fun_templ->GetFunction();
1280 env->Global()->Set(v8_str("obj"), fun); 1160 env->Global()->Set(v8_str("obj"), fun);
1281 Local<Script> script = v8_compile("obj.length"); 1161 Local<Script> script = v8_compile("obj.length");
1282 CHECK_EQ(22, script->Run()->Int32Value()); 1162 CHECK_EQ(22, script->Run()->Int32Value());
1283 } 1163 }
1284 { 1164 {
1285 // Without setting length it defaults to 0. 1165 // Without setting length it defaults to 0.
1286 Local<v8::FunctionTemplate> fun_templ = 1166 Local<v8::FunctionTemplate> fun_templ =
1287 v8::FunctionTemplate::New(handle_call); 1167 v8::FunctionTemplate::New(handle_callback);
1288 Local<Function> fun = fun_templ->GetFunction(); 1168 Local<Function> fun = fun_templ->GetFunction();
1289 env->Global()->Set(v8_str("obj"), fun); 1169 env->Global()->Set(v8_str("obj"), fun);
1290 Local<Script> script = v8_compile("obj.length"); 1170 Local<Script> script = v8_compile("obj.length");
1291 CHECK_EQ(0, script->Run()->Int32Value()); 1171 CHECK_EQ(0, script->Run()->Int32Value());
1292 } 1172 }
1293 } 1173 }
1294 1174
1295 1175
1296 static void* expected_ptr; 1176 static void* expected_ptr;
1297 static v8::Handle<v8::Value> callback(const v8::Arguments& args) { 1177 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) {
1298 void* ptr = v8::External::Cast(*args.Data())->Value(); 1178 void* ptr = v8::External::Cast(*args.Data())->Value();
1299 CHECK_EQ(expected_ptr, ptr); 1179 CHECK_EQ(expected_ptr, ptr);
1300 return v8::True(); 1180 args.GetReturnValue().Set(true);
1301 } 1181 }
1302 1182
1303 1183
1304 static void TestExternalPointerWrapping() { 1184 static void TestExternalPointerWrapping() {
1305 LocalContext env; 1185 LocalContext env;
1306 v8::HandleScope scope(env->GetIsolate()); 1186 v8::HandleScope scope(env->GetIsolate());
1307 1187
1308 v8::Handle<v8::Value> data = v8::External::New(expected_ptr); 1188 v8::Handle<v8::Value> data = v8::External::New(expected_ptr);
1309 1189
1310 v8::Handle<v8::Object> obj = v8::Object::New(); 1190 v8::Handle<v8::Object> obj = v8::Object::New();
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 v8::Handle<String> str2 = v8_str("x"); 1548 v8::Handle<String> str2 = v8_str("x");
1669 CHECK(str2->BooleanValue()); 1549 CHECK(str2->BooleanValue());
1670 CHECK(!v8::Number::New(0)->BooleanValue()); 1550 CHECK(!v8::Number::New(0)->BooleanValue());
1671 CHECK(v8::Number::New(-1)->BooleanValue()); 1551 CHECK(v8::Number::New(-1)->BooleanValue());
1672 CHECK(v8::Number::New(1)->BooleanValue()); 1552 CHECK(v8::Number::New(1)->BooleanValue());
1673 CHECK(v8::Number::New(42)->BooleanValue()); 1553 CHECK(v8::Number::New(42)->BooleanValue());
1674 CHECK(!v8_compile("NaN")->Run()->BooleanValue()); 1554 CHECK(!v8_compile("NaN")->Run()->BooleanValue());
1675 } 1555 }
1676 1556
1677 1557
1678 static v8::Handle<Value> DummyCallHandler(const v8::Arguments& args) { 1558 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {
1679 ApiTestFuzzer::Fuzz(); 1559 ApiTestFuzzer::Fuzz();
1680 return v8_num(13.4); 1560 args.GetReturnValue().Set(v8_num(13.4));
1681 } 1561 }
1682 1562
1683 1563
1684 static v8::Handle<Value> GetM(Local<String> name, const AccessorInfo&) { 1564 static void GetM(Local<String> name,
1565 const v8::PropertyCallbackInfo<v8::Value>& info) {
1685 ApiTestFuzzer::Fuzz(); 1566 ApiTestFuzzer::Fuzz();
1686 return v8_num(876); 1567 info.GetReturnValue().Set(v8_num(876));
1687 } 1568 }
1688 1569
1689 1570
1690 THREADED_TEST(GlobalPrototype) { 1571 THREADED_TEST(GlobalPrototype) {
1691 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1572 v8::HandleScope scope(v8::Isolate::GetCurrent());
1692 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 1573 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
1693 func_templ->PrototypeTemplate()->Set( 1574 func_templ->PrototypeTemplate()->Set(
1694 "dummy", 1575 "dummy",
1695 v8::FunctionTemplate::New(DummyCallHandler)); 1576 v8::FunctionTemplate::New(DummyCallHandler));
1696 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1577 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate();
(...skipping 25 matching lines...) Expand all
1722 templ2->Set("b", templ1); 1603 templ2->Set("b", templ1);
1723 Local<v8::Object> instance2 = templ2->NewInstance(); 1604 Local<v8::Object> instance2 = templ2->NewInstance();
1724 env->Global()->Set(v8_str("q"), instance2); 1605 env->Global()->Set(v8_str("q"), instance2);
1725 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); 1606 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue());
1726 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); 1607 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue());
1727 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); 1608 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue());
1728 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); 1609 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue());
1729 } 1610 }
1730 1611
1731 1612
1732 static v8::Handle<Value> GetFlabby(const v8::Arguments& args) { 1613 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1733 ApiTestFuzzer::Fuzz(); 1614 ApiTestFuzzer::Fuzz();
1734 return v8_num(17.2); 1615 args.GetReturnValue().Set(v8_num(17.2));
1735 } 1616 }
1736 1617
1737 1618
1738 static v8::Handle<Value> GetKnurd(Local<String> property, const AccessorInfo&) { 1619 static void GetKnurd(Local<String> property,
1620 const v8::PropertyCallbackInfo<v8::Value>& info) {
1739 ApiTestFuzzer::Fuzz(); 1621 ApiTestFuzzer::Fuzz();
1740 return v8_num(15.2); 1622 info.GetReturnValue().Set(v8_num(15.2));
1741 } 1623 }
1742 1624
1743 1625
1744 THREADED_TEST(DescriptorInheritance) { 1626 THREADED_TEST(DescriptorInheritance) {
1745 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1627 v8::HandleScope scope(v8::Isolate::GetCurrent());
1746 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); 1628 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New();
1747 super->PrototypeTemplate()->Set("flabby", 1629 super->PrototypeTemplate()->Set("flabby",
1748 v8::FunctionTemplate::New(GetFlabby)); 1630 v8::FunctionTemplate::New(GetFlabby));
1749 super->PrototypeTemplate()->Set("PI", v8_num(3.14)); 1631 super->PrototypeTemplate()->Set("PI", v8_num(3.14));
1750 1632
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 1675
1794 // base1 and base2 cannot cross reference to each's prototype 1676 // base1 and base2 cannot cross reference to each's prototype
1795 CHECK(v8_compile("obj.v2")->Run()->IsUndefined()); 1677 CHECK(v8_compile("obj.v2")->Run()->IsUndefined());
1796 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined()); 1678 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined());
1797 } 1679 }
1798 1680
1799 1681
1800 int echo_named_call_count; 1682 int echo_named_call_count;
1801 1683
1802 1684
1803 static v8::Handle<Value> EchoNamedProperty(Local<String> name, 1685 static void EchoNamedProperty(Local<String> name,
1804 const AccessorInfo& info) { 1686 const v8::PropertyCallbackInfo<v8::Value>& info) {
1805 ApiTestFuzzer::Fuzz(); 1687 ApiTestFuzzer::Fuzz();
1806 CHECK_EQ(v8_str("data"), info.Data()); 1688 CHECK_EQ(v8_str("data"), info.Data());
1807 echo_named_call_count++; 1689 echo_named_call_count++;
1808 return name; 1690 info.GetReturnValue().Set(name);
1809 } 1691 }
1810 1692
1811 // Helper functions for Interceptor/Accessor interaction tests 1693 // Helper functions for Interceptor/Accessor interaction tests
1812 1694
1813 Handle<Value> SimpleAccessorGetter(Local<String> name, 1695 void SimpleAccessorGetter(Local<String> name,
1814 const AccessorInfo& info) { 1696 const v8::PropertyCallbackInfo<v8::Value>& info) {
1815 Handle<Object> self = info.This(); 1697 Handle<Object> self = info.This();
1816 return self->Get(String::Concat(v8_str("accessor_"), name)); 1698 info.GetReturnValue().Set(
1699 self->Get(String::Concat(v8_str("accessor_"), name)));
1817 } 1700 }
1818 1701
1819 void SimpleAccessorSetter(Local<String> name, Local<Value> value, 1702 void SimpleAccessorSetter(Local<String> name, Local<Value> value,
1820 const AccessorInfo& info) { 1703 const v8::PropertyCallbackInfo<void>& info) {
1821 Handle<Object> self = info.This(); 1704 Handle<Object> self = info.This();
1822 self->Set(String::Concat(v8_str("accessor_"), name), value); 1705 self->Set(String::Concat(v8_str("accessor_"), name), value);
1823 } 1706 }
1824 1707
1825 Handle<Value> EmptyInterceptorGetter(Local<String> name, 1708 void EmptyInterceptorGetter(Local<String> name,
1826 const AccessorInfo& info) { 1709 const v8::PropertyCallbackInfo<v8::Value>& info) {
1827 return Handle<Value>();
1828 } 1710 }
1829 1711
1830 Handle<Value> EmptyInterceptorSetter(Local<String> name, 1712 void EmptyInterceptorSetter(Local<String> name,
1831 Local<Value> value, 1713 Local<Value> value,
1832 const AccessorInfo& info) { 1714 const v8::PropertyCallbackInfo<v8::Value>& info) {
1833 return Handle<Value>();
1834 } 1715 }
1835 1716
1836 Handle<Value> InterceptorGetter(Local<String> name, 1717 void InterceptorGetter(Local<String> name,
1837 const AccessorInfo& info) { 1718 const v8::PropertyCallbackInfo<v8::Value>& info) {
1838 // Intercept names that start with 'interceptor_'. 1719 // Intercept names that start with 'interceptor_'.
1839 String::Utf8Value utf8(name); 1720 String::Utf8Value utf8(name);
1840 char* name_str = *utf8; 1721 char* name_str = *utf8;
1841 char prefix[] = "interceptor_"; 1722 char prefix[] = "interceptor_";
1842 int i; 1723 int i;
1843 for (i = 0; name_str[i] && prefix[i]; ++i) { 1724 for (i = 0; name_str[i] && prefix[i]; ++i) {
1844 if (name_str[i] != prefix[i]) return Handle<Value>(); 1725 if (name_str[i] != prefix[i]) return;
1845 } 1726 }
1846 Handle<Object> self = info.This(); 1727 Handle<Object> self = info.This();
1847 return self->GetHiddenValue(v8_str(name_str + i)); 1728 info.GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i)));
1848 } 1729 }
1849 1730
1850 Handle<Value> InterceptorSetter(Local<String> name, 1731 void InterceptorSetter(Local<String> name,
1851 Local<Value> value, 1732 Local<Value> value,
1852 const AccessorInfo& info) { 1733 const v8::PropertyCallbackInfo<v8::Value>& info) {
1853 // Intercept accesses that set certain integer values. 1734 // Intercept accesses that set certain integer values.
1854 if (value->IsInt32() && value->Int32Value() < 10000) { 1735 if (value->IsInt32() && value->Int32Value() < 10000) {
1855 Handle<Object> self = info.This(); 1736 Handle<Object> self = info.This();
1856 self->SetHiddenValue(name, value); 1737 self->SetHiddenValue(name, value);
1857 return value; 1738 info.GetReturnValue().Set(value);
1858 } 1739 }
1859 return Handle<Value>();
1860 } 1740 }
1861 1741
1862 void AddAccessor(Handle<FunctionTemplate> templ, 1742 void AddAccessor(Handle<FunctionTemplate> templ,
1863 Handle<String> name, 1743 Handle<String> name,
1864 v8::AccessorGetter getter, 1744 v8::AccessorGetterCallback getter,
1865 v8::AccessorSetter setter) { 1745 v8::AccessorSetterCallback setter) {
1866 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); 1746 templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
1867 } 1747 }
1868 1748
1869 void AddInterceptor(Handle<FunctionTemplate> templ, 1749 void AddInterceptor(Handle<FunctionTemplate> templ,
1870 v8::NamedPropertyGetter getter, 1750 v8::NamedPropertyGetterCallback getter,
1871 v8::NamedPropertySetter setter) { 1751 v8::NamedPropertySetterCallback setter) {
1872 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); 1752 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1873 } 1753 }
1874 1754
1875 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { 1755 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) {
1876 v8::HandleScope scope(v8::Isolate::GetCurrent()); 1756 v8::HandleScope scope(v8::Isolate::GetCurrent());
1877 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1757 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1878 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1758 Handle<FunctionTemplate> child = FunctionTemplate::New();
1879 child->Inherit(parent); 1759 child->Inherit(parent);
1880 AddAccessor(parent, v8_str("age"), 1760 AddAccessor(parent, v8_str("age"),
1881 SimpleAccessorGetter, SimpleAccessorSetter); 1761 SimpleAccessorGetter, SimpleAccessorSetter);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 // Check default behavior 1982 // Check default behavior
2103 CHECK_EQ(v8_compile("obj.flob = 10;")->Run()->Int32Value(), 10); 1983 CHECK_EQ(v8_compile("obj.flob = 10;")->Run()->Int32Value(), 10);
2104 CHECK(v8_compile("'myProperty' in obj")->Run()->BooleanValue()); 1984 CHECK(v8_compile("'myProperty' in obj")->Run()->BooleanValue());
2105 CHECK(v8_compile("delete obj.myProperty")->Run()->BooleanValue()); 1985 CHECK(v8_compile("delete obj.myProperty")->Run()->BooleanValue());
2106 } 1986 }
2107 1987
2108 1988
2109 int echo_indexed_call_count = 0; 1989 int echo_indexed_call_count = 0;
2110 1990
2111 1991
2112 static v8::Handle<Value> EchoIndexedProperty(uint32_t index, 1992 static void EchoIndexedProperty(
2113 const AccessorInfo& info) { 1993 uint32_t index,
1994 const v8::PropertyCallbackInfo<v8::Value>& info) {
2114 ApiTestFuzzer::Fuzz(); 1995 ApiTestFuzzer::Fuzz();
2115 CHECK_EQ(v8_num(637), info.Data()); 1996 CHECK_EQ(v8_num(637), info.Data());
2116 echo_indexed_call_count++; 1997 echo_indexed_call_count++;
2117 return v8_num(index); 1998 info.GetReturnValue().Set(v8_num(index));
2118 } 1999 }
2119 2000
2120 2001
2121 THREADED_TEST(IndexedPropertyHandlerGetter) { 2002 THREADED_TEST(IndexedPropertyHandlerGetter) {
2122 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2003 v8::HandleScope scope(v8::Isolate::GetCurrent());
2123 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2004 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2124 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, 2005 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty,
2125 0, 0, 0, 0, 2006 0, 0, 0, 0,
2126 v8_num(637)); 2007 v8_num(637));
2127 LocalContext env; 2008 LocalContext env;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 2095
2215 2096
2216 void CheckThisNamedPropertyEnumerator( 2097 void CheckThisNamedPropertyEnumerator(
2217 const v8::PropertyCallbackInfo<v8::Array>& info) { 2098 const v8::PropertyCallbackInfo<v8::Array>& info) {
2218 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); 2099 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator));
2219 ApiTestFuzzer::Fuzz(); 2100 ApiTestFuzzer::Fuzz();
2220 CHECK(info.This()->Equals(bottom)); 2101 CHECK(info.This()->Equals(bottom));
2221 } 2102 }
2222 2103
2223 2104
2224 THREADED_TEST(PropertyHandlerInPrototype) { 2105 THREADED_PROFILED_TEST(PropertyHandlerInPrototype) {
2225 LocalContext env; 2106 LocalContext env;
2226 v8::HandleScope scope(env->GetIsolate()); 2107 v8::HandleScope scope(env->GetIsolate());
2227 2108
2228 // Set up a prototype chain with three interceptors. 2109 // Set up a prototype chain with three interceptors.
2229 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2110 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2230 templ->InstanceTemplate()->SetIndexedPropertyHandler( 2111 templ->InstanceTemplate()->SetIndexedPropertyHandler(
2231 CheckThisIndexedPropertyHandler, 2112 CheckThisIndexedPropertyHandler,
2232 CheckThisIndexedPropertySetter, 2113 CheckThisIndexedPropertySetter,
2233 CheckThisIndexedPropertyQuery, 2114 CheckThisIndexedPropertyQuery,
2234 CheckThisIndexedPropertyDeleter, 2115 CheckThisIndexedPropertyDeleter,
(...skipping 28 matching lines...) Expand all
2263 2144
2264 // Indexed and named deleter. 2145 // Indexed and named deleter.
2265 Script::Compile(v8_str("delete obj[0]"))->Run(); 2146 Script::Compile(v8_str("delete obj[0]"))->Run();
2266 Script::Compile(v8_str("delete obj.x"))->Run(); 2147 Script::Compile(v8_str("delete obj.x"))->Run();
2267 2148
2268 // Enumerators. 2149 // Enumerators.
2269 Script::Compile(v8_str("for (var p in obj) ;"))->Run(); 2150 Script::Compile(v8_str("for (var p in obj) ;"))->Run();
2270 } 2151 }
2271 2152
2272 2153
2273 static v8::Handle<Value> PrePropertyHandlerGet(Local<String> key, 2154 static void PrePropertyHandlerGet(
2274 const AccessorInfo& info) { 2155 Local<String> key,
2156 const v8::PropertyCallbackInfo<v8::Value>& info) {
2275 ApiTestFuzzer::Fuzz(); 2157 ApiTestFuzzer::Fuzz();
2276 if (v8_str("pre")->Equals(key)) { 2158 if (v8_str("pre")->Equals(key)) {
2277 return v8_str("PrePropertyHandler: pre"); 2159 info.GetReturnValue().Set(v8_str("PrePropertyHandler: pre"));
2278 } 2160 }
2279 return v8::Handle<String>();
2280 } 2161 }
2281 2162
2282 2163
2283 static v8::Handle<v8::Integer> PrePropertyHandlerQuery(Local<String> key, 2164 static void PrePropertyHandlerQuery(
2284 const AccessorInfo&) { 2165 Local<String> key,
2166 const v8::PropertyCallbackInfo<v8::Integer>& info) {
2285 if (v8_str("pre")->Equals(key)) { 2167 if (v8_str("pre")->Equals(key)) {
2286 return v8::Integer::New(v8::None); 2168 info.GetReturnValue().Set(static_cast<int32_t>(v8::None));
2287 } 2169 }
2288
2289 return v8::Handle<v8::Integer>(); // do not intercept the call
2290 } 2170 }
2291 2171
2292 2172
2293 THREADED_TEST(PrePropertyHandler) { 2173 THREADED_TEST(PrePropertyHandler) {
2294 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2174 v8::HandleScope scope(v8::Isolate::GetCurrent());
2295 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 2175 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
2296 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, 2176 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet,
2297 0, 2177 0,
2298 PrePropertyHandlerQuery); 2178 PrePropertyHandlerQuery);
2299 LocalContext env(NULL, desc->InstanceTemplate()); 2179 LocalContext env(NULL, desc->InstanceTemplate());
(...skipping 14 matching lines...) Expand all
2314 v8::Handle<Value> result = Script::Compile(v8_str( 2194 v8::Handle<Value> result = Script::Compile(v8_str(
2315 "this.propertyIsEnumerable(undefined)"))->Run(); 2195 "this.propertyIsEnumerable(undefined)"))->Run();
2316 CHECK(result->IsFalse()); 2196 CHECK(result->IsFalse());
2317 } 2197 }
2318 2198
2319 2199
2320 v8::Handle<Script> call_recursively_script; 2200 v8::Handle<Script> call_recursively_script;
2321 static const int kTargetRecursionDepth = 200; // near maximum 2201 static const int kTargetRecursionDepth = 200; // near maximum
2322 2202
2323 2203
2324 static v8::Handle<Value> CallScriptRecursivelyCall(const v8::Arguments& args) { 2204 static void CallScriptRecursivelyCall(
2205 const v8::FunctionCallbackInfo<v8::Value>& args) {
2325 ApiTestFuzzer::Fuzz(); 2206 ApiTestFuzzer::Fuzz();
2326 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2207 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2327 if (depth == kTargetRecursionDepth) return v8::Undefined(); 2208 if (depth == kTargetRecursionDepth) return;
2328 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2209 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2329 return call_recursively_script->Run(); 2210 args.GetReturnValue().Set(call_recursively_script->Run());
2330 } 2211 }
2331 2212
2332 2213
2333 static v8::Handle<Value> CallFunctionRecursivelyCall( 2214 static void CallFunctionRecursivelyCall(
2334 const v8::Arguments& args) { 2215 const v8::FunctionCallbackInfo<v8::Value>& args) {
2335 ApiTestFuzzer::Fuzz(); 2216 ApiTestFuzzer::Fuzz();
2336 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2217 int depth = args.This()->Get(v8_str("depth"))->Int32Value();
2337 if (depth == kTargetRecursionDepth) { 2218 if (depth == kTargetRecursionDepth) {
2338 printf("[depth = %d]\n", depth); 2219 printf("[depth = %d]\n", depth);
2339 return v8::Undefined(); 2220 return;
2340 } 2221 }
2341 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2222 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2342 v8::Handle<Value> function = 2223 v8::Handle<Value> function =
2343 args.This()->Get(v8_str("callFunctionRecursively")); 2224 args.This()->Get(v8_str("callFunctionRecursively"));
2344 return function.As<Function>()->Call(args.This(), 0, NULL); 2225 args.GetReturnValue().Set(
2226 function.As<Function>()->Call(args.This(), 0, NULL));
2345 } 2227 }
2346 2228
2347 2229
2348 THREADED_TEST(DeepCrossLanguageRecursion) { 2230 THREADED_TEST(DeepCrossLanguageRecursion) {
2349 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2231 v8::HandleScope scope(v8::Isolate::GetCurrent());
2350 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 2232 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
2351 global->Set(v8_str("callScriptRecursively"), 2233 global->Set(v8_str("callScriptRecursively"),
2352 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); 2234 v8::FunctionTemplate::New(CallScriptRecursivelyCall));
2353 global->Set(v8_str("callFunctionRecursively"), 2235 global->Set(v8_str("callFunctionRecursively"),
2354 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); 2236 v8::FunctionTemplate::New(CallFunctionRecursivelyCall));
2355 LocalContext env(NULL, global); 2237 LocalContext env(NULL, global);
2356 2238
2357 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2239 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2358 call_recursively_script = v8_compile("callScriptRecursively()"); 2240 call_recursively_script = v8_compile("callScriptRecursively()");
2359 call_recursively_script->Run(); 2241 call_recursively_script->Run();
2360 call_recursively_script = v8::Handle<Script>(); 2242 call_recursively_script = v8::Handle<Script>();
2361 2243
2362 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2244 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2363 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); 2245 Script::Compile(v8_str("callFunctionRecursively()"))->Run();
2364 } 2246 }
2365 2247
2366 2248
2367 static v8::Handle<Value> 2249 static void ThrowingPropertyHandlerGet(
2368 ThrowingPropertyHandlerGet(Local<String> key, const AccessorInfo&) { 2250 Local<String> key,
2251 const v8::PropertyCallbackInfo<v8::Value>& info) {
2369 ApiTestFuzzer::Fuzz(); 2252 ApiTestFuzzer::Fuzz();
2370 return v8::ThrowException(key); 2253 info.GetReturnValue().Set(v8::ThrowException(key));
2371 } 2254 }
2372 2255
2373 2256
2374 static v8::Handle<Value> ThrowingPropertyHandlerSet(Local<String> key, 2257 static void ThrowingPropertyHandlerSet(
2375 Local<Value>, 2258 Local<String> key,
2376 const AccessorInfo&) { 2259 Local<Value>,
2260 const v8::PropertyCallbackInfo<v8::Value>& info) {
2377 v8::ThrowException(key); 2261 v8::ThrowException(key);
2378 return v8::Undefined(); // not the same as v8::Handle<v8::Value>() 2262 info.GetReturnValue().SetUndefined(); // not the same as empty handle
2379 } 2263 }
2380 2264
2381 2265
2382 THREADED_TEST(CallbackExceptionRegression) { 2266 THREADED_TEST(CallbackExceptionRegression) {
2383 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2267 v8::HandleScope scope(v8::Isolate::GetCurrent());
2384 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 2268 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
2385 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, 2269 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet,
2386 ThrowingPropertyHandlerSet); 2270 ThrowingPropertyHandlerSet);
2387 LocalContext env; 2271 LocalContext env;
2388 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 2272 env->Global()->Set(v8_str("obj"), obj->NewInstance());
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 CHECK_EQ(100, result->Int32Value()); 2659 CHECK_EQ(100, result->Int32Value());
2776 CHECK_EQ(0xBB, my_data[0]); 2660 CHECK_EQ(0xBB, my_data[0]);
2777 CHECK_EQ(0xCC, my_data[1]); 2661 CHECK_EQ(0xCC, my_data[1]);
2778 my_data[0] = 0xCC; 2662 my_data[0] = 0xCC;
2779 my_data[1] = 0x11; 2663 my_data[1] = 0x11;
2780 result = CompileRun("u8_b[0] + u8_b[1]"); 2664 result = CompileRun("u8_b[0] + u8_b[1]");
2781 CHECK_EQ(0xDD, result->Int32Value()); 2665 CHECK_EQ(0xDD, result->Int32Value());
2782 } 2666 }
2783 2667
2784 2668
2669 static void CheckDataViewIsNeutered(v8::Handle<v8::DataView> dv) {
2670 CHECK_EQ(0, static_cast<int>(dv->ByteLength()));
2671 CHECK_EQ(0, static_cast<int>(dv->ByteOffset()));
2672 }
2673
2674
2785 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) { 2675 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) {
2786 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); 2676 CHECK_EQ(0, static_cast<int>(ta->ByteLength()));
2787 CHECK_EQ(0, static_cast<int>(ta->Length())); 2677 CHECK_EQ(0, static_cast<int>(ta->Length()));
2788 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); 2678 CHECK_EQ(0, static_cast<int>(ta->ByteOffset()));
2789 } 2679 }
2790 2680
2681
2682 static void CheckIsTypedArrayVarNeutered(const char* name) {
2683 i::ScopedVector<char> source(1024);
2684 i::OS::SNPrintF(source,
2685 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0",
2686 name, name, name);
2687 CHECK(CompileRun(source.start())->IsTrue());
2688 v8::Handle<v8::TypedArray> ta =
2689 v8::Handle<v8::TypedArray>::Cast(CompileRun(name));
2690 CheckIsNeutered(ta);
2691 }
2692
2693
2791 template <typename TypedArray, int kElementSize> 2694 template <typename TypedArray, int kElementSize>
2792 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, 2695 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab,
2793 int byteOffset, 2696 int byteOffset,
2794 int length) { 2697 int length) {
2795 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); 2698 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length);
2796 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); 2699 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
2797 CHECK_EQ(length, static_cast<int>(ta->Length())); 2700 CHECK_EQ(length, static_cast<int>(ta->Length()));
2798 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); 2701 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
2799 return ta; 2702 return ta;
2800 } 2703 }
(...skipping 21 matching lines...) Expand all
2822 v8::Handle<v8::Uint32Array> u32a = 2725 v8::Handle<v8::Uint32Array> u32a =
2823 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); 2726 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
2824 v8::Handle<v8::Int32Array> i32a = 2727 v8::Handle<v8::Int32Array> i32a =
2825 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); 2728 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
2826 2729
2827 v8::Handle<v8::Float32Array> f32a = 2730 v8::Handle<v8::Float32Array> f32a =
2828 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); 2731 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
2829 v8::Handle<v8::Float64Array> f64a = 2732 v8::Handle<v8::Float64Array> f64a =
2830 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); 2733 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
2831 2734
2735 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023);
2736 CHECK_EQ(1, static_cast<int>(dv->ByteOffset()));
2737 CHECK_EQ(1023, static_cast<int>(dv->ByteLength()));
2738
2832 ScopedArrayBufferContents contents(buffer->Externalize()); 2739 ScopedArrayBufferContents contents(buffer->Externalize());
2833 buffer->Neuter(); 2740 buffer->Neuter();
2834 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); 2741 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
2835 CheckIsNeutered(u8a); 2742 CheckIsNeutered(u8a);
2836 CheckIsNeutered(u8c); 2743 CheckIsNeutered(u8c);
2837 CheckIsNeutered(i8a); 2744 CheckIsNeutered(i8a);
2838 CheckIsNeutered(u16a); 2745 CheckIsNeutered(u16a);
2839 CheckIsNeutered(i16a); 2746 CheckIsNeutered(i16a);
2840 CheckIsNeutered(u32a); 2747 CheckIsNeutered(u32a);
2841 CheckIsNeutered(i32a); 2748 CheckIsNeutered(i32a);
2842 CheckIsNeutered(f32a); 2749 CheckIsNeutered(f32a);
2843 CheckIsNeutered(f64a); 2750 CheckIsNeutered(f64a);
2751 CheckDataViewIsNeutered(dv);
2844 } 2752 }
2845 2753
2846 THREADED_TEST(ArrayBuffer_NeuteringScript) { 2754 THREADED_TEST(ArrayBuffer_NeuteringScript) {
2847 LocalContext env; 2755 LocalContext env;
2848 v8::Isolate* isolate = env->GetIsolate(); 2756 v8::Isolate* isolate = env->GetIsolate();
2849 v8::HandleScope handle_scope(isolate); 2757 v8::HandleScope handle_scope(isolate);
2850 2758
2851 CompileRun( 2759 CompileRun(
2852 "var ab = new ArrayBuffer(1024);" 2760 "var ab = new ArrayBuffer(1024);"
2853 "var u8a = new Uint8Array(ab, 1, 1023);" 2761 "var u8a = new Uint8Array(ab, 1, 1023);"
2854 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" 2762 "var u8c = new Uint8ClampedArray(ab, 1, 1023);"
2855 "var i8a = new Int8Array(ab, 1, 1023);" 2763 "var i8a = new Int8Array(ab, 1, 1023);"
2856 "var u16a = new Uint16Array(ab, 2, 511);" 2764 "var u16a = new Uint16Array(ab, 2, 511);"
2857 "var i16a = new Int16Array(ab, 2, 511);" 2765 "var i16a = new Int16Array(ab, 2, 511);"
2858 "var u32a = new Uint32Array(ab, 4, 255);" 2766 "var u32a = new Uint32Array(ab, 4, 255);"
2859 "var i32a = new Int32Array(ab, 4, 255);" 2767 "var i32a = new Int32Array(ab, 4, 255);"
2860 "var f32a = new Float32Array(ab, 4, 255);" 2768 "var f32a = new Float32Array(ab, 4, 255);"
2861 "var f64a = new Float64Array(ab, 8, 127);"); 2769 "var f64a = new Float64Array(ab, 8, 127);"
2770 "var dv = new DataView(ab, 1, 1023);");
2862 2771
2863 v8::Handle<v8::ArrayBuffer> ab = 2772 v8::Handle<v8::ArrayBuffer> ab =
2864 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); 2773 Local<v8::ArrayBuffer>::Cast(CompileRun("ab"));
2865 2774
2866 v8::Handle<v8::Uint8Array> u8a = 2775 v8::Handle<v8::DataView> dv =
2867 v8::Handle<v8::Uint8Array>::Cast(CompileRun("u8a")); 2776 v8::Handle<v8::DataView>::Cast(CompileRun("dv"));
2868 v8::Handle<v8::Uint8ClampedArray> u8c =
2869 v8::Handle<v8::Uint8ClampedArray>::Cast(CompileRun("u8c"));
2870 v8::Handle<v8::Int8Array> i8a =
2871 v8::Handle<v8::Int8Array>::Cast(CompileRun("i8a"));
2872
2873 v8::Handle<v8::Uint16Array> u16a =
2874 v8::Handle<v8::Uint16Array>::Cast(CompileRun("u16a"));
2875 v8::Handle<v8::Int16Array> i16a =
2876 v8::Handle<v8::Int16Array>::Cast(CompileRun("i16a"));
2877 v8::Handle<v8::Uint32Array> u32a =
2878 v8::Handle<v8::Uint32Array>::Cast(CompileRun("u32a"));
2879 v8::Handle<v8::Int32Array> i32a =
2880 v8::Handle<v8::Int32Array>::Cast(CompileRun("i32a"));
2881 v8::Handle<v8::Float32Array> f32a =
2882 v8::Handle<v8::Float32Array>::Cast(CompileRun("f32a"));
2883 v8::Handle<v8::Float64Array> f64a =
2884 v8::Handle<v8::Float64Array>::Cast(CompileRun("f64a"));
2885 2777
2886 ScopedArrayBufferContents contents(ab->Externalize()); 2778 ScopedArrayBufferContents contents(ab->Externalize());
2887 ab->Neuter(); 2779 ab->Neuter();
2888 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); 2780 CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
2889 CheckIsNeutered(u8a); 2781 CHECK_EQ(0, CompileRun("ab.byteLength")->Int32Value());
2890 CheckIsNeutered(u8c); 2782
2891 CheckIsNeutered(i8a); 2783 CheckIsTypedArrayVarNeutered("u8a");
2892 CheckIsNeutered(u16a); 2784 CheckIsTypedArrayVarNeutered("u8c");
2893 CheckIsNeutered(i16a); 2785 CheckIsTypedArrayVarNeutered("i8a");
2894 CheckIsNeutered(u32a); 2786 CheckIsTypedArrayVarNeutered("u16a");
2895 CheckIsNeutered(i32a); 2787 CheckIsTypedArrayVarNeutered("i16a");
2896 CheckIsNeutered(f32a); 2788 CheckIsTypedArrayVarNeutered("u32a");
2897 CheckIsNeutered(f64a); 2789 CheckIsTypedArrayVarNeutered("i32a");
2790 CheckIsTypedArrayVarNeutered("f32a");
2791 CheckIsTypedArrayVarNeutered("f64a");
2792
2793 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
2794 CheckDataViewIsNeutered(dv);
2898 } 2795 }
2899 2796
2900 2797
2901 2798
2902 THREADED_TEST(HiddenProperties) { 2799 THREADED_TEST(HiddenProperties) {
2903 LocalContext env; 2800 LocalContext env;
2904 v8::HandleScope scope(env->GetIsolate()); 2801 v8::HandleScope scope(env->GetIsolate());
2905 2802
2906 v8::Local<v8::Object> obj = v8::Object::New(); 2803 v8::Local<v8::Object> obj = v8::Object::New();
2907 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2804 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 // Make sure that the getter and setter from Object.prototype is not invoked. 2870 // Make sure that the getter and setter from Object.prototype is not invoked.
2974 // If it did we would have full access to the hidden properties in 2871 // If it did we would have full access to the hidden properties in
2975 // the accessor. 2872 // the accessor.
2976 CHECK(obj->SetHiddenValue(key, v8::Integer::New(42))); 2873 CHECK(obj->SetHiddenValue(key, v8::Integer::New(42)));
2977 ExpectFalse("set_called"); 2874 ExpectFalse("set_called");
2978 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); 2875 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value());
2979 } 2876 }
2980 2877
2981 2878
2982 static bool interceptor_for_hidden_properties_called; 2879 static bool interceptor_for_hidden_properties_called;
2983 static v8::Handle<Value> InterceptorForHiddenProperties( 2880 static void InterceptorForHiddenProperties(
2984 Local<String> name, const AccessorInfo& info) { 2881 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
2985 interceptor_for_hidden_properties_called = true; 2882 interceptor_for_hidden_properties_called = true;
2986 return v8::Handle<Value>();
2987 } 2883 }
2988 2884
2989 2885
2990 THREADED_TEST(HiddenPropertiesWithInterceptors) { 2886 THREADED_TEST(HiddenPropertiesWithInterceptors) {
2991 LocalContext context; 2887 LocalContext context;
2992 v8::HandleScope scope(context->GetIsolate()); 2888 v8::HandleScope scope(context->GetIsolate());
2993 2889
2994 interceptor_for_hidden_properties_called = false; 2890 interceptor_for_hidden_properties_called = false;
2995 2891
2996 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2892 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 2962
3067 THREADED_TEST(ResettingGlobalHandle) { 2963 THREADED_TEST(ResettingGlobalHandle) {
3068 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2964 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3069 v8::Persistent<String> global; 2965 v8::Persistent<String> global;
3070 { 2966 {
3071 v8::HandleScope scope(isolate); 2967 v8::HandleScope scope(isolate);
3072 global.Reset(isolate, v8_str("str")); 2968 global.Reset(isolate, v8_str("str"));
3073 } 2969 }
3074 v8::internal::GlobalHandles* global_handles = 2970 v8::internal::GlobalHandles* global_handles =
3075 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 2971 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3076 int initial_handle_count = global_handles->NumberOfGlobalHandles(); 2972 int initial_handle_count = global_handles->global_handles_count();
3077 { 2973 {
3078 v8::HandleScope scope(isolate); 2974 v8::HandleScope scope(isolate);
3079 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 2975 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3080 } 2976 }
3081 { 2977 {
3082 v8::HandleScope scope(isolate); 2978 v8::HandleScope scope(isolate);
3083 global.Reset(isolate, v8_str("longer")); 2979 global.Reset(isolate, v8_str("longer"));
3084 } 2980 }
3085 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count); 2981 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3086 { 2982 {
3087 v8::HandleScope scope(isolate); 2983 v8::HandleScope scope(isolate);
3088 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6); 2984 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 6);
3089 } 2985 }
3090 global.Dispose(isolate); 2986 global.Dispose(isolate);
3091 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count - 1); 2987 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3092 } 2988 }
3093 2989
3094 2990
3095 THREADED_TEST(ResettingGlobalHandleToEmpty) { 2991 THREADED_TEST(ResettingGlobalHandleToEmpty) {
3096 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2992 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3097 v8::Persistent<String> global; 2993 v8::Persistent<String> global;
3098 { 2994 {
3099 v8::HandleScope scope(isolate); 2995 v8::HandleScope scope(isolate);
3100 global.Reset(isolate, v8_str("str")); 2996 global.Reset(isolate, v8_str("str"));
3101 } 2997 }
3102 v8::internal::GlobalHandles* global_handles = 2998 v8::internal::GlobalHandles* global_handles =
3103 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 2999 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3104 int initial_handle_count = global_handles->NumberOfGlobalHandles(); 3000 int initial_handle_count = global_handles->global_handles_count();
3105 { 3001 {
3106 v8::HandleScope scope(isolate); 3002 v8::HandleScope scope(isolate);
3107 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3); 3003 CHECK_EQ(v8::Local<String>::New(isolate, global)->Length(), 3);
3108 } 3004 }
3109 { 3005 {
3110 v8::HandleScope scope(isolate); 3006 v8::HandleScope scope(isolate);
3111 Local<String> empty; 3007 Local<String> empty;
3112 global.Reset(isolate, empty); 3008 global.Reset(isolate, empty);
3113 } 3009 }
3114 CHECK(global.IsEmpty()); 3010 CHECK(global.IsEmpty());
3115 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count - 1); 3011 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1);
3116 } 3012 }
3117 3013
3118 3014
3119 THREADED_TEST(ClearAndLeakGlobal) { 3015 THREADED_TEST(ClearAndLeakGlobal) {
3120 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3016 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3121 v8::internal::GlobalHandles* global_handles = NULL; 3017 v8::internal::GlobalHandles* global_handles = NULL;
3122 int initial_handle_count = 0; 3018 int initial_handle_count = 0;
3123 v8::Persistent<String> global; 3019 v8::Persistent<String> global;
3124 { 3020 {
3125 v8::HandleScope scope(isolate); 3021 v8::HandleScope scope(isolate);
3126 Local<String> str = v8_str("str"); 3022 Local<String> str = v8_str("str");
3127 global_handles = 3023 global_handles =
3128 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3024 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
3129 initial_handle_count = global_handles->NumberOfGlobalHandles(); 3025 initial_handle_count = global_handles->global_handles_count();
3130 global.Reset(isolate, str); 3026 global.Reset(isolate, str);
3131 } 3027 }
3132 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); 3028 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3133 String* str = global.ClearAndLeak(); 3029 String* str = global.ClearAndLeak();
3134 CHECK(global.IsEmpty()); 3030 CHECK(global.IsEmpty());
3135 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count + 1); 3031 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count + 1);
3136 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); 3032 global_handles->Destroy(reinterpret_cast<i::Object**>(str));
3137 CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count); 3033 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3138 } 3034 }
3139 3035
3140 3036
3141 THREADED_TEST(GlobalHandleUpcast) { 3037 THREADED_TEST(GlobalHandleUpcast) {
3142 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3038 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3143 v8::HandleScope scope(isolate); 3039 v8::HandleScope scope(isolate);
3144 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 3040 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
3145 v8::Persistent<String> global_string(isolate, local); 3041 v8::Persistent<String> global_string(isolate, local);
3146 #ifdef V8_USE_UNSAFE_HANDLES 3042 #ifdef V8_USE_UNSAFE_HANDLES
3147 v8::Persistent<Value> global_value = 3043 v8::Persistent<Value> global_value =
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
3696 CHECK_EQ(1, arr->Get(0)->Int32Value()); 3592 CHECK_EQ(1, arr->Get(0)->Int32Value());
3697 CHECK_EQ(2, arr->Get(1)->Int32Value()); 3593 CHECK_EQ(2, arr->Get(1)->Int32Value());
3698 CHECK_EQ(3, arr->Get(2)->Int32Value()); 3594 CHECK_EQ(3, arr->Get(2)->Int32Value());
3699 array = v8::Array::New(27); 3595 array = v8::Array::New(27);
3700 CHECK_EQ(27, array->Length()); 3596 CHECK_EQ(27, array->Length());
3701 array = v8::Array::New(-27); 3597 array = v8::Array::New(-27);
3702 CHECK_EQ(0, array->Length()); 3598 CHECK_EQ(0, array->Length());
3703 } 3599 }
3704 3600
3705 3601
3706 v8::Handle<Value> HandleF(const v8::Arguments& args) { 3602 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) {
3707 v8::HandleScope scope(args.GetIsolate()); 3603 v8::HandleScope scope(args.GetIsolate());
3708 ApiTestFuzzer::Fuzz(); 3604 ApiTestFuzzer::Fuzz();
3709 Local<v8::Array> result = v8::Array::New(args.Length()); 3605 Local<v8::Array> result = v8::Array::New(args.Length());
3710 for (int i = 0; i < args.Length(); i++) 3606 for (int i = 0; i < args.Length(); i++)
3711 result->Set(i, args[i]); 3607 result->Set(i, args[i]);
3712 return scope.Close(result); 3608 args.GetReturnValue().Set(scope.Close(result));
3713 } 3609 }
3714 3610
3715 3611
3716 THREADED_TEST(Vector) { 3612 THREADED_TEST(Vector) {
3717 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3613 v8::HandleScope scope(v8::Isolate::GetCurrent());
3718 Local<ObjectTemplate> global = ObjectTemplate::New(); 3614 Local<ObjectTemplate> global = ObjectTemplate::New();
3719 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); 3615 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF));
3720 LocalContext context(0, global); 3616 LocalContext context(0, global);
3721 3617
3722 const char* fun = "f()"; 3618 const char* fun = "f()";
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3826 Local<Script> script = 3722 Local<Script> script =
3827 Script::Compile(String::New(js_code_causing_out_of_memory)); 3723 Script::Compile(String::New(js_code_causing_out_of_memory));
3828 Local<Value> result = script->Run(); 3724 Local<Value> result = script->Run();
3829 3725
3830 // Check for out of memory state. 3726 // Check for out of memory state.
3831 CHECK(result.IsEmpty()); 3727 CHECK(result.IsEmpty());
3832 CHECK(context->HasOutOfMemoryException()); 3728 CHECK(context->HasOutOfMemoryException());
3833 } 3729 }
3834 3730
3835 3731
3836 v8::Handle<Value> ProvokeOutOfMemory(const v8::Arguments& args) { 3732 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
3837 ApiTestFuzzer::Fuzz(); 3733 ApiTestFuzzer::Fuzz();
3838 3734
3839 LocalContext context; 3735 LocalContext context;
3840 v8::HandleScope scope(context->GetIsolate()); 3736 v8::HandleScope scope(context->GetIsolate());
3841 Local<Script> script = 3737 Local<Script> script =
3842 Script::Compile(String::New(js_code_causing_out_of_memory)); 3738 Script::Compile(String::New(js_code_causing_out_of_memory));
3843 Local<Value> result = script->Run(); 3739 Local<Value> result = script->Run();
3844 3740
3845 // Check for out of memory state. 3741 // Check for out of memory state.
3846 CHECK(result.IsEmpty()); 3742 CHECK(result.IsEmpty());
3847 CHECK(context->HasOutOfMemoryException()); 3743 CHECK(context->HasOutOfMemoryException());
3848 3744
3849 return result; 3745 args.GetReturnValue().Set(result);
3850 } 3746 }
3851 3747
3852 3748
3853 TEST(OutOfMemoryNested) { 3749 TEST(OutOfMemoryNested) {
3854 // It's not possible to read a snapshot into a heap with different dimensions. 3750 // It's not possible to read a snapshot into a heap with different dimensions.
3855 if (i::Snapshot::IsEnabled()) return; 3751 if (i::Snapshot::IsEnabled()) return;
3856 // Set heap limits. 3752 // Set heap limits.
3857 static const int K = 1024; 3753 static const int K = 1024;
3858 v8::ResourceConstraints constraints; 3754 v8::ResourceConstraints constraints;
3859 constraints.set_max_young_space_size(256 * K); 3755 constraints.set_max_young_space_size(256 * K);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
4112 double number_value = obj->NumberValue(); 4008 double number_value = obj->NumberValue();
4113 CHECK_NE(0, std::isnan(number_value)); 4009 CHECK_NE(0, std::isnan(number_value));
4114 CheckUncle(&try_catch); 4010 CheckUncle(&try_catch);
4115 4011
4116 int64_t integer_value = obj->IntegerValue(); 4012 int64_t integer_value = obj->IntegerValue();
4117 CHECK_EQ(0.0, static_cast<double>(integer_value)); 4013 CHECK_EQ(0.0, static_cast<double>(integer_value));
4118 CheckUncle(&try_catch); 4014 CheckUncle(&try_catch);
4119 } 4015 }
4120 4016
4121 4017
4122 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { 4018 void ThrowFromC(const v8::FunctionCallbackInfo<v8::Value>& args) {
4123 ApiTestFuzzer::Fuzz(); 4019 ApiTestFuzzer::Fuzz();
4124 return v8::ThrowException(v8_str("konto")); 4020 v8::ThrowException(v8_str("konto"));
4125 } 4021 }
4126 4022
4127 4023
4128 v8::Handle<Value> CCatcher(const v8::Arguments& args) { 4024 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) {
4129 if (args.Length() < 1) return v8::False(); 4025 if (args.Length() < 1) {
4026 args.GetReturnValue().Set(false);
4027 return;
4028 }
4130 v8::HandleScope scope(args.GetIsolate()); 4029 v8::HandleScope scope(args.GetIsolate());
4131 v8::TryCatch try_catch; 4030 v8::TryCatch try_catch;
4132 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 4031 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run();
4133 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 4032 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4134 return v8::Boolean::New(try_catch.HasCaught()); 4033 args.GetReturnValue().Set(try_catch.HasCaught());
4135 } 4034 }
4136 4035
4137 4036
4138 THREADED_TEST(APICatch) { 4037 THREADED_TEST(APICatch) {
4139 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4038 v8::HandleScope scope(v8::Isolate::GetCurrent());
4140 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4039 Local<ObjectTemplate> templ = ObjectTemplate::New();
4141 templ->Set(v8_str("ThrowFromC"), 4040 templ->Set(v8_str("ThrowFromC"),
4142 v8::FunctionTemplate::New(ThrowFromC)); 4041 v8::FunctionTemplate::New(ThrowFromC));
4143 LocalContext context(0, templ); 4042 LocalContext context(0, templ);
4144 CompileRun( 4043 CompileRun(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 4089
4191 4090
4192 static void check_reference_error_message( 4091 static void check_reference_error_message(
4193 v8::Handle<v8::Message> message, 4092 v8::Handle<v8::Message> message,
4194 v8::Handle<v8::Value> data) { 4093 v8::Handle<v8::Value> data) {
4195 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; 4094 const char* reference_error = "Uncaught ReferenceError: asdf is not defined";
4196 CHECK(message->Get()->Equals(v8_str(reference_error))); 4095 CHECK(message->Get()->Equals(v8_str(reference_error)));
4197 } 4096 }
4198 4097
4199 4098
4200 static v8::Handle<Value> Fail(const v8::Arguments& args) { 4099 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
4201 ApiTestFuzzer::Fuzz(); 4100 ApiTestFuzzer::Fuzz();
4202 CHECK(false); 4101 CHECK(false);
4203 return v8::Undefined();
4204 } 4102 }
4205 4103
4206 4104
4207 // Test that overwritten methods are not invoked on uncaught exception 4105 // Test that overwritten methods are not invoked on uncaught exception
4208 // formatting. However, they are invoked when performing normal error 4106 // formatting. However, they are invoked when performing normal error
4209 // string conversions. 4107 // string conversions.
4210 TEST(APIThrowMessageOverwrittenToString) { 4108 TEST(APIThrowMessageOverwrittenToString) {
4211 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4109 v8::HandleScope scope(v8::Isolate::GetCurrent());
4212 v8::V8::AddMessageListener(check_reference_error_message); 4110 v8::V8::AddMessageListener(check_reference_error_message);
4213 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4111 Local<ObjectTemplate> templ = ObjectTemplate::New();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4337 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); 4235 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
4338 Local<Value> result = script->Run(); 4236 Local<Value> result = script->Run();
4339 CHECK(result.IsEmpty()); 4237 CHECK(result.IsEmpty());
4340 CHECK(try_catch.HasCaught()); 4238 CHECK(try_catch.HasCaught());
4341 String::Utf8Value exception_value(try_catch.Exception()); 4239 String::Utf8Value exception_value(try_catch.Exception());
4342 CHECK_EQ("konto", *exception_value); 4240 CHECK_EQ("konto", *exception_value);
4343 } 4241 }
4344 4242
4345 4243
4346 4244
4347 v8::Handle<Value> CThrowCountDown(const v8::Arguments& args) { 4245 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) {
4348 ApiTestFuzzer::Fuzz(); 4246 ApiTestFuzzer::Fuzz();
4349 CHECK_EQ(4, args.Length()); 4247 CHECK_EQ(4, args.Length());
4350 int count = args[0]->Int32Value(); 4248 int count = args[0]->Int32Value();
4351 int cInterval = args[2]->Int32Value(); 4249 int cInterval = args[2]->Int32Value();
4352 if (count == 0) { 4250 if (count == 0) {
4353 return v8::ThrowException(v8_str("FromC")); 4251 v8::ThrowException(v8_str("FromC"));
4252 return;
4354 } else { 4253 } else {
4355 Local<v8::Object> global = Context::GetCurrent()->Global(); 4254 Local<v8::Object> global = Context::GetCurrent()->Global();
4356 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); 4255 Local<Value> fun = global->Get(v8_str("JSThrowCountDown"));
4357 v8::Handle<Value> argv[] = { v8_num(count - 1), 4256 v8::Handle<Value> argv[] = { v8_num(count - 1),
4358 args[1], 4257 args[1],
4359 args[2], 4258 args[2],
4360 args[3] }; 4259 args[3] };
4361 if (count % cInterval == 0) { 4260 if (count % cInterval == 0) {
4362 v8::TryCatch try_catch; 4261 v8::TryCatch try_catch;
4363 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); 4262 Local<Value> result = fun.As<Function>()->Call(global, 4, argv);
4364 int expected = args[3]->Int32Value(); 4263 int expected = args[3]->Int32Value();
4365 if (try_catch.HasCaught()) { 4264 if (try_catch.HasCaught()) {
4366 CHECK_EQ(expected, count); 4265 CHECK_EQ(expected, count);
4367 CHECK(result.IsEmpty()); 4266 CHECK(result.IsEmpty());
4368 CHECK(!i::Isolate::Current()->has_scheduled_exception()); 4267 CHECK(!i::Isolate::Current()->has_scheduled_exception());
4369 } else { 4268 } else {
4370 CHECK_NE(expected, count); 4269 CHECK_NE(expected, count);
4371 } 4270 }
4372 return result; 4271 args.GetReturnValue().Set(result);
4272 return;
4373 } else { 4273 } else {
4374 return fun.As<Function>()->Call(global, 4, argv); 4274 args.GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv));
4275 return;
4375 } 4276 }
4376 } 4277 }
4377 } 4278 }
4378 4279
4379 4280
4380 v8::Handle<Value> JSCheck(const v8::Arguments& args) { 4281 void JSCheck(const v8::FunctionCallbackInfo<v8::Value>& args) {
4381 ApiTestFuzzer::Fuzz(); 4282 ApiTestFuzzer::Fuzz();
4382 CHECK_EQ(3, args.Length()); 4283 CHECK_EQ(3, args.Length());
4383 bool equality = args[0]->BooleanValue(); 4284 bool equality = args[0]->BooleanValue();
4384 int count = args[1]->Int32Value(); 4285 int count = args[1]->Int32Value();
4385 int expected = args[2]->Int32Value(); 4286 int expected = args[2]->Int32Value();
4386 if (equality) { 4287 if (equality) {
4387 CHECK_EQ(count, expected); 4288 CHECK_EQ(count, expected);
4388 } else { 4289 } else {
4389 CHECK_NE(count, expected); 4290 CHECK_NE(count, expected);
4390 } 4291 }
4391 return v8::Undefined();
4392 } 4292 }
4393 4293
4394 4294
4395 THREADED_TEST(EvalInTryFinally) { 4295 THREADED_TEST(EvalInTryFinally) {
4396 LocalContext context; 4296 LocalContext context;
4397 v8::HandleScope scope(context->GetIsolate()); 4297 v8::HandleScope scope(context->GetIsolate());
4398 v8::TryCatch try_catch; 4298 v8::TryCatch try_catch;
4399 CompileRun("(function() {" 4299 CompileRun("(function() {"
4400 " try {" 4300 " try {"
4401 " eval('asldkf (*&^&*^');" 4301 " eval('asldkf (*&^&*^');"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4476 4376
4477 // JS[6] *C[5] @JS[4] C[3] JS[2] C[1] JS[0] 4377 // JS[6] *C[5] @JS[4] C[3] JS[2] C[1] JS[0]
4478 v8::Handle<Value> a4[argc] = { v8_num(6), v8_num(4), v8_num(5), v8_num(4) }; 4378 v8::Handle<Value> a4[argc] = { v8_num(6), v8_num(4), v8_num(5), v8_num(4) };
4479 fun->Call(fun, argc, a4); 4379 fun->Call(fun, argc, a4);
4480 4380
4481 // JS[6] C[5] *JS[4] @C[3] JS[2] C[1] JS[0] 4381 // JS[6] C[5] *JS[4] @C[3] JS[2] C[1] JS[0]
4482 v8::Handle<Value> a5[argc] = { v8_num(6), v8_num(4), v8_num(3), v8_num(3) }; 4382 v8::Handle<Value> a5[argc] = { v8_num(6), v8_num(4), v8_num(3), v8_num(3) };
4483 fun->Call(fun, argc, a5); 4383 fun->Call(fun, argc, a5);
4484 } 4384 }
4485 4385
4486 4386 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
4487 v8::Handle<Value> ThrowValue(const v8::Arguments& args) {
4488 ApiTestFuzzer::Fuzz(); 4387 ApiTestFuzzer::Fuzz();
4489 CHECK_EQ(1, args.Length()); 4388 CHECK_EQ(1, args.Length());
4490 return v8::ThrowException(args[0]); 4389 v8::ThrowException(args[0]);
4491 } 4390 }
4492 4391
4493 4392
4494 THREADED_TEST(ThrowValues) { 4393 THREADED_TEST(ThrowValues) {
4495 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4394 v8::HandleScope scope(v8::Isolate::GetCurrent());
4496 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4395 Local<ObjectTemplate> templ = ObjectTemplate::New();
4497 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue)); 4396 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue));
4498 LocalContext context(0, templ); 4397 LocalContext context(0, templ);
4499 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 4398 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
4500 "function Run(obj) {" 4399 "function Run(obj) {"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4547 LocalContext context; 4446 LocalContext context;
4548 v8::HandleScope scope(context->GetIsolate()); 4447 v8::HandleScope scope(context->GetIsolate());
4549 v8::TryCatch try_catch; 4448 v8::TryCatch try_catch;
4550 CHECK(!try_catch.HasCaught()); 4449 CHECK(!try_catch.HasCaught());
4551 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); 4450 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };");
4552 CompileRun("f({toString: function() { throw 42; }});"); 4451 CompileRun("f({toString: function() { throw 42; }});");
4553 CHECK(!try_catch.HasCaught()); 4452 CHECK(!try_catch.HasCaught());
4554 } 4453 }
4555 4454
4556 4455
4557 v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) { 4456 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
4558 v8::TryCatch try_catch; 4457 v8::TryCatch try_catch;
4559 return v8::Undefined();
4560 } 4458 }
4561 4459
4562 4460
4563 THREADED_TEST(TryCatchAndFinally) { 4461 THREADED_TEST(TryCatchAndFinally) {
4564 LocalContext context; 4462 LocalContext context;
4565 v8::HandleScope scope(context->GetIsolate()); 4463 v8::HandleScope scope(context->GetIsolate());
4566 context->Global()->Set( 4464 context->Global()->Set(
4567 v8_str("native_with_try_catch"), 4465 v8_str("native_with_try_catch"),
4568 v8::FunctionTemplate::New(WithTryCatch)->GetFunction()); 4466 v8::FunctionTemplate::New(WithTryCatch)->GetFunction());
4569 v8::TryCatch try_catch; 4467 v8::TryCatch try_catch;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4637 4535
4638 THREADED_TEST(MultiRun) { 4536 THREADED_TEST(MultiRun) {
4639 LocalContext context; 4537 LocalContext context;
4640 v8::HandleScope scope(context->GetIsolate()); 4538 v8::HandleScope scope(context->GetIsolate());
4641 Local<Script> script = Script::Compile(v8_str("x")); 4539 Local<Script> script = Script::Compile(v8_str("x"));
4642 for (int i = 0; i < 10; i++) 4540 for (int i = 0; i < 10; i++)
4643 script->Run(); 4541 script->Run();
4644 } 4542 }
4645 4543
4646 4544
4647 static v8::Handle<Value> GetXValue(Local<String> name, 4545 static void GetXValue(Local<String> name,
4648 const AccessorInfo& info) { 4546 const v8::PropertyCallbackInfo<v8::Value>& info) {
4649 ApiTestFuzzer::Fuzz(); 4547 ApiTestFuzzer::Fuzz();
4650 CHECK_EQ(info.Data(), v8_str("donut")); 4548 CHECK_EQ(info.Data(), v8_str("donut"));
4651 CHECK_EQ(name, v8_str("x")); 4549 CHECK_EQ(name, v8_str("x"));
4652 return name; 4550 info.GetReturnValue().Set(name);
4653 } 4551 }
4654 4552
4655 4553
4656 THREADED_TEST(SimplePropertyRead) { 4554 THREADED_TEST(SimplePropertyRead) {
4657 LocalContext context; 4555 LocalContext context;
4658 v8::HandleScope scope(context->GetIsolate()); 4556 v8::HandleScope scope(context->GetIsolate());
4659 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4557 Local<ObjectTemplate> templ = ObjectTemplate::New();
4660 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 4558 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
4661 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4559 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4662 Local<Script> script = Script::Compile(v8_str("obj.x")); 4560 Local<Script> script = Script::Compile(v8_str("obj.x"));
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
4879 v8::TryCatch try_catch; 4777 v8::TryCatch try_catch;
4880 CompileRun("Object.defineProperty(obj2, 'x'," 4778 CompileRun("Object.defineProperty(obj2, 'x',"
4881 "{get: function() { return 'func'; }})"); 4779 "{get: function() { return 'func'; }})");
4882 CHECK(try_catch.HasCaught()); 4780 CHECK(try_catch.HasCaught());
4883 String::Utf8Value exception_value(try_catch.Exception()); 4781 String::Utf8Value exception_value(try_catch.Exception());
4884 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); 4782 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x");
4885 } 4783 }
4886 } 4784 }
4887 4785
4888 4786
4889 static v8::Handle<Value> Get239Value(Local<String> name, 4787 static void Get239Value(Local<String> name,
4890 const AccessorInfo& info) { 4788 const v8::PropertyCallbackInfo<v8::Value>& info) {
4891 ApiTestFuzzer::Fuzz(); 4789 ApiTestFuzzer::Fuzz();
4892 CHECK_EQ(info.Data(), v8_str("donut")); 4790 CHECK_EQ(info.Data(), v8_str("donut"));
4893 CHECK_EQ(name, v8_str("239")); 4791 CHECK_EQ(name, v8_str("239"));
4894 return name; 4792 info.GetReturnValue().Set(name);
4895 } 4793 }
4896 4794
4897 4795
4898 THREADED_TEST(ElementAPIAccessor) { 4796 THREADED_TEST(ElementAPIAccessor) {
4899 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4797 v8::HandleScope scope(v8::Isolate::GetCurrent());
4900 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4798 Local<ObjectTemplate> templ = ObjectTemplate::New();
4901 LocalContext context; 4799 LocalContext context;
4902 4800
4903 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 4801 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
4904 CompileRun("var obj2 = {};"); 4802 CompileRun("var obj2 = {};");
(...skipping 12 matching lines...) Expand all
4917 ExpectString("obj1['239']", "239"); 4815 ExpectString("obj1['239']", "239");
4918 ExpectString("obj2['239']", "239"); 4816 ExpectString("obj2['239']", "239");
4919 } 4817 }
4920 4818
4921 4819
4922 v8::Persistent<Value> xValue; 4820 v8::Persistent<Value> xValue;
4923 4821
4924 4822
4925 static void SetXValue(Local<String> name, 4823 static void SetXValue(Local<String> name,
4926 Local<Value> value, 4824 Local<Value> value,
4927 const AccessorInfo& info) { 4825 const v8::PropertyCallbackInfo<void>& info) {
4928 CHECK_EQ(value, v8_num(4)); 4826 CHECK_EQ(value, v8_num(4));
4929 CHECK_EQ(info.Data(), v8_str("donut")); 4827 CHECK_EQ(info.Data(), v8_str("donut"));
4930 CHECK_EQ(name, v8_str("x")); 4828 CHECK_EQ(name, v8_str("x"));
4931 CHECK(xValue.IsEmpty()); 4829 CHECK(xValue.IsEmpty());
4932 xValue.Reset(info.GetIsolate(), value); 4830 xValue.Reset(info.GetIsolate(), value);
4933 } 4831 }
4934 4832
4935 4833
4936 THREADED_TEST(SimplePropertyWrite) { 4834 THREADED_TEST(SimplePropertyWrite) {
4937 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4835 v8::HandleScope scope(v8::Isolate::GetCurrent());
(...skipping 26 matching lines...) Expand all
4964 xValue.Dispose(context->GetIsolate()); 4862 xValue.Dispose(context->GetIsolate());
4965 xValue.Clear(); 4863 xValue.Clear();
4966 } 4864 }
4967 } 4865 }
4968 4866
4969 4867
4970 THREADED_TEST(NoAccessors) { 4868 THREADED_TEST(NoAccessors) {
4971 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4869 v8::HandleScope scope(v8::Isolate::GetCurrent());
4972 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4870 Local<ObjectTemplate> templ = ObjectTemplate::New();
4973 templ->SetAccessor(v8_str("x"), 4871 templ->SetAccessor(v8_str("x"),
4974 static_cast<v8::AccessorGetter>(NULL), 4872 static_cast<v8::AccessorGetterCallback>(NULL),
4975 NULL, 4873 NULL,
4976 v8_str("donut")); 4874 v8_str("donut"));
4977 LocalContext context; 4875 LocalContext context;
4978 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4876 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4979 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 4877 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
4980 for (int i = 0; i < 10; i++) { 4878 for (int i = 0; i < 10; i++) {
4981 script->Run(); 4879 script->Run();
4982 } 4880 }
4983 } 4881 }
4984 4882
4985 4883
4986 static v8::Handle<Value> XPropertyGetter(Local<String> property, 4884 static void XPropertyGetter(Local<String> property,
4987 const AccessorInfo& info) { 4885 const v8::PropertyCallbackInfo<v8::Value>& info) {
4988 ApiTestFuzzer::Fuzz(); 4886 ApiTestFuzzer::Fuzz();
4989 CHECK(info.Data()->IsUndefined()); 4887 CHECK(info.Data()->IsUndefined());
4990 return property; 4888 info.GetReturnValue().Set(property);
4991 } 4889 }
4992 4890
4993 4891
4994 THREADED_TEST(NamedInterceptorPropertyRead) { 4892 THREADED_TEST(NamedInterceptorPropertyRead) {
4995 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4893 v8::HandleScope scope(v8::Isolate::GetCurrent());
4996 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4894 Local<ObjectTemplate> templ = ObjectTemplate::New();
4997 templ->SetNamedPropertyHandler(XPropertyGetter); 4895 templ->SetNamedPropertyHandler(XPropertyGetter);
4998 LocalContext context; 4896 LocalContext context;
4999 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4897 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5000 Local<Script> script = Script::Compile(v8_str("obj.x")); 4898 Local<Script> script = Script::Compile(v8_str("obj.x"));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
5069 } 4967 }
5070 4968
5071 // Return to the original context and force some object to the slow case 4969 // Return to the original context and force some object to the slow case
5072 // to cause the NormalizedMapCache to verify. 4970 // to cause the NormalizedMapCache to verify.
5073 context1->Enter(); 4971 context1->Enter();
5074 CompileRun("var obj = { x : 0 }; delete obj.x;"); 4972 CompileRun("var obj = { x : 0 }; delete obj.x;");
5075 context1->Exit(); 4973 context1->Exit();
5076 } 4974 }
5077 4975
5078 4976
5079 static v8::Handle<Value> SetXOnPrototypeGetter(Local<String> property, 4977 static void SetXOnPrototypeGetter(
5080 const AccessorInfo& info) { 4978 Local<String> property,
4979 const v8::PropertyCallbackInfo<v8::Value>& info) {
5081 // Set x on the prototype object and do not handle the get request. 4980 // Set x on the prototype object and do not handle the get request.
5082 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 4981 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
5083 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 4982 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
5084 return v8::Handle<Value>();
5085 } 4983 }
5086 4984
5087 4985
5088 // This is a regression test for http://crbug.com/20104. Map 4986 // This is a regression test for http://crbug.com/20104. Map
5089 // transitions should not interfere with post interceptor lookup. 4987 // transitions should not interfere with post interceptor lookup.
5090 THREADED_TEST(NamedInterceptorMapTransitionRead) { 4988 THREADED_TEST(NamedInterceptorMapTransitionRead) {
5091 v8::HandleScope scope(v8::Isolate::GetCurrent()); 4989 v8::HandleScope scope(v8::Isolate::GetCurrent());
5092 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); 4990 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New();
5093 Local<v8::ObjectTemplate> instance_template 4991 Local<v8::ObjectTemplate> instance_template
5094 = function_template->InstanceTemplate(); 4992 = function_template->InstanceTemplate();
5095 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); 4993 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
5096 LocalContext context; 4994 LocalContext context;
5097 context->Global()->Set(v8_str("F"), function_template->GetFunction()); 4995 context->Global()->Set(v8_str("F"), function_template->GetFunction());
5098 // Create an instance of F and introduce a map transition for x. 4996 // Create an instance of F and introduce a map transition for x.
5099 CompileRun("var o = new F(); o.x = 23;"); 4997 CompileRun("var o = new F(); o.x = 23;");
5100 // Create an instance of F and invoke the getter. The result should be 23. 4998 // Create an instance of F and invoke the getter. The result should be 23.
5101 Local<Value> result = CompileRun("o = new F(); o.x"); 4999 Local<Value> result = CompileRun("o = new F(); o.x");
5102 CHECK_EQ(result->Int32Value(), 23); 5000 CHECK_EQ(result->Int32Value(), 23);
5103 } 5001 }
5104 5002
5105 5003
5106 static v8::Handle<Value> IndexedPropertyGetter(uint32_t index, 5004 static void IndexedPropertyGetter(
5107 const AccessorInfo& info) { 5005 uint32_t index,
5006 const v8::PropertyCallbackInfo<v8::Value>& info) {
5108 ApiTestFuzzer::Fuzz(); 5007 ApiTestFuzzer::Fuzz();
5109 if (index == 37) { 5008 if (index == 37) {
5110 return v8::Handle<Value>(v8_num(625)); 5009 info.GetReturnValue().Set(v8_num(625));
5111 } 5010 }
5112 return v8::Handle<Value>();
5113 } 5011 }
5114 5012
5115 5013
5116 static v8::Handle<Value> IndexedPropertySetter(uint32_t index, 5014 static void IndexedPropertySetter(
5117 Local<Value> value, 5015 uint32_t index,
5118 const AccessorInfo& info) { 5016 Local<Value> value,
5017 const v8::PropertyCallbackInfo<v8::Value>& info) {
5119 ApiTestFuzzer::Fuzz(); 5018 ApiTestFuzzer::Fuzz();
5120 if (index == 39) { 5019 if (index == 39) {
5121 return value; 5020 info.GetReturnValue().Set(value);
5122 } 5021 }
5123 return v8::Handle<Value>();
5124 } 5022 }
5125 5023
5126 5024
5127 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 5025 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
5128 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5026 v8::HandleScope scope(v8::Isolate::GetCurrent());
5129 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5027 Local<ObjectTemplate> templ = ObjectTemplate::New();
5130 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, 5028 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
5131 IndexedPropertySetter); 5029 IndexedPropertySetter);
5132 LocalContext context; 5030 LocalContext context;
5133 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5031 context->Global()->Set(v8_str("obj"), templ->NewInstance());
(...skipping 13 matching lines...) Expand all
5147 CHECK_EQ(v8_num(5), result); 5045 CHECK_EQ(v8_num(5), result);
5148 result = setter_script->Run(); 5046 result = setter_script->Run();
5149 CHECK_EQ(v8_num(23), result); 5047 CHECK_EQ(v8_num(23), result);
5150 result = interceptor_setter_script->Run(); 5048 result = interceptor_setter_script->Run();
5151 CHECK_EQ(v8_num(23), result); 5049 CHECK_EQ(v8_num(23), result);
5152 result = interceptor_getter_script->Run(); 5050 result = interceptor_getter_script->Run();
5153 CHECK_EQ(v8_num(625), result); 5051 CHECK_EQ(v8_num(625), result);
5154 } 5052 }
5155 5053
5156 5054
5157 static v8::Handle<Value> UnboxedDoubleIndexedPropertyGetter( 5055 static void UnboxedDoubleIndexedPropertyGetter(
5158 uint32_t index, 5056 uint32_t index,
5159 const AccessorInfo& info) { 5057 const v8::PropertyCallbackInfo<v8::Value>& info) {
5160 ApiTestFuzzer::Fuzz(); 5058 ApiTestFuzzer::Fuzz();
5161 if (index < 25) { 5059 if (index < 25) {
5162 return v8::Handle<Value>(v8_num(index)); 5060 info.GetReturnValue().Set(v8_num(index));
5163 } 5061 }
5164 return v8::Handle<Value>();
5165 } 5062 }
5166 5063
5167 5064
5168 static v8::Handle<Value> UnboxedDoubleIndexedPropertySetter( 5065 static void UnboxedDoubleIndexedPropertySetter(
5169 uint32_t index, 5066 uint32_t index,
5170 Local<Value> value, 5067 Local<Value> value,
5171 const AccessorInfo& info) { 5068 const v8::PropertyCallbackInfo<v8::Value>& info) {
5172 ApiTestFuzzer::Fuzz(); 5069 ApiTestFuzzer::Fuzz();
5173 if (index < 25) { 5070 if (index < 25) {
5174 return v8::Handle<Value>(v8_num(index)); 5071 info.GetReturnValue().Set(v8_num(index));
5175 } 5072 }
5176 return v8::Handle<Value>();
5177 } 5073 }
5178 5074
5179 5075
5180 Handle<v8::Array> UnboxedDoubleIndexedPropertyEnumerator( 5076 void UnboxedDoubleIndexedPropertyEnumerator(
5181 const AccessorInfo& info) { 5077 const v8::PropertyCallbackInfo<v8::Array>& info) {
5182 // Force the list of returned keys to be stored in a FastDoubleArray. 5078 // Force the list of returned keys to be stored in a FastDoubleArray.
5183 Local<Script> indexed_property_names_script = Script::Compile(v8_str( 5079 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
5184 "keys = new Array(); keys[125000] = 1;" 5080 "keys = new Array(); keys[125000] = 1;"
5185 "for(i = 0; i < 80000; i++) { keys[i] = i; };" 5081 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
5186 "keys.length = 25; keys;")); 5082 "keys.length = 25; keys;"));
5187 Local<Value> result = indexed_property_names_script->Run(); 5083 Local<Value> result = indexed_property_names_script->Run();
5188 return Local<v8::Array>::Cast(result); 5084 info.GetReturnValue().Set(Local<v8::Array>::Cast(result));
5189 } 5085 }
5190 5086
5191 5087
5192 // Make sure that the the interceptor code in the runtime properly handles 5088 // Make sure that the the interceptor code in the runtime properly handles
5193 // merging property name lists for double-array-backed arrays. 5089 // merging property name lists for double-array-backed arrays.
5194 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { 5090 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) {
5195 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5091 v8::HandleScope scope(v8::Isolate::GetCurrent());
5196 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5092 Local<ObjectTemplate> templ = ObjectTemplate::New();
5197 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, 5093 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
5198 UnboxedDoubleIndexedPropertySetter, 5094 UnboxedDoubleIndexedPropertySetter,
(...skipping 10 matching lines...) Expand all
5209 "obj;")); 5105 "obj;"));
5210 Local<Value> result = create_unboxed_double_script->Run(); 5106 Local<Value> result = create_unboxed_double_script->Run();
5211 CHECK(result->ToObject()->HasRealIndexedProperty(2000)); 5107 CHECK(result->ToObject()->HasRealIndexedProperty(2000));
5212 Local<Script> key_count_check = Script::Compile(v8_str( 5108 Local<Script> key_count_check = Script::Compile(v8_str(
5213 "key_count;")); 5109 "key_count;"));
5214 result = key_count_check->Run(); 5110 result = key_count_check->Run();
5215 CHECK_EQ(v8_num(40013), result); 5111 CHECK_EQ(v8_num(40013), result);
5216 } 5112 }
5217 5113
5218 5114
5219 Handle<v8::Array> NonStrictArgsIndexedPropertyEnumerator( 5115 void NonStrictArgsIndexedPropertyEnumerator(
5220 const AccessorInfo& info) { 5116 const v8::PropertyCallbackInfo<v8::Array>& info) {
5221 // Force the list of returned keys to be stored in a Arguments object. 5117 // Force the list of returned keys to be stored in a Arguments object.
5222 Local<Script> indexed_property_names_script = Script::Compile(v8_str( 5118 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
5223 "function f(w,x) {" 5119 "function f(w,x) {"
5224 " return arguments;" 5120 " return arguments;"
5225 "}" 5121 "}"
5226 "keys = f(0, 1, 2, 3);" 5122 "keys = f(0, 1, 2, 3);"
5227 "keys;")); 5123 "keys;"));
5228 Local<Object> result = 5124 Local<Object> result =
5229 Local<Object>::Cast(indexed_property_names_script->Run()); 5125 Local<Object>::Cast(indexed_property_names_script->Run());
5230 // Have to populate the handle manually, as it's not Cast-able. 5126 // Have to populate the handle manually, as it's not Cast-able.
5231 i::Handle<i::JSObject> o = 5127 i::Handle<i::JSObject> o =
5232 v8::Utils::OpenHandle<Object, i::JSObject>(result); 5128 v8::Utils::OpenHandle<Object, i::JSObject>(result);
5233 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o)); 5129 i::Handle<i::JSArray> array(reinterpret_cast<i::JSArray*>(*o));
5234 return v8::Utils::ToLocal(array); 5130 info.GetReturnValue().Set(v8::Utils::ToLocal(array));
5235 } 5131 }
5236 5132
5237 5133
5238 static v8::Handle<Value> NonStrictIndexedPropertyGetter( 5134 static void NonStrictIndexedPropertyGetter(
5239 uint32_t index, 5135 uint32_t index,
5240 const AccessorInfo& info) { 5136 const v8::PropertyCallbackInfo<v8::Value>& info) {
5241 ApiTestFuzzer::Fuzz(); 5137 ApiTestFuzzer::Fuzz();
5242 if (index < 4) { 5138 if (index < 4) {
5243 return v8::Handle<Value>(v8_num(index)); 5139 info.GetReturnValue().Set(v8_num(index));
5244 } 5140 }
5245 return v8::Handle<Value>();
5246 } 5141 }
5247 5142
5248 5143
5249 // Make sure that the the interceptor code in the runtime properly handles 5144 // Make sure that the the interceptor code in the runtime properly handles
5250 // merging property name lists for non-string arguments arrays. 5145 // merging property name lists for non-string arguments arrays.
5251 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { 5146 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) {
5252 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5147 v8::HandleScope scope(v8::Isolate::GetCurrent());
5253 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5148 Local<ObjectTemplate> templ = ObjectTemplate::New();
5254 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, 5149 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
5255 0, 5150 0,
5256 0, 5151 0,
5257 0, 5152 0,
5258 NonStrictArgsIndexedPropertyEnumerator); 5153 NonStrictArgsIndexedPropertyEnumerator);
5259 LocalContext context; 5154 LocalContext context;
5260 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5155 context->Global()->Set(v8_str("obj"), templ->NewInstance());
5261 Local<Script> create_args_script = 5156 Local<Script> create_args_script =
5262 Script::Compile(v8_str( 5157 Script::Compile(v8_str(
5263 "var key_count = 0;" 5158 "var key_count = 0;"
5264 "for (x in obj) {key_count++;} key_count;")); 5159 "for (x in obj) {key_count++;} key_count;"));
5265 Local<Value> result = create_args_script->Run(); 5160 Local<Value> result = create_args_script->Run();
5266 CHECK_EQ(v8_num(4), result); 5161 CHECK_EQ(v8_num(4), result);
5267 } 5162 }
5268 5163
5269 5164
5270 static v8::Handle<Value> IdentityIndexedPropertyGetter( 5165 static void IdentityIndexedPropertyGetter(
5271 uint32_t index, 5166 uint32_t index,
5272 const AccessorInfo& info) { 5167 const v8::PropertyCallbackInfo<v8::Value>& info) {
5273 return v8::Integer::NewFromUnsigned(index); 5168 info.GetReturnValue().Set(index);
5274 } 5169 }
5275 5170
5276 5171
5277 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { 5172 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) {
5278 v8::HandleScope scope(v8::Isolate::GetCurrent()); 5173 v8::HandleScope scope(v8::Isolate::GetCurrent());
5279 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5174 Local<ObjectTemplate> templ = ObjectTemplate::New();
5280 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 5175 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
5281 5176
5282 LocalContext context; 5177 LocalContext context;
5283 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 5178 context->Global()->Set(v8_str("obj"), templ->NewInstance());
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
5834 p_str.Dispose(); 5729 p_str.Dispose();
5835 Local<Script> scr = Script::Compile(v8_str("")); 5730 Local<Script> scr = Script::Compile(v8_str(""));
5836 v8::Persistent<Script> p_scr(isolate, scr); 5731 v8::Persistent<Script> p_scr(isolate, scr);
5837 p_scr.Dispose(); 5732 p_scr.Dispose();
5838 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5733 Local<ObjectTemplate> templ = ObjectTemplate::New();
5839 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); 5734 v8::Persistent<ObjectTemplate> p_templ(isolate, templ);
5840 p_templ.Dispose(); 5735 p_templ.Dispose();
5841 } 5736 }
5842 5737
5843 5738
5844 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) { 5739 static void HandleLogDelegator(
5740 const v8::FunctionCallbackInfo<v8::Value>& args) {
5845 ApiTestFuzzer::Fuzz(); 5741 ApiTestFuzzer::Fuzz();
5846 return v8::Undefined();
5847 } 5742 }
5848 5743
5849 5744
5850 THREADED_TEST(GlobalObjectTemplate) { 5745 THREADED_TEST(GlobalObjectTemplate) {
5851 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 5746 v8::Isolate* isolate = v8::Isolate::GetCurrent();
5852 v8::HandleScope handle_scope(isolate); 5747 v8::HandleScope handle_scope(isolate);
5853 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 5748 Local<ObjectTemplate> global_template = ObjectTemplate::New();
5854 global_template->Set(v8_str("JSNI_Log"), 5749 global_template->Set(v8_str("JSNI_Log"),
5855 v8::FunctionTemplate::New(HandleLogDelegator)); 5750 v8::FunctionTemplate::New(HandleLogDelegator));
5856 v8::Local<Context> context = Context::New(isolate, 0, global_template); 5751 v8::Local<Context> context = Context::New(isolate, 0, global_template);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
6071 Context::Scope lock(context); 5966 Context::Scope lock(context);
6072 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 5967 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
6073 CHECK_EQ(result, v8::Integer::New(3)); 5968 CHECK_EQ(result, v8::Integer::New(3));
6074 } 5969 }
6075 5970
6076 5971
6077 class NativeFunctionExtension : public Extension { 5972 class NativeFunctionExtension : public Extension {
6078 public: 5973 public:
6079 NativeFunctionExtension(const char* name, 5974 NativeFunctionExtension(const char* name,
6080 const char* source, 5975 const char* source,
6081 v8::InvocationCallback fun = &Echo) 5976 v8::FunctionCallback fun = &Echo)
6082 : Extension(name, source), 5977 : Extension(name, source),
6083 function_(fun) { } 5978 function_(fun) { }
6084 5979
6085 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 5980 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
6086 v8::Handle<v8::String> name) { 5981 v8::Handle<v8::String> name) {
6087 return v8::FunctionTemplate::New(function_); 5982 return v8::FunctionTemplate::New(function_);
6088 } 5983 }
6089 5984
6090 static v8::Handle<v8::Value> Echo(const v8::Arguments& args) { 5985 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) {
6091 if (args.Length() >= 1) return (args[0]); 5986 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]);
6092 return v8::Undefined();
6093 } 5987 }
6094 private: 5988 private:
6095 v8::InvocationCallback function_; 5989 v8::FunctionCallback function_;
6096 }; 5990 };
6097 5991
6098 5992
6099 THREADED_TEST(NativeFunctionDeclaration) { 5993 THREADED_TEST(NativeFunctionDeclaration) {
6100 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 5994 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
6101 const char* name = "nativedecl"; 5995 const char* name = "nativedecl";
6102 v8::RegisterExtension(new NativeFunctionExtension(name, 5996 v8::RegisterExtension(new NativeFunctionExtension(name,
6103 "native function foo();")); 5997 "native function foo();"));
6104 const char* extension_names[] = { name }; 5998 const char* extension_names[] = { name };
6105 v8::ExtensionConfiguration extensions(1, extension_names); 5999 v8::ExtensionConfiguration extensions(1, extension_names);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
6182 "native function A();" 6076 "native function A();"
6183 "native function B();" 6077 "native function B();"
6184 "native function C();" 6078 "native function C();"
6185 "function Foo(i) {" 6079 "function Foo(i) {"
6186 " if (i == 0) return A();" 6080 " if (i == 0) return A();"
6187 " if (i == 1) return B();" 6081 " if (i == 1) return B();"
6188 " if (i == 2) return C();" 6082 " if (i == 2) return C();"
6189 "}"; 6083 "}";
6190 6084
6191 6085
6192 static v8::Handle<Value> CallFun(const v8::Arguments& args) { 6086 static void CallFun(const v8::FunctionCallbackInfo<v8::Value>& args) {
6193 ApiTestFuzzer::Fuzz(); 6087 ApiTestFuzzer::Fuzz();
6194 if (args.IsConstructCall()) { 6088 if (args.IsConstructCall()) {
6195 args.This()->Set(v8_str("data"), args.Data()); 6089 args.This()->Set(v8_str("data"), args.Data());
6196 return v8::Null(); 6090 args.GetReturnValue().SetNull();
6091 return;
6197 } 6092 }
6198 return args.Data(); 6093 args.GetReturnValue().Set(args.Data());
6199 } 6094 }
6200 6095
6201 6096
6202 class FunctionExtension : public Extension { 6097 class FunctionExtension : public Extension {
6203 public: 6098 public:
6204 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { } 6099 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { }
6205 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 6100 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
6206 v8::Handle<String> name); 6101 v8::Handle<String> name);
6207 }; 6102 };
6208 6103
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
6353 v8::Persistent<Script> script_; 6248 v8::Persistent<Script> script_;
6354 }; 6249 };
6355 6250
6356 static void HandleWeakReference(v8::Isolate* isolate, 6251 static void HandleWeakReference(v8::Isolate* isolate,
6357 v8::Persistent<v8::Value>* obj, 6252 v8::Persistent<v8::Value>* obj,
6358 Snorkel* snorkel) { 6253 Snorkel* snorkel) {
6359 delete snorkel; 6254 delete snorkel;
6360 obj->ClearWeak(isolate); 6255 obj->ClearWeak(isolate);
6361 } 6256 }
6362 6257
6363 v8::Handle<Value> WhammyPropertyGetter(Local<String> name, 6258 void WhammyPropertyGetter(Local<String> name,
6364 const AccessorInfo& info) { 6259 const v8::PropertyCallbackInfo<v8::Value>& info) {
6365 Whammy* whammy = 6260 Whammy* whammy =
6366 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 6261 static_cast<Whammy*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
6367 6262
6368 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_]; 6263 v8::Persistent<v8::Object>& prev = whammy->objects_[whammy->cursor_];
6369 6264
6370 v8::Handle<v8::Object> obj = v8::Object::New(); 6265 v8::Handle<v8::Object> obj = v8::Object::New();
6371 if (!prev.IsEmpty()) { 6266 if (!prev.IsEmpty()) {
6372 v8::Local<v8::Object>::New(info.GetIsolate(), prev) 6267 v8::Local<v8::Object>::New(info.GetIsolate(), prev)
6373 ->Set(v8_str("next"), obj); 6268 ->Set(v8_str("next"), obj);
6374 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference); 6269 prev.MakeWeak<Value, Snorkel>(new Snorkel(), &HandleWeakReference);
6375 whammy->objects_[whammy->cursor_].Clear(); 6270 whammy->objects_[whammy->cursor_].Clear();
6376 } 6271 }
6377 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); 6272 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj);
6378 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 6273 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
6379 return whammy->getScript()->Run(); 6274 info.GetReturnValue().Set(whammy->getScript()->Run());
6380 } 6275 }
6381 6276
6382 THREADED_TEST(WeakReference) { 6277 THREADED_TEST(WeakReference) {
6383 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 6278 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
6384 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 6279 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
6385 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); 6280 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent());
6386 templ->SetNamedPropertyHandler(WhammyPropertyGetter, 6281 templ->SetNamedPropertyHandler(WhammyPropertyGetter,
6387 0, 0, 0, 0, 6282 0, 0, 0, 0,
6388 v8::External::New(whammy)); 6283 v8::External::New(whammy));
6389 const char* extension_list[] = { "v8/gc" }; 6284 const char* extension_list[] = { "v8/gc" };
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
6539 v8::Local<String> y_str = v8_str("y"); 6434 v8::Local<String> y_str = v8_str("y");
6540 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x"))); 6435 CHECK_EQ(v8::Integer::New(1), o->Get(v8_str("x")));
6541 CHECK(o->Get(y_str)->Equals(y_str)); 6436 CHECK(o->Get(y_str)->Equals(y_str));
6542 } 6437 }
6543 } 6438 }
6544 6439
6545 6440
6546 v8::Handle<Function> args_fun; 6441 v8::Handle<Function> args_fun;
6547 6442
6548 6443
6549 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { 6444 static void ArgumentsTestCallback(
6445 const v8::FunctionCallbackInfo<v8::Value>& args) {
6550 ApiTestFuzzer::Fuzz(); 6446 ApiTestFuzzer::Fuzz();
6551 CHECK_EQ(args_fun, args.Callee()); 6447 CHECK_EQ(args_fun, args.Callee());
6552 CHECK_EQ(3, args.Length()); 6448 CHECK_EQ(3, args.Length());
6553 CHECK_EQ(v8::Integer::New(1), args[0]); 6449 CHECK_EQ(v8::Integer::New(1), args[0]);
6554 CHECK_EQ(v8::Integer::New(2), args[1]); 6450 CHECK_EQ(v8::Integer::New(2), args[1]);
6555 CHECK_EQ(v8::Integer::New(3), args[2]); 6451 CHECK_EQ(v8::Integer::New(3), args[2]);
6556 CHECK_EQ(v8::Undefined(), args[3]); 6452 CHECK_EQ(v8::Undefined(), args[3]);
6557 v8::HandleScope scope(args.GetIsolate()); 6453 v8::HandleScope scope(args.GetIsolate());
6558 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 6454 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
6559 return v8::Undefined();
6560 } 6455 }
6561 6456
6562 6457
6563 THREADED_TEST(Arguments) { 6458 THREADED_TEST(Arguments) {
6564 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6459 v8::HandleScope scope(v8::Isolate::GetCurrent());
6565 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 6460 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
6566 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); 6461 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback));
6567 LocalContext context(NULL, global); 6462 LocalContext context(NULL, global);
6568 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 6463 args_fun = context->Global()->Get(v8_str("f")).As<Function>();
6569 v8_compile("f(1, 2, 3)")->Run(); 6464 v8_compile("f(1, 2, 3)")->Run();
6570 } 6465 }
6571 6466
6572 6467
6573 static v8::Handle<Value> NoBlockGetterX(Local<String> name, 6468 static void NoBlockGetterX(Local<String> name,
6574 const AccessorInfo&) { 6469 const v8::PropertyCallbackInfo<v8::Value>&) {
6575 return v8::Handle<Value>();
6576 } 6470 }
6577 6471
6578 6472
6579 static v8::Handle<Value> NoBlockGetterI(uint32_t index, 6473 static void NoBlockGetterI(uint32_t index,
6580 const AccessorInfo&) { 6474 const v8::PropertyCallbackInfo<v8::Value>&) {
6581 return v8::Handle<Value>();
6582 } 6475 }
6583 6476
6584 6477
6585 static v8::Handle<v8::Boolean> PDeleter(Local<String> name, 6478 static void PDeleter(Local<String> name,
6586 const AccessorInfo&) { 6479 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
6587 if (!name->Equals(v8_str("foo"))) { 6480 if (!name->Equals(v8_str("foo"))) {
6588 return v8::Handle<v8::Boolean>(); // not intercepted 6481 return; // not intercepted
6589 } 6482 }
6590 6483
6591 return v8::False(); // intercepted, and don't delete the property 6484 info.GetReturnValue().Set(false); // intercepted, don't delete the property
6592 } 6485 }
6593 6486
6594 6487
6595 static v8::Handle<v8::Boolean> IDeleter(uint32_t index, const AccessorInfo&) { 6488 static void IDeleter(uint32_t index,
6489 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
6596 if (index != 2) { 6490 if (index != 2) {
6597 return v8::Handle<v8::Boolean>(); // not intercepted 6491 return; // not intercepted
6598 } 6492 }
6599 6493
6600 return v8::False(); // intercepted, and don't delete the property 6494 info.GetReturnValue().Set(false); // intercepted, don't delete the property
6601 } 6495 }
6602 6496
6603 6497
6604 THREADED_TEST(Deleter) { 6498 THREADED_TEST(Deleter) {
6605 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6499 v8::HandleScope scope(v8::Isolate::GetCurrent());
6606 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6500 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6607 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); 6501 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL);
6608 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); 6502 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL);
6609 LocalContext context; 6503 LocalContext context;
6610 context->Global()->Set(v8_str("k"), obj->NewInstance()); 6504 context->Global()->Set(v8_str("k"), obj->NewInstance());
6611 CompileRun( 6505 CompileRun(
6612 "k.foo = 'foo';" 6506 "k.foo = 'foo';"
6613 "k.bar = 'bar';" 6507 "k.bar = 'bar';"
6614 "k[2] = 2;" 6508 "k[2] = 2;"
6615 "k[4] = 4;"); 6509 "k[4] = 4;");
6616 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); 6510 CHECK(v8_compile("delete k.foo")->Run()->IsFalse());
6617 CHECK(v8_compile("delete k.bar")->Run()->IsTrue()); 6511 CHECK(v8_compile("delete k.bar")->Run()->IsTrue());
6618 6512
6619 CHECK_EQ(v8_compile("k.foo")->Run(), v8_str("foo")); 6513 CHECK_EQ(v8_compile("k.foo")->Run(), v8_str("foo"));
6620 CHECK(v8_compile("k.bar")->Run()->IsUndefined()); 6514 CHECK(v8_compile("k.bar")->Run()->IsUndefined());
6621 6515
6622 CHECK(v8_compile("delete k[2]")->Run()->IsFalse()); 6516 CHECK(v8_compile("delete k[2]")->Run()->IsFalse());
6623 CHECK(v8_compile("delete k[4]")->Run()->IsTrue()); 6517 CHECK(v8_compile("delete k[4]")->Run()->IsTrue());
6624 6518
6625 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2)); 6519 CHECK_EQ(v8_compile("k[2]")->Run(), v8_num(2));
6626 CHECK(v8_compile("k[4]")->Run()->IsUndefined()); 6520 CHECK(v8_compile("k[4]")->Run()->IsUndefined());
6627 } 6521 }
6628 6522
6629 6523
6630 static v8::Handle<Value> GetK(Local<String> name, const AccessorInfo&) { 6524 static void GetK(Local<String> name,
6525 const v8::PropertyCallbackInfo<v8::Value>& info) {
6631 ApiTestFuzzer::Fuzz(); 6526 ApiTestFuzzer::Fuzz();
6632 if (name->Equals(v8_str("foo")) || 6527 if (name->Equals(v8_str("foo")) ||
6633 name->Equals(v8_str("bar")) || 6528 name->Equals(v8_str("bar")) ||
6634 name->Equals(v8_str("baz"))) { 6529 name->Equals(v8_str("baz"))) {
6635 return v8::Undefined(); 6530 info.GetReturnValue().SetUndefined();
6636 } 6531 }
6637 return v8::Handle<Value>();
6638 } 6532 }
6639 6533
6640 6534
6641 static v8::Handle<Value> IndexedGetK(uint32_t index, const AccessorInfo&) { 6535 static void IndexedGetK(uint32_t index,
6536 const v8::PropertyCallbackInfo<v8::Value>& info) {
6642 ApiTestFuzzer::Fuzz(); 6537 ApiTestFuzzer::Fuzz();
6643 if (index == 0 || index == 1) return v8::Undefined(); 6538 if (index == 0 || index == 1) info.GetReturnValue().SetUndefined();
6644 return v8::Handle<Value>();
6645 } 6539 }
6646 6540
6647 6541
6648 static v8::Handle<v8::Array> NamedEnum(const AccessorInfo&) { 6542 static void NamedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
6649 ApiTestFuzzer::Fuzz(); 6543 ApiTestFuzzer::Fuzz();
6650 v8::Handle<v8::Array> result = v8::Array::New(3); 6544 v8::Handle<v8::Array> result = v8::Array::New(3);
6651 result->Set(v8::Integer::New(0), v8_str("foo")); 6545 result->Set(v8::Integer::New(0), v8_str("foo"));
6652 result->Set(v8::Integer::New(1), v8_str("bar")); 6546 result->Set(v8::Integer::New(1), v8_str("bar"));
6653 result->Set(v8::Integer::New(2), v8_str("baz")); 6547 result->Set(v8::Integer::New(2), v8_str("baz"));
6654 return result; 6548 info.GetReturnValue().Set(result);
6655 } 6549 }
6656 6550
6657 6551
6658 static v8::Handle<v8::Array> IndexedEnum(const AccessorInfo&) { 6552 static void IndexedEnum(const v8::PropertyCallbackInfo<v8::Array>& info) {
6659 ApiTestFuzzer::Fuzz(); 6553 ApiTestFuzzer::Fuzz();
6660 v8::Handle<v8::Array> result = v8::Array::New(2); 6554 v8::Handle<v8::Array> result = v8::Array::New(2);
6661 result->Set(v8::Integer::New(0), v8_str("0")); 6555 result->Set(v8::Integer::New(0), v8_str("0"));
6662 result->Set(v8::Integer::New(1), v8_str("1")); 6556 result->Set(v8::Integer::New(1), v8_str("1"));
6663 return result; 6557 info.GetReturnValue().Set(result);
6664 } 6558 }
6665 6559
6666 6560
6667 THREADED_TEST(Enumerators) { 6561 THREADED_TEST(Enumerators) {
6668 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6562 v8::HandleScope scope(v8::Isolate::GetCurrent());
6669 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6563 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6670 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 6564 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
6671 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); 6565 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
6672 LocalContext context; 6566 LocalContext context;
6673 context->Global()->Set(v8_str("k"), obj->NewInstance()); 6567 context->Global()->Set(v8_str("k"), obj->NewInstance());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
6718 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14))); 6612 CHECK_EQ(v8_str("foo"), result->Get(v8::Integer::New(14)));
6719 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15))); 6613 CHECK_EQ(v8_str("bar"), result->Get(v8::Integer::New(15)));
6720 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16))); 6614 CHECK_EQ(v8_str("baz"), result->Get(v8::Integer::New(16)));
6721 } 6615 }
6722 6616
6723 6617
6724 int p_getter_count; 6618 int p_getter_count;
6725 int p_getter_count2; 6619 int p_getter_count2;
6726 6620
6727 6621
6728 static v8::Handle<Value> PGetter(Local<String> name, const AccessorInfo& info) { 6622 static void PGetter(Local<String> name,
6623 const v8::PropertyCallbackInfo<v8::Value>& info) {
6729 ApiTestFuzzer::Fuzz(); 6624 ApiTestFuzzer::Fuzz();
6730 p_getter_count++; 6625 p_getter_count++;
6731 v8::Handle<v8::Object> global = Context::GetCurrent()->Global(); 6626 v8::Handle<v8::Object> global = Context::GetCurrent()->Global();
6732 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); 6627 CHECK_EQ(info.Holder(), global->Get(v8_str("o1")));
6733 if (name->Equals(v8_str("p1"))) { 6628 if (name->Equals(v8_str("p1"))) {
6734 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); 6629 CHECK_EQ(info.This(), global->Get(v8_str("o1")));
6735 } else if (name->Equals(v8_str("p2"))) { 6630 } else if (name->Equals(v8_str("p2"))) {
6736 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); 6631 CHECK_EQ(info.This(), global->Get(v8_str("o2")));
6737 } else if (name->Equals(v8_str("p3"))) { 6632 } else if (name->Equals(v8_str("p3"))) {
6738 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); 6633 CHECK_EQ(info.This(), global->Get(v8_str("o3")));
6739 } else if (name->Equals(v8_str("p4"))) { 6634 } else if (name->Equals(v8_str("p4"))) {
6740 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); 6635 CHECK_EQ(info.This(), global->Get(v8_str("o4")));
6741 } 6636 }
6742 return v8::Undefined();
6743 } 6637 }
6744 6638
6745 6639
6746 static void RunHolderTest(v8::Handle<v8::ObjectTemplate> obj) { 6640 static void RunHolderTest(v8::Handle<v8::ObjectTemplate> obj) {
6747 ApiTestFuzzer::Fuzz(); 6641 ApiTestFuzzer::Fuzz();
6748 LocalContext context; 6642 LocalContext context;
6749 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 6643 context->Global()->Set(v8_str("o1"), obj->NewInstance());
6750 CompileRun( 6644 CompileRun(
6751 "o1.__proto__ = { };" 6645 "o1.__proto__ = { };"
6752 "var o2 = { __proto__: o1 };" 6646 "var o2 = { __proto__: o1 };"
6753 "var o3 = { __proto__: o2 };" 6647 "var o3 = { __proto__: o2 };"
6754 "var o4 = { __proto__: o3 };" 6648 "var o4 = { __proto__: o3 };"
6755 "for (var i = 0; i < 10; i++) o4.p4;" 6649 "for (var i = 0; i < 10; i++) o4.p4;"
6756 "for (var i = 0; i < 10; i++) o3.p3;" 6650 "for (var i = 0; i < 10; i++) o3.p3;"
6757 "for (var i = 0; i < 10; i++) o2.p2;" 6651 "for (var i = 0; i < 10; i++) o2.p2;"
6758 "for (var i = 0; i < 10; i++) o1.p1;"); 6652 "for (var i = 0; i < 10; i++) o1.p1;");
6759 } 6653 }
6760 6654
6761 6655
6762 static v8::Handle<Value> PGetter2(Local<String> name, 6656 static void PGetter2(Local<String> name,
6763 const AccessorInfo& info) { 6657 const v8::PropertyCallbackInfo<v8::Value>& info) {
6764 ApiTestFuzzer::Fuzz(); 6658 ApiTestFuzzer::Fuzz();
6765 p_getter_count2++; 6659 p_getter_count2++;
6766 v8::Handle<v8::Object> global = Context::GetCurrent()->Global(); 6660 v8::Handle<v8::Object> global = Context::GetCurrent()->Global();
6767 CHECK_EQ(info.Holder(), global->Get(v8_str("o1"))); 6661 CHECK_EQ(info.Holder(), global->Get(v8_str("o1")));
6768 if (name->Equals(v8_str("p1"))) { 6662 if (name->Equals(v8_str("p1"))) {
6769 CHECK_EQ(info.This(), global->Get(v8_str("o1"))); 6663 CHECK_EQ(info.This(), global->Get(v8_str("o1")));
6770 } else if (name->Equals(v8_str("p2"))) { 6664 } else if (name->Equals(v8_str("p2"))) {
6771 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); 6665 CHECK_EQ(info.This(), global->Get(v8_str("o2")));
6772 } else if (name->Equals(v8_str("p3"))) { 6666 } else if (name->Equals(v8_str("p3"))) {
6773 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); 6667 CHECK_EQ(info.This(), global->Get(v8_str("o3")));
6774 } else if (name->Equals(v8_str("p4"))) { 6668 } else if (name->Equals(v8_str("p4"))) {
6775 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); 6669 CHECK_EQ(info.This(), global->Get(v8_str("o4")));
6776 } 6670 }
6777 return v8::Undefined();
6778 } 6671 }
6779 6672
6780 6673
6781 THREADED_TEST(GetterHolders) { 6674 THREADED_TEST(GetterHolders) {
6782 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6675 v8::HandleScope scope(v8::Isolate::GetCurrent());
6783 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6676 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6784 obj->SetAccessor(v8_str("p1"), PGetter); 6677 obj->SetAccessor(v8_str("p1"), PGetter);
6785 obj->SetAccessor(v8_str("p2"), PGetter); 6678 obj->SetAccessor(v8_str("p2"), PGetter);
6786 obj->SetAccessor(v8_str("p3"), PGetter); 6679 obj->SetAccessor(v8_str("p3"), PGetter);
6787 obj->SetAccessor(v8_str("p4"), PGetter); 6680 obj->SetAccessor(v8_str("p4"), PGetter);
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
7361 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); 7254 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo));
7362 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); 7255 v8::Handle<Value> type_error = v8::Exception::TypeError(foo);
7363 CHECK(type_error->IsObject()); 7256 CHECK(type_error->IsObject());
7364 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); 7257 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo));
7365 v8::Handle<Value> error = v8::Exception::Error(foo); 7258 v8::Handle<Value> error = v8::Exception::Error(foo);
7366 CHECK(error->IsObject()); 7259 CHECK(error->IsObject());
7367 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 7260 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo));
7368 } 7261 }
7369 7262
7370 7263
7371 static v8::Handle<Value> YGetter(Local<String> name, const AccessorInfo& info) { 7264 static void YGetter(Local<String> name,
7265 const v8::PropertyCallbackInfo<v8::Value>& info) {
7372 ApiTestFuzzer::Fuzz(); 7266 ApiTestFuzzer::Fuzz();
7373 return v8_num(10); 7267 info.GetReturnValue().Set(v8_num(10));
7374 } 7268 }
7375 7269
7376 7270
7377 static void YSetter(Local<String> name, 7271 static void YSetter(Local<String> name,
7378 Local<Value> value, 7272 Local<Value> value,
7379 const AccessorInfo& info) { 7273 const v8::PropertyCallbackInfo<void>& info) {
7380 if (info.This()->Has(name)) { 7274 if (info.This()->Has(name)) {
7381 info.This()->Delete(name); 7275 info.This()->Delete(name);
7382 } 7276 }
7383 info.This()->Set(name, value); 7277 info.This()->Set(name, value);
7384 } 7278 }
7385 7279
7386 7280
7387 THREADED_TEST(DeleteAccessor) { 7281 THREADED_TEST(DeleteAccessor) {
7388 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7282 v8::HandleScope scope(v8::Isolate::GetCurrent());
7389 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 7283 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
7444 // Always allow read access. 7338 // Always allow read access.
7445 if (type == v8::ACCESS_GET) 7339 if (type == v8::ACCESS_GET)
7446 return true; 7340 return true;
7447 7341
7448 // Sometimes allow other access. 7342 // Sometimes allow other access.
7449 return g_security_callback_result; 7343 return g_security_callback_result;
7450 } 7344 }
7451 7345
7452 7346
7453 static int trouble_nesting = 0; 7347 static int trouble_nesting = 0;
7454 static v8::Handle<Value> TroubleCallback(const v8::Arguments& args) { 7348 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
7455 ApiTestFuzzer::Fuzz(); 7349 ApiTestFuzzer::Fuzz();
7456 trouble_nesting++; 7350 trouble_nesting++;
7457 7351
7458 // Call a JS function that throws an uncaught exception. 7352 // Call a JS function that throws an uncaught exception.
7459 Local<v8::Object> arg_this = Context::GetCurrent()->Global(); 7353 Local<v8::Object> arg_this = Context::GetCurrent()->Global();
7460 Local<Value> trouble_callee = (trouble_nesting == 3) ? 7354 Local<Value> trouble_callee = (trouble_nesting == 3) ?
7461 arg_this->Get(v8_str("trouble_callee")) : 7355 arg_this->Get(v8_str("trouble_callee")) :
7462 arg_this->Get(v8_str("trouble_caller")); 7356 arg_this->Get(v8_str("trouble_caller"));
7463 CHECK(trouble_callee->IsFunction()); 7357 CHECK(trouble_callee->IsFunction());
7464 return Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL); 7358 args.GetReturnValue().Set(
7359 Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL));
7465 } 7360 }
7466 7361
7467 7362
7468 static int report_count = 0; 7363 static int report_count = 0;
7469 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, 7364 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>,
7470 v8::Handle<Value>) { 7365 v8::Handle<Value>) {
7471 report_count++; 7366 report_count++;
7472 } 7367 }
7473 7368
7474 7369
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
7984 static bool IndexedAccessBlocker(Local<v8::Object> global, 7879 static bool IndexedAccessBlocker(Local<v8::Object> global,
7985 uint32_t key, 7880 uint32_t key,
7986 v8::AccessType type, 7881 v8::AccessType type,
7987 Local<Value> data) { 7882 Local<Value> data) {
7988 return Context::GetCurrent()->Global()->Equals(global) || 7883 return Context::GetCurrent()->Global()->Equals(global) ||
7989 allowed_access_type[type]; 7884 allowed_access_type[type];
7990 } 7885 }
7991 7886
7992 7887
7993 static int g_echo_value = -1; 7888 static int g_echo_value = -1;
7994 static v8::Handle<Value> EchoGetter(Local<String> name, 7889 static void EchoGetter(
7995 const AccessorInfo& info) { 7890 Local<String> name,
7996 return v8_num(g_echo_value); 7891 const v8::PropertyCallbackInfo<v8::Value>& info) {
7892 info.GetReturnValue().Set(v8_num(g_echo_value));
7997 } 7893 }
7998 7894
7999 7895
8000 static void EchoSetter(Local<String> name, 7896 static void EchoSetter(Local<String> name,
8001 Local<Value> value, 7897 Local<Value> value,
8002 const AccessorInfo&) { 7898 const v8::PropertyCallbackInfo<void>&) {
8003 if (value->IsNumber()) 7899 if (value->IsNumber())
8004 g_echo_value = value->Int32Value(); 7900 g_echo_value = value->Int32Value();
8005 } 7901 }
8006 7902
8007 7903
8008 static v8::Handle<Value> UnreachableGetter(Local<String> name, 7904 static void UnreachableGetter(
8009 const AccessorInfo& info) { 7905 Local<String> name,
7906 const v8::PropertyCallbackInfo<v8::Value>& info) {
8010 CHECK(false); // This function should not be called.. 7907 CHECK(false); // This function should not be called..
8011 return v8::Undefined();
8012 } 7908 }
8013 7909
8014 7910
8015 static void UnreachableSetter(Local<String>, Local<Value>, 7911 static void UnreachableSetter(Local<String>,
8016 const AccessorInfo&) { 7912 Local<Value>,
7913 const v8::PropertyCallbackInfo<void>&) {
8017 CHECK(false); // This function should nto be called. 7914 CHECK(false); // This function should nto be called.
8018 } 7915 }
8019 7916
8020 7917
8021 TEST(AccessControl) { 7918 TEST(AccessControl) {
8022 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 7919 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8023 v8::HandleScope handle_scope(isolate); 7920 v8::HandleScope handle_scope(isolate);
8024 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7921 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
8025 7922
8026 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7923 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
8383 CHECK(value->IsTrue()); 8280 CHECK(value->IsTrue());
8384 8281
8385 value = CompileRun("Object.getOwnPropertyNames(object).length == 0"); 8282 value = CompileRun("Object.getOwnPropertyNames(object).length == 0");
8386 CHECK(value->IsTrue()); 8283 CHECK(value->IsTrue());
8387 8284
8388 context1->Exit(); 8285 context1->Exit();
8389 context0->Exit(); 8286 context0->Exit();
8390 } 8287 }
8391 8288
8392 8289
8393 static v8::Handle<v8::Array> IndexedPropertyEnumerator(const AccessorInfo&) { 8290 static void IndexedPropertyEnumerator(
8291 const v8::PropertyCallbackInfo<v8::Array>& info) {
8394 v8::Handle<v8::Array> result = v8::Array::New(2); 8292 v8::Handle<v8::Array> result = v8::Array::New(2);
8395 result->Set(0, v8::Integer::New(7)); 8293 result->Set(0, v8::Integer::New(7));
8396 result->Set(1, v8::Object::New()); 8294 result->Set(1, v8::Object::New());
8397 return result; 8295 info.GetReturnValue().Set(result);
8398 } 8296 }
8399 8297
8400 8298
8401 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) { 8299 static void NamedPropertyEnumerator(
8300 const v8::PropertyCallbackInfo<v8::Array>& info) {
8402 v8::Handle<v8::Array> result = v8::Array::New(2); 8301 v8::Handle<v8::Array> result = v8::Array::New(2);
8403 result->Set(0, v8_str("x")); 8302 result->Set(0, v8_str("x"));
8404 result->Set(1, v8::Object::New()); 8303 result->Set(1, v8::Object::New());
8405 return result; 8304 info.GetReturnValue().Set(result);
8406 } 8305 }
8407 8306
8408 8307
8409 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 8308 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
8410 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8309 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8411 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 8310 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
8412 8311
8413 obj_template->Set(v8_str("7"), v8::Integer::New(7)); 8312 obj_template->Set(v8_str("7"), v8::Integer::New(7));
8414 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 8313 obj_template->Set(v8_str("x"), v8::Integer::New(42));
8415 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 8314 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
(...skipping 12 matching lines...) Expand all
8428 CHECK_EQ(3, result_array->Length()); 8327 CHECK_EQ(3, result_array->Length());
8429 CHECK(result_array->Get(0)->IsString()); 8328 CHECK(result_array->Get(0)->IsString());
8430 CHECK(result_array->Get(1)->IsString()); 8329 CHECK(result_array->Get(1)->IsString());
8431 CHECK(result_array->Get(2)->IsString()); 8330 CHECK(result_array->Get(2)->IsString());
8432 CHECK_EQ(v8_str("7"), result_array->Get(0)); 8331 CHECK_EQ(v8_str("7"), result_array->Get(0));
8433 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1)); 8332 CHECK_EQ(v8_str("[object Object]"), result_array->Get(1));
8434 CHECK_EQ(v8_str("x"), result_array->Get(2)); 8333 CHECK_EQ(v8_str("x"), result_array->Get(2));
8435 } 8334 }
8436 8335
8437 8336
8438 static v8::Handle<Value> ConstTenGetter(Local<String> name, 8337 static void ConstTenGetter(Local<String> name,
8439 const AccessorInfo& info) { 8338 const v8::PropertyCallbackInfo<v8::Value>& info) {
8440 return v8_num(10); 8339 info.GetReturnValue().Set(v8_num(10));
8441 } 8340 }
8442 8341
8443 8342
8444 THREADED_TEST(CrossDomainAccessors) { 8343 THREADED_TEST(CrossDomainAccessors) {
8445 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8344 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8446 v8::HandleScope handle_scope(isolate); 8345 v8::HandleScope handle_scope(isolate);
8447 8346
8448 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 8347 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
8449 8348
8450 v8::Handle<v8::ObjectTemplate> global_template = 8349 v8::Handle<v8::ObjectTemplate> global_template =
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
8694 v8::Handle<Value> value; 8593 v8::Handle<Value> value;
8695 8594
8696 value = v8_compile("var p = 'as' + 'df';")->Run(); 8595 value = v8_compile("var p = 'as' + 'df';")->Run();
8697 value = v8_compile("obj[p];")->Run(); 8596 value = v8_compile("obj[p];")->Run();
8698 8597
8699 context1->Exit(); 8598 context1->Exit();
8700 context0->Exit(); 8599 context0->Exit();
8701 } 8600 }
8702 8601
8703 8602
8704 static v8::Handle<Value> AccessControlNamedGetter( 8603 static void AccessControlNamedGetter(
8705 Local<String>, const AccessorInfo&) { 8604 Local<String>,
8706 return v8::Integer::New(42); 8605 const v8::PropertyCallbackInfo<v8::Value>& info) {
8606 info.GetReturnValue().Set(42);
8707 } 8607 }
8708 8608
8709 8609
8710 static v8::Handle<Value> AccessControlNamedSetter( 8610 static void AccessControlNamedSetter(
8711 Local<String>, Local<Value> value, const AccessorInfo&) { 8611 Local<String>,
8712 return value; 8612 Local<Value> value,
8613 const v8::PropertyCallbackInfo<v8::Value>& info) {
8614 info.GetReturnValue().Set(value);
8713 } 8615 }
8714 8616
8715 8617
8716 static v8::Handle<Value> AccessControlIndexedGetter( 8618 static void AccessControlIndexedGetter(
8717 uint32_t index, 8619 uint32_t index,
8718 const AccessorInfo& info) { 8620 const v8::PropertyCallbackInfo<v8::Value>& info) {
8719 return v8_num(42); 8621 info.GetReturnValue().Set(v8_num(42));
8720 } 8622 }
8721 8623
8722 8624
8723 static v8::Handle<Value> AccessControlIndexedSetter( 8625 static void AccessControlIndexedSetter(
8724 uint32_t, Local<Value> value, const AccessorInfo&) { 8626 uint32_t,
8725 return value; 8627 Local<Value> value,
8628 const v8::PropertyCallbackInfo<v8::Value>& info) {
8629 info.GetReturnValue().Set(value);
8726 } 8630 }
8727 8631
8728 8632
8729 THREADED_TEST(AccessControlInterceptorIC) { 8633 THREADED_TEST(AccessControlInterceptorIC) {
8730 named_access_count = 0; 8634 named_access_count = 0;
8731 indexed_access_count = 0; 8635 indexed_access_count = 0;
8732 8636
8733 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8637 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8734 v8::HandleScope handle_scope(isolate); 8638 v8::HandleScope handle_scope(isolate);
8735 8639
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
8790 context1->Exit(); 8694 context1->Exit();
8791 context0->Exit(); 8695 context0->Exit();
8792 } 8696 }
8793 8697
8794 8698
8795 THREADED_TEST(Version) { 8699 THREADED_TEST(Version) {
8796 v8::V8::GetVersion(); 8700 v8::V8::GetVersion();
8797 } 8701 }
8798 8702
8799 8703
8800 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) { 8704 static void InstanceFunctionCallback(
8705 const v8::FunctionCallbackInfo<v8::Value>& args) {
8801 ApiTestFuzzer::Fuzz(); 8706 ApiTestFuzzer::Fuzz();
8802 return v8_num(12); 8707 args.GetReturnValue().Set(v8_num(12));
8803 } 8708 }
8804 8709
8805 8710
8806 THREADED_TEST(InstanceProperties) { 8711 THREADED_TEST(InstanceProperties) {
8807 LocalContext context; 8712 LocalContext context;
8808 v8::HandleScope handle_scope(context->GetIsolate()); 8713 v8::HandleScope handle_scope(context->GetIsolate());
8809 8714
8810 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8715 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8811 Local<ObjectTemplate> instance = t->InstanceTemplate(); 8716 Local<ObjectTemplate> instance = t->InstanceTemplate();
8812 8717
8813 instance->Set(v8_str("x"), v8_num(42)); 8718 instance->Set(v8_str("x"), v8_num(42));
8814 instance->Set(v8_str("f"), 8719 instance->Set(v8_str("f"),
8815 v8::FunctionTemplate::New(InstanceFunctionCallback)); 8720 v8::FunctionTemplate::New(InstanceFunctionCallback));
8816 8721
8817 Local<Value> o = t->GetFunction()->NewInstance(); 8722 Local<Value> o = t->GetFunction()->NewInstance();
8818 8723
8819 context->Global()->Set(v8_str("i"), o); 8724 context->Global()->Set(v8_str("i"), o);
8820 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); 8725 Local<Value> value = Script::Compile(v8_str("i.x"))->Run();
8821 CHECK_EQ(42, value->Int32Value()); 8726 CHECK_EQ(42, value->Int32Value());
8822 8727
8823 value = Script::Compile(v8_str("i.f()"))->Run(); 8728 value = Script::Compile(v8_str("i.f()"))->Run();
8824 CHECK_EQ(12, value->Int32Value()); 8729 CHECK_EQ(12, value->Int32Value());
8825 } 8730 }
8826 8731
8827 8732
8828 static v8::Handle<Value> 8733 static void GlobalObjectInstancePropertiesGet(
8829 GlobalObjectInstancePropertiesGet(Local<String> key, const AccessorInfo&) { 8734 Local<String> key,
8735 const v8::PropertyCallbackInfo<v8::Value>&) {
8830 ApiTestFuzzer::Fuzz(); 8736 ApiTestFuzzer::Fuzz();
8831 return v8::Handle<Value>();
8832 } 8737 }
8833 8738
8834 8739
8835 THREADED_TEST(GlobalObjectInstanceProperties) { 8740 THREADED_TEST(GlobalObjectInstanceProperties) {
8836 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8741 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8837 8742
8838 Local<Value> global_object; 8743 Local<Value> global_object;
8839 8744
8840 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8745 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8841 t->InstanceTemplate()->SetNamedPropertyHandler( 8746 t->InstanceTemplate()->SetNamedPropertyHandler(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
8921 8826
8922 { 8827 {
8923 // Create new environment reusing the global object. 8828 // Create new environment reusing the global object.
8924 LocalContext env(NULL, instance_template, global_object); 8829 LocalContext env(NULL, instance_template, global_object);
8925 env->Global()->Set(v8_str("foo"), foo); 8830 env->Global()->Set(v8_str("foo"), foo);
8926 Script::Compile(v8_str("foo()"))->Run(); 8831 Script::Compile(v8_str("foo()"))->Run();
8927 } 8832 }
8928 } 8833 }
8929 8834
8930 8835
8931 static v8::Handle<Value> ShadowFunctionCallback(const v8::Arguments& args) { 8836 static void ShadowFunctionCallback(
8837 const v8::FunctionCallbackInfo<v8::Value>& args) {
8932 ApiTestFuzzer::Fuzz(); 8838 ApiTestFuzzer::Fuzz();
8933 return v8_num(42); 8839 args.GetReturnValue().Set(v8_num(42));
8934 } 8840 }
8935 8841
8936 8842
8937 static int shadow_y; 8843 static int shadow_y;
8938 static int shadow_y_setter_call_count; 8844 static int shadow_y_setter_call_count;
8939 static int shadow_y_getter_call_count; 8845 static int shadow_y_getter_call_count;
8940 8846
8941 8847
8942 static void ShadowYSetter(Local<String>, Local<Value>, const AccessorInfo&) { 8848 static void ShadowYSetter(Local<String>,
8849 Local<Value>,
8850 const v8::PropertyCallbackInfo<void>&) {
8943 shadow_y_setter_call_count++; 8851 shadow_y_setter_call_count++;
8944 shadow_y = 42; 8852 shadow_y = 42;
8945 } 8853 }
8946 8854
8947 8855
8948 static v8::Handle<Value> ShadowYGetter(Local<String> name, 8856 static void ShadowYGetter(Local<String> name,
8949 const AccessorInfo& info) { 8857 const v8::PropertyCallbackInfo<v8::Value>& info) {
8950 ApiTestFuzzer::Fuzz(); 8858 ApiTestFuzzer::Fuzz();
8951 shadow_y_getter_call_count++; 8859 shadow_y_getter_call_count++;
8952 return v8_num(shadow_y); 8860 info.GetReturnValue().Set(v8_num(shadow_y));
8953 } 8861 }
8954 8862
8955 8863
8956 static v8::Handle<Value> ShadowIndexedGet(uint32_t index, 8864 static void ShadowIndexedGet(uint32_t index,
8957 const AccessorInfo& info) { 8865 const v8::PropertyCallbackInfo<v8::Value>&) {
8958 return v8::Handle<Value>();
8959 } 8866 }
8960 8867
8961 8868
8962 static v8::Handle<Value> ShadowNamedGet(Local<String> key, 8869 static void ShadowNamedGet(Local<String> key,
8963 const AccessorInfo&) { 8870 const v8::PropertyCallbackInfo<v8::Value>&) {
8964 return v8::Handle<Value>();
8965 } 8871 }
8966 8872
8967 8873
8968 THREADED_TEST(ShadowObject) { 8874 THREADED_TEST(ShadowObject) {
8969 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 8875 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
8970 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 8876 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8971 8877
8972 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8878 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New();
8973 LocalContext context(NULL, global_template); 8879 LocalContext context(NULL, global_template);
8974 8880
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
9304 Local<Function> cons = templ->GetFunction(); 9210 Local<Function> cons = templ->GetFunction();
9305 context->Global()->Set(v8_str("Fun"), cons); 9211 context->Global()->Set(v8_str("Fun"), cons);
9306 Local<v8::Object> inst = cons->NewInstance(); 9212 Local<v8::Object> inst = cons->NewInstance();
9307 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 9213 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
9308 CHECK(obj->IsJSObject()); 9214 CHECK(obj->IsJSObject());
9309 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 9215 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
9310 CHECK(value->BooleanValue()); 9216 CHECK(value->BooleanValue());
9311 } 9217 }
9312 9218
9313 9219
9314 static Handle<Value> ConstructorCallback(const Arguments& args) { 9220 static void ConstructorCallback(
9221 const v8::FunctionCallbackInfo<v8::Value>& args) {
9315 ApiTestFuzzer::Fuzz(); 9222 ApiTestFuzzer::Fuzz();
9316 Local<Object> This; 9223 Local<Object> This;
9317 9224
9318 if (args.IsConstructCall()) { 9225 if (args.IsConstructCall()) {
9319 Local<Object> Holder = args.Holder(); 9226 Local<Object> Holder = args.Holder();
9320 This = Object::New(); 9227 This = Object::New();
9321 Local<Value> proto = Holder->GetPrototype(); 9228 Local<Value> proto = Holder->GetPrototype();
9322 if (proto->IsObject()) { 9229 if (proto->IsObject()) {
9323 This->SetPrototype(proto); 9230 This->SetPrototype(proto);
9324 } 9231 }
9325 } else { 9232 } else {
9326 This = args.This(); 9233 This = args.This();
9327 } 9234 }
9328 9235
9329 This->Set(v8_str("a"), args[0]); 9236 This->Set(v8_str("a"), args[0]);
9330 return This; 9237 args.GetReturnValue().Set(This);
9331 } 9238 }
9332 9239
9333 9240
9334 static Handle<Value> FakeConstructorCallback(const Arguments& args) { 9241 static void FakeConstructorCallback(
9242 const v8::FunctionCallbackInfo<v8::Value>& args) {
9335 ApiTestFuzzer::Fuzz(); 9243 ApiTestFuzzer::Fuzz();
9336 return args[0]; 9244 args.GetReturnValue().Set(args[0]);
9337 } 9245 }
9338 9246
9339 9247
9340 THREADED_TEST(ConstructorForObject) { 9248 THREADED_TEST(ConstructorForObject) {
9341 LocalContext context; 9249 LocalContext context;
9342 v8::HandleScope handle_scope(context->GetIsolate()); 9250 v8::HandleScope handle_scope(context->GetIsolate());
9343 9251
9344 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 9252 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
9345 instance_template->SetCallAsFunctionHandler(ConstructorCallback); 9253 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
9346 Local<Object> instance = instance_template->NewInstance(); 9254 Local<Object> instance = instance_template->NewInstance();
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
9694 current->Global()->Set(v8_str("other"), other->Global()); 9602 current->Global()->Set(v8_str("other"), other->Global());
9695 9603
9696 // Trigger lazy loading in other context. 9604 // Trigger lazy loading in other context.
9697 Local<Script> script = 9605 Local<Script> script =
9698 Script::Compile(v8_str("other.eval('new Date(42)')")); 9606 Script::Compile(v8_str("other.eval('new Date(42)')"));
9699 Local<Value> value = script->Run(); 9607 Local<Value> value = script->Run();
9700 CHECK_EQ(42.0, value->NumberValue()); 9608 CHECK_EQ(42.0, value->NumberValue());
9701 } 9609 }
9702 9610
9703 9611
9704 static v8::Handle<Value> call_as_function(const v8::Arguments& args) { 9612 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) {
9705 ApiTestFuzzer::Fuzz(); 9613 ApiTestFuzzer::Fuzz();
9706 if (args.IsConstructCall()) { 9614 if (args.IsConstructCall()) {
9707 if (args[0]->IsInt32()) { 9615 if (args[0]->IsInt32()) {
9708 return v8_num(-args[0]->Int32Value()); 9616 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value()));
9617 return;
9709 } 9618 }
9710 } 9619 }
9711 9620
9712 return args[0]; 9621 args.GetReturnValue().Set(args[0]);
9713 } 9622 }
9714 9623
9715 9624
9716 // Test that a call handler can be set for objects which will allow 9625 // Test that a call handler can be set for objects which will allow
9717 // non-function objects created through the API to be called as 9626 // non-function objects created through the API to be called as
9718 // functions. 9627 // functions.
9719 THREADED_TEST(CallAsFunction) { 9628 THREADED_TEST(CallAsFunction) {
9720 LocalContext context; 9629 LocalContext context;
9721 v8::HandleScope scope(context->GetIsolate()); 9630 v8::HandleScope scope(context->GetIsolate());
9722 9631
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
9906 CHECK_EQ(j + 1 + kIterations, CountHandles()); 9815 CHECK_EQ(j + 1 + kIterations, CountHandles());
9907 } 9816 }
9908 } 9817 }
9909 CHECK_EQ(kIterations, CountHandles()); 9818 CHECK_EQ(kIterations, CountHandles());
9910 } 9819 }
9911 CHECK_EQ(0, CountHandles()); 9820 CHECK_EQ(0, CountHandles());
9912 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 9821 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
9913 } 9822 }
9914 9823
9915 9824
9916 static v8::Handle<Value> InterceptorHasOwnPropertyGetter( 9825 static void InterceptorHasOwnPropertyGetter(
9917 Local<String> name, 9826 Local<String> name,
9918 const AccessorInfo& info) { 9827 const v8::PropertyCallbackInfo<v8::Value>& info) {
9919 ApiTestFuzzer::Fuzz(); 9828 ApiTestFuzzer::Fuzz();
9920 return v8::Handle<Value>();
9921 } 9829 }
9922 9830
9923 9831
9924 THREADED_TEST(InterceptorHasOwnProperty) { 9832 THREADED_TEST(InterceptorHasOwnProperty) {
9925 LocalContext context; 9833 LocalContext context;
9926 v8::HandleScope scope(context->GetIsolate()); 9834 v8::HandleScope scope(context->GetIsolate());
9927 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9835 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9928 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9836 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9929 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); 9837 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
9930 Local<Function> function = fun_templ->GetFunction(); 9838 Local<Function> function = fun_templ->GetFunction();
9931 context->Global()->Set(v8_str("constructor"), function); 9839 context->Global()->Set(v8_str("constructor"), function);
9932 v8::Handle<Value> value = CompileRun( 9840 v8::Handle<Value> value = CompileRun(
9933 "var o = new constructor();" 9841 "var o = new constructor();"
9934 "o.hasOwnProperty('ostehaps');"); 9842 "o.hasOwnProperty('ostehaps');");
9935 CHECK_EQ(false, value->BooleanValue()); 9843 CHECK_EQ(false, value->BooleanValue());
9936 value = CompileRun( 9844 value = CompileRun(
9937 "o.ostehaps = 42;" 9845 "o.ostehaps = 42;"
9938 "o.hasOwnProperty('ostehaps');"); 9846 "o.hasOwnProperty('ostehaps');");
9939 CHECK_EQ(true, value->BooleanValue()); 9847 CHECK_EQ(true, value->BooleanValue());
9940 value = CompileRun( 9848 value = CompileRun(
9941 "var p = new constructor();" 9849 "var p = new constructor();"
9942 "p.hasOwnProperty('ostehaps');"); 9850 "p.hasOwnProperty('ostehaps');");
9943 CHECK_EQ(false, value->BooleanValue()); 9851 CHECK_EQ(false, value->BooleanValue());
9944 } 9852 }
9945 9853
9946 9854
9947 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC( 9855 static void InterceptorHasOwnPropertyGetterGC(
9948 Local<String> name, 9856 Local<String> name,
9949 const AccessorInfo& info) { 9857 const v8::PropertyCallbackInfo<v8::Value>& info) {
9950 ApiTestFuzzer::Fuzz(); 9858 ApiTestFuzzer::Fuzz();
9951 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 9859 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
9952 return v8::Handle<Value>();
9953 } 9860 }
9954 9861
9955 9862
9956 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 9863 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
9957 LocalContext context; 9864 LocalContext context;
9958 v8::HandleScope scope(context->GetIsolate()); 9865 v8::HandleScope scope(context->GetIsolate());
9959 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9866 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9960 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9867 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9961 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); 9868 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
9962 Local<Function> function = fun_templ->GetFunction(); 9869 Local<Function> function = fun_templ->GetFunction();
(...skipping 12 matching lines...) Expand all
9975 "x = makestr(31415);" 9882 "x = makestr(31415);"
9976 "x = makestr(23456);"); 9883 "x = makestr(23456);");
9977 v8::Handle<Value> value = CompileRun( 9884 v8::Handle<Value> value = CompileRun(
9978 "var o = new constructor();" 9885 "var o = new constructor();"
9979 "o.__proto__ = new String(x);" 9886 "o.__proto__ = new String(x);"
9980 "o.hasOwnProperty('ostehaps');"); 9887 "o.hasOwnProperty('ostehaps');");
9981 CHECK_EQ(false, value->BooleanValue()); 9888 CHECK_EQ(false, value->BooleanValue());
9982 } 9889 }
9983 9890
9984 9891
9985 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property, 9892 typedef void (*NamedPropertyGetter)(
9986 const AccessorInfo& info); 9893 Local<String> property,
9894 const v8::PropertyCallbackInfo<v8::Value>& info);
9987 9895
9988 9896
9989 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, 9897 static void CheckInterceptorLoadIC(NamedPropertyGetter getter,
9990 const char* source, 9898 const char* source,
9991 int expected) { 9899 int expected) {
9992 v8::HandleScope scope(v8::Isolate::GetCurrent()); 9900 v8::HandleScope scope(v8::Isolate::GetCurrent());
9993 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9901 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9994 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); 9902 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data"));
9995 LocalContext context; 9903 LocalContext context;
9996 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9904 context->Global()->Set(v8_str("o"), templ->NewInstance());
9997 v8::Handle<Value> value = CompileRun(source); 9905 v8::Handle<Value> value = CompileRun(source);
9998 CHECK_EQ(expected, value->Int32Value()); 9906 CHECK_EQ(expected, value->Int32Value());
9999 } 9907 }
10000 9908
10001 9909
10002 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, 9910 static void InterceptorLoadICGetter(
10003 const AccessorInfo& info) { 9911 Local<String> name,
9912 const v8::PropertyCallbackInfo<v8::Value>& info) {
10004 ApiTestFuzzer::Fuzz(); 9913 ApiTestFuzzer::Fuzz();
10005 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 9914 v8::Isolate* isolate = v8::Isolate::GetCurrent();
10006 CHECK_EQ(isolate, info.GetIsolate()); 9915 CHECK_EQ(isolate, info.GetIsolate());
10007 CHECK_EQ(v8_str("data"), info.Data()); 9916 CHECK_EQ(v8_str("data"), info.Data());
10008 CHECK_EQ(v8_str("x"), name); 9917 CHECK_EQ(v8_str("x"), name);
10009 return v8::Integer::New(42); 9918 info.GetReturnValue().Set(v8::Integer::New(42));
10010 } 9919 }
10011 9920
10012 9921
10013 // This test should hit the load IC for the interceptor case. 9922 // This test should hit the load IC for the interceptor case.
10014 THREADED_TEST(InterceptorLoadIC) { 9923 THREADED_TEST(InterceptorLoadIC) {
10015 CheckInterceptorLoadIC(InterceptorLoadICGetter, 9924 CheckInterceptorLoadIC(InterceptorLoadICGetter,
10016 "var result = 0;" 9925 "var result = 0;"
10017 "for (var i = 0; i < 1000; i++) {" 9926 "for (var i = 0; i < 1000; i++) {"
10018 " result = o.x;" 9927 " result = o.x;"
10019 "}", 9928 "}",
10020 42); 9929 42);
10021 } 9930 }
10022 9931
10023 9932
10024 // Below go several tests which verify that JITing for various 9933 // Below go several tests which verify that JITing for various
10025 // configurations of interceptor and explicit fields works fine 9934 // configurations of interceptor and explicit fields works fine
10026 // (those cases are special cased to get better performance). 9935 // (those cases are special cased to get better performance).
10027 9936
10028 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, 9937 static void InterceptorLoadXICGetter(
10029 const AccessorInfo& info) { 9938 Local<String> name,
9939 const v8::PropertyCallbackInfo<v8::Value>& info) {
10030 ApiTestFuzzer::Fuzz(); 9940 ApiTestFuzzer::Fuzz();
10031 return v8_str("x")->Equals(name) 9941 info.GetReturnValue().Set(
10032 ? v8::Handle<v8::Value>(v8::Integer::New(42)) : v8::Handle<v8::Value>(); 9942 v8_str("x")->Equals(name) ?
9943 v8::Handle<v8::Value>(v8::Integer::New(42)) :
9944 v8::Handle<v8::Value>());
10033 } 9945 }
10034 9946
10035 9947
10036 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { 9948 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) {
10037 CheckInterceptorLoadIC(InterceptorLoadXICGetter, 9949 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
10038 "var result = 0;" 9950 "var result = 0;"
10039 "o.y = 239;" 9951 "o.y = 239;"
10040 "for (var i = 0; i < 1000; i++) {" 9952 "for (var i = 0; i < 1000; i++) {"
10041 " result = o.y;" 9953 " result = o.y;"
10042 "}", 9954 "}",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
10131 "var result = 0;" 10043 "var result = 0;"
10132 "for (var i = 0; i < 1000; i++) {" 10044 "for (var i = 0; i < 1000; i++) {"
10133 " result += o.y;" 10045 " result += o.y;"
10134 "}" 10046 "}"
10135 "result;", 10047 "result;",
10136 42 * 1000); 10048 42 * 1000);
10137 } 10049 }
10138 10050
10139 10051
10140 static int interceptor_load_not_handled_calls = 0; 10052 static int interceptor_load_not_handled_calls = 0;
10141 static v8::Handle<Value> InterceptorLoadNotHandled(Local<String> name, 10053 static void InterceptorLoadNotHandled(
10142 const AccessorInfo& info) { 10054 Local<String> name,
10055 const v8::PropertyCallbackInfo<v8::Value>& info) {
10143 ++interceptor_load_not_handled_calls; 10056 ++interceptor_load_not_handled_calls;
10144 return v8::Handle<v8::Value>();
10145 } 10057 }
10146 10058
10147 10059
10148 // Test how post-interceptor lookups are done in the non-cacheable 10060 // Test how post-interceptor lookups are done in the non-cacheable
10149 // case: the interceptor should not be invoked during this lookup. 10061 // case: the interceptor should not be invoked during this lookup.
10150 THREADED_TEST(InterceptorLoadICPostInterceptor) { 10062 THREADED_TEST(InterceptorLoadICPostInterceptor) {
10151 interceptor_load_not_handled_calls = 0; 10063 interceptor_load_not_handled_calls = 0;
10152 CheckInterceptorLoadIC(InterceptorLoadNotHandled, 10064 CheckInterceptorLoadIC(InterceptorLoadNotHandled,
10153 "receiver = new Object();" 10065 "receiver = new Object();"
10154 "receiver.__proto__ = o;" 10066 "receiver.__proto__ = o;"
(...skipping 30 matching lines...) Expand all
10185 "for (var i = 0; i < 10; i++) {" 10097 "for (var i = 0; i < 10; i++) {"
10186 " result += o.y;" 10098 " result += o.y;"
10187 "}" 10099 "}"
10188 "result;", 10100 "result;",
10189 42 * 10); 10101 42 * 10);
10190 } 10102 }
10191 10103
10192 10104
10193 static void SetOnThis(Local<String> name, 10105 static void SetOnThis(Local<String> name,
10194 Local<Value> value, 10106 Local<Value> value,
10195 const AccessorInfo& info) { 10107 const v8::PropertyCallbackInfo<void>& info) {
10196 info.This()->ForceSet(name, value); 10108 info.This()->ForceSet(name, value);
10197 } 10109 }
10198 10110
10199 10111
10200 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { 10112 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) {
10201 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10113 v8::HandleScope scope(v8::Isolate::GetCurrent());
10202 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10114 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10203 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10115 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10204 templ->SetAccessor(v8_str("y"), Return239); 10116 templ->SetAccessor(v8_str("y"), Return239Callback);
10205 LocalContext context; 10117 LocalContext context;
10206 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10118 context->Global()->Set(v8_str("o"), templ->NewInstance());
10207 10119
10208 // Check the case when receiver and interceptor's holder 10120 // Check the case when receiver and interceptor's holder
10209 // are the same objects. 10121 // are the same objects.
10210 v8::Handle<Value> value = CompileRun( 10122 v8::Handle<Value> value = CompileRun(
10211 "var result = 0;" 10123 "var result = 0;"
10212 "for (var i = 0; i < 7; i++) {" 10124 "for (var i = 0; i < 7; i++) {"
10213 " result = o.y;" 10125 " result = o.y;"
10214 "}"); 10126 "}");
10215 CHECK_EQ(239, value->Int32Value()); 10127 CHECK_EQ(239, value->Int32Value());
10216 10128
10217 // Check the case when interceptor's holder is in proto chain 10129 // Check the case when interceptor's holder is in proto chain
10218 // of receiver. 10130 // of receiver.
10219 value = CompileRun( 10131 value = CompileRun(
10220 "r = { __proto__: o };" 10132 "r = { __proto__: o };"
10221 "var result = 0;" 10133 "var result = 0;"
10222 "for (var i = 0; i < 7; i++) {" 10134 "for (var i = 0; i < 7; i++) {"
10223 " result = r.y;" 10135 " result = r.y;"
10224 "}"); 10136 "}");
10225 CHECK_EQ(239, value->Int32Value()); 10137 CHECK_EQ(239, value->Int32Value());
10226 } 10138 }
10227 10139
10228 10140
10229 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { 10141 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) {
10230 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10142 v8::HandleScope scope(v8::Isolate::GetCurrent());
10231 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10143 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10232 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10144 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10233 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10145 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10234 templ_p->SetAccessor(v8_str("y"), Return239); 10146 templ_p->SetAccessor(v8_str("y"), Return239Callback);
10235 10147
10236 LocalContext context; 10148 LocalContext context;
10237 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10149 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10238 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10150 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10239 10151
10240 // Check the case when receiver and interceptor's holder 10152 // Check the case when receiver and interceptor's holder
10241 // are the same objects. 10153 // are the same objects.
10242 v8::Handle<Value> value = CompileRun( 10154 v8::Handle<Value> value = CompileRun(
10243 "o.__proto__ = p;" 10155 "o.__proto__ = p;"
10244 "var result = 0;" 10156 "var result = 0;"
(...skipping 11 matching lines...) Expand all
10256 " result = r.x + r.y;" 10168 " result = r.x + r.y;"
10257 "}"); 10169 "}");
10258 CHECK_EQ(239 + 42, value->Int32Value()); 10170 CHECK_EQ(239 + 42, value->Int32Value());
10259 } 10171 }
10260 10172
10261 10173
10262 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { 10174 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) {
10263 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10175 v8::HandleScope scope(v8::Isolate::GetCurrent());
10264 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10176 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10265 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10177 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10266 templ->SetAccessor(v8_str("y"), Return239); 10178 templ->SetAccessor(v8_str("y"), Return239Callback);
10267 10179
10268 LocalContext context; 10180 LocalContext context;
10269 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10181 context->Global()->Set(v8_str("o"), templ->NewInstance());
10270 10182
10271 v8::Handle<Value> value = CompileRun( 10183 v8::Handle<Value> value = CompileRun(
10272 "fst = new Object(); fst.__proto__ = o;" 10184 "fst = new Object(); fst.__proto__ = o;"
10273 "snd = new Object(); snd.__proto__ = fst;" 10185 "snd = new Object(); snd.__proto__ = fst;"
10274 "var result1 = 0;" 10186 "var result1 = 0;"
10275 "for (var i = 0; i < 7; i++) {" 10187 "for (var i = 0; i < 7; i++) {"
10276 " result1 = snd.x;" 10188 " result1 = snd.x;"
10277 "}" 10189 "}"
10278 "fst.x = 239;" 10190 "fst.x = 239;"
10279 "var result = 0;" 10191 "var result = 0;"
10280 "for (var i = 0; i < 7; i++) {" 10192 "for (var i = 0; i < 7; i++) {"
10281 " result = snd.x;" 10193 " result = snd.x;"
10282 "}" 10194 "}"
10283 "result + result1"); 10195 "result + result1");
10284 CHECK_EQ(239 + 42, value->Int32Value()); 10196 CHECK_EQ(239 + 42, value->Int32Value());
10285 } 10197 }
10286 10198
10287 10199
10288 // Test the case when we stored callback into 10200 // Test the case when we stored callback into
10289 // a stub, but interceptor produced value on its own. 10201 // a stub, but interceptor produced value on its own.
10290 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { 10202 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) {
10291 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10203 v8::HandleScope scope(v8::Isolate::GetCurrent());
10292 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10204 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10293 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10205 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10294 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10206 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10295 templ_p->SetAccessor(v8_str("y"), Return239); 10207 templ_p->SetAccessor(v8_str("y"), Return239Callback);
10296 10208
10297 LocalContext context; 10209 LocalContext context;
10298 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10210 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10299 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10211 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10300 10212
10301 v8::Handle<Value> value = CompileRun( 10213 v8::Handle<Value> value = CompileRun(
10302 "o.__proto__ = p;" 10214 "o.__proto__ = p;"
10303 "for (var i = 0; i < 7; i++) {" 10215 "for (var i = 0; i < 7; i++) {"
10304 " o.x;" 10216 " o.x;"
10305 // Now it should be ICed and keep a reference to x defined on p 10217 // Now it should be ICed and keep a reference to x defined on p
10306 "}" 10218 "}"
10307 "var result = 0;" 10219 "var result = 0;"
10308 "for (var i = 0; i < 7; i++) {" 10220 "for (var i = 0; i < 7; i++) {"
10309 " result += o.x;" 10221 " result += o.x;"
10310 "}" 10222 "}"
10311 "result"); 10223 "result");
10312 CHECK_EQ(42 * 7, value->Int32Value()); 10224 CHECK_EQ(42 * 7, value->Int32Value());
10313 } 10225 }
10314 10226
10315 10227
10316 // Test the case when we stored callback into 10228 // Test the case when we stored callback into
10317 // a stub, but it got invalidated later on. 10229 // a stub, but it got invalidated later on.
10318 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { 10230 THREADED_TEST(InterceptorLoadICInvalidatedCallback) {
10319 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10231 v8::HandleScope scope(v8::Isolate::GetCurrent());
10320 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10232 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10321 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10233 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10322 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10234 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10323 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 10235 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
10324 10236
10325 LocalContext context; 10237 LocalContext context;
10326 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10238 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10327 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10239 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10328 10240
10329 v8::Handle<Value> value = CompileRun( 10241 v8::Handle<Value> value = CompileRun(
10330 "inbetween = new Object();" 10242 "inbetween = new Object();"
10331 "o.__proto__ = inbetween;" 10243 "o.__proto__ = inbetween;"
10332 "inbetween.__proto__ = p;" 10244 "inbetween.__proto__ = p;"
10333 "for (var i = 0; i < 10; i++) {" 10245 "for (var i = 0; i < 10; i++) {"
(...skipping 11 matching lines...) Expand all
10345 10257
10346 10258
10347 // Test the case when we stored callback into 10259 // Test the case when we stored callback into
10348 // a stub, but it got invalidated later on due to override on 10260 // a stub, but it got invalidated later on due to override on
10349 // global object which is between interceptor and callbacks' holders. 10261 // global object which is between interceptor and callbacks' holders.
10350 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { 10262 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) {
10351 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10263 v8::HandleScope scope(v8::Isolate::GetCurrent());
10352 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10264 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10353 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10265 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10354 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 10266 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
10355 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 10267 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis);
10356 10268
10357 LocalContext context; 10269 LocalContext context;
10358 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10270 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10359 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 10271 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
10360 10272
10361 v8::Handle<Value> value = CompileRun( 10273 v8::Handle<Value> value = CompileRun(
10362 "o.__proto__ = this;" 10274 "o.__proto__ = this;"
10363 "this.__proto__ = p;" 10275 "this.__proto__ = p;"
10364 "for (var i = 0; i < 10; i++) {" 10276 "for (var i = 0; i < 10; i++) {"
10365 " if (o.y != 239) throw 'oops: ' + o.y;" 10277 " if (o.y != 239) throw 'oops: ' + o.y;"
10366 // Now it should be ICed and keep a reference to y defined on p 10278 // Now it should be ICed and keep a reference to y defined on p
10367 "}" 10279 "}"
10368 "this.y = 42;" 10280 "this.y = 42;"
10369 "var result = 0;" 10281 "var result = 0;"
10370 "for (var i = 0; i < 10; i++) {" 10282 "for (var i = 0; i < 10; i++) {"
10371 " result += o.y;" 10283 " result += o.y;"
10372 "}" 10284 "}"
10373 "result"); 10285 "result");
10374 CHECK_EQ(42 * 10, value->Int32Value()); 10286 CHECK_EQ(42 * 10, value->Int32Value());
10375 } 10287 }
10376 10288
10377 10289
10378 static v8::Handle<Value> InterceptorLoadICGetter0(Local<String> name, 10290 static void InterceptorLoadICGetter0(
10379 const AccessorInfo& info) { 10291 Local<String> name,
10292 const v8::PropertyCallbackInfo<v8::Value>& info) {
10380 ApiTestFuzzer::Fuzz(); 10293 ApiTestFuzzer::Fuzz();
10381 CHECK(v8_str("x")->Equals(name)); 10294 CHECK(v8_str("x")->Equals(name));
10382 return v8::Integer::New(0); 10295 info.GetReturnValue().Set(v8::Integer::New(0));
10383 } 10296 }
10384 10297
10385 10298
10386 THREADED_TEST(InterceptorReturningZero) { 10299 THREADED_TEST(InterceptorReturningZero) {
10387 CheckInterceptorLoadIC(InterceptorLoadICGetter0, 10300 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
10388 "o.x == undefined ? 1 : 0", 10301 "o.x == undefined ? 1 : 0",
10389 0); 10302 0);
10390 } 10303 }
10391 10304
10392 10305
10393 static v8::Handle<Value> InterceptorStoreICSetter( 10306 static void InterceptorStoreICSetter(
10394 Local<String> key, Local<Value> value, const AccessorInfo&) { 10307 Local<String> key,
10308 Local<Value> value,
10309 const v8::PropertyCallbackInfo<v8::Value>& info) {
10395 CHECK(v8_str("x")->Equals(key)); 10310 CHECK(v8_str("x")->Equals(key));
10396 CHECK_EQ(42, value->Int32Value()); 10311 CHECK_EQ(42, value->Int32Value());
10397 return value; 10312 info.GetReturnValue().Set(value);
10398 } 10313 }
10399 10314
10400 10315
10401 // This test should hit the store IC for the interceptor case. 10316 // This test should hit the store IC for the interceptor case.
10402 THREADED_TEST(InterceptorStoreIC) { 10317 THREADED_TEST(InterceptorStoreIC) {
10403 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10318 v8::HandleScope scope(v8::Isolate::GetCurrent());
10404 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10319 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10405 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, 10320 templ->SetNamedPropertyHandler(InterceptorLoadICGetter,
10406 InterceptorStoreICSetter, 10321 InterceptorStoreICSetter,
10407 0, 0, 0, v8_str("data")); 10322 0, 0, 0, v8_str("data"));
(...skipping 20 matching lines...) Expand all
10428 CHECK_EQ(239 + 42, value->Int32Value()); 10343 CHECK_EQ(239 + 42, value->Int32Value());
10429 } 10344 }
10430 10345
10431 10346
10432 10347
10433 10348
10434 v8::Handle<Value> call_ic_function; 10349 v8::Handle<Value> call_ic_function;
10435 v8::Handle<Value> call_ic_function2; 10350 v8::Handle<Value> call_ic_function2;
10436 v8::Handle<Value> call_ic_function3; 10351 v8::Handle<Value> call_ic_function3;
10437 10352
10438 static v8::Handle<Value> InterceptorCallICGetter(Local<String> name, 10353 static void InterceptorCallICGetter(
10439 const AccessorInfo& info) { 10354 Local<String> name,
10355 const v8::PropertyCallbackInfo<v8::Value>& info) {
10440 ApiTestFuzzer::Fuzz(); 10356 ApiTestFuzzer::Fuzz();
10441 CHECK(v8_str("x")->Equals(name)); 10357 CHECK(v8_str("x")->Equals(name));
10442 return call_ic_function; 10358 info.GetReturnValue().Set(call_ic_function);
10443 } 10359 }
10444 10360
10445 10361
10446 // This test should hit the call IC for the interceptor case. 10362 // This test should hit the call IC for the interceptor case.
10447 THREADED_TEST(InterceptorCallIC) { 10363 THREADED_TEST(InterceptorCallIC) {
10448 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10364 v8::HandleScope scope(v8::Isolate::GetCurrent());
10449 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10365 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10450 templ->SetNamedPropertyHandler(InterceptorCallICGetter); 10366 templ->SetNamedPropertyHandler(InterceptorCallICGetter);
10451 LocalContext context; 10367 LocalContext context;
10452 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10368 context->Global()->Set(v8_str("o"), templ->NewInstance());
(...skipping 20 matching lines...) Expand all
10473 "o.x = function f(x) { return x + 1; };" 10389 "o.x = function f(x) { return x + 1; };"
10474 "var result = 0;" 10390 "var result = 0;"
10475 "for (var i = 0; i < 7; i++) {" 10391 "for (var i = 0; i < 7; i++) {"
10476 " result = o.x(41);" 10392 " result = o.x(41);"
10477 "}"); 10393 "}");
10478 CHECK_EQ(42, value->Int32Value()); 10394 CHECK_EQ(42, value->Int32Value());
10479 } 10395 }
10480 10396
10481 10397
10482 static v8::Handle<Value> call_ic_function4; 10398 static v8::Handle<Value> call_ic_function4;
10483 static v8::Handle<Value> InterceptorCallICGetter4(Local<String> name, 10399 static void InterceptorCallICGetter4(
10484 const AccessorInfo& info) { 10400 Local<String> name,
10401 const v8::PropertyCallbackInfo<v8::Value>& info) {
10485 ApiTestFuzzer::Fuzz(); 10402 ApiTestFuzzer::Fuzz();
10486 CHECK(v8_str("x")->Equals(name)); 10403 CHECK(v8_str("x")->Equals(name));
10487 return call_ic_function4; 10404 info.GetReturnValue().Set(call_ic_function4);
10488 } 10405 }
10489 10406
10490 10407
10491 // This test checks that if interceptor provides a function, 10408 // This test checks that if interceptor provides a function,
10492 // even if we cached shadowed variant, interceptor's function 10409 // even if we cached shadowed variant, interceptor's function
10493 // is invoked 10410 // is invoked
10494 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { 10411 THREADED_TEST(InterceptorCallICCacheableNotNeeded) {
10495 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10412 v8::HandleScope scope(v8::Isolate::GetCurrent());
10496 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10413 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10497 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); 10414 templ->SetNamedPropertyHandler(InterceptorCallICGetter4);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
10550 "o.x = inc;" 10467 "o.x = inc;"
10551 "var result = 0;" 10468 "var result = 0;"
10552 "for (var i = 0; i < 1000; i++) {" 10469 "for (var i = 0; i < 1000; i++) {"
10553 " result = o.x(42);" 10470 " result = o.x(42);"
10554 "}"); 10471 "}");
10555 CHECK_EQ(43, value->Int32Value()); 10472 CHECK_EQ(43, value->Int32Value());
10556 } 10473 }
10557 10474
10558 10475
10559 static v8::Handle<Value> call_ic_function5; 10476 static v8::Handle<Value> call_ic_function5;
10560 static v8::Handle<Value> InterceptorCallICGetter5(Local<String> name, 10477 static void InterceptorCallICGetter5(
10561 const AccessorInfo& info) { 10478 Local<String> name,
10479 const v8::PropertyCallbackInfo<v8::Value>& info) {
10562 ApiTestFuzzer::Fuzz(); 10480 ApiTestFuzzer::Fuzz();
10563 if (v8_str("x")->Equals(name)) 10481 if (v8_str("x")->Equals(name))
10564 return call_ic_function5; 10482 info.GetReturnValue().Set(call_ic_function5);
10565 else
10566 return Local<Value>();
10567 } 10483 }
10568 10484
10569 10485
10570 // This test checks that if interceptor provides a function, 10486 // This test checks that if interceptor provides a function,
10571 // even if we cached constant function, interceptor's function 10487 // even if we cached constant function, interceptor's function
10572 // is invoked 10488 // is invoked
10573 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 10489 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
10574 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10490 v8::HandleScope scope(v8::Isolate::GetCurrent());
10575 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10491 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10576 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 10492 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
10577 LocalContext context; 10493 LocalContext context;
10578 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10494 context->Global()->Set(v8_str("o"), templ->NewInstance());
10579 call_ic_function5 = 10495 call_ic_function5 =
10580 v8_compile("function f(x) { return x - 1; }; f")->Run(); 10496 v8_compile("function f(x) { return x - 1; }; f")->Run();
10581 v8::Handle<Value> value = CompileRun( 10497 v8::Handle<Value> value = CompileRun(
10582 "function inc(x) { return x + 1; };" 10498 "function inc(x) { return x + 1; };"
10583 "inc(1);" 10499 "inc(1);"
10584 "o.x = inc;" 10500 "o.x = inc;"
10585 "var result = 0;" 10501 "var result = 0;"
10586 "for (var i = 0; i < 1000; i++) {" 10502 "for (var i = 0; i < 1000; i++) {"
10587 " result = o.x(42);" 10503 " result = o.x(42);"
10588 "}"); 10504 "}");
10589 CHECK_EQ(41, value->Int32Value()); 10505 CHECK_EQ(41, value->Int32Value());
10590 } 10506 }
10591 10507
10592 10508
10593 static v8::Handle<Value> call_ic_function6; 10509 static v8::Handle<Value> call_ic_function6;
10594 static v8::Handle<Value> InterceptorCallICGetter6(Local<String> name, 10510 static void InterceptorCallICGetter6(
10595 const AccessorInfo& info) { 10511 Local<String> name,
10512 const v8::PropertyCallbackInfo<v8::Value>& info) {
10596 ApiTestFuzzer::Fuzz(); 10513 ApiTestFuzzer::Fuzz();
10597 if (v8_str("x")->Equals(name)) 10514 if (v8_str("x")->Equals(name))
10598 return call_ic_function6; 10515 info.GetReturnValue().Set(call_ic_function6);
10599 else
10600 return Local<Value>();
10601 } 10516 }
10602 10517
10603 10518
10604 // Same test as above, except the code is wrapped in a function 10519 // Same test as above, except the code is wrapped in a function
10605 // to test the optimized compiler. 10520 // to test the optimized compiler.
10606 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { 10521 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
10607 i::FLAG_allow_natives_syntax = true; 10522 i::FLAG_allow_natives_syntax = true;
10608 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10523 v8::HandleScope scope(v8::Isolate::GetCurrent());
10609 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10524 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10610 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); 10525 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
10709 " for (var i = 0; i < 10; i++) {" 10624 " for (var i = 0; i < 10; i++) {"
10710 " result += o.parseFloat('239');" 10625 " result += o.parseFloat('239');"
10711 " }" 10626 " }"
10712 " result" 10627 " result"
10713 "} catch(e) {" 10628 "} catch(e) {"
10714 " e" 10629 " e"
10715 "};"); 10630 "};");
10716 CHECK_EQ(239 * 10, value->Int32Value()); 10631 CHECK_EQ(239 * 10, value->Int32Value());
10717 } 10632 }
10718 10633
10719 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name, 10634 static void InterceptorCallICFastApi(
10720 const AccessorInfo& info) { 10635 Local<String> name,
10636 const v8::PropertyCallbackInfo<v8::Value>& info) {
10721 ApiTestFuzzer::Fuzz(); 10637 ApiTestFuzzer::Fuzz();
10722 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi)); 10638 CheckReturnValue(info, FUNCTION_ADDR(InterceptorCallICFastApi));
10723 int* call_count = 10639 int* call_count =
10724 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value()); 10640 reinterpret_cast<int*>(v8::External::Cast(*info.Data())->Value());
10725 ++(*call_count); 10641 ++(*call_count);
10726 if ((*call_count) % 20 == 0) { 10642 if ((*call_count) % 20 == 0) {
10727 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 10643 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
10728 } 10644 }
10729 return v8::Handle<Value>();
10730 } 10645 }
10731 10646
10732 static v8::Handle<Value> FastApiCallback_TrivialSignature( 10647 static void FastApiCallback_TrivialSignature(
10733 const v8::Arguments& args) { 10648 const v8::FunctionCallbackInfo<v8::Value>& args) {
10734 ApiTestFuzzer::Fuzz(); 10649 ApiTestFuzzer::Fuzz();
10735 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); 10650 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature));
10736 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10651 v8::Isolate* isolate = v8::Isolate::GetCurrent();
10737 CHECK_EQ(isolate, args.GetIsolate()); 10652 CHECK_EQ(isolate, args.GetIsolate());
10738 CHECK_EQ(args.This(), args.Holder()); 10653 CHECK_EQ(args.This(), args.Holder());
10739 CHECK(args.Data()->Equals(v8_str("method_data"))); 10654 CHECK(args.Data()->Equals(v8_str("method_data")));
10740 return v8::Integer::New(args[0]->Int32Value() + 1); 10655 args.GetReturnValue().Set(args[0]->Int32Value() + 1);
10741 } 10656 }
10742 10657
10743 static v8::Handle<Value> FastApiCallback_SimpleSignature( 10658 static void FastApiCallback_SimpleSignature(
10744 const v8::Arguments& args) { 10659 const v8::FunctionCallbackInfo<v8::Value>& args) {
10745 ApiTestFuzzer::Fuzz(); 10660 ApiTestFuzzer::Fuzz();
10746 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); 10661 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature));
10747 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 10662 v8::Isolate* isolate = v8::Isolate::GetCurrent();
10748 CHECK_EQ(isolate, args.GetIsolate()); 10663 CHECK_EQ(isolate, args.GetIsolate());
10749 CHECK_EQ(args.This()->GetPrototype(), args.Holder()); 10664 CHECK_EQ(args.This()->GetPrototype(), args.Holder());
10750 CHECK(args.Data()->Equals(v8_str("method_data"))); 10665 CHECK(args.Data()->Equals(v8_str("method_data")));
10751 // Note, we're using HasRealNamedProperty instead of Has to avoid 10666 // Note, we're using HasRealNamedProperty instead of Has to avoid
10752 // invoking the interceptor again. 10667 // invoking the interceptor again.
10753 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); 10668 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo")));
10754 return v8::Integer::New(args[0]->Int32Value() + 1); 10669 args.GetReturnValue().Set(args[0]->Int32Value() + 1);
10755 } 10670 }
10756 10671
10757 // Helper to maximize the odds of object moving. 10672 // Helper to maximize the odds of object moving.
10758 static void GenerateSomeGarbage() { 10673 static void GenerateSomeGarbage() {
10759 CompileRun( 10674 CompileRun(
10760 "var garbage;" 10675 "var garbage;"
10761 "for (var i = 0; i < 1000; i++) {" 10676 "for (var i = 0; i < 1000; i++) {"
10762 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" 10677 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
10763 "}" 10678 "}"
10764 "garbage = undefined;"); 10679 "garbage = undefined;");
10765 } 10680 }
10766 10681
10767 10682
10768 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { 10683 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
10769 static int count = 0; 10684 static int count = 0;
10770 if (count++ % 3 == 0) { 10685 if (count++ % 3 == 0) {
10771 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 10686 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
10772 // This should move the stub 10687 // This should move the stub
10773 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 10688 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
10774 } 10689 }
10775 return v8::Handle<v8::Value>();
10776 } 10690 }
10777 10691
10778 10692
10779 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 10693 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
10780 LocalContext context; 10694 LocalContext context;
10781 v8::HandleScope scope(context->GetIsolate()); 10695 v8::HandleScope scope(context->GetIsolate());
10782 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 10696 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
10783 nativeobject_templ->Set("callback", 10697 nativeobject_templ->Set("callback",
10784 v8::FunctionTemplate::New(DirectApiCallback)); 10698 v8::FunctionTemplate::New(DirectApiCallback));
10785 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 10699 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
10786 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 10700 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
10787 // call the api function multiple times to ensure direct call stub creation. 10701 // call the api function multiple times to ensure direct call stub creation.
10788 CompileRun( 10702 CompileRun(
10789 "function f() {" 10703 "function f() {"
10790 " for (var i = 1; i <= 30; i++) {" 10704 " for (var i = 1; i <= 30; i++) {"
10791 " nativeobject.callback();" 10705 " nativeobject.callback();"
10792 " }" 10706 " }"
10793 "}" 10707 "}"
10794 "f();"); 10708 "f();");
10795 } 10709 }
10796 10710
10797 10711
10798 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { 10712 void ThrowingDirectApiCallback(
10799 return v8::ThrowException(v8_str("g")); 10713 const v8::FunctionCallbackInfo<v8::Value>& args) {
10714 v8::ThrowException(v8_str("g"));
10800 } 10715 }
10801 10716
10802 10717
10803 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 10718 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
10804 LocalContext context; 10719 LocalContext context;
10805 v8::HandleScope scope(context->GetIsolate()); 10720 v8::HandleScope scope(context->GetIsolate());
10806 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 10721 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
10807 nativeobject_templ->Set("callback", 10722 nativeobject_templ->Set("callback",
10808 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); 10723 v8::FunctionTemplate::New(ThrowingDirectApiCallback));
10809 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 10724 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
(...skipping 12 matching lines...) Expand all
10822 10737
10823 10738
10824 static Handle<Value> DoDirectGetter() { 10739 static Handle<Value> DoDirectGetter() {
10825 if (++p_getter_count % 3 == 0) { 10740 if (++p_getter_count % 3 == 0) {
10826 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 10741 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
10827 GenerateSomeGarbage(); 10742 GenerateSomeGarbage();
10828 } 10743 }
10829 return v8_str("Direct Getter Result"); 10744 return v8_str("Direct Getter Result");
10830 } 10745 }
10831 10746
10832 static v8::Handle<v8::Value> DirectGetter(Local<String> name,
10833 const v8::AccessorInfo& info) {
10834 CheckReturnValue(info, FUNCTION_ADDR(DirectGetter));
10835 info.GetReturnValue().Set(v8_str("Garbage"));
10836 return DoDirectGetter();
10837 }
10838
10839 static v8::Handle<v8::Value> DirectGetterIndirect(
10840 Local<String> name,
10841 const v8::AccessorInfo& info) {
10842 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterIndirect));
10843 info.GetReturnValue().Set(DoDirectGetter());
10844 return v8::Handle<v8::Value>();
10845 }
10846
10847 static void DirectGetterCallback( 10747 static void DirectGetterCallback(
10848 Local<String> name, 10748 Local<String> name,
10849 const v8::PropertyCallbackInfo<v8::Value>& info) { 10749 const v8::PropertyCallbackInfo<v8::Value>& info) {
10850 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); 10750 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback));
10851 info.GetReturnValue().Set(DoDirectGetter()); 10751 info.GetReturnValue().Set(DoDirectGetter());
10852 } 10752 }
10853 10753
10854 10754
10855 template<typename Accessor> 10755 template<typename Accessor>
10856 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { 10756 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
10857 LocalContext context; 10757 LocalContext context;
10858 v8::HandleScope scope(context->GetIsolate()); 10758 v8::HandleScope scope(context->GetIsolate());
10859 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10759 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10860 obj->SetAccessor(v8_str("p1"), accessor); 10760 obj->SetAccessor(v8_str("p1"), accessor);
10861 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10761 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10862 p_getter_count = 0; 10762 p_getter_count = 0;
10863 v8::Handle<v8::Value> result = CompileRun( 10763 v8::Handle<v8::Value> result = CompileRun(
10864 "function f() {" 10764 "function f() {"
10865 " for (var i = 0; i < 30; i++) o1.p1;" 10765 " for (var i = 0; i < 30; i++) o1.p1;"
10866 " return o1.p1" 10766 " return o1.p1"
10867 "}" 10767 "}"
10868 "f();"); 10768 "f();");
10869 CHECK_EQ(v8_str("Direct Getter Result"), result); 10769 CHECK_EQ(v8_str("Direct Getter Result"), result);
10870 CHECK_EQ(31, p_getter_count); 10770 CHECK_EQ(31, p_getter_count);
10871 } 10771 }
10872 10772
10873 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 10773 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
10874 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterIndirect);
10875 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); 10774 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
10876 LoadICFastApi_DirectCall_GCMoveStub(DirectGetter);
10877 } 10775 }
10878 10776
10879 10777
10880 v8::Handle<v8::Value> ThrowingDirectGetterCallback( 10778 void ThrowingDirectGetterCallback(
10881 Local<String> name, const v8::AccessorInfo& info) { 10779 Local<String> name,
10882 return v8::ThrowException(v8_str("g")); 10780 const v8::PropertyCallbackInfo<v8::Value>& info) {
10781 v8::ThrowException(v8_str("g"));
10883 } 10782 }
10884 10783
10885 10784
10886 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 10785 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
10887 LocalContext context; 10786 LocalContext context;
10888 v8::HandleScope scope(context->GetIsolate()); 10787 v8::HandleScope scope(context->GetIsolate());
10889 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10788 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10890 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); 10789 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
10891 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10790 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10892 v8::Handle<Value> result = CompileRun( 10791 v8::Handle<Value> result = CompileRun(
10893 "var result = '';" 10792 "var result = '';"
10894 "for (var i = 0; i < 5; i++) {" 10793 "for (var i = 0; i < 5; i++) {"
10895 " try { o1.p1; } catch (e) { result += e; }" 10794 " try { o1.p1; } catch (e) { result += e; }"
10896 "}" 10795 "}"
10897 "result;"); 10796 "result;");
10898 CHECK_EQ(v8_str("ggggg"), result); 10797 CHECK_EQ(v8_str("ggggg"), result);
10899 } 10798 }
10900 10799
10901 10800
10902 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { 10801 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) {
10903 int interceptor_call_count = 0; 10802 int interceptor_call_count = 0;
10904 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10803 v8::HandleScope scope(v8::Isolate::GetCurrent());
10905 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10804 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10906 v8::Handle<v8::FunctionTemplate> method_templ = 10805 v8::Handle<v8::FunctionTemplate> method_templ =
10907 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 10806 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
10908 v8_str("method_data"), 10807 v8_str("method_data"),
10909 v8::Handle<v8::Signature>()); 10808 v8::Handle<v8::Signature>());
10910 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10809 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10911 proto_templ->Set(v8_str("method"), method_templ); 10810 proto_templ->Set(v8_str("method"), method_templ);
10912 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10811 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10913 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10812 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
10914 NULL, NULL, NULL, NULL, 10813 NULL, NULL, NULL, NULL,
10915 v8::External::New(&interceptor_call_count)); 10814 v8::External::New(&interceptor_call_count));
10916 LocalContext context; 10815 LocalContext context;
10917 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10816 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10918 GenerateSomeGarbage(); 10817 GenerateSomeGarbage();
10919 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10818 context->Global()->Set(v8_str("o"), fun->NewInstance());
10920 CompileRun( 10819 CompileRun(
10921 "var result = 0;" 10820 "var result = 0;"
10922 "for (var i = 0; i < 100; i++) {" 10821 "for (var i = 0; i < 100; i++) {"
10923 " result = o.method(41);" 10822 " result = o.method(41);"
10924 "}"); 10823 "}");
10925 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10824 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10926 CHECK_EQ(100, interceptor_call_count); 10825 CHECK_EQ(100, interceptor_call_count);
10927 } 10826 }
10928 10827
10929 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { 10828 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) {
10930 int interceptor_call_count = 0; 10829 int interceptor_call_count = 0;
10931 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10830 v8::HandleScope scope(v8::Isolate::GetCurrent());
10932 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10831 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10933 v8::Handle<v8::FunctionTemplate> method_templ = 10832 v8::Handle<v8::FunctionTemplate> method_templ =
10934 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10833 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10935 v8_str("method_data"), 10834 v8_str("method_data"),
10936 v8::Signature::New(fun_templ)); 10835 v8::Signature::New(fun_templ));
10937 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10836 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10938 proto_templ->Set(v8_str("method"), method_templ); 10837 proto_templ->Set(v8_str("method"), method_templ);
10939 fun_templ->SetHiddenPrototype(true); 10838 fun_templ->SetHiddenPrototype(true);
(...skipping 10 matching lines...) Expand all
10950 "var receiver = {};" 10849 "var receiver = {};"
10951 "receiver.__proto__ = o;" 10850 "receiver.__proto__ = o;"
10952 "var result = 0;" 10851 "var result = 0;"
10953 "for (var i = 0; i < 100; i++) {" 10852 "for (var i = 0; i < 100; i++) {"
10954 " result = receiver.method(41);" 10853 " result = receiver.method(41);"
10955 "}"); 10854 "}");
10956 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10855 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10957 CHECK_EQ(100, interceptor_call_count); 10856 CHECK_EQ(100, interceptor_call_count);
10958 } 10857 }
10959 10858
10960 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 10859 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
10961 int interceptor_call_count = 0; 10860 int interceptor_call_count = 0;
10962 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10861 v8::HandleScope scope(v8::Isolate::GetCurrent());
10963 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10862 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10964 v8::Handle<v8::FunctionTemplate> method_templ = 10863 v8::Handle<v8::FunctionTemplate> method_templ =
10965 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10864 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10966 v8_str("method_data"), 10865 v8_str("method_data"),
10967 v8::Signature::New(fun_templ)); 10866 v8::Signature::New(fun_templ));
10968 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10867 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10969 proto_templ->Set(v8_str("method"), method_templ); 10868 proto_templ->Set(v8_str("method"), method_templ);
10970 fun_templ->SetHiddenPrototype(true); 10869 fun_templ->SetHiddenPrototype(true);
(...skipping 16 matching lines...) Expand all
10987 " if (i == 50) {" 10886 " if (i == 50) {"
10988 " saved_result = result;" 10887 " saved_result = result;"
10989 " receiver = {method: function(x) { return x - 1 }};" 10888 " receiver = {method: function(x) { return x - 1 }};"
10990 " }" 10889 " }"
10991 "}"); 10890 "}");
10992 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10891 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10993 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10892 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10994 CHECK_GE(interceptor_call_count, 50); 10893 CHECK_GE(interceptor_call_count, 50);
10995 } 10894 }
10996 10895
10997 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 10896 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
10998 int interceptor_call_count = 0; 10897 int interceptor_call_count = 0;
10999 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10898 v8::HandleScope scope(v8::Isolate::GetCurrent());
11000 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10899 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11001 v8::Handle<v8::FunctionTemplate> method_templ = 10900 v8::Handle<v8::FunctionTemplate> method_templ =
11002 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10901 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11003 v8_str("method_data"), 10902 v8_str("method_data"),
11004 v8::Signature::New(fun_templ)); 10903 v8::Signature::New(fun_templ));
11005 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10904 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11006 proto_templ->Set(v8_str("method"), method_templ); 10905 proto_templ->Set(v8_str("method"), method_templ);
11007 fun_templ->SetHiddenPrototype(true); 10906 fun_templ->SetHiddenPrototype(true);
(...skipping 16 matching lines...) Expand all
11024 " if (i == 50) {" 10923 " if (i == 50) {"
11025 " saved_result = result;" 10924 " saved_result = result;"
11026 " o.method = function(x) { return x - 1 };" 10925 " o.method = function(x) { return x - 1 };"
11027 " }" 10926 " }"
11028 "}"); 10927 "}");
11029 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10928 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11030 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10929 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11031 CHECK_GE(interceptor_call_count, 50); 10930 CHECK_GE(interceptor_call_count, 50);
11032 } 10931 }
11033 10932
11034 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 10933 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
11035 int interceptor_call_count = 0; 10934 int interceptor_call_count = 0;
11036 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10935 v8::HandleScope scope(v8::Isolate::GetCurrent());
11037 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10936 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11038 v8::Handle<v8::FunctionTemplate> method_templ = 10937 v8::Handle<v8::FunctionTemplate> method_templ =
11039 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10938 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11040 v8_str("method_data"), 10939 v8_str("method_data"),
11041 v8::Signature::New(fun_templ)); 10940 v8::Signature::New(fun_templ));
11042 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10941 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11043 proto_templ->Set(v8_str("method"), method_templ); 10942 proto_templ->Set(v8_str("method"), method_templ);
11044 fun_templ->SetHiddenPrototype(true); 10943 fun_templ->SetHiddenPrototype(true);
(...skipping 19 matching lines...) Expand all
11064 " receiver = 333;" 10963 " receiver = 333;"
11065 " }" 10964 " }"
11066 "}"); 10965 "}");
11067 CHECK(try_catch.HasCaught()); 10966 CHECK(try_catch.HasCaught());
11068 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 10967 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11069 try_catch.Exception()->ToString()); 10968 try_catch.Exception()->ToString());
11070 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10969 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11071 CHECK_GE(interceptor_call_count, 50); 10970 CHECK_GE(interceptor_call_count, 50);
11072 } 10971 }
11073 10972
11074 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 10973 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
11075 int interceptor_call_count = 0; 10974 int interceptor_call_count = 0;
11076 v8::HandleScope scope(v8::Isolate::GetCurrent()); 10975 v8::HandleScope scope(v8::Isolate::GetCurrent());
11077 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10976 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11078 v8::Handle<v8::FunctionTemplate> method_templ = 10977 v8::Handle<v8::FunctionTemplate> method_templ =
11079 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10978 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11080 v8_str("method_data"), 10979 v8_str("method_data"),
11081 v8::Signature::New(fun_templ)); 10980 v8::Signature::New(fun_templ));
11082 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10981 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11083 proto_templ->Set(v8_str("method"), method_templ); 10982 proto_templ->Set(v8_str("method"), method_templ);
11084 fun_templ->SetHiddenPrototype(true); 10983 fun_templ->SetHiddenPrototype(true);
(...skipping 19 matching lines...) Expand all
11104 " receiver = {method: receiver.method};" 11003 " receiver = {method: receiver.method};"
11105 " }" 11004 " }"
11106 "}"); 11005 "}");
11107 CHECK(try_catch.HasCaught()); 11006 CHECK(try_catch.HasCaught());
11108 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 11007 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
11109 try_catch.Exception()->ToString()); 11008 try_catch.Exception()->ToString());
11110 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11009 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11111 CHECK_GE(interceptor_call_count, 50); 11010 CHECK_GE(interceptor_call_count, 50);
11112 } 11011 }
11113 11012
11114 THREADED_TEST(CallICFastApi_TrivialSignature) { 11013 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) {
11115 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11014 v8::HandleScope scope(v8::Isolate::GetCurrent());
11116 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11015 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11117 v8::Handle<v8::FunctionTemplate> method_templ = 11016 v8::Handle<v8::FunctionTemplate> method_templ =
11118 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 11017 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
11119 v8_str("method_data"), 11018 v8_str("method_data"),
11120 v8::Handle<v8::Signature>()); 11019 v8::Handle<v8::Signature>());
11121 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11020 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11122 proto_templ->Set(v8_str("method"), method_templ); 11021 proto_templ->Set(v8_str("method"), method_templ);
11123 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11022 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11124 USE(templ); 11023 USE(templ);
11125 LocalContext context; 11024 LocalContext context;
11126 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11025 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11127 GenerateSomeGarbage(); 11026 GenerateSomeGarbage();
11128 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11027 context->Global()->Set(v8_str("o"), fun->NewInstance());
11129 CompileRun( 11028 CompileRun(
11130 "var result = 0;" 11029 "var result = 0;"
11131 "for (var i = 0; i < 100; i++) {" 11030 "for (var i = 0; i < 100; i++) {"
11132 " result = o.method(41);" 11031 " result = o.method(41);"
11133 "}"); 11032 "}");
11134 11033
11135 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11034 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11136 } 11035 }
11137 11036
11138 THREADED_TEST(CallICFastApi_SimpleSignature) { 11037 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) {
11139 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11038 v8::HandleScope scope(v8::Isolate::GetCurrent());
11140 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11039 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11141 v8::Handle<v8::FunctionTemplate> method_templ = 11040 v8::Handle<v8::FunctionTemplate> method_templ =
11142 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11041 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11143 v8_str("method_data"), 11042 v8_str("method_data"),
11144 v8::Signature::New(fun_templ)); 11043 v8::Signature::New(fun_templ));
11145 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11044 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11146 proto_templ->Set(v8_str("method"), method_templ); 11045 proto_templ->Set(v8_str("method"), method_templ);
11147 fun_templ->SetHiddenPrototype(true); 11046 fun_templ->SetHiddenPrototype(true);
11148 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11047 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11149 CHECK(!templ.IsEmpty()); 11048 CHECK(!templ.IsEmpty());
11150 LocalContext context; 11049 LocalContext context;
11151 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11050 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11152 GenerateSomeGarbage(); 11051 GenerateSomeGarbage();
11153 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11052 context->Global()->Set(v8_str("o"), fun->NewInstance());
11154 CompileRun( 11053 CompileRun(
11155 "o.foo = 17;" 11054 "o.foo = 17;"
11156 "var receiver = {};" 11055 "var receiver = {};"
11157 "receiver.__proto__ = o;" 11056 "receiver.__proto__ = o;"
11158 "var result = 0;" 11057 "var result = 0;"
11159 "for (var i = 0; i < 100; i++) {" 11058 "for (var i = 0; i < 100; i++) {"
11160 " result = receiver.method(41);" 11059 " result = receiver.method(41);"
11161 "}"); 11060 "}");
11162 11061
11163 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11062 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11164 } 11063 }
11165 11064
11166 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { 11065 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) {
11167 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11066 v8::HandleScope scope(v8::Isolate::GetCurrent());
11168 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11067 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11169 v8::Handle<v8::FunctionTemplate> method_templ = 11068 v8::Handle<v8::FunctionTemplate> method_templ =
11170 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11069 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11171 v8_str("method_data"), 11070 v8_str("method_data"),
11172 v8::Signature::New(fun_templ)); 11071 v8::Signature::New(fun_templ));
11173 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11072 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11174 proto_templ->Set(v8_str("method"), method_templ); 11073 proto_templ->Set(v8_str("method"), method_templ);
11175 fun_templ->SetHiddenPrototype(true); 11074 fun_templ->SetHiddenPrototype(true);
11176 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11075 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
(...skipping 12 matching lines...) Expand all
11189 " result = receiver.method(41);" 11088 " result = receiver.method(41);"
11190 " if (i == 50) {" 11089 " if (i == 50) {"
11191 " saved_result = result;" 11090 " saved_result = result;"
11192 " receiver = {method: function(x) { return x - 1 }};" 11091 " receiver = {method: function(x) { return x - 1 }};"
11193 " }" 11092 " }"
11194 "}"); 11093 "}");
11195 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11094 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11196 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11095 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11197 } 11096 }
11198 11097
11199 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { 11098 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
11200 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11099 v8::HandleScope scope(v8::Isolate::GetCurrent());
11201 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11100 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11202 v8::Handle<v8::FunctionTemplate> method_templ = 11101 v8::Handle<v8::FunctionTemplate> method_templ =
11203 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11102 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11204 v8_str("method_data"), 11103 v8_str("method_data"),
11205 v8::Signature::New(fun_templ)); 11104 v8::Signature::New(fun_templ));
11206 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11105 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11207 proto_templ->Set(v8_str("method"), method_templ); 11106 proto_templ->Set(v8_str("method"), method_templ);
11208 fun_templ->SetHiddenPrototype(true); 11107 fun_templ->SetHiddenPrototype(true);
11209 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11108 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
(...skipping 15 matching lines...) Expand all
11225 " saved_result = result;" 11124 " saved_result = result;"
11226 " receiver = 333;" 11125 " receiver = 333;"
11227 " }" 11126 " }"
11228 "}"); 11127 "}");
11229 CHECK(try_catch.HasCaught()); 11128 CHECK(try_catch.HasCaught());
11230 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 11129 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11231 try_catch.Exception()->ToString()); 11130 try_catch.Exception()->ToString());
11232 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11131 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11233 } 11132 }
11234 11133
11235 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) { 11134 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) {
11236 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11135 v8::HandleScope scope(v8::Isolate::GetCurrent());
11237 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11136 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
11238 v8::Handle<v8::FunctionTemplate> method_templ = 11137 v8::Handle<v8::FunctionTemplate> method_templ =
11239 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 11138 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
11240 v8_str("method_data"), 11139 v8_str("method_data"),
11241 v8::Signature::New(fun_templ)); 11140 v8::Signature::New(fun_templ));
11242 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11141 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11243 proto_templ->Set(v8_str("method"), method_templ); 11142 proto_templ->Set(v8_str("method"), method_templ);
11244 fun_templ->SetHiddenPrototype(true); 11143 fun_templ->SetHiddenPrototype(true);
11245 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 11144 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
(...skipping 18 matching lines...) Expand all
11264 "}"); 11163 "}");
11265 CHECK(try_catch.HasCaught()); 11164 CHECK(try_catch.HasCaught());
11266 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 11165 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
11267 try_catch.Exception()->ToString()); 11166 try_catch.Exception()->ToString());
11268 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11167 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11269 } 11168 }
11270 11169
11271 11170
11272 v8::Handle<Value> keyed_call_ic_function; 11171 v8::Handle<Value> keyed_call_ic_function;
11273 11172
11274 static v8::Handle<Value> InterceptorKeyedCallICGetter( 11173 static void InterceptorKeyedCallICGetter(
11275 Local<String> name, const AccessorInfo& info) { 11174 Local<String> name,
11175 const v8::PropertyCallbackInfo<v8::Value>& info) {
11276 ApiTestFuzzer::Fuzz(); 11176 ApiTestFuzzer::Fuzz();
11277 if (v8_str("x")->Equals(name)) { 11177 if (v8_str("x")->Equals(name)) {
11278 return keyed_call_ic_function; 11178 info.GetReturnValue().Set(keyed_call_ic_function);
11279 } 11179 }
11280 return v8::Handle<Value>();
11281 } 11180 }
11282 11181
11283 11182
11284 // Test the case when we stored cacheable lookup into 11183 // Test the case when we stored cacheable lookup into
11285 // a stub, but the function name changed (to another cacheable function). 11184 // a stub, but the function name changed (to another cacheable function).
11286 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { 11185 THREADED_TEST(InterceptorKeyedCallICKeyChange1) {
11287 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11186 v8::HandleScope scope(v8::Isolate::GetCurrent());
11288 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11187 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11289 templ->SetNamedPropertyHandler(NoBlockGetterX); 11188 templ->SetNamedPropertyHandler(NoBlockGetterX);
11290 LocalContext context; 11189 LocalContext context;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
11421 "for (var i = 0; i < 10; i++) {" 11320 "for (var i = 0; i < 10; i++) {"
11422 " if (i == 5) { proto.method = function(x) { return x - 1; }; };" 11321 " if (i == 5) { proto.method = function(x) { return x - 1; }; };"
11423 " result += o[m](41);" 11322 " result += o[m](41);"
11424 "}"); 11323 "}");
11425 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 11324 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
11426 } 11325 }
11427 11326
11428 11327
11429 static int interceptor_call_count = 0; 11328 static int interceptor_call_count = 0;
11430 11329
11431 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, 11330 static void InterceptorICRefErrorGetter(
11432 const AccessorInfo& info) { 11331 Local<String> name,
11332 const v8::PropertyCallbackInfo<v8::Value>& info) {
11433 ApiTestFuzzer::Fuzz(); 11333 ApiTestFuzzer::Fuzz();
11434 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { 11334 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) {
11435 return call_ic_function2; 11335 info.GetReturnValue().Set(call_ic_function2);
11436 } 11336 }
11437 return v8::Handle<Value>();
11438 } 11337 }
11439 11338
11440 11339
11441 // This test should hit load and call ICs for the interceptor case. 11340 // This test should hit load and call ICs for the interceptor case.
11442 // Once in a while, the interceptor will reply that a property was not 11341 // Once in a while, the interceptor will reply that a property was not
11443 // found in which case we should get a reference error. 11342 // found in which case we should get a reference error.
11444 THREADED_TEST(InterceptorICReferenceErrors) { 11343 THREADED_TEST(InterceptorICReferenceErrors) {
11445 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11344 v8::HandleScope scope(v8::Isolate::GetCurrent());
11446 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11345 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11447 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); 11346 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter);
(...skipping 16 matching lines...) Expand all
11464 " }" 11363 " }"
11465 " return false;" 11364 " return false;"
11466 "};" 11365 "};"
11467 "g();"); 11366 "g();");
11468 CHECK_EQ(true, value->BooleanValue()); 11367 CHECK_EQ(true, value->BooleanValue());
11469 } 11368 }
11470 11369
11471 11370
11472 static int interceptor_ic_exception_get_count = 0; 11371 static int interceptor_ic_exception_get_count = 0;
11473 11372
11474 static v8::Handle<Value> InterceptorICExceptionGetter( 11373 static void InterceptorICExceptionGetter(
11475 Local<String> name, 11374 Local<String> name,
11476 const AccessorInfo& info) { 11375 const v8::PropertyCallbackInfo<v8::Value>& info) {
11477 ApiTestFuzzer::Fuzz(); 11376 ApiTestFuzzer::Fuzz();
11478 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) { 11377 if (v8_str("x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) {
11479 return call_ic_function3; 11378 info.GetReturnValue().Set(call_ic_function3);
11480 } 11379 }
11481 if (interceptor_ic_exception_get_count == 20) { 11380 if (interceptor_ic_exception_get_count == 20) {
11482 return v8::ThrowException(v8_num(42)); 11381 v8::ThrowException(v8_num(42));
11382 return;
11483 } 11383 }
11484 // Do not handle get for properties other than x.
11485 return v8::Handle<Value>();
11486 } 11384 }
11487 11385
11488 // Test interceptor load/call IC where the interceptor throws an 11386 // Test interceptor load/call IC where the interceptor throws an
11489 // exception once in a while. 11387 // exception once in a while.
11490 THREADED_TEST(InterceptorICGetterExceptions) { 11388 THREADED_TEST(InterceptorICGetterExceptions) {
11491 interceptor_ic_exception_get_count = 0; 11389 interceptor_ic_exception_get_count = 0;
11492 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11390 v8::HandleScope scope(v8::Isolate::GetCurrent());
11493 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11391 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11494 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); 11392 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter);
11495 LocalContext context(0, templ, v8::Handle<Value>()); 11393 LocalContext context(0, templ, v8::Handle<Value>());
(...skipping 15 matching lines...) Expand all
11511 " }" 11409 " }"
11512 " return false;" 11410 " return false;"
11513 "};" 11411 "};"
11514 "f();"); 11412 "f();");
11515 CHECK_EQ(true, value->BooleanValue()); 11413 CHECK_EQ(true, value->BooleanValue());
11516 } 11414 }
11517 11415
11518 11416
11519 static int interceptor_ic_exception_set_count = 0; 11417 static int interceptor_ic_exception_set_count = 0;
11520 11418
11521 static v8::Handle<Value> InterceptorICExceptionSetter( 11419 static void InterceptorICExceptionSetter(
11522 Local<String> key, Local<Value> value, const AccessorInfo&) { 11420 Local<String> key,
11421 Local<Value> value,
11422 const v8::PropertyCallbackInfo<v8::Value>& info) {
11523 ApiTestFuzzer::Fuzz(); 11423 ApiTestFuzzer::Fuzz();
11524 if (++interceptor_ic_exception_set_count > 20) { 11424 if (++interceptor_ic_exception_set_count > 20) {
11525 return v8::ThrowException(v8_num(42)); 11425 v8::ThrowException(v8_num(42));
11526 } 11426 }
11527 // Do not actually handle setting.
11528 return v8::Handle<Value>();
11529 } 11427 }
11530 11428
11531 // Test interceptor store IC where the interceptor throws an exception 11429 // Test interceptor store IC where the interceptor throws an exception
11532 // once in a while. 11430 // once in a while.
11533 THREADED_TEST(InterceptorICSetterExceptions) { 11431 THREADED_TEST(InterceptorICSetterExceptions) {
11534 interceptor_ic_exception_set_count = 0; 11432 interceptor_ic_exception_set_count = 0;
11535 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11433 v8::HandleScope scope(v8::Isolate::GetCurrent());
11536 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11434 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11537 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); 11435 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter);
11538 LocalContext context(0, templ, v8::Handle<Value>()); 11436 LocalContext context(0, templ, v8::Handle<Value>());
11539 v8::Handle<Value> value = CompileRun( 11437 v8::Handle<Value> value = CompileRun(
11540 "function f() {" 11438 "function f() {"
11541 " for (var i = 0; i < 100; i++) {" 11439 " for (var i = 0; i < 100; i++) {"
11542 " try { x = 42; } catch(e) { return true; }" 11440 " try { x = 42; } catch(e) { return true; }"
11543 " }" 11441 " }"
11544 " return false;" 11442 " return false;"
11545 "};" 11443 "};"
11546 "f();"); 11444 "f();");
11547 CHECK_EQ(true, value->BooleanValue()); 11445 CHECK_EQ(true, value->BooleanValue());
11548 } 11446 }
11549 11447
11550 11448
11551 // Test that we ignore null interceptors. 11449 // Test that we ignore null interceptors.
11552 THREADED_TEST(NullNamedInterceptor) { 11450 THREADED_TEST(NullNamedInterceptor) {
11553 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11451 v8::HandleScope scope(v8::Isolate::GetCurrent());
11554 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11452 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11555 templ->SetNamedPropertyHandler(static_cast<v8::NamedPropertyGetter>(0)); 11453 templ->SetNamedPropertyHandler(
11454 static_cast<v8::NamedPropertyGetterCallback>(0));
11556 LocalContext context; 11455 LocalContext context;
11557 templ->Set("x", v8_num(42)); 11456 templ->Set("x", v8_num(42));
11558 v8::Handle<v8::Object> obj = templ->NewInstance(); 11457 v8::Handle<v8::Object> obj = templ->NewInstance();
11559 context->Global()->Set(v8_str("obj"), obj); 11458 context->Global()->Set(v8_str("obj"), obj);
11560 v8::Handle<Value> value = CompileRun("obj.x"); 11459 v8::Handle<Value> value = CompileRun("obj.x");
11561 CHECK(value->IsInt32()); 11460 CHECK(value->IsInt32());
11562 CHECK_EQ(42, value->Int32Value()); 11461 CHECK_EQ(42, value->Int32Value());
11563 } 11462 }
11564 11463
11565 11464
11566 // Test that we ignore null interceptors. 11465 // Test that we ignore null interceptors.
11567 THREADED_TEST(NullIndexedInterceptor) { 11466 THREADED_TEST(NullIndexedInterceptor) {
11568 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11467 v8::HandleScope scope(v8::Isolate::GetCurrent());
11569 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 11468 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
11570 templ->SetIndexedPropertyHandler(static_cast<v8::IndexedPropertyGetter>(0)); 11469 templ->SetIndexedPropertyHandler(
11470 static_cast<v8::IndexedPropertyGetterCallback>(0));
11571 LocalContext context; 11471 LocalContext context;
11572 templ->Set("42", v8_num(42)); 11472 templ->Set("42", v8_num(42));
11573 v8::Handle<v8::Object> obj = templ->NewInstance(); 11473 v8::Handle<v8::Object> obj = templ->NewInstance();
11574 context->Global()->Set(v8_str("obj"), obj); 11474 context->Global()->Set(v8_str("obj"), obj);
11575 v8::Handle<Value> value = CompileRun("obj[42]"); 11475 v8::Handle<Value> value = CompileRun("obj[42]");
11576 CHECK(value->IsInt32()); 11476 CHECK(value->IsInt32());
11577 CHECK_EQ(42, value->Int32Value()); 11477 CHECK_EQ(42, value->Int32Value());
11578 } 11478 }
11579 11479
11580 11480
11581 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 11481 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
11582 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11482 v8::HandleScope scope(v8::Isolate::GetCurrent());
11583 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 11483 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
11584 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 11484 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
11585 LocalContext env; 11485 LocalContext env;
11586 env->Global()->Set(v8_str("obj"), 11486 env->Global()->Set(v8_str("obj"),
11587 templ->GetFunction()->NewInstance()); 11487 templ->GetFunction()->NewInstance());
11588 ExpectTrue("obj.x === 42"); 11488 ExpectTrue("obj.x === 42");
11589 ExpectTrue("!obj.propertyIsEnumerable('x')"); 11489 ExpectTrue("!obj.propertyIsEnumerable('x')");
11590 } 11490 }
11591 11491
11592 11492
11593 static Handle<Value> ThrowingGetter(Local<String> name, 11493 static void ThrowingGetter(Local<String> name,
11594 const AccessorInfo& info) { 11494 const v8::PropertyCallbackInfo<v8::Value>& info) {
11595 ApiTestFuzzer::Fuzz(); 11495 ApiTestFuzzer::Fuzz();
11596 ThrowException(Handle<Value>()); 11496 ThrowException(Handle<Value>());
11597 return Undefined(); 11497 info.GetReturnValue().SetUndefined();
11598 } 11498 }
11599 11499
11600 11500
11601 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 11501 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
11602 LocalContext context; 11502 LocalContext context;
11603 HandleScope scope(context->GetIsolate()); 11503 HandleScope scope(context->GetIsolate());
11604 11504
11605 Local<FunctionTemplate> templ = FunctionTemplate::New(); 11505 Local<FunctionTemplate> templ = FunctionTemplate::New();
11606 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 11506 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
11607 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 11507 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
11644 try_catch.Reset(); 11544 try_catch.Reset();
11645 CHECK(result.IsEmpty()); 11545 CHECK(result.IsEmpty());
11646 11546
11647 result = with_js_getter->Get(v8_str("f")); 11547 result = with_js_getter->Get(v8_str("f"));
11648 CHECK(try_catch.HasCaught()); 11548 CHECK(try_catch.HasCaught());
11649 try_catch.Reset(); 11549 try_catch.Reset();
11650 CHECK(result.IsEmpty()); 11550 CHECK(result.IsEmpty());
11651 } 11551 }
11652 11552
11653 11553
11654 static Handle<Value> ThrowingCallbackWithTryCatch(const Arguments& args) { 11554 static void ThrowingCallbackWithTryCatch(
11555 const v8::FunctionCallbackInfo<v8::Value>& args) {
11655 TryCatch try_catch; 11556 TryCatch try_catch;
11656 // Verboseness is important: it triggers message delivery which can call into 11557 // Verboseness is important: it triggers message delivery which can call into
11657 // external code. 11558 // external code.
11658 try_catch.SetVerbose(true); 11559 try_catch.SetVerbose(true);
11659 CompileRun("throw 'from JS';"); 11560 CompileRun("throw 'from JS';");
11660 CHECK(try_catch.HasCaught()); 11561 CHECK(try_catch.HasCaught());
11661 CHECK(!i::Isolate::Current()->has_pending_exception()); 11562 CHECK(!i::Isolate::Current()->has_pending_exception());
11662 CHECK(!i::Isolate::Current()->has_scheduled_exception()); 11563 CHECK(!i::Isolate::Current()->has_scheduled_exception());
11663 return Undefined();
11664 } 11564 }
11665 11565
11666 11566
11667 static int call_depth; 11567 static int call_depth;
11668 11568
11669 11569
11670 static void WithTryCatch(Handle<Message> message, Handle<Value> data) { 11570 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
11671 TryCatch try_catch; 11571 TryCatch try_catch;
11672 } 11572 }
11673 11573
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
11711 "var thrown = false;\n" 11611 "var thrown = false;\n"
11712 "try { func(); } catch(e) { thrown = true; }\n" 11612 "try { func(); } catch(e) { thrown = true; }\n"
11713 "thrown\n"); 11613 "thrown\n");
11714 if (callback != NULL) { 11614 if (callback != NULL) {
11715 V8::RemoveMessageListeners(callback); 11615 V8::RemoveMessageListeners(callback);
11716 } 11616 }
11717 } 11617 }
11718 } 11618 }
11719 11619
11720 11620
11721 static v8::Handle<Value> ParentGetter(Local<String> name, 11621 static void ParentGetter(Local<String> name,
11722 const AccessorInfo& info) { 11622 const v8::PropertyCallbackInfo<v8::Value>& info) {
11723 ApiTestFuzzer::Fuzz(); 11623 ApiTestFuzzer::Fuzz();
11724 return v8_num(1); 11624 info.GetReturnValue().Set(v8_num(1));
11725 } 11625 }
11726 11626
11727 11627
11728 static v8::Handle<Value> ChildGetter(Local<String> name, 11628 static void ChildGetter(Local<String> name,
11729 const AccessorInfo& info) { 11629 const v8::PropertyCallbackInfo<v8::Value>& info) {
11730 ApiTestFuzzer::Fuzz(); 11630 ApiTestFuzzer::Fuzz();
11731 return v8_num(42); 11631 info.GetReturnValue().Set(v8_num(42));
11732 } 11632 }
11733 11633
11734 11634
11735 THREADED_TEST(Overriding) { 11635 THREADED_TEST(Overriding) {
11736 i::FLAG_es5_readonly = true; 11636 i::FLAG_es5_readonly = true;
11737 LocalContext context; 11637 LocalContext context;
11738 v8::HandleScope scope(context->GetIsolate()); 11638 v8::HandleScope scope(context->GetIsolate());
11739 11639
11740 // Parent template. 11640 // Parent template.
11741 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); 11641 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
11783 // Check that 'h' cannot be shadowed. 11683 // Check that 'h' cannot be shadowed.
11784 value = v8_compile("o.h = 3; o.h")->Run(); 11684 value = v8_compile("o.h = 3; o.h")->Run();
11785 CHECK_EQ(1, value->Int32Value()); 11685 CHECK_EQ(1, value->Int32Value());
11786 11686
11787 // Check that 'i' cannot be shadowed or changed. 11687 // Check that 'i' cannot be shadowed or changed.
11788 value = v8_compile("o.i = 3; o.i")->Run(); 11688 value = v8_compile("o.i = 3; o.i")->Run();
11789 CHECK_EQ(42, value->Int32Value()); 11689 CHECK_EQ(42, value->Int32Value());
11790 } 11690 }
11791 11691
11792 11692
11793 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) { 11693 static void IsConstructHandler(
11694 const v8::FunctionCallbackInfo<v8::Value>& args) {
11794 ApiTestFuzzer::Fuzz(); 11695 ApiTestFuzzer::Fuzz();
11795 return v8::Boolean::New(args.IsConstructCall()); 11696 args.GetReturnValue().Set(args.IsConstructCall());
11796 } 11697 }
11797 11698
11798 11699
11799 THREADED_TEST(IsConstructCall) { 11700 THREADED_TEST(IsConstructCall) {
11800 v8::HandleScope scope(v8::Isolate::GetCurrent()); 11701 v8::HandleScope scope(v8::Isolate::GetCurrent());
11801 11702
11802 // Function template with call handler. 11703 // Function template with call handler.
11803 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 11704 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
11804 templ->SetCallHandler(IsConstructHandler); 11705 templ->SetCallHandler(IsConstructHandler);
11805 11706
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
12026 11927
12027 void ApiTestFuzzer::CallTest() { 11928 void ApiTestFuzzer::CallTest() {
12028 if (kLogThreading) 11929 if (kLogThreading)
12029 printf("Start test %d\n", test_number_); 11930 printf("Start test %d\n", test_number_);
12030 CallTestNumber(test_number_); 11931 CallTestNumber(test_number_);
12031 if (kLogThreading) 11932 if (kLogThreading)
12032 printf("End test %d\n", test_number_); 11933 printf("End test %d\n", test_number_);
12033 } 11934 }
12034 11935
12035 11936
12036 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) { 11937 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) {
12037 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11938 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
12038 ApiTestFuzzer::Fuzz(); 11939 ApiTestFuzzer::Fuzz();
12039 v8::Unlocker unlocker(CcTest::default_isolate()); 11940 v8::Unlocker unlocker(CcTest::default_isolate());
12040 const char* code = "throw 7;"; 11941 const char* code = "throw 7;";
12041 { 11942 {
12042 v8::Locker nested_locker(CcTest::default_isolate()); 11943 v8::Locker nested_locker(CcTest::default_isolate());
12043 v8::HandleScope scope(args.GetIsolate()); 11944 v8::HandleScope scope(args.GetIsolate());
12044 v8::Handle<Value> exception; 11945 v8::Handle<Value> exception;
12045 { v8::TryCatch try_catch; 11946 { v8::TryCatch try_catch;
12046 v8::Handle<Value> value = CompileRun(code); 11947 v8::Handle<Value> value = CompileRun(code);
12047 CHECK(value.IsEmpty()); 11948 CHECK(value.IsEmpty());
12048 CHECK(try_catch.HasCaught()); 11949 CHECK(try_catch.HasCaught());
12049 // Make sure to wrap the exception in a new handle because 11950 // Make sure to wrap the exception in a new handle because
12050 // the handle returned from the TryCatch is destroyed 11951 // the handle returned from the TryCatch is destroyed
12051 // when the TryCatch is destroyed. 11952 // when the TryCatch is destroyed.
12052 exception = Local<Value>::New(try_catch.Exception()); 11953 exception = Local<Value>::New(try_catch.Exception());
12053 } 11954 }
12054 return v8::ThrowException(exception); 11955 v8::ThrowException(exception);
12055 } 11956 }
12056 } 11957 }
12057 11958
12058 11959
12059 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) { 11960 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
12060 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11961 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
12061 ApiTestFuzzer::Fuzz(); 11962 ApiTestFuzzer::Fuzz();
12062 v8::Unlocker unlocker(CcTest::default_isolate()); 11963 v8::Unlocker unlocker(CcTest::default_isolate());
12063 const char* code = "throw 7;"; 11964 const char* code = "throw 7;";
12064 { 11965 {
12065 v8::Locker nested_locker(CcTest::default_isolate()); 11966 v8::Locker nested_locker(CcTest::default_isolate());
12066 v8::HandleScope scope(args.GetIsolate()); 11967 v8::HandleScope scope(args.GetIsolate());
12067 v8::Handle<Value> value = CompileRun(code); 11968 v8::Handle<Value> value = CompileRun(code);
12068 CHECK(value.IsEmpty()); 11969 CHECK(value.IsEmpty());
12069 return scope.Close(v8_str("foo")); 11970 args.GetReturnValue().Set(v8_str("foo"));
12070 } 11971 }
12071 } 11972 }
12072 11973
12073 11974
12074 // These are locking tests that don't need to be run again 11975 // These are locking tests that don't need to be run again
12075 // as part of the locking aggregation tests. 11976 // as part of the locking aggregation tests.
12076 TEST(NestedLockers) { 11977 TEST(NestedLockers) {
12077 v8::Locker locker(CcTest::default_isolate()); 11978 v8::Locker locker(CcTest::default_isolate());
12078 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11979 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
12079 LocalContext env; 11980 LocalContext env;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
12117 12018
12118 THREADED_TEST(RecursiveLocking) { 12019 THREADED_TEST(RecursiveLocking) {
12119 v8::Locker locker(CcTest::default_isolate()); 12020 v8::Locker locker(CcTest::default_isolate());
12120 { 12021 {
12121 v8::Locker locker2(CcTest::default_isolate()); 12022 v8::Locker locker2(CcTest::default_isolate());
12122 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 12023 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
12123 } 12024 }
12124 } 12025 }
12125 12026
12126 12027
12127 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) { 12028 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) {
12128 ApiTestFuzzer::Fuzz(); 12029 ApiTestFuzzer::Fuzz();
12129 v8::Unlocker unlocker(CcTest::default_isolate()); 12030 v8::Unlocker unlocker(CcTest::default_isolate());
12130 return v8::Undefined();
12131 } 12031 }
12132 12032
12133 12033
12134 THREADED_TEST(LockUnlockLock) { 12034 THREADED_TEST(LockUnlockLock) {
12135 { 12035 {
12136 v8::Locker locker(CcTest::default_isolate()); 12036 v8::Locker locker(CcTest::default_isolate());
12137 v8::HandleScope scope(CcTest::default_isolate()); 12037 v8::HandleScope scope(CcTest::default_isolate());
12138 LocalContext env; 12038 LocalContext env;
12139 Local<v8::FunctionTemplate> fun_templ = 12039 Local<v8::FunctionTemplate> fun_templ =
12140 v8::FunctionTemplate::New(UnlockForAMoment); 12040 v8::FunctionTemplate::New(UnlockForAMoment);
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
12878 v8::Handle<v8::Script> script1 = 12778 v8::Handle<v8::Script> script1 =
12879 v8::Script::Compile(source1, v8::String::New("test.js")); 12779 v8::Script::Compile(source1, v8::String::New("test.js"));
12880 v8::Handle<v8::Script> script2 = 12780 v8::Handle<v8::Script> script2 =
12881 v8::Script::Compile(source0); // different origin 12781 v8::Script::Compile(source0); // different origin
12882 CHECK_EQ(1234, script0->Run()->Int32Value()); 12782 CHECK_EQ(1234, script0->Run()->Int32Value());
12883 CHECK_EQ(1234, script1->Run()->Int32Value()); 12783 CHECK_EQ(1234, script1->Run()->Int32Value());
12884 CHECK_EQ(1234, script2->Run()->Int32Value()); 12784 CHECK_EQ(1234, script2->Run()->Int32Value());
12885 } 12785 }
12886 12786
12887 12787
12888 static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) { 12788 static void FunctionNameCallback(
12789 const v8::FunctionCallbackInfo<v8::Value>& args) {
12889 ApiTestFuzzer::Fuzz(); 12790 ApiTestFuzzer::Fuzz();
12890 return v8_num(42); 12791 args.GetReturnValue().Set(v8_num(42));
12891 } 12792 }
12892 12793
12893 12794
12894 THREADED_TEST(CallbackFunctionName) { 12795 THREADED_TEST(CallbackFunctionName) {
12895 LocalContext context; 12796 LocalContext context;
12896 v8::HandleScope scope(context->GetIsolate()); 12797 v8::HandleScope scope(context->GetIsolate());
12897 Local<ObjectTemplate> t = ObjectTemplate::New(); 12798 Local<ObjectTemplate> t = ObjectTemplate::New();
12898 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback)); 12799 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback));
12899 context->Global()->Set(v8_str("obj"), t->NewInstance()); 12800 context->Global()->Set(v8_str("obj"), t->NewInstance());
12900 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 12801 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
14049 CHECK_EQ(v8::Integer::New(0), res); 13950 CHECK_EQ(v8::Integer::New(0), res);
14050 // Check with 'with'. 13951 // Check with 'with'.
14051 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); 13952 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()");
14052 CHECK_EQ(v8::Integer::New(0), res); 13953 CHECK_EQ(v8::Integer::New(0), res);
14053 } 13954 }
14054 13955
14055 static int force_set_set_count = 0; 13956 static int force_set_set_count = 0;
14056 static int force_set_get_count = 0; 13957 static int force_set_get_count = 0;
14057 bool pass_on_get = false; 13958 bool pass_on_get = false;
14058 13959
14059 static v8::Handle<v8::Value> ForceSetGetter(v8::Local<v8::String> name, 13960 static void ForceSetGetter(v8::Local<v8::String> name,
14060 const v8::AccessorInfo& info) { 13961 const v8::PropertyCallbackInfo<v8::Value>& info) {
14061 force_set_get_count++; 13962 force_set_get_count++;
14062 if (pass_on_get) { 13963 if (pass_on_get) {
14063 return v8::Handle<v8::Value>(); 13964 return;
14064 } else {
14065 return v8::Int32::New(3);
14066 } 13965 }
13966 info.GetReturnValue().Set(3);
14067 } 13967 }
14068 13968
14069 static void ForceSetSetter(v8::Local<v8::String> name, 13969 static void ForceSetSetter(v8::Local<v8::String> name,
14070 v8::Local<v8::Value> value, 13970 v8::Local<v8::Value> value,
14071 const v8::AccessorInfo& info) { 13971 const v8::PropertyCallbackInfo<void>& info) {
14072 force_set_set_count++; 13972 force_set_set_count++;
14073 } 13973 }
14074 13974
14075 static v8::Handle<v8::Value> ForceSetInterceptSetter( 13975 static void ForceSetInterceptSetter(
14076 v8::Local<v8::String> name, 13976 v8::Local<v8::String> name,
14077 v8::Local<v8::Value> value, 13977 v8::Local<v8::Value> value,
14078 const v8::AccessorInfo& info) { 13978 const v8::PropertyCallbackInfo<v8::Value>& info) {
14079 force_set_set_count++; 13979 force_set_set_count++;
14080 return v8::Undefined(); 13980 info.GetReturnValue().SetUndefined();
14081 } 13981 }
14082 13982
14083 TEST(ForceSet) { 13983 TEST(ForceSet) {
14084 force_set_get_count = 0; 13984 force_set_get_count = 0;
14085 force_set_set_count = 0; 13985 force_set_set_count = 0;
14086 pass_on_get = false; 13986 pass_on_get = false;
14087 13987
14088 v8::HandleScope scope(v8::Isolate::GetCurrent()); 13988 v8::HandleScope scope(v8::Isolate::GetCurrent());
14089 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13989 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14090 v8::Handle<v8::String> access_property = v8::String::New("a"); 13990 v8::Handle<v8::String> access_property = v8::String::New("a");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
14184 // This should succeed even though the property is dont-delete. 14084 // This should succeed even though the property is dont-delete.
14185 CHECK(global->ForceDelete(simple_property)); 14085 CHECK(global->ForceDelete(simple_property));
14186 CHECK(global->Get(simple_property)->IsUndefined()); 14086 CHECK(global->Get(simple_property)->IsUndefined());
14187 } 14087 }
14188 14088
14189 14089
14190 static int force_delete_interceptor_count = 0; 14090 static int force_delete_interceptor_count = 0;
14191 static bool pass_on_delete = false; 14091 static bool pass_on_delete = false;
14192 14092
14193 14093
14194 static v8::Handle<v8::Boolean> ForceDeleteDeleter( 14094 static void ForceDeleteDeleter(
14195 v8::Local<v8::String> name, 14095 v8::Local<v8::String> name,
14196 const v8::AccessorInfo& info) { 14096 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
14197 force_delete_interceptor_count++; 14097 force_delete_interceptor_count++;
14198 if (pass_on_delete) { 14098 if (pass_on_delete) return;
14199 return v8::Handle<v8::Boolean>(); 14099 info.GetReturnValue().Set(true);
14200 } else {
14201 return v8::True();
14202 }
14203 } 14100 }
14204 14101
14205 14102
14206 THREADED_TEST(ForceDeleteWithInterceptor) { 14103 THREADED_TEST(ForceDeleteWithInterceptor) {
14207 force_delete_interceptor_count = 0; 14104 force_delete_interceptor_count = 0;
14208 pass_on_delete = false; 14105 pass_on_delete = false;
14209 14106
14210 v8::HandleScope scope(v8::Isolate::GetCurrent()); 14107 v8::HandleScope scope(v8::Isolate::GetCurrent());
14211 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 14108 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
14212 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 14109 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
14298 14195
14299 14196
14300 static v8::Local<Context> calling_context0; 14197 static v8::Local<Context> calling_context0;
14301 static v8::Local<Context> calling_context1; 14198 static v8::Local<Context> calling_context1;
14302 static v8::Local<Context> calling_context2; 14199 static v8::Local<Context> calling_context2;
14303 14200
14304 14201
14305 // Check that the call to the callback is initiated in 14202 // Check that the call to the callback is initiated in
14306 // calling_context2, the directly calling context is calling_context1 14203 // calling_context2, the directly calling context is calling_context1
14307 // and the callback itself is in calling_context0. 14204 // and the callback itself is in calling_context0.
14308 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) { 14205 static void GetCallingContextCallback(
14206 const v8::FunctionCallbackInfo<v8::Value>& args) {
14309 ApiTestFuzzer::Fuzz(); 14207 ApiTestFuzzer::Fuzz();
14310 CHECK(Context::GetCurrent() == calling_context0); 14208 CHECK(Context::GetCurrent() == calling_context0);
14311 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0); 14209 CHECK(args.GetIsolate()->GetCurrentContext() == calling_context0);
14312 CHECK(Context::GetCalling() == calling_context1); 14210 CHECK(Context::GetCalling() == calling_context1);
14313 CHECK(Context::GetEntered() == calling_context2); 14211 CHECK(Context::GetEntered() == calling_context2);
14314 return v8::Integer::New(42); 14212 args.GetReturnValue().Set(42);
14315 } 14213 }
14316 14214
14317 14215
14216 THREADED_TEST(GetCurrentContextWhenNotInContext) {
14217 i::Isolate* isolate = i::Isolate::Current();
14218 CHECK(isolate != NULL);
14219 CHECK(isolate->context() == NULL);
14220 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
14221 v8::HandleScope scope(v8_isolate);
14222 // The following should not crash, but return an empty handle.
14223 v8::Local<v8::Context> current = v8_isolate->GetCurrentContext();
14224 CHECK(current.IsEmpty());
14225 }
14226
14227
14318 THREADED_TEST(GetCallingContext) { 14228 THREADED_TEST(GetCallingContext) {
14319 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 14229 v8::Isolate* isolate = v8::Isolate::GetCurrent();
14320 v8::HandleScope scope(isolate); 14230 v8::HandleScope scope(isolate);
14321 14231
14322 Local<Context> calling_context0(Context::New(isolate)); 14232 Local<Context> calling_context0(Context::New(isolate));
14323 Local<Context> calling_context1(Context::New(isolate)); 14233 Local<Context> calling_context1(Context::New(isolate));
14324 Local<Context> calling_context2(Context::New(isolate)); 14234 Local<Context> calling_context2(Context::New(isolate));
14325 ::calling_context0 = calling_context0; 14235 ::calling_context0 = calling_context0;
14326 ::calling_context1 = calling_context1; 14236 ::calling_context1 = calling_context1;
14327 ::calling_context2 = calling_context2; 14237 ::calling_context2 = calling_context2;
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
14810 v8::Handle<v8::Object> obj = v8::Object::New(); 14720 v8::Handle<v8::Object> obj = v8::Object::New();
14811 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 14721 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
14812 CHECK(obj->HasIndexedPropertiesInPixelData()); 14722 CHECK(obj->HasIndexedPropertiesInPixelData());
14813 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 14723 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
14814 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 14724 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
14815 free(pixel_data); 14725 free(pixel_data);
14816 } 14726 }
14817 } 14727 }
14818 14728
14819 14729
14820 static v8::Handle<Value> NotHandledIndexedPropertyGetter( 14730 static void NotHandledIndexedPropertyGetter(
14821 uint32_t index, 14731 uint32_t index,
14822 const AccessorInfo& info) { 14732 const v8::PropertyCallbackInfo<v8::Value>& info) {
14823 ApiTestFuzzer::Fuzz(); 14733 ApiTestFuzzer::Fuzz();
14824 return v8::Handle<Value>();
14825 } 14734 }
14826 14735
14827 14736
14828 static v8::Handle<Value> NotHandledIndexedPropertySetter( 14737 static void NotHandledIndexedPropertySetter(
14829 uint32_t index, 14738 uint32_t index,
14830 Local<Value> value, 14739 Local<Value> value,
14831 const AccessorInfo& info) { 14740 const v8::PropertyCallbackInfo<v8::Value>& info) {
14832 ApiTestFuzzer::Fuzz(); 14741 ApiTestFuzzer::Fuzz();
14833 return v8::Handle<Value>();
14834 } 14742 }
14835 14743
14836 14744
14837 THREADED_TEST(PixelArrayWithInterceptor) { 14745 THREADED_TEST(PixelArrayWithInterceptor) {
14838 LocalContext context; 14746 LocalContext context;
14839 i::Factory* factory = i::Isolate::Current()->factory(); 14747 i::Factory* factory = i::Isolate::Current()->factory();
14840 v8::HandleScope scope(context->GetIsolate()); 14748 v8::HandleScope scope(context->GetIsolate());
14841 const int kElementCount = 260; 14749 const int kElementCount = 260;
14842 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 14750 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
14843 i::Handle<i::ExternalPixelArray> pixels = 14751 i::Handle<i::ExternalPixelArray> pixels =
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
15554 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); 15462 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000);
15555 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); 15463 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff);
15556 } 15464 }
15557 15465
15558 15466
15559 template <typename ElementType, typename TypedArray, 15467 template <typename ElementType, typename TypedArray,
15560 class ExternalArrayClass> 15468 class ExternalArrayClass>
15561 void TypedArrayTestHelper(v8::ExternalArrayType array_type, 15469 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
15562 int64_t low, int64_t high) { 15470 int64_t low, int64_t high) {
15563 const int kElementCount = 50; 15471 const int kElementCount = 50;
15564 i::FLAG_harmony_array_buffer = true;
15565 i::FLAG_harmony_typed_arrays = true;
15566 15472
15567 i::ScopedVector<ElementType> backing_store(kElementCount+2); 15473 i::ScopedVector<ElementType> backing_store(kElementCount+2);
15568 15474
15569 LocalContext env; 15475 LocalContext env;
15570 v8::Isolate* isolate = env->GetIsolate(); 15476 v8::Isolate* isolate = env->GetIsolate();
15571 v8::HandleScope handle_scope(isolate); 15477 v8::HandleScope handle_scope(isolate);
15572 15478
15573 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( 15479 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
15574 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); 15480 backing_store.start(), (kElementCount+2)*sizeof(ElementType));
15575 Local<TypedArray> ta = 15481 Local<TypedArray> ta =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
15639 v8::kExternalDoubleArray, -500, 500); 15545 v8::kExternalDoubleArray, -500, 500);
15640 } 15546 }
15641 15547
15642 15548
15643 THREADED_TEST(Uint8ClampedArray) { 15549 THREADED_TEST(Uint8ClampedArray) {
15644 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, i::ExternalPixelArray>( 15550 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, i::ExternalPixelArray>(
15645 v8::kExternalPixelArray, 0, 0xFF); 15551 v8::kExternalPixelArray, 0, 0xFF);
15646 } 15552 }
15647 15553
15648 15554
15649 #define IS_TYPED_ARRAY_TEST(TypedArray) \ 15555 THREADED_TEST(DataView) {
15650 THREADED_TEST(Is##TypedArray) { \ 15556 const int kSize = 50;
15557
15558 i::ScopedVector<uint8_t> backing_store(kSize+2);
15559
15560 LocalContext env;
15561 v8::Isolate* isolate = env->GetIsolate();
15562 v8::HandleScope handle_scope(isolate);
15563
15564 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
15565 backing_store.start(), 2 + kSize);
15566 Local<v8::DataView> dv =
15567 v8::DataView::New(ab, 2, kSize);
15568 CHECK_EQ(2, static_cast<int>(dv->ByteOffset()));
15569 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
15570 CHECK_EQ(ab, dv->Buffer());
15571 }
15572
15573
15574 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
15575 THREADED_TEST(Is##View) { \
15651 i::FLAG_harmony_array_buffer = true; \ 15576 i::FLAG_harmony_array_buffer = true; \
15652 i::FLAG_harmony_typed_arrays = true; \ 15577 i::FLAG_harmony_typed_arrays = true; \
15653 LocalContext env; \ 15578 LocalContext env; \
15654 v8::Isolate* isolate = env->GetIsolate(); \ 15579 v8::Isolate* isolate = env->GetIsolate(); \
15655 v8::HandleScope handle_scope(isolate); \ 15580 v8::HandleScope handle_scope(isolate); \
15656 \ 15581 \
15657 Handle<Value> result = CompileRun( \ 15582 Handle<Value> result = CompileRun( \
15658 "var ab = new ArrayBuffer(128);" \ 15583 "var ab = new ArrayBuffer(128);" \
15659 "new " #TypedArray "(ab)"); \ 15584 "new " #View "(ab)"); \
15660 CHECK(result->Is##TypedArray()); \ 15585 CHECK(result->IsArrayBufferView()); \
15586 CHECK(result->Is##View()); \
15661 } 15587 }
15662 15588
15663 IS_TYPED_ARRAY_TEST(Uint8Array) 15589 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array)
15664 IS_TYPED_ARRAY_TEST(Int8Array) 15590 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array)
15665 IS_TYPED_ARRAY_TEST(Uint16Array) 15591 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array)
15666 IS_TYPED_ARRAY_TEST(Int16Array) 15592 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array)
15667 IS_TYPED_ARRAY_TEST(Uint32Array) 15593 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array)
15668 IS_TYPED_ARRAY_TEST(Int32Array) 15594 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array)
15669 IS_TYPED_ARRAY_TEST(Float32Array) 15595 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array)
15670 IS_TYPED_ARRAY_TEST(Float64Array) 15596 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array)
15671 IS_TYPED_ARRAY_TEST(Uint8ClampedArray) 15597 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray)
15598 IS_ARRAY_BUFFER_VIEW_TEST(DataView)
15672 15599
15673 #undef IS_TYPED_ARRAY_TEST 15600 #undef IS_ARRAY_BUFFER_VIEW_TEST
15674 15601
15675 15602
15676 15603
15677 THREADED_TEST(ScriptContextDependence) { 15604 THREADED_TEST(ScriptContextDependence) {
15678 LocalContext c1; 15605 LocalContext c1;
15679 v8::HandleScope scope(c1->GetIsolate()); 15606 v8::HandleScope scope(c1->GetIsolate());
15680 const char *source = "foo"; 15607 const char *source = "foo";
15681 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 15608 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
15682 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 15609 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
15683 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 15610 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
15719 CHECK(strstr(*script_name, expected_script_name) != NULL); 15646 CHECK(strstr(*script_name, expected_script_name) != NULL);
15720 } 15647 }
15721 CHECK(strstr(*func_name, expected_func_name) != NULL); 15648 CHECK(strstr(*func_name, expected_func_name) != NULL);
15722 CHECK_EQ(expected_line_number, frame->GetLineNumber()); 15649 CHECK_EQ(expected_line_number, frame->GetLineNumber());
15723 CHECK_EQ(expected_column, frame->GetColumn()); 15650 CHECK_EQ(expected_column, frame->GetColumn());
15724 CHECK_EQ(is_eval, frame->IsEval()); 15651 CHECK_EQ(is_eval, frame->IsEval());
15725 CHECK_EQ(is_constructor, frame->IsConstructor()); 15652 CHECK_EQ(is_constructor, frame->IsConstructor());
15726 } 15653 }
15727 15654
15728 15655
15729 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) { 15656 void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo<v8::Value>& args) {
15730 v8::HandleScope scope(args.GetIsolate()); 15657 v8::HandleScope scope(args.GetIsolate());
15731 const char* origin = "capture-stack-trace-test"; 15658 const char* origin = "capture-stack-trace-test";
15732 const int kOverviewTest = 1; 15659 const int kOverviewTest = 1;
15733 const int kDetailedTest = 2; 15660 const int kDetailedTest = 2;
15734 15661
15735 ASSERT(args.Length() == 1); 15662 ASSERT(args.Length() == 1);
15736 15663
15737 int testGroup = args[0]->Int32Value(); 15664 int testGroup = args[0]->Int32Value();
15738 if (testGroup == kOverviewTest) { 15665 if (testGroup == kOverviewTest) {
15739 v8::Handle<v8::StackTrace> stackTrace = 15666 v8::Handle<v8::StackTrace> stackTrace =
(...skipping 27 matching lines...) Expand all
15767 15694
15768 // This is the source string inside the eval which has the call to baz. 15695 // This is the source string inside the eval which has the call to baz.
15769 checkStackFrame(NULL, "", 1, 5, is_eval, false, 15696 checkStackFrame(NULL, "", 1, 5, is_eval, false,
15770 stackTrace->GetFrame(2)); 15697 stackTrace->GetFrame(2));
15771 // The last frame is an anonymous function which has the initial eval call. 15698 // The last frame is an anonymous function which has the initial eval call.
15772 checkStackFrame(origin, "", 10, 1, false, false, 15699 checkStackFrame(origin, "", 10, 1, false, false,
15773 stackTrace->GetFrame(3)); 15700 stackTrace->GetFrame(3));
15774 15701
15775 CHECK(stackTrace->AsArray()->IsArray()); 15702 CHECK(stackTrace->AsArray()->IsArray());
15776 } 15703 }
15777 return v8::Undefined();
15778 } 15704 }
15779 15705
15780 15706
15781 // Tests the C++ StackTrace API. 15707 // Tests the C++ StackTrace API.
15782 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 15708 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
15783 // THREADED_TEST(CaptureStackTrace) { 15709 // THREADED_TEST(CaptureStackTrace) {
15784 TEST(CaptureStackTrace) { 15710 TEST(CaptureStackTrace) {
15785 v8::HandleScope scope(v8::Isolate::GetCurrent()); 15711 v8::HandleScope scope(v8::Isolate::GetCurrent());
15786 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); 15712 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test");
15787 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15713 Local<ObjectTemplate> templ = ObjectTemplate::New();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
16006 "var e = {__proto__: new Error()} \n" 15932 "var e = {__proto__: new Error()} \n"
16007 "throw e; \n"; 15933 "throw e; \n";
16008 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler); 15934 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler);
16009 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 15935 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
16010 CompileRun(source); 15936 CompileRun(source);
16011 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 15937 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
16012 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 15938 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
16013 } 15939 }
16014 15940
16015 15941
16016 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { 15942 void AnalyzeStackOfEvalWithSourceURL(
15943 const v8::FunctionCallbackInfo<v8::Value>& args) {
16017 v8::HandleScope scope(args.GetIsolate()); 15944 v8::HandleScope scope(args.GetIsolate());
16018 v8::Handle<v8::StackTrace> stackTrace = 15945 v8::Handle<v8::StackTrace> stackTrace =
16019 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15946 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
16020 CHECK_EQ(5, stackTrace->GetFrameCount()); 15947 CHECK_EQ(5, stackTrace->GetFrameCount());
16021 v8::Handle<v8::String> url = v8_str("eval_url"); 15948 v8::Handle<v8::String> url = v8_str("eval_url");
16022 for (int i = 0; i < 3; i++) { 15949 for (int i = 0; i < 3; i++) {
16023 v8::Handle<v8::String> name = 15950 v8::Handle<v8::String> name =
16024 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15951 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16025 CHECK(!name.IsEmpty()); 15952 CHECK(!name.IsEmpty());
16026 CHECK_EQ(url, name); 15953 CHECK_EQ(url, name);
16027 } 15954 }
16028 return v8::Undefined();
16029 } 15955 }
16030 15956
16031 15957
16032 TEST(SourceURLInStackTrace) { 15958 TEST(SourceURLInStackTrace) {
16033 v8::HandleScope scope(v8::Isolate::GetCurrent()); 15959 v8::HandleScope scope(v8::Isolate::GetCurrent());
16034 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15960 Local<ObjectTemplate> templ = ObjectTemplate::New();
16035 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 15961 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
16036 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); 15962 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL));
16037 LocalContext context(0, templ); 15963 LocalContext context(0, templ);
16038 15964
(...skipping 11 matching lines...) Expand all
16050 "eval('(' + outer +')()%s');"; 15976 "eval('(' + outer +')()%s');";
16051 15977
16052 i::ScopedVector<char> code(1024); 15978 i::ScopedVector<char> code(1024);
16053 i::OS::SNPrintF(code, source, "//# sourceURL=eval_url"); 15979 i::OS::SNPrintF(code, source, "//# sourceURL=eval_url");
16054 CHECK(CompileRun(code.start())->IsUndefined()); 15980 CHECK(CompileRun(code.start())->IsUndefined());
16055 i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url"); 15981 i::OS::SNPrintF(code, source, "//@ sourceURL=eval_url");
16056 CHECK(CompileRun(code.start())->IsUndefined()); 15982 CHECK(CompileRun(code.start())->IsUndefined());
16057 } 15983 }
16058 15984
16059 15985
16060 v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL( 15986 void AnalyzeStackOfInlineScriptWithSourceURL(
16061 const v8::Arguments& args) { 15987 const v8::FunctionCallbackInfo<v8::Value>& args) {
16062 v8::HandleScope scope(args.GetIsolate()); 15988 v8::HandleScope scope(args.GetIsolate());
16063 v8::Handle<v8::StackTrace> stackTrace = 15989 v8::Handle<v8::StackTrace> stackTrace =
16064 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15990 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
16065 CHECK_EQ(4, stackTrace->GetFrameCount()); 15991 CHECK_EQ(4, stackTrace->GetFrameCount());
16066 v8::Handle<v8::String> url = v8_str("url"); 15992 v8::Handle<v8::String> url = v8_str("url");
16067 for (int i = 0; i < 3; i++) { 15993 for (int i = 0; i < 3; i++) {
16068 v8::Handle<v8::String> name = 15994 v8::Handle<v8::String> name =
16069 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15995 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16070 CHECK(!name.IsEmpty()); 15996 CHECK(!name.IsEmpty());
16071 CHECK_EQ(url, name); 15997 CHECK_EQ(url, name);
16072 } 15998 }
16073 return v8::Undefined();
16074 } 15999 }
16075 16000
16076 16001
16077 TEST(InlineScriptWithSourceURLInStackTrace) { 16002 TEST(InlineScriptWithSourceURLInStackTrace) {
16078 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16003 v8::HandleScope scope(v8::Isolate::GetCurrent());
16079 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16004 Local<ObjectTemplate> templ = ObjectTemplate::New();
16080 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 16005 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
16081 v8::FunctionTemplate::New( 16006 v8::FunctionTemplate::New(
16082 AnalyzeStackOfInlineScriptWithSourceURL)); 16007 AnalyzeStackOfInlineScriptWithSourceURL));
16083 LocalContext context(0, templ); 16008 LocalContext context(0, templ);
(...skipping 12 matching lines...) Expand all
16096 "outer()\n%s"; 16021 "outer()\n%s";
16097 16022
16098 i::ScopedVector<char> code(1024); 16023 i::ScopedVector<char> code(1024);
16099 i::OS::SNPrintF(code, source, "//# sourceURL=source_url"); 16024 i::OS::SNPrintF(code, source, "//# sourceURL=source_url");
16100 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16025 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
16101 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url"); 16026 i::OS::SNPrintF(code, source, "//@ sourceURL=source_url");
16102 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16027 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
16103 } 16028 }
16104 16029
16105 16030
16106 v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL( 16031 void AnalyzeStackOfDynamicScriptWithSourceURL(
16107 const v8::Arguments& args) { 16032 const v8::FunctionCallbackInfo<v8::Value>& args) {
16108 v8::HandleScope scope(args.GetIsolate()); 16033 v8::HandleScope scope(args.GetIsolate());
16109 v8::Handle<v8::StackTrace> stackTrace = 16034 v8::Handle<v8::StackTrace> stackTrace =
16110 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 16035 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
16111 CHECK_EQ(4, stackTrace->GetFrameCount()); 16036 CHECK_EQ(4, stackTrace->GetFrameCount());
16112 v8::Handle<v8::String> url = v8_str("source_url"); 16037 v8::Handle<v8::String> url = v8_str("source_url");
16113 for (int i = 0; i < 3; i++) { 16038 for (int i = 0; i < 3; i++) {
16114 v8::Handle<v8::String> name = 16039 v8::Handle<v8::String> name =
16115 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16040 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16116 CHECK(!name.IsEmpty()); 16041 CHECK(!name.IsEmpty());
16117 CHECK_EQ(url, name); 16042 CHECK_EQ(url, name);
16118 } 16043 }
16119 return v8::Undefined();
16120 } 16044 }
16121 16045
16122 16046
16123 TEST(DynamicWithSourceURLInStackTrace) { 16047 TEST(DynamicWithSourceURLInStackTrace) {
16124 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16048 v8::HandleScope scope(v8::Isolate::GetCurrent());
16125 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16049 Local<ObjectTemplate> templ = ObjectTemplate::New();
16126 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 16050 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
16127 v8::FunctionTemplate::New( 16051 v8::FunctionTemplate::New(
16128 AnalyzeStackOfDynamicScriptWithSourceURL)); 16052 AnalyzeStackOfDynamicScriptWithSourceURL));
16129 LocalContext context(0, templ); 16053 LocalContext context(0, templ);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
16245 bool finished = false; 16169 bool finished = false;
16246 for (int i = 0; i < 200 && !finished; i++) { 16170 for (int i = 0; i < 200 && !finished; i++) {
16247 finished = v8::V8::IdleNotification(kShortIdlePauseInMs); 16171 finished = v8::V8::IdleNotification(kShortIdlePauseInMs);
16248 } 16172 }
16249 intptr_t final_size = HEAP->SizeOfObjects(); 16173 intptr_t final_size = HEAP->SizeOfObjects();
16250 CHECK_LT(final_size, initial_size + 1); 16174 CHECK_LT(final_size, initial_size + 1);
16251 } 16175 }
16252 16176
16253 static uint32_t* stack_limit; 16177 static uint32_t* stack_limit;
16254 16178
16255 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) { 16179 static void GetStackLimitCallback(
16180 const v8::FunctionCallbackInfo<v8::Value>& args) {
16256 stack_limit = reinterpret_cast<uint32_t*>( 16181 stack_limit = reinterpret_cast<uint32_t*>(
16257 i::Isolate::Current()->stack_guard()->real_climit()); 16182 i::Isolate::Current()->stack_guard()->real_climit());
16258 return v8::Undefined();
16259 } 16183 }
16260 16184
16261 16185
16262 // Uses the address of a local variable to determine the stack top now. 16186 // Uses the address of a local variable to determine the stack top now.
16263 // Given a size, returns an address that is that far from the current 16187 // Given a size, returns an address that is that far from the current
16264 // top of stack. 16188 // top of stack.
16265 static uint32_t* ComputeStackLimit(uint32_t size) { 16189 static uint32_t* ComputeStackLimit(uint32_t size) {
16266 uint32_t* answer = &size - (size / sizeof(size)); 16190 uint32_t* answer = &size - (size / sizeof(size));
16267 // If the size is very large and the stack is very near the bottom of 16191 // If the size is very large and the stack is very near the bottom of
16268 // memory then the calculation above may wrap around and give an address 16192 // memory then the calculation above may wrap around and give an address
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
16517 // on MIPS architecture. Allowed by IEEE-754. 16441 // on MIPS architecture. Allowed by IEEE-754.
16518 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 16442 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
16519 #else 16443 #else
16520 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 16444 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
16521 #endif 16445 #endif
16522 } 16446 }
16523 } 16447 }
16524 } 16448 }
16525 16449
16526 16450
16527 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) { 16451 static void SpaghettiIncident(
16452 const v8::FunctionCallbackInfo<v8::Value>& args) {
16528 v8::HandleScope scope(args.GetIsolate()); 16453 v8::HandleScope scope(args.GetIsolate());
16529 v8::TryCatch tc; 16454 v8::TryCatch tc;
16530 v8::Handle<v8::String> str(args[0]->ToString()); 16455 v8::Handle<v8::String> str(args[0]->ToString());
16531 USE(str); 16456 USE(str);
16532 if (tc.HasCaught()) 16457 if (tc.HasCaught())
16533 return tc.ReThrow(); 16458 tc.ReThrow();
16534 return v8::Undefined();
16535 } 16459 }
16536 16460
16537 16461
16538 // Test that an exception can be propagated down through a spaghetti 16462 // Test that an exception can be propagated down through a spaghetti
16539 // stack using ReThrow. 16463 // stack using ReThrow.
16540 THREADED_TEST(SpaghettiStackReThrow) { 16464 THREADED_TEST(SpaghettiStackReThrow) {
16541 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16465 v8::HandleScope scope(v8::Isolate::GetCurrent());
16542 LocalContext context; 16466 LocalContext context;
16543 context->Global()->Set( 16467 context->Global()->Set(
16544 v8::String::New("s"), 16468 v8::String::New("s"),
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
16728 script->Run(); 16652 script->Run();
16729 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 16653 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
16730 env->Global()->Get(v8::String::New("foo"))); 16654 env->Global()->Get(v8::String::New("foo")));
16731 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 16655 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
16732 env->Global()->Get(v8::String::New("bar"))); 16656 env->Global()->Get(v8::String::New("bar")));
16733 CHECK_EQ(script->Id(), foo->GetScriptId()); 16657 CHECK_EQ(script->Id(), foo->GetScriptId());
16734 CHECK_EQ(script->Id(), bar->GetScriptId()); 16658 CHECK_EQ(script->Id(), bar->GetScriptId());
16735 } 16659 }
16736 16660
16737 16661
16738 static v8::Handle<Value> GetterWhichReturns42(Local<String> name, 16662 static void GetterWhichReturns42(
16739 const AccessorInfo& info) { 16663 Local<String> name,
16664 const v8::PropertyCallbackInfo<v8::Value>& info) {
16740 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 16665 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
16741 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 16666 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
16742 return v8_num(42); 16667 info.GetReturnValue().Set(v8_num(42));
16743 } 16668 }
16744 16669
16745 16670
16746 static void SetterWhichSetsYOnThisTo23(Local<String> name, 16671 static void SetterWhichSetsYOnThisTo23(
16747 Local<Value> value, 16672 Local<String> name,
16748 const AccessorInfo& info) { 16673 Local<Value> value,
16674 const v8::PropertyCallbackInfo<void>& info) {
16749 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 16675 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
16750 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 16676 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
16751 info.This()->Set(v8_str("y"), v8_num(23)); 16677 info.This()->Set(v8_str("y"), v8_num(23));
16752 } 16678 }
16753 16679
16754 16680
16755 Handle<Value> FooGetInterceptor(Local<String> name, 16681 void FooGetInterceptor(Local<String> name,
16756 const AccessorInfo& info) { 16682 const v8::PropertyCallbackInfo<v8::Value>& info) {
16757 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 16683 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
16758 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 16684 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
16759 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); 16685 if (!name->Equals(v8_str("foo"))) return;
16760 return v8_num(42); 16686 info.GetReturnValue().Set(v8_num(42));
16761 } 16687 }
16762 16688
16763 16689
16764 Handle<Value> FooSetInterceptor(Local<String> name, 16690 void FooSetInterceptor(Local<String> name,
16765 Local<Value> value, 16691 Local<Value> value,
16766 const AccessorInfo& info) { 16692 const v8::PropertyCallbackInfo<v8::Value>& info) {
16767 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 16693 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
16768 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 16694 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
16769 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); 16695 if (!name->Equals(v8_str("foo"))) return;
16770 info.This()->Set(v8_str("y"), v8_num(23)); 16696 info.This()->Set(v8_str("y"), v8_num(23));
16771 return v8_num(23); 16697 info.GetReturnValue().Set(v8_num(23));
16772 } 16698 }
16773 16699
16774 16700
16775 TEST(SetterOnConstructorPrototype) { 16701 TEST(SetterOnConstructorPrototype) {
16776 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16702 v8::HandleScope scope(v8::Isolate::GetCurrent());
16777 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16703 Local<ObjectTemplate> templ = ObjectTemplate::New();
16778 templ->SetAccessor(v8_str("x"), 16704 templ->SetAccessor(v8_str("x"),
16779 GetterWhichReturns42, 16705 GetterWhichReturns42,
16780 SetterWhichSetsYOnThisTo23); 16706 SetterWhichSetsYOnThisTo23);
16781 LocalContext context; 16707 LocalContext context;
(...skipping 18 matching lines...) Expand all
16800 16726
16801 script = v8::Script::Compile(v8_str("new C2();")); 16727 script = v8::Script::Compile(v8_str("new C2();"));
16802 for (int i = 0; i < 10; i++) { 16728 for (int i = 0; i < 10; i++) {
16803 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 16729 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run());
16804 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); 16730 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value());
16805 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); 16731 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value());
16806 } 16732 }
16807 } 16733 }
16808 16734
16809 16735
16810 static v8::Handle<Value> NamedPropertyGetterWhichReturns42( 16736 static void NamedPropertyGetterWhichReturns42(
16811 Local<String> name, const AccessorInfo& info) { 16737 Local<String> name,
16812 return v8_num(42); 16738 const v8::PropertyCallbackInfo<v8::Value>& info) {
16739 info.GetReturnValue().Set(v8_num(42));
16813 } 16740 }
16814 16741
16815 16742
16816 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23( 16743 static void NamedPropertySetterWhichSetsYOnThisTo23(
16817 Local<String> name, Local<Value> value, const AccessorInfo& info) { 16744 Local<String> name,
16745 Local<Value> value,
16746 const v8::PropertyCallbackInfo<v8::Value>& info) {
16818 if (name->Equals(v8_str("x"))) { 16747 if (name->Equals(v8_str("x"))) {
16819 info.This()->Set(v8_str("y"), v8_num(23)); 16748 info.This()->Set(v8_str("y"), v8_num(23));
16820 } 16749 }
16821 return v8::Handle<Value>();
16822 } 16750 }
16823 16751
16824 16752
16825 THREADED_TEST(InterceptorOnConstructorPrototype) { 16753 THREADED_TEST(InterceptorOnConstructorPrototype) {
16826 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16754 v8::HandleScope scope(v8::Isolate::GetCurrent());
16827 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16755 Local<ObjectTemplate> templ = ObjectTemplate::New();
16828 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, 16756 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
16829 NamedPropertySetterWhichSetsYOnThisTo23); 16757 NamedPropertySetterWhichSetsYOnThisTo23);
16830 LocalContext context; 16758 LocalContext context;
16831 context->Global()->Set(v8_str("P"), templ->NewInstance()); 16759 context->Global()->Set(v8_str("P"), templ->NewInstance());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
16950 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); 16878 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond);
16951 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16879 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16952 CHECK_EQ(2, prologue_call_count); 16880 CHECK_EQ(2, prologue_call_count);
16953 CHECK_EQ(2, epilogue_call_count); 16881 CHECK_EQ(2, epilogue_call_count);
16954 CHECK_EQ(2, prologue_call_count_second); 16882 CHECK_EQ(2, prologue_call_count_second);
16955 CHECK_EQ(2, epilogue_call_count_second); 16883 CHECK_EQ(2, epilogue_call_count_second);
16956 } 16884 }
16957 16885
16958 16886
16959 THREADED_TEST(AddToJSFunctionResultCache) { 16887 THREADED_TEST(AddToJSFunctionResultCache) {
16888 i::FLAG_stress_compaction = false;
16960 i::FLAG_allow_natives_syntax = true; 16889 i::FLAG_allow_natives_syntax = true;
16961 v8::HandleScope scope(v8::Isolate::GetCurrent()); 16890 v8::HandleScope scope(v8::Isolate::GetCurrent());
16962 16891
16963 LocalContext context; 16892 LocalContext context;
16964 16893
16965 const char* code = 16894 const char* code =
16966 "(function() {" 16895 "(function() {"
16967 " var key0 = 'a';" 16896 " var key0 = 'a';"
16968 " var key1 = 'b';" 16897 " var key1 = 'b';"
16969 " var r0 = %_GetFromCache(0, key0);" 16898 " var r0 = %_GetFromCache(0, key0);"
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
18051 CHECK(!globalProxy->StrictEquals(global)); 17980 CHECK(!globalProxy->StrictEquals(global));
18052 CHECK(globalProxy->StrictEquals(globalProxy)); 17981 CHECK(globalProxy->StrictEquals(globalProxy));
18053 17982
18054 CHECK(global->Equals(global)); 17983 CHECK(global->Equals(global));
18055 CHECK(!global->Equals(globalProxy)); 17984 CHECK(!global->Equals(globalProxy));
18056 CHECK(!globalProxy->Equals(global)); 17985 CHECK(!globalProxy->Equals(global));
18057 CHECK(globalProxy->Equals(globalProxy)); 17986 CHECK(globalProxy->Equals(globalProxy));
18058 } 17987 }
18059 17988
18060 17989
18061 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, 17990 static void Getter(v8::Local<v8::String> property,
18062 const v8::AccessorInfo& info ) { 17991 const v8::PropertyCallbackInfo<v8::Value>& info ) {
18063 return v8_str("42!"); 17992 info.GetReturnValue().Set(v8_str("42!"));
18064 } 17993 }
18065 17994
18066 17995
18067 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { 17996 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
18068 v8::Handle<v8::Array> result = v8::Array::New(); 17997 v8::Handle<v8::Array> result = v8::Array::New();
18069 result->Set(0, v8_str("universalAnswer")); 17998 result->Set(0, v8_str("universalAnswer"));
18070 return result; 17999 info.GetReturnValue().Set(result);
18071 } 18000 }
18072 18001
18073 18002
18074 TEST(NamedEnumeratorAndForIn) { 18003 TEST(NamedEnumeratorAndForIn) {
18075 LocalContext context; 18004 LocalContext context;
18076 v8::HandleScope handle_scope(context->GetIsolate()); 18005 v8::HandleScope handle_scope(context->GetIsolate());
18077 v8::Context::Scope context_scope(context.local()); 18006 v8::Context::Scope context_scope(context.local());
18078 18007
18079 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 18008 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
18080 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 18009 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
18206 { 18135 {
18207 Context::Scope scope(context); 18136 Context::Scope scope(context);
18208 function = CompileRun("function foo() {}; foo").As<Object>(); 18137 function = CompileRun("function foo() {}; foo").As<Object>();
18209 } 18138 }
18210 18139
18211 CHECK(function->CreationContext() == context); 18140 CHECK(function->CreationContext() == context);
18212 CheckContextId(function, 1); 18141 CheckContextId(function, 1);
18213 } 18142 }
18214 18143
18215 18144
18216 Handle<Value> HasOwnPropertyIndexedPropertyGetter(uint32_t index, 18145 void HasOwnPropertyIndexedPropertyGetter(
18217 const AccessorInfo& info) { 18146 uint32_t index,
18218 if (index == 42) return v8_str("yes"); 18147 const v8::PropertyCallbackInfo<v8::Value>& info) {
18219 return Handle<v8::Integer>(); 18148 if (index == 42) info.GetReturnValue().Set(v8_str("yes"));
18220 } 18149 }
18221 18150
18222 18151
18223 Handle<Value> HasOwnPropertyNamedPropertyGetter(Local<String> property, 18152 void HasOwnPropertyNamedPropertyGetter(
18224 const AccessorInfo& info) { 18153 Local<String> property,
18225 if (property->Equals(v8_str("foo"))) return v8_str("yes"); 18154 const v8::PropertyCallbackInfo<v8::Value>& info) {
18226 return Handle<Value>(); 18155 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(v8_str("yes"));
18227 } 18156 }
18228 18157
18229 18158
18230 Handle<v8::Integer> HasOwnPropertyIndexedPropertyQuery( 18159 void HasOwnPropertyIndexedPropertyQuery(
18231 uint32_t index, const AccessorInfo& info) { 18160 uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) {
18232 if (index == 42) return v8_num(1).As<v8::Integer>(); 18161 if (index == 42) info.GetReturnValue().Set(1);
18233 return Handle<v8::Integer>();
18234 } 18162 }
18235 18163
18236 18164
18237 Handle<v8::Integer> HasOwnPropertyNamedPropertyQuery( 18165 void HasOwnPropertyNamedPropertyQuery(
18238 Local<String> property, const AccessorInfo& info) { 18166 Local<String> property,
18239 if (property->Equals(v8_str("foo"))) return v8_num(1).As<v8::Integer>(); 18167 const v8::PropertyCallbackInfo<v8::Integer>& info) {
18240 return Handle<v8::Integer>(); 18168 if (property->Equals(v8_str("foo"))) info.GetReturnValue().Set(1);
18241 } 18169 }
18242 18170
18243 18171
18244 Handle<v8::Integer> HasOwnPropertyNamedPropertyQuery2( 18172 void HasOwnPropertyNamedPropertyQuery2(
18245 Local<String> property, const AccessorInfo& info) { 18173 Local<String> property,
18246 if (property->Equals(v8_str("bar"))) return v8_num(1).As<v8::Integer>(); 18174 const v8::PropertyCallbackInfo<v8::Integer>& info) {
18247 return Handle<v8::Integer>(); 18175 if (property->Equals(v8_str("bar"))) info.GetReturnValue().Set(1);
18248 } 18176 }
18249 18177
18250 18178
18251 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property, 18179 void HasOwnPropertyAccessorGetter(
18252 const AccessorInfo& info) { 18180 Local<String> property,
18253 return v8_str("yes"); 18181 const v8::PropertyCallbackInfo<v8::Value>& info) {
18182 info.GetReturnValue().Set(v8_str("yes"));
18254 } 18183 }
18255 18184
18256 18185
18257 TEST(HasOwnProperty) { 18186 TEST(HasOwnProperty) {
18258 LocalContext env; 18187 LocalContext env;
18259 v8::HandleScope scope(env->GetIsolate()); 18188 v8::HandleScope scope(env->GetIsolate());
18260 { // Check normal properties and defined getters. 18189 { // Check normal properties and defined getters.
18261 Handle<Value> value = CompileRun( 18190 Handle<Value> value = CompileRun(
18262 "function Foo() {" 18191 "function Foo() {"
18263 " this.foo = 11;" 18192 " this.foo = 11;"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
18430 context->AllowCodeGenerationFromStrings(false); 18359 context->AllowCodeGenerationFromStrings(false);
18431 context->SetErrorMessageForCodeGenerationFromStrings(message); 18360 context->SetErrorMessageForCodeGenerationFromStrings(message);
18432 Handle<Value> result = CompileRun("eval('42')"); 18361 Handle<Value> result = CompileRun("eval('42')");
18433 CHECK(result.IsEmpty()); 18362 CHECK(result.IsEmpty());
18434 CHECK(try_catch.HasCaught()); 18363 CHECK(try_catch.HasCaught());
18435 Handle<String> actual_message = try_catch.Message()->Get(); 18364 Handle<String> actual_message = try_catch.Message()->Get();
18436 CHECK(expected_message->Equals(actual_message)); 18365 CHECK(expected_message->Equals(actual_message));
18437 } 18366 }
18438 18367
18439 18368
18440 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) { 18369 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
18441 return v8::Undefined();
18442 } 18370 }
18443 18371
18444 18372
18445 THREADED_TEST(CallAPIFunctionOnNonObject) { 18373 THREADED_TEST(CallAPIFunctionOnNonObject) {
18446 LocalContext context; 18374 LocalContext context;
18447 v8::HandleScope scope(context->GetIsolate()); 18375 v8::HandleScope scope(context->GetIsolate());
18448 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 18376 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
18449 Handle<Function> function = templ->GetFunction(); 18377 Handle<Function> function = templ->GetFunction();
18450 context->Global()->Set(v8_str("f"), function); 18378 context->Global()->Set(v8_str("f"), function);
18451 TryCatch try_catch; 18379 TryCatch try_catch;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
18744 callback_fired ^= 1; // Toggle first bit. 18672 callback_fired ^= 1; // Toggle first bit.
18745 } 18673 }
18746 18674
18747 18675
18748 void CallCompletedCallback2() { 18676 void CallCompletedCallback2() {
18749 i::OS::Print("Firing callback 2.\n"); 18677 i::OS::Print("Firing callback 2.\n");
18750 callback_fired ^= 2; // Toggle second bit. 18678 callback_fired ^= 2; // Toggle second bit.
18751 } 18679 }
18752 18680
18753 18681
18754 Handle<Value> RecursiveCall(const Arguments& args) { 18682 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
18755 int32_t level = args[0]->Int32Value(); 18683 int32_t level = args[0]->Int32Value();
18756 if (level < 3) { 18684 if (level < 3) {
18757 level++; 18685 level++;
18758 i::OS::Print("Entering recursion level %d.\n", level); 18686 i::OS::Print("Entering recursion level %d.\n", level);
18759 char script[64]; 18687 char script[64];
18760 i::Vector<char> script_vector(script, sizeof(script)); 18688 i::Vector<char> script_vector(script, sizeof(script));
18761 i::OS::SNPrintF(script_vector, "recursion(%d)", level); 18689 i::OS::SNPrintF(script_vector, "recursion(%d)", level);
18762 CompileRun(script_vector.start()); 18690 CompileRun(script_vector.start());
18763 i::OS::Print("Leaving recursion level %d.\n", level); 18691 i::OS::Print("Leaving recursion level %d.\n", level);
18764 CHECK_EQ(0, callback_fired); 18692 CHECK_EQ(0, callback_fired);
18765 } else { 18693 } else {
18766 i::OS::Print("Recursion ends.\n"); 18694 i::OS::Print("Recursion ends.\n");
18767 CHECK_EQ(0, callback_fired); 18695 CHECK_EQ(0, callback_fired);
18768 } 18696 }
18769 return Undefined();
18770 } 18697 }
18771 18698
18772 18699
18773 TEST(CallCompletedCallback) { 18700 TEST(CallCompletedCallback) {
18774 LocalContext env; 18701 LocalContext env;
18775 v8::HandleScope scope(env->GetIsolate()); 18702 v8::HandleScope scope(env->GetIsolate());
18776 v8::Handle<v8::FunctionTemplate> recursive_runtime = 18703 v8::Handle<v8::FunctionTemplate> recursive_runtime =
18777 v8::FunctionTemplate::New(RecursiveCall); 18704 v8::FunctionTemplate::New(RecursiveCall);
18778 env->Global()->Set(v8_str("recursion"), 18705 env->Global()->Set(v8_str("recursion"),
18779 recursive_runtime->GetFunction()); 18706 recursive_runtime->GetFunction());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
18892 TEST(SecondaryStubCache) { 18819 TEST(SecondaryStubCache) {
18893 StubCacheHelper(true); 18820 StubCacheHelper(true);
18894 } 18821 }
18895 18822
18896 18823
18897 TEST(PrimaryStubCache) { 18824 TEST(PrimaryStubCache) {
18898 StubCacheHelper(false); 18825 StubCacheHelper(false);
18899 } 18826 }
18900 18827
18901 18828
18902 static int fatal_error_callback_counter = 0;
18903 static void CountingErrorCallback(const char* location, const char* message) {
18904 printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
18905 fatal_error_callback_counter++;
18906 }
18907
18908
18909 TEST(StaticGetters) { 18829 TEST(StaticGetters) {
18910 LocalContext context; 18830 LocalContext context;
18911 i::Factory* factory = i::Isolate::Current()->factory(); 18831 i::Factory* factory = i::Isolate::Current()->factory();
18912 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18832 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18913 v8::HandleScope scope(isolate); 18833 v8::HandleScope scope(isolate);
18914 i::Handle<i::Object> undefined_value = factory->undefined_value(); 18834 i::Handle<i::Object> undefined_value = factory->undefined_value();
18915 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value); 18835 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value);
18916 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value); 18836 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value);
18917 i::Handle<i::Object> null_value = factory->null_value(); 18837 i::Handle<i::Object> null_value = factory->null_value();
18918 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value); 18838 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value);
18919 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value); 18839 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
18920 i::Handle<i::Object> true_value = factory->true_value(); 18840 i::Handle<i::Object> true_value = factory->true_value();
18921 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); 18841 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
18922 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); 18842 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
18923 i::Handle<i::Object> false_value = factory->false_value(); 18843 i::Handle<i::Object> false_value = factory->false_value();
18924 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value); 18844 CHECK(*v8::Utils::OpenHandle(*v8::False()) == *false_value);
18925 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value); 18845 CHECK(*v8::Utils::OpenHandle(*v8::False(isolate)) == *false_value);
18926
18927 // Test after-death behavior.
18928 CHECK(i::Internals::IsInitialized(isolate));
18929 CHECK_EQ(0, fatal_error_callback_counter);
18930 v8::V8::SetFatalErrorHandler(CountingErrorCallback);
18931 v8::Utils::ReportApiFailure("StaticGetters()", "Kill V8");
18932 i::Isolate::Current()->TearDown();
18933 CHECK(!i::Internals::IsInitialized(isolate));
18934 CHECK_EQ(1, fatal_error_callback_counter);
18935 CHECK(v8::Undefined().IsEmpty());
18936 CHECK_EQ(2, fatal_error_callback_counter);
18937 CHECK(v8::Undefined(isolate).IsEmpty());
18938 CHECK_EQ(3, fatal_error_callback_counter);
18939 CHECK(v8::Null().IsEmpty());
18940 CHECK_EQ(4, fatal_error_callback_counter);
18941 CHECK(v8::Null(isolate).IsEmpty());
18942 CHECK_EQ(5, fatal_error_callback_counter);
18943 CHECK(v8::True().IsEmpty());
18944 CHECK_EQ(6, fatal_error_callback_counter);
18945 CHECK(v8::True(isolate).IsEmpty());
18946 CHECK_EQ(7, fatal_error_callback_counter);
18947 CHECK(v8::False().IsEmpty());
18948 CHECK_EQ(8, fatal_error_callback_counter);
18949 CHECK(v8::False(isolate).IsEmpty());
18950 CHECK_EQ(9, fatal_error_callback_counter);
18951 } 18846 }
18952 18847
18953 18848
18954 TEST(IsolateEmbedderData) { 18849 TEST(IsolateEmbedderData) {
18955 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18850 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18956 CHECK_EQ(NULL, isolate->GetData()); 18851 CHECK_EQ(NULL, isolate->GetData());
18957 CHECK_EQ(NULL, ISOLATE->GetData()); 18852 CHECK_EQ(NULL, ISOLATE->GetData());
18958 static void* data1 = reinterpret_cast<void*>(0xacce55ed); 18853 static void* data1 = reinterpret_cast<void*>(0xacce55ed);
18959 isolate->SetData(data1); 18854 isolate->SetData(data1);
18960 CHECK_EQ(data1, isolate->GetData()); 18855 CHECK_EQ(data1, isolate->GetData());
18961 CHECK_EQ(data1, ISOLATE->GetData()); 18856 CHECK_EQ(data1, ISOLATE->GetData());
18962 static void* data2 = reinterpret_cast<void*>(0xdecea5ed); 18857 static void* data2 = reinterpret_cast<void*>(0xdecea5ed);
18963 ISOLATE->SetData(data2); 18858 ISOLATE->SetData(data2);
18964 CHECK_EQ(data2, isolate->GetData()); 18859 CHECK_EQ(data2, isolate->GetData());
18965 CHECK_EQ(data2, ISOLATE->GetData()); 18860 CHECK_EQ(data2, ISOLATE->GetData());
18966 ISOLATE->TearDown(); 18861 ISOLATE->TearDown();
18967 CHECK_EQ(data2, isolate->GetData()); 18862 CHECK_EQ(data2, isolate->GetData());
18968 CHECK_EQ(data2, ISOLATE->GetData()); 18863 CHECK_EQ(data2, ISOLATE->GetData());
18969 } 18864 }
18970 18865
18971 18866
18972 TEST(StringEmpty) { 18867 TEST(StringEmpty) {
18973 LocalContext context; 18868 LocalContext context;
18974 i::Factory* factory = i::Isolate::Current()->factory(); 18869 i::Factory* factory = i::Isolate::Current()->factory();
18975 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 18870 v8::Isolate* isolate = v8::Isolate::GetCurrent();
18976 v8::HandleScope scope(isolate); 18871 v8::HandleScope scope(isolate);
18977 i::Handle<i::Object> empty_string = factory->empty_string(); 18872 i::Handle<i::Object> empty_string = factory->empty_string();
18978 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); 18873 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
18979 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 18874 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
18980
18981 // Test after-death behavior.
18982 CHECK(i::Internals::IsInitialized(isolate));
18983 CHECK_EQ(0, fatal_error_callback_counter);
18984 v8::V8::SetFatalErrorHandler(CountingErrorCallback);
18985 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8");
18986 i::Isolate::Current()->TearDown();
18987 CHECK(!i::Internals::IsInitialized(isolate));
18988 CHECK_EQ(1, fatal_error_callback_counter);
18989 CHECK(v8::String::Empty().IsEmpty());
18990 CHECK_EQ(2, fatal_error_callback_counter);
18991 CHECK(v8::String::Empty(isolate).IsEmpty());
18992 CHECK_EQ(3, fatal_error_callback_counter);
18993 } 18875 }
18994 18876
18995 18877
18996 static int instance_checked_getter_count = 0; 18878 static int instance_checked_getter_count = 0;
18997 static Handle<Value> InstanceCheckedGetter(Local<String> name, 18879 static void InstanceCheckedGetter(
18998 const AccessorInfo& info) { 18880 Local<String> name,
18881 const v8::PropertyCallbackInfo<v8::Value>& info) {
18999 CHECK_EQ(name, v8_str("foo")); 18882 CHECK_EQ(name, v8_str("foo"));
19000 instance_checked_getter_count++; 18883 instance_checked_getter_count++;
19001 return v8_num(11); 18884 info.GetReturnValue().Set(v8_num(11));
19002 } 18885 }
19003 18886
19004 18887
19005 static int instance_checked_setter_count = 0; 18888 static int instance_checked_setter_count = 0;
19006 static void InstanceCheckedSetter(Local<String> name, 18889 static void InstanceCheckedSetter(Local<String> name,
19007 Local<Value> value, 18890 Local<Value> value,
19008 const AccessorInfo& info) { 18891 const v8::PropertyCallbackInfo<void>& info) {
19009 CHECK_EQ(name, v8_str("foo")); 18892 CHECK_EQ(name, v8_str("foo"));
19010 CHECK_EQ(value, v8_num(23)); 18893 CHECK_EQ(value, v8_num(23));
19011 instance_checked_setter_count++; 18894 instance_checked_setter_count++;
19012 } 18895 }
19013 18896
19014 18897
19015 static void CheckInstanceCheckedResult(int getters, 18898 static void CheckInstanceCheckedResult(int getters,
19016 int setters, 18899 int setters,
19017 bool expects_callbacks, 18900 bool expects_callbacks,
19018 TryCatch* try_catch) { 18901 TryCatch* try_catch) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
19390 v8::HandleScope scope(context->GetIsolate()); 19273 v8::HandleScope scope(context->GetIsolate());
19391 Local<Value> set_value = CompileRun("new Set();"); 19274 Local<Value> set_value = CompileRun("new Set();");
19392 Local<Object> set_object(Local<Object>::Cast(set_value)); 19275 Local<Object> set_object(Local<Object>::Cast(set_value));
19393 CHECK_EQ(0, set_object->InternalFieldCount()); 19276 CHECK_EQ(0, set_object->InternalFieldCount());
19394 Local<Value> map_value = CompileRun("new Map();"); 19277 Local<Value> map_value = CompileRun("new Map();");
19395 Local<Object> map_object(Local<Object>::Cast(map_value)); 19278 Local<Object> map_object(Local<Object>::Cast(map_value));
19396 CHECK_EQ(0, map_object->InternalFieldCount()); 19279 CHECK_EQ(0, map_object->InternalFieldCount());
19397 } 19280 }
19398 19281
19399 19282
19283 THREADED_TEST(Regress2746) {
19284 LocalContext context;
19285 v8::HandleScope scope(context->GetIsolate());
19286 Local<Object> obj = Object::New();
19287 Local<String> key = String::New("key");
19288 obj->SetHiddenValue(key, v8::Undefined());
19289 Local<Value> value = obj->GetHiddenValue(key);
19290 CHECK(!value.IsEmpty());
19291 CHECK(value->IsUndefined());
19292 }
19293
19294
19400 #ifndef WIN32 19295 #ifndef WIN32
19401 class ThreadInterruptTest { 19296 class ThreadInterruptTest {
19402 public: 19297 public:
19403 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } 19298 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { }
19404 ~ThreadInterruptTest() { delete sem_; } 19299 ~ThreadInterruptTest() { delete sem_; }
19405 19300
19406 void RunTest() { 19301 void RunTest() {
19407 sem_ = i::OS::CreateSemaphore(0); 19302 sem_ = i::OS::CreateSemaphore(0);
19408 19303
19409 InterruptThread i_thread(this); 19304 InterruptThread i_thread(this);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
19453 i::Semaphore* sem_; 19348 i::Semaphore* sem_;
19454 volatile int sem_value_; 19349 volatile int sem_value_;
19455 }; 19350 };
19456 19351
19457 19352
19458 THREADED_TEST(SemaphoreInterruption) { 19353 THREADED_TEST(SemaphoreInterruption) {
19459 ThreadInterruptTest().RunTest(); 19354 ThreadInterruptTest().RunTest();
19460 } 19355 }
19461 19356
19462 #endif // WIN32 19357 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698