| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 void RunWithProfiler(void (*test)()) { | 88 void RunWithProfiler(void (*test)()) { |
| 89 LocalContext env; | 89 LocalContext env; |
| 90 v8::HandleScope scope(env->GetIsolate()); | 90 v8::HandleScope scope(env->GetIsolate()); |
| 91 v8::Local<v8::String> profile_name = | 91 v8::Local<v8::String> profile_name = |
| 92 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile1"); | 92 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile1"); |
| 93 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 93 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 94 | 94 |
| 95 cpu_profiler->StartCpuProfiling(profile_name); | 95 cpu_profiler->StartCpuProfiling(profile_name); |
| 96 (*test)(); | 96 (*test)(); |
| 97 cpu_profiler->DeleteAllCpuProfiles(); | 97 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 static void ExpectString(const char* code, const char* expected) { | 101 static void ExpectString(const char* code, const char* expected) { |
| 102 Local<Value> result = CompileRun(code); | 102 Local<Value> result = CompileRun(code); |
| 103 CHECK(result->IsString()); | 103 CHECK(result->IsString()); |
| 104 String::Utf8Value utf8(result); | 104 String::Utf8Value utf8(result); |
| 105 CHECK_EQ(expected, *utf8); | 105 CHECK_EQ(expected, *utf8); |
| 106 } | 106 } |
| 107 | 107 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 CHECK_EQ(10, signature_callback_count); | 245 CHECK_EQ(10, signature_callback_count); |
| 246 } else { | 246 } else { |
| 247 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 247 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
| 248 try_catch.Exception()->ToString()); | 248 try_catch.Exception()->ToString()); |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 THREADED_TEST(ReceiverSignature) { | 253 THREADED_TEST(ReceiverSignature) { |
| 254 LocalContext env; | 254 LocalContext env; |
| 255 v8::HandleScope scope(env->GetIsolate()); | 255 v8::Isolate* isolate = env->GetIsolate(); |
| 256 v8::HandleScope scope(isolate); |
| 256 // Setup templates. | 257 // Setup templates. |
| 257 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 258 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
| 258 v8::Handle<v8::Signature> sig = v8::Signature::New(env->GetIsolate(), fun); | 259 v8::Handle<v8::Signature> sig = v8::Signature::New(isolate, fun); |
| 259 v8::Handle<v8::FunctionTemplate> callback_sig = | 260 v8::Handle<v8::FunctionTemplate> callback_sig = |
| 260 v8::FunctionTemplate::New( | 261 v8::FunctionTemplate::New( |
| 261 IncrementingSignatureCallback, Local<Value>(), sig); | 262 isolate, IncrementingSignatureCallback, Local<Value>(), sig); |
| 262 v8::Handle<v8::FunctionTemplate> callback = | 263 v8::Handle<v8::FunctionTemplate> callback = |
| 263 v8::FunctionTemplate::New(IncrementingSignatureCallback); | 264 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback); |
| 264 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); | 265 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate); |
| 265 sub_fun->Inherit(fun); | 266 sub_fun->Inherit(fun); |
| 266 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); | 267 v8::Handle<v8::FunctionTemplate> unrel_fun = |
| 268 v8::FunctionTemplate::New(isolate); |
| 267 // Install properties. | 269 // Install properties. |
| 268 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); | 270 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); |
| 269 fun_proto->Set(v8_str("prop_sig"), callback_sig); | 271 fun_proto->Set(v8_str("prop_sig"), callback_sig); |
| 270 fun_proto->Set(v8_str("prop"), callback); | 272 fun_proto->Set(v8_str("prop"), callback); |
| 271 fun_proto->SetAccessorProperty( | 273 fun_proto->SetAccessorProperty( |
| 272 v8_str("accessor_sig"), callback_sig, callback_sig); | 274 v8_str("accessor_sig"), callback_sig, callback_sig); |
| 273 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); | 275 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); |
| 274 // Instantiate templates. | 276 // Instantiate templates. |
| 275 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); | 277 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); |
| 276 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance(); | 278 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 TestSignature("test_object.accessor_sig;", test_object); | 320 TestSignature("test_object.accessor_sig;", test_object); |
| 319 TestSignature("test_object[accessor_sig_key];", test_object); | 321 TestSignature("test_object[accessor_sig_key];", test_object); |
| 320 TestSignature("test_object.accessor_sig = 1;", test_object); | 322 TestSignature("test_object.accessor_sig = 1;", test_object); |
| 321 TestSignature("test_object[accessor_sig_key] = 1;", test_object); | 323 TestSignature("test_object[accessor_sig_key] = 1;", test_object); |
| 322 } | 324 } |
| 323 } | 325 } |
| 324 | 326 |
| 325 | 327 |
| 326 THREADED_TEST(ArgumentSignature) { | 328 THREADED_TEST(ArgumentSignature) { |
| 327 LocalContext env; | 329 LocalContext env; |
| 328 v8::HandleScope scope(env->GetIsolate()); | 330 v8::Isolate* isolate = env->GetIsolate(); |
| 329 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); | 331 v8::HandleScope scope(isolate); |
| 332 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(isolate); |
| 330 cons->SetClassName(v8_str("Cons")); | 333 cons->SetClassName(v8_str("Cons")); |
| 331 v8::Handle<v8::Signature> sig = v8::Signature::New( | 334 v8::Handle<v8::Signature> sig = v8::Signature::New( |
| 332 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 1, &cons); | 335 isolate, v8::Handle<v8::FunctionTemplate>(), 1, &cons); |
| 333 v8::Handle<v8::FunctionTemplate> fun = | 336 v8::Handle<v8::FunctionTemplate> fun = |
| 334 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); | 337 v8::FunctionTemplate::New(isolate, |
| 338 SignatureCallback, |
| 339 v8::Handle<Value>(), |
| 340 sig); |
| 335 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); | 341 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); |
| 336 env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); | 342 env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); |
| 337 | 343 |
| 338 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';"); | 344 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';"); |
| 339 CHECK(value1->IsTrue()); | 345 CHECK(value1->IsTrue()); |
| 340 | 346 |
| 341 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';"); | 347 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';"); |
| 342 CHECK(value2->IsTrue()); | 348 CHECK(value2->IsTrue()); |
| 343 | 349 |
| 344 v8::Handle<Value> value3 = CompileRun("Fun1() == '';"); | 350 v8::Handle<Value> value3 = CompileRun("Fun1() == '';"); |
| 345 CHECK(value3->IsTrue()); | 351 CHECK(value3->IsTrue()); |
| 346 | 352 |
| 347 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New(); | 353 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New(isolate); |
| 348 cons1->SetClassName(v8_str("Cons1")); | 354 cons1->SetClassName(v8_str("Cons1")); |
| 349 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New(); | 355 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New(isolate); |
| 350 cons2->SetClassName(v8_str("Cons2")); | 356 cons2->SetClassName(v8_str("Cons2")); |
| 351 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New(); | 357 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New(isolate); |
| 352 cons3->SetClassName(v8_str("Cons3")); | 358 cons3->SetClassName(v8_str("Cons3")); |
| 353 | 359 |
| 354 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 }; | 360 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 }; |
| 355 v8::Handle<v8::Signature> wsig = v8::Signature::New( | 361 v8::Handle<v8::Signature> wsig = v8::Signature::New( |
| 356 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 3, args); | 362 isolate, v8::Handle<v8::FunctionTemplate>(), 3, args); |
| 357 v8::Handle<v8::FunctionTemplate> fun2 = | 363 v8::Handle<v8::FunctionTemplate> fun2 = |
| 358 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), wsig); | 364 v8::FunctionTemplate::New(isolate, |
| 365 SignatureCallback, |
| 366 v8::Handle<Value>(), |
| 367 wsig); |
| 359 | 368 |
| 360 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction()); | 369 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction()); |
| 361 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction()); | 370 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction()); |
| 362 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction()); | 371 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction()); |
| 363 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction()); | 372 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction()); |
| 364 v8::Handle<Value> value4 = CompileRun( | 373 v8::Handle<Value> value4 = CompileRun( |
| 365 "Fun2(new Cons1(), new Cons2(), new Cons3()) ==" | 374 "Fun2(new Cons1(), new Cons2(), new Cons3()) ==" |
| 366 "'[object Cons1],[object Cons2],[object Cons3]'"); | 375 "'[object Cons1],[object Cons2],[object Cons3]'"); |
| 367 CHECK(value4->IsTrue()); | 376 CHECK(value4->IsTrue()); |
| 368 | 377 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 info.GetReturnValue().Set(v8_num(239)); | 1022 info.GetReturnValue().Set(v8_num(239)); |
| 1014 } | 1023 } |
| 1015 | 1024 |
| 1016 | 1025 |
| 1017 template<typename Handler> | 1026 template<typename Handler> |
| 1018 static void TestFunctionTemplateInitializer(Handler handler, | 1027 static void TestFunctionTemplateInitializer(Handler handler, |
| 1019 Handler handler_2) { | 1028 Handler handler_2) { |
| 1020 // Test constructor calls. | 1029 // Test constructor calls. |
| 1021 { | 1030 { |
| 1022 LocalContext env; | 1031 LocalContext env; |
| 1023 v8::HandleScope scope(env->GetIsolate()); | 1032 v8::Isolate* isolate = env->GetIsolate(); |
| 1033 v8::HandleScope scope(isolate); |
| 1024 | 1034 |
| 1025 Local<v8::FunctionTemplate> fun_templ = | 1035 Local<v8::FunctionTemplate> fun_templ = |
| 1026 v8::FunctionTemplate::New(handler); | 1036 v8::FunctionTemplate::New(isolate, handler); |
| 1027 Local<Function> fun = fun_templ->GetFunction(); | 1037 Local<Function> fun = fun_templ->GetFunction(); |
| 1028 env->Global()->Set(v8_str("obj"), fun); | 1038 env->Global()->Set(v8_str("obj"), fun); |
| 1029 Local<Script> script = v8_compile("obj()"); | 1039 Local<Script> script = v8_compile("obj()"); |
| 1030 for (int i = 0; i < 30; i++) { | 1040 for (int i = 0; i < 30; i++) { |
| 1031 CHECK_EQ(102, script->Run()->Int32Value()); | 1041 CHECK_EQ(102, script->Run()->Int32Value()); |
| 1032 } | 1042 } |
| 1033 } | 1043 } |
| 1034 // Use SetCallHandler to initialize a function template, should work like | 1044 // Use SetCallHandler to initialize a function template, should work like |
| 1035 // the previous one. | 1045 // the previous one. |
| 1036 { | 1046 { |
| 1037 LocalContext env; | 1047 LocalContext env; |
| 1038 v8::HandleScope scope(env->GetIsolate()); | 1048 v8::Isolate* isolate = env->GetIsolate(); |
| 1049 v8::HandleScope scope(isolate); |
| 1039 | 1050 |
| 1040 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 1051 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
| 1041 fun_templ->SetCallHandler(handler_2); | 1052 fun_templ->SetCallHandler(handler_2); |
| 1042 Local<Function> fun = fun_templ->GetFunction(); | 1053 Local<Function> fun = fun_templ->GetFunction(); |
| 1043 env->Global()->Set(v8_str("obj"), fun); | 1054 env->Global()->Set(v8_str("obj"), fun); |
| 1044 Local<Script> script = v8_compile("obj()"); | 1055 Local<Script> script = v8_compile("obj()"); |
| 1045 for (int i = 0; i < 30; i++) { | 1056 for (int i = 0; i < 30; i++) { |
| 1046 CHECK_EQ(102, script->Run()->Int32Value()); | 1057 CHECK_EQ(102, script->Run()->Int32Value()); |
| 1047 } | 1058 } |
| 1048 } | 1059 } |
| 1049 } | 1060 } |
| 1050 | 1061 |
| 1051 | 1062 |
| 1052 template<typename Constructor, typename Accessor> | 1063 template<typename Constructor, typename Accessor> |
| 1053 static void TestFunctionTemplateAccessor(Constructor constructor, | 1064 static void TestFunctionTemplateAccessor(Constructor constructor, |
| 1054 Accessor accessor) { | 1065 Accessor accessor) { |
| 1055 LocalContext env; | 1066 LocalContext env; |
| 1056 v8::HandleScope scope(env->GetIsolate()); | 1067 v8::HandleScope scope(env->GetIsolate()); |
| 1057 | 1068 |
| 1058 Local<v8::FunctionTemplate> fun_templ = | 1069 Local<v8::FunctionTemplate> fun_templ = |
| 1059 v8::FunctionTemplate::New(constructor); | 1070 v8::FunctionTemplate::New(env->GetIsolate(), constructor); |
| 1060 fun_templ->SetClassName(v8_str("funky")); | 1071 fun_templ->SetClassName(v8_str("funky")); |
| 1061 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); | 1072 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); |
| 1062 Local<Function> fun = fun_templ->GetFunction(); | 1073 Local<Function> fun = fun_templ->GetFunction(); |
| 1063 env->Global()->Set(v8_str("obj"), fun); | 1074 env->Global()->Set(v8_str("obj"), fun); |
| 1064 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 1075 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
| 1065 CHECK_EQ(v8_str("[object funky]"), result); | 1076 CHECK_EQ(v8_str("[object funky]"), result); |
| 1066 CompileRun("var obj_instance = new obj();"); | 1077 CompileRun("var obj_instance = new obj();"); |
| 1067 Local<Script> script; | 1078 Local<Script> script; |
| 1068 script = v8_compile("obj_instance.x"); | 1079 script = v8_compile("obj_instance.x"); |
| 1069 for (int i = 0; i < 30; i++) { | 1080 for (int i = 0; i < 30; i++) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1089 } | 1100 } |
| 1090 | 1101 |
| 1091 | 1102 |
| 1092 template<typename Callback> | 1103 template<typename Callback> |
| 1093 static void TestSimpleCallback(Callback callback) { | 1104 static void TestSimpleCallback(Callback callback) { |
| 1094 LocalContext env; | 1105 LocalContext env; |
| 1095 v8::HandleScope scope(env->GetIsolate()); | 1106 v8::HandleScope scope(env->GetIsolate()); |
| 1096 | 1107 |
| 1097 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1108 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
| 1098 object_template->Set(env->GetIsolate(), "callback", | 1109 object_template->Set(env->GetIsolate(), "callback", |
| 1099 v8::FunctionTemplate::New(callback)); | 1110 v8::FunctionTemplate::New(env->GetIsolate(), callback)); |
| 1100 v8::Local<v8::Object> object = object_template->NewInstance(); | 1111 v8::Local<v8::Object> object = object_template->NewInstance(); |
| 1101 (*env)->Global()->Set(v8_str("callback_object"), object); | 1112 (*env)->Global()->Set(v8_str("callback_object"), object); |
| 1102 v8::Handle<v8::Script> script; | 1113 v8::Handle<v8::Script> script; |
| 1103 script = v8_compile("callback_object.callback(17)"); | 1114 script = v8_compile("callback_object.callback(17)"); |
| 1104 for (int i = 0; i < 30; i++) { | 1115 for (int i = 0; i < 30; i++) { |
| 1105 CHECK_EQ(51424, script->Run()->Int32Value()); | 1116 CHECK_EQ(51424, script->Run()->Int32Value()); |
| 1106 } | 1117 } |
| 1107 script = v8_compile("callback_object.callback(17, 24)"); | 1118 script = v8_compile("callback_object.callback(17, 24)"); |
| 1108 for (int i = 0; i < 30; i++) { | 1119 for (int i = 0; i < 30; i++) { |
| 1109 CHECK_EQ(51425, script->Run()->Int32Value()); | 1120 CHECK_EQ(51425, script->Run()->Int32Value()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 info.GetReturnValue().Set(object); | 1203 info.GetReturnValue().Set(object); |
| 1193 } | 1204 } |
| 1194 | 1205 |
| 1195 template<typename T> | 1206 template<typename T> |
| 1196 Handle<Value> TestFastReturnValues() { | 1207 Handle<Value> TestFastReturnValues() { |
| 1197 LocalContext env; | 1208 LocalContext env; |
| 1198 v8::EscapableHandleScope scope(env->GetIsolate()); | 1209 v8::EscapableHandleScope scope(env->GetIsolate()); |
| 1199 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1210 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); |
| 1200 v8::FunctionCallback callback = &FastReturnValueCallback<T>; | 1211 v8::FunctionCallback callback = &FastReturnValueCallback<T>; |
| 1201 object_template->Set(env->GetIsolate(), "callback", | 1212 object_template->Set(env->GetIsolate(), "callback", |
| 1202 v8::FunctionTemplate::New(callback)); | 1213 v8::FunctionTemplate::New(env->GetIsolate(), callback)); |
| 1203 v8::Local<v8::Object> object = object_template->NewInstance(); | 1214 v8::Local<v8::Object> object = object_template->NewInstance(); |
| 1204 (*env)->Global()->Set(v8_str("callback_object"), object); | 1215 (*env)->Global()->Set(v8_str("callback_object"), object); |
| 1205 return scope.Escape(CompileRun("callback_object.callback()")); | 1216 return scope.Escape(CompileRun("callback_object.callback()")); |
| 1206 } | 1217 } |
| 1207 | 1218 |
| 1208 | 1219 |
| 1209 THREADED_PROFILED_TEST(FastReturnValues) { | 1220 THREADED_PROFILED_TEST(FastReturnValues) { |
| 1210 LocalContext env; | 1221 LocalContext env; |
| 1211 v8::HandleScope scope(CcTest::isolate()); | 1222 v8::HandleScope scope(CcTest::isolate()); |
| 1212 v8::Handle<v8::Value> value; | 1223 v8::Handle<v8::Value> value; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 value = TestFastReturnValues<Object>(); | 1279 value = TestFastReturnValues<Object>(); |
| 1269 CHECK(value->IsObject()); | 1280 CHECK(value->IsObject()); |
| 1270 fast_return_value_object_is_empty = true; | 1281 fast_return_value_object_is_empty = true; |
| 1271 value = TestFastReturnValues<Object>(); | 1282 value = TestFastReturnValues<Object>(); |
| 1272 CHECK(value->IsUndefined()); | 1283 CHECK(value->IsUndefined()); |
| 1273 } | 1284 } |
| 1274 | 1285 |
| 1275 | 1286 |
| 1276 THREADED_TEST(FunctionTemplateSetLength) { | 1287 THREADED_TEST(FunctionTemplateSetLength) { |
| 1277 LocalContext env; | 1288 LocalContext env; |
| 1278 v8::HandleScope scope(env->GetIsolate()); | 1289 v8::Isolate* isolate = env->GetIsolate(); |
| 1290 v8::HandleScope scope(isolate); |
| 1279 { | 1291 { |
| 1280 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( | 1292 Local<v8::FunctionTemplate> fun_templ = |
| 1281 handle_callback, Handle<v8::Value>(), Handle<v8::Signature>(), 23); | 1293 v8::FunctionTemplate::New(isolate, |
| 1294 handle_callback, |
| 1295 Handle<v8::Value>(), |
| 1296 Handle<v8::Signature>(), |
| 1297 23); |
| 1282 Local<Function> fun = fun_templ->GetFunction(); | 1298 Local<Function> fun = fun_templ->GetFunction(); |
| 1283 env->Global()->Set(v8_str("obj"), fun); | 1299 env->Global()->Set(v8_str("obj"), fun); |
| 1284 Local<Script> script = v8_compile("obj.length"); | 1300 Local<Script> script = v8_compile("obj.length"); |
| 1285 CHECK_EQ(23, script->Run()->Int32Value()); | 1301 CHECK_EQ(23, script->Run()->Int32Value()); |
| 1286 } | 1302 } |
| 1287 { | 1303 { |
| 1288 Local<v8::FunctionTemplate> fun_templ = | 1304 Local<v8::FunctionTemplate> fun_templ = |
| 1289 v8::FunctionTemplate::New(handle_callback); | 1305 v8::FunctionTemplate::New(isolate, handle_callback); |
| 1290 fun_templ->SetLength(22); | 1306 fun_templ->SetLength(22); |
| 1291 Local<Function> fun = fun_templ->GetFunction(); | 1307 Local<Function> fun = fun_templ->GetFunction(); |
| 1292 env->Global()->Set(v8_str("obj"), fun); | 1308 env->Global()->Set(v8_str("obj"), fun); |
| 1293 Local<Script> script = v8_compile("obj.length"); | 1309 Local<Script> script = v8_compile("obj.length"); |
| 1294 CHECK_EQ(22, script->Run()->Int32Value()); | 1310 CHECK_EQ(22, script->Run()->Int32Value()); |
| 1295 } | 1311 } |
| 1296 { | 1312 { |
| 1297 // Without setting length it defaults to 0. | 1313 // Without setting length it defaults to 0. |
| 1298 Local<v8::FunctionTemplate> fun_templ = | 1314 Local<v8::FunctionTemplate> fun_templ = |
| 1299 v8::FunctionTemplate::New(handle_callback); | 1315 v8::FunctionTemplate::New(isolate, handle_callback); |
| 1300 Local<Function> fun = fun_templ->GetFunction(); | 1316 Local<Function> fun = fun_templ->GetFunction(); |
| 1301 env->Global()->Set(v8_str("obj"), fun); | 1317 env->Global()->Set(v8_str("obj"), fun); |
| 1302 Local<Script> script = v8_compile("obj.length"); | 1318 Local<Script> script = v8_compile("obj.length"); |
| 1303 CHECK_EQ(0, script->Run()->Int32Value()); | 1319 CHECK_EQ(0, script->Run()->Int32Value()); |
| 1304 } | 1320 } |
| 1305 } | 1321 } |
| 1306 | 1322 |
| 1307 | 1323 |
| 1308 static void* expected_ptr; | 1324 static void* expected_ptr; |
| 1309 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1325 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1310 void* ptr = v8::External::Cast(*args.Data())->Value(); | 1326 void* ptr = v8::External::Cast(*args.Data())->Value(); |
| 1311 CHECK_EQ(expected_ptr, ptr); | 1327 CHECK_EQ(expected_ptr, ptr); |
| 1312 args.GetReturnValue().Set(true); | 1328 args.GetReturnValue().Set(true); |
| 1313 } | 1329 } |
| 1314 | 1330 |
| 1315 | 1331 |
| 1316 static void TestExternalPointerWrapping() { | 1332 static void TestExternalPointerWrapping() { |
| 1317 LocalContext env; | 1333 LocalContext env; |
| 1318 v8::HandleScope scope(env->GetIsolate()); | 1334 v8::Isolate* isolate = env->GetIsolate(); |
| 1335 v8::HandleScope scope(isolate); |
| 1319 | 1336 |
| 1320 v8::Handle<v8::Value> data = | 1337 v8::Handle<v8::Value> data = |
| 1321 v8::External::New(env->GetIsolate(), expected_ptr); | 1338 v8::External::New(isolate, expected_ptr); |
| 1322 | 1339 |
| 1323 v8::Handle<v8::Object> obj = v8::Object::New(); | 1340 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 1324 obj->Set(v8_str("func"), | 1341 obj->Set(v8_str("func"), |
| 1325 v8::FunctionTemplate::New(callback, data)->GetFunction()); | 1342 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction()); |
| 1326 env->Global()->Set(v8_str("obj"), obj); | 1343 env->Global()->Set(v8_str("obj"), obj); |
| 1327 | 1344 |
| 1328 CHECK(CompileRun( | 1345 CHECK(CompileRun( |
| 1329 "function foo() {\n" | 1346 "function foo() {\n" |
| 1330 " for (var i = 0; i < 13; i++) obj.func();\n" | 1347 " for (var i = 0; i < 13; i++) obj.func();\n" |
| 1331 "}\n" | 1348 "}\n" |
| 1332 "foo(), true")->BooleanValue()); | 1349 "foo(), true")->BooleanValue()); |
| 1333 } | 1350 } |
| 1334 | 1351 |
| 1335 | 1352 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 TestExternalPointerWrapping(); | 1391 TestExternalPointerWrapping(); |
| 1375 | 1392 |
| 1376 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1); | 1393 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1); |
| 1377 TestExternalPointerWrapping(); | 1394 TestExternalPointerWrapping(); |
| 1378 #endif | 1395 #endif |
| 1379 } | 1396 } |
| 1380 | 1397 |
| 1381 | 1398 |
| 1382 THREADED_TEST(FindInstanceInPrototypeChain) { | 1399 THREADED_TEST(FindInstanceInPrototypeChain) { |
| 1383 LocalContext env; | 1400 LocalContext env; |
| 1384 v8::HandleScope scope(env->GetIsolate()); | 1401 v8::Isolate* isolate = env->GetIsolate(); |
| 1402 v8::HandleScope scope(isolate); |
| 1385 | 1403 |
| 1386 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); | 1404 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate); |
| 1387 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); | 1405 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate); |
| 1388 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); | 1406 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate); |
| 1389 derived->Inherit(base); | 1407 derived->Inherit(base); |
| 1390 | 1408 |
| 1391 Local<v8::Function> base_function = base->GetFunction(); | 1409 Local<v8::Function> base_function = base->GetFunction(); |
| 1392 Local<v8::Function> derived_function = derived->GetFunction(); | 1410 Local<v8::Function> derived_function = derived->GetFunction(); |
| 1393 Local<v8::Function> other_function = other->GetFunction(); | 1411 Local<v8::Function> other_function = other->GetFunction(); |
| 1394 | 1412 |
| 1395 Local<v8::Object> base_instance = base_function->NewInstance(); | 1413 Local<v8::Object> base_instance = base_function->NewInstance(); |
| 1396 Local<v8::Object> derived_instance = derived_function->NewInstance(); | 1414 Local<v8::Object> derived_instance = derived_function->NewInstance(); |
| 1397 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); | 1415 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); |
| 1398 Local<v8::Object> other_instance = other_function->NewInstance(); | 1416 Local<v8::Object> other_instance = other_function->NewInstance(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 | 1767 |
| 1750 | 1768 |
| 1751 static void GetM(Local<String> name, | 1769 static void GetM(Local<String> name, |
| 1752 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1770 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1753 ApiTestFuzzer::Fuzz(); | 1771 ApiTestFuzzer::Fuzz(); |
| 1754 info.GetReturnValue().Set(v8_num(876)); | 1772 info.GetReturnValue().Set(v8_num(876)); |
| 1755 } | 1773 } |
| 1756 | 1774 |
| 1757 | 1775 |
| 1758 THREADED_TEST(GlobalPrototype) { | 1776 THREADED_TEST(GlobalPrototype) { |
| 1759 v8::HandleScope scope(CcTest::isolate()); | 1777 v8::Isolate* isolate = CcTest::isolate(); |
| 1760 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); | 1778 v8::HandleScope scope(isolate); |
| 1779 v8::Handle<v8::FunctionTemplate> func_templ = |
| 1780 v8::FunctionTemplate::New(isolate); |
| 1761 func_templ->PrototypeTemplate()->Set( | 1781 func_templ->PrototypeTemplate()->Set( |
| 1762 CcTest::isolate(), "dummy", v8::FunctionTemplate::New(DummyCallHandler)); | 1782 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler)); |
| 1763 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); | 1783 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); |
| 1764 templ->Set(CcTest::isolate(), "x", v8_num(200)); | 1784 templ->Set(isolate, "x", v8_num(200)); |
| 1765 templ->SetAccessor(v8_str("m"), GetM); | 1785 templ->SetAccessor(v8_str("m"), GetM); |
| 1766 LocalContext env(0, templ); | 1786 LocalContext env(0, templ); |
| 1767 v8::Handle<Script> script(v8_compile("dummy()")); | 1787 v8::Handle<Script> script(v8_compile("dummy()")); |
| 1768 v8::Handle<Value> result(script->Run()); | 1788 v8::Handle<Value> result(script->Run()); |
| 1769 CHECK_EQ(13.4, result->NumberValue()); | 1789 CHECK_EQ(13.4, result->NumberValue()); |
| 1770 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); | 1790 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); |
| 1771 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); | 1791 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); |
| 1772 } | 1792 } |
| 1773 | 1793 |
| 1774 | 1794 |
| 1775 THREADED_TEST(ObjectTemplate) { | 1795 THREADED_TEST(ObjectTemplate) { |
| 1776 v8::HandleScope scope(CcTest::isolate()); | 1796 v8::Isolate* isolate = CcTest::isolate(); |
| 1797 v8::HandleScope scope(isolate); |
| 1777 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); | 1798 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); |
| 1778 templ1->Set(CcTest::isolate(), "x", v8_num(10)); | 1799 templ1->Set(isolate, "x", v8_num(10)); |
| 1779 templ1->Set(CcTest::isolate(), "y", v8_num(13)); | 1800 templ1->Set(isolate, "y", v8_num(13)); |
| 1780 LocalContext env; | 1801 LocalContext env; |
| 1781 Local<v8::Object> instance1 = templ1->NewInstance(); | 1802 Local<v8::Object> instance1 = templ1->NewInstance(); |
| 1782 env->Global()->Set(v8_str("p"), instance1); | 1803 env->Global()->Set(v8_str("p"), instance1); |
| 1783 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); | 1804 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); |
| 1784 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); | 1805 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); |
| 1785 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); | 1806 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
| 1786 fun->PrototypeTemplate()->Set(CcTest::isolate(), "nirk", v8_num(123)); | 1807 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); |
| 1787 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); | 1808 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); |
| 1788 templ2->Set(CcTest::isolate(), "a", v8_num(12)); | 1809 templ2->Set(isolate, "a", v8_num(12)); |
| 1789 templ2->Set(CcTest::isolate(), "b", templ1); | 1810 templ2->Set(isolate, "b", templ1); |
| 1790 Local<v8::Object> instance2 = templ2->NewInstance(); | 1811 Local<v8::Object> instance2 = templ2->NewInstance(); |
| 1791 env->Global()->Set(v8_str("q"), instance2); | 1812 env->Global()->Set(v8_str("q"), instance2); |
| 1792 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); | 1813 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); |
| 1793 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); | 1814 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); |
| 1794 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); | 1815 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); |
| 1795 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); | 1816 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); |
| 1796 } | 1817 } |
| 1797 | 1818 |
| 1798 | 1819 |
| 1799 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1820 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1800 ApiTestFuzzer::Fuzz(); | 1821 ApiTestFuzzer::Fuzz(); |
| 1801 args.GetReturnValue().Set(v8_num(17.2)); | 1822 args.GetReturnValue().Set(v8_num(17.2)); |
| 1802 } | 1823 } |
| 1803 | 1824 |
| 1804 | 1825 |
| 1805 static void GetKnurd(Local<String> property, | 1826 static void GetKnurd(Local<String> property, |
| 1806 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1827 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1807 ApiTestFuzzer::Fuzz(); | 1828 ApiTestFuzzer::Fuzz(); |
| 1808 info.GetReturnValue().Set(v8_num(15.2)); | 1829 info.GetReturnValue().Set(v8_num(15.2)); |
| 1809 } | 1830 } |
| 1810 | 1831 |
| 1811 | 1832 |
| 1812 THREADED_TEST(DescriptorInheritance) { | 1833 THREADED_TEST(DescriptorInheritance) { |
| 1813 v8::HandleScope scope(CcTest::isolate()); | 1834 v8::Isolate* isolate = CcTest::isolate(); |
| 1814 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); | 1835 v8::HandleScope scope(isolate); |
| 1815 super->PrototypeTemplate()->Set(CcTest::isolate(), "flabby", | 1836 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate); |
| 1816 v8::FunctionTemplate::New(GetFlabby)); | 1837 super->PrototypeTemplate()->Set(isolate, "flabby", |
| 1817 super->PrototypeTemplate()->Set(CcTest::isolate(), "PI", v8_num(3.14)); | 1838 v8::FunctionTemplate::New(isolate, |
| 1839 GetFlabby)); |
| 1840 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14)); |
| 1818 | 1841 |
| 1819 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); | 1842 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); |
| 1820 | 1843 |
| 1821 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(); | 1844 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate); |
| 1822 base1->Inherit(super); | 1845 base1->Inherit(super); |
| 1823 base1->PrototypeTemplate()->Set(CcTest::isolate(), "v1", v8_num(20.1)); | 1846 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1)); |
| 1824 | 1847 |
| 1825 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(); | 1848 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate); |
| 1826 base2->Inherit(super); | 1849 base2->Inherit(super); |
| 1827 base2->PrototypeTemplate()->Set(CcTest::isolate(), "v2", v8_num(10.1)); | 1850 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1)); |
| 1828 | 1851 |
| 1829 LocalContext env; | 1852 LocalContext env; |
| 1830 | 1853 |
| 1831 env->Global()->Set(v8_str("s"), super->GetFunction()); | 1854 env->Global()->Set(v8_str("s"), super->GetFunction()); |
| 1832 env->Global()->Set(v8_str("base1"), base1->GetFunction()); | 1855 env->Global()->Set(v8_str("base1"), base1->GetFunction()); |
| 1833 env->Global()->Set(v8_str("base2"), base2->GetFunction()); | 1856 env->Global()->Set(v8_str("base2"), base2->GetFunction()); |
| 1834 | 1857 |
| 1835 // Checks right __proto__ chain. | 1858 // Checks right __proto__ chain. |
| 1836 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); | 1859 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); |
| 1837 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); | 1860 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 | 1968 |
| 1946 void AddInterceptor(Handle<FunctionTemplate> templ, | 1969 void AddInterceptor(Handle<FunctionTemplate> templ, |
| 1947 v8::NamedPropertyGetterCallback getter, | 1970 v8::NamedPropertyGetterCallback getter, |
| 1948 v8::NamedPropertySetterCallback setter) { | 1971 v8::NamedPropertySetterCallback setter) { |
| 1949 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); | 1972 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); |
| 1950 } | 1973 } |
| 1951 | 1974 |
| 1952 | 1975 |
| 1953 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { | 1976 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { |
| 1954 v8::HandleScope scope(CcTest::isolate()); | 1977 v8::HandleScope scope(CcTest::isolate()); |
| 1955 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1978 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 1956 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1979 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 1957 child->Inherit(parent); | 1980 child->Inherit(parent); |
| 1958 AddAccessor(parent, v8_str("age"), | 1981 AddAccessor(parent, v8_str("age"), |
| 1959 SimpleAccessorGetter, SimpleAccessorSetter); | 1982 SimpleAccessorGetter, SimpleAccessorSetter); |
| 1960 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); | 1983 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 1961 LocalContext env; | 1984 LocalContext env; |
| 1962 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 1985 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 1963 CompileRun("var child = new Child;" | 1986 CompileRun("var child = new Child;" |
| 1964 "child.age = 10;"); | 1987 "child.age = 10;"); |
| 1965 ExpectBoolean("child.hasOwnProperty('age')", false); | 1988 ExpectBoolean("child.hasOwnProperty('age')", false); |
| 1966 ExpectInt32("child.age", 10); | 1989 ExpectInt32("child.age", 10); |
| 1967 ExpectInt32("child.accessor_age", 10); | 1990 ExpectInt32("child.accessor_age", 10); |
| 1968 } | 1991 } |
| 1969 | 1992 |
| 1970 | 1993 |
| 1971 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) { | 1994 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) { |
| 1972 v8::HandleScope scope(CcTest::isolate()); | 1995 v8::Isolate* isolate = CcTest::isolate(); |
| 1973 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 1996 v8::HandleScope scope(isolate); |
| 1974 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 1997 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate); |
| 1998 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate); |
| 1975 child->Inherit(parent); | 1999 child->Inherit(parent); |
| 1976 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); | 2000 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 1977 LocalContext env; | 2001 LocalContext env; |
| 1978 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2002 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 1979 CompileRun("var child = new Child;" | 2003 CompileRun("var child = new Child;" |
| 1980 "var parent = child.__proto__;" | 2004 "var parent = child.__proto__;" |
| 1981 "Object.defineProperty(parent, 'age', " | 2005 "Object.defineProperty(parent, 'age', " |
| 1982 " {get: function(){ return this.accessor_age; }, " | 2006 " {get: function(){ return this.accessor_age; }, " |
| 1983 " set: function(v){ this.accessor_age = v; }, " | 2007 " set: function(v){ this.accessor_age = v; }, " |
| 1984 " enumerable: true, configurable: true});" | 2008 " enumerable: true, configurable: true});" |
| 1985 "child.age = 10;"); | 2009 "child.age = 10;"); |
| 1986 ExpectBoolean("child.hasOwnProperty('age')", false); | 2010 ExpectBoolean("child.hasOwnProperty('age')", false); |
| 1987 ExpectInt32("child.age", 10); | 2011 ExpectInt32("child.age", 10); |
| 1988 ExpectInt32("child.accessor_age", 10); | 2012 ExpectInt32("child.accessor_age", 10); |
| 1989 } | 2013 } |
| 1990 | 2014 |
| 1991 | 2015 |
| 1992 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) { | 2016 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) { |
| 1993 v8::HandleScope scope(CcTest::isolate()); | 2017 v8::Isolate* isolate = CcTest::isolate(); |
| 1994 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 2018 v8::HandleScope scope(isolate); |
| 1995 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 2019 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate); |
| 2020 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate); |
| 1996 child->Inherit(parent); | 2021 child->Inherit(parent); |
| 1997 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); | 2022 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 1998 LocalContext env; | 2023 LocalContext env; |
| 1999 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2024 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2000 CompileRun("var child = new Child;" | 2025 CompileRun("var child = new Child;" |
| 2001 "var parent = child.__proto__;" | 2026 "var parent = child.__proto__;" |
| 2002 "parent.name = 'Alice';"); | 2027 "parent.name = 'Alice';"); |
| 2003 ExpectBoolean("child.hasOwnProperty('name')", false); | 2028 ExpectBoolean("child.hasOwnProperty('name')", false); |
| 2004 ExpectString("child.name", "Alice"); | 2029 ExpectString("child.name", "Alice"); |
| 2005 CompileRun("child.name = 'Bob';"); | 2030 CompileRun("child.name = 'Bob';"); |
| 2006 ExpectString("child.name", "Bob"); | 2031 ExpectString("child.name", "Bob"); |
| 2007 ExpectBoolean("child.hasOwnProperty('name')", true); | 2032 ExpectBoolean("child.hasOwnProperty('name')", true); |
| 2008 ExpectString("parent.name", "Alice"); | 2033 ExpectString("parent.name", "Alice"); |
| 2009 } | 2034 } |
| 2010 | 2035 |
| 2011 | 2036 |
| 2012 THREADED_TEST(SwitchFromInterceptorToAccessor) { | 2037 THREADED_TEST(SwitchFromInterceptorToAccessor) { |
| 2013 v8::HandleScope scope(CcTest::isolate()); | 2038 v8::HandleScope scope(CcTest::isolate()); |
| 2014 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 2039 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 2015 AddAccessor(templ, v8_str("age"), | 2040 AddAccessor(templ, v8_str("age"), |
| 2016 SimpleAccessorGetter, SimpleAccessorSetter); | 2041 SimpleAccessorGetter, SimpleAccessorSetter); |
| 2017 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 2042 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 2018 LocalContext env; | 2043 LocalContext env; |
| 2019 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 2044 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 2020 CompileRun("var obj = new Obj;" | 2045 CompileRun("var obj = new Obj;" |
| 2021 "function setAge(i){ obj.age = i; };" | 2046 "function setAge(i){ obj.age = i; };" |
| 2022 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 2047 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 2023 // All i < 10000 go to the interceptor. | 2048 // All i < 10000 go to the interceptor. |
| 2024 ExpectInt32("obj.interceptor_age", 9999); | 2049 ExpectInt32("obj.interceptor_age", 9999); |
| 2025 // The last i goes to the accessor. | 2050 // The last i goes to the accessor. |
| 2026 ExpectInt32("obj.accessor_age", 10000); | 2051 ExpectInt32("obj.accessor_age", 10000); |
| 2027 } | 2052 } |
| 2028 | 2053 |
| 2029 | 2054 |
| 2030 THREADED_TEST(SwitchFromAccessorToInterceptor) { | 2055 THREADED_TEST(SwitchFromAccessorToInterceptor) { |
| 2031 v8::HandleScope scope(CcTest::isolate()); | 2056 v8::HandleScope scope(CcTest::isolate()); |
| 2032 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 2057 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 2033 AddAccessor(templ, v8_str("age"), | 2058 AddAccessor(templ, v8_str("age"), |
| 2034 SimpleAccessorGetter, SimpleAccessorSetter); | 2059 SimpleAccessorGetter, SimpleAccessorSetter); |
| 2035 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 2060 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 2036 LocalContext env; | 2061 LocalContext env; |
| 2037 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 2062 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 2038 CompileRun("var obj = new Obj;" | 2063 CompileRun("var obj = new Obj;" |
| 2039 "function setAge(i){ obj.age = i; };" | 2064 "function setAge(i){ obj.age = i; };" |
| 2040 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 2065 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 2041 // All i >= 10000 go to the accessor. | 2066 // All i >= 10000 go to the accessor. |
| 2042 ExpectInt32("obj.accessor_age", 10000); | 2067 ExpectInt32("obj.accessor_age", 10000); |
| 2043 // The last i goes to the interceptor. | 2068 // The last i goes to the interceptor. |
| 2044 ExpectInt32("obj.interceptor_age", 9999); | 2069 ExpectInt32("obj.interceptor_age", 9999); |
| 2045 } | 2070 } |
| 2046 | 2071 |
| 2047 | 2072 |
| 2048 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { | 2073 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { |
| 2049 v8::HandleScope scope(CcTest::isolate()); | 2074 v8::HandleScope scope(CcTest::isolate()); |
| 2050 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 2075 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 2051 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 2076 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 2052 child->Inherit(parent); | 2077 child->Inherit(parent); |
| 2053 AddAccessor(parent, v8_str("age"), | 2078 AddAccessor(parent, v8_str("age"), |
| 2054 SimpleAccessorGetter, SimpleAccessorSetter); | 2079 SimpleAccessorGetter, SimpleAccessorSetter); |
| 2055 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 2080 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
| 2056 LocalContext env; | 2081 LocalContext env; |
| 2057 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2082 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2058 CompileRun("var child = new Child;" | 2083 CompileRun("var child = new Child;" |
| 2059 "function setAge(i){ child.age = i; };" | 2084 "function setAge(i){ child.age = i; };" |
| 2060 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 2085 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 2061 // All i < 10000 go to the interceptor. | 2086 // All i < 10000 go to the interceptor. |
| 2062 ExpectInt32("child.interceptor_age", 9999); | 2087 ExpectInt32("child.interceptor_age", 9999); |
| 2063 // The last i goes to the accessor. | 2088 // The last i goes to the accessor. |
| 2064 ExpectInt32("child.accessor_age", 10000); | 2089 ExpectInt32("child.accessor_age", 10000); |
| 2065 } | 2090 } |
| 2066 | 2091 |
| 2067 | 2092 |
| 2068 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { | 2093 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { |
| 2069 v8::HandleScope scope(CcTest::isolate()); | 2094 v8::HandleScope scope(CcTest::isolate()); |
| 2070 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 2095 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 2071 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 2096 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 2072 child->Inherit(parent); | 2097 child->Inherit(parent); |
| 2073 AddAccessor(parent, v8_str("age"), | 2098 AddAccessor(parent, v8_str("age"), |
| 2074 SimpleAccessorGetter, SimpleAccessorSetter); | 2099 SimpleAccessorGetter, SimpleAccessorSetter); |
| 2075 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 2100 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
| 2076 LocalContext env; | 2101 LocalContext env; |
| 2077 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2102 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2078 CompileRun("var child = new Child;" | 2103 CompileRun("var child = new Child;" |
| 2079 "function setAge(i){ child.age = i; };" | 2104 "function setAge(i){ child.age = i; };" |
| 2080 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 2105 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 2081 // All i >= 10000 go to the accessor. | 2106 // All i >= 10000 go to the accessor. |
| 2082 ExpectInt32("child.accessor_age", 10000); | 2107 ExpectInt32("child.accessor_age", 10000); |
| 2083 // The last i goes to the interceptor. | 2108 // The last i goes to the interceptor. |
| 2084 ExpectInt32("child.interceptor_age", 9999); | 2109 ExpectInt32("child.interceptor_age", 9999); |
| 2085 } | 2110 } |
| 2086 | 2111 |
| 2087 | 2112 |
| 2088 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { | 2113 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { |
| 2089 v8::HandleScope scope(CcTest::isolate()); | 2114 v8::HandleScope scope(CcTest::isolate()); |
| 2090 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 2115 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 2091 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 2116 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 2092 LocalContext env; | 2117 LocalContext env; |
| 2093 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 2118 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 2094 CompileRun("var obj = new Obj;" | 2119 CompileRun("var obj = new Obj;" |
| 2095 "function setter(i) { this.accessor_age = i; };" | 2120 "function setter(i) { this.accessor_age = i; };" |
| 2096 "function getter() { return this.accessor_age; };" | 2121 "function getter() { return this.accessor_age; };" |
| 2097 "function setAge(i) { obj.age = i; };" | 2122 "function setAge(i) { obj.age = i; };" |
| 2098 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" | 2123 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" |
| 2099 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 2124 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 2100 // All i < 10000 go to the interceptor. | 2125 // All i < 10000 go to the interceptor. |
| 2101 ExpectInt32("obj.interceptor_age", 9999); | 2126 ExpectInt32("obj.interceptor_age", 9999); |
| 2102 // The last i goes to the JavaScript accessor. | 2127 // The last i goes to the JavaScript accessor. |
| 2103 ExpectInt32("obj.accessor_age", 10000); | 2128 ExpectInt32("obj.accessor_age", 10000); |
| 2104 // The installed JavaScript getter is still intact. | 2129 // The installed JavaScript getter is still intact. |
| 2105 // This last part is a regression test for issue 1651 and relies on the fact | 2130 // This last part is a regression test for issue 1651 and relies on the fact |
| 2106 // that both interceptor and accessor are being installed on the same object. | 2131 // that both interceptor and accessor are being installed on the same object. |
| 2107 ExpectInt32("obj.age", 10000); | 2132 ExpectInt32("obj.age", 10000); |
| 2108 ExpectBoolean("obj.hasOwnProperty('age')", true); | 2133 ExpectBoolean("obj.hasOwnProperty('age')", true); |
| 2109 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); | 2134 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); |
| 2110 } | 2135 } |
| 2111 | 2136 |
| 2112 | 2137 |
| 2113 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { | 2138 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { |
| 2114 v8::HandleScope scope(CcTest::isolate()); | 2139 v8::HandleScope scope(CcTest::isolate()); |
| 2115 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 2140 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 2116 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 2141 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 2117 LocalContext env; | 2142 LocalContext env; |
| 2118 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 2143 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 2119 CompileRun("var obj = new Obj;" | 2144 CompileRun("var obj = new Obj;" |
| 2120 "function setter(i) { this.accessor_age = i; };" | 2145 "function setter(i) { this.accessor_age = i; };" |
| 2121 "function getter() { return this.accessor_age; };" | 2146 "function getter() { return this.accessor_age; };" |
| 2122 "function setAge(i) { obj.age = i; };" | 2147 "function setAge(i) { obj.age = i; };" |
| 2123 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" | 2148 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" |
| 2124 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 2149 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 2125 // All i >= 10000 go to the accessor. | 2150 // All i >= 10000 go to the accessor. |
| 2126 ExpectInt32("obj.accessor_age", 10000); | 2151 ExpectInt32("obj.accessor_age", 10000); |
| 2127 // The last i goes to the interceptor. | 2152 // The last i goes to the interceptor. |
| 2128 ExpectInt32("obj.interceptor_age", 9999); | 2153 ExpectInt32("obj.interceptor_age", 9999); |
| 2129 // The installed JavaScript getter is still intact. | 2154 // The installed JavaScript getter is still intact. |
| 2130 // This last part is a regression test for issue 1651 and relies on the fact | 2155 // This last part is a regression test for issue 1651 and relies on the fact |
| 2131 // that both interceptor and accessor are being installed on the same object. | 2156 // that both interceptor and accessor are being installed on the same object. |
| 2132 ExpectInt32("obj.age", 10000); | 2157 ExpectInt32("obj.age", 10000); |
| 2133 ExpectBoolean("obj.hasOwnProperty('age')", true); | 2158 ExpectBoolean("obj.hasOwnProperty('age')", true); |
| 2134 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); | 2159 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); |
| 2135 } | 2160 } |
| 2136 | 2161 |
| 2137 | 2162 |
| 2138 THREADED_TEST(SwitchFromInterceptorToProperty) { | 2163 THREADED_TEST(SwitchFromInterceptorToProperty) { |
| 2139 v8::HandleScope scope(CcTest::isolate()); | 2164 v8::HandleScope scope(CcTest::isolate()); |
| 2140 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 2165 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 2141 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 2166 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 2142 child->Inherit(parent); | 2167 child->Inherit(parent); |
| 2143 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 2168 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
| 2144 LocalContext env; | 2169 LocalContext env; |
| 2145 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2170 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2146 CompileRun("var child = new Child;" | 2171 CompileRun("var child = new Child;" |
| 2147 "function setAge(i){ child.age = i; };" | 2172 "function setAge(i){ child.age = i; };" |
| 2148 "for(var i = 0; i <= 10000; i++) setAge(i);"); | 2173 "for(var i = 0; i <= 10000; i++) setAge(i);"); |
| 2149 // All i < 10000 go to the interceptor. | 2174 // All i < 10000 go to the interceptor. |
| 2150 ExpectInt32("child.interceptor_age", 9999); | 2175 ExpectInt32("child.interceptor_age", 9999); |
| 2151 // The last i goes to child's own property. | 2176 // The last i goes to child's own property. |
| 2152 ExpectInt32("child.age", 10000); | 2177 ExpectInt32("child.age", 10000); |
| 2153 } | 2178 } |
| 2154 | 2179 |
| 2155 | 2180 |
| 2156 THREADED_TEST(SwitchFromPropertyToInterceptor) { | 2181 THREADED_TEST(SwitchFromPropertyToInterceptor) { |
| 2157 v8::HandleScope scope(CcTest::isolate()); | 2182 v8::HandleScope scope(CcTest::isolate()); |
| 2158 Handle<FunctionTemplate> parent = FunctionTemplate::New(); | 2183 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate()); |
| 2159 Handle<FunctionTemplate> child = FunctionTemplate::New(); | 2184 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate()); |
| 2160 child->Inherit(parent); | 2185 child->Inherit(parent); |
| 2161 AddInterceptor(child, InterceptorGetter, InterceptorSetter); | 2186 AddInterceptor(child, InterceptorGetter, InterceptorSetter); |
| 2162 LocalContext env; | 2187 LocalContext env; |
| 2163 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 2188 env->Global()->Set(v8_str("Child"), child->GetFunction()); |
| 2164 CompileRun("var child = new Child;" | 2189 CompileRun("var child = new Child;" |
| 2165 "function setAge(i){ child.age = i; };" | 2190 "function setAge(i){ child.age = i; };" |
| 2166 "for(var i = 20000; i >= 9999; i--) setAge(i);"); | 2191 "for(var i = 20000; i >= 9999; i--) setAge(i);"); |
| 2167 // All i >= 10000 go to child's own property. | 2192 // All i >= 10000 go to child's own property. |
| 2168 ExpectInt32("child.age", 10000); | 2193 ExpectInt32("child.age", 10000); |
| 2169 // The last i goes to the interceptor. | 2194 // The last i goes to the interceptor. |
| 2170 ExpectInt32("child.interceptor_age", 9999); | 2195 ExpectInt32("child.interceptor_age", 9999); |
| 2171 } | 2196 } |
| 2172 | 2197 |
| 2173 | 2198 |
| 2174 THREADED_TEST(NamedPropertyHandlerGetter) { | 2199 THREADED_TEST(NamedPropertyHandlerGetter) { |
| 2175 echo_named_call_count = 0; | 2200 echo_named_call_count = 0; |
| 2176 v8::HandleScope scope(CcTest::isolate()); | 2201 v8::HandleScope scope(CcTest::isolate()); |
| 2177 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 2202 v8::Handle<v8::FunctionTemplate> templ = |
| 2203 v8::FunctionTemplate::New(CcTest::isolate()); |
| 2178 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, | 2204 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, |
| 2179 0, 0, 0, 0, | 2205 0, 0, 0, 0, |
| 2180 v8_str("data")); | 2206 v8_str("data")); |
| 2181 LocalContext env; | 2207 LocalContext env; |
| 2182 env->Global()->Set(v8_str("obj"), | 2208 env->Global()->Set(v8_str("obj"), |
| 2183 templ->GetFunction()->NewInstance()); | 2209 templ->GetFunction()->NewInstance()); |
| 2184 CHECK_EQ(echo_named_call_count, 0); | 2210 CHECK_EQ(echo_named_call_count, 0); |
| 2185 v8_compile("obj.x")->Run(); | 2211 v8_compile("obj.x")->Run(); |
| 2186 CHECK_EQ(echo_named_call_count, 1); | 2212 CHECK_EQ(echo_named_call_count, 1); |
| 2187 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; | 2213 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2202 uint32_t index, | 2228 uint32_t index, |
| 2203 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2229 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2204 ApiTestFuzzer::Fuzz(); | 2230 ApiTestFuzzer::Fuzz(); |
| 2205 CHECK_EQ(v8_num(637), info.Data()); | 2231 CHECK_EQ(v8_num(637), info.Data()); |
| 2206 echo_indexed_call_count++; | 2232 echo_indexed_call_count++; |
| 2207 info.GetReturnValue().Set(v8_num(index)); | 2233 info.GetReturnValue().Set(v8_num(index)); |
| 2208 } | 2234 } |
| 2209 | 2235 |
| 2210 | 2236 |
| 2211 THREADED_TEST(IndexedPropertyHandlerGetter) { | 2237 THREADED_TEST(IndexedPropertyHandlerGetter) { |
| 2212 v8::HandleScope scope(CcTest::isolate()); | 2238 v8::Isolate* isolate = CcTest::isolate(); |
| 2213 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 2239 v8::HandleScope scope(isolate); |
| 2240 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 2214 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, | 2241 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, |
| 2215 0, 0, 0, 0, | 2242 0, 0, 0, 0, |
| 2216 v8_num(637)); | 2243 v8_num(637)); |
| 2217 LocalContext env; | 2244 LocalContext env; |
| 2218 env->Global()->Set(v8_str("obj"), | 2245 env->Global()->Set(v8_str("obj"), |
| 2219 templ->GetFunction()->NewInstance()); | 2246 templ->GetFunction()->NewInstance()); |
| 2220 Local<Script> script = v8_compile("obj[900]"); | 2247 Local<Script> script = v8_compile("obj[900]"); |
| 2221 CHECK_EQ(script->Run()->Int32Value(), 900); | 2248 CHECK_EQ(script->Run()->Int32Value(), 900); |
| 2222 } | 2249 } |
| 2223 | 2250 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 void CheckThisNamedPropertyEnumerator( | 2333 void CheckThisNamedPropertyEnumerator( |
| 2307 const v8::PropertyCallbackInfo<v8::Array>& info) { | 2334 const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 2308 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); | 2335 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); |
| 2309 ApiTestFuzzer::Fuzz(); | 2336 ApiTestFuzzer::Fuzz(); |
| 2310 CHECK(info.This()->Equals(bottom)); | 2337 CHECK(info.This()->Equals(bottom)); |
| 2311 } | 2338 } |
| 2312 | 2339 |
| 2313 | 2340 |
| 2314 THREADED_PROFILED_TEST(PropertyHandlerInPrototype) { | 2341 THREADED_PROFILED_TEST(PropertyHandlerInPrototype) { |
| 2315 LocalContext env; | 2342 LocalContext env; |
| 2316 v8::HandleScope scope(env->GetIsolate()); | 2343 v8::Isolate* isolate = env->GetIsolate(); |
| 2344 v8::HandleScope scope(isolate); |
| 2317 | 2345 |
| 2318 // Set up a prototype chain with three interceptors. | 2346 // Set up a prototype chain with three interceptors. |
| 2319 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 2347 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 2320 templ->InstanceTemplate()->SetIndexedPropertyHandler( | 2348 templ->InstanceTemplate()->SetIndexedPropertyHandler( |
| 2321 CheckThisIndexedPropertyHandler, | 2349 CheckThisIndexedPropertyHandler, |
| 2322 CheckThisIndexedPropertySetter, | 2350 CheckThisIndexedPropertySetter, |
| 2323 CheckThisIndexedPropertyQuery, | 2351 CheckThisIndexedPropertyQuery, |
| 2324 CheckThisIndexedPropertyDeleter, | 2352 CheckThisIndexedPropertyDeleter, |
| 2325 CheckThisIndexedPropertyEnumerator); | 2353 CheckThisIndexedPropertyEnumerator); |
| 2326 | 2354 |
| 2327 templ->InstanceTemplate()->SetNamedPropertyHandler( | 2355 templ->InstanceTemplate()->SetNamedPropertyHandler( |
| 2328 CheckThisNamedPropertyHandler, | 2356 CheckThisNamedPropertyHandler, |
| 2329 CheckThisNamedPropertySetter, | 2357 CheckThisNamedPropertySetter, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 static void PrePropertyHandlerQuery( | 2401 static void PrePropertyHandlerQuery( |
| 2374 Local<String> key, | 2402 Local<String> key, |
| 2375 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 2403 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 2376 if (v8_str("pre")->Equals(key)) { | 2404 if (v8_str("pre")->Equals(key)) { |
| 2377 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); | 2405 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); |
| 2378 } | 2406 } |
| 2379 } | 2407 } |
| 2380 | 2408 |
| 2381 | 2409 |
| 2382 THREADED_TEST(PrePropertyHandler) { | 2410 THREADED_TEST(PrePropertyHandler) { |
| 2383 v8::HandleScope scope(CcTest::isolate()); | 2411 v8::Isolate* isolate = CcTest::isolate(); |
| 2384 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); | 2412 v8::HandleScope scope(isolate); |
| 2413 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
| 2385 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, | 2414 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, |
| 2386 0, | 2415 0, |
| 2387 PrePropertyHandlerQuery); | 2416 PrePropertyHandlerQuery); |
| 2388 LocalContext env(NULL, desc->InstanceTemplate()); | 2417 LocalContext env(NULL, desc->InstanceTemplate()); |
| 2389 Script::Compile(v8_str( | 2418 Script::Compile(v8_str( |
| 2390 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); | 2419 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); |
| 2391 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run(); | 2420 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run(); |
| 2392 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); | 2421 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); |
| 2393 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); | 2422 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); |
| 2394 CHECK_EQ(v8_str("Object: on"), result_on); | 2423 CHECK_EQ(v8_str("Object: on"), result_on); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 } | 2459 } |
| 2431 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); | 2460 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); |
| 2432 v8::Handle<Value> function = | 2461 v8::Handle<Value> function = |
| 2433 args.This()->Get(v8_str("callFunctionRecursively")); | 2462 args.This()->Get(v8_str("callFunctionRecursively")); |
| 2434 args.GetReturnValue().Set( | 2463 args.GetReturnValue().Set( |
| 2435 function.As<Function>()->Call(args.This(), 0, NULL)); | 2464 function.As<Function>()->Call(args.This(), 0, NULL)); |
| 2436 } | 2465 } |
| 2437 | 2466 |
| 2438 | 2467 |
| 2439 THREADED_TEST(DeepCrossLanguageRecursion) { | 2468 THREADED_TEST(DeepCrossLanguageRecursion) { |
| 2440 v8::HandleScope scope(CcTest::isolate()); | 2469 v8::Isolate* isolate = CcTest::isolate(); |
| 2470 v8::HandleScope scope(isolate); |
| 2441 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 2471 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
| 2442 global->Set(v8_str("callScriptRecursively"), | 2472 global->Set(v8_str("callScriptRecursively"), |
| 2443 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); | 2473 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); |
| 2444 global->Set(v8_str("callFunctionRecursively"), | 2474 global->Set(v8_str("callFunctionRecursively"), |
| 2445 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); | 2475 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); |
| 2446 LocalContext env(NULL, global); | 2476 LocalContext env(NULL, global); |
| 2447 | 2477 |
| 2448 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); | 2478 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); |
| 2449 call_recursively_script = v8_compile("callScriptRecursively()"); | 2479 call_recursively_script = v8_compile("callScriptRecursively()"); |
| 2450 call_recursively_script->Run(); | 2480 call_recursively_script->Run(); |
| 2451 call_recursively_script = v8::Handle<Script>(); | 2481 call_recursively_script = v8::Handle<Script>(); |
| 2452 | 2482 |
| 2453 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); | 2483 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); |
| 2454 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); | 2484 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); |
| 2455 } | 2485 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2482 v8::Handle<Value> otto = Script::Compile(v8_str( | 2512 v8::Handle<Value> otto = Script::Compile(v8_str( |
| 2483 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); | 2513 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); |
| 2484 CHECK_EQ(v8_str("otto"), otto); | 2514 CHECK_EQ(v8_str("otto"), otto); |
| 2485 v8::Handle<Value> netto = Script::Compile(v8_str( | 2515 v8::Handle<Value> netto = Script::Compile(v8_str( |
| 2486 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); | 2516 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); |
| 2487 CHECK_EQ(v8_str("netto"), netto); | 2517 CHECK_EQ(v8_str("netto"), netto); |
| 2488 } | 2518 } |
| 2489 | 2519 |
| 2490 | 2520 |
| 2491 THREADED_TEST(FunctionPrototype) { | 2521 THREADED_TEST(FunctionPrototype) { |
| 2492 v8::HandleScope scope(CcTest::isolate()); | 2522 v8::Isolate* isolate = CcTest::isolate(); |
| 2493 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(); | 2523 v8::HandleScope scope(isolate); |
| 2524 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); |
| 2494 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); | 2525 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); |
| 2495 LocalContext env; | 2526 LocalContext env; |
| 2496 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); | 2527 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); |
| 2497 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); | 2528 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); |
| 2498 CHECK_EQ(script->Run()->Int32Value(), 321); | 2529 CHECK_EQ(script->Run()->Int32Value(), 321); |
| 2499 } | 2530 } |
| 2500 | 2531 |
| 2501 | 2532 |
| 2502 THREADED_TEST(InternalFields) { | 2533 THREADED_TEST(InternalFields) { |
| 2503 LocalContext env; | 2534 LocalContext env; |
| 2504 v8::HandleScope scope(env->GetIsolate()); | 2535 v8::Isolate* isolate = env->GetIsolate(); |
| 2536 v8::HandleScope scope(isolate); |
| 2505 | 2537 |
| 2506 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 2538 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 2507 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 2539 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 2508 instance_templ->SetInternalFieldCount(1); | 2540 instance_templ->SetInternalFieldCount(1); |
| 2509 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 2541 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 2510 CHECK_EQ(1, obj->InternalFieldCount()); | 2542 CHECK_EQ(1, obj->InternalFieldCount()); |
| 2511 CHECK(obj->GetInternalField(0)->IsUndefined()); | 2543 CHECK(obj->GetInternalField(0)->IsUndefined()); |
| 2512 obj->SetInternalField(0, v8_num(17)); | 2544 obj->SetInternalField(0, v8_num(17)); |
| 2513 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); | 2545 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); |
| 2514 } | 2546 } |
| 2515 | 2547 |
| 2516 | 2548 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2542 void* value) { | 2574 void* value) { |
| 2543 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2575 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
| 2544 obj->SetAlignedPointerInInternalField(0, value); | 2576 obj->SetAlignedPointerInInternalField(0, value); |
| 2545 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2577 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 2546 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); | 2578 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); |
| 2547 } | 2579 } |
| 2548 | 2580 |
| 2549 | 2581 |
| 2550 THREADED_TEST(InternalFieldsAlignedPointers) { | 2582 THREADED_TEST(InternalFieldsAlignedPointers) { |
| 2551 LocalContext env; | 2583 LocalContext env; |
| 2552 v8::HandleScope scope(env->GetIsolate()); | 2584 v8::Isolate* isolate = env->GetIsolate(); |
| 2585 v8::HandleScope scope(isolate); |
| 2553 | 2586 |
| 2554 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 2587 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 2555 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 2588 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 2556 instance_templ->SetInternalFieldCount(1); | 2589 instance_templ->SetInternalFieldCount(1); |
| 2557 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 2590 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
| 2558 CHECK_EQ(1, obj->InternalFieldCount()); | 2591 CHECK_EQ(1, obj->InternalFieldCount()); |
| 2559 | 2592 |
| 2560 CheckAlignedPointerInInternalField(obj, NULL); | 2593 CheckAlignedPointerInInternalField(obj, NULL); |
| 2561 | 2594 |
| 2562 int* heap_allocated = new int[100]; | 2595 int* heap_allocated = new int[100]; |
| 2563 CheckAlignedPointerInInternalField(obj, heap_allocated); | 2596 CheckAlignedPointerInInternalField(obj, heap_allocated); |
| 2564 delete[] heap_allocated; | 2597 delete[] heap_allocated; |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3173 | 3206 |
| 3174 static bool interceptor_for_hidden_properties_called; | 3207 static bool interceptor_for_hidden_properties_called; |
| 3175 static void InterceptorForHiddenProperties( | 3208 static void InterceptorForHiddenProperties( |
| 3176 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 3209 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 3177 interceptor_for_hidden_properties_called = true; | 3210 interceptor_for_hidden_properties_called = true; |
| 3178 } | 3211 } |
| 3179 | 3212 |
| 3180 | 3213 |
| 3181 THREADED_TEST(HiddenPropertiesWithInterceptors) { | 3214 THREADED_TEST(HiddenPropertiesWithInterceptors) { |
| 3182 LocalContext context; | 3215 LocalContext context; |
| 3183 v8::HandleScope scope(context->GetIsolate()); | 3216 v8::Isolate* isolate = context->GetIsolate(); |
| 3217 v8::HandleScope scope(isolate); |
| 3184 | 3218 |
| 3185 interceptor_for_hidden_properties_called = false; | 3219 interceptor_for_hidden_properties_called = false; |
| 3186 | 3220 |
| 3187 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 3221 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| 3188 | 3222 |
| 3189 // Associate an interceptor with an object and start setting hidden values. | 3223 // Associate an interceptor with an object and start setting hidden values. |
| 3190 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 3224 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
| 3191 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 3225 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
| 3192 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); | 3226 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); |
| 3193 Local<v8::Function> function = fun_templ->GetFunction(); | 3227 Local<v8::Function> function = fun_templ->GetFunction(); |
| 3194 Local<v8::Object> obj = function->NewInstance(); | 3228 Local<v8::Object> obj = function->NewInstance(); |
| 3195 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); | 3229 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); |
| 3196 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); | 3230 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); |
| 3197 CHECK(!interceptor_for_hidden_properties_called); | 3231 CHECK(!interceptor_for_hidden_properties_called); |
| 3198 } | 3232 } |
| 3199 | 3233 |
| 3200 | 3234 |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4191 v8::EscapableHandleScope scope(args.GetIsolate()); | 4225 v8::EscapableHandleScope scope(args.GetIsolate()); |
| 4192 ApiTestFuzzer::Fuzz(); | 4226 ApiTestFuzzer::Fuzz(); |
| 4193 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); | 4227 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); |
| 4194 for (int i = 0; i < args.Length(); i++) | 4228 for (int i = 0; i < args.Length(); i++) |
| 4195 result->Set(i, args[i]); | 4229 result->Set(i, args[i]); |
| 4196 args.GetReturnValue().Set(scope.Escape(result)); | 4230 args.GetReturnValue().Set(scope.Escape(result)); |
| 4197 } | 4231 } |
| 4198 | 4232 |
| 4199 | 4233 |
| 4200 THREADED_TEST(Vector) { | 4234 THREADED_TEST(Vector) { |
| 4201 v8::HandleScope scope(CcTest::isolate()); | 4235 v8::Isolate* isolate = CcTest::isolate(); |
| 4236 v8::HandleScope scope(isolate); |
| 4202 Local<ObjectTemplate> global = ObjectTemplate::New(); | 4237 Local<ObjectTemplate> global = ObjectTemplate::New(); |
| 4203 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); | 4238 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); |
| 4204 LocalContext context(0, global); | 4239 LocalContext context(0, global); |
| 4205 | 4240 |
| 4206 const char* fun = "f()"; | 4241 const char* fun = "f()"; |
| 4207 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); | 4242 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); |
| 4208 CHECK_EQ(0, a0->Length()); | 4243 CHECK_EQ(0, a0->Length()); |
| 4209 | 4244 |
| 4210 const char* fun2 = "f(11)"; | 4245 const char* fun2 = "f(11)"; |
| 4211 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); | 4246 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); |
| 4212 CHECK_EQ(1, a1->Length()); | 4247 CHECK_EQ(1, a1->Length()); |
| 4213 CHECK_EQ(11, a1->Get(0)->Int32Value()); | 4248 CHECK_EQ(11, a1->Get(0)->Int32Value()); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4377 // Set heap limits. | 4412 // Set heap limits. |
| 4378 static const int K = 1024; | 4413 static const int K = 1024; |
| 4379 v8::ResourceConstraints constraints; | 4414 v8::ResourceConstraints constraints; |
| 4380 constraints.set_max_young_space_size(256 * K); | 4415 constraints.set_max_young_space_size(256 * K); |
| 4381 constraints.set_max_old_space_size(5 * K * K); | 4416 constraints.set_max_old_space_size(5 * K * K); |
| 4382 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 4417 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
| 4383 | 4418 |
| 4384 v8::HandleScope scope(CcTest::isolate()); | 4419 v8::HandleScope scope(CcTest::isolate()); |
| 4385 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4420 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4386 templ->Set(v8_str("ProvokeOutOfMemory"), | 4421 templ->Set(v8_str("ProvokeOutOfMemory"), |
| 4387 v8::FunctionTemplate::New(ProvokeOutOfMemory)); | 4422 v8::FunctionTemplate::New(CcTest::isolate(), ProvokeOutOfMemory)); |
| 4388 LocalContext context(0, templ); | 4423 LocalContext context(0, templ); |
| 4389 v8::V8::IgnoreOutOfMemoryException(); | 4424 v8::V8::IgnoreOutOfMemoryException(); |
| 4390 Local<Value> result = CompileRun( | 4425 Local<Value> result = CompileRun( |
| 4391 "var thrown = false;" | 4426 "var thrown = false;" |
| 4392 "try {" | 4427 "try {" |
| 4393 " ProvokeOutOfMemory();" | 4428 " ProvokeOutOfMemory();" |
| 4394 "} catch (e) {" | 4429 "} catch (e) {" |
| 4395 " thrown = true;" | 4430 " thrown = true;" |
| 4396 "}"); | 4431 "}"); |
| 4397 // Check for out of memory state. | 4432 // Check for out of memory state. |
| 4398 CHECK(result.IsEmpty()); | 4433 CHECK(result.IsEmpty()); |
| 4399 CHECK(context->HasOutOfMemoryException()); | 4434 CHECK(context->HasOutOfMemoryException()); |
| 4400 } | 4435 } |
| 4401 | 4436 |
| 4402 | 4437 |
| 4438 void OOMCallback(const char* location, const char* message) { |
| 4439 exit(0); |
| 4440 } |
| 4441 |
| 4442 |
| 4403 TEST(HugeConsStringOutOfMemory) { | 4443 TEST(HugeConsStringOutOfMemory) { |
| 4404 // It's not possible to read a snapshot into a heap with different dimensions. | 4444 // It's not possible to read a snapshot into a heap with different dimensions. |
| 4405 if (i::Snapshot::IsEnabled()) return; | 4445 if (i::Snapshot::IsEnabled()) return; |
| 4406 // Set heap limits. | 4446 // Set heap limits. |
| 4407 static const int K = 1024; | 4447 static const int K = 1024; |
| 4408 v8::ResourceConstraints constraints; | 4448 v8::ResourceConstraints constraints; |
| 4409 constraints.set_max_young_space_size(256 * K); | 4449 constraints.set_max_young_space_size(256 * K); |
| 4410 constraints.set_max_old_space_size(4 * K * K); | 4450 constraints.set_max_old_space_size(4 * K * K); |
| 4411 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 4451 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
| 4412 | 4452 |
| 4413 // Execute a script that causes out of memory. | 4453 // Execute a script that causes out of memory. |
| 4414 v8::V8::IgnoreOutOfMemoryException(); | 4454 v8::V8::SetFatalErrorHandler(OOMCallback); |
| 4415 | 4455 |
| 4416 LocalContext context; | 4456 LocalContext context; |
| 4417 v8::HandleScope scope(context->GetIsolate()); | 4457 v8::HandleScope scope(context->GetIsolate()); |
| 4418 | 4458 |
| 4419 // Build huge string. This should fail with out of memory exception. | 4459 // Build huge string. This should fail with out of memory exception. |
| 4420 Local<Value> result = CompileRun( | 4460 CompileRun( |
| 4421 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" | 4461 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" |
| 4422 "for (var i = 0; i < 22; i++) { str = str + str; }"); | 4462 "for (var i = 0; i < 22; i++) { str = str + str; }"); |
| 4423 | 4463 |
| 4424 // Check for out of memory state. | 4464 CHECK(false); // Should not return. |
| 4425 CHECK(result.IsEmpty()); | |
| 4426 CHECK(context->HasOutOfMemoryException()); | |
| 4427 } | 4465 } |
| 4428 | 4466 |
| 4429 | 4467 |
| 4430 THREADED_TEST(ConstructCall) { | 4468 THREADED_TEST(ConstructCall) { |
| 4431 LocalContext context; | 4469 LocalContext context; |
| 4432 v8::HandleScope scope(context->GetIsolate()); | 4470 v8::HandleScope scope(context->GetIsolate()); |
| 4433 CompileRun( | 4471 CompileRun( |
| 4434 "function Foo() {" | 4472 "function Foo() {" |
| 4435 " var result = [];" | 4473 " var result = [];" |
| 4436 " for (var i = 0; i < arguments.length; i++) {" | 4474 " for (var i = 0; i < arguments.length; i++) {" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4657 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); | 4695 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); |
| 4658 CHECK(!try_catch.HasCaught() || result.IsEmpty()); | 4696 CHECK(!try_catch.HasCaught() || result.IsEmpty()); |
| 4659 args.GetReturnValue().Set(try_catch.HasCaught()); | 4697 args.GetReturnValue().Set(try_catch.HasCaught()); |
| 4660 } | 4698 } |
| 4661 | 4699 |
| 4662 | 4700 |
| 4663 THREADED_TEST(APICatch) { | 4701 THREADED_TEST(APICatch) { |
| 4664 v8::HandleScope scope(CcTest::isolate()); | 4702 v8::HandleScope scope(CcTest::isolate()); |
| 4665 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4703 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4666 templ->Set(v8_str("ThrowFromC"), | 4704 templ->Set(v8_str("ThrowFromC"), |
| 4667 v8::FunctionTemplate::New(ThrowFromC)); | 4705 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); |
| 4668 LocalContext context(0, templ); | 4706 LocalContext context(0, templ); |
| 4669 CompileRun( | 4707 CompileRun( |
| 4670 "var thrown = false;" | 4708 "var thrown = false;" |
| 4671 "try {" | 4709 "try {" |
| 4672 " ThrowFromC();" | 4710 " ThrowFromC();" |
| 4673 "} catch (e) {" | 4711 "} catch (e) {" |
| 4674 " thrown = true;" | 4712 " thrown = true;" |
| 4675 "}"); | 4713 "}"); |
| 4676 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); | 4714 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); |
| 4677 CHECK(thrown->BooleanValue()); | 4715 CHECK(thrown->BooleanValue()); |
| 4678 } | 4716 } |
| 4679 | 4717 |
| 4680 | 4718 |
| 4681 THREADED_TEST(APIThrowTryCatch) { | 4719 THREADED_TEST(APIThrowTryCatch) { |
| 4682 v8::HandleScope scope(CcTest::isolate()); | 4720 v8::HandleScope scope(CcTest::isolate()); |
| 4683 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4721 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4684 templ->Set(v8_str("ThrowFromC"), | 4722 templ->Set(v8_str("ThrowFromC"), |
| 4685 v8::FunctionTemplate::New(ThrowFromC)); | 4723 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); |
| 4686 LocalContext context(0, templ); | 4724 LocalContext context(0, templ); |
| 4687 v8::TryCatch try_catch; | 4725 v8::TryCatch try_catch; |
| 4688 CompileRun("ThrowFromC();"); | 4726 CompileRun("ThrowFromC();"); |
| 4689 CHECK(try_catch.HasCaught()); | 4727 CHECK(try_catch.HasCaught()); |
| 4690 } | 4728 } |
| 4691 | 4729 |
| 4692 | 4730 |
| 4693 // Test that a try-finally block doesn't shadow a try-catch block | 4731 // Test that a try-finally block doesn't shadow a try-catch block |
| 4694 // when setting up an external handler. | 4732 // when setting up an external handler. |
| 4695 // | 4733 // |
| 4696 // BUG(271): Some of the exception propagation does not work on the | 4734 // BUG(271): Some of the exception propagation does not work on the |
| 4697 // ARM simulator because the simulator separates the C++ stack and the | 4735 // ARM simulator because the simulator separates the C++ stack and the |
| 4698 // JS stack. This test therefore fails on the simulator. The test is | 4736 // JS stack. This test therefore fails on the simulator. The test is |
| 4699 // not threaded to allow the threading tests to run on the simulator. | 4737 // not threaded to allow the threading tests to run on the simulator. |
| 4700 TEST(TryCatchInTryFinally) { | 4738 TEST(TryCatchInTryFinally) { |
| 4701 v8::HandleScope scope(CcTest::isolate()); | 4739 v8::HandleScope scope(CcTest::isolate()); |
| 4702 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4740 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4703 templ->Set(v8_str("CCatcher"), | 4741 templ->Set(v8_str("CCatcher"), |
| 4704 v8::FunctionTemplate::New(CCatcher)); | 4742 v8::FunctionTemplate::New(CcTest::isolate(), CCatcher)); |
| 4705 LocalContext context(0, templ); | 4743 LocalContext context(0, templ); |
| 4706 Local<Value> result = CompileRun("try {" | 4744 Local<Value> result = CompileRun("try {" |
| 4707 " try {" | 4745 " try {" |
| 4708 " CCatcher('throw 7;');" | 4746 " CCatcher('throw 7;');" |
| 4709 " } finally {" | 4747 " } finally {" |
| 4710 " }" | 4748 " }" |
| 4711 "} catch (e) {" | 4749 "} catch (e) {" |
| 4712 "}"); | 4750 "}"); |
| 4713 CHECK(result->IsTrue()); | 4751 CHECK(result->IsTrue()); |
| 4714 } | 4752 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4725 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { | 4763 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 4726 ApiTestFuzzer::Fuzz(); | 4764 ApiTestFuzzer::Fuzz(); |
| 4727 CHECK(false); | 4765 CHECK(false); |
| 4728 } | 4766 } |
| 4729 | 4767 |
| 4730 | 4768 |
| 4731 // Test that overwritten methods are not invoked on uncaught exception | 4769 // Test that overwritten methods are not invoked on uncaught exception |
| 4732 // formatting. However, they are invoked when performing normal error | 4770 // formatting. However, they are invoked when performing normal error |
| 4733 // string conversions. | 4771 // string conversions. |
| 4734 TEST(APIThrowMessageOverwrittenToString) { | 4772 TEST(APIThrowMessageOverwrittenToString) { |
| 4735 v8::HandleScope scope(CcTest::isolate()); | 4773 v8::Isolate* isolate = CcTest::isolate(); |
| 4774 v8::HandleScope scope(isolate); |
| 4736 v8::V8::AddMessageListener(check_reference_error_message); | 4775 v8::V8::AddMessageListener(check_reference_error_message); |
| 4737 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4776 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4738 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail)); | 4777 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); |
| 4739 LocalContext context(NULL, templ); | 4778 LocalContext context(NULL, templ); |
| 4740 CompileRun("asdf;"); | 4779 CompileRun("asdf;"); |
| 4741 CompileRun("var limit = {};" | 4780 CompileRun("var limit = {};" |
| 4742 "limit.valueOf = fail;" | 4781 "limit.valueOf = fail;" |
| 4743 "Error.stackTraceLimit = limit;"); | 4782 "Error.stackTraceLimit = limit;"); |
| 4744 CompileRun("asdf"); | 4783 CompileRun("asdf"); |
| 4745 CompileRun("Array.prototype.pop = fail;"); | 4784 CompileRun("Array.prototype.pop = fail;"); |
| 4746 CompileRun("Object.prototype.hasOwnProperty = fail;"); | 4785 CompileRun("Object.prototype.hasOwnProperty = fail;"); |
| 4747 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); | 4786 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); |
| 4748 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); | 4787 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4853 message_received = true; | 4892 message_received = true; |
| 4854 } | 4893 } |
| 4855 | 4894 |
| 4856 | 4895 |
| 4857 TEST(APIThrowMessage) { | 4896 TEST(APIThrowMessage) { |
| 4858 message_received = false; | 4897 message_received = false; |
| 4859 v8::HandleScope scope(CcTest::isolate()); | 4898 v8::HandleScope scope(CcTest::isolate()); |
| 4860 v8::V8::AddMessageListener(receive_message); | 4899 v8::V8::AddMessageListener(receive_message); |
| 4861 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4900 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4862 templ->Set(v8_str("ThrowFromC"), | 4901 templ->Set(v8_str("ThrowFromC"), |
| 4863 v8::FunctionTemplate::New(ThrowFromC)); | 4902 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); |
| 4864 LocalContext context(0, templ); | 4903 LocalContext context(0, templ); |
| 4865 CompileRun("ThrowFromC();"); | 4904 CompileRun("ThrowFromC();"); |
| 4866 CHECK(message_received); | 4905 CHECK(message_received); |
| 4867 v8::V8::RemoveMessageListeners(receive_message); | 4906 v8::V8::RemoveMessageListeners(receive_message); |
| 4868 } | 4907 } |
| 4869 | 4908 |
| 4870 | 4909 |
| 4871 TEST(APIThrowMessageAndVerboseTryCatch) { | 4910 TEST(APIThrowMessageAndVerboseTryCatch) { |
| 4872 message_received = false; | 4911 message_received = false; |
| 4873 v8::HandleScope scope(CcTest::isolate()); | 4912 v8::HandleScope scope(CcTest::isolate()); |
| 4874 v8::V8::AddMessageListener(receive_message); | 4913 v8::V8::AddMessageListener(receive_message); |
| 4875 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4914 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4876 templ->Set(v8_str("ThrowFromC"), | 4915 templ->Set(v8_str("ThrowFromC"), |
| 4877 v8::FunctionTemplate::New(ThrowFromC)); | 4916 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); |
| 4878 LocalContext context(0, templ); | 4917 LocalContext context(0, templ); |
| 4879 v8::TryCatch try_catch; | 4918 v8::TryCatch try_catch; |
| 4880 try_catch.SetVerbose(true); | 4919 try_catch.SetVerbose(true); |
| 4881 Local<Value> result = CompileRun("ThrowFromC();"); | 4920 Local<Value> result = CompileRun("ThrowFromC();"); |
| 4882 CHECK(try_catch.HasCaught()); | 4921 CHECK(try_catch.HasCaught()); |
| 4883 CHECK(result.IsEmpty()); | 4922 CHECK(result.IsEmpty()); |
| 4884 CHECK(message_received); | 4923 CHECK(message_received); |
| 4885 v8::V8::RemoveMessageListeners(receive_message); | 4924 v8::V8::RemoveMessageListeners(receive_message); |
| 4886 } | 4925 } |
| 4887 | 4926 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4898 CHECK(result.IsEmpty()); | 4937 CHECK(result.IsEmpty()); |
| 4899 CHECK(message_received); | 4938 CHECK(message_received); |
| 4900 v8::V8::RemoveMessageListeners(receive_message); | 4939 v8::V8::RemoveMessageListeners(receive_message); |
| 4901 } | 4940 } |
| 4902 | 4941 |
| 4903 | 4942 |
| 4904 THREADED_TEST(ExternalScriptException) { | 4943 THREADED_TEST(ExternalScriptException) { |
| 4905 v8::HandleScope scope(CcTest::isolate()); | 4944 v8::HandleScope scope(CcTest::isolate()); |
| 4906 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4945 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 4907 templ->Set(v8_str("ThrowFromC"), | 4946 templ->Set(v8_str("ThrowFromC"), |
| 4908 v8::FunctionTemplate::New(ThrowFromC)); | 4947 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); |
| 4909 LocalContext context(0, templ); | 4948 LocalContext context(0, templ); |
| 4910 | 4949 |
| 4911 v8::TryCatch try_catch; | 4950 v8::TryCatch try_catch; |
| 4912 Local<Script> script | 4951 Local<Script> script |
| 4913 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); | 4952 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); |
| 4914 Local<Value> result = script->Run(); | 4953 Local<Value> result = script->Run(); |
| 4915 CHECK(result.IsEmpty()); | 4954 CHECK(result.IsEmpty()); |
| 4916 CHECK(try_catch.HasCaught()); | 4955 CHECK(try_catch.HasCaught()); |
| 4917 String::Utf8Value exception_value(try_catch.Exception()); | 4956 String::Utf8Value exception_value(try_catch.Exception()); |
| 4918 CHECK_EQ("konto", *exception_value); | 4957 CHECK_EQ("konto", *exception_value); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5000 // | 5039 // |
| 5001 // Each entry is an activation, either JS or C. The index is the count at that | 5040 // Each entry is an activation, either JS or C. The index is the count at that |
| 5002 // level. Stars identify activations with exception handlers, the @ identifies | 5041 // level. Stars identify activations with exception handlers, the @ identifies |
| 5003 // the exception handler that should catch the exception. | 5042 // the exception handler that should catch the exception. |
| 5004 // | 5043 // |
| 5005 // BUG(271): Some of the exception propagation does not work on the | 5044 // BUG(271): Some of the exception propagation does not work on the |
| 5006 // ARM simulator because the simulator separates the C++ stack and the | 5045 // ARM simulator because the simulator separates the C++ stack and the |
| 5007 // JS stack. This test therefore fails on the simulator. The test is | 5046 // JS stack. This test therefore fails on the simulator. The test is |
| 5008 // not threaded to allow the threading tests to run on the simulator. | 5047 // not threaded to allow the threading tests to run on the simulator. |
| 5009 TEST(ExceptionOrder) { | 5048 TEST(ExceptionOrder) { |
| 5010 v8::HandleScope scope(CcTest::isolate()); | 5049 v8::Isolate* isolate = CcTest::isolate(); |
| 5050 v8::HandleScope scope(isolate); |
| 5011 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5051 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5012 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); | 5052 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck)); |
| 5013 templ->Set(v8_str("CThrowCountDown"), | 5053 templ->Set(v8_str("CThrowCountDown"), |
| 5014 v8::FunctionTemplate::New(CThrowCountDown)); | 5054 v8::FunctionTemplate::New(isolate, CThrowCountDown)); |
| 5015 LocalContext context(0, templ); | 5055 LocalContext context(0, templ); |
| 5016 CompileRun( | 5056 CompileRun( |
| 5017 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" | 5057 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" |
| 5018 " if (count == 0) throw 'FromJS';" | 5058 " if (count == 0) throw 'FromJS';" |
| 5019 " if (count % jsInterval == 0) {" | 5059 " if (count % jsInterval == 0) {" |
| 5020 " try {" | 5060 " try {" |
| 5021 " var value = CThrowCountDown(count - 1," | 5061 " var value = CThrowCountDown(count - 1," |
| 5022 " jsInterval," | 5062 " jsInterval," |
| 5023 " cInterval," | 5063 " cInterval," |
| 5024 " expected);" | 5064 " expected);" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5064 | 5104 |
| 5065 | 5105 |
| 5066 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5106 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 5067 ApiTestFuzzer::Fuzz(); | 5107 ApiTestFuzzer::Fuzz(); |
| 5068 CHECK_EQ(1, args.Length()); | 5108 CHECK_EQ(1, args.Length()); |
| 5069 args.GetIsolate()->ThrowException(args[0]); | 5109 args.GetIsolate()->ThrowException(args[0]); |
| 5070 } | 5110 } |
| 5071 | 5111 |
| 5072 | 5112 |
| 5073 THREADED_TEST(ThrowValues) { | 5113 THREADED_TEST(ThrowValues) { |
| 5074 v8::HandleScope scope(CcTest::isolate()); | 5114 v8::Isolate* isolate = CcTest::isolate(); |
| 5115 v8::HandleScope scope(isolate); |
| 5075 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5116 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5076 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue)); | 5117 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); |
| 5077 LocalContext context(0, templ); | 5118 LocalContext context(0, templ); |
| 5078 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 5119 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
| 5079 "function Run(obj) {" | 5120 "function Run(obj) {" |
| 5080 " try {" | 5121 " try {" |
| 5081 " Throw(obj);" | 5122 " Throw(obj);" |
| 5082 " } catch (e) {" | 5123 " } catch (e) {" |
| 5083 " return e;" | 5124 " return e;" |
| 5084 " }" | 5125 " }" |
| 5085 " return 'no exception';" | 5126 " return 'no exception';" |
| 5086 "}" | 5127 "}" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5133 } | 5174 } |
| 5134 | 5175 |
| 5135 | 5176 |
| 5136 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5177 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 5137 v8::TryCatch try_catch; | 5178 v8::TryCatch try_catch; |
| 5138 } | 5179 } |
| 5139 | 5180 |
| 5140 | 5181 |
| 5141 THREADED_TEST(TryCatchAndFinally) { | 5182 THREADED_TEST(TryCatchAndFinally) { |
| 5142 LocalContext context; | 5183 LocalContext context; |
| 5143 v8::HandleScope scope(context->GetIsolate()); | 5184 v8::Isolate* isolate = context->GetIsolate(); |
| 5185 v8::HandleScope scope(isolate); |
| 5144 context->Global()->Set( | 5186 context->Global()->Set( |
| 5145 v8_str("native_with_try_catch"), | 5187 v8_str("native_with_try_catch"), |
| 5146 v8::FunctionTemplate::New(WithTryCatch)->GetFunction()); | 5188 v8::FunctionTemplate::New(isolate, WithTryCatch)->GetFunction()); |
| 5147 v8::TryCatch try_catch; | 5189 v8::TryCatch try_catch; |
| 5148 CHECK(!try_catch.HasCaught()); | 5190 CHECK(!try_catch.HasCaught()); |
| 5149 CompileRun( | 5191 CompileRun( |
| 5150 "try {\n" | 5192 "try {\n" |
| 5151 " throw new Error('a');\n" | 5193 " throw new Error('a');\n" |
| 5152 "} finally {\n" | 5194 "} finally {\n" |
| 5153 " native_with_try_catch();\n" | 5195 " native_with_try_catch();\n" |
| 5154 "}\n"); | 5196 "}\n"); |
| 5155 CHECK(try_catch.HasCaught()); | 5197 CHECK(try_catch.HasCaught()); |
| 5156 } | 5198 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5202 try_catch.ReThrow(); | 5244 try_catch.ReThrow(); |
| 5203 } | 5245 } |
| 5204 | 5246 |
| 5205 | 5247 |
| 5206 // This test ensures that an outer TryCatch in the following situation: | 5248 // This test ensures that an outer TryCatch in the following situation: |
| 5207 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError | 5249 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError |
| 5208 // does not clobber the Message object generated for the inner TryCatch. | 5250 // does not clobber the Message object generated for the inner TryCatch. |
| 5209 // This exercises the ability of TryCatch.ReThrow() to restore the | 5251 // This exercises the ability of TryCatch.ReThrow() to restore the |
| 5210 // inner pending Message before throwing the exception again. | 5252 // inner pending Message before throwing the exception again. |
| 5211 TEST(TryCatchMixedNesting) { | 5253 TEST(TryCatchMixedNesting) { |
| 5212 v8::HandleScope scope(CcTest::isolate()); | 5254 v8::Isolate* isolate = CcTest::isolate(); |
| 5255 v8::HandleScope scope(isolate); |
| 5213 v8::V8::Initialize(); | 5256 v8::V8::Initialize(); |
| 5214 v8::TryCatch try_catch; | 5257 v8::TryCatch try_catch; |
| 5215 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5258 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5216 templ->Set(v8_str("TryCatchMixedNestingHelper"), | 5259 templ->Set(v8_str("TryCatchMixedNestingHelper"), |
| 5217 v8::FunctionTemplate::New(TryCatchMixedNestingHelper)); | 5260 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); |
| 5218 LocalContext context(0, templ); | 5261 LocalContext context(0, templ); |
| 5219 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); | 5262 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); |
| 5220 TryCatchMixedNestingCheck(&try_catch); | 5263 TryCatchMixedNestingCheck(&try_catch); |
| 5221 } | 5264 } |
| 5222 | 5265 |
| 5223 | 5266 |
| 5224 THREADED_TEST(Equality) { | 5267 THREADED_TEST(Equality) { |
| 5225 LocalContext context; | 5268 LocalContext context; |
| 5226 v8::Isolate* isolate = context->GetIsolate(); | 5269 v8::Isolate* isolate = context->GetIsolate(); |
| 5227 v8::HandleScope scope(context->GetIsolate()); | 5270 v8::HandleScope scope(context->GetIsolate()); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5710 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5753 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 5711 // Set x on the prototype object and do not handle the get request. | 5754 // Set x on the prototype object and do not handle the get request. |
| 5712 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); | 5755 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); |
| 5713 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); | 5756 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); |
| 5714 } | 5757 } |
| 5715 | 5758 |
| 5716 | 5759 |
| 5717 // This is a regression test for http://crbug.com/20104. Map | 5760 // This is a regression test for http://crbug.com/20104. Map |
| 5718 // transitions should not interfere with post interceptor lookup. | 5761 // transitions should not interfere with post interceptor lookup. |
| 5719 THREADED_TEST(NamedInterceptorMapTransitionRead) { | 5762 THREADED_TEST(NamedInterceptorMapTransitionRead) { |
| 5720 v8::HandleScope scope(CcTest::isolate()); | 5763 v8::Isolate* isolate = CcTest::isolate(); |
| 5721 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); | 5764 v8::HandleScope scope(isolate); |
| 5765 Local<v8::FunctionTemplate> function_template = |
| 5766 v8::FunctionTemplate::New(isolate); |
| 5722 Local<v8::ObjectTemplate> instance_template | 5767 Local<v8::ObjectTemplate> instance_template |
| 5723 = function_template->InstanceTemplate(); | 5768 = function_template->InstanceTemplate(); |
| 5724 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); | 5769 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); |
| 5725 LocalContext context; | 5770 LocalContext context; |
| 5726 context->Global()->Set(v8_str("F"), function_template->GetFunction()); | 5771 context->Global()->Set(v8_str("F"), function_template->GetFunction()); |
| 5727 // Create an instance of F and introduce a map transition for x. | 5772 // Create an instance of F and introduce a map transition for x. |
| 5728 CompileRun("var o = new F(); o.x = 23;"); | 5773 CompileRun("var o = new F(); o.x = 23;"); |
| 5729 // Create an instance of F and invoke the getter. The result should be 23. | 5774 // Create an instance of F and invoke the getter. The result should be 23. |
| 5730 Local<Value> result = CompileRun("o = new F(); o.x"); | 5775 Local<Value> result = CompileRun("o = new F(); o.x"); |
| 5731 CHECK_EQ(result->Int32Value(), 23); | 5776 CHECK_EQ(result->Int32Value(), 23); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6167 " }" | 6212 " }" |
| 6168 " 'PASSED'" | 6213 " 'PASSED'" |
| 6169 "} catch(e) {" | 6214 "} catch(e) {" |
| 6170 " e" | 6215 " e" |
| 6171 "}"; | 6216 "}"; |
| 6172 ExpectString(code, "PASSED"); | 6217 ExpectString(code, "PASSED"); |
| 6173 } | 6218 } |
| 6174 | 6219 |
| 6175 | 6220 |
| 6176 THREADED_TEST(MultiContexts) { | 6221 THREADED_TEST(MultiContexts) { |
| 6177 v8::HandleScope scope(CcTest::isolate()); | 6222 v8::Isolate* isolate = CcTest::isolate(); |
| 6223 v8::HandleScope scope(isolate); |
| 6178 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 6224 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); |
| 6179 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); | 6225 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate, |
| 6226 DummyCallHandler)); |
| 6180 | 6227 |
| 6181 Local<String> password = v8_str("Password"); | 6228 Local<String> password = v8_str("Password"); |
| 6182 | 6229 |
| 6183 // Create an environment | 6230 // Create an environment |
| 6184 LocalContext context0(0, templ); | 6231 LocalContext context0(0, templ); |
| 6185 context0->SetSecurityToken(password); | 6232 context0->SetSecurityToken(password); |
| 6186 v8::Handle<v8::Object> global0 = context0->Global(); | 6233 v8::Handle<v8::Object> global0 = context0->Global(); |
| 6187 global0->Set(v8_str("custom"), v8_num(1234)); | 6234 global0->Set(v8_str("custom"), v8_num(1234)); |
| 6188 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); | 6235 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); |
| 6189 | 6236 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6256 LocalContext env1; | 6303 LocalContext env1; |
| 6257 Local<Script> script1 = Script::Compile(source); | 6304 Local<Script> script1 = Script::Compile(source); |
| 6258 CHECK_EQ(8901.0, script1->Run()->NumberValue()); | 6305 CHECK_EQ(8901.0, script1->Run()->NumberValue()); |
| 6259 } | 6306 } |
| 6260 | 6307 |
| 6261 | 6308 |
| 6262 THREADED_TEST(UndetectableObject) { | 6309 THREADED_TEST(UndetectableObject) { |
| 6263 LocalContext env; | 6310 LocalContext env; |
| 6264 v8::HandleScope scope(env->GetIsolate()); | 6311 v8::HandleScope scope(env->GetIsolate()); |
| 6265 | 6312 |
| 6266 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); | 6313 Local<v8::FunctionTemplate> desc = |
| 6314 v8::FunctionTemplate::New(env->GetIsolate()); |
| 6267 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6315 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
| 6268 | 6316 |
| 6269 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6317 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
| 6270 env->Global()->Set(v8_str("undetectable"), obj); | 6318 env->Global()->Set(v8_str("undetectable"), obj); |
| 6271 | 6319 |
| 6272 ExpectString("undetectable.toString()", "[object Object]"); | 6320 ExpectString("undetectable.toString()", "[object Object]"); |
| 6273 ExpectString("typeof undetectable", "undefined"); | 6321 ExpectString("typeof undetectable", "undefined"); |
| 6274 ExpectString("typeof(undetectable)", "undefined"); | 6322 ExpectString("typeof(undetectable)", "undefined"); |
| 6275 ExpectBoolean("typeof undetectable == 'undefined'", true); | 6323 ExpectBoolean("typeof undetectable == 'undefined'", true); |
| 6276 ExpectBoolean("typeof undetectable == 'object'", false); | 6324 ExpectBoolean("typeof undetectable == 'object'", false); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6297 ExpectBoolean("undetectable===null", false); | 6345 ExpectBoolean("undetectable===null", false); |
| 6298 ExpectBoolean("null===undetectable", false); | 6346 ExpectBoolean("null===undetectable", false); |
| 6299 ExpectBoolean("undetectable===undefined", false); | 6347 ExpectBoolean("undetectable===undefined", false); |
| 6300 ExpectBoolean("undefined===undetectable", false); | 6348 ExpectBoolean("undefined===undetectable", false); |
| 6301 ExpectBoolean("undetectable===undetectable", true); | 6349 ExpectBoolean("undetectable===undetectable", true); |
| 6302 } | 6350 } |
| 6303 | 6351 |
| 6304 | 6352 |
| 6305 THREADED_TEST(VoidLiteral) { | 6353 THREADED_TEST(VoidLiteral) { |
| 6306 LocalContext env; | 6354 LocalContext env; |
| 6307 v8::HandleScope scope(env->GetIsolate()); | 6355 v8::Isolate* isolate = env->GetIsolate(); |
| 6356 v8::HandleScope scope(isolate); |
| 6308 | 6357 |
| 6309 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); | 6358 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
| 6310 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6359 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
| 6311 | 6360 |
| 6312 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6361 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
| 6313 env->Global()->Set(v8_str("undetectable"), obj); | 6362 env->Global()->Set(v8_str("undetectable"), obj); |
| 6314 | 6363 |
| 6315 ExpectBoolean("undefined == void 0", true); | 6364 ExpectBoolean("undefined == void 0", true); |
| 6316 ExpectBoolean("undetectable == void 0", true); | 6365 ExpectBoolean("undetectable == void 0", true); |
| 6317 ExpectBoolean("null == void 0", true); | 6366 ExpectBoolean("null == void 0", true); |
| 6318 ExpectBoolean("undefined === void 0", true); | 6367 ExpectBoolean("undefined === void 0", true); |
| 6319 ExpectBoolean("undetectable === void 0", false); | 6368 ExpectBoolean("undetectable === void 0", false); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6340 " } catch(e) {" | 6389 " } catch(e) {" |
| 6341 " return e.toString();" | 6390 " return e.toString();" |
| 6342 " }" | 6391 " }" |
| 6343 "})()", | 6392 "})()", |
| 6344 "ReferenceError: x is not defined"); | 6393 "ReferenceError: x is not defined"); |
| 6345 } | 6394 } |
| 6346 | 6395 |
| 6347 | 6396 |
| 6348 THREADED_TEST(ExtensibleOnUndetectable) { | 6397 THREADED_TEST(ExtensibleOnUndetectable) { |
| 6349 LocalContext env; | 6398 LocalContext env; |
| 6350 v8::HandleScope scope(env->GetIsolate()); | 6399 v8::Isolate* isolate = env->GetIsolate(); |
| 6400 v8::HandleScope scope(isolate); |
| 6351 | 6401 |
| 6352 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); | 6402 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
| 6353 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6403 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
| 6354 | 6404 |
| 6355 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6405 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); |
| 6356 env->Global()->Set(v8_str("undetectable"), obj); | 6406 env->Global()->Set(v8_str("undetectable"), obj); |
| 6357 | 6407 |
| 6358 Local<String> source = v8_str("undetectable.x = 42;" | 6408 Local<String> source = v8_str("undetectable.x = 42;" |
| 6359 "undetectable.x"); | 6409 "undetectable.x"); |
| 6360 | 6410 |
| 6361 Local<Script> script = Script::Compile(source); | 6411 Local<Script> script = Script::Compile(source); |
| 6362 | 6412 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6447 " testBool();" | 6497 " testBool();" |
| 6448 "}\n" | 6498 "}\n" |
| 6449 "\"PASS\"", | 6499 "\"PASS\"", |
| 6450 "PASS"); | 6500 "PASS"); |
| 6451 } | 6501 } |
| 6452 | 6502 |
| 6453 | 6503 |
| 6454 template <typename T> static void USE(T) { } | 6504 template <typename T> static void USE(T) { } |
| 6455 | 6505 |
| 6456 | 6506 |
| 6457 // This test is not intended to be run, just type checked. | 6507 // The point of this test is type checking. We run it only so compilers |
| 6458 static inline void PersistentHandles(v8::Isolate* isolate) { | 6508 // don't complain about an unused function. |
| 6459 USE(PersistentHandles); | 6509 TEST(PersistentHandles) { |
| 6510 LocalContext env; |
| 6511 v8::Isolate* isolate = CcTest::isolate(); |
| 6512 v8::HandleScope scope(isolate); |
| 6460 Local<String> str = v8_str("foo"); | 6513 Local<String> str = v8_str("foo"); |
| 6461 v8::Persistent<String> p_str(isolate, str); | 6514 v8::Persistent<String> p_str(isolate, str); |
| 6462 p_str.Reset(); | 6515 p_str.Reset(); |
| 6463 Local<Script> scr = Script::Compile(v8_str("")); | 6516 Local<Script> scr = Script::Compile(v8_str("")); |
| 6464 v8::Persistent<Script> p_scr(isolate, scr); | 6517 v8::Persistent<Script> p_scr(isolate, scr); |
| 6465 p_scr.Reset(); | 6518 p_scr.Reset(); |
| 6466 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6519 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 6467 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); | 6520 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); |
| 6468 p_templ.Reset(); | 6521 p_templ.Reset(); |
| 6469 } | 6522 } |
| 6470 | 6523 |
| 6471 | 6524 |
| 6472 static void HandleLogDelegator( | 6525 static void HandleLogDelegator( |
| 6473 const v8::FunctionCallbackInfo<v8::Value>& args) { | 6526 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 6474 ApiTestFuzzer::Fuzz(); | 6527 ApiTestFuzzer::Fuzz(); |
| 6475 } | 6528 } |
| 6476 | 6529 |
| 6477 | 6530 |
| 6478 THREADED_TEST(GlobalObjectTemplate) { | 6531 THREADED_TEST(GlobalObjectTemplate) { |
| 6479 v8::Isolate* isolate = CcTest::isolate(); | 6532 v8::Isolate* isolate = CcTest::isolate(); |
| 6480 v8::HandleScope handle_scope(isolate); | 6533 v8::HandleScope handle_scope(isolate); |
| 6481 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 6534 Local<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 6482 global_template->Set(v8_str("JSNI_Log"), | 6535 global_template->Set(v8_str("JSNI_Log"), |
| 6483 v8::FunctionTemplate::New(HandleLogDelegator)); | 6536 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); |
| 6484 v8::Local<Context> context = Context::New(isolate, 0, global_template); | 6537 v8::Local<Context> context = Context::New(isolate, 0, global_template); |
| 6485 Context::Scope context_scope(context); | 6538 Context::Scope context_scope(context); |
| 6486 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); | 6539 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); |
| 6487 } | 6540 } |
| 6488 | 6541 |
| 6489 | 6542 |
| 6490 static const char* kSimpleExtensionSource = | 6543 static const char* kSimpleExtensionSource = |
| 6491 "function Foo() {" | 6544 "function Foo() {" |
| 6492 " return 4;" | 6545 " return 4;" |
| 6493 "}"; | 6546 "}"; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6706 public: | 6759 public: |
| 6707 NativeFunctionExtension(const char* name, | 6760 NativeFunctionExtension(const char* name, |
| 6708 const char* source, | 6761 const char* source, |
| 6709 v8::FunctionCallback fun = &Echo) | 6762 v8::FunctionCallback fun = &Echo) |
| 6710 : Extension(name, source), | 6763 : Extension(name, source), |
| 6711 function_(fun) { } | 6764 function_(fun) { } |
| 6712 | 6765 |
| 6713 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 6766 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 6714 v8::Isolate* isolate, | 6767 v8::Isolate* isolate, |
| 6715 v8::Handle<v8::String> name) { | 6768 v8::Handle<v8::String> name) { |
| 6716 return v8::FunctionTemplate::New(function_); | 6769 return v8::FunctionTemplate::New(isolate, function_); |
| 6717 } | 6770 } |
| 6718 | 6771 |
| 6719 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { | 6772 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 6720 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); | 6773 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); |
| 6721 } | 6774 } |
| 6722 private: | 6775 private: |
| 6723 v8::FunctionCallback function_; | 6776 v8::FunctionCallback function_; |
| 6724 }; | 6777 }; |
| 6725 | 6778 |
| 6726 | 6779 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6836 v8::Isolate* isolate, | 6889 v8::Isolate* isolate, |
| 6837 v8::Handle<String> name); | 6890 v8::Handle<String> name); |
| 6838 }; | 6891 }; |
| 6839 | 6892 |
| 6840 | 6893 |
| 6841 static int lookup_count = 0; | 6894 static int lookup_count = 0; |
| 6842 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( | 6895 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( |
| 6843 v8::Isolate* isolate, v8::Handle<String> name) { | 6896 v8::Isolate* isolate, v8::Handle<String> name) { |
| 6844 lookup_count++; | 6897 lookup_count++; |
| 6845 if (name->Equals(v8_str("A"))) { | 6898 if (name->Equals(v8_str("A"))) { |
| 6846 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(8)); | 6899 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(8)); |
| 6847 } else if (name->Equals(v8_str("B"))) { | 6900 } else if (name->Equals(v8_str("B"))) { |
| 6848 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(7)); | 6901 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(7)); |
| 6849 } else if (name->Equals(v8_str("C"))) { | 6902 } else if (name->Equals(v8_str("C"))) { |
| 6850 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6)); | 6903 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(6)); |
| 6851 } else { | 6904 } else { |
| 6852 return v8::Handle<v8::FunctionTemplate>(); | 6905 return v8::Handle<v8::FunctionTemplate>(); |
| 6853 } | 6906 } |
| 6854 } | 6907 } |
| 6855 | 6908 |
| 6856 | 6909 |
| 6857 THREADED_TEST(FunctionLookup) { | 6910 THREADED_TEST(FunctionLookup) { |
| 6858 v8::RegisterExtension(new FunctionExtension()); | 6911 v8::RegisterExtension(new FunctionExtension()); |
| 6859 v8::HandleScope handle_scope(CcTest::isolate()); | 6912 v8::HandleScope handle_scope(CcTest::isolate()); |
| 6860 static const char* exts[1] = { "functiontest" }; | 6913 static const char* exts[1] = { "functiontest" }; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6915 | 6968 |
| 6916 | 6969 |
| 6917 static const char* js_code_causing_huge_string_flattening = | 6970 static const char* js_code_causing_huge_string_flattening = |
| 6918 "var str = 'X';" | 6971 "var str = 'X';" |
| 6919 "for (var i = 0; i < 30; i++) {" | 6972 "for (var i = 0; i < 30; i++) {" |
| 6920 " str = str + str;" | 6973 " str = str + str;" |
| 6921 "}" | 6974 "}" |
| 6922 "str.match(/X/);"; | 6975 "str.match(/X/);"; |
| 6923 | 6976 |
| 6924 | 6977 |
| 6925 void OOMCallback(const char* location, const char* message) { | |
| 6926 exit(0); | |
| 6927 } | |
| 6928 | |
| 6929 | |
| 6930 TEST(RegexpOutOfMemory) { | 6978 TEST(RegexpOutOfMemory) { |
| 6931 // Execute a script that causes out of memory when flattening a string. | 6979 // Execute a script that causes out of memory when flattening a string. |
| 6932 v8::HandleScope scope(CcTest::isolate()); | 6980 v8::HandleScope scope(CcTest::isolate()); |
| 6933 v8::V8::SetFatalErrorHandler(OOMCallback); | 6981 v8::V8::SetFatalErrorHandler(OOMCallback); |
| 6934 LocalContext context; | 6982 LocalContext context; |
| 6935 Local<Script> script = Script::Compile(String::NewFromUtf8( | 6983 Local<Script> script = Script::Compile(String::NewFromUtf8( |
| 6936 CcTest::isolate(), js_code_causing_huge_string_flattening)); | 6984 CcTest::isolate(), js_code_causing_huge_string_flattening)); |
| 6937 last_location = NULL; | 6985 last_location = NULL; |
| 6938 script->Run(); | 6986 script->Run(); |
| 6939 | 6987 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7194 CHECK_EQ(v8::Integer::New(1, isolate), args[0]); | 7242 CHECK_EQ(v8::Integer::New(1, isolate), args[0]); |
| 7195 CHECK_EQ(v8::Integer::New(2, isolate), args[1]); | 7243 CHECK_EQ(v8::Integer::New(2, isolate), args[1]); |
| 7196 CHECK_EQ(v8::Integer::New(3, isolate), args[2]); | 7244 CHECK_EQ(v8::Integer::New(3, isolate), args[2]); |
| 7197 CHECK_EQ(v8::Undefined(isolate), args[3]); | 7245 CHECK_EQ(v8::Undefined(isolate), args[3]); |
| 7198 v8::HandleScope scope(args.GetIsolate()); | 7246 v8::HandleScope scope(args.GetIsolate()); |
| 7199 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 7247 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 7200 } | 7248 } |
| 7201 | 7249 |
| 7202 | 7250 |
| 7203 THREADED_TEST(Arguments) { | 7251 THREADED_TEST(Arguments) { |
| 7204 v8::HandleScope scope(CcTest::isolate()); | 7252 v8::Isolate* isolate = CcTest::isolate(); |
| 7253 v8::HandleScope scope(isolate); |
| 7205 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 7254 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); |
| 7206 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); | 7255 global->Set(v8_str("f"), |
| 7256 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); |
| 7207 LocalContext context(NULL, global); | 7257 LocalContext context(NULL, global); |
| 7208 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); | 7258 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); |
| 7209 v8_compile("f(1, 2, 3)")->Run(); | 7259 v8_compile("f(1, 2, 3)")->Run(); |
| 7210 } | 7260 } |
| 7211 | 7261 |
| 7212 | 7262 |
| 7213 static void NoBlockGetterX(Local<String> name, | 7263 static void NoBlockGetterX(Local<String> name, |
| 7214 const v8::PropertyCallbackInfo<v8::Value>&) { | 7264 const v8::PropertyCallbackInfo<v8::Value>&) { |
| 7215 } | 7265 } |
| 7216 | 7266 |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8052 LocalContext context; | 8102 LocalContext context; |
| 8053 v8::Handle<v8::Object> holder = obj->NewInstance(); | 8103 v8::Handle<v8::Object> holder = obj->NewInstance(); |
| 8054 context->Global()->Set(v8_str("holder"), holder); | 8104 context->Global()->Set(v8_str("holder"), holder); |
| 8055 v8::Handle<Value> result = CompileRun( | 8105 v8::Handle<Value> result = CompileRun( |
| 8056 "holder.y = 11; holder.y = 12; holder.y"); | 8106 "holder.y = 11; holder.y = 12; holder.y"); |
| 8057 CHECK_EQ(12, result->Uint32Value()); | 8107 CHECK_EQ(12, result->Uint32Value()); |
| 8058 } | 8108 } |
| 8059 | 8109 |
| 8060 | 8110 |
| 8061 THREADED_TEST(TypeSwitch) { | 8111 THREADED_TEST(TypeSwitch) { |
| 8062 v8::HandleScope scope(CcTest::isolate()); | 8112 v8::Isolate* isolate = CcTest::isolate(); |
| 8063 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(); | 8113 v8::HandleScope scope(isolate); |
| 8064 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(); | 8114 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); |
| 8065 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(); | 8115 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); |
| 8116 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); |
| 8066 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; | 8117 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; |
| 8067 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); | 8118 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); |
| 8068 LocalContext context; | 8119 LocalContext context; |
| 8069 v8::Handle<v8::Object> obj0 = v8::Object::New(); | 8120 v8::Handle<v8::Object> obj0 = v8::Object::New(); |
| 8070 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); | 8121 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); |
| 8071 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); | 8122 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); |
| 8072 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); | 8123 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); |
| 8073 for (int i = 0; i < 10; i++) { | 8124 for (int i = 0; i < 10; i++) { |
| 8074 CHECK_EQ(0, type_switch->match(obj0)); | 8125 CHECK_EQ(0, type_switch->match(obj0)); |
| 8075 CHECK_EQ(1, type_switch->match(obj1)); | 8126 CHECK_EQ(1, type_switch->match(obj1)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8133 v8::Handle<Value>) { | 8184 v8::Handle<Value>) { |
| 8134 report_count++; | 8185 report_count++; |
| 8135 } | 8186 } |
| 8136 | 8187 |
| 8137 | 8188 |
| 8138 // Counts uncaught exceptions, but other tests running in parallel | 8189 // Counts uncaught exceptions, but other tests running in parallel |
| 8139 // also have uncaught exceptions. | 8190 // also have uncaught exceptions. |
| 8140 TEST(ApiUncaughtException) { | 8191 TEST(ApiUncaughtException) { |
| 8141 report_count = 0; | 8192 report_count = 0; |
| 8142 LocalContext env; | 8193 LocalContext env; |
| 8143 v8::HandleScope scope(env->GetIsolate()); | 8194 v8::Isolate* isolate = env->GetIsolate(); |
| 8195 v8::HandleScope scope(isolate); |
| 8144 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 8196 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); |
| 8145 | 8197 |
| 8146 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); | 8198 Local<v8::FunctionTemplate> fun = |
| 8199 v8::FunctionTemplate::New(isolate, TroubleCallback); |
| 8147 v8::Local<v8::Object> global = env->Global(); | 8200 v8::Local<v8::Object> global = env->Global(); |
| 8148 global->Set(v8_str("trouble"), fun->GetFunction()); | 8201 global->Set(v8_str("trouble"), fun->GetFunction()); |
| 8149 | 8202 |
| 8150 Script::Compile(v8_str("function trouble_callee() {" | 8203 Script::Compile(v8_str("function trouble_callee() {" |
| 8151 " var x = null;" | 8204 " var x = null;" |
| 8152 " return x.foo;" | 8205 " return x.foo;" |
| 8153 "};" | 8206 "};" |
| 8154 "function trouble_caller() {" | 8207 "function trouble_caller() {" |
| 8155 " trouble();" | 8208 " trouble();" |
| 8156 "};"))->Run(); | 8209 "};"))->Run(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 8173 v8::String::Utf8Value name(message->GetScriptResourceName()); | 8226 v8::String::Utf8Value name(message->GetScriptResourceName()); |
| 8174 CHECK_EQ(script_resource_name, *name); | 8227 CHECK_EQ(script_resource_name, *name); |
| 8175 CHECK_EQ(3, message->GetLineNumber()); | 8228 CHECK_EQ(3, message->GetLineNumber()); |
| 8176 v8::String::Utf8Value source_line(message->GetSourceLine()); | 8229 v8::String::Utf8Value source_line(message->GetSourceLine()); |
| 8177 CHECK_EQ(" new o.foo();", *source_line); | 8230 CHECK_EQ(" new o.foo();", *source_line); |
| 8178 } | 8231 } |
| 8179 | 8232 |
| 8180 | 8233 |
| 8181 TEST(ExceptionInNativeScript) { | 8234 TEST(ExceptionInNativeScript) { |
| 8182 LocalContext env; | 8235 LocalContext env; |
| 8183 v8::HandleScope scope(env->GetIsolate()); | 8236 v8::Isolate* isolate = env->GetIsolate(); |
| 8237 v8::HandleScope scope(isolate); |
| 8184 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); | 8238 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); |
| 8185 | 8239 |
| 8186 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); | 8240 Local<v8::FunctionTemplate> fun = |
| 8241 v8::FunctionTemplate::New(isolate, TroubleCallback); |
| 8187 v8::Local<v8::Object> global = env->Global(); | 8242 v8::Local<v8::Object> global = env->Global(); |
| 8188 global->Set(v8_str("trouble"), fun->GetFunction()); | 8243 global->Set(v8_str("trouble"), fun->GetFunction()); |
| 8189 | 8244 |
| 8190 Script::Compile( | 8245 Script::Compile( |
| 8191 v8_str( | 8246 v8_str( |
| 8192 "function trouble() {\n" | 8247 "function trouble() {\n" |
| 8193 " var o = {};\n" | 8248 " var o = {};\n" |
| 8194 " new o.foo();\n" | 8249 " new o.foo();\n" |
| 8195 "};"), | 8250 "};"), |
| 8196 v8::String::NewFromUtf8(env->GetIsolate(), script_resource_name))->Run(); | 8251 v8::String::NewFromUtf8(isolate, script_resource_name))->Run(); |
| 8197 Local<Value> trouble = global->Get(v8_str("trouble")); | 8252 Local<Value> trouble = global->Get(v8_str("trouble")); |
| 8198 CHECK(trouble->IsFunction()); | 8253 CHECK(trouble->IsFunction()); |
| 8199 Function::Cast(*trouble)->Call(global, 0, NULL); | 8254 Function::Cast(*trouble)->Call(global, 0, NULL); |
| 8200 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); | 8255 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); |
| 8201 } | 8256 } |
| 8202 | 8257 |
| 8203 | 8258 |
| 8204 TEST(CompilationErrorUsingTryCatchHandler) { | 8259 TEST(CompilationErrorUsingTryCatchHandler) { |
| 8205 LocalContext env; | 8260 LocalContext env; |
| 8206 v8::HandleScope scope(env->GetIsolate()); | 8261 v8::HandleScope scope(env->GetIsolate()); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8517 Local<v8::Object> global2 = env2->Global(); | 8572 Local<v8::Object> global2 = env2->Global(); |
| 8518 global2->Set(v8_str("prop"), v8::Integer::New(1)); | 8573 global2->Set(v8_str("prop"), v8::Integer::New(1)); |
| 8519 CompileRun("function getProp() {return prop;}"); | 8574 CompileRun("function getProp() {return prop;}"); |
| 8520 | 8575 |
| 8521 env1->Global()->Set(v8_str("getProp"), | 8576 env1->Global()->Set(v8_str("getProp"), |
| 8522 global2->Get(v8_str("getProp"))); | 8577 global2->Get(v8_str("getProp"))); |
| 8523 | 8578 |
| 8524 // Detach env2's global, and reuse the global object of env2 | 8579 // Detach env2's global, and reuse the global object of env2 |
| 8525 env2->Exit(); | 8580 env2->Exit(); |
| 8526 env2->DetachGlobal(); | 8581 env2->DetachGlobal(); |
| 8527 // env2 has a new global object. | |
| 8528 CHECK(!env2->Global()->Equals(global2)); | |
| 8529 | 8582 |
| 8530 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), | 8583 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), |
| 8531 0, | 8584 0, |
| 8532 v8::Handle<v8::ObjectTemplate>(), | 8585 v8::Handle<v8::ObjectTemplate>(), |
| 8533 global2); | 8586 global2); |
| 8534 env3->SetSecurityToken(v8_str("bar")); | 8587 env3->SetSecurityToken(v8_str("bar")); |
| 8535 env3->Enter(); | 8588 env3->Enter(); |
| 8536 | 8589 |
| 8537 Local<v8::Object> global3 = env3->Global(); | 8590 Local<v8::Object> global3 = env3->Global(); |
| 8538 CHECK_EQ(global2, global3); | 8591 CHECK_EQ(global2, global3); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8553 } | 8606 } |
| 8554 | 8607 |
| 8555 // Check that env3 is not accessible from env1 | 8608 // Check that env3 is not accessible from env1 |
| 8556 { | 8609 { |
| 8557 Local<Value> r = global3->Get(v8_str("prop2")); | 8610 Local<Value> r = global3->Get(v8_str("prop2")); |
| 8558 CHECK(r->IsUndefined()); | 8611 CHECK(r->IsUndefined()); |
| 8559 } | 8612 } |
| 8560 } | 8613 } |
| 8561 | 8614 |
| 8562 | 8615 |
| 8563 TEST(DetachAndReattachGlobal) { | 8616 TEST(DetachGlobal) { |
| 8564 LocalContext env1; | 8617 LocalContext env1; |
| 8565 v8::HandleScope scope(env1->GetIsolate()); | 8618 v8::HandleScope scope(env1->GetIsolate()); |
| 8566 | 8619 |
| 8567 // Create second environment. | 8620 // Create second environment. |
| 8568 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8621 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8569 | 8622 |
| 8570 Local<Value> foo = v8_str("foo"); | 8623 Local<Value> foo = v8_str("foo"); |
| 8571 | 8624 |
| 8572 // Set same security token for env1 and env2. | 8625 // Set same security token for env1 and env2. |
| 8573 env1->SetSecurityToken(foo); | 8626 env1->SetSecurityToken(foo); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8618 CHECK_EQ(24, result->Int32Value()); | 8671 CHECK_EQ(24, result->Int32Value()); |
| 8619 | 8672 |
| 8620 // Change security token for env3 to something different from env1 and env2. | 8673 // Change security token for env3 to something different from env1 and env2. |
| 8621 env3->SetSecurityToken(v8_str("bar")); | 8674 env3->SetSecurityToken(v8_str("bar")); |
| 8622 | 8675 |
| 8623 // Check that we do not have access to other.p in env1. |other| is now | 8676 // Check that we do not have access to other.p in env1. |other| is now |
| 8624 // the global object for env3 which has a different security token, | 8677 // the global object for env3 which has a different security token, |
| 8625 // so access should be blocked. | 8678 // so access should be blocked. |
| 8626 result = CompileRun("other.p"); | 8679 result = CompileRun("other.p"); |
| 8627 CHECK(result->IsUndefined()); | 8680 CHECK(result->IsUndefined()); |
| 8628 | |
| 8629 // Detach the global for env3 and reattach it to env2. | |
| 8630 env3->DetachGlobal(); | |
| 8631 env2->ReattachGlobal(global2); | |
| 8632 | |
| 8633 // Check that we have access to other.p again in env1. |other| is now | |
| 8634 // the global object for env2 which has the same security token as env1. | |
| 8635 result = CompileRun("other.p"); | |
| 8636 CHECK(result->IsInt32()); | |
| 8637 CHECK_EQ(42, result->Int32Value()); | |
| 8638 } | 8681 } |
| 8639 | 8682 |
| 8640 | 8683 |
| 8684 TEST(DetachedAccesses) { |
| 8685 LocalContext env1; |
| 8686 v8::HandleScope scope(env1->GetIsolate()); |
| 8687 |
| 8688 // Create second environment. |
| 8689 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); |
| 8690 |
| 8691 Local<Value> foo = v8_str("foo"); |
| 8692 |
| 8693 // Set same security token for env1 and env2. |
| 8694 env1->SetSecurityToken(foo); |
| 8695 env2->SetSecurityToken(foo); |
| 8696 |
| 8697 { |
| 8698 v8::Context::Scope scope(env2); |
| 8699 CompileRun( |
| 8700 "var x = 'x';" |
| 8701 "function get_x() { return this.x; }" |
| 8702 "function get_x_w() { return get_x(); }" |
| 8703 ""); |
| 8704 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); |
| 8705 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); |
| 8706 } |
| 8707 |
| 8708 Local<Object> env2_global = env2->Global(); |
| 8709 env2_global->TurnOnAccessCheck(); |
| 8710 env2->DetachGlobal(); |
| 8711 |
| 8712 Local<Value> result; |
| 8713 result = CompileRun("get_x()"); |
| 8714 CHECK(result->IsUndefined()); |
| 8715 result = CompileRun("get_x_w()"); |
| 8716 CHECK(result->IsUndefined()); |
| 8717 |
| 8718 // Reattach env2's proxy |
| 8719 env2 = Context::New(env1->GetIsolate(), |
| 8720 0, |
| 8721 v8::Handle<v8::ObjectTemplate>(), |
| 8722 env2_global); |
| 8723 env2->SetSecurityToken(foo); |
| 8724 { |
| 8725 v8::Context::Scope scope(env2); |
| 8726 CompileRun("var x = 'x2';"); |
| 8727 } |
| 8728 |
| 8729 result = CompileRun("get_x()"); |
| 8730 CHECK(result->IsUndefined()); |
| 8731 result = CompileRun("get_x_w()"); |
| 8732 CHECK_EQ(v8_str("x2"), result); |
| 8733 } |
| 8734 |
| 8735 |
| 8641 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; | 8736 static bool allowed_access_type[v8::ACCESS_KEYS + 1] = { false }; |
| 8642 static bool NamedAccessBlocker(Local<v8::Object> global, | 8737 static bool NamedAccessBlocker(Local<v8::Object> global, |
| 8643 Local<Value> name, | 8738 Local<Value> name, |
| 8644 v8::AccessType type, | 8739 v8::AccessType type, |
| 8645 Local<Value> data) { | 8740 Local<Value> data) { |
| 8646 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || | 8741 return CcTest::isolate()->GetCurrentContext()->Global()->Equals(global) || |
| 8647 allowed_access_type[type]; | 8742 allowed_access_type[type]; |
| 8648 } | 8743 } |
| 8649 | 8744 |
| 8650 | 8745 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8719 // Add an accessor accessible by cross-domain JS code. | 8814 // Add an accessor accessible by cross-domain JS code. |
| 8720 global_template->SetAccessor( | 8815 global_template->SetAccessor( |
| 8721 v8_str("accessible_prop"), | 8816 v8_str("accessible_prop"), |
| 8722 EchoGetter, EchoSetter, | 8817 EchoGetter, EchoSetter, |
| 8723 v8::Handle<Value>(), | 8818 v8::Handle<Value>(), |
| 8724 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 8819 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
| 8725 | 8820 |
| 8726 | 8821 |
| 8727 global_template->SetAccessorProperty( | 8822 global_template->SetAccessorProperty( |
| 8728 v8_str("accessible_js_prop"), | 8823 v8_str("accessible_js_prop"), |
| 8729 v8::FunctionTemplate::New(EchoGetter), | 8824 v8::FunctionTemplate::New(isolate, EchoGetter), |
| 8730 v8::FunctionTemplate::New(EchoSetter), | 8825 v8::FunctionTemplate::New(isolate, EchoSetter), |
| 8731 v8::None, | 8826 v8::None, |
| 8732 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 8827 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
| 8733 | 8828 |
| 8734 // Add an accessor that is not accessible by cross-domain JS code. | 8829 // Add an accessor that is not accessible by cross-domain JS code. |
| 8735 global_template->SetAccessor(v8_str("blocked_prop"), | 8830 global_template->SetAccessor(v8_str("blocked_prop"), |
| 8736 UnreachableGetter, UnreachableSetter, | 8831 UnreachableGetter, UnreachableSetter, |
| 8737 v8::Handle<Value>(), | 8832 v8::Handle<Value>(), |
| 8738 v8::DEFAULT); | 8833 v8::DEFAULT); |
| 8739 | 8834 |
| 8740 global_template->SetAccessorProperty( | 8835 global_template->SetAccessorProperty( |
| 8741 v8_str("blocked_js_prop"), | 8836 v8_str("blocked_js_prop"), |
| 8742 v8::FunctionTemplate::New(UnreachableFunction), | 8837 v8::FunctionTemplate::New(isolate, UnreachableFunction), |
| 8743 v8::FunctionTemplate::New(UnreachableFunction), | 8838 v8::FunctionTemplate::New(isolate, UnreachableFunction), |
| 8744 v8::None, | 8839 v8::None, |
| 8745 v8::DEFAULT); | 8840 v8::DEFAULT); |
| 8746 | 8841 |
| 8747 // Create an environment | 8842 // Create an environment |
| 8748 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); | 8843 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
| 8749 context0->Enter(); | 8844 context0->Enter(); |
| 8750 | 8845 |
| 8751 v8::Handle<v8::Object> global0 = context0->Global(); | 8846 v8::Handle<v8::Object> global0 = context0->Global(); |
| 8752 | 8847 |
| 8753 // Define a property with JS getter and setter. | 8848 // Define a property with JS getter and setter. |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9166 static void ConstTenGetter(Local<String> name, | 9261 static void ConstTenGetter(Local<String> name, |
| 9167 const v8::PropertyCallbackInfo<v8::Value>& info) { | 9262 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 9168 info.GetReturnValue().Set(v8_num(10)); | 9263 info.GetReturnValue().Set(v8_num(10)); |
| 9169 } | 9264 } |
| 9170 | 9265 |
| 9171 | 9266 |
| 9172 THREADED_TEST(CrossDomainAccessors) { | 9267 THREADED_TEST(CrossDomainAccessors) { |
| 9173 v8::Isolate* isolate = CcTest::isolate(); | 9268 v8::Isolate* isolate = CcTest::isolate(); |
| 9174 v8::HandleScope handle_scope(isolate); | 9269 v8::HandleScope handle_scope(isolate); |
| 9175 | 9270 |
| 9176 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 9271 v8::Handle<v8::FunctionTemplate> func_template = |
| 9272 v8::FunctionTemplate::New(isolate); |
| 9177 | 9273 |
| 9178 v8::Handle<v8::ObjectTemplate> global_template = | 9274 v8::Handle<v8::ObjectTemplate> global_template = |
| 9179 func_template->InstanceTemplate(); | 9275 func_template->InstanceTemplate(); |
| 9180 | 9276 |
| 9181 v8::Handle<v8::ObjectTemplate> proto_template = | 9277 v8::Handle<v8::ObjectTemplate> proto_template = |
| 9182 func_template->PrototypeTemplate(); | 9278 func_template->PrototypeTemplate(); |
| 9183 | 9279 |
| 9184 // Add an accessor to proto that's accessible by cross-domain JS code. | 9280 // Add an accessor to proto that's accessible by cross-domain JS code. |
| 9185 proto_template->SetAccessor(v8_str("accessible"), | 9281 proto_template->SetAccessor(v8_str("accessible"), |
| 9186 ConstTenGetter, 0, | 9282 ConstTenGetter, 0, |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9532 | 9628 |
| 9533 static void InstanceFunctionCallback( | 9629 static void InstanceFunctionCallback( |
| 9534 const v8::FunctionCallbackInfo<v8::Value>& args) { | 9630 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 9535 ApiTestFuzzer::Fuzz(); | 9631 ApiTestFuzzer::Fuzz(); |
| 9536 args.GetReturnValue().Set(v8_num(12)); | 9632 args.GetReturnValue().Set(v8_num(12)); |
| 9537 } | 9633 } |
| 9538 | 9634 |
| 9539 | 9635 |
| 9540 THREADED_TEST(InstanceProperties) { | 9636 THREADED_TEST(InstanceProperties) { |
| 9541 LocalContext context; | 9637 LocalContext context; |
| 9542 v8::HandleScope handle_scope(context->GetIsolate()); | 9638 v8::Isolate* isolate = context->GetIsolate(); |
| 9639 v8::HandleScope handle_scope(isolate); |
| 9543 | 9640 |
| 9544 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 9641 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9545 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 9642 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
| 9546 | 9643 |
| 9547 instance->Set(v8_str("x"), v8_num(42)); | 9644 instance->Set(v8_str("x"), v8_num(42)); |
| 9548 instance->Set(v8_str("f"), | 9645 instance->Set(v8_str("f"), |
| 9549 v8::FunctionTemplate::New(InstanceFunctionCallback)); | 9646 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); |
| 9550 | 9647 |
| 9551 Local<Value> o = t->GetFunction()->NewInstance(); | 9648 Local<Value> o = t->GetFunction()->NewInstance(); |
| 9552 | 9649 |
| 9553 context->Global()->Set(v8_str("i"), o); | 9650 context->Global()->Set(v8_str("i"), o); |
| 9554 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); | 9651 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); |
| 9555 CHECK_EQ(42, value->Int32Value()); | 9652 CHECK_EQ(42, value->Int32Value()); |
| 9556 | 9653 |
| 9557 value = Script::Compile(v8_str("i.f()"))->Run(); | 9654 value = Script::Compile(v8_str("i.f()"))->Run(); |
| 9558 CHECK_EQ(12, value->Int32Value()); | 9655 CHECK_EQ(12, value->Int32Value()); |
| 9559 } | 9656 } |
| 9560 | 9657 |
| 9561 | 9658 |
| 9562 static void GlobalObjectInstancePropertiesGet( | 9659 static void GlobalObjectInstancePropertiesGet( |
| 9563 Local<String> key, | 9660 Local<String> key, |
| 9564 const v8::PropertyCallbackInfo<v8::Value>&) { | 9661 const v8::PropertyCallbackInfo<v8::Value>&) { |
| 9565 ApiTestFuzzer::Fuzz(); | 9662 ApiTestFuzzer::Fuzz(); |
| 9566 } | 9663 } |
| 9567 | 9664 |
| 9568 | 9665 |
| 9569 THREADED_TEST(GlobalObjectInstanceProperties) { | 9666 THREADED_TEST(GlobalObjectInstanceProperties) { |
| 9570 v8::HandleScope handle_scope(CcTest::isolate()); | 9667 v8::Isolate* isolate = CcTest::isolate(); |
| 9668 v8::HandleScope handle_scope(isolate); |
| 9571 | 9669 |
| 9572 Local<Value> global_object; | 9670 Local<Value> global_object; |
| 9573 | 9671 |
| 9574 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 9672 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9575 t->InstanceTemplate()->SetNamedPropertyHandler( | 9673 t->InstanceTemplate()->SetNamedPropertyHandler( |
| 9576 GlobalObjectInstancePropertiesGet); | 9674 GlobalObjectInstancePropertiesGet); |
| 9577 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 9675 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 9578 instance_template->Set(v8_str("x"), v8_num(42)); | 9676 instance_template->Set(v8_str("x"), v8_num(42)); |
| 9579 instance_template->Set(v8_str("f"), | 9677 instance_template->Set(v8_str("f"), |
| 9580 v8::FunctionTemplate::New(InstanceFunctionCallback)); | 9678 v8::FunctionTemplate::New(isolate, |
| 9679 InstanceFunctionCallback)); |
| 9581 | 9680 |
| 9582 // The script to check how Crankshaft compiles missing global function | 9681 // The script to check how Crankshaft compiles missing global function |
| 9583 // invocations. function g is not defined and should throw on call. | 9682 // invocations. function g is not defined and should throw on call. |
| 9584 const char* script = | 9683 const char* script = |
| 9585 "function wrapper(call) {" | 9684 "function wrapper(call) {" |
| 9586 " var x = 0, y = 1;" | 9685 " var x = 0, y = 1;" |
| 9587 " for (var i = 0; i < 1000; i++) {" | 9686 " for (var i = 0; i < 1000; i++) {" |
| 9588 " x += i * 100;" | 9687 " x += i * 100;" |
| 9589 " y += i * 100;" | 9688 " y += i * 100;" |
| 9590 " }" | 9689 " }" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 9616 CHECK_EQ(42, value->Int32Value()); | 9715 CHECK_EQ(42, value->Int32Value()); |
| 9617 value = Script::Compile(v8_str("f()"))->Run(); | 9716 value = Script::Compile(v8_str("f()"))->Run(); |
| 9618 CHECK_EQ(12, value->Int32Value()); | 9717 CHECK_EQ(12, value->Int32Value()); |
| 9619 value = Script::Compile(v8_str(script))->Run(); | 9718 value = Script::Compile(v8_str(script))->Run(); |
| 9620 CHECK_EQ(1, value->Int32Value()); | 9719 CHECK_EQ(1, value->Int32Value()); |
| 9621 } | 9720 } |
| 9622 } | 9721 } |
| 9623 | 9722 |
| 9624 | 9723 |
| 9625 THREADED_TEST(CallKnownGlobalReceiver) { | 9724 THREADED_TEST(CallKnownGlobalReceiver) { |
| 9626 v8::HandleScope handle_scope(CcTest::isolate()); | 9725 v8::Isolate* isolate = CcTest::isolate(); |
| 9726 v8::HandleScope handle_scope(isolate); |
| 9627 | 9727 |
| 9628 Local<Value> global_object; | 9728 Local<Value> global_object; |
| 9629 | 9729 |
| 9630 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 9730 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9631 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 9731 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 9632 | 9732 |
| 9633 // The script to check that we leave global object not | 9733 // The script to check that we leave global object not |
| 9634 // global object proxy on stack when we deoptimize from inside | 9734 // global object proxy on stack when we deoptimize from inside |
| 9635 // arguments evaluation. | 9735 // arguments evaluation. |
| 9636 // To provoke error we need to both force deoptimization | 9736 // To provoke error we need to both force deoptimization |
| 9637 // from arguments evaluation and to force CallIC to take | 9737 // from arguments evaluation and to force CallIC to take |
| 9638 // CallIC_Miss code path that can't cope with global proxy. | 9738 // CallIC_Miss code path that can't cope with global proxy. |
| 9639 const char* script = | 9739 const char* script = |
| 9640 "function bar(x, y) { try { } finally { } }" | 9740 "function bar(x, y) { try { } finally { } }" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9695 } | 9795 } |
| 9696 | 9796 |
| 9697 | 9797 |
| 9698 static void ShadowNamedGet(Local<String> key, | 9798 static void ShadowNamedGet(Local<String> key, |
| 9699 const v8::PropertyCallbackInfo<v8::Value>&) { | 9799 const v8::PropertyCallbackInfo<v8::Value>&) { |
| 9700 } | 9800 } |
| 9701 | 9801 |
| 9702 | 9802 |
| 9703 THREADED_TEST(ShadowObject) { | 9803 THREADED_TEST(ShadowObject) { |
| 9704 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; | 9804 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; |
| 9705 v8::HandleScope handle_scope(CcTest::isolate()); | 9805 v8::Isolate* isolate = CcTest::isolate(); |
| 9806 v8::HandleScope handle_scope(isolate); |
| 9706 | 9807 |
| 9707 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 9808 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 9708 LocalContext context(NULL, global_template); | 9809 LocalContext context(NULL, global_template); |
| 9709 | 9810 |
| 9710 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 9811 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9711 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); | 9812 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); |
| 9712 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); | 9813 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
| 9713 Local<ObjectTemplate> proto = t->PrototypeTemplate(); | 9814 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
| 9714 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 9815 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
| 9715 | 9816 |
| 9716 proto->Set(v8_str("f"), | 9817 proto->Set(v8_str("f"), |
| 9717 v8::FunctionTemplate::New(ShadowFunctionCallback, Local<Value>())); | 9818 v8::FunctionTemplate::New(isolate, |
| 9819 ShadowFunctionCallback, |
| 9820 Local<Value>())); |
| 9718 proto->Set(v8_str("x"), v8_num(12)); | 9821 proto->Set(v8_str("x"), v8_num(12)); |
| 9719 | 9822 |
| 9720 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); | 9823 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); |
| 9721 | 9824 |
| 9722 Local<Value> o = t->GetFunction()->NewInstance(); | 9825 Local<Value> o = t->GetFunction()->NewInstance(); |
| 9723 context->Global()->Set(v8_str("__proto__"), o); | 9826 context->Global()->Set(v8_str("__proto__"), o); |
| 9724 | 9827 |
| 9725 Local<Value> value = | 9828 Local<Value> value = |
| 9726 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); | 9829 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); |
| 9727 CHECK(value->IsBoolean()); | 9830 CHECK(value->IsBoolean()); |
| 9728 CHECK(!value->BooleanValue()); | 9831 CHECK(!value->BooleanValue()); |
| 9729 | 9832 |
| 9730 value = Script::Compile(v8_str("x"))->Run(); | 9833 value = Script::Compile(v8_str("x"))->Run(); |
| 9731 CHECK_EQ(12, value->Int32Value()); | 9834 CHECK_EQ(12, value->Int32Value()); |
| 9732 | 9835 |
| 9733 value = Script::Compile(v8_str("f()"))->Run(); | 9836 value = Script::Compile(v8_str("f()"))->Run(); |
| 9734 CHECK_EQ(42, value->Int32Value()); | 9837 CHECK_EQ(42, value->Int32Value()); |
| 9735 | 9838 |
| 9736 Script::Compile(v8_str("y = 43"))->Run(); | 9839 Script::Compile(v8_str("y = 43"))->Run(); |
| 9737 CHECK_EQ(1, shadow_y_setter_call_count); | 9840 CHECK_EQ(1, shadow_y_setter_call_count); |
| 9738 value = Script::Compile(v8_str("y"))->Run(); | 9841 value = Script::Compile(v8_str("y"))->Run(); |
| 9739 CHECK_EQ(1, shadow_y_getter_call_count); | 9842 CHECK_EQ(1, shadow_y_getter_call_count); |
| 9740 CHECK_EQ(42, value->Int32Value()); | 9843 CHECK_EQ(42, value->Int32Value()); |
| 9741 } | 9844 } |
| 9742 | 9845 |
| 9743 | 9846 |
| 9744 THREADED_TEST(HiddenPrototype) { | 9847 THREADED_TEST(HiddenPrototype) { |
| 9745 LocalContext context; | 9848 LocalContext context; |
| 9746 v8::HandleScope handle_scope(context->GetIsolate()); | 9849 v8::Isolate* isolate = context->GetIsolate(); |
| 9850 v8::HandleScope handle_scope(isolate); |
| 9747 | 9851 |
| 9748 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); | 9852 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); |
| 9749 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 9853 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
| 9750 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 9854 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 9751 t1->SetHiddenPrototype(true); | 9855 t1->SetHiddenPrototype(true); |
| 9752 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); | 9856 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); |
| 9753 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); | 9857 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
| 9754 t2->SetHiddenPrototype(true); | 9858 t2->SetHiddenPrototype(true); |
| 9755 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); | 9859 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); |
| 9756 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); | 9860 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
| 9757 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); | 9861 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); |
| 9758 | 9862 |
| 9759 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); | 9863 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); |
| 9760 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 9864 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); |
| 9761 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 9865 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); |
| 9762 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); | 9866 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); |
| 9763 | 9867 |
| 9764 // Setting the prototype on an object skips hidden prototypes. | 9868 // Setting the prototype on an object skips hidden prototypes. |
| 9765 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 9869 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); |
| 9766 o0->Set(v8_str("__proto__"), o1); | 9870 o0->Set(v8_str("__proto__"), o1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 9780 // which is o3. Therefore, z should not be defined on the prototype | 9884 // which is o3. Therefore, z should not be defined on the prototype |
| 9781 // object. | 9885 // object. |
| 9782 Local<Value> proto = o0->Get(v8_str("__proto__")); | 9886 Local<Value> proto = o0->Get(v8_str("__proto__")); |
| 9783 CHECK(proto->IsObject()); | 9887 CHECK(proto->IsObject()); |
| 9784 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); | 9888 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); |
| 9785 } | 9889 } |
| 9786 | 9890 |
| 9787 | 9891 |
| 9788 THREADED_TEST(HiddenPrototypeSet) { | 9892 THREADED_TEST(HiddenPrototypeSet) { |
| 9789 LocalContext context; | 9893 LocalContext context; |
| 9790 v8::HandleScope handle_scope(context->GetIsolate()); | 9894 v8::Isolate* isolate = context->GetIsolate(); |
| 9895 v8::HandleScope handle_scope(isolate); |
| 9791 | 9896 |
| 9792 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(); | 9897 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate); |
| 9793 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(); | 9898 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate); |
| 9794 ht->SetHiddenPrototype(true); | 9899 ht->SetHiddenPrototype(true); |
| 9795 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(); | 9900 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate); |
| 9796 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 9901 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
| 9797 | 9902 |
| 9798 Local<v8::Object> o = ot->GetFunction()->NewInstance(); | 9903 Local<v8::Object> o = ot->GetFunction()->NewInstance(); |
| 9799 Local<v8::Object> h = ht->GetFunction()->NewInstance(); | 9904 Local<v8::Object> h = ht->GetFunction()->NewInstance(); |
| 9800 Local<v8::Object> p = pt->GetFunction()->NewInstance(); | 9905 Local<v8::Object> p = pt->GetFunction()->NewInstance(); |
| 9801 o->Set(v8_str("__proto__"), h); | 9906 o->Set(v8_str("__proto__"), h); |
| 9802 h->Set(v8_str("__proto__"), p); | 9907 h->Set(v8_str("__proto__"), p); |
| 9803 | 9908 |
| 9804 // Setting a property that exists on the hidden prototype goes there. | 9909 // Setting a property that exists on the hidden prototype goes there. |
| 9805 o->Set(v8_str("x"), v8_num(7)); | 9910 o->Set(v8_str("x"), v8_num(7)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 9824 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); | 9929 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); |
| 9825 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); | 9930 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); |
| 9826 } | 9931 } |
| 9827 | 9932 |
| 9828 | 9933 |
| 9829 // Regression test for issue 2457. | 9934 // Regression test for issue 2457. |
| 9830 THREADED_TEST(HiddenPrototypeIdentityHash) { | 9935 THREADED_TEST(HiddenPrototypeIdentityHash) { |
| 9831 LocalContext context; | 9936 LocalContext context; |
| 9832 v8::HandleScope handle_scope(context->GetIsolate()); | 9937 v8::HandleScope handle_scope(context->GetIsolate()); |
| 9833 | 9938 |
| 9834 Handle<FunctionTemplate> t = FunctionTemplate::New(); | 9939 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); |
| 9835 t->SetHiddenPrototype(true); | 9940 t->SetHiddenPrototype(true); |
| 9836 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); | 9941 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); |
| 9837 Handle<Object> p = t->GetFunction()->NewInstance(); | 9942 Handle<Object> p = t->GetFunction()->NewInstance(); |
| 9838 Handle<Object> o = Object::New(); | 9943 Handle<Object> o = Object::New(); |
| 9839 o->SetPrototype(p); | 9944 o->SetPrototype(p); |
| 9840 | 9945 |
| 9841 int hash = o->GetIdentityHash(); | 9946 int hash = o->GetIdentityHash(); |
| 9842 USE(hash); | 9947 USE(hash); |
| 9843 o->Set(v8_str("foo"), v8_num(42)); | 9948 o->Set(v8_str("foo"), v8_num(42)); |
| 9844 ASSERT_EQ(hash, o->GetIdentityHash()); | 9949 ASSERT_EQ(hash, o->GetIdentityHash()); |
| 9845 } | 9950 } |
| 9846 | 9951 |
| 9847 | 9952 |
| 9848 THREADED_TEST(SetPrototype) { | 9953 THREADED_TEST(SetPrototype) { |
| 9849 LocalContext context; | 9954 LocalContext context; |
| 9850 v8::HandleScope handle_scope(context->GetIsolate()); | 9955 v8::Isolate* isolate = context->GetIsolate(); |
| 9956 v8::HandleScope handle_scope(isolate); |
| 9851 | 9957 |
| 9852 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); | 9958 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); |
| 9853 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 9959 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
| 9854 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 9960 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 9855 t1->SetHiddenPrototype(true); | 9961 t1->SetHiddenPrototype(true); |
| 9856 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); | 9962 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); |
| 9857 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); | 9963 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
| 9858 t2->SetHiddenPrototype(true); | 9964 t2->SetHiddenPrototype(true); |
| 9859 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); | 9965 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); |
| 9860 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); | 9966 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
| 9861 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); | 9967 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); |
| 9862 | 9968 |
| 9863 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); | 9969 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); |
| 9864 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 9970 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); |
| 9865 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 9971 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); |
| 9866 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); | 9972 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); |
| 9867 | 9973 |
| 9868 // Setting the prototype on an object does not skip hidden prototypes. | 9974 // Setting the prototype on an object does not skip hidden prototypes. |
| 9869 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 9975 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); |
| 9870 CHECK(o0->SetPrototype(o1)); | 9976 CHECK(o0->SetPrototype(o1)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 9901 CHECK_EQ(proto2.As<v8::Object>(), o3); | 10007 CHECK_EQ(proto2.As<v8::Object>(), o3); |
| 9902 } | 10008 } |
| 9903 | 10009 |
| 9904 | 10010 |
| 9905 // Getting property names of an object with a prototype chain that | 10011 // Getting property names of an object with a prototype chain that |
| 9906 // triggers dictionary elements in GetLocalPropertyNames() shouldn't | 10012 // triggers dictionary elements in GetLocalPropertyNames() shouldn't |
| 9907 // crash the runtime. | 10013 // crash the runtime. |
| 9908 THREADED_TEST(Regress91517) { | 10014 THREADED_TEST(Regress91517) { |
| 9909 i::FLAG_allow_natives_syntax = true; | 10015 i::FLAG_allow_natives_syntax = true; |
| 9910 LocalContext context; | 10016 LocalContext context; |
| 9911 v8::HandleScope handle_scope(context->GetIsolate()); | 10017 v8::Isolate* isolate = context->GetIsolate(); |
| 10018 v8::HandleScope handle_scope(isolate); |
| 9912 | 10019 |
| 9913 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 10020 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 9914 t1->SetHiddenPrototype(true); | 10021 t1->SetHiddenPrototype(true); |
| 9915 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); | 10022 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); |
| 9916 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); | 10023 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
| 9917 t2->SetHiddenPrototype(true); | 10024 t2->SetHiddenPrototype(true); |
| 9918 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); | 10025 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); |
| 9919 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); | 10026 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); |
| 9920 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); | 10027 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); |
| 9921 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); | 10028 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
| 9922 t3->SetHiddenPrototype(true); | 10029 t3->SetHiddenPrototype(true); |
| 9923 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); | 10030 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); |
| 9924 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(); | 10031 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); |
| 9925 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); | 10032 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); |
| 9926 | 10033 |
| 9927 // Force dictionary-based properties. | 10034 // Force dictionary-based properties. |
| 9928 i::ScopedVector<char> name_buf(1024); | 10035 i::ScopedVector<char> name_buf(1024); |
| 9929 for (int i = 1; i <= 1000; i++) { | 10036 for (int i = 1; i <= 1000; i++) { |
| 9930 i::OS::SNPrintF(name_buf, "sdf%d", i); | 10037 i::OS::SNPrintF(name_buf, "sdf%d", i); |
| 9931 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); | 10038 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); |
| 9932 } | 10039 } |
| 9933 | 10040 |
| 9934 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 10041 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 9951 ExpectTrue("names.indexOf(\"boo\") >= 0"); | 10058 ExpectTrue("names.indexOf(\"boo\") >= 0"); |
| 9952 ExpectTrue("names.indexOf(\"foo\") >= 0"); | 10059 ExpectTrue("names.indexOf(\"foo\") >= 0"); |
| 9953 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); | 10060 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); |
| 9954 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); | 10061 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); |
| 9955 ExpectFalse("names[1005] == undefined"); | 10062 ExpectFalse("names[1005] == undefined"); |
| 9956 } | 10063 } |
| 9957 | 10064 |
| 9958 | 10065 |
| 9959 THREADED_TEST(FunctionReadOnlyPrototype) { | 10066 THREADED_TEST(FunctionReadOnlyPrototype) { |
| 9960 LocalContext context; | 10067 LocalContext context; |
| 9961 v8::HandleScope handle_scope(context->GetIsolate()); | 10068 v8::Isolate* isolate = context->GetIsolate(); |
| 10069 v8::HandleScope handle_scope(isolate); |
| 9962 | 10070 |
| 9963 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 10071 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 9964 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); | 10072 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); |
| 9965 t1->ReadOnlyPrototype(); | 10073 t1->ReadOnlyPrototype(); |
| 9966 context->Global()->Set(v8_str("func1"), t1->GetFunction()); | 10074 context->Global()->Set(v8_str("func1"), t1->GetFunction()); |
| 9967 // Configured value of ReadOnly flag. | 10075 // Configured value of ReadOnly flag. |
| 9968 CHECK(CompileRun( | 10076 CHECK(CompileRun( |
| 9969 "(function() {" | 10077 "(function() {" |
| 9970 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" | 10078 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" |
| 9971 " return (descriptor['writable'] == false);" | 10079 " return (descriptor['writable'] == false);" |
| 9972 "})()")->BooleanValue()); | 10080 "})()")->BooleanValue()); |
| 9973 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); | 10081 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); |
| 9974 CHECK_EQ(42, | 10082 CHECK_EQ(42, |
| 9975 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); | 10083 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); |
| 9976 | 10084 |
| 9977 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); | 10085 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
| 9978 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); | 10086 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); |
| 9979 context->Global()->Set(v8_str("func2"), t2->GetFunction()); | 10087 context->Global()->Set(v8_str("func2"), t2->GetFunction()); |
| 9980 // Default value of ReadOnly flag. | 10088 // Default value of ReadOnly flag. |
| 9981 CHECK(CompileRun( | 10089 CHECK(CompileRun( |
| 9982 "(function() {" | 10090 "(function() {" |
| 9983 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" | 10091 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" |
| 9984 " return (descriptor['writable'] == true);" | 10092 " return (descriptor['writable'] == true);" |
| 9985 "})()")->BooleanValue()); | 10093 "})()")->BooleanValue()); |
| 9986 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); | 10094 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); |
| 9987 } | 10095 } |
| 9988 | 10096 |
| 9989 | 10097 |
| 9990 THREADED_TEST(SetPrototypeThrows) { | 10098 THREADED_TEST(SetPrototypeThrows) { |
| 9991 LocalContext context; | 10099 LocalContext context; |
| 9992 v8::HandleScope handle_scope(context->GetIsolate()); | 10100 v8::Isolate* isolate = context->GetIsolate(); |
| 10101 v8::HandleScope handle_scope(isolate); |
| 9993 | 10102 |
| 9994 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 10103 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 9995 | 10104 |
| 9996 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); | 10105 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); |
| 9997 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); | 10106 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); |
| 9998 | 10107 |
| 9999 CHECK(o0->SetPrototype(o1)); | 10108 CHECK(o0->SetPrototype(o1)); |
| 10000 // If setting the prototype leads to the cycle, SetPrototype should | 10109 // If setting the prototype leads to the cycle, SetPrototype should |
| 10001 // return false and keep VM in sane state. | 10110 // return false and keep VM in sane state. |
| 10002 v8::TryCatch try_catch; | 10111 v8::TryCatch try_catch; |
| 10003 CHECK(!o1->SetPrototype(o0)); | 10112 CHECK(!o1->SetPrototype(o0)); |
| 10004 CHECK(!try_catch.HasCaught()); | 10113 CHECK(!try_catch.HasCaught()); |
| 10005 ASSERT(!CcTest::i_isolate()->has_pending_exception()); | 10114 ASSERT(!CcTest::i_isolate()->has_pending_exception()); |
| 10006 | 10115 |
| 10007 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); | 10116 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); |
| 10008 } | 10117 } |
| 10009 | 10118 |
| 10010 | 10119 |
| 10011 THREADED_TEST(FunctionRemovePrototype) { | 10120 THREADED_TEST(FunctionRemovePrototype) { |
| 10012 LocalContext context; | 10121 LocalContext context; |
| 10013 v8::HandleScope handle_scope(context->GetIsolate()); | 10122 v8::Isolate* isolate = context->GetIsolate(); |
| 10123 v8::HandleScope handle_scope(isolate); |
| 10014 | 10124 |
| 10015 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); | 10125 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
| 10016 t1->RemovePrototype(); | 10126 t1->RemovePrototype(); |
| 10017 Local<v8::Function> fun = t1->GetFunction(); | 10127 Local<v8::Function> fun = t1->GetFunction(); |
| 10018 context->Global()->Set(v8_str("fun"), fun); | 10128 context->Global()->Set(v8_str("fun"), fun); |
| 10019 CHECK(!CompileRun("'prototype' in fun")->BooleanValue()); | 10129 CHECK(!CompileRun("'prototype' in fun")->BooleanValue()); |
| 10020 | 10130 |
| 10021 v8::TryCatch try_catch; | 10131 v8::TryCatch try_catch; |
| 10022 CompileRun("new fun()"); | 10132 CompileRun("new fun()"); |
| 10023 CHECK(try_catch.HasCaught()); | 10133 CHECK(try_catch.HasCaught()); |
| 10024 | 10134 |
| 10025 try_catch.Reset(); | 10135 try_catch.Reset(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 10046 x->Get(v8_str("get")); | 10156 x->Get(v8_str("get")); |
| 10047 x->Set(v8_str("set"), v8::Integer::New(8)); | 10157 x->Set(v8_str("set"), v8::Integer::New(8)); |
| 10048 x->Get(v8_str("get")); | 10158 x->Get(v8_str("get")); |
| 10049 x->Set(v8_str("set"), v8::Integer::New(8)); | 10159 x->Set(v8_str("set"), v8::Integer::New(8)); |
| 10050 x->Get(v8_str("get")); | 10160 x->Get(v8_str("get")); |
| 10051 } | 10161 } |
| 10052 | 10162 |
| 10053 | 10163 |
| 10054 THREADED_TEST(Constructor) { | 10164 THREADED_TEST(Constructor) { |
| 10055 LocalContext context; | 10165 LocalContext context; |
| 10056 v8::HandleScope handle_scope(context->GetIsolate()); | 10166 v8::Isolate* isolate = context->GetIsolate(); |
| 10057 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 10167 v8::HandleScope handle_scope(isolate); |
| 10168 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 10058 templ->SetClassName(v8_str("Fun")); | 10169 templ->SetClassName(v8_str("Fun")); |
| 10059 Local<Function> cons = templ->GetFunction(); | 10170 Local<Function> cons = templ->GetFunction(); |
| 10060 context->Global()->Set(v8_str("Fun"), cons); | 10171 context->Global()->Set(v8_str("Fun"), cons); |
| 10061 Local<v8::Object> inst = cons->NewInstance(); | 10172 Local<v8::Object> inst = cons->NewInstance(); |
| 10062 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); | 10173 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); |
| 10063 CHECK(obj->IsJSObject()); | 10174 CHECK(obj->IsJSObject()); |
| 10064 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); | 10175 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); |
| 10065 CHECK(value->BooleanValue()); | 10176 CHECK(value->BooleanValue()); |
| 10066 } | 10177 } |
| 10067 | 10178 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10214 Local<Value> args[] = { v8_num(23) }; | 10325 Local<Value> args[] = { v8_num(23) }; |
| 10215 value = instance->CallAsConstructor(1, args); | 10326 value = instance->CallAsConstructor(1, args); |
| 10216 CHECK(try_catch.HasCaught()); | 10327 CHECK(try_catch.HasCaught()); |
| 10217 String::Utf8Value exception_value2(try_catch.Exception()); | 10328 String::Utf8Value exception_value2(try_catch.Exception()); |
| 10218 CHECK_EQ("23", *exception_value2); | 10329 CHECK_EQ("23", *exception_value2); |
| 10219 try_catch.Reset(); | 10330 try_catch.Reset(); |
| 10220 } | 10331 } |
| 10221 | 10332 |
| 10222 // Check whether constructor returns with an object or non-object. | 10333 // Check whether constructor returns with an object or non-object. |
| 10223 { Local<FunctionTemplate> function_template = | 10334 { Local<FunctionTemplate> function_template = |
| 10224 FunctionTemplate::New(FakeConstructorCallback); | 10335 FunctionTemplate::New(isolate, FakeConstructorCallback); |
| 10225 Local<Function> function = function_template->GetFunction(); | 10336 Local<Function> function = function_template->GetFunction(); |
| 10226 Local<Object> instance1 = function; | 10337 Local<Object> instance1 = function; |
| 10227 context->Global()->Set(v8_str("obj4"), instance1); | 10338 context->Global()->Set(v8_str("obj4"), instance1); |
| 10228 v8::TryCatch try_catch; | 10339 v8::TryCatch try_catch; |
| 10229 Local<Value> value; | 10340 Local<Value> value; |
| 10230 CHECK(!try_catch.HasCaught()); | 10341 CHECK(!try_catch.HasCaught()); |
| 10231 | 10342 |
| 10232 CHECK(instance1->IsObject()); | 10343 CHECK(instance1->IsObject()); |
| 10233 CHECK(instance1->IsFunction()); | 10344 CHECK(instance1->IsFunction()); |
| 10234 | 10345 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 10257 Local<Value> args2[] = { v8_num(28) }; | 10368 Local<Value> args2[] = { v8_num(28) }; |
| 10258 value = instance2->CallAsConstructor(1, args2); | 10369 value = instance2->CallAsConstructor(1, args2); |
| 10259 CHECK(!try_catch.HasCaught()); | 10370 CHECK(!try_catch.HasCaught()); |
| 10260 CHECK(!value->IsObject()); | 10371 CHECK(!value->IsObject()); |
| 10261 } | 10372 } |
| 10262 } | 10373 } |
| 10263 | 10374 |
| 10264 | 10375 |
| 10265 THREADED_TEST(FunctionDescriptorException) { | 10376 THREADED_TEST(FunctionDescriptorException) { |
| 10266 LocalContext context; | 10377 LocalContext context; |
| 10267 v8::HandleScope handle_scope(context->GetIsolate()); | 10378 v8::Isolate* isolate = context->GetIsolate(); |
| 10268 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 10379 v8::HandleScope handle_scope(isolate); |
| 10380 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 10269 templ->SetClassName(v8_str("Fun")); | 10381 templ->SetClassName(v8_str("Fun")); |
| 10270 Local<Function> cons = templ->GetFunction(); | 10382 Local<Function> cons = templ->GetFunction(); |
| 10271 context->Global()->Set(v8_str("Fun"), cons); | 10383 context->Global()->Set(v8_str("Fun"), cons); |
| 10272 Local<Value> value = CompileRun( | 10384 Local<Value> value = CompileRun( |
| 10273 "function test() {" | 10385 "function test() {" |
| 10274 " try {" | 10386 " try {" |
| 10275 " (new Fun()).blah()" | 10387 " (new Fun()).blah()" |
| 10276 " } catch (e) {" | 10388 " } catch (e) {" |
| 10277 " var str = String(e);" | 10389 " var str = String(e);" |
| 10278 " if (str.indexOf('TypeError') == -1) return 1;" | 10390 " if (str.indexOf('TypeError') == -1) return 1;" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10475 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { | 10587 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 10476 args.GetReturnValue().Set(args.This()); | 10588 args.GetReturnValue().Set(args.This()); |
| 10477 } | 10589 } |
| 10478 | 10590 |
| 10479 | 10591 |
| 10480 // Test that a call handler can be set for objects which will allow | 10592 // Test that a call handler can be set for objects which will allow |
| 10481 // non-function objects created through the API to be called as | 10593 // non-function objects created through the API to be called as |
| 10482 // functions. | 10594 // functions. |
| 10483 THREADED_TEST(CallAsFunction) { | 10595 THREADED_TEST(CallAsFunction) { |
| 10484 LocalContext context; | 10596 LocalContext context; |
| 10485 v8::HandleScope scope(context->GetIsolate()); | 10597 v8::Isolate* isolate = context->GetIsolate(); |
| 10598 v8::HandleScope scope(isolate); |
| 10486 | 10599 |
| 10487 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 10600 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 10488 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 10601 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 10489 instance_template->SetCallAsFunctionHandler(call_as_function); | 10602 instance_template->SetCallAsFunctionHandler(call_as_function); |
| 10490 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 10603 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
| 10491 context->Global()->Set(v8_str("obj"), instance); | 10604 context->Global()->Set(v8_str("obj"), instance); |
| 10492 v8::TryCatch try_catch; | 10605 v8::TryCatch try_catch; |
| 10493 Local<Value> value; | 10606 Local<Value> value; |
| 10494 CHECK(!try_catch.HasCaught()); | 10607 CHECK(!try_catch.HasCaught()); |
| 10495 | 10608 |
| 10496 value = CompileRun("obj(42)"); | 10609 value = CompileRun("obj(42)"); |
| 10497 CHECK(!try_catch.HasCaught()); | 10610 CHECK(!try_catch.HasCaught()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10530 CHECK_EQ(-43, value->Int32Value()); | 10643 CHECK_EQ(-43, value->Int32Value()); |
| 10531 | 10644 |
| 10532 // Check that the call-as-function handler can be called through | 10645 // Check that the call-as-function handler can be called through |
| 10533 // the API. | 10646 // the API. |
| 10534 v8::Handle<Value> args[] = { v8_num(28) }; | 10647 v8::Handle<Value> args[] = { v8_num(28) }; |
| 10535 value = instance->CallAsFunction(instance, 1, args); | 10648 value = instance->CallAsFunction(instance, 1, args); |
| 10536 CHECK(!try_catch.HasCaught()); | 10649 CHECK(!try_catch.HasCaught()); |
| 10537 CHECK_EQ(28, value->Int32Value()); | 10650 CHECK_EQ(28, value->Int32Value()); |
| 10538 } | 10651 } |
| 10539 | 10652 |
| 10540 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 10653 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 10541 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); | 10654 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); |
| 10542 USE(instance_template); | 10655 USE(instance_template); |
| 10543 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 10656 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
| 10544 context->Global()->Set(v8_str("obj2"), instance); | 10657 context->Global()->Set(v8_str("obj2"), instance); |
| 10545 v8::TryCatch try_catch; | 10658 v8::TryCatch try_catch; |
| 10546 Local<Value> value; | 10659 Local<Value> value; |
| 10547 CHECK(!try_catch.HasCaught()); | 10660 CHECK(!try_catch.HasCaught()); |
| 10548 | 10661 |
| 10549 // Call an object without call-as-function handler through the JS | 10662 // Call an object without call-as-function handler through the JS |
| 10550 value = CompileRun("obj2(28)"); | 10663 value = CompileRun("obj2(28)"); |
| 10551 CHECK(value.IsEmpty()); | 10664 CHECK(value.IsEmpty()); |
| 10552 CHECK(try_catch.HasCaught()); | 10665 CHECK(try_catch.HasCaught()); |
| 10553 String::Utf8Value exception_value1(try_catch.Exception()); | 10666 String::Utf8Value exception_value1(try_catch.Exception()); |
| 10554 CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function", | 10667 CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function", |
| 10555 *exception_value1); | 10668 *exception_value1); |
| 10556 try_catch.Reset(); | 10669 try_catch.Reset(); |
| 10557 | 10670 |
| 10558 // Call an object without call-as-function handler through the API | 10671 // Call an object without call-as-function handler through the API |
| 10559 value = CompileRun("obj2(28)"); | 10672 value = CompileRun("obj2(28)"); |
| 10560 v8::Handle<Value> args[] = { v8_num(28) }; | 10673 v8::Handle<Value> args[] = { v8_num(28) }; |
| 10561 value = instance->CallAsFunction(instance, 1, args); | 10674 value = instance->CallAsFunction(instance, 1, args); |
| 10562 CHECK(value.IsEmpty()); | 10675 CHECK(value.IsEmpty()); |
| 10563 CHECK(try_catch.HasCaught()); | 10676 CHECK(try_catch.HasCaught()); |
| 10564 String::Utf8Value exception_value2(try_catch.Exception()); | 10677 String::Utf8Value exception_value2(try_catch.Exception()); |
| 10565 CHECK_EQ("TypeError: [object Object] is not a function", *exception_value2); | 10678 CHECK_EQ("TypeError: [object Object] is not a function", *exception_value2); |
| 10566 try_catch.Reset(); | 10679 try_catch.Reset(); |
| 10567 } | 10680 } |
| 10568 | 10681 |
| 10569 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | 10682 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 10570 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 10683 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 10571 instance_template->SetCallAsFunctionHandler(ThrowValue); | 10684 instance_template->SetCallAsFunctionHandler(ThrowValue); |
| 10572 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 10685 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
| 10573 context->Global()->Set(v8_str("obj3"), instance); | 10686 context->Global()->Set(v8_str("obj3"), instance); |
| 10574 v8::TryCatch try_catch; | 10687 v8::TryCatch try_catch; |
| 10575 Local<Value> value; | 10688 Local<Value> value; |
| 10576 CHECK(!try_catch.HasCaught()); | 10689 CHECK(!try_catch.HasCaught()); |
| 10577 | 10690 |
| 10578 // Catch the exception which is thrown by call-as-function handler | 10691 // Catch the exception which is thrown by call-as-function handler |
| 10579 value = CompileRun("obj3(22)"); | 10692 value = CompileRun("obj3(22)"); |
| 10580 CHECK(try_catch.HasCaught()); | 10693 CHECK(try_catch.HasCaught()); |
| 10581 String::Utf8Value exception_value1(try_catch.Exception()); | 10694 String::Utf8Value exception_value1(try_catch.Exception()); |
| 10582 CHECK_EQ("22", *exception_value1); | 10695 CHECK_EQ("22", *exception_value1); |
| 10583 try_catch.Reset(); | 10696 try_catch.Reset(); |
| 10584 | 10697 |
| 10585 v8::Handle<Value> args[] = { v8_num(23) }; | 10698 v8::Handle<Value> args[] = { v8_num(23) }; |
| 10586 value = instance->CallAsFunction(instance, 1, args); | 10699 value = instance->CallAsFunction(instance, 1, args); |
| 10587 CHECK(try_catch.HasCaught()); | 10700 CHECK(try_catch.HasCaught()); |
| 10588 String::Utf8Value exception_value2(try_catch.Exception()); | 10701 String::Utf8Value exception_value2(try_catch.Exception()); |
| 10589 CHECK_EQ("23", *exception_value2); | 10702 CHECK_EQ("23", *exception_value2); |
| 10590 try_catch.Reset(); | 10703 try_catch.Reset(); |
| 10591 } | 10704 } |
| 10592 | 10705 |
| 10593 { v8::Isolate* isolate = context->GetIsolate(); | 10706 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
| 10594 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); | |
| 10595 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 10707 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 10596 instance_template->SetCallAsFunctionHandler(ReturnThis); | 10708 instance_template->SetCallAsFunctionHandler(ReturnThis); |
| 10597 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 10709 Local<v8::Object> instance = t->GetFunction()->NewInstance(); |
| 10598 | 10710 |
| 10599 Local<v8::Value> a1 = | 10711 Local<v8::Value> a1 = |
| 10600 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); | 10712 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); |
| 10601 CHECK(a1->StrictEquals(instance)); | 10713 CHECK(a1->StrictEquals(instance)); |
| 10602 Local<v8::Value> a2 = | 10714 Local<v8::Value> a2 = |
| 10603 instance->CallAsFunction(v8::Null(isolate), 0, NULL); | 10715 instance->CallAsFunction(v8::Null(isolate), 0, NULL); |
| 10604 CHECK(a2->StrictEquals(instance)); | 10716 CHECK(a2->StrictEquals(instance)); |
| 10605 Local<v8::Value> a3 = | 10717 Local<v8::Value> a3 = |
| 10606 instance->CallAsFunction(v8_num(42), 0, NULL); | 10718 instance->CallAsFunction(v8_num(42), 0, NULL); |
| 10607 CHECK(a3->StrictEquals(instance)); | 10719 CHECK(a3->StrictEquals(instance)); |
| 10608 Local<v8::Value> a4 = | 10720 Local<v8::Value> a4 = |
| 10609 instance->CallAsFunction(v8_str("hello"), 0, NULL); | 10721 instance->CallAsFunction(v8_str("hello"), 0, NULL); |
| 10610 CHECK(a4->StrictEquals(instance)); | 10722 CHECK(a4->StrictEquals(instance)); |
| 10611 Local<v8::Value> a5 = | 10723 Local<v8::Value> a5 = |
| 10612 instance->CallAsFunction(v8::True(isolate), 0, NULL); | 10724 instance->CallAsFunction(v8::True(isolate), 0, NULL); |
| 10613 CHECK(a5->StrictEquals(instance)); | 10725 CHECK(a5->StrictEquals(instance)); |
| 10614 } | 10726 } |
| 10615 | 10727 |
| 10616 { v8::Isolate* isolate = context->GetIsolate(); | 10728 { CompileRun( |
| 10617 CompileRun( | |
| 10618 "function ReturnThisSloppy() {" | 10729 "function ReturnThisSloppy() {" |
| 10619 " return this;" | 10730 " return this;" |
| 10620 "}" | 10731 "}" |
| 10621 "function ReturnThisStrict() {" | 10732 "function ReturnThisStrict() {" |
| 10622 " 'use strict';" | 10733 " 'use strict';" |
| 10623 " return this;" | 10734 " return this;" |
| 10624 "}"); | 10735 "}"); |
| 10625 Local<Function> ReturnThisSloppy = | 10736 Local<Function> ReturnThisSloppy = |
| 10626 Local<Function>::Cast( | 10737 Local<Function>::Cast( |
| 10627 context->Global()->Get(v8_str("ReturnThisSloppy"))); | 10738 context->Global()->Get(v8_str("ReturnThisSloppy"))); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10663 Local<v8::Value> a10 = | 10774 Local<v8::Value> a10 = |
| 10664 ReturnThisStrict->CallAsFunction(v8::True(isolate), 0, NULL); | 10775 ReturnThisStrict->CallAsFunction(v8::True(isolate), 0, NULL); |
| 10665 CHECK(a10->StrictEquals(v8::True(isolate))); | 10776 CHECK(a10->StrictEquals(v8::True(isolate))); |
| 10666 } | 10777 } |
| 10667 } | 10778 } |
| 10668 | 10779 |
| 10669 | 10780 |
| 10670 // Check whether a non-function object is callable. | 10781 // Check whether a non-function object is callable. |
| 10671 THREADED_TEST(CallableObject) { | 10782 THREADED_TEST(CallableObject) { |
| 10672 LocalContext context; | 10783 LocalContext context; |
| 10673 v8::HandleScope scope(context->GetIsolate()); | 10784 v8::Isolate* isolate = context->GetIsolate(); |
| 10785 v8::HandleScope scope(isolate); |
| 10674 | 10786 |
| 10675 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10787 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); |
| 10676 instance_template->SetCallAsFunctionHandler(call_as_function); | 10788 instance_template->SetCallAsFunctionHandler(call_as_function); |
| 10677 Local<Object> instance = instance_template->NewInstance(); | 10789 Local<Object> instance = instance_template->NewInstance(); |
| 10678 v8::TryCatch try_catch; | 10790 v8::TryCatch try_catch; |
| 10679 | 10791 |
| 10680 CHECK(instance->IsCallable()); | 10792 CHECK(instance->IsCallable()); |
| 10681 CHECK(!try_catch.HasCaught()); | 10793 CHECK(!try_catch.HasCaught()); |
| 10682 } | 10794 } |
| 10683 | 10795 |
| 10684 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10796 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); |
| 10685 Local<Object> instance = instance_template->NewInstance(); | 10797 Local<Object> instance = instance_template->NewInstance(); |
| 10686 v8::TryCatch try_catch; | 10798 v8::TryCatch try_catch; |
| 10687 | 10799 |
| 10688 CHECK(!instance->IsCallable()); | 10800 CHECK(!instance->IsCallable()); |
| 10689 CHECK(!try_catch.HasCaught()); | 10801 CHECK(!try_catch.HasCaught()); |
| 10690 } | 10802 } |
| 10691 | 10803 |
| 10692 { Local<FunctionTemplate> function_template = | 10804 { Local<FunctionTemplate> function_template = |
| 10693 FunctionTemplate::New(call_as_function); | 10805 FunctionTemplate::New(isolate, call_as_function); |
| 10694 Local<Function> function = function_template->GetFunction(); | 10806 Local<Function> function = function_template->GetFunction(); |
| 10695 Local<Object> instance = function; | 10807 Local<Object> instance = function; |
| 10696 v8::TryCatch try_catch; | 10808 v8::TryCatch try_catch; |
| 10697 | 10809 |
| 10698 CHECK(instance->IsCallable()); | 10810 CHECK(instance->IsCallable()); |
| 10699 CHECK(!try_catch.HasCaught()); | 10811 CHECK(!try_catch.HasCaught()); |
| 10700 } | 10812 } |
| 10701 | 10813 |
| 10702 { Local<FunctionTemplate> function_template = FunctionTemplate::New(); | 10814 { Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate); |
| 10703 Local<Function> function = function_template->GetFunction(); | 10815 Local<Function> function = function_template->GetFunction(); |
| 10704 Local<Object> instance = function; | 10816 Local<Object> instance = function; |
| 10705 v8::TryCatch try_catch; | 10817 v8::TryCatch try_catch; |
| 10706 | 10818 |
| 10707 CHECK(instance->IsCallable()); | 10819 CHECK(instance->IsCallable()); |
| 10708 CHECK(!try_catch.HasCaught()); | 10820 CHECK(!try_catch.HasCaught()); |
| 10709 } | 10821 } |
| 10710 } | 10822 } |
| 10711 | 10823 |
| 10712 | 10824 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10754 | 10866 |
| 10755 static void InterceptorHasOwnPropertyGetter( | 10867 static void InterceptorHasOwnPropertyGetter( |
| 10756 Local<String> name, | 10868 Local<String> name, |
| 10757 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10869 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 10758 ApiTestFuzzer::Fuzz(); | 10870 ApiTestFuzzer::Fuzz(); |
| 10759 } | 10871 } |
| 10760 | 10872 |
| 10761 | 10873 |
| 10762 THREADED_TEST(InterceptorHasOwnProperty) { | 10874 THREADED_TEST(InterceptorHasOwnProperty) { |
| 10763 LocalContext context; | 10875 LocalContext context; |
| 10764 v8::HandleScope scope(context->GetIsolate()); | 10876 v8::Isolate* isolate = context->GetIsolate(); |
| 10765 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10877 v8::HandleScope scope(isolate); |
| 10878 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
| 10766 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 10879 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
| 10767 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); | 10880 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); |
| 10768 Local<Function> function = fun_templ->GetFunction(); | 10881 Local<Function> function = fun_templ->GetFunction(); |
| 10769 context->Global()->Set(v8_str("constructor"), function); | 10882 context->Global()->Set(v8_str("constructor"), function); |
| 10770 v8::Handle<Value> value = CompileRun( | 10883 v8::Handle<Value> value = CompileRun( |
| 10771 "var o = new constructor();" | 10884 "var o = new constructor();" |
| 10772 "o.hasOwnProperty('ostehaps');"); | 10885 "o.hasOwnProperty('ostehaps');"); |
| 10773 CHECK_EQ(false, value->BooleanValue()); | 10886 CHECK_EQ(false, value->BooleanValue()); |
| 10774 value = CompileRun( | 10887 value = CompileRun( |
| 10775 "o.ostehaps = 42;" | 10888 "o.ostehaps = 42;" |
| 10776 "o.hasOwnProperty('ostehaps');"); | 10889 "o.hasOwnProperty('ostehaps');"); |
| 10777 CHECK_EQ(true, value->BooleanValue()); | 10890 CHECK_EQ(true, value->BooleanValue()); |
| 10778 value = CompileRun( | 10891 value = CompileRun( |
| 10779 "var p = new constructor();" | 10892 "var p = new constructor();" |
| 10780 "p.hasOwnProperty('ostehaps');"); | 10893 "p.hasOwnProperty('ostehaps');"); |
| 10781 CHECK_EQ(false, value->BooleanValue()); | 10894 CHECK_EQ(false, value->BooleanValue()); |
| 10782 } | 10895 } |
| 10783 | 10896 |
| 10784 | 10897 |
| 10785 static void InterceptorHasOwnPropertyGetterGC( | 10898 static void InterceptorHasOwnPropertyGetterGC( |
| 10786 Local<String> name, | 10899 Local<String> name, |
| 10787 const v8::PropertyCallbackInfo<v8::Value>& info) { | 10900 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 10788 ApiTestFuzzer::Fuzz(); | 10901 ApiTestFuzzer::Fuzz(); |
| 10789 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 10902 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 10790 } | 10903 } |
| 10791 | 10904 |
| 10792 | 10905 |
| 10793 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { | 10906 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { |
| 10794 LocalContext context; | 10907 LocalContext context; |
| 10795 v8::HandleScope scope(context->GetIsolate()); | 10908 v8::Isolate* isolate = context->GetIsolate(); |
| 10796 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 10909 v8::HandleScope scope(isolate); |
| 10910 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
| 10797 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); | 10911 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); |
| 10798 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); | 10912 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); |
| 10799 Local<Function> function = fun_templ->GetFunction(); | 10913 Local<Function> function = fun_templ->GetFunction(); |
| 10800 context->Global()->Set(v8_str("constructor"), function); | 10914 context->Global()->Set(v8_str("constructor"), function); |
| 10801 // Let's first make some stuff so we can be sure to get a good GC. | 10915 // Let's first make some stuff so we can be sure to get a good GC. |
| 10802 CompileRun( | 10916 CompileRun( |
| 10803 "function makestr(size) {" | 10917 "function makestr(size) {" |
| 10804 " switch (size) {" | 10918 " switch (size) {" |
| 10805 " case 1: return 'f';" | 10919 " case 1: return 'f';" |
| 10806 " case 2: return 'fo';" | 10920 " case 2: return 'fo';" |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11616 if (count++ % 3 == 0) { | 11730 if (count++ % 3 == 0) { |
| 11617 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 11731 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
| 11618 // This should move the stub | 11732 // This should move the stub |
| 11619 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed | 11733 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 11620 } | 11734 } |
| 11621 } | 11735 } |
| 11622 | 11736 |
| 11623 | 11737 |
| 11624 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { | 11738 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 11625 LocalContext context; | 11739 LocalContext context; |
| 11626 v8::HandleScope scope(context->GetIsolate()); | 11740 v8::Isolate* isolate = context->GetIsolate(); |
| 11741 v8::HandleScope scope(isolate); |
| 11627 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); | 11742 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| 11628 nativeobject_templ->Set(context->GetIsolate(), "callback", | 11743 nativeobject_templ->Set(isolate, "callback", |
| 11629 v8::FunctionTemplate::New(DirectApiCallback)); | 11744 v8::FunctionTemplate::New(isolate, |
| 11745 DirectApiCallback)); |
| 11630 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11746 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 11631 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11747 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 11632 // call the api function multiple times to ensure direct call stub creation. | 11748 // call the api function multiple times to ensure direct call stub creation. |
| 11633 CompileRun( | 11749 CompileRun( |
| 11634 "function f() {" | 11750 "function f() {" |
| 11635 " for (var i = 1; i <= 30; i++) {" | 11751 " for (var i = 1; i <= 30; i++) {" |
| 11636 " nativeobject.callback();" | 11752 " nativeobject.callback();" |
| 11637 " }" | 11753 " }" |
| 11638 "}" | 11754 "}" |
| 11639 "f();"); | 11755 "f();"); |
| 11640 } | 11756 } |
| 11641 | 11757 |
| 11642 | 11758 |
| 11643 void ThrowingDirectApiCallback( | 11759 void ThrowingDirectApiCallback( |
| 11644 const v8::FunctionCallbackInfo<v8::Value>& args) { | 11760 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 11645 args.GetIsolate()->ThrowException(v8_str("g")); | 11761 args.GetIsolate()->ThrowException(v8_str("g")); |
| 11646 } | 11762 } |
| 11647 | 11763 |
| 11648 | 11764 |
| 11649 THREADED_TEST(CallICFastApi_DirectCall_Throw) { | 11765 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
| 11650 LocalContext context; | 11766 LocalContext context; |
| 11651 v8::HandleScope scope(context->GetIsolate()); | 11767 v8::Isolate* isolate = context->GetIsolate(); |
| 11652 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); | 11768 v8::HandleScope scope(isolate); |
| 11653 nativeobject_templ->Set(context->GetIsolate(), "callback", | 11769 v8::Handle<v8::ObjectTemplate> nativeobject_templ = |
| 11654 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); | 11770 v8::ObjectTemplate::New(); |
| 11771 nativeobject_templ->Set(isolate, "callback", |
| 11772 v8::FunctionTemplate::New(isolate, |
| 11773 ThrowingDirectApiCallback)); |
| 11655 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11774 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
| 11656 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11775 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
| 11657 // call the api function multiple times to ensure direct call stub creation. | 11776 // call the api function multiple times to ensure direct call stub creation. |
| 11658 v8::Handle<Value> result = CompileRun( | 11777 v8::Handle<Value> result = CompileRun( |
| 11659 "var result = '';" | 11778 "var result = '';" |
| 11660 "function f() {" | 11779 "function f() {" |
| 11661 " for (var i = 1; i <= 5; i++) {" | 11780 " for (var i = 1; i <= 5; i++) {" |
| 11662 " try { nativeobject.callback(); } catch (e) { result += e; }" | 11781 " try { nativeobject.callback(); } catch (e) { result += e; }" |
| 11663 " }" | 11782 " }" |
| 11664 "}" | 11783 "}" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11725 "for (var i = 0; i < 5; i++) {" | 11844 "for (var i = 0; i < 5; i++) {" |
| 11726 " try { o1.p1; } catch (e) { result += e; }" | 11845 " try { o1.p1; } catch (e) { result += e; }" |
| 11727 "}" | 11846 "}" |
| 11728 "result;"); | 11847 "result;"); |
| 11729 CHECK_EQ(v8_str("ggggg"), result); | 11848 CHECK_EQ(v8_str("ggggg"), result); |
| 11730 } | 11849 } |
| 11731 | 11850 |
| 11732 | 11851 |
| 11733 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 11852 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
| 11734 int interceptor_call_count = 0; | 11853 int interceptor_call_count = 0; |
| 11735 v8::HandleScope scope(CcTest::isolate()); | 11854 v8::Isolate* isolate = CcTest::isolate(); |
| 11736 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 11855 v8::HandleScope scope(isolate); |
| 11856 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 11857 v8::FunctionTemplate::New(isolate); |
| 11737 v8::Handle<v8::FunctionTemplate> method_templ = | 11858 v8::Handle<v8::FunctionTemplate> method_templ = |
| 11738 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 11859 v8::FunctionTemplate::New(isolate, |
| 11860 FastApiCallback_TrivialSignature, |
| 11739 v8_str("method_data"), | 11861 v8_str("method_data"), |
| 11740 v8::Handle<v8::Signature>()); | 11862 v8::Handle<v8::Signature>()); |
| 11741 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 11863 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11742 proto_templ->Set(v8_str("method"), method_templ); | 11864 proto_templ->Set(v8_str("method"), method_templ); |
| 11743 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11865 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11744 templ->SetNamedPropertyHandler( | 11866 templ->SetNamedPropertyHandler( |
| 11745 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11867 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11746 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 11868 v8::External::New(isolate, &interceptor_call_count)); |
| 11747 LocalContext context; | 11869 LocalContext context; |
| 11748 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11870 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11749 GenerateSomeGarbage(); | 11871 GenerateSomeGarbage(); |
| 11750 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11872 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11751 CompileRun( | 11873 CompileRun( |
| 11752 "var result = 0;" | 11874 "var result = 0;" |
| 11753 "for (var i = 0; i < 100; i++) {" | 11875 "for (var i = 0; i < 100; i++) {" |
| 11754 " result = o.method(41);" | 11876 " result = o.method(41);" |
| 11755 "}"); | 11877 "}"); |
| 11756 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 11878 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11757 CHECK_EQ(100, interceptor_call_count); | 11879 CHECK_EQ(100, interceptor_call_count); |
| 11758 } | 11880 } |
| 11759 | 11881 |
| 11760 | 11882 |
| 11761 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 11883 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
| 11762 int interceptor_call_count = 0; | 11884 int interceptor_call_count = 0; |
| 11763 v8::HandleScope scope(CcTest::isolate()); | 11885 v8::Isolate* isolate = CcTest::isolate(); |
| 11764 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 11886 v8::HandleScope scope(isolate); |
| 11887 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 11888 v8::FunctionTemplate::New(isolate); |
| 11765 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 11889 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11766 FastApiCallback_SimpleSignature, v8_str("method_data"), | 11890 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11767 v8::Signature::New(CcTest::isolate(), fun_templ)); | 11891 v8::Signature::New(isolate, fun_templ)); |
| 11768 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 11892 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11769 proto_templ->Set(v8_str("method"), method_templ); | 11893 proto_templ->Set(v8_str("method"), method_templ); |
| 11770 fun_templ->SetHiddenPrototype(true); | 11894 fun_templ->SetHiddenPrototype(true); |
| 11771 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11895 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11772 templ->SetNamedPropertyHandler( | 11896 templ->SetNamedPropertyHandler( |
| 11773 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11897 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11774 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 11898 v8::External::New(isolate, &interceptor_call_count)); |
| 11775 LocalContext context; | 11899 LocalContext context; |
| 11776 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11900 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11777 GenerateSomeGarbage(); | 11901 GenerateSomeGarbage(); |
| 11778 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11902 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11779 CompileRun( | 11903 CompileRun( |
| 11780 "o.foo = 17;" | 11904 "o.foo = 17;" |
| 11781 "var receiver = {};" | 11905 "var receiver = {};" |
| 11782 "receiver.__proto__ = o;" | 11906 "receiver.__proto__ = o;" |
| 11783 "var result = 0;" | 11907 "var result = 0;" |
| 11784 "for (var i = 0; i < 100; i++) {" | 11908 "for (var i = 0; i < 100; i++) {" |
| 11785 " result = receiver.method(41);" | 11909 " result = receiver.method(41);" |
| 11786 "}"); | 11910 "}"); |
| 11787 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 11911 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11788 CHECK_EQ(100, interceptor_call_count); | 11912 CHECK_EQ(100, interceptor_call_count); |
| 11789 } | 11913 } |
| 11790 | 11914 |
| 11791 | 11915 |
| 11792 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { | 11916 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { |
| 11793 int interceptor_call_count = 0; | 11917 int interceptor_call_count = 0; |
| 11794 v8::HandleScope scope(CcTest::isolate()); | 11918 v8::Isolate* isolate = CcTest::isolate(); |
| 11795 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 11919 v8::HandleScope scope(isolate); |
| 11920 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 11921 v8::FunctionTemplate::New(isolate); |
| 11796 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 11922 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11797 FastApiCallback_SimpleSignature, v8_str("method_data"), | 11923 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11798 v8::Signature::New(CcTest::isolate(), fun_templ)); | 11924 v8::Signature::New(isolate, fun_templ)); |
| 11799 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 11925 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11800 proto_templ->Set(v8_str("method"), method_templ); | 11926 proto_templ->Set(v8_str("method"), method_templ); |
| 11801 fun_templ->SetHiddenPrototype(true); | 11927 fun_templ->SetHiddenPrototype(true); |
| 11802 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11928 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11803 templ->SetNamedPropertyHandler( | 11929 templ->SetNamedPropertyHandler( |
| 11804 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11930 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11805 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 11931 v8::External::New(isolate, &interceptor_call_count)); |
| 11806 LocalContext context; | 11932 LocalContext context; |
| 11807 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11933 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11808 GenerateSomeGarbage(); | 11934 GenerateSomeGarbage(); |
| 11809 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11935 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11810 CompileRun( | 11936 CompileRun( |
| 11811 "o.foo = 17;" | 11937 "o.foo = 17;" |
| 11812 "var receiver = {};" | 11938 "var receiver = {};" |
| 11813 "receiver.__proto__ = o;" | 11939 "receiver.__proto__ = o;" |
| 11814 "var result = 0;" | 11940 "var result = 0;" |
| 11815 "var saved_result = 0;" | 11941 "var saved_result = 0;" |
| 11816 "for (var i = 0; i < 100; i++) {" | 11942 "for (var i = 0; i < 100; i++) {" |
| 11817 " result = receiver.method(41);" | 11943 " result = receiver.method(41);" |
| 11818 " if (i == 50) {" | 11944 " if (i == 50) {" |
| 11819 " saved_result = result;" | 11945 " saved_result = result;" |
| 11820 " receiver = {method: function(x) { return x - 1 }};" | 11946 " receiver = {method: function(x) { return x - 1 }};" |
| 11821 " }" | 11947 " }" |
| 11822 "}"); | 11948 "}"); |
| 11823 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 11949 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11824 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 11950 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 11825 CHECK_GE(interceptor_call_count, 50); | 11951 CHECK_GE(interceptor_call_count, 50); |
| 11826 } | 11952 } |
| 11827 | 11953 |
| 11828 | 11954 |
| 11829 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { | 11955 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { |
| 11830 int interceptor_call_count = 0; | 11956 int interceptor_call_count = 0; |
| 11831 v8::HandleScope scope(CcTest::isolate()); | 11957 v8::Isolate* isolate = CcTest::isolate(); |
| 11832 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 11958 v8::HandleScope scope(isolate); |
| 11959 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 11960 v8::FunctionTemplate::New(isolate); |
| 11833 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 11961 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11834 FastApiCallback_SimpleSignature, v8_str("method_data"), | 11962 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11835 v8::Signature::New(CcTest::isolate(), fun_templ)); | 11963 v8::Signature::New(isolate, fun_templ)); |
| 11836 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 11964 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11837 proto_templ->Set(v8_str("method"), method_templ); | 11965 proto_templ->Set(v8_str("method"), method_templ); |
| 11838 fun_templ->SetHiddenPrototype(true); | 11966 fun_templ->SetHiddenPrototype(true); |
| 11839 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11967 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11840 templ->SetNamedPropertyHandler( | 11968 templ->SetNamedPropertyHandler( |
| 11841 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11969 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11842 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 11970 v8::External::New(isolate, &interceptor_call_count)); |
| 11843 LocalContext context; | 11971 LocalContext context; |
| 11844 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11972 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11845 GenerateSomeGarbage(); | 11973 GenerateSomeGarbage(); |
| 11846 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11974 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11847 CompileRun( | 11975 CompileRun( |
| 11848 "o.foo = 17;" | 11976 "o.foo = 17;" |
| 11849 "var receiver = {};" | 11977 "var receiver = {};" |
| 11850 "receiver.__proto__ = o;" | 11978 "receiver.__proto__ = o;" |
| 11851 "var result = 0;" | 11979 "var result = 0;" |
| 11852 "var saved_result = 0;" | 11980 "var saved_result = 0;" |
| 11853 "for (var i = 0; i < 100; i++) {" | 11981 "for (var i = 0; i < 100; i++) {" |
| 11854 " result = receiver.method(41);" | 11982 " result = receiver.method(41);" |
| 11855 " if (i == 50) {" | 11983 " if (i == 50) {" |
| 11856 " saved_result = result;" | 11984 " saved_result = result;" |
| 11857 " o.method = function(x) { return x - 1 };" | 11985 " o.method = function(x) { return x - 1 };" |
| 11858 " }" | 11986 " }" |
| 11859 "}"); | 11987 "}"); |
| 11860 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 11988 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11861 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 11989 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 11862 CHECK_GE(interceptor_call_count, 50); | 11990 CHECK_GE(interceptor_call_count, 50); |
| 11863 } | 11991 } |
| 11864 | 11992 |
| 11865 | 11993 |
| 11866 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { | 11994 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { |
| 11867 int interceptor_call_count = 0; | 11995 int interceptor_call_count = 0; |
| 11868 v8::HandleScope scope(CcTest::isolate()); | 11996 v8::Isolate* isolate = CcTest::isolate(); |
| 11869 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 11997 v8::HandleScope scope(isolate); |
| 11998 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 11999 v8::FunctionTemplate::New(isolate); |
| 11870 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12000 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11871 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12001 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11872 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12002 v8::Signature::New(isolate, fun_templ)); |
| 11873 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12003 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11874 proto_templ->Set(v8_str("method"), method_templ); | 12004 proto_templ->Set(v8_str("method"), method_templ); |
| 11875 fun_templ->SetHiddenPrototype(true); | 12005 fun_templ->SetHiddenPrototype(true); |
| 11876 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12006 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11877 templ->SetNamedPropertyHandler( | 12007 templ->SetNamedPropertyHandler( |
| 11878 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12008 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11879 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 12009 v8::External::New(isolate, &interceptor_call_count)); |
| 11880 LocalContext context; | 12010 LocalContext context; |
| 11881 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12011 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11882 GenerateSomeGarbage(); | 12012 GenerateSomeGarbage(); |
| 11883 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12013 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11884 v8::TryCatch try_catch; | 12014 v8::TryCatch try_catch; |
| 11885 CompileRun( | 12015 CompileRun( |
| 11886 "o.foo = 17;" | 12016 "o.foo = 17;" |
| 11887 "var receiver = {};" | 12017 "var receiver = {};" |
| 11888 "receiver.__proto__ = o;" | 12018 "receiver.__proto__ = o;" |
| 11889 "var result = 0;" | 12019 "var result = 0;" |
| 11890 "var saved_result = 0;" | 12020 "var saved_result = 0;" |
| 11891 "for (var i = 0; i < 100; i++) {" | 12021 "for (var i = 0; i < 100; i++) {" |
| 11892 " result = receiver.method(41);" | 12022 " result = receiver.method(41);" |
| 11893 " if (i == 50) {" | 12023 " if (i == 50) {" |
| 11894 " saved_result = result;" | 12024 " saved_result = result;" |
| 11895 " receiver = 333;" | 12025 " receiver = 333;" |
| 11896 " }" | 12026 " }" |
| 11897 "}"); | 12027 "}"); |
| 11898 CHECK(try_catch.HasCaught()); | 12028 CHECK(try_catch.HasCaught()); |
| 11899 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 12029 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
| 11900 try_catch.Exception()->ToString()); | 12030 try_catch.Exception()->ToString()); |
| 11901 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12031 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 11902 CHECK_GE(interceptor_call_count, 50); | 12032 CHECK_GE(interceptor_call_count, 50); |
| 11903 } | 12033 } |
| 11904 | 12034 |
| 11905 | 12035 |
| 11906 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { | 12036 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { |
| 11907 int interceptor_call_count = 0; | 12037 int interceptor_call_count = 0; |
| 11908 v8::HandleScope scope(CcTest::isolate()); | 12038 v8::Isolate* isolate = CcTest::isolate(); |
| 11909 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12039 v8::HandleScope scope(isolate); |
| 12040 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12041 v8::FunctionTemplate::New(isolate); |
| 11910 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12042 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11911 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12043 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11912 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12044 v8::Signature::New(isolate, fun_templ)); |
| 11913 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12045 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11914 proto_templ->Set(v8_str("method"), method_templ); | 12046 proto_templ->Set(v8_str("method"), method_templ); |
| 11915 fun_templ->SetHiddenPrototype(true); | 12047 fun_templ->SetHiddenPrototype(true); |
| 11916 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12048 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
| 11917 templ->SetNamedPropertyHandler( | 12049 templ->SetNamedPropertyHandler( |
| 11918 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12050 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
| 11919 v8::External::New(CcTest::isolate(), &interceptor_call_count)); | 12051 v8::External::New(isolate, &interceptor_call_count)); |
| 11920 LocalContext context; | 12052 LocalContext context; |
| 11921 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12053 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11922 GenerateSomeGarbage(); | 12054 GenerateSomeGarbage(); |
| 11923 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12055 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11924 v8::TryCatch try_catch; | 12056 v8::TryCatch try_catch; |
| 11925 CompileRun( | 12057 CompileRun( |
| 11926 "o.foo = 17;" | 12058 "o.foo = 17;" |
| 11927 "var receiver = {};" | 12059 "var receiver = {};" |
| 11928 "receiver.__proto__ = o;" | 12060 "receiver.__proto__ = o;" |
| 11929 "var result = 0;" | 12061 "var result = 0;" |
| 11930 "var saved_result = 0;" | 12062 "var saved_result = 0;" |
| 11931 "for (var i = 0; i < 100; i++) {" | 12063 "for (var i = 0; i < 100; i++) {" |
| 11932 " result = receiver.method(41);" | 12064 " result = receiver.method(41);" |
| 11933 " if (i == 50) {" | 12065 " if (i == 50) {" |
| 11934 " saved_result = result;" | 12066 " saved_result = result;" |
| 11935 " receiver = {method: receiver.method};" | 12067 " receiver = {method: receiver.method};" |
| 11936 " }" | 12068 " }" |
| 11937 "}"); | 12069 "}"); |
| 11938 CHECK(try_catch.HasCaught()); | 12070 CHECK(try_catch.HasCaught()); |
| 11939 CHECK_EQ(v8_str("TypeError: Illegal invocation"), | 12071 CHECK_EQ(v8_str("TypeError: Illegal invocation"), |
| 11940 try_catch.Exception()->ToString()); | 12072 try_catch.Exception()->ToString()); |
| 11941 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12073 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 11942 CHECK_GE(interceptor_call_count, 50); | 12074 CHECK_GE(interceptor_call_count, 50); |
| 11943 } | 12075 } |
| 11944 | 12076 |
| 11945 | 12077 |
| 11946 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { | 12078 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { |
| 11947 v8::HandleScope scope(CcTest::isolate()); | 12079 v8::Isolate* isolate = CcTest::isolate(); |
| 11948 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12080 v8::HandleScope scope(isolate); |
| 12081 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12082 v8::FunctionTemplate::New(isolate); |
| 11949 v8::Handle<v8::FunctionTemplate> method_templ = | 12083 v8::Handle<v8::FunctionTemplate> method_templ = |
| 11950 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 12084 v8::FunctionTemplate::New(isolate, |
| 12085 FastApiCallback_TrivialSignature, |
| 11951 v8_str("method_data"), | 12086 v8_str("method_data"), |
| 11952 v8::Handle<v8::Signature>()); | 12087 v8::Handle<v8::Signature>()); |
| 11953 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12088 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11954 proto_templ->Set(v8_str("method"), method_templ); | 12089 proto_templ->Set(v8_str("method"), method_templ); |
| 11955 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12090 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 11956 USE(templ); | 12091 USE(templ); |
| 11957 LocalContext context; | 12092 LocalContext context; |
| 11958 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12093 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11959 GenerateSomeGarbage(); | 12094 GenerateSomeGarbage(); |
| 11960 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12095 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11961 CompileRun( | 12096 CompileRun( |
| 11962 "var result = 0;" | 12097 "var result = 0;" |
| 11963 "for (var i = 0; i < 100; i++) {" | 12098 "for (var i = 0; i < 100; i++) {" |
| 11964 " result = o.method(41);" | 12099 " result = o.method(41);" |
| 11965 "}"); | 12100 "}"); |
| 11966 | 12101 |
| 11967 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12102 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11968 } | 12103 } |
| 11969 | 12104 |
| 11970 | 12105 |
| 11971 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { | 12106 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { |
| 11972 v8::HandleScope scope(CcTest::isolate()); | 12107 v8::Isolate* isolate = CcTest::isolate(); |
| 11973 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12108 v8::HandleScope scope(isolate); |
| 12109 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12110 v8::FunctionTemplate::New(isolate); |
| 11974 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12111 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 11975 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12112 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 11976 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12113 v8::Signature::New(isolate, fun_templ)); |
| 11977 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12114 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 11978 proto_templ->Set(v8_str("method"), method_templ); | 12115 proto_templ->Set(v8_str("method"), method_templ); |
| 11979 fun_templ->SetHiddenPrototype(true); | 12116 fun_templ->SetHiddenPrototype(true); |
| 11980 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12117 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 11981 CHECK(!templ.IsEmpty()); | 12118 CHECK(!templ.IsEmpty()); |
| 11982 LocalContext context; | 12119 LocalContext context; |
| 11983 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12120 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 11984 GenerateSomeGarbage(); | 12121 GenerateSomeGarbage(); |
| 11985 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12122 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 11986 CompileRun( | 12123 CompileRun( |
| 11987 "o.foo = 17;" | 12124 "o.foo = 17;" |
| 11988 "var receiver = {};" | 12125 "var receiver = {};" |
| 11989 "receiver.__proto__ = o;" | 12126 "receiver.__proto__ = o;" |
| 11990 "var result = 0;" | 12127 "var result = 0;" |
| 11991 "for (var i = 0; i < 100; i++) {" | 12128 "for (var i = 0; i < 100; i++) {" |
| 11992 " result = receiver.method(41);" | 12129 " result = receiver.method(41);" |
| 11993 "}"); | 12130 "}"); |
| 11994 | 12131 |
| 11995 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12132 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 11996 } | 12133 } |
| 11997 | 12134 |
| 11998 | 12135 |
| 11999 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { | 12136 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { |
| 12000 v8::HandleScope scope(CcTest::isolate()); | 12137 v8::Isolate* isolate = CcTest::isolate(); |
| 12001 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12138 v8::HandleScope scope(isolate); |
| 12139 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12140 v8::FunctionTemplate::New(isolate); |
| 12002 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12141 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 12003 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12142 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 12004 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12143 v8::Signature::New(isolate, fun_templ)); |
| 12005 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12144 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 12006 proto_templ->Set(v8_str("method"), method_templ); | 12145 proto_templ->Set(v8_str("method"), method_templ); |
| 12007 fun_templ->SetHiddenPrototype(true); | 12146 fun_templ->SetHiddenPrototype(true); |
| 12008 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12147 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 12009 CHECK(!templ.IsEmpty()); | 12148 CHECK(!templ.IsEmpty()); |
| 12010 LocalContext context; | 12149 LocalContext context; |
| 12011 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12150 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 12012 GenerateSomeGarbage(); | 12151 GenerateSomeGarbage(); |
| 12013 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12152 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 12014 CompileRun( | 12153 CompileRun( |
| 12015 "o.foo = 17;" | 12154 "o.foo = 17;" |
| 12016 "var receiver = {};" | 12155 "var receiver = {};" |
| 12017 "receiver.__proto__ = o;" | 12156 "receiver.__proto__ = o;" |
| 12018 "var result = 0;" | 12157 "var result = 0;" |
| 12019 "var saved_result = 0;" | 12158 "var saved_result = 0;" |
| 12020 "for (var i = 0; i < 100; i++) {" | 12159 "for (var i = 0; i < 100; i++) {" |
| 12021 " result = receiver.method(41);" | 12160 " result = receiver.method(41);" |
| 12022 " if (i == 50) {" | 12161 " if (i == 50) {" |
| 12023 " saved_result = result;" | 12162 " saved_result = result;" |
| 12024 " receiver = {method: function(x) { return x - 1 }};" | 12163 " receiver = {method: function(x) { return x - 1 }};" |
| 12025 " }" | 12164 " }" |
| 12026 "}"); | 12165 "}"); |
| 12027 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 12166 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); |
| 12028 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12167 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 12029 } | 12168 } |
| 12030 | 12169 |
| 12031 | 12170 |
| 12032 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { | 12171 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { |
| 12033 v8::HandleScope scope(CcTest::isolate()); | 12172 v8::Isolate* isolate = CcTest::isolate(); |
| 12034 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12173 v8::HandleScope scope(isolate); |
| 12174 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12175 v8::FunctionTemplate::New(isolate); |
| 12035 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12176 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 12036 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12177 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 12037 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12178 v8::Signature::New(isolate, fun_templ)); |
| 12038 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12179 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 12039 proto_templ->Set(v8_str("method"), method_templ); | 12180 proto_templ->Set(v8_str("method"), method_templ); |
| 12040 fun_templ->SetHiddenPrototype(true); | 12181 fun_templ->SetHiddenPrototype(true); |
| 12041 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12182 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 12042 CHECK(!templ.IsEmpty()); | 12183 CHECK(!templ.IsEmpty()); |
| 12043 LocalContext context; | 12184 LocalContext context; |
| 12044 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12185 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 12045 GenerateSomeGarbage(); | 12186 GenerateSomeGarbage(); |
| 12046 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12187 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 12047 v8::TryCatch try_catch; | 12188 v8::TryCatch try_catch; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 12059 " }" | 12200 " }" |
| 12060 "}"); | 12201 "}"); |
| 12061 CHECK(try_catch.HasCaught()); | 12202 CHECK(try_catch.HasCaught()); |
| 12062 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), | 12203 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), |
| 12063 try_catch.Exception()->ToString()); | 12204 try_catch.Exception()->ToString()); |
| 12064 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12205 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
| 12065 } | 12206 } |
| 12066 | 12207 |
| 12067 | 12208 |
| 12068 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { | 12209 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { |
| 12069 v8::HandleScope scope(CcTest::isolate()); | 12210 v8::Isolate* isolate = CcTest::isolate(); |
| 12070 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 12211 v8::HandleScope scope(isolate); |
| 12212 v8::Handle<v8::FunctionTemplate> fun_templ = |
| 12213 v8::FunctionTemplate::New(isolate); |
| 12071 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12214 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
| 12072 FastApiCallback_SimpleSignature, v8_str("method_data"), | 12215 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
| 12073 v8::Signature::New(CcTest::isolate(), fun_templ)); | 12216 v8::Signature::New(isolate, fun_templ)); |
| 12074 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12217 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 12075 proto_templ->Set(v8_str("method"), method_templ); | 12218 proto_templ->Set(v8_str("method"), method_templ); |
| 12076 fun_templ->SetHiddenPrototype(true); | 12219 fun_templ->SetHiddenPrototype(true); |
| 12077 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12220 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
| 12078 CHECK(!templ.IsEmpty()); | 12221 CHECK(!templ.IsEmpty()); |
| 12079 LocalContext context; | 12222 LocalContext context; |
| 12080 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12223 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); |
| 12081 GenerateSomeGarbage(); | 12224 GenerateSomeGarbage(); |
| 12082 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12225 context->Global()->Set(v8_str("o"), fun->NewInstance()); |
| 12083 v8::TryCatch try_catch; | 12226 v8::TryCatch try_catch; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12408 templ->Set(CcTest::isolate(), "42", v8_num(42)); | 12551 templ->Set(CcTest::isolate(), "42", v8_num(42)); |
| 12409 v8::Handle<v8::Object> obj = templ->NewInstance(); | 12552 v8::Handle<v8::Object> obj = templ->NewInstance(); |
| 12410 context->Global()->Set(v8_str("obj"), obj); | 12553 context->Global()->Set(v8_str("obj"), obj); |
| 12411 v8::Handle<Value> value = CompileRun("obj[42]"); | 12554 v8::Handle<Value> value = CompileRun("obj[42]"); |
| 12412 CHECK(value->IsInt32()); | 12555 CHECK(value->IsInt32()); |
| 12413 CHECK_EQ(42, value->Int32Value()); | 12556 CHECK_EQ(42, value->Int32Value()); |
| 12414 } | 12557 } |
| 12415 | 12558 |
| 12416 | 12559 |
| 12417 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { | 12560 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { |
| 12418 v8::HandleScope scope(CcTest::isolate()); | 12561 v8::Isolate* isolate = CcTest::isolate(); |
| 12419 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 12562 v8::HandleScope scope(isolate); |
| 12563 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 12420 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 12564 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
| 12421 LocalContext env; | 12565 LocalContext env; |
| 12422 env->Global()->Set(v8_str("obj"), | 12566 env->Global()->Set(v8_str("obj"), |
| 12423 templ->GetFunction()->NewInstance()); | 12567 templ->GetFunction()->NewInstance()); |
| 12424 ExpectTrue("obj.x === 42"); | 12568 ExpectTrue("obj.x === 42"); |
| 12425 ExpectTrue("!obj.propertyIsEnumerable('x')"); | 12569 ExpectTrue("!obj.propertyIsEnumerable('x')"); |
| 12426 } | 12570 } |
| 12427 | 12571 |
| 12428 | 12572 |
| 12429 static void ThrowingGetter(Local<String> name, | 12573 static void ThrowingGetter(Local<String> name, |
| 12430 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12574 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 12431 ApiTestFuzzer::Fuzz(); | 12575 ApiTestFuzzer::Fuzz(); |
| 12432 info.GetIsolate()->ThrowException(Handle<Value>()); | 12576 info.GetIsolate()->ThrowException(Handle<Value>()); |
| 12433 info.GetReturnValue().SetUndefined(); | 12577 info.GetReturnValue().SetUndefined(); |
| 12434 } | 12578 } |
| 12435 | 12579 |
| 12436 | 12580 |
| 12437 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { | 12581 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { |
| 12438 LocalContext context; | 12582 LocalContext context; |
| 12439 HandleScope scope(context->GetIsolate()); | 12583 HandleScope scope(context->GetIsolate()); |
| 12440 | 12584 |
| 12441 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 12585 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 12442 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 12586 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
| 12443 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); | 12587 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); |
| 12444 | 12588 |
| 12445 Local<Object> instance = templ->GetFunction()->NewInstance(); | 12589 Local<Object> instance = templ->GetFunction()->NewInstance(); |
| 12446 | 12590 |
| 12447 Local<Object> another = Object::New(); | 12591 Local<Object> another = Object::New(); |
| 12448 another->SetPrototype(instance); | 12592 another->SetPrototype(instance); |
| 12449 | 12593 |
| 12450 Local<Object> with_js_getter = CompileRun( | 12594 Local<Object> with_js_getter = CompileRun( |
| 12451 "o = {};\n" | 12595 "o = {};\n" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12521 static void WebKitLike(Handle<Message> message, Handle<Value> data) { | 12665 static void WebKitLike(Handle<Message> message, Handle<Value> data) { |
| 12522 Handle<String> errorMessageString = message->Get(); | 12666 Handle<String> errorMessageString = message->Get(); |
| 12523 CHECK(!errorMessageString.IsEmpty()); | 12667 CHECK(!errorMessageString.IsEmpty()); |
| 12524 message->GetStackTrace(); | 12668 message->GetStackTrace(); |
| 12525 message->GetScriptResourceName(); | 12669 message->GetScriptResourceName(); |
| 12526 } | 12670 } |
| 12527 | 12671 |
| 12528 | 12672 |
| 12529 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { | 12673 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { |
| 12530 LocalContext context; | 12674 LocalContext context; |
| 12531 HandleScope scope(context->GetIsolate()); | 12675 v8::Isolate* isolate = context->GetIsolate(); |
| 12676 HandleScope scope(isolate); |
| 12532 | 12677 |
| 12533 Local<Function> func = | 12678 Local<Function> func = |
| 12534 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction(); | 12679 FunctionTemplate::New(isolate, |
| 12680 ThrowingCallbackWithTryCatch)->GetFunction(); |
| 12535 context->Global()->Set(v8_str("func"), func); | 12681 context->Global()->Set(v8_str("func"), func); |
| 12536 | 12682 |
| 12537 MessageCallback callbacks[] = | 12683 MessageCallback callbacks[] = |
| 12538 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; | 12684 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; |
| 12539 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { | 12685 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { |
| 12540 MessageCallback callback = callbacks[i]; | 12686 MessageCallback callback = callbacks[i]; |
| 12541 if (callback != NULL) { | 12687 if (callback != NULL) { |
| 12542 V8::AddMessageListener(callback); | 12688 V8::AddMessageListener(callback); |
| 12543 } | 12689 } |
| 12544 // Some small number to control number of times message handler should | 12690 // Some small number to control number of times message handler should |
| (...skipping 20 matching lines...) Expand all Loading... |
| 12565 static void ChildGetter(Local<String> name, | 12711 static void ChildGetter(Local<String> name, |
| 12566 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12712 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 12567 ApiTestFuzzer::Fuzz(); | 12713 ApiTestFuzzer::Fuzz(); |
| 12568 info.GetReturnValue().Set(v8_num(42)); | 12714 info.GetReturnValue().Set(v8_num(42)); |
| 12569 } | 12715 } |
| 12570 | 12716 |
| 12571 | 12717 |
| 12572 THREADED_TEST(Overriding) { | 12718 THREADED_TEST(Overriding) { |
| 12573 i::FLAG_es5_readonly = true; | 12719 i::FLAG_es5_readonly = true; |
| 12574 LocalContext context; | 12720 LocalContext context; |
| 12575 v8::HandleScope scope(context->GetIsolate()); | 12721 v8::Isolate* isolate = context->GetIsolate(); |
| 12722 v8::HandleScope scope(isolate); |
| 12576 | 12723 |
| 12577 // Parent template. | 12724 // Parent template. |
| 12578 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); | 12725 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(isolate); |
| 12579 Local<ObjectTemplate> parent_instance_templ = | 12726 Local<ObjectTemplate> parent_instance_templ = |
| 12580 parent_templ->InstanceTemplate(); | 12727 parent_templ->InstanceTemplate(); |
| 12581 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); | 12728 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); |
| 12582 | 12729 |
| 12583 // Template that inherits from the parent template. | 12730 // Template that inherits from the parent template. |
| 12584 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(); | 12731 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(isolate); |
| 12585 Local<ObjectTemplate> child_instance_templ = | 12732 Local<ObjectTemplate> child_instance_templ = |
| 12586 child_templ->InstanceTemplate(); | 12733 child_templ->InstanceTemplate(); |
| 12587 child_templ->Inherit(parent_templ); | 12734 child_templ->Inherit(parent_templ); |
| 12588 // Override 'f'. The child version of 'f' should get called for child | 12735 // Override 'f'. The child version of 'f' should get called for child |
| 12589 // instances. | 12736 // instances. |
| 12590 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); | 12737 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); |
| 12591 // Add 'g' twice. The 'g' added last should get called for instances. | 12738 // Add 'g' twice. The 'g' added last should get called for instances. |
| 12592 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); | 12739 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); |
| 12593 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); | 12740 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); |
| 12594 | 12741 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12628 | 12775 |
| 12629 | 12776 |
| 12630 static void IsConstructHandler( | 12777 static void IsConstructHandler( |
| 12631 const v8::FunctionCallbackInfo<v8::Value>& args) { | 12778 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 12632 ApiTestFuzzer::Fuzz(); | 12779 ApiTestFuzzer::Fuzz(); |
| 12633 args.GetReturnValue().Set(args.IsConstructCall()); | 12780 args.GetReturnValue().Set(args.IsConstructCall()); |
| 12634 } | 12781 } |
| 12635 | 12782 |
| 12636 | 12783 |
| 12637 THREADED_TEST(IsConstructCall) { | 12784 THREADED_TEST(IsConstructCall) { |
| 12638 v8::HandleScope scope(CcTest::isolate()); | 12785 v8::Isolate* isolate = CcTest::isolate(); |
| 12786 v8::HandleScope scope(isolate); |
| 12639 | 12787 |
| 12640 // Function template with call handler. | 12788 // Function template with call handler. |
| 12641 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 12789 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 12642 templ->SetCallHandler(IsConstructHandler); | 12790 templ->SetCallHandler(IsConstructHandler); |
| 12643 | 12791 |
| 12644 LocalContext context; | 12792 LocalContext context; |
| 12645 | 12793 |
| 12646 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 12794 context->Global()->Set(v8_str("f"), templ->GetFunction()); |
| 12647 Local<Value> value = v8_compile("f()")->Run(); | 12795 Local<Value> value = v8_compile("f()")->Run(); |
| 12648 CHECK(!value->BooleanValue()); | 12796 CHECK(!value->BooleanValue()); |
| 12649 value = v8_compile("new f()")->Run(); | 12797 value = v8_compile("new f()")->Run(); |
| 12650 CHECK(value->BooleanValue()); | 12798 CHECK(value->BooleanValue()); |
| 12651 } | 12799 } |
| 12652 | 12800 |
| 12653 | 12801 |
| 12654 THREADED_TEST(ObjectProtoToString) { | 12802 THREADED_TEST(ObjectProtoToString) { |
| 12655 v8::HandleScope scope(CcTest::isolate()); | 12803 v8::Isolate* isolate = CcTest::isolate(); |
| 12656 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 12804 v8::HandleScope scope(isolate); |
| 12805 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
| 12657 templ->SetClassName(v8_str("MyClass")); | 12806 templ->SetClassName(v8_str("MyClass")); |
| 12658 | 12807 |
| 12659 LocalContext context; | 12808 LocalContext context; |
| 12660 | 12809 |
| 12661 Local<String> customized_tostring = v8_str("customized toString"); | 12810 Local<String> customized_tostring = v8_str("customized toString"); |
| 12662 | 12811 |
| 12663 // Replace Object.prototype.toString | 12812 // Replace Object.prototype.toString |
| 12664 v8_compile("Object.prototype.toString = function() {" | 12813 v8_compile("Object.prototype.toString = function() {" |
| 12665 " return 'customized toString';" | 12814 " return 'customized toString';" |
| 12666 "}")->Run(); | 12815 "}")->Run(); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12907 v8::Handle<Value> value = CompileRun(code); | 13056 v8::Handle<Value> value = CompileRun(code); |
| 12908 CHECK(value.IsEmpty()); | 13057 CHECK(value.IsEmpty()); |
| 12909 args.GetReturnValue().Set(v8_str("foo")); | 13058 args.GetReturnValue().Set(v8_str("foo")); |
| 12910 } | 13059 } |
| 12911 } | 13060 } |
| 12912 | 13061 |
| 12913 | 13062 |
| 12914 // These are locking tests that don't need to be run again | 13063 // These are locking tests that don't need to be run again |
| 12915 // as part of the locking aggregation tests. | 13064 // as part of the locking aggregation tests. |
| 12916 TEST(NestedLockers) { | 13065 TEST(NestedLockers) { |
| 12917 v8::Locker locker(CcTest::isolate()); | 13066 v8::Isolate* isolate = CcTest::isolate(); |
| 12918 CHECK(v8::Locker::IsLocked(CcTest::isolate())); | 13067 v8::Locker locker(isolate); |
| 13068 CHECK(v8::Locker::IsLocked(isolate)); |
| 12919 LocalContext env; | 13069 LocalContext env; |
| 12920 v8::HandleScope scope(env->GetIsolate()); | 13070 v8::HandleScope scope(env->GetIsolate()); |
| 12921 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); | 13071 Local<v8::FunctionTemplate> fun_templ = |
| 13072 v8::FunctionTemplate::New(isolate, ThrowInJS); |
| 12922 Local<Function> fun = fun_templ->GetFunction(); | 13073 Local<Function> fun = fun_templ->GetFunction(); |
| 12923 env->Global()->Set(v8_str("throw_in_js"), fun); | 13074 env->Global()->Set(v8_str("throw_in_js"), fun); |
| 12924 Local<Script> script = v8_compile("(function () {" | 13075 Local<Script> script = v8_compile("(function () {" |
| 12925 " try {" | 13076 " try {" |
| 12926 " throw_in_js();" | 13077 " throw_in_js();" |
| 12927 " return 42;" | 13078 " return 42;" |
| 12928 " } catch (e) {" | 13079 " } catch (e) {" |
| 12929 " return e * 13;" | 13080 " return e * 13;" |
| 12930 " }" | 13081 " }" |
| 12931 "})();"); | 13082 "})();"); |
| 12932 CHECK_EQ(91, script->Run()->Int32Value()); | 13083 CHECK_EQ(91, script->Run()->Int32Value()); |
| 12933 } | 13084 } |
| 12934 | 13085 |
| 12935 | 13086 |
| 12936 // These are locking tests that don't need to be run again | 13087 // These are locking tests that don't need to be run again |
| 12937 // as part of the locking aggregation tests. | 13088 // as part of the locking aggregation tests. |
| 12938 TEST(NestedLockersNoTryCatch) { | 13089 TEST(NestedLockersNoTryCatch) { |
| 12939 v8::Locker locker(CcTest::isolate()); | 13090 v8::Locker locker(CcTest::isolate()); |
| 12940 LocalContext env; | 13091 LocalContext env; |
| 12941 v8::HandleScope scope(env->GetIsolate()); | 13092 v8::HandleScope scope(env->GetIsolate()); |
| 12942 Local<v8::FunctionTemplate> fun_templ = | 13093 Local<v8::FunctionTemplate> fun_templ = |
| 12943 v8::FunctionTemplate::New(ThrowInJSNoCatch); | 13094 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch); |
| 12944 Local<Function> fun = fun_templ->GetFunction(); | 13095 Local<Function> fun = fun_templ->GetFunction(); |
| 12945 env->Global()->Set(v8_str("throw_in_js"), fun); | 13096 env->Global()->Set(v8_str("throw_in_js"), fun); |
| 12946 Local<Script> script = v8_compile("(function () {" | 13097 Local<Script> script = v8_compile("(function () {" |
| 12947 " try {" | 13098 " try {" |
| 12948 " throw_in_js();" | 13099 " throw_in_js();" |
| 12949 " return 42;" | 13100 " return 42;" |
| 12950 " } catch (e) {" | 13101 " } catch (e) {" |
| 12951 " return e * 13;" | 13102 " return e * 13;" |
| 12952 " }" | 13103 " }" |
| 12953 "})();"); | 13104 "})();"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 12969 v8::Unlocker unlocker(CcTest::isolate()); | 13120 v8::Unlocker unlocker(CcTest::isolate()); |
| 12970 } | 13121 } |
| 12971 | 13122 |
| 12972 | 13123 |
| 12973 THREADED_TEST(LockUnlockLock) { | 13124 THREADED_TEST(LockUnlockLock) { |
| 12974 { | 13125 { |
| 12975 v8::Locker locker(CcTest::isolate()); | 13126 v8::Locker locker(CcTest::isolate()); |
| 12976 v8::HandleScope scope(CcTest::isolate()); | 13127 v8::HandleScope scope(CcTest::isolate()); |
| 12977 LocalContext env; | 13128 LocalContext env; |
| 12978 Local<v8::FunctionTemplate> fun_templ = | 13129 Local<v8::FunctionTemplate> fun_templ = |
| 12979 v8::FunctionTemplate::New(UnlockForAMoment); | 13130 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); |
| 12980 Local<Function> fun = fun_templ->GetFunction(); | 13131 Local<Function> fun = fun_templ->GetFunction(); |
| 12981 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 13132 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
| 12982 Local<Script> script = v8_compile("(function () {" | 13133 Local<Script> script = v8_compile("(function () {" |
| 12983 " unlock_for_a_moment();" | 13134 " unlock_for_a_moment();" |
| 12984 " return 42;" | 13135 " return 42;" |
| 12985 "})();"); | 13136 "})();"); |
| 12986 CHECK_EQ(42, script->Run()->Int32Value()); | 13137 CHECK_EQ(42, script->Run()->Int32Value()); |
| 12987 } | 13138 } |
| 12988 { | 13139 { |
| 12989 v8::Locker locker(CcTest::isolate()); | 13140 v8::Locker locker(CcTest::isolate()); |
| 12990 v8::HandleScope scope(CcTest::isolate()); | 13141 v8::HandleScope scope(CcTest::isolate()); |
| 12991 LocalContext env; | 13142 LocalContext env; |
| 12992 Local<v8::FunctionTemplate> fun_templ = | 13143 Local<v8::FunctionTemplate> fun_templ = |
| 12993 v8::FunctionTemplate::New(UnlockForAMoment); | 13144 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); |
| 12994 Local<Function> fun = fun_templ->GetFunction(); | 13145 Local<Function> fun = fun_templ->GetFunction(); |
| 12995 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 13146 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); |
| 12996 Local<Script> script = v8_compile("(function () {" | 13147 Local<Script> script = v8_compile("(function () {" |
| 12997 " unlock_for_a_moment();" | 13148 " unlock_for_a_moment();" |
| 12998 " return 42;" | 13149 " return 42;" |
| 12999 "})();"); | 13150 "})();"); |
| 13000 CHECK_EQ(42, script->Run()->Int32Value()); | 13151 CHECK_EQ(42, script->Run()->Int32Value()); |
| 13001 } | 13152 } |
| 13002 } | 13153 } |
| 13003 | 13154 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13490 return invocations; | 13641 return invocations; |
| 13491 } | 13642 } |
| 13492 | 13643 |
| 13493 | 13644 |
| 13494 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { | 13645 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { |
| 13495 v8::HandleScope outer(isolate); | 13646 v8::HandleScope outer(isolate); |
| 13496 v8::Local<Context> env = Context::New(isolate); | 13647 v8::Local<Context> env = Context::New(isolate); |
| 13497 env->Enter(); | 13648 env->Enter(); |
| 13498 | 13649 |
| 13499 Local<ObjectTemplate> t = ObjectTemplate::New(); | 13650 Local<ObjectTemplate> t = ObjectTemplate::New(); |
| 13500 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(RuntimeCallback)); | 13651 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); |
| 13501 env->Global()->Set(v8_str("obj"), t->NewInstance()); | 13652 env->Global()->Set(v8_str("obj"), t->NewInstance()); |
| 13502 | 13653 |
| 13503 const char* script = | 13654 const char* script = |
| 13504 "function bar() {\n" | 13655 "function bar() {\n" |
| 13505 " var sum = 0;\n" | 13656 " var sum = 0;\n" |
| 13506 " for (i = 0; i < 100; ++i)\n" | 13657 " for (i = 0; i < 100; ++i)\n" |
| 13507 " sum = foo(i);\n" | 13658 " sum = foo(i);\n" |
| 13508 " return sum;\n" | 13659 " return sum;\n" |
| 13509 "}\n" | 13660 "}\n" |
| 13510 "function foo(i) { return i * i; }\n" | 13661 "function foo(i) { return i * i; }\n" |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13978 | 14129 |
| 13979 static void FunctionNameCallback( | 14130 static void FunctionNameCallback( |
| 13980 const v8::FunctionCallbackInfo<v8::Value>& args) { | 14131 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 13981 ApiTestFuzzer::Fuzz(); | 14132 ApiTestFuzzer::Fuzz(); |
| 13982 args.GetReturnValue().Set(v8_num(42)); | 14133 args.GetReturnValue().Set(v8_num(42)); |
| 13983 } | 14134 } |
| 13984 | 14135 |
| 13985 | 14136 |
| 13986 THREADED_TEST(CallbackFunctionName) { | 14137 THREADED_TEST(CallbackFunctionName) { |
| 13987 LocalContext context; | 14138 LocalContext context; |
| 13988 v8::HandleScope scope(context->GetIsolate()); | 14139 v8::Isolate* isolate = context->GetIsolate(); |
| 14140 v8::HandleScope scope(isolate); |
| 13989 Local<ObjectTemplate> t = ObjectTemplate::New(); | 14141 Local<ObjectTemplate> t = ObjectTemplate::New(); |
| 13990 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback)); | 14142 t->Set(v8_str("asdf"), |
| 14143 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); |
| 13991 context->Global()->Set(v8_str("obj"), t->NewInstance()); | 14144 context->Global()->Set(v8_str("obj"), t->NewInstance()); |
| 13992 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); | 14145 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); |
| 13993 CHECK(value->IsString()); | 14146 CHECK(value->IsString()); |
| 13994 v8::String::Utf8Value name(value); | 14147 v8::String::Utf8Value name(value); |
| 13995 CHECK_EQ("asdf", *name); | 14148 CHECK_EQ("asdf", *name); |
| 13996 } | 14149 } |
| 13997 | 14150 |
| 13998 | 14151 |
| 13999 THREADED_TEST(DateAccess) { | 14152 THREADED_TEST(DateAccess) { |
| 14000 LocalContext context; | 14153 LocalContext context; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14241 CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14394 CHECK(f2->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14242 } | 14395 } |
| 14243 | 14396 |
| 14244 // Same for g1 and g2. | 14397 // Same for g1 and g2. |
| 14245 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); | 14398 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14246 for (int i = 0; i < 4; i++) { | 14399 for (int i = 0; i < 4; i++) { |
| 14247 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14400 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14248 } | 14401 } |
| 14249 | 14402 |
| 14250 // Detach the global and turn on access check. | 14403 // Detach the global and turn on access check. |
| 14404 Local<Object> hidden_global = Local<Object>::Cast( |
| 14405 context->Global()->GetPrototype()); |
| 14251 context->DetachGlobal(); | 14406 context->DetachGlobal(); |
| 14252 context->Global()->TurnOnAccessCheck(); | 14407 hidden_global->TurnOnAccessCheck(); |
| 14253 | 14408 |
| 14254 // Failing access check to property get results in undefined. | 14409 // Failing access check to property get results in undefined. |
| 14255 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14410 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
| 14256 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14411 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
| 14257 | 14412 |
| 14258 // Failing access check to function call results in exception. | 14413 // Failing access check to function call results in exception. |
| 14259 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14414 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
| 14260 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14415 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
| 14261 | 14416 |
| 14262 // No failing access check when just returning a constant. | 14417 // No failing access check when just returning a constant. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14326 } | 14481 } |
| 14327 | 14482 |
| 14328 // Same for g1 and g2. | 14483 // Same for g1 and g2. |
| 14329 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); | 14484 CHECK(g1->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14330 for (int i = 0; i < 4; i++) { | 14485 for (int i = 0; i < 4; i++) { |
| 14331 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); | 14486 CHECK(g2->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14332 } | 14487 } |
| 14333 | 14488 |
| 14334 // Detach the global and turn on access check now blocking access to property | 14489 // Detach the global and turn on access check now blocking access to property |
| 14335 // a and function h. | 14490 // a and function h. |
| 14491 Local<Object> hidden_global = Local<Object>::Cast( |
| 14492 context->Global()->GetPrototype()); |
| 14336 context->DetachGlobal(); | 14493 context->DetachGlobal(); |
| 14337 context->Global()->TurnOnAccessCheck(); | 14494 hidden_global->TurnOnAccessCheck(); |
| 14338 | 14495 |
| 14339 // Failing access check to property get results in undefined. | 14496 // Failing access check to property get results in undefined. |
| 14340 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14497 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
| 14341 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14498 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
| 14342 | 14499 |
| 14343 // Failing access check to function call results in exception. | 14500 // Failing access check to function call results in exception. |
| 14344 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14501 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
| 14345 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14502 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
| 14346 | 14503 |
| 14347 // No failing access check when just returning a constant. | 14504 // No failing access check when just returning a constant. |
| 14348 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1))); | 14505 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1))); |
| 14349 | 14506 |
| 14350 // Now compile the source again. And get the newly compiled functions, except | 14507 // Now compile the source again. And get the newly compiled functions, except |
| 14351 // for h for which access is blocked. | 14508 // for h for which access is blocked. |
| 14352 CompileRun(source); | 14509 CompileRun(source); |
| 14353 f1 = Local<Function>::Cast(context->Global()->Get(v8_str("f1"))); | 14510 f1 = Local<Function>::Cast(hidden_global->Get(v8_str("f1"))); |
| 14354 f2 = Local<Function>::Cast(context->Global()->Get(v8_str("f2"))); | 14511 f2 = Local<Function>::Cast(hidden_global->Get(v8_str("f2"))); |
| 14355 g1 = Local<Function>::Cast(context->Global()->Get(v8_str("g1"))); | 14512 g1 = Local<Function>::Cast(hidden_global->Get(v8_str("g1"))); |
| 14356 g2 = Local<Function>::Cast(context->Global()->Get(v8_str("g2"))); | 14513 g2 = Local<Function>::Cast(hidden_global->Get(v8_str("g2"))); |
| 14357 CHECK(context->Global()->Get(v8_str("h"))->IsUndefined()); | 14514 CHECK(hidden_global->Get(v8_str("h"))->IsUndefined()); |
| 14358 | 14515 |
| 14359 // Failing access check to property get results in undefined. | 14516 // Failing access check to property get results in undefined. |
| 14360 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); | 14517 CHECK(f1->Call(global, 0, NULL)->IsUndefined()); |
| 14361 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); | 14518 CHECK(f2->Call(global, 0, NULL)->IsUndefined()); |
| 14362 | 14519 |
| 14363 // Failing access check to function call results in exception. | 14520 // Failing access check to function call results in exception. |
| 14364 CHECK(g1->Call(global, 0, NULL).IsEmpty()); | 14521 CHECK(g1->Call(global, 0, NULL).IsEmpty()); |
| 14365 CHECK(g2->Call(global, 0, NULL).IsEmpty()); | 14522 CHECK(g2->Call(global, 0, NULL).IsEmpty()); |
| 14366 } | 14523 } |
| 14367 | 14524 |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15154 | 15311 |
| 15155 // Allow cross-domain access. | 15312 // Allow cross-domain access. |
| 15156 Local<String> token = v8_str("<security token>"); | 15313 Local<String> token = v8_str("<security token>"); |
| 15157 calling_context0->SetSecurityToken(token); | 15314 calling_context0->SetSecurityToken(token); |
| 15158 calling_context1->SetSecurityToken(token); | 15315 calling_context1->SetSecurityToken(token); |
| 15159 calling_context2->SetSecurityToken(token); | 15316 calling_context2->SetSecurityToken(token); |
| 15160 | 15317 |
| 15161 // Create an object with a C++ callback in context0. | 15318 // Create an object with a C++ callback in context0. |
| 15162 calling_context0->Enter(); | 15319 calling_context0->Enter(); |
| 15163 Local<v8::FunctionTemplate> callback_templ = | 15320 Local<v8::FunctionTemplate> callback_templ = |
| 15164 v8::FunctionTemplate::New(GetCallingContextCallback); | 15321 v8::FunctionTemplate::New(isolate, GetCallingContextCallback); |
| 15165 calling_context0->Global()->Set(v8_str("callback"), | 15322 calling_context0->Global()->Set(v8_str("callback"), |
| 15166 callback_templ->GetFunction()); | 15323 callback_templ->GetFunction()); |
| 15167 calling_context0->Exit(); | 15324 calling_context0->Exit(); |
| 15168 | 15325 |
| 15169 // Expose context0 in context1 and set up a function that calls the | 15326 // Expose context0 in context1 and set up a function that calls the |
| 15170 // callback function. | 15327 // callback function. |
| 15171 calling_context1->Enter(); | 15328 calling_context1->Enter(); |
| 15172 calling_context1->Global()->Set(v8_str("context0"), | 15329 calling_context1->Global()->Set(v8_str("context0"), |
| 15173 calling_context0->Global()); | 15330 calling_context0->Global()); |
| 15174 CompileRun("function f() { context0.callback() }"); | 15331 CompileRun("function f() { context0.callback() }"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 15201 } | 15358 } |
| 15202 | 15359 |
| 15203 | 15360 |
| 15204 // Regression test for issue 398. | 15361 // Regression test for issue 398. |
| 15205 // If a function is added to an object, creating a constant function | 15362 // If a function is added to an object, creating a constant function |
| 15206 // field, and the result is cloned, replacing the constant function on the | 15363 // field, and the result is cloned, replacing the constant function on the |
| 15207 // original should not affect the clone. | 15364 // original should not affect the clone. |
| 15208 // See http://code.google.com/p/v8/issues/detail?id=398 | 15365 // See http://code.google.com/p/v8/issues/detail?id=398 |
| 15209 THREADED_TEST(ReplaceConstantFunction) { | 15366 THREADED_TEST(ReplaceConstantFunction) { |
| 15210 LocalContext context; | 15367 LocalContext context; |
| 15211 v8::HandleScope scope(context->GetIsolate()); | 15368 v8::Isolate* isolate = context->GetIsolate(); |
| 15369 v8::HandleScope scope(isolate); |
| 15212 v8::Handle<v8::Object> obj = v8::Object::New(); | 15370 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 15213 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); | 15371 v8::Handle<v8::FunctionTemplate> func_templ = |
| 15372 v8::FunctionTemplate::New(isolate); |
| 15214 v8::Handle<v8::String> foo_string = | 15373 v8::Handle<v8::String> foo_string = |
| 15215 v8::String::NewFromUtf8(context->GetIsolate(), "foo"); | 15374 v8::String::NewFromUtf8(isolate, "foo"); |
| 15216 obj->Set(foo_string, func_templ->GetFunction()); | 15375 obj->Set(foo_string, func_templ->GetFunction()); |
| 15217 v8::Handle<v8::Object> obj_clone = obj->Clone(); | 15376 v8::Handle<v8::Object> obj_clone = obj->Clone(); |
| 15218 obj_clone->Set(foo_string, | 15377 obj_clone->Set(foo_string, |
| 15219 v8::String::NewFromUtf8(context->GetIsolate(), "Hello")); | 15378 v8::String::NewFromUtf8(isolate, "Hello")); |
| 15220 CHECK(!obj->Get(foo_string)->IsUndefined()); | 15379 CHECK(!obj->Get(foo_string)->IsUndefined()); |
| 15221 } | 15380 } |
| 15222 | 15381 |
| 15223 | 15382 |
| 15224 // Regression test for http://crbug.com/16276. | |
| 15225 THREADED_TEST(Regress16276) { | |
| 15226 LocalContext context; | |
| 15227 v8::HandleScope scope(context->GetIsolate()); | |
| 15228 // Force the IC in f to be a dictionary load IC. | |
| 15229 CompileRun("function f(obj) { return obj.x; }\n" | |
| 15230 "var obj = { x: { foo: 42 }, y: 87 };\n" | |
| 15231 "var x = obj.x;\n" | |
| 15232 "delete obj.y;\n" | |
| 15233 "for (var i = 0; i < 5; i++) f(obj);"); | |
| 15234 // Detach the global object to make 'this' refer directly to the | |
| 15235 // global object (not the proxy), and make sure that the dictionary | |
| 15236 // load IC doesn't mess up loading directly from the global object. | |
| 15237 context->DetachGlobal(); | |
| 15238 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); | |
| 15239 } | |
| 15240 | |
| 15241 static void CheckElementValue(i::Isolate* isolate, | 15383 static void CheckElementValue(i::Isolate* isolate, |
| 15242 int expected, | 15384 int expected, |
| 15243 i::Handle<i::Object> obj, | 15385 i::Handle<i::Object> obj, |
| 15244 int offset) { | 15386 int offset) { |
| 15245 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); | 15387 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); |
| 15246 CHECK_EQ(expected, i::Smi::cast(element)->value()); | 15388 CHECK_EQ(expected, i::Smi::cast(element)->value()); |
| 15247 } | 15389 } |
| 15248 | 15390 |
| 15249 | 15391 |
| 15250 THREADED_TEST(PixelArray) { | 15392 THREADED_TEST(PixelArray) { |
| (...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16628 | 16770 |
| 16629 CHECK(stackTrace->AsArray()->IsArray()); | 16771 CHECK(stackTrace->AsArray()->IsArray()); |
| 16630 } | 16772 } |
| 16631 } | 16773 } |
| 16632 | 16774 |
| 16633 | 16775 |
| 16634 // Tests the C++ StackTrace API. | 16776 // Tests the C++ StackTrace API. |
| 16635 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. | 16777 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. |
| 16636 // THREADED_TEST(CaptureStackTrace) { | 16778 // THREADED_TEST(CaptureStackTrace) { |
| 16637 TEST(CaptureStackTrace) { | 16779 TEST(CaptureStackTrace) { |
| 16638 v8::HandleScope scope(CcTest::isolate()); | 16780 v8::Isolate* isolate = CcTest::isolate(); |
| 16781 v8::HandleScope scope(isolate); |
| 16639 v8::Handle<v8::String> origin = | 16782 v8::Handle<v8::String> origin = |
| 16640 v8::String::NewFromUtf8(CcTest::isolate(), "capture-stack-trace-test"); | 16783 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); |
| 16641 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 16784 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 16642 templ->Set(v8_str("AnalyzeStackInNativeCode"), | 16785 templ->Set(v8_str("AnalyzeStackInNativeCode"), |
| 16643 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); | 16786 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); |
| 16644 LocalContext context(0, templ); | 16787 LocalContext context(0, templ); |
| 16645 | 16788 |
| 16646 // Test getting OVERVIEW information. Should ignore information that is not | 16789 // Test getting OVERVIEW information. Should ignore information that is not |
| 16647 // script name, function name, line number, and column offset. | 16790 // script name, function name, line number, and column offset. |
| 16648 const char *overview_source = | 16791 const char *overview_source = |
| 16649 "function bar() {\n" | 16792 "function bar() {\n" |
| 16650 " var y; AnalyzeStackInNativeCode(1);\n" | 16793 " var y; AnalyzeStackInNativeCode(1);\n" |
| 16651 "}\n" | 16794 "}\n" |
| 16652 "function foo() {\n" | 16795 "function foo() {\n" |
| 16653 "\n" | 16796 "\n" |
| 16654 " bar();\n" | 16797 " bar();\n" |
| 16655 "}\n" | 16798 "}\n" |
| 16656 "var x;eval('new foo();');"; | 16799 "var x;eval('new foo();');"; |
| 16657 v8::Handle<v8::String> overview_src = | 16800 v8::Handle<v8::String> overview_src = |
| 16658 v8::String::NewFromUtf8(CcTest::isolate(), overview_source); | 16801 v8::String::NewFromUtf8(isolate, overview_source); |
| 16659 v8::Handle<Value> overview_result( | 16802 v8::Handle<Value> overview_result( |
| 16660 v8::Script::New(overview_src, origin)->Run()); | 16803 v8::Script::New(overview_src, origin)->Run()); |
| 16661 CHECK(!overview_result.IsEmpty()); | 16804 CHECK(!overview_result.IsEmpty()); |
| 16662 CHECK(overview_result->IsObject()); | 16805 CHECK(overview_result->IsObject()); |
| 16663 | 16806 |
| 16664 // Test getting DETAILED information. | 16807 // Test getting DETAILED information. |
| 16665 const char *detailed_source = | 16808 const char *detailed_source = |
| 16666 "function bat() {AnalyzeStackInNativeCode(2);\n" | 16809 "function bat() {AnalyzeStackInNativeCode(2);\n" |
| 16667 "}\n" | 16810 "}\n" |
| 16668 "\n" | 16811 "\n" |
| 16669 "function baz() {\n" | 16812 "function baz() {\n" |
| 16670 " bat();\n" | 16813 " bat();\n" |
| 16671 "}\n" | 16814 "}\n" |
| 16672 "eval('new baz();');"; | 16815 "eval('new baz();');"; |
| 16673 v8::Handle<v8::String> detailed_src = | 16816 v8::Handle<v8::String> detailed_src = |
| 16674 v8::String::NewFromUtf8(CcTest::isolate(), detailed_source); | 16817 v8::String::NewFromUtf8(isolate, detailed_source); |
| 16675 // Make the script using a non-zero line and column offset. | 16818 // Make the script using a non-zero line and column offset. |
| 16676 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); | 16819 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); |
| 16677 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); | 16820 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); |
| 16678 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 16821 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
| 16679 v8::Handle<v8::Script> detailed_script( | 16822 v8::Handle<v8::Script> detailed_script( |
| 16680 v8::Script::New(detailed_src, &detailed_origin)); | 16823 v8::Script::New(detailed_src, &detailed_origin)); |
| 16681 v8::Handle<Value> detailed_result(detailed_script->Run()); | 16824 v8::Handle<Value> detailed_result(detailed_script->Run()); |
| 16682 CHECK(!detailed_result.IsEmpty()); | 16825 CHECK(!detailed_result.IsEmpty()); |
| 16683 CHECK(detailed_result->IsObject()); | 16826 CHECK(detailed_result->IsObject()); |
| 16684 } | 16827 } |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16880 for (int i = 0; i < 3; i++) { | 17023 for (int i = 0; i < 3; i++) { |
| 16881 v8::Handle<v8::String> name = | 17024 v8::Handle<v8::String> name = |
| 16882 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 17025 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
| 16883 CHECK(!name.IsEmpty()); | 17026 CHECK(!name.IsEmpty()); |
| 16884 CHECK_EQ(url, name); | 17027 CHECK_EQ(url, name); |
| 16885 } | 17028 } |
| 16886 } | 17029 } |
| 16887 | 17030 |
| 16888 | 17031 |
| 16889 TEST(SourceURLInStackTrace) { | 17032 TEST(SourceURLInStackTrace) { |
| 16890 v8::HandleScope scope(CcTest::isolate()); | 17033 v8::Isolate* isolate = CcTest::isolate(); |
| 17034 v8::HandleScope scope(isolate); |
| 16891 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17035 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 16892 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), | 17036 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), |
| 16893 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); | 17037 v8::FunctionTemplate::New(isolate, |
| 17038 AnalyzeStackOfEvalWithSourceURL)); |
| 16894 LocalContext context(0, templ); | 17039 LocalContext context(0, templ); |
| 16895 | 17040 |
| 16896 const char *source = | 17041 const char *source = |
| 16897 "function outer() {\n" | 17042 "function outer() {\n" |
| 16898 "function bar() {\n" | 17043 "function bar() {\n" |
| 16899 " AnalyzeStackOfEvalWithSourceURL();\n" | 17044 " AnalyzeStackOfEvalWithSourceURL();\n" |
| 16900 "}\n" | 17045 "}\n" |
| 16901 "function foo() {\n" | 17046 "function foo() {\n" |
| 16902 "\n" | 17047 "\n" |
| 16903 " bar();\n" | 17048 " bar();\n" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 16922 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 17067 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
| 16923 args.GetIsolate(), 10, v8::StackTrace::kScriptId); | 17068 args.GetIsolate(), 10, v8::StackTrace::kScriptId); |
| 16924 CHECK_EQ(2, stackTrace->GetFrameCount()); | 17069 CHECK_EQ(2, stackTrace->GetFrameCount()); |
| 16925 for (int i = 0; i < 2; i++) { | 17070 for (int i = 0; i < 2; i++) { |
| 16926 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); | 17071 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); |
| 16927 } | 17072 } |
| 16928 } | 17073 } |
| 16929 | 17074 |
| 16930 | 17075 |
| 16931 TEST(ScriptIdInStackTrace) { | 17076 TEST(ScriptIdInStackTrace) { |
| 16932 v8::HandleScope scope(CcTest::isolate()); | 17077 v8::Isolate* isolate = CcTest::isolate(); |
| 17078 v8::HandleScope scope(isolate); |
| 16933 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17079 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 16934 templ->Set(v8_str("AnalyzeScriptIdInStack"), | 17080 templ->Set(v8_str("AnalyzeScriptIdInStack"), |
| 16935 v8::FunctionTemplate::New(AnalyzeScriptIdInStack)); | 17081 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); |
| 16936 LocalContext context(0, templ); | 17082 LocalContext context(0, templ); |
| 16937 | 17083 |
| 16938 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 17084 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( |
| 16939 CcTest::isolate(), | 17085 isolate, |
| 16940 "function foo() {\n" | 17086 "function foo() {\n" |
| 16941 " AnalyzeScriptIdInStack();" | 17087 " AnalyzeScriptIdInStack();" |
| 16942 "}\n" | 17088 "}\n" |
| 16943 "foo();\n"); | 17089 "foo();\n"); |
| 16944 v8::ScriptOrigin origin = | 17090 v8::ScriptOrigin origin = |
| 16945 v8::ScriptOrigin(v8::String::NewFromUtf8(CcTest::isolate(), "test")); | 17091 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test")); |
| 16946 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); | 17092 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); |
| 16947 script->Run(); | 17093 script->Run(); |
| 16948 for (int i = 0; i < 2; i++) { | 17094 for (int i = 0; i < 2; i++) { |
| 16949 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); | 17095 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); |
| 16950 CHECK_EQ(scriptIdInStack[i], script->GetId()); | 17096 CHECK_EQ(scriptIdInStack[i], script->GetId()); |
| 16951 } | 17097 } |
| 16952 } | 17098 } |
| 16953 | 17099 |
| 16954 | 17100 |
| 16955 void AnalyzeStackOfInlineScriptWithSourceURL( | 17101 void AnalyzeStackOfInlineScriptWithSourceURL( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 16966 CHECK_EQ(url, name); | 17112 CHECK_EQ(url, name); |
| 16967 } | 17113 } |
| 16968 } | 17114 } |
| 16969 | 17115 |
| 16970 | 17116 |
| 16971 TEST(InlineScriptWithSourceURLInStackTrace) { | 17117 TEST(InlineScriptWithSourceURLInStackTrace) { |
| 16972 v8::HandleScope scope(CcTest::isolate()); | 17118 v8::HandleScope scope(CcTest::isolate()); |
| 16973 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17119 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 16974 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), | 17120 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), |
| 16975 v8::FunctionTemplate::New( | 17121 v8::FunctionTemplate::New( |
| 16976 AnalyzeStackOfInlineScriptWithSourceURL)); | 17122 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL)); |
| 16977 LocalContext context(0, templ); | 17123 LocalContext context(0, templ); |
| 16978 | 17124 |
| 16979 const char *source = | 17125 const char *source = |
| 16980 "function outer() {\n" | 17126 "function outer() {\n" |
| 16981 "function bar() {\n" | 17127 "function bar() {\n" |
| 16982 " AnalyzeStackOfInlineScriptWithSourceURL();\n" | 17128 " AnalyzeStackOfInlineScriptWithSourceURL();\n" |
| 16983 "}\n" | 17129 "}\n" |
| 16984 "function foo() {\n" | 17130 "function foo() {\n" |
| 16985 "\n" | 17131 "\n" |
| 16986 " bar();\n" | 17132 " bar();\n" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 17011 CHECK_EQ(url, name); | 17157 CHECK_EQ(url, name); |
| 17012 } | 17158 } |
| 17013 } | 17159 } |
| 17014 | 17160 |
| 17015 | 17161 |
| 17016 TEST(DynamicWithSourceURLInStackTrace) { | 17162 TEST(DynamicWithSourceURLInStackTrace) { |
| 17017 v8::HandleScope scope(CcTest::isolate()); | 17163 v8::HandleScope scope(CcTest::isolate()); |
| 17018 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17164 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 17019 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), | 17165 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), |
| 17020 v8::FunctionTemplate::New( | 17166 v8::FunctionTemplate::New( |
| 17021 AnalyzeStackOfDynamicScriptWithSourceURL)); | 17167 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL)); |
| 17022 LocalContext context(0, templ); | 17168 LocalContext context(0, templ); |
| 17023 | 17169 |
| 17024 const char *source = | 17170 const char *source = |
| 17025 "function outer() {\n" | 17171 "function outer() {\n" |
| 17026 "function bar() {\n" | 17172 "function bar() {\n" |
| 17027 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" | 17173 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" |
| 17028 "}\n" | 17174 "}\n" |
| 17029 "function foo() {\n" | 17175 "function foo() {\n" |
| 17030 "\n" | 17176 "\n" |
| 17031 " bar();\n" | 17177 " bar();\n" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17185 | 17331 |
| 17186 // Set stack limit. | 17332 // Set stack limit. |
| 17187 v8::ResourceConstraints constraints; | 17333 v8::ResourceConstraints constraints; |
| 17188 constraints.set_stack_limit(set_limit); | 17334 constraints.set_stack_limit(set_limit); |
| 17189 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); | 17335 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); |
| 17190 | 17336 |
| 17191 // Execute a script. | 17337 // Execute a script. |
| 17192 LocalContext env; | 17338 LocalContext env; |
| 17193 v8::HandleScope scope(env->GetIsolate()); | 17339 v8::HandleScope scope(env->GetIsolate()); |
| 17194 Local<v8::FunctionTemplate> fun_templ = | 17340 Local<v8::FunctionTemplate> fun_templ = |
| 17195 v8::FunctionTemplate::New(GetStackLimitCallback); | 17341 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback); |
| 17196 Local<Function> fun = fun_templ->GetFunction(); | 17342 Local<Function> fun = fun_templ->GetFunction(); |
| 17197 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17343 env->Global()->Set(v8_str("get_stack_limit"), fun); |
| 17198 CompileRun("get_stack_limit();"); | 17344 CompileRun("get_stack_limit();"); |
| 17199 | 17345 |
| 17200 CHECK(stack_limit == set_limit); | 17346 CHECK(stack_limit == set_limit); |
| 17201 } | 17347 } |
| 17202 | 17348 |
| 17203 | 17349 |
| 17204 TEST(SetResourceConstraintsInThread) { | 17350 TEST(SetResourceConstraintsInThread) { |
| 17205 uint32_t* set_limit; | 17351 uint32_t* set_limit; |
| 17206 { | 17352 { |
| 17207 v8::Locker locker(CcTest::isolate()); | 17353 v8::Locker locker(CcTest::isolate()); |
| 17208 set_limit = ComputeStackLimit(stack_breathing_room); | 17354 set_limit = ComputeStackLimit(stack_breathing_room); |
| 17209 | 17355 |
| 17210 // Set stack limit. | 17356 // Set stack limit. |
| 17211 v8::ResourceConstraints constraints; | 17357 v8::ResourceConstraints constraints; |
| 17212 constraints.set_stack_limit(set_limit); | 17358 constraints.set_stack_limit(set_limit); |
| 17213 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); | 17359 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); |
| 17214 | 17360 |
| 17215 // Execute a script. | 17361 // Execute a script. |
| 17216 v8::HandleScope scope(CcTest::isolate()); | 17362 v8::HandleScope scope(CcTest::isolate()); |
| 17217 LocalContext env; | 17363 LocalContext env; |
| 17218 Local<v8::FunctionTemplate> fun_templ = | 17364 Local<v8::FunctionTemplate> fun_templ = |
| 17219 v8::FunctionTemplate::New(GetStackLimitCallback); | 17365 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback); |
| 17220 Local<Function> fun = fun_templ->GetFunction(); | 17366 Local<Function> fun = fun_templ->GetFunction(); |
| 17221 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17367 env->Global()->Set(v8_str("get_stack_limit"), fun); |
| 17222 CompileRun("get_stack_limit();"); | 17368 CompileRun("get_stack_limit();"); |
| 17223 | 17369 |
| 17224 CHECK(stack_limit == set_limit); | 17370 CHECK(stack_limit == set_limit); |
| 17225 } | 17371 } |
| 17226 { | 17372 { |
| 17227 v8::Locker locker(CcTest::isolate()); | 17373 v8::Locker locker(CcTest::isolate()); |
| 17228 CHECK(stack_limit == set_limit); | 17374 CHECK(stack_limit == set_limit); |
| 17229 } | 17375 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17332 CHECK_EQ(0, destroyed); | 17478 CHECK_EQ(0, destroyed); |
| 17333 USE(ring); | 17479 USE(ring); |
| 17334 } | 17480 } |
| 17335 | 17481 |
| 17336 isolate->Dispose(); | 17482 isolate->Dispose(); |
| 17337 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. | 17483 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 17338 CHECK_EQ(1, destroyed); | 17484 CHECK_EQ(1, destroyed); |
| 17339 } | 17485 } |
| 17340 | 17486 |
| 17341 | 17487 |
| 17488 TEST(ExternalInternalizedStringCollectedAtTearDown) { |
| 17489 int destroyed = 0; |
| 17490 v8::Isolate* isolate = v8::Isolate::New(); |
| 17491 { v8::Isolate::Scope isolate_scope(isolate); |
| 17492 LocalContext env(isolate); |
| 17493 v8::HandleScope handle_scope(isolate); |
| 17494 CompileRun("var ring = 'One string to test them all';"); |
| 17495 const char* s = "One string to test them all"; |
| 17496 TestAsciiResource* inscription = |
| 17497 new TestAsciiResource(i::StrDup(s), &destroyed); |
| 17498 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); |
| 17499 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
| 17500 ring->MakeExternal(inscription); |
| 17501 // Ring is still alive. Orcs are roaming freely across our lands. |
| 17502 CHECK_EQ(0, destroyed); |
| 17503 USE(ring); |
| 17504 } |
| 17505 |
| 17506 isolate->Dispose(); |
| 17507 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 17508 CHECK_EQ(1, destroyed); |
| 17509 } |
| 17510 |
| 17511 |
| 17512 TEST(ExternalInternalizedStringCollectedAtGC) { |
| 17513 int destroyed = 0; |
| 17514 { LocalContext env; |
| 17515 v8::HandleScope handle_scope(env->GetIsolate()); |
| 17516 CompileRun("var ring = 'One string to test them all';"); |
| 17517 const char* s = "One string to test them all"; |
| 17518 TestAsciiResource* inscription = |
| 17519 new TestAsciiResource(i::StrDup(s), &destroyed); |
| 17520 v8::Local<v8::String> ring = CompileRun("ring")->ToString(); |
| 17521 CHECK(v8::Utils::OpenHandle(*ring)->IsInternalizedString()); |
| 17522 ring->MakeExternal(inscription); |
| 17523 // Ring is still alive. Orcs are roaming freely across our lands. |
| 17524 CHECK_EQ(0, destroyed); |
| 17525 USE(ring); |
| 17526 } |
| 17527 |
| 17528 // Garbage collector deals swift blows to evil. |
| 17529 CcTest::i_isolate()->compilation_cache()->Clear(); |
| 17530 CcTest::heap()->CollectAllAvailableGarbage(); |
| 17531 |
| 17532 // Ring has been destroyed. Free Peoples of Middle-earth Rejoice. |
| 17533 CHECK_EQ(1, destroyed); |
| 17534 } |
| 17535 |
| 17536 |
| 17342 static double DoubleFromBits(uint64_t value) { | 17537 static double DoubleFromBits(uint64_t value) { |
| 17343 double target; | 17538 double target; |
| 17344 i::OS::MemCopy(&target, &value, sizeof(target)); | 17539 i::OS::MemCopy(&target, &value, sizeof(target)); |
| 17345 return target; | 17540 return target; |
| 17346 } | 17541 } |
| 17347 | 17542 |
| 17348 | 17543 |
| 17349 static uint64_t DoubleToBits(double value) { | 17544 static uint64_t DoubleToBits(double value) { |
| 17350 uint64_t target; | 17545 uint64_t target; |
| 17351 i::OS::MemCopy(&target, &value, sizeof(target)); | 17546 i::OS::MemCopy(&target, &value, sizeof(target)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17461 v8::Handle<v8::String> str(args[0]->ToString()); | 17656 v8::Handle<v8::String> str(args[0]->ToString()); |
| 17462 USE(str); | 17657 USE(str); |
| 17463 if (tc.HasCaught()) | 17658 if (tc.HasCaught()) |
| 17464 tc.ReThrow(); | 17659 tc.ReThrow(); |
| 17465 } | 17660 } |
| 17466 | 17661 |
| 17467 | 17662 |
| 17468 // Test that an exception can be propagated down through a spaghetti | 17663 // Test that an exception can be propagated down through a spaghetti |
| 17469 // stack using ReThrow. | 17664 // stack using ReThrow. |
| 17470 THREADED_TEST(SpaghettiStackReThrow) { | 17665 THREADED_TEST(SpaghettiStackReThrow) { |
| 17471 v8::HandleScope scope(CcTest::isolate()); | 17666 v8::Isolate* isolate = CcTest::isolate(); |
| 17667 v8::HandleScope scope(isolate); |
| 17472 LocalContext context; | 17668 LocalContext context; |
| 17473 context->Global()->Set( | 17669 context->Global()->Set( |
| 17474 v8::String::NewFromUtf8(CcTest::isolate(), "s"), | 17670 v8::String::NewFromUtf8(isolate, "s"), |
| 17475 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); | 17671 v8::FunctionTemplate::New(isolate, SpaghettiIncident)->GetFunction()); |
| 17476 v8::TryCatch try_catch; | 17672 v8::TryCatch try_catch; |
| 17477 CompileRun( | 17673 CompileRun( |
| 17478 "var i = 0;" | 17674 "var i = 0;" |
| 17479 "var o = {" | 17675 "var o = {" |
| 17480 " toString: function () {" | 17676 " toString: function () {" |
| 17481 " if (i == 10) {" | 17677 " if (i == 10) {" |
| 17482 " throw 'Hey!';" | 17678 " throw 'Hey!';" |
| 17483 " } else {" | 17679 " } else {" |
| 17484 " i++;" | 17680 " i++;" |
| 17485 " return s(o);" | 17681 " return s(o);" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17750 script->Run(); | 17946 script->Run(); |
| 17751 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 17947 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
| 17752 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); | 17948 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "foo"))); |
| 17753 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 17949 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
| 17754 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); | 17950 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "bar"))); |
| 17755 CHECK_EQ(script->GetId(), foo->ScriptId()); | 17951 CHECK_EQ(script->GetId(), foo->ScriptId()); |
| 17756 CHECK_EQ(script->GetId(), bar->ScriptId()); | 17952 CHECK_EQ(script->GetId(), bar->ScriptId()); |
| 17757 } | 17953 } |
| 17758 | 17954 |
| 17759 | 17955 |
| 17956 THREADED_TEST(FunctionGetBoundFunction) { |
| 17957 LocalContext env; |
| 17958 v8::HandleScope scope(env->GetIsolate()); |
| 17959 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8( |
| 17960 env->GetIsolate(), "test")); |
| 17961 v8::Handle<v8::String> script = v8::String::NewFromUtf8( |
| 17962 env->GetIsolate(), |
| 17963 "var a = new Object();\n" |
| 17964 "a.x = 1;\n" |
| 17965 "function f () { return this.x };\n" |
| 17966 "var g = f.bind(a);\n" |
| 17967 "var b = g();"); |
| 17968 v8::Script::Compile(script, &origin)->Run(); |
| 17969 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 17970 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); |
| 17971 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( |
| 17972 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); |
| 17973 CHECK(g->GetBoundFunction()->IsFunction()); |
| 17974 Local<v8::Function> original_function = Local<v8::Function>::Cast( |
| 17975 g->GetBoundFunction()); |
| 17976 CHECK_EQ(f->GetName(), original_function->GetName()); |
| 17977 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); |
| 17978 CHECK_EQ(f->GetScriptColumnNumber(), |
| 17979 original_function->GetScriptColumnNumber()); |
| 17980 } |
| 17981 |
| 17982 |
| 17760 static void GetterWhichReturns42( | 17983 static void GetterWhichReturns42( |
| 17761 Local<String> name, | 17984 Local<String> name, |
| 17762 const v8::PropertyCallbackInfo<v8::Value>& info) { | 17985 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 17763 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 17986 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
| 17764 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 17987 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
| 17765 info.GetReturnValue().Set(v8_num(42)); | 17988 info.GetReturnValue().Set(v8_num(42)); |
| 17766 } | 17989 } |
| 17767 | 17990 |
| 17768 | 17991 |
| 17769 static void SetterWhichSetsYOnThisTo23( | 17992 static void SetterWhichSetsYOnThisTo23( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18081 " var r1_ = %_GetFromCache(0, key1);" | 18304 " var r1_ = %_GetFromCache(0, key1);" |
| 18082 " if (r1 !== r1_)" | 18305 " if (r1 !== r1_)" |
| 18083 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" | 18306 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" |
| 18084 " return 'PASSED';" | 18307 " return 'PASSED';" |
| 18085 "})()"; | 18308 "})()"; |
| 18086 CcTest::heap()->ClearJSFunctionResultCaches(); | 18309 CcTest::heap()->ClearJSFunctionResultCaches(); |
| 18087 ExpectString(code, "PASSED"); | 18310 ExpectString(code, "PASSED"); |
| 18088 } | 18311 } |
| 18089 | 18312 |
| 18090 | 18313 |
| 18091 static const int k0CacheSize = 16; | |
| 18092 | |
| 18093 THREADED_TEST(FillJSFunctionResultCache) { | 18314 THREADED_TEST(FillJSFunctionResultCache) { |
| 18094 i::FLAG_allow_natives_syntax = true; | 18315 i::FLAG_allow_natives_syntax = true; |
| 18095 LocalContext context; | 18316 LocalContext context; |
| 18096 v8::HandleScope scope(context->GetIsolate()); | 18317 v8::HandleScope scope(context->GetIsolate()); |
| 18097 | 18318 |
| 18098 const char* code = | 18319 const char* code = |
| 18099 "(function() {" | 18320 "(function() {" |
| 18100 " var k = 'a';" | 18321 " var k = 'a';" |
| 18101 " var r = %_GetFromCache(0, k);" | 18322 " var r = %_GetFromCache(0, k);" |
| 18102 " for (var i = 0; i < 16; i++) {" | 18323 " for (var i = 0; i < 16; i++) {" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18269 TEST(ContainsOnlyOneByte) { | 18490 TEST(ContainsOnlyOneByte) { |
| 18270 v8::V8::Initialize(); | 18491 v8::V8::Initialize(); |
| 18271 v8::Isolate* isolate = CcTest::isolate(); | 18492 v8::Isolate* isolate = CcTest::isolate(); |
| 18272 v8::HandleScope scope(isolate); | 18493 v8::HandleScope scope(isolate); |
| 18273 // Make a buffer long enough that it won't automatically be converted. | 18494 // Make a buffer long enough that it won't automatically be converted. |
| 18274 const int length = 512; | 18495 const int length = 512; |
| 18275 // Ensure word aligned assignment. | 18496 // Ensure word aligned assignment. |
| 18276 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); | 18497 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); |
| 18277 i::SmartArrayPointer<uintptr_t> | 18498 i::SmartArrayPointer<uintptr_t> |
| 18278 aligned_contents(new uintptr_t[aligned_length]); | 18499 aligned_contents(new uintptr_t[aligned_length]); |
| 18279 uint16_t* string_contents = reinterpret_cast<uint16_t*>(*aligned_contents); | 18500 uint16_t* string_contents = |
| 18501 reinterpret_cast<uint16_t*>(aligned_contents.get()); |
| 18280 // Set to contain only one byte. | 18502 // Set to contain only one byte. |
| 18281 for (int i = 0; i < length-1; i++) { | 18503 for (int i = 0; i < length-1; i++) { |
| 18282 string_contents[i] = 0x41; | 18504 string_contents[i] = 0x41; |
| 18283 } | 18505 } |
| 18284 string_contents[length-1] = 0; | 18506 string_contents[length-1] = 0; |
| 18285 // Simple case. | 18507 // Simple case. |
| 18286 Handle<String> string; | 18508 Handle<String> string; |
| 18287 string = String::NewExternal(isolate, new TestResource(string_contents)); | 18509 string = String::NewExternal(isolate, new TestResource(string_contents)); |
| 18288 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18510 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
| 18289 // Counter example. | 18511 // Counter example. |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19147 Set(v8_str("context_id"), v8::Integer::New(id)); | 19369 Set(v8_str("context_id"), v8::Integer::New(id)); |
| 19148 } | 19370 } |
| 19149 | 19371 |
| 19150 | 19372 |
| 19151 static void CheckContextId(v8::Handle<Object> object, int expected) { | 19373 static void CheckContextId(v8::Handle<Object> object, int expected) { |
| 19152 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); | 19374 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); |
| 19153 } | 19375 } |
| 19154 | 19376 |
| 19155 | 19377 |
| 19156 THREADED_TEST(CreationContext) { | 19378 THREADED_TEST(CreationContext) { |
| 19157 HandleScope handle_scope(CcTest::isolate()); | 19379 v8::Isolate* isolate = CcTest::isolate(); |
| 19158 Handle<Context> context1 = Context::New(CcTest::isolate()); | 19380 HandleScope handle_scope(isolate); |
| 19381 Handle<Context> context1 = Context::New(isolate); |
| 19159 InstallContextId(context1, 1); | 19382 InstallContextId(context1, 1); |
| 19160 Handle<Context> context2 = Context::New(CcTest::isolate()); | 19383 Handle<Context> context2 = Context::New(isolate); |
| 19161 InstallContextId(context2, 2); | 19384 InstallContextId(context2, 2); |
| 19162 Handle<Context> context3 = Context::New(CcTest::isolate()); | 19385 Handle<Context> context3 = Context::New(isolate); |
| 19163 InstallContextId(context3, 3); | 19386 InstallContextId(context3, 3); |
| 19164 | 19387 |
| 19165 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); | 19388 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); |
| 19166 | 19389 |
| 19167 Local<Object> object1; | 19390 Local<Object> object1; |
| 19168 Local<Function> func1; | 19391 Local<Function> func1; |
| 19169 { | 19392 { |
| 19170 Context::Scope scope(context1); | 19393 Context::Scope scope(context1); |
| 19171 object1 = Object::New(); | 19394 object1 = Object::New(); |
| 19172 func1 = tmpl->GetFunction(); | 19395 func1 = tmpl->GetFunction(); |
| 19173 } | 19396 } |
| 19174 | 19397 |
| 19175 Local<Object> object2; | 19398 Local<Object> object2; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19475 CHECK(expected_message->Equals(actual_message)); | 19698 CHECK(expected_message->Equals(actual_message)); |
| 19476 } | 19699 } |
| 19477 | 19700 |
| 19478 | 19701 |
| 19479 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { | 19702 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 19480 } | 19703 } |
| 19481 | 19704 |
| 19482 | 19705 |
| 19483 THREADED_TEST(CallAPIFunctionOnNonObject) { | 19706 THREADED_TEST(CallAPIFunctionOnNonObject) { |
| 19484 LocalContext context; | 19707 LocalContext context; |
| 19485 v8::HandleScope scope(context->GetIsolate()); | 19708 v8::Isolate* isolate = context->GetIsolate(); |
| 19486 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 19709 v8::HandleScope scope(isolate); |
| 19710 Handle<FunctionTemplate> templ = |
| 19711 v8::FunctionTemplate::New(isolate, NonObjectThis); |
| 19487 Handle<Function> function = templ->GetFunction(); | 19712 Handle<Function> function = templ->GetFunction(); |
| 19488 context->Global()->Set(v8_str("f"), function); | 19713 context->Global()->Set(v8_str("f"), function); |
| 19489 TryCatch try_catch; | 19714 TryCatch try_catch; |
| 19490 CompileRun("f.call(2)"); | 19715 CompileRun("f.call(2)"); |
| 19491 } | 19716 } |
| 19492 | 19717 |
| 19493 | 19718 |
| 19494 // Regression test for issue 1470. | 19719 // Regression test for issue 1470. |
| 19495 THREADED_TEST(ReadOnlyIndexedProperties) { | 19720 THREADED_TEST(ReadOnlyIndexedProperties) { |
| 19496 v8::HandleScope scope(CcTest::isolate()); | 19721 v8::HandleScope scope(CcTest::isolate()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19562 HandleScope scope(isolate); | 19787 HandleScope scope(isolate); |
| 19563 | 19788 |
| 19564 // Template for object with security check. | 19789 // Template for object with security check. |
| 19565 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); | 19790 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); |
| 19566 // We don't do indexing, so any callback can be used for that. | 19791 // We don't do indexing, so any callback can be used for that. |
| 19567 no_proto_template->SetAccessCheckCallbacks( | 19792 no_proto_template->SetAccessCheckCallbacks( |
| 19568 BlockProtoNamedSecurityTestCallback, | 19793 BlockProtoNamedSecurityTestCallback, |
| 19569 IndexedSecurityTestCallback); | 19794 IndexedSecurityTestCallback); |
| 19570 | 19795 |
| 19571 // Templates for objects with hidden prototypes and possibly security check. | 19796 // Templates for objects with hidden prototypes and possibly security check. |
| 19572 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); | 19797 Local<FunctionTemplate> hidden_proto_template = |
| 19798 v8::FunctionTemplate::New(isolate); |
| 19573 hidden_proto_template->SetHiddenPrototype(true); | 19799 hidden_proto_template->SetHiddenPrototype(true); |
| 19574 | 19800 |
| 19575 Local<FunctionTemplate> protected_hidden_proto_template = | 19801 Local<FunctionTemplate> protected_hidden_proto_template = |
| 19576 v8::FunctionTemplate::New(); | 19802 v8::FunctionTemplate::New(isolate); |
| 19577 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( | 19803 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( |
| 19578 BlockProtoNamedSecurityTestCallback, | 19804 BlockProtoNamedSecurityTestCallback, |
| 19579 IndexedSecurityTestCallback); | 19805 IndexedSecurityTestCallback); |
| 19580 protected_hidden_proto_template->SetHiddenPrototype(true); | 19806 protected_hidden_proto_template->SetHiddenPrototype(true); |
| 19581 | 19807 |
| 19582 // Context for "foreign" objects used in test. | 19808 // Context for "foreign" objects used in test. |
| 19583 Local<Context> context = v8::Context::New(isolate); | 19809 Local<Context> context = v8::Context::New(isolate); |
| 19584 context->Enter(); | 19810 context->Enter(); |
| 19585 | 19811 |
| 19586 // Plain object, no security check. | 19812 // Plain object, no security check. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19642 CHECK(result5->Equals( | 19868 CHECK(result5->Equals( |
| 19643 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); | 19869 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); |
| 19644 | 19870 |
| 19645 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); | 19871 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); |
| 19646 CHECK(result6->Equals(Undefined(isolate))); | 19872 CHECK(result6->Equals(Undefined(isolate))); |
| 19647 } | 19873 } |
| 19648 | 19874 |
| 19649 | 19875 |
| 19650 THREADED_TEST(Regress125988) { | 19876 THREADED_TEST(Regress125988) { |
| 19651 v8::HandleScope scope(CcTest::isolate()); | 19877 v8::HandleScope scope(CcTest::isolate()); |
| 19652 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); | 19878 Handle<FunctionTemplate> intercept = FunctionTemplate::New(CcTest::isolate()); |
| 19653 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); | 19879 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 19654 LocalContext env; | 19880 LocalContext env; |
| 19655 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); | 19881 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); |
| 19656 CompileRun("var a = new Object();" | 19882 CompileRun("var a = new Object();" |
| 19657 "var b = new Intercept();" | 19883 "var b = new Intercept();" |
| 19658 "var c = new Object();" | 19884 "var c = new Object();" |
| 19659 "c.__proto__ = b;" | 19885 "c.__proto__ = b;" |
| 19660 "b.__proto__ = a;" | 19886 "b.__proto__ = a;" |
| 19661 "a.x = 23;" | 19887 "a.x = 23;" |
| 19662 "for (var i = 0; i < 3; i++) c.x;"); | 19888 "for (var i = 0; i < 3; i++) c.x;"); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19804 i::OS::Print("Recursion ends.\n"); | 20030 i::OS::Print("Recursion ends.\n"); |
| 19805 CHECK_EQ(0, callback_fired); | 20031 CHECK_EQ(0, callback_fired); |
| 19806 } | 20032 } |
| 19807 } | 20033 } |
| 19808 | 20034 |
| 19809 | 20035 |
| 19810 TEST(CallCompletedCallback) { | 20036 TEST(CallCompletedCallback) { |
| 19811 LocalContext env; | 20037 LocalContext env; |
| 19812 v8::HandleScope scope(env->GetIsolate()); | 20038 v8::HandleScope scope(env->GetIsolate()); |
| 19813 v8::Handle<v8::FunctionTemplate> recursive_runtime = | 20039 v8::Handle<v8::FunctionTemplate> recursive_runtime = |
| 19814 v8::FunctionTemplate::New(RecursiveCall); | 20040 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); |
| 19815 env->Global()->Set(v8_str("recursion"), | 20041 env->Global()->Set(v8_str("recursion"), |
| 19816 recursive_runtime->GetFunction()); | 20042 recursive_runtime->GetFunction()); |
| 19817 // Adding the same callback a second time has no effect. | 20043 // Adding the same callback a second time has no effect. |
| 19818 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 20044 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); |
| 19819 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); | 20045 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); |
| 19820 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); | 20046 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); |
| 19821 i::OS::Print("--- Script (1) ---\n"); | 20047 i::OS::Print("--- Script (1) ---\n"); |
| 19822 Local<Script> script = v8::Script::Compile( | 20048 Local<Script> script = v8::Script::Compile( |
| 19823 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); | 20049 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); |
| 19824 script->Run(); | 20050 script->Run(); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20101 "%DeoptimizeFunction(test_set);" | 20327 "%DeoptimizeFunction(test_set);" |
| 20102 "%ClearFunctionTypeFeedback(test_set);"); | 20328 "%ClearFunctionTypeFeedback(test_set);"); |
| 20103 } | 20329 } |
| 20104 | 20330 |
| 20105 | 20331 |
| 20106 THREADED_TEST(InstanceCheckOnInstanceAccessor) { | 20332 THREADED_TEST(InstanceCheckOnInstanceAccessor) { |
| 20107 v8::internal::FLAG_allow_natives_syntax = true; | 20333 v8::internal::FLAG_allow_natives_syntax = true; |
| 20108 LocalContext context; | 20334 LocalContext context; |
| 20109 v8::HandleScope scope(context->GetIsolate()); | 20335 v8::HandleScope scope(context->GetIsolate()); |
| 20110 | 20336 |
| 20111 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 20337 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 20112 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | 20338 Local<ObjectTemplate> inst = templ->InstanceTemplate(); |
| 20113 inst->SetAccessor(v8_str("foo"), | 20339 inst->SetAccessor(v8_str("foo"), |
| 20114 InstanceCheckedGetter, InstanceCheckedSetter, | 20340 InstanceCheckedGetter, InstanceCheckedSetter, |
| 20115 Handle<Value>(), | 20341 Handle<Value>(), |
| 20116 v8::DEFAULT, | 20342 v8::DEFAULT, |
| 20117 v8::None, | 20343 v8::None, |
| 20118 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20344 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
| 20119 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20345 context->Global()->Set(v8_str("f"), templ->GetFunction()); |
| 20120 | 20346 |
| 20121 printf("Testing positive ...\n"); | 20347 printf("Testing positive ...\n"); |
| 20122 CompileRun("var obj = new f();"); | 20348 CompileRun("var obj = new f();"); |
| 20123 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20349 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 20124 CheckInstanceCheckedAccessors(true); | 20350 CheckInstanceCheckedAccessors(true); |
| 20125 | 20351 |
| 20126 printf("Testing negative ...\n"); | 20352 printf("Testing negative ...\n"); |
| 20127 CompileRun("var obj = {};" | 20353 CompileRun("var obj = {};" |
| 20128 "obj.__proto__ = new f();"); | 20354 "obj.__proto__ = new f();"); |
| 20129 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20355 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 20130 CheckInstanceCheckedAccessors(false); | 20356 CheckInstanceCheckedAccessors(false); |
| 20131 } | 20357 } |
| 20132 | 20358 |
| 20133 | 20359 |
| 20134 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { | 20360 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { |
| 20135 v8::internal::FLAG_allow_natives_syntax = true; | 20361 v8::internal::FLAG_allow_natives_syntax = true; |
| 20136 LocalContext context; | 20362 LocalContext context; |
| 20137 v8::HandleScope scope(context->GetIsolate()); | 20363 v8::HandleScope scope(context->GetIsolate()); |
| 20138 | 20364 |
| 20139 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 20365 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 20140 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | 20366 Local<ObjectTemplate> inst = templ->InstanceTemplate(); |
| 20141 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); | 20367 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 20142 inst->SetAccessor(v8_str("foo"), | 20368 inst->SetAccessor(v8_str("foo"), |
| 20143 InstanceCheckedGetter, InstanceCheckedSetter, | 20369 InstanceCheckedGetter, InstanceCheckedSetter, |
| 20144 Handle<Value>(), | 20370 Handle<Value>(), |
| 20145 v8::DEFAULT, | 20371 v8::DEFAULT, |
| 20146 v8::None, | 20372 v8::None, |
| 20147 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20373 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
| 20148 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20374 context->Global()->Set(v8_str("f"), templ->GetFunction()); |
| 20149 | 20375 |
| 20150 printf("Testing positive ...\n"); | 20376 printf("Testing positive ...\n"); |
| 20151 CompileRun("var obj = new f();"); | 20377 CompileRun("var obj = new f();"); |
| 20152 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20378 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 20153 CheckInstanceCheckedAccessors(true); | 20379 CheckInstanceCheckedAccessors(true); |
| 20154 | 20380 |
| 20155 printf("Testing negative ...\n"); | 20381 printf("Testing negative ...\n"); |
| 20156 CompileRun("var obj = {};" | 20382 CompileRun("var obj = {};" |
| 20157 "obj.__proto__ = new f();"); | 20383 "obj.__proto__ = new f();"); |
| 20158 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20384 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
| 20159 CheckInstanceCheckedAccessors(false); | 20385 CheckInstanceCheckedAccessors(false); |
| 20160 } | 20386 } |
| 20161 | 20387 |
| 20162 | 20388 |
| 20163 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { | 20389 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { |
| 20164 v8::internal::FLAG_allow_natives_syntax = true; | 20390 v8::internal::FLAG_allow_natives_syntax = true; |
| 20165 LocalContext context; | 20391 LocalContext context; |
| 20166 v8::HandleScope scope(context->GetIsolate()); | 20392 v8::HandleScope scope(context->GetIsolate()); |
| 20167 | 20393 |
| 20168 Local<FunctionTemplate> templ = FunctionTemplate::New(); | 20394 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 20169 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); | 20395 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); |
| 20170 proto->SetAccessor(v8_str("foo"), | 20396 proto->SetAccessor(v8_str("foo"), |
| 20171 InstanceCheckedGetter, InstanceCheckedSetter, | 20397 InstanceCheckedGetter, InstanceCheckedSetter, |
| 20172 Handle<Value>(), | 20398 Handle<Value>(), |
| 20173 v8::DEFAULT, | 20399 v8::DEFAULT, |
| 20174 v8::None, | 20400 v8::None, |
| 20175 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20401 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
| 20176 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20402 context->Global()->Set(v8_str("f"), templ->GetFunction()); |
| 20177 | 20403 |
| 20178 printf("Testing positive ...\n"); | 20404 printf("Testing positive ...\n"); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20391 TryCatch try_catch; | 20617 TryCatch try_catch; |
| 20392 try_catch.SetVerbose(true); | 20618 try_catch.SetVerbose(true); |
| 20393 CompileRun("try { throw new Error(); } finally { gc(); }"); | 20619 CompileRun("try { throw new Error(); } finally { gc(); }"); |
| 20394 CHECK(try_catch.HasCaught()); | 20620 CHECK(try_catch.HasCaught()); |
| 20395 } | 20621 } |
| 20396 | 20622 |
| 20397 | 20623 |
| 20398 THREADED_TEST(Regress149912) { | 20624 THREADED_TEST(Regress149912) { |
| 20399 LocalContext context; | 20625 LocalContext context; |
| 20400 v8::HandleScope scope(context->GetIsolate()); | 20626 v8::HandleScope scope(context->GetIsolate()); |
| 20401 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 20627 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 20402 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); | 20628 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 20403 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); | 20629 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); |
| 20404 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); | 20630 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); |
| 20405 } | 20631 } |
| 20406 | 20632 |
| 20407 | 20633 |
| 20408 THREADED_TEST(Regress157124) { | 20634 THREADED_TEST(Regress157124) { |
| 20409 LocalContext context; | 20635 LocalContext context; |
| 20410 v8::HandleScope scope(context->GetIsolate()); | 20636 v8::HandleScope scope(context->GetIsolate()); |
| 20411 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20637 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 20436 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); | 20662 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); |
| 20437 obj->SetHiddenValue(key, v8::Undefined(isolate)); | 20663 obj->SetHiddenValue(key, v8::Undefined(isolate)); |
| 20438 Local<Value> value = obj->GetHiddenValue(key); | 20664 Local<Value> value = obj->GetHiddenValue(key); |
| 20439 CHECK(!value.IsEmpty()); | 20665 CHECK(!value.IsEmpty()); |
| 20440 CHECK(value->IsUndefined()); | 20666 CHECK(value->IsUndefined()); |
| 20441 } | 20667 } |
| 20442 | 20668 |
| 20443 | 20669 |
| 20444 THREADED_TEST(Regress260106) { | 20670 THREADED_TEST(Regress260106) { |
| 20445 LocalContext context; | 20671 LocalContext context; |
| 20446 v8::HandleScope scope(context->GetIsolate()); | 20672 v8::Isolate* isolate = context->GetIsolate(); |
| 20447 Local<FunctionTemplate> templ = FunctionTemplate::New(DummyCallHandler); | 20673 v8::HandleScope scope(isolate); |
| 20674 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, |
| 20675 DummyCallHandler); |
| 20448 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); | 20676 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); |
| 20449 Local<Function> function = templ->GetFunction(); | 20677 Local<Function> function = templ->GetFunction(); |
| 20450 CHECK(!function.IsEmpty()); | 20678 CHECK(!function.IsEmpty()); |
| 20451 CHECK(function->IsFunction()); | 20679 CHECK(function->IsFunction()); |
| 20452 } | 20680 } |
| 20453 | 20681 |
| 20454 | 20682 |
| 20455 THREADED_TEST(JSONParseObject) { | 20683 THREADED_TEST(JSONParseObject) { |
| 20456 LocalContext context; | 20684 LocalContext context; |
| 20457 HandleScope scope(context->GetIsolate()); | 20685 HandleScope scope(context->GetIsolate()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20526 i::Semaphore sem_; | 20754 i::Semaphore sem_; |
| 20527 volatile int sem_value_; | 20755 volatile int sem_value_; |
| 20528 }; | 20756 }; |
| 20529 | 20757 |
| 20530 | 20758 |
| 20531 THREADED_TEST(SemaphoreInterruption) { | 20759 THREADED_TEST(SemaphoreInterruption) { |
| 20532 ThreadInterruptTest().RunTest(); | 20760 ThreadInterruptTest().RunTest(); |
| 20533 } | 20761 } |
| 20534 | 20762 |
| 20535 | 20763 |
| 20764 #endif // V8_OS_POSIX |
| 20765 |
| 20766 |
| 20536 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global, | 20767 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global, |
| 20537 Local<Value> name, | 20768 Local<Value> name, |
| 20538 v8::AccessType type, | 20769 v8::AccessType type, |
| 20539 Local<Value> data) { | 20770 Local<Value> data) { |
| 20540 i::PrintF("Named access blocked.\n"); | 20771 i::PrintF("Named access blocked.\n"); |
| 20541 return false; | 20772 return false; |
| 20542 } | 20773 } |
| 20543 | 20774 |
| 20544 | 20775 |
| 20545 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global, | 20776 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 20569 // Create a context and set an x property on it's global object. | 20800 // Create a context and set an x property on it's global object. |
| 20570 LocalContext context0(NULL, global_template); | 20801 LocalContext context0(NULL, global_template); |
| 20571 v8::Handle<v8::Object> global0 = context0->Global(); | 20802 v8::Handle<v8::Object> global0 = context0->Global(); |
| 20572 global0->Set(v8_str("x"), v8_num(42)); | 20803 global0->Set(v8_str("x"), v8_num(42)); |
| 20573 ExpectString("JSON.stringify(this)", "{\"x\":42}"); | 20804 ExpectString("JSON.stringify(this)", "{\"x\":42}"); |
| 20574 | 20805 |
| 20575 for (int i = 0; i < 2; i++) { | 20806 for (int i = 0; i < 2; i++) { |
| 20576 if (i == 1) { | 20807 if (i == 1) { |
| 20577 // Install a toJSON function on the second run. | 20808 // Install a toJSON function on the second run. |
| 20578 v8::Handle<v8::FunctionTemplate> toJSON = | 20809 v8::Handle<v8::FunctionTemplate> toJSON = |
| 20579 v8::FunctionTemplate::New(UnreachableCallback); | 20810 v8::FunctionTemplate::New(CcTest::isolate(), UnreachableCallback); |
| 20580 | 20811 |
| 20581 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); | 20812 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); |
| 20582 } | 20813 } |
| 20583 // Create a context with a different security token so that the | 20814 // Create a context with a different security token so that the |
| 20584 // failed access check callback will be called on each access. | 20815 // failed access check callback will be called on each access. |
| 20585 LocalContext context1(NULL, global_template); | 20816 LocalContext context1(NULL, global_template); |
| 20586 context1->Global()->Set(v8_str("other"), global0); | 20817 context1->Global()->Set(v8_str("other"), global0); |
| 20587 | 20818 |
| 20588 ExpectString("JSON.stringify(other)", "{}"); | 20819 ExpectString("JSON.stringify(other)", "{}"); |
| 20589 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", | 20820 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20668 LocalContext context0(NULL, global_template); | 20899 LocalContext context0(NULL, global_template); |
| 20669 context0->Global()->Set(v8_str("x"), v8_num(42)); | 20900 context0->Global()->Set(v8_str("x"), v8_num(42)); |
| 20670 v8::Handle<v8::Object> global0 = context0->Global(); | 20901 v8::Handle<v8::Object> global0 = context0->Global(); |
| 20671 | 20902 |
| 20672 // Create a context with a different security token so that the | 20903 // Create a context with a different security token so that the |
| 20673 // failed access check callback will be called on each access. | 20904 // failed access check callback will be called on each access. |
| 20674 LocalContext context1(NULL, global_template); | 20905 LocalContext context1(NULL, global_template); |
| 20675 context1->Global()->Set(v8_str("other"), global0); | 20906 context1->Global()->Set(v8_str("other"), global0); |
| 20676 | 20907 |
| 20677 v8::Handle<v8::FunctionTemplate> catcher_fun = | 20908 v8::Handle<v8::FunctionTemplate> catcher_fun = |
| 20678 v8::FunctionTemplate::New(CatcherCallback); | 20909 v8::FunctionTemplate::New(CcTest::isolate(), CatcherCallback); |
| 20679 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); | 20910 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); |
| 20680 | 20911 |
| 20681 v8::Handle<v8::FunctionTemplate> has_own_property_fun = | 20912 v8::Handle<v8::FunctionTemplate> has_own_property_fun = |
| 20682 v8::FunctionTemplate::New(HasOwnPropertyCallback); | 20913 v8::FunctionTemplate::New(CcTest::isolate(), HasOwnPropertyCallback); |
| 20683 context1->Global()->Set(v8_str("has_own_property"), | 20914 context1->Global()->Set(v8_str("has_own_property"), |
| 20684 has_own_property_fun->GetFunction()); | 20915 has_own_property_fun->GetFunction()); |
| 20685 | 20916 |
| 20686 { v8::TryCatch try_catch; | 20917 { v8::TryCatch try_catch; |
| 20687 access_check_fail_thrown = false; | 20918 access_check_fail_thrown = false; |
| 20688 CompileRun("other.x;"); | 20919 CompileRun("other.x;"); |
| 20689 CHECK(access_check_fail_thrown); | 20920 CHECK(access_check_fail_thrown); |
| 20690 CHECK(try_catch.HasCaught()); | 20921 CHECK(try_catch.HasCaught()); |
| 20691 } | 20922 } |
| 20692 | 20923 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 20711 // Reset the failed access check callback so it does not influence | 20942 // Reset the failed access check callback so it does not influence |
| 20712 // the other tests. | 20943 // the other tests. |
| 20713 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); | 20944 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); |
| 20714 } | 20945 } |
| 20715 | 20946 |
| 20716 | 20947 |
| 20717 THREADED_TEST(Regress256330) { | 20948 THREADED_TEST(Regress256330) { |
| 20718 i::FLAG_allow_natives_syntax = true; | 20949 i::FLAG_allow_natives_syntax = true; |
| 20719 LocalContext context; | 20950 LocalContext context; |
| 20720 v8::HandleScope scope(context->GetIsolate()); | 20951 v8::HandleScope scope(context->GetIsolate()); |
| 20721 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 20952 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
| 20722 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); | 20953 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); |
| 20723 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); | 20954 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); |
| 20724 CompileRun("\"use strict\"; var o = new Bug;" | 20955 CompileRun("\"use strict\"; var o = new Bug;" |
| 20725 "function f(o) { o.x = 10; };" | 20956 "function f(o) { o.x = 10; };" |
| 20726 "f(o); f(o); f(o);" | 20957 "f(o); f(o); f(o);" |
| 20727 "%OptimizeFunctionOnNextCall(f);" | 20958 "%OptimizeFunctionOnNextCall(f);" |
| 20728 "f(o);"); | 20959 "f(o);"); |
| 20729 ExpectBoolean("%GetOptimizationStatus(f) != 2", true); | 20960 ExpectBoolean("%GetOptimizationStatus(f) != 2", true); |
| 20730 } | 20961 } |
| 20731 | 20962 |
| 20732 | 20963 |
| 20733 THREADED_TEST(CrankshaftInterceptorSetter) { | 20964 THREADED_TEST(CrankshaftInterceptorSetter) { |
| 20734 i::FLAG_allow_natives_syntax = true; | 20965 i::FLAG_allow_natives_syntax = true; |
| 20735 v8::HandleScope scope(CcTest::isolate()); | 20966 v8::HandleScope scope(CcTest::isolate()); |
| 20736 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 20967 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 20737 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 20968 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 20738 LocalContext env; | 20969 LocalContext env; |
| 20739 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 20970 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 20740 CompileRun("var obj = new Obj;" | 20971 CompileRun("var obj = new Obj;" |
| 20741 // Initialize fields to avoid transitions later. | 20972 // Initialize fields to avoid transitions later. |
| 20742 "obj.age = 0;" | 20973 "obj.age = 0;" |
| 20743 "obj.accessor_age = 42;" | 20974 "obj.accessor_age = 42;" |
| 20744 "function setter(i) { this.accessor_age = i; };" | 20975 "function setter(i) { this.accessor_age = i; };" |
| 20745 "function getter() { return this.accessor_age; };" | 20976 "function getter() { return this.accessor_age; };" |
| 20746 "function setAge(i) { obj.age = i; };" | 20977 "function setAge(i) { obj.age = i; };" |
| 20747 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" | 20978 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" |
| 20748 "setAge(1);" | 20979 "setAge(1);" |
| 20749 "setAge(2);" | 20980 "setAge(2);" |
| 20750 "setAge(3);" | 20981 "setAge(3);" |
| 20751 "%OptimizeFunctionOnNextCall(setAge);" | 20982 "%OptimizeFunctionOnNextCall(setAge);" |
| 20752 "setAge(4);"); | 20983 "setAge(4);"); |
| 20753 // All stores went through the interceptor. | 20984 // All stores went through the interceptor. |
| 20754 ExpectInt32("obj.interceptor_age", 4); | 20985 ExpectInt32("obj.interceptor_age", 4); |
| 20755 ExpectInt32("obj.accessor_age", 42); | 20986 ExpectInt32("obj.accessor_age", 42); |
| 20756 } | 20987 } |
| 20757 | 20988 |
| 20758 | 20989 |
| 20759 THREADED_TEST(CrankshaftInterceptorGetter) { | 20990 THREADED_TEST(CrankshaftInterceptorGetter) { |
| 20760 i::FLAG_allow_natives_syntax = true; | 20991 i::FLAG_allow_natives_syntax = true; |
| 20761 v8::HandleScope scope(CcTest::isolate()); | 20992 v8::HandleScope scope(CcTest::isolate()); |
| 20762 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 20993 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 20763 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 20994 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 20764 LocalContext env; | 20995 LocalContext env; |
| 20765 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 20996 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 20766 CompileRun("var obj = new Obj;" | 20997 CompileRun("var obj = new Obj;" |
| 20767 // Initialize fields to avoid transitions later. | 20998 // Initialize fields to avoid transitions later. |
| 20768 "obj.age = 1;" | 20999 "obj.age = 1;" |
| 20769 "obj.accessor_age = 42;" | 21000 "obj.accessor_age = 42;" |
| 20770 "function getter() { return this.accessor_age; };" | 21001 "function getter() { return this.accessor_age; };" |
| 20771 "function getAge() { return obj.interceptor_age; };" | 21002 "function getAge() { return obj.interceptor_age; };" |
| 20772 "Object.defineProperty(obj, 'interceptor_age', { get:getter });" | 21003 "Object.defineProperty(obj, 'interceptor_age', { get:getter });" |
| 20773 "getAge();" | 21004 "getAge();" |
| 20774 "getAge();" | 21005 "getAge();" |
| 20775 "getAge();" | 21006 "getAge();" |
| 20776 "%OptimizeFunctionOnNextCall(getAge);"); | 21007 "%OptimizeFunctionOnNextCall(getAge);"); |
| 20777 // Access through interceptor. | 21008 // Access through interceptor. |
| 20778 ExpectInt32("getAge()", 1); | 21009 ExpectInt32("getAge()", 1); |
| 20779 } | 21010 } |
| 20780 | 21011 |
| 20781 | 21012 |
| 20782 THREADED_TEST(CrankshaftInterceptorFieldRead) { | 21013 THREADED_TEST(CrankshaftInterceptorFieldRead) { |
| 20783 i::FLAG_allow_natives_syntax = true; | 21014 i::FLAG_allow_natives_syntax = true; |
| 20784 v8::HandleScope scope(CcTest::isolate()); | 21015 v8::HandleScope scope(CcTest::isolate()); |
| 20785 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 21016 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 20786 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 21017 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 20787 LocalContext env; | 21018 LocalContext env; |
| 20788 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 21019 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 20789 CompileRun("var obj = new Obj;" | 21020 CompileRun("var obj = new Obj;" |
| 20790 "obj.__proto__.interceptor_age = 42;" | 21021 "obj.__proto__.interceptor_age = 42;" |
| 20791 "obj.age = 100;" | 21022 "obj.age = 100;" |
| 20792 "function getAge() { return obj.interceptor_age; };"); | 21023 "function getAge() { return obj.interceptor_age; };"); |
| 20793 ExpectInt32("getAge();", 100); | 21024 ExpectInt32("getAge();", 100); |
| 20794 ExpectInt32("getAge();", 100); | 21025 ExpectInt32("getAge();", 100); |
| 20795 ExpectInt32("getAge();", 100); | 21026 ExpectInt32("getAge();", 100); |
| 20796 CompileRun("%OptimizeFunctionOnNextCall(getAge);"); | 21027 CompileRun("%OptimizeFunctionOnNextCall(getAge);"); |
| 20797 // Access through interceptor. | 21028 // Access through interceptor. |
| 20798 ExpectInt32("getAge();", 100); | 21029 ExpectInt32("getAge();", 100); |
| 20799 } | 21030 } |
| 20800 | 21031 |
| 20801 | 21032 |
| 20802 THREADED_TEST(CrankshaftInterceptorFieldWrite) { | 21033 THREADED_TEST(CrankshaftInterceptorFieldWrite) { |
| 20803 i::FLAG_allow_natives_syntax = true; | 21034 i::FLAG_allow_natives_syntax = true; |
| 20804 v8::HandleScope scope(CcTest::isolate()); | 21035 v8::HandleScope scope(CcTest::isolate()); |
| 20805 Handle<FunctionTemplate> templ = FunctionTemplate::New(); | 21036 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate()); |
| 20806 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); | 21037 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); |
| 20807 LocalContext env; | 21038 LocalContext env; |
| 20808 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); | 21039 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); |
| 20809 CompileRun("var obj = new Obj;" | 21040 CompileRun("var obj = new Obj;" |
| 20810 "obj.age = 100000;" | 21041 "obj.age = 100000;" |
| 20811 "function setAge(i) { obj.age = i };" | 21042 "function setAge(i) { obj.age = i };" |
| 20812 "setAge(100);" | 21043 "setAge(100);" |
| 20813 "setAge(101);" | 21044 "setAge(101);" |
| 20814 "setAge(102);" | 21045 "setAge(102);" |
| 20815 "%OptimizeFunctionOnNextCall(setAge);" | 21046 "%OptimizeFunctionOnNextCall(setAge);" |
| 20816 "setAge(103);"); | 21047 "setAge(103);"); |
| 20817 ExpectInt32("obj.age", 100000); | 21048 ExpectInt32("obj.age", 100000); |
| 20818 ExpectInt32("obj.interceptor_age", 103); | 21049 ExpectInt32("obj.interceptor_age", 103); |
| 20819 } | 21050 } |
| 20820 | 21051 |
| 20821 | 21052 |
| 20822 #endif // V8_OS_POSIX | 21053 class RequestInterruptTestBase { |
| 21054 public: |
| 21055 RequestInterruptTestBase() |
| 21056 : env_(), |
| 21057 isolate_(env_->GetIsolate()), |
| 21058 sem_(0), |
| 21059 warmup_(20000), |
| 21060 should_continue_(true) { |
| 21061 } |
| 21062 |
| 21063 virtual ~RequestInterruptTestBase() { } |
| 21064 |
| 21065 virtual void TestBody() = 0; |
| 21066 |
| 21067 void RunTest() { |
| 21068 InterruptThread i_thread(this); |
| 21069 i_thread.Start(); |
| 21070 |
| 21071 v8::HandleScope handle_scope(isolate_); |
| 21072 |
| 21073 TestBody(); |
| 21074 |
| 21075 isolate_->ClearInterrupt(); |
| 21076 |
| 21077 // Verify we arrived here because interruptor was called |
| 21078 // not due to a bug causing us to exit the loop too early. |
| 21079 CHECK(!should_continue()); |
| 21080 } |
| 21081 |
| 21082 void WakeUpInterruptor() { |
| 21083 sem_.Signal(); |
| 21084 } |
| 21085 |
| 21086 bool should_continue() const { return should_continue_; } |
| 21087 |
| 21088 bool ShouldContinue() { |
| 21089 if (warmup_ > 0) { |
| 21090 if (--warmup_ == 0) { |
| 21091 WakeUpInterruptor(); |
| 21092 } |
| 21093 } |
| 21094 |
| 21095 return should_continue_; |
| 21096 } |
| 21097 |
| 21098 protected: |
| 21099 static void ShouldContinueCallback( |
| 21100 const v8::FunctionCallbackInfo<Value>& info) { |
| 21101 RequestInterruptTestBase* test = |
| 21102 reinterpret_cast<RequestInterruptTestBase*>( |
| 21103 info.Data().As<v8::External>()->Value()); |
| 21104 info.GetReturnValue().Set(test->ShouldContinue()); |
| 21105 } |
| 21106 |
| 21107 class InterruptThread : public i::Thread { |
| 21108 public: |
| 21109 explicit InterruptThread(RequestInterruptTestBase* test) |
| 21110 : Thread("RequestInterruptTest"), test_(test) {} |
| 21111 |
| 21112 virtual void Run() { |
| 21113 test_->sem_.Wait(); |
| 21114 test_->isolate_->RequestInterrupt(&OnInterrupt, test_); |
| 21115 } |
| 21116 |
| 21117 static void OnInterrupt(v8::Isolate* isolate, void* data) { |
| 21118 reinterpret_cast<RequestInterruptTestBase*>(data)-> |
| 21119 should_continue_ = false; |
| 21120 } |
| 21121 |
| 21122 private: |
| 21123 RequestInterruptTestBase* test_; |
| 21124 }; |
| 21125 |
| 21126 LocalContext env_; |
| 21127 v8::Isolate* isolate_; |
| 21128 i::Semaphore sem_; |
| 21129 int warmup_; |
| 21130 bool should_continue_; |
| 21131 }; |
| 21132 |
| 21133 |
| 21134 class RequestInterruptTestWithFunctionCall : public RequestInterruptTestBase { |
| 21135 public: |
| 21136 virtual void TestBody() { |
| 21137 Local<Function> func = Function::New( |
| 21138 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); |
| 21139 env_->Global()->Set(v8_str("ShouldContinue"), func); |
| 21140 |
| 21141 CompileRun("while (ShouldContinue()) { }"); |
| 21142 } |
| 21143 }; |
| 21144 |
| 21145 |
| 21146 class RequestInterruptTestWithMethodCall : public RequestInterruptTestBase { |
| 21147 public: |
| 21148 virtual void TestBody() { |
| 21149 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21150 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21151 proto->Set(v8_str("shouldContinue"), Function::New( |
| 21152 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21153 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21154 |
| 21155 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
| 21156 } |
| 21157 }; |
| 21158 |
| 21159 |
| 21160 class RequestInterruptTestWithAccessor : public RequestInterruptTestBase { |
| 21161 public: |
| 21162 virtual void TestBody() { |
| 21163 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21164 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21165 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( |
| 21166 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21167 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21168 |
| 21169 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
| 21170 } |
| 21171 }; |
| 21172 |
| 21173 |
| 21174 class RequestInterruptTestWithNativeAccessor : public RequestInterruptTestBase { |
| 21175 public: |
| 21176 virtual void TestBody() { |
| 21177 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21178 t->InstanceTemplate()->SetNativeDataProperty( |
| 21179 v8_str("shouldContinue"), |
| 21180 &ShouldContinueNativeGetter, |
| 21181 NULL, |
| 21182 v8::External::New(isolate_, this)); |
| 21183 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21184 |
| 21185 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
| 21186 } |
| 21187 |
| 21188 private: |
| 21189 static void ShouldContinueNativeGetter( |
| 21190 Local<String> property, |
| 21191 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 21192 RequestInterruptTestBase* test = |
| 21193 reinterpret_cast<RequestInterruptTestBase*>( |
| 21194 info.Data().As<v8::External>()->Value()); |
| 21195 info.GetReturnValue().Set(test->ShouldContinue()); |
| 21196 } |
| 21197 }; |
| 21198 |
| 21199 |
| 21200 class RequestInterruptTestWithMethodCallAndInterceptor |
| 21201 : public RequestInterruptTestBase { |
| 21202 public: |
| 21203 virtual void TestBody() { |
| 21204 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
| 21205 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
| 21206 proto->Set(v8_str("shouldContinue"), Function::New( |
| 21207 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
| 21208 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
| 21209 instance_template->SetNamedPropertyHandler(EmptyInterceptor); |
| 21210 |
| 21211 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); |
| 21212 |
| 21213 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
| 21214 } |
| 21215 |
| 21216 private: |
| 21217 static void EmptyInterceptor( |
| 21218 Local<String> property, |
| 21219 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 21220 } |
| 21221 }; |
| 21222 |
| 21223 |
| 21224 class RequestInterruptTestWithMathAbs : public RequestInterruptTestBase { |
| 21225 public: |
| 21226 virtual void TestBody() { |
| 21227 env_->Global()->Set(v8_str("WakeUpInterruptor"), Function::New( |
| 21228 isolate_, |
| 21229 WakeUpInterruptorCallback, |
| 21230 v8::External::New(isolate_, this))); |
| 21231 |
| 21232 env_->Global()->Set(v8_str("ShouldContinue"), Function::New( |
| 21233 isolate_, |
| 21234 ShouldContinueCallback, |
| 21235 v8::External::New(isolate_, this))); |
| 21236 |
| 21237 i::FLAG_allow_natives_syntax = true; |
| 21238 CompileRun("function loopish(o) {" |
| 21239 " var pre = 10;" |
| 21240 " while (o.abs(1) > 0) {" |
| 21241 " if (o.abs(1) >= 0 && !ShouldContinue()) break;" |
| 21242 " if (pre > 0) {" |
| 21243 " if (--pre === 0) WakeUpInterruptor(o === Math);" |
| 21244 " }" |
| 21245 " }" |
| 21246 "}" |
| 21247 "var i = 50;" |
| 21248 "var obj = {abs: function () { return i-- }, x: null};" |
| 21249 "delete obj.x;" |
| 21250 "loopish(obj);" |
| 21251 "%OptimizeFunctionOnNextCall(loopish);" |
| 21252 "loopish(Math);"); |
| 21253 |
| 21254 i::FLAG_allow_natives_syntax = false; |
| 21255 } |
| 21256 |
| 21257 private: |
| 21258 static void WakeUpInterruptorCallback( |
| 21259 const v8::FunctionCallbackInfo<Value>& info) { |
| 21260 if (!info[0]->BooleanValue()) return; |
| 21261 |
| 21262 RequestInterruptTestBase* test = |
| 21263 reinterpret_cast<RequestInterruptTestBase*>( |
| 21264 info.Data().As<v8::External>()->Value()); |
| 21265 test->WakeUpInterruptor(); |
| 21266 } |
| 21267 |
| 21268 static void ShouldContinueCallback( |
| 21269 const v8::FunctionCallbackInfo<Value>& info) { |
| 21270 RequestInterruptTestBase* test = |
| 21271 reinterpret_cast<RequestInterruptTestBase*>( |
| 21272 info.Data().As<v8::External>()->Value()); |
| 21273 info.GetReturnValue().Set(test->should_continue()); |
| 21274 } |
| 21275 }; |
| 21276 |
| 21277 |
| 21278 TEST(RequestInterruptTestWithFunctionCall) { |
| 21279 RequestInterruptTestWithFunctionCall().RunTest(); |
| 21280 } |
| 21281 |
| 21282 |
| 21283 TEST(RequestInterruptTestWithMethodCall) { |
| 21284 RequestInterruptTestWithMethodCall().RunTest(); |
| 21285 } |
| 21286 |
| 21287 |
| 21288 TEST(RequestInterruptTestWithAccessor) { |
| 21289 RequestInterruptTestWithAccessor().RunTest(); |
| 21290 } |
| 21291 |
| 21292 |
| 21293 TEST(RequestInterruptTestWithNativeAccessor) { |
| 21294 RequestInterruptTestWithNativeAccessor().RunTest(); |
| 21295 } |
| 21296 |
| 21297 |
| 21298 TEST(RequestInterruptTestWithMethodCallAndInterceptor) { |
| 21299 RequestInterruptTestWithMethodCallAndInterceptor().RunTest(); |
| 21300 } |
| 21301 |
| 21302 |
| 21303 TEST(RequestInterruptTestWithMathAbs) { |
| 21304 RequestInterruptTestWithMathAbs().RunTest(); |
| 21305 } |
| 20823 | 21306 |
| 20824 | 21307 |
| 20825 static Local<Value> function_new_expected_env; | 21308 static Local<Value> function_new_expected_env; |
| 20826 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { | 21309 static void FunctionNewCallback(const v8::FunctionCallbackInfo<Value>& info) { |
| 20827 CHECK_EQ(function_new_expected_env, info.Data()); | 21310 CHECK_EQ(function_new_expected_env, info.Data()); |
| 20828 info.GetReturnValue().Set(17); | 21311 info.GetReturnValue().Set(17); |
| 20829 } | 21312 } |
| 20830 | 21313 |
| 20831 | 21314 |
| 20832 THREADED_TEST(FunctionNew) { | 21315 THREADED_TEST(FunctionNew) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20872 } | 21355 } |
| 20873 for (int i = 0; i < runs; i++) { | 21356 for (int i = 0; i < runs; i++) { |
| 20874 Local<String> expected; | 21357 Local<String> expected; |
| 20875 if (i != 0) { | 21358 if (i != 0) { |
| 20876 CHECK_EQ(v8_str("escape value"), values[i]); | 21359 CHECK_EQ(v8_str("escape value"), values[i]); |
| 20877 } else { | 21360 } else { |
| 20878 CHECK(values[i].IsEmpty()); | 21361 CHECK(values[i].IsEmpty()); |
| 20879 } | 21362 } |
| 20880 } | 21363 } |
| 20881 } | 21364 } |
| OLD | NEW |