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 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1096 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
1097 ApiTestFuzzer::Fuzz(); | 1097 ApiTestFuzzer::Fuzz(); |
1098 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); | 1098 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); |
1099 info.GetReturnValue().Set(v8_num(51423 + info.Length())); | 1099 info.GetReturnValue().Set(v8_num(51423 + info.Length())); |
1100 } | 1100 } |
1101 | 1101 |
1102 | 1102 |
1103 template<typename Callback> | 1103 template<typename Callback> |
1104 static void TestSimpleCallback(Callback callback) { | 1104 static void TestSimpleCallback(Callback callback) { |
1105 LocalContext env; | 1105 LocalContext env; |
1106 v8::HandleScope scope(env->GetIsolate()); | 1106 v8::Isolate* isolate = env->GetIsolate(); |
| 1107 v8::HandleScope scope(isolate); |
1107 | 1108 |
1108 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1109 v8::Handle<v8::ObjectTemplate> object_template = |
1109 object_template->Set(env->GetIsolate(), "callback", | 1110 v8::ObjectTemplate::New(isolate); |
1110 v8::FunctionTemplate::New(env->GetIsolate(), callback)); | 1111 object_template->Set(isolate, "callback", |
| 1112 v8::FunctionTemplate::New(isolate, callback)); |
1111 v8::Local<v8::Object> object = object_template->NewInstance(); | 1113 v8::Local<v8::Object> object = object_template->NewInstance(); |
1112 (*env)->Global()->Set(v8_str("callback_object"), object); | 1114 (*env)->Global()->Set(v8_str("callback_object"), object); |
1113 v8::Handle<v8::Script> script; | 1115 v8::Handle<v8::Script> script; |
1114 script = v8_compile("callback_object.callback(17)"); | 1116 script = v8_compile("callback_object.callback(17)"); |
1115 for (int i = 0; i < 30; i++) { | 1117 for (int i = 0; i < 30; i++) { |
1116 CHECK_EQ(51424, script->Run()->Int32Value()); | 1118 CHECK_EQ(51424, script->Run()->Int32Value()); |
1117 } | 1119 } |
1118 script = v8_compile("callback_object.callback(17, 24)"); | 1120 script = v8_compile("callback_object.callback(17, 24)"); |
1119 for (int i = 0; i < 30; i++) { | 1121 for (int i = 0; i < 30; i++) { |
1120 CHECK_EQ(51425, script->Run()->Int32Value()); | 1122 CHECK_EQ(51425, script->Run()->Int32Value()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 v8::Handle<v8::Object> object; | 1203 v8::Handle<v8::Object> object; |
1202 if (!fast_return_value_object_is_empty) { | 1204 if (!fast_return_value_object_is_empty) { |
1203 object = Object::New(info.GetIsolate()); | 1205 object = Object::New(info.GetIsolate()); |
1204 } | 1206 } |
1205 info.GetReturnValue().Set(object); | 1207 info.GetReturnValue().Set(object); |
1206 } | 1208 } |
1207 | 1209 |
1208 template<typename T> | 1210 template<typename T> |
1209 Handle<Value> TestFastReturnValues() { | 1211 Handle<Value> TestFastReturnValues() { |
1210 LocalContext env; | 1212 LocalContext env; |
1211 v8::EscapableHandleScope scope(env->GetIsolate()); | 1213 v8::Isolate* isolate = env->GetIsolate(); |
1212 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 1214 v8::EscapableHandleScope scope(isolate); |
| 1215 v8::Handle<v8::ObjectTemplate> object_template = |
| 1216 v8::ObjectTemplate::New(isolate); |
1213 v8::FunctionCallback callback = &FastReturnValueCallback<T>; | 1217 v8::FunctionCallback callback = &FastReturnValueCallback<T>; |
1214 object_template->Set(env->GetIsolate(), "callback", | 1218 object_template->Set(isolate, "callback", |
1215 v8::FunctionTemplate::New(env->GetIsolate(), callback)); | 1219 v8::FunctionTemplate::New(isolate, callback)); |
1216 v8::Local<v8::Object> object = object_template->NewInstance(); | 1220 v8::Local<v8::Object> object = object_template->NewInstance(); |
1217 (*env)->Global()->Set(v8_str("callback_object"), object); | 1221 (*env)->Global()->Set(v8_str("callback_object"), object); |
1218 return scope.Escape(CompileRun("callback_object.callback()")); | 1222 return scope.Escape(CompileRun("callback_object.callback()")); |
1219 } | 1223 } |
1220 | 1224 |
1221 | 1225 |
1222 THREADED_PROFILED_TEST(FastReturnValues) { | 1226 THREADED_PROFILED_TEST(FastReturnValues) { |
1223 LocalContext env; | 1227 LocalContext env; |
1224 v8::HandleScope scope(CcTest::isolate()); | 1228 v8::HandleScope scope(CcTest::isolate()); |
1225 v8::Handle<v8::Value> value; | 1229 v8::Handle<v8::Value> value; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 v8::Handle<Value> result(script->Run()); | 1796 v8::Handle<Value> result(script->Run()); |
1793 CHECK_EQ(13.4, result->NumberValue()); | 1797 CHECK_EQ(13.4, result->NumberValue()); |
1794 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); | 1798 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); |
1795 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); | 1799 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); |
1796 } | 1800 } |
1797 | 1801 |
1798 | 1802 |
1799 THREADED_TEST(ObjectTemplate) { | 1803 THREADED_TEST(ObjectTemplate) { |
1800 v8::Isolate* isolate = CcTest::isolate(); | 1804 v8::Isolate* isolate = CcTest::isolate(); |
1801 v8::HandleScope scope(isolate); | 1805 v8::HandleScope scope(isolate); |
1802 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); | 1806 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate); |
1803 templ1->Set(isolate, "x", v8_num(10)); | 1807 templ1->Set(isolate, "x", v8_num(10)); |
1804 templ1->Set(isolate, "y", v8_num(13)); | 1808 templ1->Set(isolate, "y", v8_num(13)); |
1805 LocalContext env; | 1809 LocalContext env; |
1806 Local<v8::Object> instance1 = templ1->NewInstance(); | 1810 Local<v8::Object> instance1 = templ1->NewInstance(); |
1807 env->Global()->Set(v8_str("p"), instance1); | 1811 env->Global()->Set(v8_str("p"), instance1); |
1808 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); | 1812 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); |
1809 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); | 1813 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); |
1810 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); | 1814 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
1811 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); | 1815 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); |
1812 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); | 1816 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2467 v8::Handle<Value> function = | 2471 v8::Handle<Value> function = |
2468 args.This()->Get(v8_str("callFunctionRecursively")); | 2472 args.This()->Get(v8_str("callFunctionRecursively")); |
2469 args.GetReturnValue().Set( | 2473 args.GetReturnValue().Set( |
2470 function.As<Function>()->Call(args.This(), 0, NULL)); | 2474 function.As<Function>()->Call(args.This(), 0, NULL)); |
2471 } | 2475 } |
2472 | 2476 |
2473 | 2477 |
2474 THREADED_TEST(DeepCrossLanguageRecursion) { | 2478 THREADED_TEST(DeepCrossLanguageRecursion) { |
2475 v8::Isolate* isolate = CcTest::isolate(); | 2479 v8::Isolate* isolate = CcTest::isolate(); |
2476 v8::HandleScope scope(isolate); | 2480 v8::HandleScope scope(isolate); |
2477 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 2481 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
2478 global->Set(v8_str("callScriptRecursively"), | 2482 global->Set(v8_str("callScriptRecursively"), |
2479 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); | 2483 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); |
2480 global->Set(v8_str("callFunctionRecursively"), | 2484 global->Set(v8_str("callFunctionRecursively"), |
2481 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); | 2485 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); |
2482 LocalContext env(NULL, global); | 2486 LocalContext env(NULL, global); |
2483 | 2487 |
2484 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2488 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); |
2485 call_recursively_script = v8_compile("callScriptRecursively()"); | 2489 call_recursively_script = v8_compile("callScriptRecursively()"); |
2486 call_recursively_script->Run(); | 2490 call_recursively_script->Run(); |
2487 call_recursively_script = v8::Handle<Script>(); | 2491 call_recursively_script = v8::Handle<Script>(); |
(...skipping 14 matching lines...) Expand all Loading... |
2502 static void ThrowingPropertyHandlerSet( | 2506 static void ThrowingPropertyHandlerSet( |
2503 Local<String> key, | 2507 Local<String> key, |
2504 Local<Value>, | 2508 Local<Value>, |
2505 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2509 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2506 info.GetIsolate()->ThrowException(key); | 2510 info.GetIsolate()->ThrowException(key); |
2507 info.GetReturnValue().SetUndefined(); // not the same as empty handle | 2511 info.GetReturnValue().SetUndefined(); // not the same as empty handle |
2508 } | 2512 } |
2509 | 2513 |
2510 | 2514 |
2511 THREADED_TEST(CallbackExceptionRegression) { | 2515 THREADED_TEST(CallbackExceptionRegression) { |
2512 v8::HandleScope scope(CcTest::isolate()); | 2516 v8::Isolate* isolate = CcTest::isolate(); |
2513 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 2517 v8::HandleScope scope(isolate); |
| 2518 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
2514 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, | 2519 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, |
2515 ThrowingPropertyHandlerSet); | 2520 ThrowingPropertyHandlerSet); |
2516 LocalContext env; | 2521 LocalContext env; |
2517 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 2522 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
2518 v8::Handle<Value> otto = Script::Compile(v8_str( | 2523 v8::Handle<Value> otto = Script::Compile(v8_str( |
2519 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); | 2524 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); |
2520 CHECK_EQ(v8_str("otto"), otto); | 2525 CHECK_EQ(v8_str("otto"), otto); |
2521 v8::Handle<Value> netto = Script::Compile(v8_str( | 2526 v8::Handle<Value> netto = Script::Compile(v8_str( |
2522 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); | 2527 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); |
2523 CHECK_EQ(v8_str("netto"), netto); | 2528 CHECK_EQ(v8_str("netto"), netto); |
(...skipping 22 matching lines...) Expand all Loading... |
2546 instance_templ->SetInternalFieldCount(1); | 2551 instance_templ->SetInternalFieldCount(1); |
2547 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 2552 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); |
2548 CHECK_EQ(1, obj->InternalFieldCount()); | 2553 CHECK_EQ(1, obj->InternalFieldCount()); |
2549 CHECK(obj->GetInternalField(0)->IsUndefined()); | 2554 CHECK(obj->GetInternalField(0)->IsUndefined()); |
2550 obj->SetInternalField(0, v8_num(17)); | 2555 obj->SetInternalField(0, v8_num(17)); |
2551 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); | 2556 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); |
2552 } | 2557 } |
2553 | 2558 |
2554 | 2559 |
2555 THREADED_TEST(GlobalObjectInternalFields) { | 2560 THREADED_TEST(GlobalObjectInternalFields) { |
2556 v8::HandleScope scope(CcTest::isolate()); | 2561 v8::Isolate* isolate = CcTest::isolate(); |
2557 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 2562 v8::HandleScope scope(isolate); |
| 2563 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
2558 global_template->SetInternalFieldCount(1); | 2564 global_template->SetInternalFieldCount(1); |
2559 LocalContext env(NULL, global_template); | 2565 LocalContext env(NULL, global_template); |
2560 v8::Handle<v8::Object> global_proxy = env->Global(); | 2566 v8::Handle<v8::Object> global_proxy = env->Global(); |
2561 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 2567 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
2562 CHECK_EQ(1, global->InternalFieldCount()); | 2568 CHECK_EQ(1, global->InternalFieldCount()); |
2563 CHECK(global->GetInternalField(0)->IsUndefined()); | 2569 CHECK(global->GetInternalField(0)->IsUndefined()); |
2564 global->SetInternalField(0, v8_num(17)); | 2570 global->SetInternalField(0, v8_num(17)); |
2565 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); | 2571 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); |
2566 } | 2572 } |
2567 | 2573 |
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4240 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); | 4246 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); |
4241 for (int i = 0; i < args.Length(); i++) | 4247 for (int i = 0; i < args.Length(); i++) |
4242 result->Set(i, args[i]); | 4248 result->Set(i, args[i]); |
4243 args.GetReturnValue().Set(scope.Escape(result)); | 4249 args.GetReturnValue().Set(scope.Escape(result)); |
4244 } | 4250 } |
4245 | 4251 |
4246 | 4252 |
4247 THREADED_TEST(Vector) { | 4253 THREADED_TEST(Vector) { |
4248 v8::Isolate* isolate = CcTest::isolate(); | 4254 v8::Isolate* isolate = CcTest::isolate(); |
4249 v8::HandleScope scope(isolate); | 4255 v8::HandleScope scope(isolate); |
4250 Local<ObjectTemplate> global = ObjectTemplate::New(); | 4256 Local<ObjectTemplate> global = ObjectTemplate::New(isolate); |
4251 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); | 4257 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); |
4252 LocalContext context(0, global); | 4258 LocalContext context(0, global); |
4253 | 4259 |
4254 const char* fun = "f()"; | 4260 const char* fun = "f()"; |
4255 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); | 4261 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); |
4256 CHECK_EQ(0, a0->Length()); | 4262 CHECK_EQ(0, a0->Length()); |
4257 | 4263 |
4258 const char* fun2 = "f(11)"; | 4264 const char* fun2 = "f(11)"; |
4259 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); | 4265 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); |
4260 CHECK_EQ(1, a1->Length()); | 4266 CHECK_EQ(1, a1->Length()); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4420 | 4426 |
4421 | 4427 |
4422 TEST(OutOfMemoryNested) { | 4428 TEST(OutOfMemoryNested) { |
4423 // It's not possible to read a snapshot into a heap with different dimensions. | 4429 // It's not possible to read a snapshot into a heap with different dimensions. |
4424 if (i::Snapshot::IsEnabled()) return; | 4430 if (i::Snapshot::IsEnabled()) return; |
4425 // Set heap limits. | 4431 // Set heap limits. |
4426 static const int K = 1024; | 4432 static const int K = 1024; |
4427 v8::ResourceConstraints constraints; | 4433 v8::ResourceConstraints constraints; |
4428 constraints.set_max_young_space_size(256 * K); | 4434 constraints.set_max_young_space_size(256 * K); |
4429 constraints.set_max_old_space_size(5 * K * K); | 4435 constraints.set_max_old_space_size(5 * K * K); |
4430 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 4436 v8::Isolate* isolate = CcTest::isolate(); |
| 4437 v8::SetResourceConstraints(isolate, &constraints); |
4431 | 4438 |
4432 v8::HandleScope scope(CcTest::isolate()); | 4439 v8::HandleScope scope(isolate); |
4433 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4440 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4434 templ->Set(v8_str("ProvokeOutOfMemory"), | 4441 templ->Set(v8_str("ProvokeOutOfMemory"), |
4435 v8::FunctionTemplate::New(CcTest::isolate(), ProvokeOutOfMemory)); | 4442 v8::FunctionTemplate::New(isolate, ProvokeOutOfMemory)); |
4436 LocalContext context(0, templ); | 4443 LocalContext context(0, templ); |
4437 v8::V8::IgnoreOutOfMemoryException(); | 4444 v8::V8::IgnoreOutOfMemoryException(); |
4438 Local<Value> result = CompileRun( | 4445 Local<Value> result = CompileRun( |
4439 "var thrown = false;" | 4446 "var thrown = false;" |
4440 "try {" | 4447 "try {" |
4441 " ProvokeOutOfMemory();" | 4448 " ProvokeOutOfMemory();" |
4442 "} catch (e) {" | 4449 "} catch (e) {" |
4443 " thrown = true;" | 4450 " thrown = true;" |
4444 "}"); | 4451 "}"); |
4445 // Check for out of memory state. | 4452 // Check for out of memory state. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4706 } | 4713 } |
4707 v8::HandleScope scope(args.GetIsolate()); | 4714 v8::HandleScope scope(args.GetIsolate()); |
4708 v8::TryCatch try_catch; | 4715 v8::TryCatch try_catch; |
4709 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); | 4716 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); |
4710 CHECK(!try_catch.HasCaught() || result.IsEmpty()); | 4717 CHECK(!try_catch.HasCaught() || result.IsEmpty()); |
4711 args.GetReturnValue().Set(try_catch.HasCaught()); | 4718 args.GetReturnValue().Set(try_catch.HasCaught()); |
4712 } | 4719 } |
4713 | 4720 |
4714 | 4721 |
4715 THREADED_TEST(APICatch) { | 4722 THREADED_TEST(APICatch) { |
4716 v8::HandleScope scope(CcTest::isolate()); | 4723 v8::Isolate* isolate = CcTest::isolate(); |
4717 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4724 v8::HandleScope scope(isolate); |
| 4725 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4718 templ->Set(v8_str("ThrowFromC"), | 4726 templ->Set(v8_str("ThrowFromC"), |
4719 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); | 4727 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4720 LocalContext context(0, templ); | 4728 LocalContext context(0, templ); |
4721 CompileRun( | 4729 CompileRun( |
4722 "var thrown = false;" | 4730 "var thrown = false;" |
4723 "try {" | 4731 "try {" |
4724 " ThrowFromC();" | 4732 " ThrowFromC();" |
4725 "} catch (e) {" | 4733 "} catch (e) {" |
4726 " thrown = true;" | 4734 " thrown = true;" |
4727 "}"); | 4735 "}"); |
4728 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); | 4736 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); |
4729 CHECK(thrown->BooleanValue()); | 4737 CHECK(thrown->BooleanValue()); |
4730 } | 4738 } |
4731 | 4739 |
4732 | 4740 |
4733 THREADED_TEST(APIThrowTryCatch) { | 4741 THREADED_TEST(APIThrowTryCatch) { |
4734 v8::HandleScope scope(CcTest::isolate()); | 4742 v8::Isolate* isolate = CcTest::isolate(); |
4735 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4743 v8::HandleScope scope(isolate); |
| 4744 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4736 templ->Set(v8_str("ThrowFromC"), | 4745 templ->Set(v8_str("ThrowFromC"), |
4737 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); | 4746 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4738 LocalContext context(0, templ); | 4747 LocalContext context(0, templ); |
4739 v8::TryCatch try_catch; | 4748 v8::TryCatch try_catch; |
4740 CompileRun("ThrowFromC();"); | 4749 CompileRun("ThrowFromC();"); |
4741 CHECK(try_catch.HasCaught()); | 4750 CHECK(try_catch.HasCaught()); |
4742 } | 4751 } |
4743 | 4752 |
4744 | 4753 |
4745 // Test that a try-finally block doesn't shadow a try-catch block | 4754 // Test that a try-finally block doesn't shadow a try-catch block |
4746 // when setting up an external handler. | 4755 // when setting up an external handler. |
4747 // | 4756 // |
4748 // BUG(271): Some of the exception propagation does not work on the | 4757 // BUG(271): Some of the exception propagation does not work on the |
4749 // ARM simulator because the simulator separates the C++ stack and the | 4758 // ARM simulator because the simulator separates the C++ stack and the |
4750 // JS stack. This test therefore fails on the simulator. The test is | 4759 // JS stack. This test therefore fails on the simulator. The test is |
4751 // not threaded to allow the threading tests to run on the simulator. | 4760 // not threaded to allow the threading tests to run on the simulator. |
4752 TEST(TryCatchInTryFinally) { | 4761 TEST(TryCatchInTryFinally) { |
4753 v8::HandleScope scope(CcTest::isolate()); | 4762 v8::Isolate* isolate = CcTest::isolate(); |
4754 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4763 v8::HandleScope scope(isolate); |
| 4764 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4755 templ->Set(v8_str("CCatcher"), | 4765 templ->Set(v8_str("CCatcher"), |
4756 v8::FunctionTemplate::New(CcTest::isolate(), CCatcher)); | 4766 v8::FunctionTemplate::New(isolate, CCatcher)); |
4757 LocalContext context(0, templ); | 4767 LocalContext context(0, templ); |
4758 Local<Value> result = CompileRun("try {" | 4768 Local<Value> result = CompileRun("try {" |
4759 " try {" | 4769 " try {" |
4760 " CCatcher('throw 7;');" | 4770 " CCatcher('throw 7;');" |
4761 " } finally {" | 4771 " } finally {" |
4762 " }" | 4772 " }" |
4763 "} catch (e) {" | 4773 "} catch (e) {" |
4764 "}"); | 4774 "}"); |
4765 CHECK(result->IsTrue()); | 4775 CHECK(result->IsTrue()); |
4766 } | 4776 } |
(...skipping 13 matching lines...) Expand all Loading... |
4780 } | 4790 } |
4781 | 4791 |
4782 | 4792 |
4783 // Test that overwritten methods are not invoked on uncaught exception | 4793 // Test that overwritten methods are not invoked on uncaught exception |
4784 // formatting. However, they are invoked when performing normal error | 4794 // formatting. However, they are invoked when performing normal error |
4785 // string conversions. | 4795 // string conversions. |
4786 TEST(APIThrowMessageOverwrittenToString) { | 4796 TEST(APIThrowMessageOverwrittenToString) { |
4787 v8::Isolate* isolate = CcTest::isolate(); | 4797 v8::Isolate* isolate = CcTest::isolate(); |
4788 v8::HandleScope scope(isolate); | 4798 v8::HandleScope scope(isolate); |
4789 v8::V8::AddMessageListener(check_reference_error_message); | 4799 v8::V8::AddMessageListener(check_reference_error_message); |
4790 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4800 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4791 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); | 4801 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); |
4792 LocalContext context(NULL, templ); | 4802 LocalContext context(NULL, templ); |
4793 CompileRun("asdf;"); | 4803 CompileRun("asdf;"); |
4794 CompileRun("var limit = {};" | 4804 CompileRun("var limit = {};" |
4795 "limit.valueOf = fail;" | 4805 "limit.valueOf = fail;" |
4796 "Error.stackTraceLimit = limit;"); | 4806 "Error.stackTraceLimit = limit;"); |
4797 CompileRun("asdf"); | 4807 CompileRun("asdf"); |
4798 CompileRun("Array.prototype.pop = fail;"); | 4808 CompileRun("Array.prototype.pop = fail;"); |
4799 CompileRun("Object.prototype.hasOwnProperty = fail;"); | 4809 CompileRun("Object.prototype.hasOwnProperty = fail;"); |
4800 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); | 4810 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4902 | 4912 |
4903 static void receive_message(v8::Handle<v8::Message> message, | 4913 static void receive_message(v8::Handle<v8::Message> message, |
4904 v8::Handle<v8::Value> data) { | 4914 v8::Handle<v8::Value> data) { |
4905 message->Get(); | 4915 message->Get(); |
4906 message_received = true; | 4916 message_received = true; |
4907 } | 4917 } |
4908 | 4918 |
4909 | 4919 |
4910 TEST(APIThrowMessage) { | 4920 TEST(APIThrowMessage) { |
4911 message_received = false; | 4921 message_received = false; |
4912 v8::HandleScope scope(CcTest::isolate()); | 4922 v8::Isolate* isolate = CcTest::isolate(); |
| 4923 v8::HandleScope scope(isolate); |
4913 v8::V8::AddMessageListener(receive_message); | 4924 v8::V8::AddMessageListener(receive_message); |
4914 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4925 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4915 templ->Set(v8_str("ThrowFromC"), | 4926 templ->Set(v8_str("ThrowFromC"), |
4916 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); | 4927 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4917 LocalContext context(0, templ); | 4928 LocalContext context(0, templ); |
4918 CompileRun("ThrowFromC();"); | 4929 CompileRun("ThrowFromC();"); |
4919 CHECK(message_received); | 4930 CHECK(message_received); |
4920 v8::V8::RemoveMessageListeners(receive_message); | 4931 v8::V8::RemoveMessageListeners(receive_message); |
4921 } | 4932 } |
4922 | 4933 |
4923 | 4934 |
4924 TEST(APIThrowMessageAndVerboseTryCatch) { | 4935 TEST(APIThrowMessageAndVerboseTryCatch) { |
4925 message_received = false; | 4936 message_received = false; |
4926 v8::HandleScope scope(CcTest::isolate()); | 4937 v8::Isolate* isolate = CcTest::isolate(); |
| 4938 v8::HandleScope scope(isolate); |
4927 v8::V8::AddMessageListener(receive_message); | 4939 v8::V8::AddMessageListener(receive_message); |
4928 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4940 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4929 templ->Set(v8_str("ThrowFromC"), | 4941 templ->Set(v8_str("ThrowFromC"), |
4930 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); | 4942 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4931 LocalContext context(0, templ); | 4943 LocalContext context(0, templ); |
4932 v8::TryCatch try_catch; | 4944 v8::TryCatch try_catch; |
4933 try_catch.SetVerbose(true); | 4945 try_catch.SetVerbose(true); |
4934 Local<Value> result = CompileRun("ThrowFromC();"); | 4946 Local<Value> result = CompileRun("ThrowFromC();"); |
4935 CHECK(try_catch.HasCaught()); | 4947 CHECK(try_catch.HasCaught()); |
4936 CHECK(result.IsEmpty()); | 4948 CHECK(result.IsEmpty()); |
4937 CHECK(message_received); | 4949 CHECK(message_received); |
4938 v8::V8::RemoveMessageListeners(receive_message); | 4950 v8::V8::RemoveMessageListeners(receive_message); |
4939 } | 4951 } |
4940 | 4952 |
4941 | 4953 |
4942 TEST(APIStackOverflowAndVerboseTryCatch) { | 4954 TEST(APIStackOverflowAndVerboseTryCatch) { |
4943 message_received = false; | 4955 message_received = false; |
4944 LocalContext context; | 4956 LocalContext context; |
4945 v8::HandleScope scope(context->GetIsolate()); | 4957 v8::HandleScope scope(context->GetIsolate()); |
4946 v8::V8::AddMessageListener(receive_message); | 4958 v8::V8::AddMessageListener(receive_message); |
4947 v8::TryCatch try_catch; | 4959 v8::TryCatch try_catch; |
4948 try_catch.SetVerbose(true); | 4960 try_catch.SetVerbose(true); |
4949 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); | 4961 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); |
4950 CHECK(try_catch.HasCaught()); | 4962 CHECK(try_catch.HasCaught()); |
4951 CHECK(result.IsEmpty()); | 4963 CHECK(result.IsEmpty()); |
4952 CHECK(message_received); | 4964 CHECK(message_received); |
4953 v8::V8::RemoveMessageListeners(receive_message); | 4965 v8::V8::RemoveMessageListeners(receive_message); |
4954 } | 4966 } |
4955 | 4967 |
4956 | 4968 |
4957 THREADED_TEST(ExternalScriptException) { | 4969 THREADED_TEST(ExternalScriptException) { |
4958 v8::HandleScope scope(CcTest::isolate()); | 4970 v8::Isolate* isolate = CcTest::isolate(); |
4959 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4971 v8::HandleScope scope(isolate); |
| 4972 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4960 templ->Set(v8_str("ThrowFromC"), | 4973 templ->Set(v8_str("ThrowFromC"), |
4961 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC)); | 4974 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4962 LocalContext context(0, templ); | 4975 LocalContext context(0, templ); |
4963 | 4976 |
4964 v8::TryCatch try_catch; | 4977 v8::TryCatch try_catch; |
4965 Local<Script> script | 4978 Local<Script> script |
4966 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); | 4979 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); |
4967 Local<Value> result = script->Run(); | 4980 Local<Value> result = script->Run(); |
4968 CHECK(result.IsEmpty()); | 4981 CHECK(result.IsEmpty()); |
4969 CHECK(try_catch.HasCaught()); | 4982 CHECK(try_catch.HasCaught()); |
4970 String::Utf8Value exception_value(try_catch.Exception()); | 4983 String::Utf8Value exception_value(try_catch.Exception()); |
4971 CHECK_EQ("konto", *exception_value); | 4984 CHECK_EQ("konto", *exception_value); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5055 // level. Stars identify activations with exception handlers, the @ identifies | 5068 // level. Stars identify activations with exception handlers, the @ identifies |
5056 // the exception handler that should catch the exception. | 5069 // the exception handler that should catch the exception. |
5057 // | 5070 // |
5058 // BUG(271): Some of the exception propagation does not work on the | 5071 // BUG(271): Some of the exception propagation does not work on the |
5059 // ARM simulator because the simulator separates the C++ stack and the | 5072 // ARM simulator because the simulator separates the C++ stack and the |
5060 // JS stack. This test therefore fails on the simulator. The test is | 5073 // JS stack. This test therefore fails on the simulator. The test is |
5061 // not threaded to allow the threading tests to run on the simulator. | 5074 // not threaded to allow the threading tests to run on the simulator. |
5062 TEST(ExceptionOrder) { | 5075 TEST(ExceptionOrder) { |
5063 v8::Isolate* isolate = CcTest::isolate(); | 5076 v8::Isolate* isolate = CcTest::isolate(); |
5064 v8::HandleScope scope(isolate); | 5077 v8::HandleScope scope(isolate); |
5065 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5078 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5066 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck)); | 5079 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck)); |
5067 templ->Set(v8_str("CThrowCountDown"), | 5080 templ->Set(v8_str("CThrowCountDown"), |
5068 v8::FunctionTemplate::New(isolate, CThrowCountDown)); | 5081 v8::FunctionTemplate::New(isolate, CThrowCountDown)); |
5069 LocalContext context(0, templ); | 5082 LocalContext context(0, templ); |
5070 CompileRun( | 5083 CompileRun( |
5071 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" | 5084 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" |
5072 " if (count == 0) throw 'FromJS';" | 5085 " if (count == 0) throw 'FromJS';" |
5073 " if (count % jsInterval == 0) {" | 5086 " if (count % jsInterval == 0) {" |
5074 " try {" | 5087 " try {" |
5075 " var value = CThrowCountDown(count - 1," | 5088 " var value = CThrowCountDown(count - 1," |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5120 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5133 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5121 ApiTestFuzzer::Fuzz(); | 5134 ApiTestFuzzer::Fuzz(); |
5122 CHECK_EQ(1, args.Length()); | 5135 CHECK_EQ(1, args.Length()); |
5123 args.GetIsolate()->ThrowException(args[0]); | 5136 args.GetIsolate()->ThrowException(args[0]); |
5124 } | 5137 } |
5125 | 5138 |
5126 | 5139 |
5127 THREADED_TEST(ThrowValues) { | 5140 THREADED_TEST(ThrowValues) { |
5128 v8::Isolate* isolate = CcTest::isolate(); | 5141 v8::Isolate* isolate = CcTest::isolate(); |
5129 v8::HandleScope scope(isolate); | 5142 v8::HandleScope scope(isolate); |
5130 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5143 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5131 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); | 5144 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); |
5132 LocalContext context(0, templ); | 5145 LocalContext context(0, templ); |
5133 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 5146 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
5134 "function Run(obj) {" | 5147 "function Run(obj) {" |
5135 " try {" | 5148 " try {" |
5136 " Throw(obj);" | 5149 " Throw(obj);" |
5137 " } catch (e) {" | 5150 " } catch (e) {" |
5138 " return e;" | 5151 " return e;" |
5139 " }" | 5152 " }" |
5140 " return 'no exception';" | 5153 " return 'no exception';" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5262 // This test ensures that an outer TryCatch in the following situation: | 5275 // This test ensures that an outer TryCatch in the following situation: |
5263 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError | 5276 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError |
5264 // does not clobber the Message object generated for the inner TryCatch. | 5277 // does not clobber the Message object generated for the inner TryCatch. |
5265 // This exercises the ability of TryCatch.ReThrow() to restore the | 5278 // This exercises the ability of TryCatch.ReThrow() to restore the |
5266 // inner pending Message before throwing the exception again. | 5279 // inner pending Message before throwing the exception again. |
5267 TEST(TryCatchMixedNesting) { | 5280 TEST(TryCatchMixedNesting) { |
5268 v8::Isolate* isolate = CcTest::isolate(); | 5281 v8::Isolate* isolate = CcTest::isolate(); |
5269 v8::HandleScope scope(isolate); | 5282 v8::HandleScope scope(isolate); |
5270 v8::V8::Initialize(); | 5283 v8::V8::Initialize(); |
5271 v8::TryCatch try_catch; | 5284 v8::TryCatch try_catch; |
5272 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5285 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5273 templ->Set(v8_str("TryCatchMixedNestingHelper"), | 5286 templ->Set(v8_str("TryCatchMixedNestingHelper"), |
5274 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); | 5287 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); |
5275 LocalContext context(0, templ); | 5288 LocalContext context(0, templ); |
5276 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); | 5289 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); |
5277 TryCatchMixedNestingCheck(&try_catch); | 5290 TryCatchMixedNestingCheck(&try_catch); |
5278 } | 5291 } |
5279 | 5292 |
5280 | 5293 |
5281 THREADED_TEST(Equality) { | 5294 THREADED_TEST(Equality) { |
5282 LocalContext context; | 5295 LocalContext context; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5334 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5347 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5335 ApiTestFuzzer::Fuzz(); | 5348 ApiTestFuzzer::Fuzz(); |
5336 CHECK_EQ(info.Data(), v8_str("donut")); | 5349 CHECK_EQ(info.Data(), v8_str("donut")); |
5337 CHECK_EQ(name, v8_str("x")); | 5350 CHECK_EQ(name, v8_str("x")); |
5338 info.GetReturnValue().Set(name); | 5351 info.GetReturnValue().Set(name); |
5339 } | 5352 } |
5340 | 5353 |
5341 | 5354 |
5342 THREADED_TEST(SimplePropertyRead) { | 5355 THREADED_TEST(SimplePropertyRead) { |
5343 LocalContext context; | 5356 LocalContext context; |
5344 v8::HandleScope scope(context->GetIsolate()); | 5357 v8::Isolate* isolate = context->GetIsolate(); |
5345 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5358 v8::HandleScope scope(isolate); |
| 5359 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5346 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5360 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5347 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5361 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5348 Local<Script> script = Script::Compile(v8_str("obj.x")); | 5362 Local<Script> script = Script::Compile(v8_str("obj.x")); |
5349 for (int i = 0; i < 10; i++) { | 5363 for (int i = 0; i < 10; i++) { |
5350 Local<Value> result = script->Run(); | 5364 Local<Value> result = script->Run(); |
5351 CHECK_EQ(result, v8_str("x")); | 5365 CHECK_EQ(result, v8_str("x")); |
5352 } | 5366 } |
5353 } | 5367 } |
5354 | 5368 |
5355 | 5369 |
5356 THREADED_TEST(DefinePropertyOnAPIAccessor) { | 5370 THREADED_TEST(DefinePropertyOnAPIAccessor) { |
5357 LocalContext context; | 5371 LocalContext context; |
5358 v8::HandleScope scope(context->GetIsolate()); | 5372 v8::Isolate* isolate = context->GetIsolate(); |
5359 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5373 v8::HandleScope scope(isolate); |
| 5374 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5360 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5375 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5361 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5376 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5362 | 5377 |
5363 // Uses getOwnPropertyDescriptor to check the configurable status | 5378 // Uses getOwnPropertyDescriptor to check the configurable status |
5364 Local<Script> script_desc | 5379 Local<Script> script_desc |
5365 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " | 5380 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " |
5366 "obj, 'x');" | 5381 "obj, 'x');" |
5367 "prop.configurable;")); | 5382 "prop.configurable;")); |
5368 Local<Value> result = script_desc->Run(); | 5383 Local<Value> result = script_desc->Run(); |
5369 CHECK_EQ(result->BooleanValue(), true); | 5384 CHECK_EQ(result->BooleanValue(), true); |
(...skipping 25 matching lines...) Expand all Loading... |
5395 // Make sure that it is not possible to redefine again | 5410 // Make sure that it is not possible to redefine again |
5396 v8::TryCatch try_catch; | 5411 v8::TryCatch try_catch; |
5397 result = script_define->Run(); | 5412 result = script_define->Run(); |
5398 CHECK(try_catch.HasCaught()); | 5413 CHECK(try_catch.HasCaught()); |
5399 String::Utf8Value exception_value(try_catch.Exception()); | 5414 String::Utf8Value exception_value(try_catch.Exception()); |
5400 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); | 5415 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); |
5401 } | 5416 } |
5402 | 5417 |
5403 | 5418 |
5404 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { | 5419 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { |
5405 v8::HandleScope scope(CcTest::isolate()); | 5420 v8::Isolate* isolate = CcTest::isolate(); |
5406 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5421 v8::HandleScope scope(isolate); |
| 5422 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5407 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 5423 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5408 LocalContext context; | 5424 LocalContext context; |
5409 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5425 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5410 | 5426 |
5411 Local<Script> script_desc = Script::Compile(v8_str("var prop =" | 5427 Local<Script> script_desc = Script::Compile(v8_str("var prop =" |
5412 "Object.getOwnPropertyDescriptor( " | 5428 "Object.getOwnPropertyDescriptor( " |
5413 "obj, 'x');" | 5429 "obj, 'x');" |
5414 "prop.configurable;")); | 5430 "prop.configurable;")); |
5415 Local<Value> result = script_desc->Run(); | 5431 Local<Value> result = script_desc->Run(); |
5416 CHECK_EQ(result->BooleanValue(), true); | 5432 CHECK_EQ(result->BooleanValue(), true); |
(...skipping 30 matching lines...) Expand all Loading... |
5447 } | 5463 } |
5448 | 5464 |
5449 | 5465 |
5450 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, | 5466 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, |
5451 char const* name) { | 5467 char const* name) { |
5452 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); | 5468 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); |
5453 } | 5469 } |
5454 | 5470 |
5455 | 5471 |
5456 THREADED_TEST(DefineAPIAccessorOnObject) { | 5472 THREADED_TEST(DefineAPIAccessorOnObject) { |
5457 v8::HandleScope scope(CcTest::isolate()); | 5473 v8::Isolate* isolate = CcTest::isolate(); |
5458 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5474 v8::HandleScope scope(isolate); |
| 5475 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5459 LocalContext context; | 5476 LocalContext context; |
5460 | 5477 |
5461 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 5478 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); |
5462 CompileRun("var obj2 = {};"); | 5479 CompileRun("var obj2 = {};"); |
5463 | 5480 |
5464 CHECK(CompileRun("obj1.x")->IsUndefined()); | 5481 CHECK(CompileRun("obj1.x")->IsUndefined()); |
5465 CHECK(CompileRun("obj2.x")->IsUndefined()); | 5482 CHECK(CompileRun("obj2.x")->IsUndefined()); |
5466 | 5483 |
5467 CHECK(GetGlobalProperty(&context, "obj1")-> | 5484 CHECK(GetGlobalProperty(&context, "obj1")-> |
5468 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 5485 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5521 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 5538 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); |
5522 CHECK(!GetGlobalProperty(&context, "obj2")-> | 5539 CHECK(!GetGlobalProperty(&context, "obj2")-> |
5523 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 5540 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); |
5524 | 5541 |
5525 ExpectString("obj1.x", "z"); | 5542 ExpectString("obj1.x", "z"); |
5526 ExpectString("obj2.x", "z"); | 5543 ExpectString("obj2.x", "z"); |
5527 } | 5544 } |
5528 | 5545 |
5529 | 5546 |
5530 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { | 5547 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { |
5531 v8::HandleScope scope(CcTest::isolate()); | 5548 v8::Isolate* isolate = CcTest::isolate(); |
5532 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5549 v8::HandleScope scope(isolate); |
| 5550 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5533 LocalContext context; | 5551 LocalContext context; |
5534 | 5552 |
5535 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 5553 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); |
5536 CompileRun("var obj2 = {};"); | 5554 CompileRun("var obj2 = {};"); |
5537 | 5555 |
5538 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( | 5556 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( |
5539 v8_str("x"), | 5557 v8_str("x"), |
5540 GetXValue, NULL, | 5558 GetXValue, NULL, |
5541 v8_str("donut"), v8::DEFAULT, v8::DontDelete)); | 5559 v8_str("donut"), v8::DEFAULT, v8::DontDelete)); |
5542 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( | 5560 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5577 static void Get239Value(Local<String> name, | 5595 static void Get239Value(Local<String> name, |
5578 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5596 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5579 ApiTestFuzzer::Fuzz(); | 5597 ApiTestFuzzer::Fuzz(); |
5580 CHECK_EQ(info.Data(), v8_str("donut")); | 5598 CHECK_EQ(info.Data(), v8_str("donut")); |
5581 CHECK_EQ(name, v8_str("239")); | 5599 CHECK_EQ(name, v8_str("239")); |
5582 info.GetReturnValue().Set(name); | 5600 info.GetReturnValue().Set(name); |
5583 } | 5601 } |
5584 | 5602 |
5585 | 5603 |
5586 THREADED_TEST(ElementAPIAccessor) { | 5604 THREADED_TEST(ElementAPIAccessor) { |
5587 v8::HandleScope scope(CcTest::isolate()); | 5605 v8::Isolate* isolate = CcTest::isolate(); |
5588 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5606 v8::HandleScope scope(isolate); |
| 5607 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5589 LocalContext context; | 5608 LocalContext context; |
5590 | 5609 |
5591 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 5610 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); |
5592 CompileRun("var obj2 = {};"); | 5611 CompileRun("var obj2 = {};"); |
5593 | 5612 |
5594 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( | 5613 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( |
5595 v8_str("239"), | 5614 v8_str("239"), |
5596 Get239Value, NULL, | 5615 Get239Value, NULL, |
5597 v8_str("donut"))); | 5616 v8_str("donut"))); |
5598 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( | 5617 CHECK(GetGlobalProperty(&context, "obj2")->SetAccessor( |
(...skipping 16 matching lines...) Expand all Loading... |
5615 const v8::PropertyCallbackInfo<void>& info) { | 5634 const v8::PropertyCallbackInfo<void>& info) { |
5616 CHECK_EQ(value, v8_num(4)); | 5635 CHECK_EQ(value, v8_num(4)); |
5617 CHECK_EQ(info.Data(), v8_str("donut")); | 5636 CHECK_EQ(info.Data(), v8_str("donut")); |
5618 CHECK_EQ(name, v8_str("x")); | 5637 CHECK_EQ(name, v8_str("x")); |
5619 CHECK(xValue.IsEmpty()); | 5638 CHECK(xValue.IsEmpty()); |
5620 xValue.Reset(info.GetIsolate(), value); | 5639 xValue.Reset(info.GetIsolate(), value); |
5621 } | 5640 } |
5622 | 5641 |
5623 | 5642 |
5624 THREADED_TEST(SimplePropertyWrite) { | 5643 THREADED_TEST(SimplePropertyWrite) { |
5625 v8::HandleScope scope(CcTest::isolate()); | 5644 v8::Isolate* isolate = CcTest::isolate(); |
5626 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5645 v8::HandleScope scope(isolate); |
| 5646 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5627 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 5647 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
5628 LocalContext context; | 5648 LocalContext context; |
5629 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5649 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5630 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 5650 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); |
5631 for (int i = 0; i < 10; i++) { | 5651 for (int i = 0; i < 10; i++) { |
5632 CHECK(xValue.IsEmpty()); | 5652 CHECK(xValue.IsEmpty()); |
5633 script->Run(); | 5653 script->Run(); |
5634 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); | 5654 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); |
5635 xValue.Reset(); | 5655 xValue.Reset(); |
5636 } | 5656 } |
5637 } | 5657 } |
5638 | 5658 |
5639 | 5659 |
5640 THREADED_TEST(SetterOnly) { | 5660 THREADED_TEST(SetterOnly) { |
5641 v8::HandleScope scope(CcTest::isolate()); | 5661 v8::Isolate* isolate = CcTest::isolate(); |
5642 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5662 v8::HandleScope scope(isolate); |
| 5663 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5643 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 5664 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
5644 LocalContext context; | 5665 LocalContext context; |
5645 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5666 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5646 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 5667 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
5647 for (int i = 0; i < 10; i++) { | 5668 for (int i = 0; i < 10; i++) { |
5648 CHECK(xValue.IsEmpty()); | 5669 CHECK(xValue.IsEmpty()); |
5649 script->Run(); | 5670 script->Run(); |
5650 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); | 5671 CHECK_EQ(v8_num(4), Local<Value>::New(CcTest::isolate(), xValue)); |
5651 xValue.Reset(); | 5672 xValue.Reset(); |
5652 } | 5673 } |
5653 } | 5674 } |
5654 | 5675 |
5655 | 5676 |
5656 THREADED_TEST(NoAccessors) { | 5677 THREADED_TEST(NoAccessors) { |
5657 v8::HandleScope scope(CcTest::isolate()); | 5678 v8::Isolate* isolate = CcTest::isolate(); |
5658 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5679 v8::HandleScope scope(isolate); |
| 5680 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5659 templ->SetAccessor(v8_str("x"), | 5681 templ->SetAccessor(v8_str("x"), |
5660 static_cast<v8::AccessorGetterCallback>(NULL), | 5682 static_cast<v8::AccessorGetterCallback>(NULL), |
5661 NULL, | 5683 NULL, |
5662 v8_str("donut")); | 5684 v8_str("donut")); |
5663 LocalContext context; | 5685 LocalContext context; |
5664 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5686 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5665 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 5687 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
5666 for (int i = 0; i < 10; i++) { | 5688 for (int i = 0; i < 10; i++) { |
5667 script->Run(); | 5689 script->Run(); |
5668 } | 5690 } |
5669 } | 5691 } |
5670 | 5692 |
5671 | 5693 |
5672 static void XPropertyGetter(Local<String> property, | 5694 static void XPropertyGetter(Local<String> property, |
5673 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5695 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5674 ApiTestFuzzer::Fuzz(); | 5696 ApiTestFuzzer::Fuzz(); |
5675 CHECK(info.Data()->IsUndefined()); | 5697 CHECK(info.Data()->IsUndefined()); |
5676 info.GetReturnValue().Set(property); | 5698 info.GetReturnValue().Set(property); |
5677 } | 5699 } |
5678 | 5700 |
5679 | 5701 |
5680 THREADED_TEST(NamedInterceptorPropertyRead) { | 5702 THREADED_TEST(NamedInterceptorPropertyRead) { |
5681 v8::HandleScope scope(CcTest::isolate()); | 5703 v8::Isolate* isolate = CcTest::isolate(); |
5682 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5704 v8::HandleScope scope(isolate); |
| 5705 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5683 templ->SetNamedPropertyHandler(XPropertyGetter); | 5706 templ->SetNamedPropertyHandler(XPropertyGetter); |
5684 LocalContext context; | 5707 LocalContext context; |
5685 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5708 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5686 Local<Script> script = Script::Compile(v8_str("obj.x")); | 5709 Local<Script> script = Script::Compile(v8_str("obj.x")); |
5687 for (int i = 0; i < 10; i++) { | 5710 for (int i = 0; i < 10; i++) { |
5688 Local<Value> result = script->Run(); | 5711 Local<Value> result = script->Run(); |
5689 CHECK_EQ(result, v8_str("x")); | 5712 CHECK_EQ(result, v8_str("x")); |
5690 } | 5713 } |
5691 } | 5714 } |
5692 | 5715 |
5693 | 5716 |
5694 THREADED_TEST(NamedInterceptorDictionaryIC) { | 5717 THREADED_TEST(NamedInterceptorDictionaryIC) { |
5695 v8::HandleScope scope(CcTest::isolate()); | 5718 v8::Isolate* isolate = CcTest::isolate(); |
5696 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5719 v8::HandleScope scope(isolate); |
| 5720 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5697 templ->SetNamedPropertyHandler(XPropertyGetter); | 5721 templ->SetNamedPropertyHandler(XPropertyGetter); |
5698 LocalContext context; | 5722 LocalContext context; |
5699 // Create an object with a named interceptor. | 5723 // Create an object with a named interceptor. |
5700 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); | 5724 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); |
5701 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); | 5725 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); |
5702 for (int i = 0; i < 10; i++) { | 5726 for (int i = 0; i < 10; i++) { |
5703 Local<Value> result = script->Run(); | 5727 Local<Value> result = script->Run(); |
5704 CHECK_EQ(result, v8_str("x")); | 5728 CHECK_EQ(result, v8_str("x")); |
5705 } | 5729 } |
5706 // Create a slow case object and a function accessing a property in | 5730 // Create a slow case object and a function accessing a property in |
(...skipping 13 matching lines...) Expand all Loading... |
5720 CHECK_EQ(result, v8_str("x")); | 5744 CHECK_EQ(result, v8_str("x")); |
5721 } | 5745 } |
5722 | 5746 |
5723 | 5747 |
5724 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { | 5748 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { |
5725 v8::Isolate* isolate = CcTest::isolate(); | 5749 v8::Isolate* isolate = CcTest::isolate(); |
5726 v8::HandleScope scope(isolate); | 5750 v8::HandleScope scope(isolate); |
5727 v8::Local<Context> context1 = Context::New(isolate); | 5751 v8::Local<Context> context1 = Context::New(isolate); |
5728 | 5752 |
5729 context1->Enter(); | 5753 context1->Enter(); |
5730 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5754 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5731 templ->SetNamedPropertyHandler(XPropertyGetter); | 5755 templ->SetNamedPropertyHandler(XPropertyGetter); |
5732 // Create an object with a named interceptor. | 5756 // Create an object with a named interceptor. |
5733 v8::Local<v8::Object> object = templ->NewInstance(); | 5757 v8::Local<v8::Object> object = templ->NewInstance(); |
5734 context1->Global()->Set(v8_str("interceptor_obj"), object); | 5758 context1->Global()->Set(v8_str("interceptor_obj"), object); |
5735 | 5759 |
5736 // Force the object into the slow case. | 5760 // Force the object into the slow case. |
5737 CompileRun("interceptor_obj.y = 0;" | 5761 CompileRun("interceptor_obj.y = 0;" |
5738 "delete interceptor_obj.y;"); | 5762 "delete interceptor_obj.y;"); |
5739 context1->Exit(); | 5763 context1->Exit(); |
5740 | 5764 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5807 Local<Value> value, | 5831 Local<Value> value, |
5808 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5832 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5809 ApiTestFuzzer::Fuzz(); | 5833 ApiTestFuzzer::Fuzz(); |
5810 if (index == 39) { | 5834 if (index == 39) { |
5811 info.GetReturnValue().Set(value); | 5835 info.GetReturnValue().Set(value); |
5812 } | 5836 } |
5813 } | 5837 } |
5814 | 5838 |
5815 | 5839 |
5816 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { | 5840 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { |
5817 v8::HandleScope scope(CcTest::isolate()); | 5841 v8::Isolate* isolate = CcTest::isolate(); |
5818 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5842 v8::HandleScope scope(isolate); |
| 5843 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5819 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, | 5844 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, |
5820 IndexedPropertySetter); | 5845 IndexedPropertySetter); |
5821 LocalContext context; | 5846 LocalContext context; |
5822 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5847 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5823 Local<Script> getter_script = Script::Compile(v8_str( | 5848 Local<Script> getter_script = Script::Compile(v8_str( |
5824 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); | 5849 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); |
5825 Local<Script> setter_script = Script::Compile(v8_str( | 5850 Local<Script> setter_script = Script::Compile(v8_str( |
5826 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" | 5851 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" |
5827 "obj[17] = 23;" | 5852 "obj[17] = 23;" |
5828 "obj.foo;")); | 5853 "obj.foo;")); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5872 "for(i = 0; i < 80000; i++) { keys[i] = i; };" | 5897 "for(i = 0; i < 80000; i++) { keys[i] = i; };" |
5873 "keys.length = 25; keys;")); | 5898 "keys.length = 25; keys;")); |
5874 Local<Value> result = indexed_property_names_script->Run(); | 5899 Local<Value> result = indexed_property_names_script->Run(); |
5875 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); | 5900 info.GetReturnValue().Set(Local<v8::Array>::Cast(result)); |
5876 } | 5901 } |
5877 | 5902 |
5878 | 5903 |
5879 // Make sure that the the interceptor code in the runtime properly handles | 5904 // Make sure that the the interceptor code in the runtime properly handles |
5880 // merging property name lists for double-array-backed arrays. | 5905 // merging property name lists for double-array-backed arrays. |
5881 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { | 5906 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { |
5882 v8::HandleScope scope(CcTest::isolate()); | 5907 v8::Isolate* isolate = CcTest::isolate(); |
5883 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5908 v8::HandleScope scope(isolate); |
| 5909 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5884 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, | 5910 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, |
5885 UnboxedDoubleIndexedPropertySetter, | 5911 UnboxedDoubleIndexedPropertySetter, |
5886 0, | 5912 0, |
5887 0, | 5913 0, |
5888 UnboxedDoubleIndexedPropertyEnumerator); | 5914 UnboxedDoubleIndexedPropertyEnumerator); |
5889 LocalContext context; | 5915 LocalContext context; |
5890 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5916 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5891 // When obj is created, force it to be Stored in a FastDoubleArray. | 5917 // When obj is created, force it to be Stored in a FastDoubleArray. |
5892 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( | 5918 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( |
5893 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " | 5919 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } " |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5928 ApiTestFuzzer::Fuzz(); | 5954 ApiTestFuzzer::Fuzz(); |
5929 if (index < 4) { | 5955 if (index < 4) { |
5930 info.GetReturnValue().Set(v8_num(index)); | 5956 info.GetReturnValue().Set(v8_num(index)); |
5931 } | 5957 } |
5932 } | 5958 } |
5933 | 5959 |
5934 | 5960 |
5935 // Make sure that the the interceptor code in the runtime properly handles | 5961 // Make sure that the the interceptor code in the runtime properly handles |
5936 // merging property name lists for non-string arguments arrays. | 5962 // merging property name lists for non-string arguments arrays. |
5937 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { | 5963 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { |
5938 v8::HandleScope scope(CcTest::isolate()); | 5964 v8::Isolate* isolate = CcTest::isolate(); |
5939 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5965 v8::HandleScope scope(isolate); |
| 5966 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5940 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, | 5967 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, |
5941 0, | 5968 0, |
5942 0, | 5969 0, |
5943 0, | 5970 0, |
5944 NonStrictArgsIndexedPropertyEnumerator); | 5971 NonStrictArgsIndexedPropertyEnumerator); |
5945 LocalContext context; | 5972 LocalContext context; |
5946 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5973 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5947 Local<Script> create_args_script = | 5974 Local<Script> create_args_script = |
5948 Script::Compile(v8_str( | 5975 Script::Compile(v8_str( |
5949 "var key_count = 0;" | 5976 "var key_count = 0;" |
5950 "for (x in obj) {key_count++;} key_count;")); | 5977 "for (x in obj) {key_count++;} key_count;")); |
5951 Local<Value> result = create_args_script->Run(); | 5978 Local<Value> result = create_args_script->Run(); |
5952 CHECK_EQ(v8_num(4), result); | 5979 CHECK_EQ(v8_num(4), result); |
5953 } | 5980 } |
5954 | 5981 |
5955 | 5982 |
5956 static void IdentityIndexedPropertyGetter( | 5983 static void IdentityIndexedPropertyGetter( |
5957 uint32_t index, | 5984 uint32_t index, |
5958 const v8::PropertyCallbackInfo<v8::Value>& info) { | 5985 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5959 info.GetReturnValue().Set(index); | 5986 info.GetReturnValue().Set(index); |
5960 } | 5987 } |
5961 | 5988 |
5962 | 5989 |
5963 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { | 5990 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { |
5964 v8::HandleScope scope(CcTest::isolate()); | 5991 v8::Isolate* isolate = CcTest::isolate(); |
5965 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5992 v8::HandleScope scope(isolate); |
| 5993 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5966 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 5994 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
5967 | 5995 |
5968 LocalContext context; | 5996 LocalContext context; |
5969 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 5997 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5970 | 5998 |
5971 // Check fast object case. | 5999 // Check fast object case. |
5972 const char* fast_case_code = | 6000 const char* fast_case_code = |
5973 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()"; | 6001 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()"; |
5974 ExpectString(fast_case_code, "0"); | 6002 ExpectString(fast_case_code, "0"); |
5975 | 6003 |
5976 // Check slow case. | 6004 // Check slow case. |
5977 const char* slow_case_code = | 6005 const char* slow_case_code = |
5978 "obj.x = 1; delete obj.x;" | 6006 "obj.x = 1; delete obj.x;" |
5979 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()"; | 6007 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()"; |
5980 ExpectString(slow_case_code, "1"); | 6008 ExpectString(slow_case_code, "1"); |
5981 } | 6009 } |
5982 | 6010 |
5983 | 6011 |
5984 THREADED_TEST(IndexedInterceptorWithNoSetter) { | 6012 THREADED_TEST(IndexedInterceptorWithNoSetter) { |
5985 v8::HandleScope scope(CcTest::isolate()); | 6013 v8::Isolate* isolate = CcTest::isolate(); |
5986 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6014 v8::HandleScope scope(isolate); |
| 6015 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5987 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6016 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
5988 | 6017 |
5989 LocalContext context; | 6018 LocalContext context; |
5990 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6019 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
5991 | 6020 |
5992 const char* code = | 6021 const char* code = |
5993 "try {" | 6022 "try {" |
5994 " obj[0] = 239;" | 6023 " obj[0] = 239;" |
5995 " for (var i = 0; i < 100; i++) {" | 6024 " for (var i = 0; i < 100; i++) {" |
5996 " var v = obj[0];" | 6025 " var v = obj[0];" |
5997 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6026 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" |
5998 " }" | 6027 " }" |
5999 " 'PASSED'" | 6028 " 'PASSED'" |
6000 "} catch(e) {" | 6029 "} catch(e) {" |
6001 " e" | 6030 " e" |
6002 "}"; | 6031 "}"; |
6003 ExpectString(code, "PASSED"); | 6032 ExpectString(code, "PASSED"); |
6004 } | 6033 } |
6005 | 6034 |
6006 | 6035 |
6007 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { | 6036 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { |
6008 v8::HandleScope scope(CcTest::isolate()); | 6037 v8::Isolate* isolate = CcTest::isolate(); |
6009 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6038 v8::HandleScope scope(isolate); |
| 6039 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6010 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6040 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6011 | 6041 |
6012 LocalContext context; | 6042 LocalContext context; |
6013 Local<v8::Object> obj = templ->NewInstance(); | 6043 Local<v8::Object> obj = templ->NewInstance(); |
6014 obj->TurnOnAccessCheck(); | 6044 obj->TurnOnAccessCheck(); |
6015 context->Global()->Set(v8_str("obj"), obj); | 6045 context->Global()->Set(v8_str("obj"), obj); |
6016 | 6046 |
6017 const char* code = | 6047 const char* code = |
6018 "try {" | 6048 "try {" |
6019 " for (var i = 0; i < 100; i++) {" | 6049 " for (var i = 0; i < 100; i++) {" |
6020 " var v = obj[0];" | 6050 " var v = obj[0];" |
6021 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6051 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6022 " }" | 6052 " }" |
6023 " 'PASSED'" | 6053 " 'PASSED'" |
6024 "} catch(e) {" | 6054 "} catch(e) {" |
6025 " e" | 6055 " e" |
6026 "}"; | 6056 "}"; |
6027 ExpectString(code, "PASSED"); | 6057 ExpectString(code, "PASSED"); |
6028 } | 6058 } |
6029 | 6059 |
6030 | 6060 |
6031 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { | 6061 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { |
6032 i::FLAG_allow_natives_syntax = true; | 6062 i::FLAG_allow_natives_syntax = true; |
6033 v8::HandleScope scope(CcTest::isolate()); | 6063 v8::Isolate* isolate = CcTest::isolate(); |
6034 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6064 v8::HandleScope scope(isolate); |
| 6065 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6035 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6066 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6036 | 6067 |
6037 LocalContext context; | 6068 LocalContext context; |
6038 Local<v8::Object> obj = templ->NewInstance(); | 6069 Local<v8::Object> obj = templ->NewInstance(); |
6039 context->Global()->Set(v8_str("obj"), obj); | 6070 context->Global()->Set(v8_str("obj"), obj); |
6040 | 6071 |
6041 const char* code = | 6072 const char* code = |
6042 "try {" | 6073 "try {" |
6043 " for (var i = 0; i < 100; i++) {" | 6074 " for (var i = 0; i < 100; i++) {" |
6044 " var expected = i;" | 6075 " var expected = i;" |
6045 " if (i == 5) {" | 6076 " if (i == 5) {" |
6046 " %EnableAccessChecks(obj);" | 6077 " %EnableAccessChecks(obj);" |
6047 " expected = undefined;" | 6078 " expected = undefined;" |
6048 " }" | 6079 " }" |
6049 " var v = obj[i];" | 6080 " var v = obj[i];" |
6050 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6081 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6051 " if (i == 5) %DisableAccessChecks(obj);" | 6082 " if (i == 5) %DisableAccessChecks(obj);" |
6052 " }" | 6083 " }" |
6053 " 'PASSED'" | 6084 " 'PASSED'" |
6054 "} catch(e) {" | 6085 "} catch(e) {" |
6055 " e" | 6086 " e" |
6056 "}"; | 6087 "}"; |
6057 ExpectString(code, "PASSED"); | 6088 ExpectString(code, "PASSED"); |
6058 } | 6089 } |
6059 | 6090 |
6060 | 6091 |
6061 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { | 6092 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { |
6062 v8::HandleScope scope(CcTest::isolate()); | 6093 v8::Isolate* isolate = CcTest::isolate(); |
6063 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6094 v8::HandleScope scope(isolate); |
| 6095 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6064 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6096 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6065 | 6097 |
6066 LocalContext context; | 6098 LocalContext context; |
6067 Local<v8::Object> obj = templ->NewInstance(); | 6099 Local<v8::Object> obj = templ->NewInstance(); |
6068 context->Global()->Set(v8_str("obj"), obj); | 6100 context->Global()->Set(v8_str("obj"), obj); |
6069 | 6101 |
6070 const char* code = | 6102 const char* code = |
6071 "try {" | 6103 "try {" |
6072 " for (var i = 0; i < 100; i++) {" | 6104 " for (var i = 0; i < 100; i++) {" |
6073 " var v = obj[i];" | 6105 " var v = obj[i];" |
6074 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6106 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6075 " }" | 6107 " }" |
6076 " 'PASSED'" | 6108 " 'PASSED'" |
6077 "} catch(e) {" | 6109 "} catch(e) {" |
6078 " e" | 6110 " e" |
6079 "}"; | 6111 "}"; |
6080 ExpectString(code, "PASSED"); | 6112 ExpectString(code, "PASSED"); |
6081 } | 6113 } |
6082 | 6114 |
6083 | 6115 |
6084 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { | 6116 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { |
6085 v8::HandleScope scope(CcTest::isolate()); | 6117 v8::Isolate* isolate = CcTest::isolate(); |
6086 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6118 v8::HandleScope scope(isolate); |
| 6119 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6087 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6120 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6088 | 6121 |
6089 LocalContext context; | 6122 LocalContext context; |
6090 Local<v8::Object> obj = templ->NewInstance(); | 6123 Local<v8::Object> obj = templ->NewInstance(); |
6091 context->Global()->Set(v8_str("obj"), obj); | 6124 context->Global()->Set(v8_str("obj"), obj); |
6092 | 6125 |
6093 const char* code = | 6126 const char* code = |
6094 "try {" | 6127 "try {" |
6095 " for (var i = 0; i < 100; i++) {" | 6128 " for (var i = 0; i < 100; i++) {" |
6096 " var expected = i;" | 6129 " var expected = i;" |
(...skipping 17 matching lines...) Expand all Loading... |
6114 " }" | 6147 " }" |
6115 " 'PASSED'" | 6148 " 'PASSED'" |
6116 "} catch(e) {" | 6149 "} catch(e) {" |
6117 " e" | 6150 " e" |
6118 "}"; | 6151 "}"; |
6119 ExpectString(code, "PASSED"); | 6152 ExpectString(code, "PASSED"); |
6120 } | 6153 } |
6121 | 6154 |
6122 | 6155 |
6123 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { | 6156 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { |
6124 v8::HandleScope scope(CcTest::isolate()); | 6157 v8::Isolate* isolate = CcTest::isolate(); |
6125 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6158 v8::HandleScope scope(isolate); |
| 6159 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6126 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6160 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6127 | 6161 |
6128 LocalContext context; | 6162 LocalContext context; |
6129 Local<v8::Object> obj = templ->NewInstance(); | 6163 Local<v8::Object> obj = templ->NewInstance(); |
6130 context->Global()->Set(v8_str("obj"), obj); | 6164 context->Global()->Set(v8_str("obj"), obj); |
6131 | 6165 |
6132 const char* code = | 6166 const char* code = |
6133 "try {" | 6167 "try {" |
6134 " for (var i = 0; i < 100; i++) {" | 6168 " for (var i = 0; i < 100; i++) {" |
6135 " var expected = i;" | 6169 " var expected = i;" |
6136 " var key = i;" | 6170 " var key = i;" |
6137 " if (i == 50) {" | 6171 " if (i == 50) {" |
6138 " key = 'foobar';" | 6172 " key = 'foobar';" |
6139 " expected = undefined;" | 6173 " expected = undefined;" |
6140 " }" | 6174 " }" |
6141 " var v = obj[key];" | 6175 " var v = obj[key];" |
6142 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6176 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6143 " }" | 6177 " }" |
6144 " 'PASSED'" | 6178 " 'PASSED'" |
6145 "} catch(e) {" | 6179 "} catch(e) {" |
6146 " e" | 6180 " e" |
6147 "}"; | 6181 "}"; |
6148 ExpectString(code, "PASSED"); | 6182 ExpectString(code, "PASSED"); |
6149 } | 6183 } |
6150 | 6184 |
6151 | 6185 |
6152 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { | 6186 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { |
6153 v8::HandleScope scope(CcTest::isolate()); | 6187 v8::Isolate* isolate = CcTest::isolate(); |
6154 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6188 v8::HandleScope scope(isolate); |
| 6189 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6155 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6190 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6156 | 6191 |
6157 LocalContext context; | 6192 LocalContext context; |
6158 Local<v8::Object> obj = templ->NewInstance(); | 6193 Local<v8::Object> obj = templ->NewInstance(); |
6159 context->Global()->Set(v8_str("obj"), obj); | 6194 context->Global()->Set(v8_str("obj"), obj); |
6160 | 6195 |
6161 const char* code = | 6196 const char* code = |
6162 "var original = obj;" | 6197 "var original = obj;" |
6163 "try {" | 6198 "try {" |
6164 " for (var i = 0; i < 100; i++) {" | 6199 " for (var i = 0; i < 100; i++) {" |
6165 " var expected = i;" | 6200 " var expected = i;" |
6166 " if (i == 50) {" | 6201 " if (i == 50) {" |
6167 " obj = {50: 'foobar'};" | 6202 " obj = {50: 'foobar'};" |
6168 " expected = 'foobar';" | 6203 " expected = 'foobar';" |
6169 " }" | 6204 " }" |
6170 " var v = obj[i];" | 6205 " var v = obj[i];" |
6171 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6206 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6172 " if (i == 50) obj = original;" | 6207 " if (i == 50) obj = original;" |
6173 " }" | 6208 " }" |
6174 " 'PASSED'" | 6209 " 'PASSED'" |
6175 "} catch(e) {" | 6210 "} catch(e) {" |
6176 " e" | 6211 " e" |
6177 "}"; | 6212 "}"; |
6178 ExpectString(code, "PASSED"); | 6213 ExpectString(code, "PASSED"); |
6179 } | 6214 } |
6180 | 6215 |
6181 | 6216 |
6182 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { | 6217 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { |
6183 v8::HandleScope scope(CcTest::isolate()); | 6218 v8::Isolate* isolate = CcTest::isolate(); |
6184 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6219 v8::HandleScope scope(isolate); |
| 6220 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6185 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6221 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6186 | 6222 |
6187 LocalContext context; | 6223 LocalContext context; |
6188 Local<v8::Object> obj = templ->NewInstance(); | 6224 Local<v8::Object> obj = templ->NewInstance(); |
6189 context->Global()->Set(v8_str("obj"), obj); | 6225 context->Global()->Set(v8_str("obj"), obj); |
6190 | 6226 |
6191 const char* code = | 6227 const char* code = |
6192 "var original = obj;" | 6228 "var original = obj;" |
6193 "try {" | 6229 "try {" |
6194 " for (var i = 0; i < 100; i++) {" | 6230 " for (var i = 0; i < 100; i++) {" |
6195 " var expected = i;" | 6231 " var expected = i;" |
6196 " if (i == 5) {" | 6232 " if (i == 5) {" |
6197 " obj = 239;" | 6233 " obj = 239;" |
6198 " expected = undefined;" | 6234 " expected = undefined;" |
6199 " }" | 6235 " }" |
6200 " var v = obj[i];" | 6236 " var v = obj[i];" |
6201 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6237 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6202 " if (i == 5) obj = original;" | 6238 " if (i == 5) obj = original;" |
6203 " }" | 6239 " }" |
6204 " 'PASSED'" | 6240 " 'PASSED'" |
6205 "} catch(e) {" | 6241 "} catch(e) {" |
6206 " e" | 6242 " e" |
6207 "}"; | 6243 "}"; |
6208 ExpectString(code, "PASSED"); | 6244 ExpectString(code, "PASSED"); |
6209 } | 6245 } |
6210 | 6246 |
6211 | 6247 |
6212 THREADED_TEST(IndexedInterceptorOnProto) { | 6248 THREADED_TEST(IndexedInterceptorOnProto) { |
6213 v8::HandleScope scope(CcTest::isolate()); | 6249 v8::Isolate* isolate = CcTest::isolate(); |
6214 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6250 v8::HandleScope scope(isolate); |
| 6251 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6215 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); | 6252 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); |
6216 | 6253 |
6217 LocalContext context; | 6254 LocalContext context; |
6218 Local<v8::Object> obj = templ->NewInstance(); | 6255 Local<v8::Object> obj = templ->NewInstance(); |
6219 context->Global()->Set(v8_str("obj"), obj); | 6256 context->Global()->Set(v8_str("obj"), obj); |
6220 | 6257 |
6221 const char* code = | 6258 const char* code = |
6222 "var o = {__proto__: obj};" | 6259 "var o = {__proto__: obj};" |
6223 "try {" | 6260 "try {" |
6224 " for (var i = 0; i < 100; i++) {" | 6261 " for (var i = 0; i < 100; i++) {" |
6225 " var v = o[i];" | 6262 " var v = o[i];" |
6226 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" | 6263 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" |
6227 " }" | 6264 " }" |
6228 " 'PASSED'" | 6265 " 'PASSED'" |
6229 "} catch(e) {" | 6266 "} catch(e) {" |
6230 " e" | 6267 " e" |
6231 "}"; | 6268 "}"; |
6232 ExpectString(code, "PASSED"); | 6269 ExpectString(code, "PASSED"); |
6233 } | 6270 } |
6234 | 6271 |
6235 | 6272 |
6236 THREADED_TEST(MultiContexts) { | 6273 THREADED_TEST(MultiContexts) { |
6237 v8::Isolate* isolate = CcTest::isolate(); | 6274 v8::Isolate* isolate = CcTest::isolate(); |
6238 v8::HandleScope scope(isolate); | 6275 v8::HandleScope scope(isolate); |
6239 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 6276 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6240 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate, | 6277 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate, |
6241 DummyCallHandler)); | 6278 DummyCallHandler)); |
6242 | 6279 |
6243 Local<String> password = v8_str("Password"); | 6280 Local<String> password = v8_str("Password"); |
6244 | 6281 |
6245 // Create an environment | 6282 // Create an environment |
6246 LocalContext context0(0, templ); | 6283 LocalContext context0(0, templ); |
6247 context0->SetSecurityToken(password); | 6284 context0->SetSecurityToken(password); |
6248 v8::Handle<v8::Object> global0 = context0->Global(); | 6285 v8::Handle<v8::Object> global0 = context0->Global(); |
6249 global0->Set(v8_str("custom"), v8_num(1234)); | 6286 global0->Set(v8_str("custom"), v8_num(1234)); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6524 TEST(PersistentHandles) { | 6561 TEST(PersistentHandles) { |
6525 LocalContext env; | 6562 LocalContext env; |
6526 v8::Isolate* isolate = CcTest::isolate(); | 6563 v8::Isolate* isolate = CcTest::isolate(); |
6527 v8::HandleScope scope(isolate); | 6564 v8::HandleScope scope(isolate); |
6528 Local<String> str = v8_str("foo"); | 6565 Local<String> str = v8_str("foo"); |
6529 v8::Persistent<String> p_str(isolate, str); | 6566 v8::Persistent<String> p_str(isolate, str); |
6530 p_str.Reset(); | 6567 p_str.Reset(); |
6531 Local<Script> scr = Script::Compile(v8_str("")); | 6568 Local<Script> scr = Script::Compile(v8_str("")); |
6532 v8::Persistent<Script> p_scr(isolate, scr); | 6569 v8::Persistent<Script> p_scr(isolate, scr); |
6533 p_scr.Reset(); | 6570 p_scr.Reset(); |
6534 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 6571 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
6535 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); | 6572 v8::Persistent<ObjectTemplate> p_templ(isolate, templ); |
6536 p_templ.Reset(); | 6573 p_templ.Reset(); |
6537 } | 6574 } |
6538 | 6575 |
6539 | 6576 |
6540 static void HandleLogDelegator( | 6577 static void HandleLogDelegator( |
6541 const v8::FunctionCallbackInfo<v8::Value>& args) { | 6578 const v8::FunctionCallbackInfo<v8::Value>& args) { |
6542 ApiTestFuzzer::Fuzz(); | 6579 ApiTestFuzzer::Fuzz(); |
6543 } | 6580 } |
6544 | 6581 |
6545 | 6582 |
6546 THREADED_TEST(GlobalObjectTemplate) { | 6583 THREADED_TEST(GlobalObjectTemplate) { |
6547 v8::Isolate* isolate = CcTest::isolate(); | 6584 v8::Isolate* isolate = CcTest::isolate(); |
6548 v8::HandleScope handle_scope(isolate); | 6585 v8::HandleScope handle_scope(isolate); |
6549 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 6586 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); |
6550 global_template->Set(v8_str("JSNI_Log"), | 6587 global_template->Set(v8_str("JSNI_Log"), |
6551 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); | 6588 v8::FunctionTemplate::New(isolate, HandleLogDelegator)); |
6552 v8::Local<Context> context = Context::New(isolate, 0, global_template); | 6589 v8::Local<Context> context = Context::New(isolate, 0, global_template); |
6553 Context::Scope context_scope(context); | 6590 Context::Scope context_scope(context); |
6554 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); | 6591 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); |
6555 } | 6592 } |
6556 | 6593 |
6557 | 6594 |
6558 static const char* kSimpleExtensionSource = | 6595 static const char* kSimpleExtensionSource = |
6559 "function Foo() {" | 6596 "function Foo() {" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7077 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), | 7114 prev.SetWeak<Value, Snorkel<Value> >(new Snorkel<Value>(&prev.As<Value>()), |
7078 &HandleWeakReference); | 7115 &HandleWeakReference); |
7079 } | 7116 } |
7080 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); | 7117 whammy->objects_[whammy->cursor_].Reset(info.GetIsolate(), obj); |
7081 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; | 7118 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; |
7082 info.GetReturnValue().Set(whammy->getScript()->Run()); | 7119 info.GetReturnValue().Set(whammy->getScript()->Run()); |
7083 } | 7120 } |
7084 | 7121 |
7085 | 7122 |
7086 THREADED_TEST(WeakReference) { | 7123 THREADED_TEST(WeakReference) { |
7087 v8::HandleScope handle_scope(CcTest::isolate()); | 7124 v8::Isolate* isolate = CcTest::isolate(); |
7088 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); | 7125 v8::HandleScope handle_scope(isolate); |
| 7126 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(isolate); |
7089 Whammy* whammy = new Whammy(CcTest::isolate()); | 7127 Whammy* whammy = new Whammy(CcTest::isolate()); |
7090 templ->SetNamedPropertyHandler(WhammyPropertyGetter, | 7128 templ->SetNamedPropertyHandler(WhammyPropertyGetter, |
7091 0, 0, 0, 0, | 7129 0, 0, 0, 0, |
7092 v8::External::New(CcTest::isolate(), whammy)); | 7130 v8::External::New(CcTest::isolate(), whammy)); |
7093 const char* extension_list[] = { "v8/gc" }; | 7131 const char* extension_list[] = { "v8/gc" }; |
7094 v8::ExtensionConfiguration extensions(1, extension_list); | 7132 v8::ExtensionConfiguration extensions(1, extension_list); |
7095 v8::Handle<Context> context = | 7133 v8::Handle<Context> context = |
7096 Context::New(CcTest::isolate(), &extensions); | 7134 Context::New(CcTest::isolate(), &extensions); |
7097 Context::Scope context_scope(context); | 7135 Context::Scope context_scope(context); |
7098 | 7136 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7265 CHECK_EQ(v8::Integer::New(isolate, 3), args[2]); | 7303 CHECK_EQ(v8::Integer::New(isolate, 3), args[2]); |
7266 CHECK_EQ(v8::Undefined(isolate), args[3]); | 7304 CHECK_EQ(v8::Undefined(isolate), args[3]); |
7267 v8::HandleScope scope(args.GetIsolate()); | 7305 v8::HandleScope scope(args.GetIsolate()); |
7268 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 7306 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
7269 } | 7307 } |
7270 | 7308 |
7271 | 7309 |
7272 THREADED_TEST(Arguments) { | 7310 THREADED_TEST(Arguments) { |
7273 v8::Isolate* isolate = CcTest::isolate(); | 7311 v8::Isolate* isolate = CcTest::isolate(); |
7274 v8::HandleScope scope(isolate); | 7312 v8::HandleScope scope(isolate); |
7275 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); | 7313 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
7276 global->Set(v8_str("f"), | 7314 global->Set(v8_str("f"), |
7277 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); | 7315 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); |
7278 LocalContext context(NULL, global); | 7316 LocalContext context(NULL, global); |
7279 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); | 7317 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); |
7280 v8_compile("f(1, 2, 3)")->Run(); | 7318 v8_compile("f(1, 2, 3)")->Run(); |
7281 } | 7319 } |
7282 | 7320 |
7283 | 7321 |
7284 static void NoBlockGetterX(Local<String> name, | 7322 static void NoBlockGetterX(Local<String> name, |
7285 const v8::PropertyCallbackInfo<v8::Value>&) { | 7323 const v8::PropertyCallbackInfo<v8::Value>&) { |
(...skipping 19 matching lines...) Expand all Loading... |
7305 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 7343 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
7306 if (index != 2) { | 7344 if (index != 2) { |
7307 return; // not intercepted | 7345 return; // not intercepted |
7308 } | 7346 } |
7309 | 7347 |
7310 info.GetReturnValue().Set(false); // intercepted, don't delete the property | 7348 info.GetReturnValue().Set(false); // intercepted, don't delete the property |
7311 } | 7349 } |
7312 | 7350 |
7313 | 7351 |
7314 THREADED_TEST(Deleter) { | 7352 THREADED_TEST(Deleter) { |
7315 v8::HandleScope scope(CcTest::isolate()); | 7353 v8::Isolate* isolate = CcTest::isolate(); |
7316 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 7354 v8::HandleScope scope(isolate); |
| 7355 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7317 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); | 7356 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); |
7318 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); | 7357 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); |
7319 LocalContext context; | 7358 LocalContext context; |
7320 context->Global()->Set(v8_str("k"), obj->NewInstance()); | 7359 context->Global()->Set(v8_str("k"), obj->NewInstance()); |
7321 CompileRun( | 7360 CompileRun( |
7322 "k.foo = 'foo';" | 7361 "k.foo = 'foo';" |
7323 "k.bar = 'bar';" | 7362 "k.bar = 'bar';" |
7324 "k[2] = 2;" | 7363 "k[2] = 2;" |
7325 "k[4] = 4;"); | 7364 "k[4] = 4;"); |
7326 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); | 7365 CHECK(v8_compile("delete k.foo")->Run()->IsFalse()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7370 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 7409 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
7371 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); | 7410 result->Set(v8::Integer::New(info.GetIsolate(), 0), v8_str("0")); |
7372 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); | 7411 result->Set(v8::Integer::New(info.GetIsolate(), 1), v8_str("1")); |
7373 info.GetReturnValue().Set(result); | 7412 info.GetReturnValue().Set(result); |
7374 } | 7413 } |
7375 | 7414 |
7376 | 7415 |
7377 THREADED_TEST(Enumerators) { | 7416 THREADED_TEST(Enumerators) { |
7378 v8::Isolate* isolate = CcTest::isolate(); | 7417 v8::Isolate* isolate = CcTest::isolate(); |
7379 v8::HandleScope scope(isolate); | 7418 v8::HandleScope scope(isolate); |
7380 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 7419 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7381 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); | 7420 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); |
7382 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); | 7421 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); |
7383 LocalContext context; | 7422 LocalContext context; |
7384 context->Global()->Set(v8_str("k"), obj->NewInstance()); | 7423 context->Global()->Set(v8_str("k"), obj->NewInstance()); |
7385 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 7424 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
7386 "k[10] = 0;" | 7425 "k[10] = 0;" |
7387 "k.a = 0;" | 7426 "k.a = 0;" |
7388 "k[5] = 0;" | 7427 "k[5] = 0;" |
7389 "k.b = 0;" | 7428 "k.b = 0;" |
7390 "k[4294967295] = 0;" | 7429 "k[4294967295] = 0;" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7484 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); | 7523 CHECK_EQ(info.This(), global->Get(v8_str("o2"))); |
7485 } else if (name->Equals(v8_str("p3"))) { | 7524 } else if (name->Equals(v8_str("p3"))) { |
7486 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); | 7525 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); |
7487 } else if (name->Equals(v8_str("p4"))) { | 7526 } else if (name->Equals(v8_str("p4"))) { |
7488 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); | 7527 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); |
7489 } | 7528 } |
7490 } | 7529 } |
7491 | 7530 |
7492 | 7531 |
7493 THREADED_TEST(GetterHolders) { | 7532 THREADED_TEST(GetterHolders) { |
7494 v8::HandleScope scope(CcTest::isolate()); | 7533 v8::Isolate* isolate = CcTest::isolate(); |
7495 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 7534 v8::HandleScope scope(isolate); |
| 7535 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7496 obj->SetAccessor(v8_str("p1"), PGetter); | 7536 obj->SetAccessor(v8_str("p1"), PGetter); |
7497 obj->SetAccessor(v8_str("p2"), PGetter); | 7537 obj->SetAccessor(v8_str("p2"), PGetter); |
7498 obj->SetAccessor(v8_str("p3"), PGetter); | 7538 obj->SetAccessor(v8_str("p3"), PGetter); |
7499 obj->SetAccessor(v8_str("p4"), PGetter); | 7539 obj->SetAccessor(v8_str("p4"), PGetter); |
7500 p_getter_count = 0; | 7540 p_getter_count = 0; |
7501 RunHolderTest(obj); | 7541 RunHolderTest(obj); |
7502 CHECK_EQ(40, p_getter_count); | 7542 CHECK_EQ(40, p_getter_count); |
7503 } | 7543 } |
7504 | 7544 |
7505 | 7545 |
7506 THREADED_TEST(PreInterceptorHolders) { | 7546 THREADED_TEST(PreInterceptorHolders) { |
7507 v8::HandleScope scope(CcTest::isolate()); | 7547 v8::Isolate* isolate = CcTest::isolate(); |
7508 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 7548 v8::HandleScope scope(isolate); |
| 7549 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7509 obj->SetNamedPropertyHandler(PGetter2); | 7550 obj->SetNamedPropertyHandler(PGetter2); |
7510 p_getter_count2 = 0; | 7551 p_getter_count2 = 0; |
7511 RunHolderTest(obj); | 7552 RunHolderTest(obj); |
7512 CHECK_EQ(40, p_getter_count2); | 7553 CHECK_EQ(40, p_getter_count2); |
7513 } | 7554 } |
7514 | 7555 |
7515 | 7556 |
7516 THREADED_TEST(ObjectInstantiation) { | 7557 THREADED_TEST(ObjectInstantiation) { |
7517 v8::Isolate* isolate = CcTest::isolate(); | 7558 v8::Isolate* isolate = CcTest::isolate(); |
7518 v8::HandleScope scope(isolate); | 7559 v8::HandleScope scope(isolate); |
7519 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 7560 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
7520 templ->SetAccessor(v8_str("t"), PGetter2); | 7561 templ->SetAccessor(v8_str("t"), PGetter2); |
7521 LocalContext context; | 7562 LocalContext context; |
7522 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 7563 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
7523 for (int i = 0; i < 100; i++) { | 7564 for (int i = 0; i < 100; i++) { |
7524 v8::HandleScope inner_scope(CcTest::isolate()); | 7565 v8::HandleScope inner_scope(CcTest::isolate()); |
7525 v8::Handle<v8::Object> obj = templ->NewInstance(); | 7566 v8::Handle<v8::Object> obj = templ->NewInstance(); |
7526 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); | 7567 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); |
7527 context->Global()->Set(v8_str("o2"), obj); | 7568 context->Global()->Set(v8_str("o2"), obj); |
7528 v8::Handle<Value> value = | 7569 v8::Handle<Value> value = |
7529 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); | 7570 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8112 Local<Value> value, | 8153 Local<Value> value, |
8113 const v8::PropertyCallbackInfo<void>& info) { | 8154 const v8::PropertyCallbackInfo<void>& info) { |
8114 if (info.This()->Has(name)) { | 8155 if (info.This()->Has(name)) { |
8115 info.This()->Delete(name); | 8156 info.This()->Delete(name); |
8116 } | 8157 } |
8117 info.This()->Set(name, value); | 8158 info.This()->Set(name, value); |
8118 } | 8159 } |
8119 | 8160 |
8120 | 8161 |
8121 THREADED_TEST(DeleteAccessor) { | 8162 THREADED_TEST(DeleteAccessor) { |
8122 v8::HandleScope scope(CcTest::isolate()); | 8163 v8::Isolate* isolate = CcTest::isolate(); |
8123 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 8164 v8::HandleScope scope(isolate); |
| 8165 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
8124 obj->SetAccessor(v8_str("y"), YGetter, YSetter); | 8166 obj->SetAccessor(v8_str("y"), YGetter, YSetter); |
8125 LocalContext context; | 8167 LocalContext context; |
8126 v8::Handle<v8::Object> holder = obj->NewInstance(); | 8168 v8::Handle<v8::Object> holder = obj->NewInstance(); |
8127 context->Global()->Set(v8_str("holder"), holder); | 8169 context->Global()->Set(v8_str("holder"), holder); |
8128 v8::Handle<Value> result = CompileRun( | 8170 v8::Handle<Value> result = CompileRun( |
8129 "holder.y = 11; holder.y = 12; holder.y"); | 8171 "holder.y = 11; holder.y = 12; holder.y"); |
8130 CHECK_EQ(12, result->Uint32Value()); | 8172 CHECK_EQ(12, result->Uint32Value()); |
8131 } | 8173 } |
8132 | 8174 |
8133 | 8175 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8304 CHECK(!try_catch.HasCaught()); | 8346 CHECK(!try_catch.HasCaught()); |
8305 Script::Compile(v8_str("(function()" | 8347 Script::Compile(v8_str("(function()" |
8306 " { try { throw ''; } finally { throw 0; }" | 8348 " { try { throw ''; } finally { throw 0; }" |
8307 "})()"))->Run(); | 8349 "})()"))->Run(); |
8308 CHECK(try_catch.HasCaught()); | 8350 CHECK(try_catch.HasCaught()); |
8309 } | 8351 } |
8310 | 8352 |
8311 | 8353 |
8312 // SecurityHandler can't be run twice | 8354 // SecurityHandler can't be run twice |
8313 TEST(SecurityHandler) { | 8355 TEST(SecurityHandler) { |
8314 v8::HandleScope scope0(CcTest::isolate()); | 8356 v8::Isolate* isolate = CcTest::isolate(); |
8315 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 8357 v8::HandleScope scope0(isolate); |
| 8358 v8::Handle<v8::ObjectTemplate> global_template = |
| 8359 v8::ObjectTemplate::New(isolate); |
8316 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, | 8360 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, |
8317 IndexedSecurityTestCallback); | 8361 IndexedSecurityTestCallback); |
8318 // Create an environment | 8362 // Create an environment |
8319 v8::Handle<Context> context0 = | 8363 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template); |
8320 Context::New(CcTest::isolate(), NULL, global_template); | |
8321 context0->Enter(); | 8364 context0->Enter(); |
8322 | 8365 |
8323 v8::Handle<v8::Object> global0 = context0->Global(); | 8366 v8::Handle<v8::Object> global0 = context0->Global(); |
8324 v8::Handle<Script> script0 = v8_compile("foo = 111"); | 8367 v8::Handle<Script> script0 = v8_compile("foo = 111"); |
8325 script0->Run(); | 8368 script0->Run(); |
8326 global0->Set(v8_str("0"), v8_num(999)); | 8369 global0->Set(v8_str("0"), v8_num(999)); |
8327 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); | 8370 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); |
8328 CHECK_EQ(111, foo0->Int32Value()); | 8371 CHECK_EQ(111, foo0->Int32Value()); |
8329 v8::Handle<Value> z0 = global0->Get(v8_str("0")); | 8372 v8::Handle<Value> z0 = global0->Get(v8_str("0")); |
8330 CHECK_EQ(999, z0->Int32Value()); | 8373 CHECK_EQ(999, z0->Int32Value()); |
8331 | 8374 |
8332 // Create another environment, should fail security checks. | 8375 // Create another environment, should fail security checks. |
8333 v8::HandleScope scope1(CcTest::isolate()); | 8376 v8::HandleScope scope1(isolate); |
8334 | 8377 |
8335 v8::Handle<Context> context1 = | 8378 v8::Handle<Context> context1 = |
8336 Context::New(CcTest::isolate(), NULL, global_template); | 8379 Context::New(isolate, NULL, global_template); |
8337 context1->Enter(); | 8380 context1->Enter(); |
8338 | 8381 |
8339 v8::Handle<v8::Object> global1 = context1->Global(); | 8382 v8::Handle<v8::Object> global1 = context1->Global(); |
8340 global1->Set(v8_str("othercontext"), global0); | 8383 global1->Set(v8_str("othercontext"), global0); |
8341 // This set will fail the security check. | 8384 // This set will fail the security check. |
8342 v8::Handle<Script> script1 = | 8385 v8::Handle<Script> script1 = |
8343 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); | 8386 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); |
8344 script1->Run(); | 8387 script1->Run(); |
8345 // This read will pass the security check. | 8388 // This read will pass the security check. |
8346 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); | 8389 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); |
8347 CHECK_EQ(111, foo1->Int32Value()); | 8390 CHECK_EQ(111, foo1->Int32Value()); |
8348 // This read will pass the security check. | 8391 // This read will pass the security check. |
8349 v8::Handle<Value> z1 = global0->Get(v8_str("0")); | 8392 v8::Handle<Value> z1 = global0->Get(v8_str("0")); |
8350 CHECK_EQ(999, z1->Int32Value()); | 8393 CHECK_EQ(999, z1->Int32Value()); |
8351 | 8394 |
8352 // Create another environment, should pass security checks. | 8395 // Create another environment, should pass security checks. |
8353 { g_security_callback_result = true; // allow security handler to pass. | 8396 { g_security_callback_result = true; // allow security handler to pass. |
8354 v8::HandleScope scope2(CcTest::isolate()); | 8397 v8::HandleScope scope2(isolate); |
8355 LocalContext context2; | 8398 LocalContext context2; |
8356 v8::Handle<v8::Object> global2 = context2->Global(); | 8399 v8::Handle<v8::Object> global2 = context2->Global(); |
8357 global2->Set(v8_str("othercontext"), global0); | 8400 global2->Set(v8_str("othercontext"), global0); |
8358 v8::Handle<Script> script2 = | 8401 v8::Handle<Script> script2 = |
8359 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); | 8402 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); |
8360 script2->Run(); | 8403 script2->Run(); |
8361 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); | 8404 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); |
8362 CHECK_EQ(333, foo2->Int32Value()); | 8405 CHECK_EQ(333, foo2->Int32Value()); |
8363 v8::Handle<Value> z2 = global0->Get(v8_str("0")); | 8406 v8::Handle<Value> z2 = global0->Get(v8_str("0")); |
8364 CHECK_EQ(888, z2->Int32Value()); | 8407 CHECK_EQ(888, z2->Int32Value()); |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8892 | 8935 |
8893 static void UnreachableFunction( | 8936 static void UnreachableFunction( |
8894 const v8::FunctionCallbackInfo<v8::Value>& info) { | 8937 const v8::FunctionCallbackInfo<v8::Value>& info) { |
8895 CHECK(false); // This function should not be called.. | 8938 CHECK(false); // This function should not be called.. |
8896 } | 8939 } |
8897 | 8940 |
8898 | 8941 |
8899 TEST(AccessControl) { | 8942 TEST(AccessControl) { |
8900 v8::Isolate* isolate = CcTest::isolate(); | 8943 v8::Isolate* isolate = CcTest::isolate(); |
8901 v8::HandleScope handle_scope(isolate); | 8944 v8::HandleScope handle_scope(isolate); |
8902 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 8945 v8::Handle<v8::ObjectTemplate> global_template = |
| 8946 v8::ObjectTemplate::New(isolate); |
8903 | 8947 |
8904 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, | 8948 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, |
8905 IndexedAccessBlocker); | 8949 IndexedAccessBlocker); |
8906 | 8950 |
8907 // Add an accessor accessible by cross-domain JS code. | 8951 // Add an accessor accessible by cross-domain JS code. |
8908 global_template->SetAccessor( | 8952 global_template->SetAccessor( |
8909 v8_str("accessible_prop"), | 8953 v8_str("accessible_prop"), |
8910 EchoGetter, EchoSetter, | 8954 EchoGetter, EchoSetter, |
8911 v8::Handle<Value>(), | 8955 v8::Handle<Value>(), |
8912 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 8956 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9171 CHECK(value->IsTrue()); | 9215 CHECK(value->IsTrue()); |
9172 | 9216 |
9173 context1->Exit(); | 9217 context1->Exit(); |
9174 context0->Exit(); | 9218 context0->Exit(); |
9175 } | 9219 } |
9176 | 9220 |
9177 | 9221 |
9178 TEST(AccessControlES5) { | 9222 TEST(AccessControlES5) { |
9179 v8::Isolate* isolate = CcTest::isolate(); | 9223 v8::Isolate* isolate = CcTest::isolate(); |
9180 v8::HandleScope handle_scope(isolate); | 9224 v8::HandleScope handle_scope(isolate); |
9181 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 9225 v8::Handle<v8::ObjectTemplate> global_template = |
| 9226 v8::ObjectTemplate::New(isolate); |
9182 | 9227 |
9183 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, | 9228 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, |
9184 IndexedAccessBlocker); | 9229 IndexedAccessBlocker); |
9185 | 9230 |
9186 // Add accessible accessor. | 9231 // Add accessible accessor. |
9187 global_template->SetAccessor( | 9232 global_template->SetAccessor( |
9188 v8_str("accessible_prop"), | 9233 v8_str("accessible_prop"), |
9189 EchoGetter, EchoSetter, | 9234 EchoGetter, EchoSetter, |
9190 v8::Handle<Value>(), | 9235 v8::Handle<Value>(), |
9191 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 9236 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9258 uint32_t key, | 9303 uint32_t key, |
9259 v8::AccessType type, | 9304 v8::AccessType type, |
9260 Local<Value> data) { | 9305 Local<Value> data) { |
9261 return false; | 9306 return false; |
9262 } | 9307 } |
9263 | 9308 |
9264 | 9309 |
9265 THREADED_TEST(AccessControlGetOwnPropertyNames) { | 9310 THREADED_TEST(AccessControlGetOwnPropertyNames) { |
9266 v8::Isolate* isolate = CcTest::isolate(); | 9311 v8::Isolate* isolate = CcTest::isolate(); |
9267 v8::HandleScope handle_scope(isolate); | 9312 v8::HandleScope handle_scope(isolate); |
9268 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); | 9313 v8::Handle<v8::ObjectTemplate> obj_template = |
| 9314 v8::ObjectTemplate::New(isolate); |
9269 | 9315 |
9270 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 9316 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
9271 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, | 9317 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, |
9272 GetOwnPropertyNamesIndexedBlocker); | 9318 GetOwnPropertyNamesIndexedBlocker); |
9273 | 9319 |
9274 // Create an environment | 9320 // Create an environment |
9275 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 9321 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
9276 context0->Enter(); | 9322 context0->Enter(); |
9277 | 9323 |
9278 v8::Handle<v8::Object> global0 = context0->Global(); | 9324 v8::Handle<v8::Object> global0 = context0->Global(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9316 static void NamedPropertyEnumerator( | 9362 static void NamedPropertyEnumerator( |
9317 const v8::PropertyCallbackInfo<v8::Array>& info) { | 9363 const v8::PropertyCallbackInfo<v8::Array>& info) { |
9318 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); | 9364 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate(), 2); |
9319 result->Set(0, v8_str("x")); | 9365 result->Set(0, v8_str("x")); |
9320 result->Set(1, v8::Object::New(info.GetIsolate())); | 9366 result->Set(1, v8::Object::New(info.GetIsolate())); |
9321 info.GetReturnValue().Set(result); | 9367 info.GetReturnValue().Set(result); |
9322 } | 9368 } |
9323 | 9369 |
9324 | 9370 |
9325 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { | 9371 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { |
9326 v8::HandleScope handle_scope(CcTest::isolate()); | 9372 v8::Isolate* isolate = CcTest::isolate(); |
9327 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); | 9373 v8::HandleScope handle_scope(isolate); |
| 9374 v8::Handle<v8::ObjectTemplate> obj_template = |
| 9375 v8::ObjectTemplate::New(isolate); |
9328 | 9376 |
9329 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); | 9377 obj_template->Set(v8_str("7"), v8::Integer::New(CcTest::isolate(), 7)); |
9330 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); | 9378 obj_template->Set(v8_str("x"), v8::Integer::New(CcTest::isolate(), 42)); |
9331 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, | 9379 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, |
9332 IndexedPropertyEnumerator); | 9380 IndexedPropertyEnumerator); |
9333 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, | 9381 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, |
9334 NamedPropertyEnumerator); | 9382 NamedPropertyEnumerator); |
9335 | 9383 |
9336 LocalContext context; | 9384 LocalContext context; |
9337 v8::Handle<v8::Object> global = context->Global(); | 9385 v8::Handle<v8::Object> global = context->Global(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9438 | 9486 |
9439 v8::Isolate* isolate = CcTest::isolate(); | 9487 v8::Isolate* isolate = CcTest::isolate(); |
9440 v8::HandleScope handle_scope(isolate); | 9488 v8::HandleScope handle_scope(isolate); |
9441 | 9489 |
9442 // Create an environment. | 9490 // Create an environment. |
9443 v8::Local<Context> context0 = Context::New(isolate); | 9491 v8::Local<Context> context0 = Context::New(isolate); |
9444 context0->Enter(); | 9492 context0->Enter(); |
9445 | 9493 |
9446 // Create an object that requires access-check functions to be | 9494 // Create an object that requires access-check functions to be |
9447 // called for cross-domain access. | 9495 // called for cross-domain access. |
9448 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 9496 v8::Handle<v8::ObjectTemplate> object_template = |
| 9497 v8::ObjectTemplate::New(isolate); |
9449 object_template->SetAccessCheckCallbacks(NamedAccessCounter, | 9498 object_template->SetAccessCheckCallbacks(NamedAccessCounter, |
9450 IndexedAccessCounter); | 9499 IndexedAccessCounter); |
9451 Local<v8::Object> object = object_template->NewInstance(); | 9500 Local<v8::Object> object = object_template->NewInstance(); |
9452 | 9501 |
9453 v8::HandleScope scope1(isolate); | 9502 v8::HandleScope scope1(isolate); |
9454 | 9503 |
9455 // Create another environment. | 9504 // Create another environment. |
9456 v8::Local<Context> context1 = Context::New(isolate); | 9505 v8::Local<Context> context1 = Context::New(isolate); |
9457 context1->Enter(); | 9506 context1->Enter(); |
9458 | 9507 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9586 | 9635 |
9587 v8::Isolate* isolate = CcTest::isolate(); | 9636 v8::Isolate* isolate = CcTest::isolate(); |
9588 v8::HandleScope handle_scope(isolate); | 9637 v8::HandleScope handle_scope(isolate); |
9589 | 9638 |
9590 // Create an environment. | 9639 // Create an environment. |
9591 v8::Local<Context> context0 = Context::New(isolate); | 9640 v8::Local<Context> context0 = Context::New(isolate); |
9592 context0->Enter(); | 9641 context0->Enter(); |
9593 | 9642 |
9594 // Create an object that requires access-check functions to be | 9643 // Create an object that requires access-check functions to be |
9595 // called for cross-domain access. | 9644 // called for cross-domain access. |
9596 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 9645 v8::Handle<v8::ObjectTemplate> object_template = |
| 9646 v8::ObjectTemplate::New(isolate); |
9597 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, | 9647 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, |
9598 IndexedAccessFlatten); | 9648 IndexedAccessFlatten); |
9599 Local<v8::Object> object = object_template->NewInstance(); | 9649 Local<v8::Object> object = object_template->NewInstance(); |
9600 | 9650 |
9601 v8::HandleScope scope1(isolate); | 9651 v8::HandleScope scope1(isolate); |
9602 | 9652 |
9603 // Create another environment. | 9653 // Create another environment. |
9604 v8::Local<Context> context1 = Context::New(isolate); | 9654 v8::Local<Context> context1 = Context::New(isolate); |
9605 context1->Enter(); | 9655 context1->Enter(); |
9606 | 9656 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9655 v8::Isolate* isolate = CcTest::isolate(); | 9705 v8::Isolate* isolate = CcTest::isolate(); |
9656 v8::HandleScope handle_scope(isolate); | 9706 v8::HandleScope handle_scope(isolate); |
9657 | 9707 |
9658 // Create an environment. | 9708 // Create an environment. |
9659 v8::Local<Context> context0 = Context::New(isolate); | 9709 v8::Local<Context> context0 = Context::New(isolate); |
9660 context0->Enter(); | 9710 context0->Enter(); |
9661 | 9711 |
9662 // Create an object that requires access-check functions to be | 9712 // Create an object that requires access-check functions to be |
9663 // called for cross-domain access. The object also has interceptors | 9713 // called for cross-domain access. The object also has interceptors |
9664 // interceptor. | 9714 // interceptor. |
9665 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); | 9715 v8::Handle<v8::ObjectTemplate> object_template = |
| 9716 v8::ObjectTemplate::New(isolate); |
9666 object_template->SetAccessCheckCallbacks(NamedAccessCounter, | 9717 object_template->SetAccessCheckCallbacks(NamedAccessCounter, |
9667 IndexedAccessCounter); | 9718 IndexedAccessCounter); |
9668 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, | 9719 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, |
9669 AccessControlNamedSetter); | 9720 AccessControlNamedSetter); |
9670 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, | 9721 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, |
9671 AccessControlIndexedSetter); | 9722 AccessControlIndexedSetter); |
9672 Local<v8::Object> object = object_template->NewInstance(); | 9723 Local<v8::Object> object = object_template->NewInstance(); |
9673 | 9724 |
9674 v8::HandleScope scope1(isolate); | 9725 v8::HandleScope scope1(isolate); |
9675 | 9726 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9891 static void ShadowNamedGet(Local<String> key, | 9942 static void ShadowNamedGet(Local<String> key, |
9892 const v8::PropertyCallbackInfo<v8::Value>&) { | 9943 const v8::PropertyCallbackInfo<v8::Value>&) { |
9893 } | 9944 } |
9894 | 9945 |
9895 | 9946 |
9896 THREADED_TEST(ShadowObject) { | 9947 THREADED_TEST(ShadowObject) { |
9897 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; | 9948 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; |
9898 v8::Isolate* isolate = CcTest::isolate(); | 9949 v8::Isolate* isolate = CcTest::isolate(); |
9899 v8::HandleScope handle_scope(isolate); | 9950 v8::HandleScope handle_scope(isolate); |
9900 | 9951 |
9901 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 9952 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
9902 LocalContext context(NULL, global_template); | 9953 LocalContext context(NULL, global_template); |
9903 | 9954 |
9904 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 9955 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
9905 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); | 9956 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); |
9906 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); | 9957 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); |
9907 Local<ObjectTemplate> proto = t->PrototypeTemplate(); | 9958 Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
9908 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 9959 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
9909 | 9960 |
9910 proto->Set(v8_str("f"), | 9961 proto->Set(v8_str("f"), |
9911 v8::FunctionTemplate::New(isolate, | 9962 v8::FunctionTemplate::New(isolate, |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10352 ApiTestFuzzer::Fuzz(); | 10403 ApiTestFuzzer::Fuzz(); |
10353 args.GetReturnValue().Set(args[0]); | 10404 args.GetReturnValue().Set(args[0]); |
10354 } | 10405 } |
10355 | 10406 |
10356 | 10407 |
10357 THREADED_TEST(ConstructorForObject) { | 10408 THREADED_TEST(ConstructorForObject) { |
10358 LocalContext context; | 10409 LocalContext context; |
10359 v8::Isolate* isolate = context->GetIsolate(); | 10410 v8::Isolate* isolate = context->GetIsolate(); |
10360 v8::HandleScope handle_scope(isolate); | 10411 v8::HandleScope handle_scope(isolate); |
10361 | 10412 |
10362 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10413 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10363 instance_template->SetCallAsFunctionHandler(ConstructorCallback); | 10414 instance_template->SetCallAsFunctionHandler(ConstructorCallback); |
10364 Local<Object> instance = instance_template->NewInstance(); | 10415 Local<Object> instance = instance_template->NewInstance(); |
10365 context->Global()->Set(v8_str("obj"), instance); | 10416 context->Global()->Set(v8_str("obj"), instance); |
10366 v8::TryCatch try_catch; | 10417 v8::TryCatch try_catch; |
10367 Local<Value> value; | 10418 Local<Value> value; |
10368 CHECK(!try_catch.HasCaught()); | 10419 CHECK(!try_catch.HasCaught()); |
10369 | 10420 |
10370 // Call the Object's constructor with a 32-bit signed integer. | 10421 // Call the Object's constructor with a 32-bit signed integer. |
10371 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); | 10422 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); |
10372 CHECK(!try_catch.HasCaught()); | 10423 CHECK(!try_catch.HasCaught()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10428 Handle<Value> args5[] = { v8::Null(isolate) }; | 10479 Handle<Value> args5[] = { v8::Null(isolate) }; |
10429 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5); | 10480 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5); |
10430 CHECK(value_obj5->IsObject()); | 10481 CHECK(value_obj5->IsObject()); |
10431 Local<Object> object5 = Local<Object>::Cast(value_obj5); | 10482 Local<Object> object5 = Local<Object>::Cast(value_obj5); |
10432 value = object5->Get(v8_str("a")); | 10483 value = object5->Get(v8_str("a")); |
10433 CHECK(!try_catch.HasCaught()); | 10484 CHECK(!try_catch.HasCaught()); |
10434 CHECK(value->IsNull()); | 10485 CHECK(value->IsNull()); |
10435 } | 10486 } |
10436 | 10487 |
10437 // Check exception handling when there is no constructor set for the Object. | 10488 // Check exception handling when there is no constructor set for the Object. |
10438 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10489 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10439 Local<Object> instance = instance_template->NewInstance(); | 10490 Local<Object> instance = instance_template->NewInstance(); |
10440 context->Global()->Set(v8_str("obj2"), instance); | 10491 context->Global()->Set(v8_str("obj2"), instance); |
10441 v8::TryCatch try_catch; | 10492 v8::TryCatch try_catch; |
10442 Local<Value> value; | 10493 Local<Value> value; |
10443 CHECK(!try_catch.HasCaught()); | 10494 CHECK(!try_catch.HasCaught()); |
10444 | 10495 |
10445 value = CompileRun("new obj2(28)"); | 10496 value = CompileRun("new obj2(28)"); |
10446 CHECK(try_catch.HasCaught()); | 10497 CHECK(try_catch.HasCaught()); |
10447 String::Utf8Value exception_value1(try_catch.Exception()); | 10498 String::Utf8Value exception_value1(try_catch.Exception()); |
10448 CHECK_EQ("TypeError: object is not a function", *exception_value1); | 10499 CHECK_EQ("TypeError: object is not a function", *exception_value1); |
10449 try_catch.Reset(); | 10500 try_catch.Reset(); |
10450 | 10501 |
10451 Local<Value> args[] = { v8_num(29) }; | 10502 Local<Value> args[] = { v8_num(29) }; |
10452 value = instance->CallAsConstructor(1, args); | 10503 value = instance->CallAsConstructor(1, args); |
10453 CHECK(try_catch.HasCaught()); | 10504 CHECK(try_catch.HasCaught()); |
10454 String::Utf8Value exception_value2(try_catch.Exception()); | 10505 String::Utf8Value exception_value2(try_catch.Exception()); |
10455 CHECK_EQ("TypeError: #<Object> is not a function", *exception_value2); | 10506 CHECK_EQ("TypeError: #<Object> is not a function", *exception_value2); |
10456 try_catch.Reset(); | 10507 try_catch.Reset(); |
10457 } | 10508 } |
10458 | 10509 |
10459 // Check the case when constructor throws exception. | 10510 // Check the case when constructor throws exception. |
10460 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10511 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10461 instance_template->SetCallAsFunctionHandler(ThrowValue); | 10512 instance_template->SetCallAsFunctionHandler(ThrowValue); |
10462 Local<Object> instance = instance_template->NewInstance(); | 10513 Local<Object> instance = instance_template->NewInstance(); |
10463 context->Global()->Set(v8_str("obj3"), instance); | 10514 context->Global()->Set(v8_str("obj3"), instance); |
10464 v8::TryCatch try_catch; | 10515 v8::TryCatch try_catch; |
10465 Local<Value> value; | 10516 Local<Value> value; |
10466 CHECK(!try_catch.HasCaught()); | 10517 CHECK(!try_catch.HasCaught()); |
10467 | 10518 |
10468 value = CompileRun("new obj3(22)"); | 10519 value = CompileRun("new obj3(22)"); |
10469 CHECK(try_catch.HasCaught()); | 10520 CHECK(try_catch.HasCaught()); |
10470 String::Utf8Value exception_value1(try_catch.Exception()); | 10521 String::Utf8Value exception_value1(try_catch.Exception()); |
(...skipping 23 matching lines...) Expand all Loading... |
10494 | 10545 |
10495 value = CompileRun("new obj4(28)"); | 10546 value = CompileRun("new obj4(28)"); |
10496 CHECK(!try_catch.HasCaught()); | 10547 CHECK(!try_catch.HasCaught()); |
10497 CHECK(value->IsObject()); | 10548 CHECK(value->IsObject()); |
10498 | 10549 |
10499 Local<Value> args1[] = { v8_num(28) }; | 10550 Local<Value> args1[] = { v8_num(28) }; |
10500 value = instance1->CallAsConstructor(1, args1); | 10551 value = instance1->CallAsConstructor(1, args1); |
10501 CHECK(!try_catch.HasCaught()); | 10552 CHECK(!try_catch.HasCaught()); |
10502 CHECK(value->IsObject()); | 10553 CHECK(value->IsObject()); |
10503 | 10554 |
10504 Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10555 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10505 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); | 10556 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); |
10506 Local<Object> instance2 = instance_template->NewInstance(); | 10557 Local<Object> instance2 = instance_template->NewInstance(); |
10507 context->Global()->Set(v8_str("obj5"), instance2); | 10558 context->Global()->Set(v8_str("obj5"), instance2); |
10508 CHECK(!try_catch.HasCaught()); | 10559 CHECK(!try_catch.HasCaught()); |
10509 | 10560 |
10510 CHECK(instance2->IsObject()); | 10561 CHECK(instance2->IsObject()); |
10511 CHECK(!instance2->IsFunction()); | 10562 CHECK(!instance2->IsFunction()); |
10512 | 10563 |
10513 value = CompileRun("new obj5(28)"); | 10564 value = CompileRun("new obj5(28)"); |
10514 CHECK(!try_catch.HasCaught()); | 10565 CHECK(!try_catch.HasCaught()); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10926 } | 10977 } |
10927 } | 10978 } |
10928 | 10979 |
10929 | 10980 |
10930 // Check whether a non-function object is callable. | 10981 // Check whether a non-function object is callable. |
10931 THREADED_TEST(CallableObject) { | 10982 THREADED_TEST(CallableObject) { |
10932 LocalContext context; | 10983 LocalContext context; |
10933 v8::Isolate* isolate = context->GetIsolate(); | 10984 v8::Isolate* isolate = context->GetIsolate(); |
10934 v8::HandleScope scope(isolate); | 10985 v8::HandleScope scope(isolate); |
10935 | 10986 |
10936 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10987 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10937 instance_template->SetCallAsFunctionHandler(call_as_function); | 10988 instance_template->SetCallAsFunctionHandler(call_as_function); |
10938 Local<Object> instance = instance_template->NewInstance(); | 10989 Local<Object> instance = instance_template->NewInstance(); |
10939 v8::TryCatch try_catch; | 10990 v8::TryCatch try_catch; |
10940 | 10991 |
10941 CHECK(instance->IsCallable()); | 10992 CHECK(instance->IsCallable()); |
10942 CHECK(!try_catch.HasCaught()); | 10993 CHECK(!try_catch.HasCaught()); |
10943 } | 10994 } |
10944 | 10995 |
10945 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); | 10996 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10946 Local<Object> instance = instance_template->NewInstance(); | 10997 Local<Object> instance = instance_template->NewInstance(); |
10947 v8::TryCatch try_catch; | 10998 v8::TryCatch try_catch; |
10948 | 10999 |
10949 CHECK(!instance->IsCallable()); | 11000 CHECK(!instance->IsCallable()); |
10950 CHECK(!try_catch.HasCaught()); | 11001 CHECK(!try_catch.HasCaught()); |
10951 } | 11002 } |
10952 | 11003 |
10953 { Local<FunctionTemplate> function_template = | 11004 { Local<FunctionTemplate> function_template = |
10954 FunctionTemplate::New(isolate, call_as_function); | 11005 FunctionTemplate::New(isolate, call_as_function); |
10955 Local<Function> function = function_template->GetFunction(); | 11006 Local<Function> function = function_template->GetFunction(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11083 | 11134 |
11084 | 11135 |
11085 typedef void (*NamedPropertyGetter)( | 11136 typedef void (*NamedPropertyGetter)( |
11086 Local<String> property, | 11137 Local<String> property, |
11087 const v8::PropertyCallbackInfo<v8::Value>& info); | 11138 const v8::PropertyCallbackInfo<v8::Value>& info); |
11088 | 11139 |
11089 | 11140 |
11090 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, | 11141 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, |
11091 const char* source, | 11142 const char* source, |
11092 int expected) { | 11143 int expected) { |
11093 v8::HandleScope scope(CcTest::isolate()); | 11144 v8::Isolate* isolate = CcTest::isolate(); |
11094 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11145 v8::HandleScope scope(isolate); |
| 11146 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11095 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); | 11147 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); |
11096 LocalContext context; | 11148 LocalContext context; |
11097 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11149 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11098 v8::Handle<Value> value = CompileRun(source); | 11150 v8::Handle<Value> value = CompileRun(source); |
11099 CHECK_EQ(expected, value->Int32Value()); | 11151 CHECK_EQ(expected, value->Int32Value()); |
11100 } | 11152 } |
11101 | 11153 |
11102 | 11154 |
11103 static void InterceptorLoadICGetter( | 11155 static void InterceptorLoadICGetter( |
11104 Local<String> name, | 11156 Local<String> name, |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11296 | 11348 |
11297 | 11349 |
11298 static void SetOnThis(Local<String> name, | 11350 static void SetOnThis(Local<String> name, |
11299 Local<Value> value, | 11351 Local<Value> value, |
11300 const v8::PropertyCallbackInfo<void>& info) { | 11352 const v8::PropertyCallbackInfo<void>& info) { |
11301 info.This()->ForceSet(name, value); | 11353 info.This()->ForceSet(name, value); |
11302 } | 11354 } |
11303 | 11355 |
11304 | 11356 |
11305 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { | 11357 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { |
11306 v8::HandleScope scope(CcTest::isolate()); | 11358 v8::Isolate* isolate = CcTest::isolate(); |
11307 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11359 v8::HandleScope scope(isolate); |
| 11360 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11308 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11361 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11309 templ->SetAccessor(v8_str("y"), Return239Callback); | 11362 templ->SetAccessor(v8_str("y"), Return239Callback); |
11310 LocalContext context; | 11363 LocalContext context; |
11311 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11364 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11312 | 11365 |
11313 // Check the case when receiver and interceptor's holder | 11366 // Check the case when receiver and interceptor's holder |
11314 // are the same objects. | 11367 // are the same objects. |
11315 v8::Handle<Value> value = CompileRun( | 11368 v8::Handle<Value> value = CompileRun( |
11316 "var result = 0;" | 11369 "var result = 0;" |
11317 "for (var i = 0; i < 7; i++) {" | 11370 "for (var i = 0; i < 7; i++) {" |
11318 " result = o.y;" | 11371 " result = o.y;" |
11319 "}"); | 11372 "}"); |
11320 CHECK_EQ(239, value->Int32Value()); | 11373 CHECK_EQ(239, value->Int32Value()); |
11321 | 11374 |
11322 // Check the case when interceptor's holder is in proto chain | 11375 // Check the case when interceptor's holder is in proto chain |
11323 // of receiver. | 11376 // of receiver. |
11324 value = CompileRun( | 11377 value = CompileRun( |
11325 "r = { __proto__: o };" | 11378 "r = { __proto__: o };" |
11326 "var result = 0;" | 11379 "var result = 0;" |
11327 "for (var i = 0; i < 7; i++) {" | 11380 "for (var i = 0; i < 7; i++) {" |
11328 " result = r.y;" | 11381 " result = r.y;" |
11329 "}"); | 11382 "}"); |
11330 CHECK_EQ(239, value->Int32Value()); | 11383 CHECK_EQ(239, value->Int32Value()); |
11331 } | 11384 } |
11332 | 11385 |
11333 | 11386 |
11334 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { | 11387 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { |
11335 v8::HandleScope scope(CcTest::isolate()); | 11388 v8::Isolate* isolate = CcTest::isolate(); |
11336 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 11389 v8::HandleScope scope(isolate); |
| 11390 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
11337 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11391 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11338 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); | 11392 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
11339 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 11393 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
11340 | 11394 |
11341 LocalContext context; | 11395 LocalContext context; |
11342 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 11396 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
11343 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 11397 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
11344 | 11398 |
11345 // Check the case when receiver and interceptor's holder | 11399 // Check the case when receiver and interceptor's holder |
11346 // are the same objects. | 11400 // are the same objects. |
11347 v8::Handle<Value> value = CompileRun( | 11401 v8::Handle<Value> value = CompileRun( |
11348 "o.__proto__ = p;" | 11402 "o.__proto__ = p;" |
11349 "var result = 0;" | 11403 "var result = 0;" |
11350 "for (var i = 0; i < 7; i++) {" | 11404 "for (var i = 0; i < 7; i++) {" |
11351 " result = o.x + o.y;" | 11405 " result = o.x + o.y;" |
11352 "}"); | 11406 "}"); |
11353 CHECK_EQ(239 + 42, value->Int32Value()); | 11407 CHECK_EQ(239 + 42, value->Int32Value()); |
11354 | 11408 |
11355 // Check the case when interceptor's holder is in proto chain | 11409 // Check the case when interceptor's holder is in proto chain |
11356 // of receiver. | 11410 // of receiver. |
11357 value = CompileRun( | 11411 value = CompileRun( |
11358 "r = { __proto__: o };" | 11412 "r = { __proto__: o };" |
11359 "var result = 0;" | 11413 "var result = 0;" |
11360 "for (var i = 0; i < 7; i++) {" | 11414 "for (var i = 0; i < 7; i++) {" |
11361 " result = r.x + r.y;" | 11415 " result = r.x + r.y;" |
11362 "}"); | 11416 "}"); |
11363 CHECK_EQ(239 + 42, value->Int32Value()); | 11417 CHECK_EQ(239 + 42, value->Int32Value()); |
11364 } | 11418 } |
11365 | 11419 |
11366 | 11420 |
11367 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { | 11421 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { |
11368 v8::HandleScope scope(CcTest::isolate()); | 11422 v8::Isolate* isolate = CcTest::isolate(); |
11369 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11423 v8::HandleScope scope(isolate); |
| 11424 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11370 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11425 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11371 templ->SetAccessor(v8_str("y"), Return239Callback); | 11426 templ->SetAccessor(v8_str("y"), Return239Callback); |
11372 | 11427 |
11373 LocalContext context; | 11428 LocalContext context; |
11374 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11429 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11375 | 11430 |
11376 v8::Handle<Value> value = CompileRun( | 11431 v8::Handle<Value> value = CompileRun( |
11377 "fst = new Object(); fst.__proto__ = o;" | 11432 "fst = new Object(); fst.__proto__ = o;" |
11378 "snd = new Object(); snd.__proto__ = fst;" | 11433 "snd = new Object(); snd.__proto__ = fst;" |
11379 "var result1 = 0;" | 11434 "var result1 = 0;" |
11380 "for (var i = 0; i < 7; i++) {" | 11435 "for (var i = 0; i < 7; i++) {" |
11381 " result1 = snd.x;" | 11436 " result1 = snd.x;" |
11382 "}" | 11437 "}" |
11383 "fst.x = 239;" | 11438 "fst.x = 239;" |
11384 "var result = 0;" | 11439 "var result = 0;" |
11385 "for (var i = 0; i < 7; i++) {" | 11440 "for (var i = 0; i < 7; i++) {" |
11386 " result = snd.x;" | 11441 " result = snd.x;" |
11387 "}" | 11442 "}" |
11388 "result + result1"); | 11443 "result + result1"); |
11389 CHECK_EQ(239 + 42, value->Int32Value()); | 11444 CHECK_EQ(239 + 42, value->Int32Value()); |
11390 } | 11445 } |
11391 | 11446 |
11392 | 11447 |
11393 // Test the case when we stored callback into | 11448 // Test the case when we stored callback into |
11394 // a stub, but interceptor produced value on its own. | 11449 // a stub, but interceptor produced value on its own. |
11395 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { | 11450 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { |
11396 v8::HandleScope scope(CcTest::isolate()); | 11451 v8::Isolate* isolate = CcTest::isolate(); |
11397 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 11452 v8::HandleScope scope(isolate); |
| 11453 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
11398 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11454 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11399 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); | 11455 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
11400 templ_p->SetAccessor(v8_str("y"), Return239Callback); | 11456 templ_p->SetAccessor(v8_str("y"), Return239Callback); |
11401 | 11457 |
11402 LocalContext context; | 11458 LocalContext context; |
11403 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 11459 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
11404 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 11460 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
11405 | 11461 |
11406 v8::Handle<Value> value = CompileRun( | 11462 v8::Handle<Value> value = CompileRun( |
11407 "o.__proto__ = p;" | 11463 "o.__proto__ = p;" |
11408 "for (var i = 0; i < 7; i++) {" | 11464 "for (var i = 0; i < 7; i++) {" |
11409 " o.x;" | 11465 " o.x;" |
11410 // Now it should be ICed and keep a reference to x defined on p | 11466 // Now it should be ICed and keep a reference to x defined on p |
11411 "}" | 11467 "}" |
11412 "var result = 0;" | 11468 "var result = 0;" |
11413 "for (var i = 0; i < 7; i++) {" | 11469 "for (var i = 0; i < 7; i++) {" |
11414 " result += o.x;" | 11470 " result += o.x;" |
11415 "}" | 11471 "}" |
11416 "result"); | 11472 "result"); |
11417 CHECK_EQ(42 * 7, value->Int32Value()); | 11473 CHECK_EQ(42 * 7, value->Int32Value()); |
11418 } | 11474 } |
11419 | 11475 |
11420 | 11476 |
11421 // Test the case when we stored callback into | 11477 // Test the case when we stored callback into |
11422 // a stub, but it got invalidated later on. | 11478 // a stub, but it got invalidated later on. |
11423 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { | 11479 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { |
11424 v8::HandleScope scope(CcTest::isolate()); | 11480 v8::Isolate* isolate = CcTest::isolate(); |
11425 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 11481 v8::HandleScope scope(isolate); |
| 11482 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
11426 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11483 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11427 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); | 11484 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
11428 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 11485 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
11429 | 11486 |
11430 LocalContext context; | 11487 LocalContext context; |
11431 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 11488 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
11432 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 11489 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
11433 | 11490 |
11434 v8::Handle<Value> value = CompileRun( | 11491 v8::Handle<Value> value = CompileRun( |
11435 "inbetween = new Object();" | 11492 "inbetween = new Object();" |
11436 "o.__proto__ = inbetween;" | 11493 "o.__proto__ = inbetween;" |
11437 "inbetween.__proto__ = p;" | 11494 "inbetween.__proto__ = p;" |
11438 "for (var i = 0; i < 10; i++) {" | 11495 "for (var i = 0; i < 10; i++) {" |
11439 " o.y;" | 11496 " o.y;" |
11440 // Now it should be ICed and keep a reference to y defined on p | 11497 // Now it should be ICed and keep a reference to y defined on p |
11441 "}" | 11498 "}" |
11442 "inbetween.y = 42;" | 11499 "inbetween.y = 42;" |
11443 "var result = 0;" | 11500 "var result = 0;" |
11444 "for (var i = 0; i < 10; i++) {" | 11501 "for (var i = 0; i < 10; i++) {" |
11445 " result += o.y;" | 11502 " result += o.y;" |
11446 "}" | 11503 "}" |
11447 "result"); | 11504 "result"); |
11448 CHECK_EQ(42 * 10, value->Int32Value()); | 11505 CHECK_EQ(42 * 10, value->Int32Value()); |
11449 } | 11506 } |
11450 | 11507 |
11451 | 11508 |
11452 // Test the case when we stored callback into | 11509 // Test the case when we stored callback into |
11453 // a stub, but it got invalidated later on due to override on | 11510 // a stub, but it got invalidated later on due to override on |
11454 // global object which is between interceptor and callbacks' holders. | 11511 // global object which is between interceptor and callbacks' holders. |
11455 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { | 11512 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { |
11456 v8::HandleScope scope(CcTest::isolate()); | 11513 v8::Isolate* isolate = CcTest::isolate(); |
11457 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 11514 v8::HandleScope scope(isolate); |
| 11515 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
11458 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11516 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11459 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); | 11517 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(isolate); |
11460 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); | 11518 templ_p->SetAccessor(v8_str("y"), Return239Callback, SetOnThis); |
11461 | 11519 |
11462 LocalContext context; | 11520 LocalContext context; |
11463 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 11521 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
11464 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); | 11522 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); |
11465 | 11523 |
11466 v8::Handle<Value> value = CompileRun( | 11524 v8::Handle<Value> value = CompileRun( |
11467 "o.__proto__ = this;" | 11525 "o.__proto__ = this;" |
11468 "this.__proto__ = p;" | 11526 "this.__proto__ = p;" |
11469 "for (var i = 0; i < 10; i++) {" | 11527 "for (var i = 0; i < 10; i++) {" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11501 Local<Value> value, | 11559 Local<Value> value, |
11502 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11560 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11503 CHECK(v8_str("x")->Equals(key)); | 11561 CHECK(v8_str("x")->Equals(key)); |
11504 CHECK_EQ(42, value->Int32Value()); | 11562 CHECK_EQ(42, value->Int32Value()); |
11505 info.GetReturnValue().Set(value); | 11563 info.GetReturnValue().Set(value); |
11506 } | 11564 } |
11507 | 11565 |
11508 | 11566 |
11509 // This test should hit the store IC for the interceptor case. | 11567 // This test should hit the store IC for the interceptor case. |
11510 THREADED_TEST(InterceptorStoreIC) { | 11568 THREADED_TEST(InterceptorStoreIC) { |
11511 v8::HandleScope scope(CcTest::isolate()); | 11569 v8::Isolate* isolate = CcTest::isolate(); |
11512 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11570 v8::HandleScope scope(isolate); |
| 11571 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11513 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, | 11572 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, |
11514 InterceptorStoreICSetter, | 11573 InterceptorStoreICSetter, |
11515 0, 0, 0, v8_str("data")); | 11574 0, 0, 0, v8_str("data")); |
11516 LocalContext context; | 11575 LocalContext context; |
11517 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11576 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11518 CompileRun( | 11577 CompileRun( |
11519 "for (var i = 0; i < 1000; i++) {" | 11578 "for (var i = 0; i < 1000; i++) {" |
11520 " o.x = 42;" | 11579 " o.x = 42;" |
11521 "}"); | 11580 "}"); |
11522 } | 11581 } |
11523 | 11582 |
11524 | 11583 |
11525 THREADED_TEST(InterceptorStoreICWithNoSetter) { | 11584 THREADED_TEST(InterceptorStoreICWithNoSetter) { |
11526 v8::HandleScope scope(CcTest::isolate()); | 11585 v8::Isolate* isolate = CcTest::isolate(); |
11527 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11586 v8::HandleScope scope(isolate); |
| 11587 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11528 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | 11588 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); |
11529 LocalContext context; | 11589 LocalContext context; |
11530 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11590 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11531 v8::Handle<Value> value = CompileRun( | 11591 v8::Handle<Value> value = CompileRun( |
11532 "for (var i = 0; i < 1000; i++) {" | 11592 "for (var i = 0; i < 1000; i++) {" |
11533 " o.y = 239;" | 11593 " o.y = 239;" |
11534 "}" | 11594 "}" |
11535 "42 + o.y"); | 11595 "42 + o.y"); |
11536 CHECK_EQ(239 + 42, value->Int32Value()); | 11596 CHECK_EQ(239 + 42, value->Int32Value()); |
11537 } | 11597 } |
11538 | 11598 |
11539 | 11599 |
11540 | 11600 |
11541 | 11601 |
11542 v8::Handle<Value> call_ic_function; | 11602 v8::Handle<Value> call_ic_function; |
11543 v8::Handle<Value> call_ic_function2; | 11603 v8::Handle<Value> call_ic_function2; |
11544 v8::Handle<Value> call_ic_function3; | 11604 v8::Handle<Value> call_ic_function3; |
11545 | 11605 |
11546 static void InterceptorCallICGetter( | 11606 static void InterceptorCallICGetter( |
11547 Local<String> name, | 11607 Local<String> name, |
11548 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11608 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11549 ApiTestFuzzer::Fuzz(); | 11609 ApiTestFuzzer::Fuzz(); |
11550 CHECK(v8_str("x")->Equals(name)); | 11610 CHECK(v8_str("x")->Equals(name)); |
11551 info.GetReturnValue().Set(call_ic_function); | 11611 info.GetReturnValue().Set(call_ic_function); |
11552 } | 11612 } |
11553 | 11613 |
11554 | 11614 |
11555 // This test should hit the call IC for the interceptor case. | 11615 // This test should hit the call IC for the interceptor case. |
11556 THREADED_TEST(InterceptorCallIC) { | 11616 THREADED_TEST(InterceptorCallIC) { |
11557 v8::HandleScope scope(CcTest::isolate()); | 11617 v8::Isolate* isolate = CcTest::isolate(); |
11558 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11618 v8::HandleScope scope(isolate); |
| 11619 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11559 templ->SetNamedPropertyHandler(InterceptorCallICGetter); | 11620 templ->SetNamedPropertyHandler(InterceptorCallICGetter); |
11560 LocalContext context; | 11621 LocalContext context; |
11561 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11622 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11562 call_ic_function = | 11623 call_ic_function = |
11563 v8_compile("function f(x) { return x + 1; }; f")->Run(); | 11624 v8_compile("function f(x) { return x + 1; }; f")->Run(); |
11564 v8::Handle<Value> value = CompileRun( | 11625 v8::Handle<Value> value = CompileRun( |
11565 "var result = 0;" | 11626 "var result = 0;" |
11566 "for (var i = 0; i < 1000; i++) {" | 11627 "for (var i = 0; i < 1000; i++) {" |
11567 " result = o.x(41);" | 11628 " result = o.x(41);" |
11568 "}"); | 11629 "}"); |
11569 CHECK_EQ(42, value->Int32Value()); | 11630 CHECK_EQ(42, value->Int32Value()); |
11570 } | 11631 } |
11571 | 11632 |
11572 | 11633 |
11573 // This test checks that if interceptor doesn't provide | 11634 // This test checks that if interceptor doesn't provide |
11574 // a value, we can fetch regular value. | 11635 // a value, we can fetch regular value. |
11575 THREADED_TEST(InterceptorCallICSeesOthers) { | 11636 THREADED_TEST(InterceptorCallICSeesOthers) { |
11576 v8::HandleScope scope(CcTest::isolate()); | 11637 v8::Isolate* isolate = CcTest::isolate(); |
11577 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11638 v8::HandleScope scope(isolate); |
| 11639 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11578 templ->SetNamedPropertyHandler(NoBlockGetterX); | 11640 templ->SetNamedPropertyHandler(NoBlockGetterX); |
11579 LocalContext context; | 11641 LocalContext context; |
11580 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11642 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11581 v8::Handle<Value> value = CompileRun( | 11643 v8::Handle<Value> value = CompileRun( |
11582 "o.x = function f(x) { return x + 1; };" | 11644 "o.x = function f(x) { return x + 1; };" |
11583 "var result = 0;" | 11645 "var result = 0;" |
11584 "for (var i = 0; i < 7; i++) {" | 11646 "for (var i = 0; i < 7; i++) {" |
11585 " result = o.x(41);" | 11647 " result = o.x(41);" |
11586 "}"); | 11648 "}"); |
11587 CHECK_EQ(42, value->Int32Value()); | 11649 CHECK_EQ(42, value->Int32Value()); |
11588 } | 11650 } |
11589 | 11651 |
11590 | 11652 |
11591 static v8::Handle<Value> call_ic_function4; | 11653 static v8::Handle<Value> call_ic_function4; |
11592 static void InterceptorCallICGetter4( | 11654 static void InterceptorCallICGetter4( |
11593 Local<String> name, | 11655 Local<String> name, |
11594 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11656 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11595 ApiTestFuzzer::Fuzz(); | 11657 ApiTestFuzzer::Fuzz(); |
11596 CHECK(v8_str("x")->Equals(name)); | 11658 CHECK(v8_str("x")->Equals(name)); |
11597 info.GetReturnValue().Set(call_ic_function4); | 11659 info.GetReturnValue().Set(call_ic_function4); |
11598 } | 11660 } |
11599 | 11661 |
11600 | 11662 |
11601 // This test checks that if interceptor provides a function, | 11663 // This test checks that if interceptor provides a function, |
11602 // even if we cached shadowed variant, interceptor's function | 11664 // even if we cached shadowed variant, interceptor's function |
11603 // is invoked | 11665 // is invoked |
11604 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { | 11666 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { |
11605 v8::HandleScope scope(CcTest::isolate()); | 11667 v8::Isolate* isolate = CcTest::isolate(); |
11606 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11668 v8::HandleScope scope(isolate); |
| 11669 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11607 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); | 11670 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); |
11608 LocalContext context; | 11671 LocalContext context; |
11609 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11672 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11610 call_ic_function4 = | 11673 call_ic_function4 = |
11611 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 11674 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
11612 v8::Handle<Value> value = CompileRun( | 11675 v8::Handle<Value> value = CompileRun( |
11613 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" | 11676 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" |
11614 "var result = 0;" | 11677 "var result = 0;" |
11615 "for (var i = 0; i < 1000; i++) {" | 11678 "for (var i = 0; i < 1000; i++) {" |
11616 " result = o.x(42);" | 11679 " result = o.x(42);" |
11617 "}"); | 11680 "}"); |
11618 CHECK_EQ(41, value->Int32Value()); | 11681 CHECK_EQ(41, value->Int32Value()); |
11619 } | 11682 } |
11620 | 11683 |
11621 | 11684 |
11622 // Test the case when we stored cacheable lookup into | 11685 // Test the case when we stored cacheable lookup into |
11623 // a stub, but it got invalidated later on | 11686 // a stub, but it got invalidated later on |
11624 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { | 11687 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { |
11625 v8::HandleScope scope(CcTest::isolate()); | 11688 v8::Isolate* isolate = CcTest::isolate(); |
11626 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11689 v8::HandleScope scope(isolate); |
| 11690 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11627 templ->SetNamedPropertyHandler(NoBlockGetterX); | 11691 templ->SetNamedPropertyHandler(NoBlockGetterX); |
11628 LocalContext context; | 11692 LocalContext context; |
11629 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11693 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11630 v8::Handle<Value> value = CompileRun( | 11694 v8::Handle<Value> value = CompileRun( |
11631 "proto1 = new Object();" | 11695 "proto1 = new Object();" |
11632 "proto2 = new Object();" | 11696 "proto2 = new Object();" |
11633 "o.__proto__ = proto1;" | 11697 "o.__proto__ = proto1;" |
11634 "proto1.__proto__ = proto2;" | 11698 "proto1.__proto__ = proto2;" |
11635 "proto2.y = function(x) { return x + 1; };" | 11699 "proto2.y = function(x) { return x + 1; };" |
11636 // Invoke it many times to compile a stub | 11700 // Invoke it many times to compile a stub |
11637 "for (var i = 0; i < 7; i++) {" | 11701 "for (var i = 0; i < 7; i++) {" |
11638 " o.y(42);" | 11702 " o.y(42);" |
11639 "}" | 11703 "}" |
11640 "proto1.y = function(x) { return x - 1; };" | 11704 "proto1.y = function(x) { return x - 1; };" |
11641 "var result = 0;" | 11705 "var result = 0;" |
11642 "for (var i = 0; i < 7; i++) {" | 11706 "for (var i = 0; i < 7; i++) {" |
11643 " result += o.y(42);" | 11707 " result += o.y(42);" |
11644 "}"); | 11708 "}"); |
11645 CHECK_EQ(41 * 7, value->Int32Value()); | 11709 CHECK_EQ(41 * 7, value->Int32Value()); |
11646 } | 11710 } |
11647 | 11711 |
11648 | 11712 |
11649 // This test checks that if interceptor doesn't provide a function, | 11713 // This test checks that if interceptor doesn't provide a function, |
11650 // cached constant function is used | 11714 // cached constant function is used |
11651 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { | 11715 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { |
11652 v8::HandleScope scope(CcTest::isolate()); | 11716 v8::Isolate* isolate = CcTest::isolate(); |
11653 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11717 v8::HandleScope scope(isolate); |
| 11718 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11654 templ->SetNamedPropertyHandler(NoBlockGetterX); | 11719 templ->SetNamedPropertyHandler(NoBlockGetterX); |
11655 LocalContext context; | 11720 LocalContext context; |
11656 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11721 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11657 v8::Handle<Value> value = CompileRun( | 11722 v8::Handle<Value> value = CompileRun( |
11658 "function inc(x) { return x + 1; };" | 11723 "function inc(x) { return x + 1; };" |
11659 "inc(1);" | 11724 "inc(1);" |
11660 "o.x = inc;" | 11725 "o.x = inc;" |
11661 "var result = 0;" | 11726 "var result = 0;" |
11662 "for (var i = 0; i < 1000; i++) {" | 11727 "for (var i = 0; i < 1000; i++) {" |
11663 " result = o.x(42);" | 11728 " result = o.x(42);" |
11664 "}"); | 11729 "}"); |
11665 CHECK_EQ(43, value->Int32Value()); | 11730 CHECK_EQ(43, value->Int32Value()); |
11666 } | 11731 } |
11667 | 11732 |
11668 | 11733 |
11669 static v8::Handle<Value> call_ic_function5; | 11734 static v8::Handle<Value> call_ic_function5; |
11670 static void InterceptorCallICGetter5( | 11735 static void InterceptorCallICGetter5( |
11671 Local<String> name, | 11736 Local<String> name, |
11672 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11737 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11673 ApiTestFuzzer::Fuzz(); | 11738 ApiTestFuzzer::Fuzz(); |
11674 if (v8_str("x")->Equals(name)) | 11739 if (v8_str("x")->Equals(name)) |
11675 info.GetReturnValue().Set(call_ic_function5); | 11740 info.GetReturnValue().Set(call_ic_function5); |
11676 } | 11741 } |
11677 | 11742 |
11678 | 11743 |
11679 // This test checks that if interceptor provides a function, | 11744 // This test checks that if interceptor provides a function, |
11680 // even if we cached constant function, interceptor's function | 11745 // even if we cached constant function, interceptor's function |
11681 // is invoked | 11746 // is invoked |
11682 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { | 11747 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { |
11683 v8::HandleScope scope(CcTest::isolate()); | 11748 v8::Isolate* isolate = CcTest::isolate(); |
11684 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11749 v8::HandleScope scope(isolate); |
| 11750 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11685 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); | 11751 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); |
11686 LocalContext context; | 11752 LocalContext context; |
11687 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11753 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11688 call_ic_function5 = | 11754 call_ic_function5 = |
11689 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 11755 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
11690 v8::Handle<Value> value = CompileRun( | 11756 v8::Handle<Value> value = CompileRun( |
11691 "function inc(x) { return x + 1; };" | 11757 "function inc(x) { return x + 1; };" |
11692 "inc(1);" | 11758 "inc(1);" |
11693 "o.x = inc;" | 11759 "o.x = inc;" |
11694 "var result = 0;" | 11760 "var result = 0;" |
(...skipping 11 matching lines...) Expand all Loading... |
11706 ApiTestFuzzer::Fuzz(); | 11772 ApiTestFuzzer::Fuzz(); |
11707 if (v8_str("x")->Equals(name)) | 11773 if (v8_str("x")->Equals(name)) |
11708 info.GetReturnValue().Set(call_ic_function6); | 11774 info.GetReturnValue().Set(call_ic_function6); |
11709 } | 11775 } |
11710 | 11776 |
11711 | 11777 |
11712 // Same test as above, except the code is wrapped in a function | 11778 // Same test as above, except the code is wrapped in a function |
11713 // to test the optimized compiler. | 11779 // to test the optimized compiler. |
11714 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { | 11780 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { |
11715 i::FLAG_allow_natives_syntax = true; | 11781 i::FLAG_allow_natives_syntax = true; |
11716 v8::HandleScope scope(CcTest::isolate()); | 11782 v8::Isolate* isolate = CcTest::isolate(); |
11717 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11783 v8::HandleScope scope(isolate); |
| 11784 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11718 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); | 11785 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); |
11719 LocalContext context; | 11786 LocalContext context; |
11720 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11787 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11721 call_ic_function6 = | 11788 call_ic_function6 = |
11722 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 11789 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
11723 v8::Handle<Value> value = CompileRun( | 11790 v8::Handle<Value> value = CompileRun( |
11724 "function inc(x) { return x + 1; };" | 11791 "function inc(x) { return x + 1; };" |
11725 "inc(1);" | 11792 "inc(1);" |
11726 "o.x = inc;" | 11793 "o.x = inc;" |
11727 "function test() {" | 11794 "function test() {" |
11728 " var result = 0;" | 11795 " var result = 0;" |
11729 " for (var i = 0; i < 1000; i++) {" | 11796 " for (var i = 0; i < 1000; i++) {" |
11730 " result = o.x(42);" | 11797 " result = o.x(42);" |
11731 " }" | 11798 " }" |
11732 " return result;" | 11799 " return result;" |
11733 "};" | 11800 "};" |
11734 "test();" | 11801 "test();" |
11735 "test();" | 11802 "test();" |
11736 "test();" | 11803 "test();" |
11737 "%OptimizeFunctionOnNextCall(test);" | 11804 "%OptimizeFunctionOnNextCall(test);" |
11738 "test()"); | 11805 "test()"); |
11739 CHECK_EQ(41, value->Int32Value()); | 11806 CHECK_EQ(41, value->Int32Value()); |
11740 } | 11807 } |
11741 | 11808 |
11742 | 11809 |
11743 // Test the case when we stored constant function into | 11810 // Test the case when we stored constant function into |
11744 // a stub, but it got invalidated later on | 11811 // a stub, but it got invalidated later on |
11745 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { | 11812 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { |
11746 v8::HandleScope scope(CcTest::isolate()); | 11813 v8::Isolate* isolate = CcTest::isolate(); |
11747 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11814 v8::HandleScope scope(isolate); |
| 11815 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11748 templ->SetNamedPropertyHandler(NoBlockGetterX); | 11816 templ->SetNamedPropertyHandler(NoBlockGetterX); |
11749 LocalContext context; | 11817 LocalContext context; |
11750 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11818 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11751 v8::Handle<Value> value = CompileRun( | 11819 v8::Handle<Value> value = CompileRun( |
11752 "function inc(x) { return x + 1; };" | 11820 "function inc(x) { return x + 1; };" |
11753 "inc(1);" | 11821 "inc(1);" |
11754 "proto1 = new Object();" | 11822 "proto1 = new Object();" |
11755 "proto2 = new Object();" | 11823 "proto2 = new Object();" |
11756 "o.__proto__ = proto1;" | 11824 "o.__proto__ = proto1;" |
11757 "proto1.__proto__ = proto2;" | 11825 "proto1.__proto__ = proto2;" |
11758 "proto2.y = inc;" | 11826 "proto2.y = inc;" |
11759 // Invoke it many times to compile a stub | 11827 // Invoke it many times to compile a stub |
11760 "for (var i = 0; i < 7; i++) {" | 11828 "for (var i = 0; i < 7; i++) {" |
11761 " o.y(42);" | 11829 " o.y(42);" |
11762 "}" | 11830 "}" |
11763 "proto1.y = function(x) { return x - 1; };" | 11831 "proto1.y = function(x) { return x - 1; };" |
11764 "var result = 0;" | 11832 "var result = 0;" |
11765 "for (var i = 0; i < 7; i++) {" | 11833 "for (var i = 0; i < 7; i++) {" |
11766 " result += o.y(42);" | 11834 " result += o.y(42);" |
11767 "}"); | 11835 "}"); |
11768 CHECK_EQ(41 * 7, value->Int32Value()); | 11836 CHECK_EQ(41 * 7, value->Int32Value()); |
11769 } | 11837 } |
11770 | 11838 |
11771 | 11839 |
11772 // Test the case when we stored constant function into | 11840 // Test the case when we stored constant function into |
11773 // a stub, but it got invalidated later on due to override on | 11841 // a stub, but it got invalidated later on due to override on |
11774 // global object which is between interceptor and constant function' holders. | 11842 // global object which is between interceptor and constant function' holders. |
11775 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { | 11843 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { |
11776 v8::HandleScope scope(CcTest::isolate()); | 11844 v8::Isolate* isolate = CcTest::isolate(); |
11777 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 11845 v8::HandleScope scope(isolate); |
| 11846 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
11778 templ->SetNamedPropertyHandler(NoBlockGetterX); | 11847 templ->SetNamedPropertyHandler(NoBlockGetterX); |
11779 LocalContext context; | 11848 LocalContext context; |
11780 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 11849 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
11781 v8::Handle<Value> value = CompileRun( | 11850 v8::Handle<Value> value = CompileRun( |
11782 "function inc(x) { return x + 1; };" | 11851 "function inc(x) { return x + 1; };" |
11783 "inc(1);" | 11852 "inc(1);" |
11784 "o.__proto__ = this;" | 11853 "o.__proto__ = this;" |
11785 "this.__proto__.y = inc;" | 11854 "this.__proto__.y = inc;" |
11786 // Invoke it many times to compile a stub | 11855 // Invoke it many times to compile a stub |
11787 "for (var i = 0; i < 7; i++) {" | 11856 "for (var i = 0; i < 7; i++) {" |
11788 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" | 11857 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" |
11789 "}" | 11858 "}" |
11790 "this.y = function(x) { return x - 1; };" | 11859 "this.y = function(x) { return x - 1; };" |
11791 "var result = 0;" | 11860 "var result = 0;" |
11792 "for (var i = 0; i < 7; i++) {" | 11861 "for (var i = 0; i < 7; i++) {" |
11793 " result += o.y(42);" | 11862 " result += o.y(42);" |
11794 "}"); | 11863 "}"); |
11795 CHECK_EQ(41 * 7, value->Int32Value()); | 11864 CHECK_EQ(41 * 7, value->Int32Value()); |
11796 } | 11865 } |
11797 | 11866 |
11798 | 11867 |
11799 // Test the case when actual function to call sits on global object. | 11868 // Test the case when actual function to call sits on global object. |
11800 THREADED_TEST(InterceptorCallICCachedFromGlobal) { | 11869 THREADED_TEST(InterceptorCallICCachedFromGlobal) { |
11801 v8::HandleScope scope(CcTest::isolate()); | 11870 v8::Isolate* isolate = CcTest::isolate(); |
11802 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 11871 v8::HandleScope scope(isolate); |
| 11872 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
11803 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 11873 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
11804 | 11874 |
11805 LocalContext context; | 11875 LocalContext context; |
11806 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 11876 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
11807 | 11877 |
11808 v8::Handle<Value> value = CompileRun( | 11878 v8::Handle<Value> value = CompileRun( |
11809 "try {" | 11879 "try {" |
11810 " o.__proto__ = this;" | 11880 " o.__proto__ = this;" |
11811 " for (var i = 0; i < 10; i++) {" | 11881 " for (var i = 0; i < 10; i++) {" |
11812 " var v = o.parseFloat('239');" | 11882 " var v = o.parseFloat('239');" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11881 // This should move the stub | 11951 // This should move the stub |
11882 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed | 11952 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
11883 } | 11953 } |
11884 } | 11954 } |
11885 | 11955 |
11886 | 11956 |
11887 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { | 11957 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
11888 LocalContext context; | 11958 LocalContext context; |
11889 v8::Isolate* isolate = context->GetIsolate(); | 11959 v8::Isolate* isolate = context->GetIsolate(); |
11890 v8::HandleScope scope(isolate); | 11960 v8::HandleScope scope(isolate); |
11891 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); | 11961 v8::Handle<v8::ObjectTemplate> nativeobject_templ = |
| 11962 v8::ObjectTemplate::New(isolate); |
11892 nativeobject_templ->Set(isolate, "callback", | 11963 nativeobject_templ->Set(isolate, "callback", |
11893 v8::FunctionTemplate::New(isolate, | 11964 v8::FunctionTemplate::New(isolate, |
11894 DirectApiCallback)); | 11965 DirectApiCallback)); |
11895 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11966 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
11896 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11967 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
11897 // call the api function multiple times to ensure direct call stub creation. | 11968 // call the api function multiple times to ensure direct call stub creation. |
11898 CompileRun( | 11969 CompileRun( |
11899 "function f() {" | 11970 "function f() {" |
11900 " for (var i = 1; i <= 30; i++) {" | 11971 " for (var i = 1; i <= 30; i++) {" |
11901 " nativeobject.callback();" | 11972 " nativeobject.callback();" |
11902 " }" | 11973 " }" |
11903 "}" | 11974 "}" |
11904 "f();"); | 11975 "f();"); |
11905 } | 11976 } |
11906 | 11977 |
11907 | 11978 |
11908 void ThrowingDirectApiCallback( | 11979 void ThrowingDirectApiCallback( |
11909 const v8::FunctionCallbackInfo<v8::Value>& args) { | 11980 const v8::FunctionCallbackInfo<v8::Value>& args) { |
11910 args.GetIsolate()->ThrowException(v8_str("g")); | 11981 args.GetIsolate()->ThrowException(v8_str("g")); |
11911 } | 11982 } |
11912 | 11983 |
11913 | 11984 |
11914 THREADED_TEST(CallICFastApi_DirectCall_Throw) { | 11985 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
11915 LocalContext context; | 11986 LocalContext context; |
11916 v8::Isolate* isolate = context->GetIsolate(); | 11987 v8::Isolate* isolate = context->GetIsolate(); |
11917 v8::HandleScope scope(isolate); | 11988 v8::HandleScope scope(isolate); |
11918 v8::Handle<v8::ObjectTemplate> nativeobject_templ = | 11989 v8::Handle<v8::ObjectTemplate> nativeobject_templ = |
11919 v8::ObjectTemplate::New(); | 11990 v8::ObjectTemplate::New(isolate); |
11920 nativeobject_templ->Set(isolate, "callback", | 11991 nativeobject_templ->Set(isolate, "callback", |
11921 v8::FunctionTemplate::New(isolate, | 11992 v8::FunctionTemplate::New(isolate, |
11922 ThrowingDirectApiCallback)); | 11993 ThrowingDirectApiCallback)); |
11923 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11994 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); |
11924 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11995 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); |
11925 // call the api function multiple times to ensure direct call stub creation. | 11996 // call the api function multiple times to ensure direct call stub creation. |
11926 v8::Handle<Value> result = CompileRun( | 11997 v8::Handle<Value> result = CompileRun( |
11927 "var result = '';" | 11998 "var result = '';" |
11928 "function f() {" | 11999 "function f() {" |
11929 " for (var i = 1; i <= 5; i++) {" | 12000 " for (var i = 1; i <= 5; i++) {" |
(...skipping 17 matching lines...) Expand all Loading... |
11947 Local<String> name, | 12018 Local<String> name, |
11948 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12019 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11949 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); | 12020 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); |
11950 info.GetReturnValue().Set(DoDirectGetter()); | 12021 info.GetReturnValue().Set(DoDirectGetter()); |
11951 } | 12022 } |
11952 | 12023 |
11953 | 12024 |
11954 template<typename Accessor> | 12025 template<typename Accessor> |
11955 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { | 12026 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { |
11956 LocalContext context; | 12027 LocalContext context; |
11957 v8::HandleScope scope(context->GetIsolate()); | 12028 v8::Isolate* isolate = context->GetIsolate(); |
11958 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); | 12029 v8::HandleScope scope(isolate); |
| 12030 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); |
11959 obj->SetAccessor(v8_str("p1"), accessor); | 12031 obj->SetAccessor(v8_str("p1"), accessor); |
11960 context->Global()->Set(v8_str("o1"), obj->NewInstance()); | 12032 context->Global()->Set(v8_str("o1"), obj->NewInstance()); |
11961 p_getter_count = 0; | 12033 p_getter_count = 0; |
11962 v8::Handle<v8::Value> result = CompileRun( | 12034 v8::Handle<v8::Value> result = CompileRun( |
11963 "function f() {" | 12035 "function f() {" |
11964 " for (var i = 0; i < 30; i++) o1.p1;" | 12036 " for (var i = 0; i < 30; i++) o1.p1;" |
11965 " return o1.p1" | 12037 " return o1.p1" |
11966 "}" | 12038 "}" |
11967 "f();"); | 12039 "f();"); |
11968 CHECK_EQ(v8_str("Direct Getter Result"), result); | 12040 CHECK_EQ(v8_str("Direct Getter Result"), result); |
11969 CHECK_EQ(31, p_getter_count); | 12041 CHECK_EQ(31, p_getter_count); |
11970 } | 12042 } |
11971 | 12043 |
11972 | 12044 |
11973 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { | 12045 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { |
11974 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); | 12046 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); |
11975 } | 12047 } |
11976 | 12048 |
11977 | 12049 |
11978 void ThrowingDirectGetterCallback( | 12050 void ThrowingDirectGetterCallback( |
11979 Local<String> name, | 12051 Local<String> name, |
11980 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12052 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11981 info.GetIsolate()->ThrowException(v8_str("g")); | 12053 info.GetIsolate()->ThrowException(v8_str("g")); |
11982 } | 12054 } |
11983 | 12055 |
11984 | 12056 |
11985 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { | 12057 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { |
11986 LocalContext context; | 12058 LocalContext context; |
11987 v8::HandleScope scope(context->GetIsolate()); | 12059 v8::Isolate* isolate = context->GetIsolate(); |
11988 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); | 12060 v8::HandleScope scope(isolate); |
| 12061 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); |
11989 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); | 12062 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); |
11990 context->Global()->Set(v8_str("o1"), obj->NewInstance()); | 12063 context->Global()->Set(v8_str("o1"), obj->NewInstance()); |
11991 v8::Handle<Value> result = CompileRun( | 12064 v8::Handle<Value> result = CompileRun( |
11992 "var result = '';" | 12065 "var result = '';" |
11993 "for (var i = 0; i < 5; i++) {" | 12066 "for (var i = 0; i < 5; i++) {" |
11994 " try { o1.p1; } catch (e) { result += e; }" | 12067 " try { o1.p1; } catch (e) { result += e; }" |
11995 "}" | 12068 "}" |
11996 "result;"); | 12069 "result;"); |
11997 CHECK_EQ(v8_str("ggggg"), result); | 12070 CHECK_EQ(v8_str("ggggg"), result); |
11998 } | 12071 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12401 ApiTestFuzzer::Fuzz(); | 12474 ApiTestFuzzer::Fuzz(); |
12402 if (v8_str("x")->Equals(name)) { | 12475 if (v8_str("x")->Equals(name)) { |
12403 info.GetReturnValue().Set(keyed_call_ic_function); | 12476 info.GetReturnValue().Set(keyed_call_ic_function); |
12404 } | 12477 } |
12405 } | 12478 } |
12406 | 12479 |
12407 | 12480 |
12408 // Test the case when we stored cacheable lookup into | 12481 // Test the case when we stored cacheable lookup into |
12409 // a stub, but the function name changed (to another cacheable function). | 12482 // a stub, but the function name changed (to another cacheable function). |
12410 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { | 12483 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { |
12411 v8::HandleScope scope(CcTest::isolate()); | 12484 v8::Isolate* isolate = CcTest::isolate(); |
12412 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12485 v8::HandleScope scope(isolate); |
| 12486 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12413 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12487 templ->SetNamedPropertyHandler(NoBlockGetterX); |
12414 LocalContext context; | 12488 LocalContext context; |
12415 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12489 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12416 CompileRun( | 12490 CompileRun( |
12417 "proto = new Object();" | 12491 "proto = new Object();" |
12418 "proto.y = function(x) { return x + 1; };" | 12492 "proto.y = function(x) { return x + 1; };" |
12419 "proto.z = function(x) { return x - 1; };" | 12493 "proto.z = function(x) { return x - 1; };" |
12420 "o.__proto__ = proto;" | 12494 "o.__proto__ = proto;" |
12421 "var result = 0;" | 12495 "var result = 0;" |
12422 "var method = 'y';" | 12496 "var method = 'y';" |
12423 "for (var i = 0; i < 10; i++) {" | 12497 "for (var i = 0; i < 10; i++) {" |
12424 " if (i == 5) { method = 'z'; };" | 12498 " if (i == 5) { method = 'z'; };" |
12425 " result += o[method](41);" | 12499 " result += o[method](41);" |
12426 "}"); | 12500 "}"); |
12427 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 12501 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
12428 } | 12502 } |
12429 | 12503 |
12430 | 12504 |
12431 // Test the case when we stored cacheable lookup into | 12505 // Test the case when we stored cacheable lookup into |
12432 // a stub, but the function name changed (and the new function is present | 12506 // a stub, but the function name changed (and the new function is present |
12433 // both before and after the interceptor in the prototype chain). | 12507 // both before and after the interceptor in the prototype chain). |
12434 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { | 12508 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { |
12435 v8::HandleScope scope(CcTest::isolate()); | 12509 v8::Isolate* isolate = CcTest::isolate(); |
12436 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12510 v8::HandleScope scope(isolate); |
| 12511 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12437 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); | 12512 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); |
12438 LocalContext context; | 12513 LocalContext context; |
12439 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); | 12514 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); |
12440 keyed_call_ic_function = | 12515 keyed_call_ic_function = |
12441 v8_compile("function f(x) { return x - 1; }; f")->Run(); | 12516 v8_compile("function f(x) { return x - 1; }; f")->Run(); |
12442 CompileRun( | 12517 CompileRun( |
12443 "o = new Object();" | 12518 "o = new Object();" |
12444 "proto2 = new Object();" | 12519 "proto2 = new Object();" |
12445 "o.y = function(x) { return x + 1; };" | 12520 "o.y = function(x) { return x + 1; };" |
12446 "proto2.y = function(x) { return x + 2; };" | 12521 "proto2.y = function(x) { return x + 2; };" |
12447 "o.__proto__ = proto1;" | 12522 "o.__proto__ = proto1;" |
12448 "proto1.__proto__ = proto2;" | 12523 "proto1.__proto__ = proto2;" |
12449 "var result = 0;" | 12524 "var result = 0;" |
12450 "var method = 'x';" | 12525 "var method = 'x';" |
12451 "for (var i = 0; i < 10; i++) {" | 12526 "for (var i = 0; i < 10; i++) {" |
12452 " if (i == 5) { method = 'y'; };" | 12527 " if (i == 5) { method = 'y'; };" |
12453 " result += o[method](41);" | 12528 " result += o[method](41);" |
12454 "}"); | 12529 "}"); |
12455 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 12530 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
12456 } | 12531 } |
12457 | 12532 |
12458 | 12533 |
12459 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit | 12534 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit |
12460 // on the global object. | 12535 // on the global object. |
12461 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { | 12536 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { |
12462 v8::HandleScope scope(CcTest::isolate()); | 12537 v8::Isolate* isolate = CcTest::isolate(); |
12463 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12538 v8::HandleScope scope(isolate); |
| 12539 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12464 templ->SetNamedPropertyHandler(NoBlockGetterX); | 12540 templ->SetNamedPropertyHandler(NoBlockGetterX); |
12465 LocalContext context; | 12541 LocalContext context; |
12466 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 12542 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
12467 CompileRun( | 12543 CompileRun( |
12468 "function inc(x) { return x + 1; };" | 12544 "function inc(x) { return x + 1; };" |
12469 "inc(1);" | 12545 "inc(1);" |
12470 "function dec(x) { return x - 1; };" | 12546 "function dec(x) { return x - 1; };" |
12471 "dec(1);" | 12547 "dec(1);" |
12472 "o.__proto__ = this;" | 12548 "o.__proto__ = this;" |
12473 "this.__proto__.x = inc;" | 12549 "this.__proto__.x = inc;" |
12474 "this.__proto__.y = dec;" | 12550 "this.__proto__.y = dec;" |
12475 "var result = 0;" | 12551 "var result = 0;" |
12476 "var method = 'x';" | 12552 "var method = 'x';" |
12477 "for (var i = 0; i < 10; i++) {" | 12553 "for (var i = 0; i < 10; i++) {" |
12478 " if (i == 5) { method = 'y'; };" | 12554 " if (i == 5) { method = 'y'; };" |
12479 " result += o[method](41);" | 12555 " result += o[method](41);" |
12480 "}"); | 12556 "}"); |
12481 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 12557 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
12482 } | 12558 } |
12483 | 12559 |
12484 | 12560 |
12485 // Test the case when actual function to call sits on global object. | 12561 // Test the case when actual function to call sits on global object. |
12486 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { | 12562 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { |
12487 v8::HandleScope scope(CcTest::isolate()); | 12563 v8::Isolate* isolate = CcTest::isolate(); |
12488 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 12564 v8::HandleScope scope(isolate); |
| 12565 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12489 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 12566 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
12490 LocalContext context; | 12567 LocalContext context; |
12491 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12568 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12492 | 12569 |
12493 CompileRun( | 12570 CompileRun( |
12494 "function len(x) { return x.length; };" | 12571 "function len(x) { return x.length; };" |
12495 "o.__proto__ = this;" | 12572 "o.__proto__ = this;" |
12496 "var m = 'parseFloat';" | 12573 "var m = 'parseFloat';" |
12497 "var result = 0;" | 12574 "var result = 0;" |
12498 "for (var i = 0; i < 10; i++) {" | 12575 "for (var i = 0; i < 10; i++) {" |
12499 " if (i == 5) {" | 12576 " if (i == 5) {" |
12500 " m = 'len';" | 12577 " m = 'len';" |
12501 " saved_result = result;" | 12578 " saved_result = result;" |
12502 " };" | 12579 " };" |
12503 " result = o[m]('239');" | 12580 " result = o[m]('239');" |
12504 "}"); | 12581 "}"); |
12505 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); | 12582 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); |
12506 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12583 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); |
12507 } | 12584 } |
12508 | 12585 |
12509 | 12586 |
12510 // Test the map transition before the interceptor. | 12587 // Test the map transition before the interceptor. |
12511 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { | 12588 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { |
12512 v8::HandleScope scope(CcTest::isolate()); | 12589 v8::Isolate* isolate = CcTest::isolate(); |
12513 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 12590 v8::HandleScope scope(isolate); |
| 12591 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12514 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 12592 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
12515 LocalContext context; | 12593 LocalContext context; |
12516 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); | 12594 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); |
12517 | 12595 |
12518 CompileRun( | 12596 CompileRun( |
12519 "var o = new Object();" | 12597 "var o = new Object();" |
12520 "o.__proto__ = proto;" | 12598 "o.__proto__ = proto;" |
12521 "o.method = function(x) { return x + 1; };" | 12599 "o.method = function(x) { return x + 1; };" |
12522 "var m = 'method';" | 12600 "var m = 'method';" |
12523 "var result = 0;" | 12601 "var result = 0;" |
12524 "for (var i = 0; i < 10; i++) {" | 12602 "for (var i = 0; i < 10; i++) {" |
12525 " if (i == 5) { o.method = function(x) { return x - 1; }; };" | 12603 " if (i == 5) { o.method = function(x) { return x - 1; }; };" |
12526 " result += o[m](41);" | 12604 " result += o[m](41);" |
12527 "}"); | 12605 "}"); |
12528 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); | 12606 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); |
12529 } | 12607 } |
12530 | 12608 |
12531 | 12609 |
12532 // Test the map transition after the interceptor. | 12610 // Test the map transition after the interceptor. |
12533 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { | 12611 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { |
12534 v8::HandleScope scope(CcTest::isolate()); | 12612 v8::Isolate* isolate = CcTest::isolate(); |
12535 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); | 12613 v8::HandleScope scope(isolate); |
| 12614 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(isolate); |
12536 templ_o->SetNamedPropertyHandler(NoBlockGetterX); | 12615 templ_o->SetNamedPropertyHandler(NoBlockGetterX); |
12537 LocalContext context; | 12616 LocalContext context; |
12538 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); | 12617 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); |
12539 | 12618 |
12540 CompileRun( | 12619 CompileRun( |
12541 "var proto = new Object();" | 12620 "var proto = new Object();" |
12542 "o.__proto__ = proto;" | 12621 "o.__proto__ = proto;" |
12543 "proto.method = function(x) { return x + 1; };" | 12622 "proto.method = function(x) { return x + 1; };" |
12544 "var m = 'method';" | 12623 "var m = 'method';" |
12545 "var result = 0;" | 12624 "var result = 0;" |
(...skipping 14 matching lines...) Expand all Loading... |
12560 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { | 12639 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { |
12561 info.GetReturnValue().Set(call_ic_function2); | 12640 info.GetReturnValue().Set(call_ic_function2); |
12562 } | 12641 } |
12563 } | 12642 } |
12564 | 12643 |
12565 | 12644 |
12566 // This test should hit load and call ICs for the interceptor case. | 12645 // This test should hit load and call ICs for the interceptor case. |
12567 // Once in a while, the interceptor will reply that a property was not | 12646 // Once in a while, the interceptor will reply that a property was not |
12568 // found in which case we should get a reference error. | 12647 // found in which case we should get a reference error. |
12569 THREADED_TEST(InterceptorICReferenceErrors) { | 12648 THREADED_TEST(InterceptorICReferenceErrors) { |
12570 v8::HandleScope scope(CcTest::isolate()); | 12649 v8::Isolate* isolate = CcTest::isolate(); |
12571 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12650 v8::HandleScope scope(isolate); |
| 12651 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12572 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); | 12652 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); |
12573 LocalContext context(0, templ, v8::Handle<Value>()); | 12653 LocalContext context(0, templ, v8::Handle<Value>()); |
12574 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); | 12654 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); |
12575 v8::Handle<Value> value = CompileRun( | 12655 v8::Handle<Value> value = CompileRun( |
12576 "function f() {" | 12656 "function f() {" |
12577 " for (var i = 0; i < 1000; i++) {" | 12657 " for (var i = 0; i < 1000; i++) {" |
12578 " try { x; } catch(e) { return true; }" | 12658 " try { x; } catch(e) { return true; }" |
12579 " }" | 12659 " }" |
12580 " return false;" | 12660 " return false;" |
12581 "};" | 12661 "};" |
(...skipping 25 matching lines...) Expand all Loading... |
12607 info.GetIsolate()->ThrowException(v8_num(42)); | 12687 info.GetIsolate()->ThrowException(v8_num(42)); |
12608 return; | 12688 return; |
12609 } | 12689 } |
12610 } | 12690 } |
12611 | 12691 |
12612 | 12692 |
12613 // Test interceptor load/call IC where the interceptor throws an | 12693 // Test interceptor load/call IC where the interceptor throws an |
12614 // exception once in a while. | 12694 // exception once in a while. |
12615 THREADED_TEST(InterceptorICGetterExceptions) { | 12695 THREADED_TEST(InterceptorICGetterExceptions) { |
12616 interceptor_ic_exception_get_count = 0; | 12696 interceptor_ic_exception_get_count = 0; |
12617 v8::HandleScope scope(CcTest::isolate()); | 12697 v8::Isolate* isolate = CcTest::isolate(); |
12618 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12698 v8::HandleScope scope(isolate); |
| 12699 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12619 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); | 12700 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); |
12620 LocalContext context(0, templ, v8::Handle<Value>()); | 12701 LocalContext context(0, templ, v8::Handle<Value>()); |
12621 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); | 12702 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); |
12622 v8::Handle<Value> value = CompileRun( | 12703 v8::Handle<Value> value = CompileRun( |
12623 "function f() {" | 12704 "function f() {" |
12624 " for (var i = 0; i < 100; i++) {" | 12705 " for (var i = 0; i < 100; i++) {" |
12625 " try { x; } catch(e) { return true; }" | 12706 " try { x; } catch(e) { return true; }" |
12626 " }" | 12707 " }" |
12627 " return false;" | 12708 " return false;" |
12628 "};" | 12709 "};" |
(...skipping 22 matching lines...) Expand all Loading... |
12651 if (++interceptor_ic_exception_set_count > 20) { | 12732 if (++interceptor_ic_exception_set_count > 20) { |
12652 info.GetIsolate()->ThrowException(v8_num(42)); | 12733 info.GetIsolate()->ThrowException(v8_num(42)); |
12653 } | 12734 } |
12654 } | 12735 } |
12655 | 12736 |
12656 | 12737 |
12657 // Test interceptor store IC where the interceptor throws an exception | 12738 // Test interceptor store IC where the interceptor throws an exception |
12658 // once in a while. | 12739 // once in a while. |
12659 THREADED_TEST(InterceptorICSetterExceptions) { | 12740 THREADED_TEST(InterceptorICSetterExceptions) { |
12660 interceptor_ic_exception_set_count = 0; | 12741 interceptor_ic_exception_set_count = 0; |
12661 v8::HandleScope scope(CcTest::isolate()); | 12742 v8::Isolate* isolate = CcTest::isolate(); |
12662 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12743 v8::HandleScope scope(isolate); |
| 12744 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12663 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); | 12745 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); |
12664 LocalContext context(0, templ, v8::Handle<Value>()); | 12746 LocalContext context(0, templ, v8::Handle<Value>()); |
12665 v8::Handle<Value> value = CompileRun( | 12747 v8::Handle<Value> value = CompileRun( |
12666 "function f() {" | 12748 "function f() {" |
12667 " for (var i = 0; i < 100; i++) {" | 12749 " for (var i = 0; i < 100; i++) {" |
12668 " try { x = 42; } catch(e) { return true; }" | 12750 " try { x = 42; } catch(e) { return true; }" |
12669 " }" | 12751 " }" |
12670 " return false;" | 12752 " return false;" |
12671 "};" | 12753 "};" |
12672 "f();"); | 12754 "f();"); |
12673 CHECK_EQ(true, value->BooleanValue()); | 12755 CHECK_EQ(true, value->BooleanValue()); |
12674 } | 12756 } |
12675 | 12757 |
12676 | 12758 |
12677 // Test that we ignore null interceptors. | 12759 // Test that we ignore null interceptors. |
12678 THREADED_TEST(NullNamedInterceptor) { | 12760 THREADED_TEST(NullNamedInterceptor) { |
12679 v8::HandleScope scope(CcTest::isolate()); | 12761 v8::Isolate* isolate = CcTest::isolate(); |
12680 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12762 v8::HandleScope scope(isolate); |
| 12763 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12681 templ->SetNamedPropertyHandler( | 12764 templ->SetNamedPropertyHandler( |
12682 static_cast<v8::NamedPropertyGetterCallback>(0)); | 12765 static_cast<v8::NamedPropertyGetterCallback>(0)); |
12683 LocalContext context; | 12766 LocalContext context; |
12684 templ->Set(CcTest::isolate(), "x", v8_num(42)); | 12767 templ->Set(CcTest::isolate(), "x", v8_num(42)); |
12685 v8::Handle<v8::Object> obj = templ->NewInstance(); | 12768 v8::Handle<v8::Object> obj = templ->NewInstance(); |
12686 context->Global()->Set(v8_str("obj"), obj); | 12769 context->Global()->Set(v8_str("obj"), obj); |
12687 v8::Handle<Value> value = CompileRun("obj.x"); | 12770 v8::Handle<Value> value = CompileRun("obj.x"); |
12688 CHECK(value->IsInt32()); | 12771 CHECK(value->IsInt32()); |
12689 CHECK_EQ(42, value->Int32Value()); | 12772 CHECK_EQ(42, value->Int32Value()); |
12690 } | 12773 } |
12691 | 12774 |
12692 | 12775 |
12693 // Test that we ignore null interceptors. | 12776 // Test that we ignore null interceptors. |
12694 THREADED_TEST(NullIndexedInterceptor) { | 12777 THREADED_TEST(NullIndexedInterceptor) { |
12695 v8::HandleScope scope(CcTest::isolate()); | 12778 v8::Isolate* isolate = CcTest::isolate(); |
12696 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | 12779 v8::HandleScope scope(isolate); |
| 12780 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
12697 templ->SetIndexedPropertyHandler( | 12781 templ->SetIndexedPropertyHandler( |
12698 static_cast<v8::IndexedPropertyGetterCallback>(0)); | 12782 static_cast<v8::IndexedPropertyGetterCallback>(0)); |
12699 LocalContext context; | 12783 LocalContext context; |
12700 templ->Set(CcTest::isolate(), "42", v8_num(42)); | 12784 templ->Set(CcTest::isolate(), "42", v8_num(42)); |
12701 v8::Handle<v8::Object> obj = templ->NewInstance(); | 12785 v8::Handle<v8::Object> obj = templ->NewInstance(); |
12702 context->Global()->Set(v8_str("obj"), obj); | 12786 context->Global()->Set(v8_str("obj"), obj); |
12703 v8::Handle<Value> value = CompileRun("obj[42]"); | 12787 v8::Handle<Value> value = CompileRun("obj[42]"); |
12704 CHECK(value->IsInt32()); | 12788 CHECK(value->IsInt32()); |
12705 CHECK_EQ(42, value->Int32Value()); | 12789 CHECK_EQ(42, value->Int32Value()); |
12706 } | 12790 } |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13790 | 13874 |
13791 return invocations; | 13875 return invocations; |
13792 } | 13876 } |
13793 | 13877 |
13794 | 13878 |
13795 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { | 13879 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { |
13796 v8::HandleScope outer(isolate); | 13880 v8::HandleScope outer(isolate); |
13797 v8::Local<Context> env = Context::New(isolate); | 13881 v8::Local<Context> env = Context::New(isolate); |
13798 env->Enter(); | 13882 env->Enter(); |
13799 | 13883 |
13800 Local<ObjectTemplate> t = ObjectTemplate::New(); | 13884 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); |
13801 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); | 13885 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); |
13802 env->Global()->Set(v8_str("obj"), t->NewInstance()); | 13886 env->Global()->Set(v8_str("obj"), t->NewInstance()); |
13803 | 13887 |
13804 const char* script = | 13888 const char* script = |
13805 "function bar() {\n" | 13889 "function bar() {\n" |
13806 " var sum = 0;\n" | 13890 " var sum = 0;\n" |
13807 " for (i = 0; i < 100; ++i)\n" | 13891 " for (i = 0; i < 100; ++i)\n" |
13808 " sum = foo(i);\n" | 13892 " sum = foo(i);\n" |
13809 " return sum;\n" | 13893 " return sum;\n" |
13810 "}\n" | 13894 "}\n" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14160 // Regression test for issue 54, object templates with internal fields | 14244 // Regression test for issue 54, object templates with internal fields |
14161 // but no accessors or interceptors did not get their internal field | 14245 // but no accessors or interceptors did not get their internal field |
14162 // count set on instances. | 14246 // count set on instances. |
14163 THREADED_TEST(Regress54) { | 14247 THREADED_TEST(Regress54) { |
14164 LocalContext context; | 14248 LocalContext context; |
14165 v8::Isolate* isolate = context->GetIsolate(); | 14249 v8::Isolate* isolate = context->GetIsolate(); |
14166 v8::HandleScope outer(isolate); | 14250 v8::HandleScope outer(isolate); |
14167 static v8::Persistent<v8::ObjectTemplate> templ; | 14251 static v8::Persistent<v8::ObjectTemplate> templ; |
14168 if (templ.IsEmpty()) { | 14252 if (templ.IsEmpty()) { |
14169 v8::EscapableHandleScope inner(isolate); | 14253 v8::EscapableHandleScope inner(isolate); |
14170 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); | 14254 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate); |
14171 local->SetInternalFieldCount(1); | 14255 local->SetInternalFieldCount(1); |
14172 templ.Reset(isolate, inner.Escape(local)); | 14256 templ.Reset(isolate, inner.Escape(local)); |
14173 } | 14257 } |
14174 v8::Handle<v8::Object> result = | 14258 v8::Handle<v8::Object> result = |
14175 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); | 14259 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); |
14176 CHECK_EQ(1, result->InternalFieldCount()); | 14260 CHECK_EQ(1, result->InternalFieldCount()); |
14177 } | 14261 } |
14178 | 14262 |
14179 | 14263 |
14180 // If part of the threaded tests, this test makes ThreadingTest fail | 14264 // If part of the threaded tests, this test makes ThreadingTest fail |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14281 const v8::FunctionCallbackInfo<v8::Value>& args) { | 14365 const v8::FunctionCallbackInfo<v8::Value>& args) { |
14282 ApiTestFuzzer::Fuzz(); | 14366 ApiTestFuzzer::Fuzz(); |
14283 args.GetReturnValue().Set(v8_num(42)); | 14367 args.GetReturnValue().Set(v8_num(42)); |
14284 } | 14368 } |
14285 | 14369 |
14286 | 14370 |
14287 THREADED_TEST(CallbackFunctionName) { | 14371 THREADED_TEST(CallbackFunctionName) { |
14288 LocalContext context; | 14372 LocalContext context; |
14289 v8::Isolate* isolate = context->GetIsolate(); | 14373 v8::Isolate* isolate = context->GetIsolate(); |
14290 v8::HandleScope scope(isolate); | 14374 v8::HandleScope scope(isolate); |
14291 Local<ObjectTemplate> t = ObjectTemplate::New(); | 14375 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); |
14292 t->Set(v8_str("asdf"), | 14376 t->Set(v8_str("asdf"), |
14293 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); | 14377 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); |
14294 context->Global()->Set(v8_str("obj"), t->NewInstance()); | 14378 context->Global()->Set(v8_str("obj"), t->NewInstance()); |
14295 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); | 14379 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); |
14296 CHECK(value->IsString()); | 14380 CHECK(value->IsString()); |
14297 v8::String::Utf8Value name(value); | 14381 v8::String::Utf8Value name(value); |
14298 CHECK_EQ("asdf", *name); | 14382 CHECK_EQ("asdf", *name); |
14299 } | 14383 } |
14300 | 14384 |
14301 | 14385 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14424 v8::AccessType type, | 14508 v8::AccessType type, |
14425 Local<Value> data) { | 14509 Local<Value> data) { |
14426 return type != v8::ACCESS_SET; | 14510 return type != v8::ACCESS_SET; |
14427 } | 14511 } |
14428 | 14512 |
14429 | 14513 |
14430 THREADED_TEST(DisableAccessChecksWhileConfiguring) { | 14514 THREADED_TEST(DisableAccessChecksWhileConfiguring) { |
14431 LocalContext context; | 14515 LocalContext context; |
14432 v8::Isolate* isolate = context->GetIsolate(); | 14516 v8::Isolate* isolate = context->GetIsolate(); |
14433 v8::HandleScope scope(isolate); | 14517 v8::HandleScope scope(isolate); |
14434 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 14518 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
14435 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 14519 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
14436 IndexedSetAccessBlocker); | 14520 IndexedSetAccessBlocker); |
14437 templ->Set(v8_str("x"), v8::True(isolate)); | 14521 templ->Set(v8_str("x"), v8::True(isolate)); |
14438 Local<v8::Object> instance = templ->NewInstance(); | 14522 Local<v8::Object> instance = templ->NewInstance(); |
14439 context->Global()->Set(v8_str("obj"), instance); | 14523 context->Global()->Set(v8_str("obj"), instance); |
14440 Local<Value> value = CompileRun("obj.x"); | 14524 Local<Value> value = CompileRun("obj.x"); |
14441 CHECK(value->BooleanValue()); | 14525 CHECK(value->BooleanValue()); |
14442 } | 14526 } |
14443 | 14527 |
14444 | 14528 |
14445 static bool NamedGetAccessBlocker(Local<v8::Object> obj, | 14529 static bool NamedGetAccessBlocker(Local<v8::Object> obj, |
14446 Local<Value> name, | 14530 Local<Value> name, |
14447 v8::AccessType type, | 14531 v8::AccessType type, |
14448 Local<Value> data) { | 14532 Local<Value> data) { |
14449 return false; | 14533 return false; |
14450 } | 14534 } |
14451 | 14535 |
14452 | 14536 |
14453 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, | 14537 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, |
14454 uint32_t key, | 14538 uint32_t key, |
14455 v8::AccessType type, | 14539 v8::AccessType type, |
14456 Local<Value> data) { | 14540 Local<Value> data) { |
14457 return false; | 14541 return false; |
14458 } | 14542 } |
14459 | 14543 |
14460 | 14544 |
14461 | 14545 |
14462 THREADED_TEST(AccessChecksReenabledCorrectly) { | 14546 THREADED_TEST(AccessChecksReenabledCorrectly) { |
14463 LocalContext context; | 14547 LocalContext context; |
14464 v8::HandleScope scope(context->GetIsolate()); | 14548 v8::Isolate* isolate = context->GetIsolate(); |
14465 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 14549 v8::HandleScope scope(isolate); |
| 14550 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
14466 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, | 14551 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
14467 IndexedGetAccessBlocker); | 14552 IndexedGetAccessBlocker); |
14468 templ->Set(v8_str("a"), v8_str("a")); | 14553 templ->Set(v8_str("a"), v8_str("a")); |
14469 // Add more than 8 (see kMaxFastProperties) properties | 14554 // Add more than 8 (see kMaxFastProperties) properties |
14470 // so that the constructor will force copying map. | 14555 // so that the constructor will force copying map. |
14471 // Cannot sprintf, gcc complains unsafety. | 14556 // Cannot sprintf, gcc complains unsafety. |
14472 char buf[4]; | 14557 char buf[4]; |
14473 for (char i = '0'; i <= '9' ; i++) { | 14558 for (char i = '0'; i <= '9' ; i++) { |
14474 buf[0] = i; | 14559 buf[0] = i; |
14475 for (char j = '0'; j <= '9'; j++) { | 14560 for (char j = '0'; j <= '9'; j++) { |
14476 buf[1] = j; | 14561 buf[1] = j; |
14477 for (char k = '0'; k <= '9'; k++) { | 14562 for (char k = '0'; k <= '9'; k++) { |
14478 buf[2] = k; | 14563 buf[2] = k; |
14479 buf[3] = 0; | 14564 buf[3] = 0; |
14480 templ->Set(v8_str(buf), v8::Number::New(context->GetIsolate(), k)); | 14565 templ->Set(v8_str(buf), v8::Number::New(isolate, k)); |
14481 } | 14566 } |
14482 } | 14567 } |
14483 } | 14568 } |
14484 | 14569 |
14485 Local<v8::Object> instance_1 = templ->NewInstance(); | 14570 Local<v8::Object> instance_1 = templ->NewInstance(); |
14486 context->Global()->Set(v8_str("obj_1"), instance_1); | 14571 context->Global()->Set(v8_str("obj_1"), instance_1); |
14487 | 14572 |
14488 Local<Value> value_1 = CompileRun("obj_1.a"); | 14573 Local<Value> value_1 = CompileRun("obj_1.a"); |
14489 CHECK(value_1->IsUndefined()); | 14574 CHECK(value_1->IsUndefined()); |
14490 | 14575 |
14491 Local<v8::Object> instance_2 = templ->NewInstance(); | 14576 Local<v8::Object> instance_2 = templ->NewInstance(); |
14492 context->Global()->Set(v8_str("obj_2"), instance_2); | 14577 context->Global()->Set(v8_str("obj_2"), instance_2); |
14493 | 14578 |
14494 Local<Value> value_2 = CompileRun("obj_2.a"); | 14579 Local<Value> value_2 = CompileRun("obj_2.a"); |
14495 CHECK(value_2->IsUndefined()); | 14580 CHECK(value_2->IsUndefined()); |
14496 } | 14581 } |
14497 | 14582 |
14498 | 14583 |
14499 // This tests that access check information remains on the global | 14584 // This tests that access check information remains on the global |
14500 // object template when creating contexts. | 14585 // object template when creating contexts. |
14501 THREADED_TEST(AccessControlRepeatedContextCreation) { | 14586 THREADED_TEST(AccessControlRepeatedContextCreation) { |
14502 v8::Isolate* isolate = CcTest::isolate(); | 14587 v8::Isolate* isolate = CcTest::isolate(); |
14503 v8::HandleScope handle_scope(isolate); | 14588 v8::HandleScope handle_scope(isolate); |
14504 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 14589 v8::Handle<v8::ObjectTemplate> global_template = |
| 14590 v8::ObjectTemplate::New(isolate); |
14505 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 14591 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
14506 IndexedSetAccessBlocker); | 14592 IndexedSetAccessBlocker); |
14507 i::Handle<i::ObjectTemplateInfo> internal_template = | 14593 i::Handle<i::ObjectTemplateInfo> internal_template = |
14508 v8::Utils::OpenHandle(*global_template); | 14594 v8::Utils::OpenHandle(*global_template); |
14509 CHECK(!internal_template->constructor()->IsUndefined()); | 14595 CHECK(!internal_template->constructor()->IsUndefined()); |
14510 i::Handle<i::FunctionTemplateInfo> constructor( | 14596 i::Handle<i::FunctionTemplateInfo> constructor( |
14511 i::FunctionTemplateInfo::cast(internal_template->constructor())); | 14597 i::FunctionTemplateInfo::cast(internal_template->constructor())); |
14512 CHECK(!constructor->access_check_info()->IsUndefined()); | 14598 CHECK(!constructor->access_check_info()->IsUndefined()); |
14513 v8::Local<Context> context0(Context::New(isolate, NULL, global_template)); | 14599 v8::Local<Context> context0(Context::New(isolate, NULL, global_template)); |
14514 CHECK(!context0.IsEmpty()); | 14600 CHECK(!context0.IsEmpty()); |
14515 CHECK(!constructor->access_check_info()->IsUndefined()); | 14601 CHECK(!constructor->access_check_info()->IsUndefined()); |
14516 } | 14602 } |
14517 | 14603 |
14518 | 14604 |
14519 THREADED_TEST(TurnOnAccessCheck) { | 14605 THREADED_TEST(TurnOnAccessCheck) { |
14520 v8::Isolate* isolate = CcTest::isolate(); | 14606 v8::Isolate* isolate = CcTest::isolate(); |
14521 v8::HandleScope handle_scope(isolate); | 14607 v8::HandleScope handle_scope(isolate); |
14522 | 14608 |
14523 // Create an environment with access check to the global object disabled by | 14609 // Create an environment with access check to the global object disabled by |
14524 // default. | 14610 // default. |
14525 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 14611 v8::Handle<v8::ObjectTemplate> global_template = |
| 14612 v8::ObjectTemplate::New(isolate); |
14526 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, | 14613 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
14527 IndexedGetAccessBlocker, | 14614 IndexedGetAccessBlocker, |
14528 v8::Handle<v8::Value>(), | 14615 v8::Handle<v8::Value>(), |
14529 false); | 14616 false); |
14530 v8::Local<Context> context = Context::New(isolate, NULL, global_template); | 14617 v8::Local<Context> context = Context::New(isolate, NULL, global_template); |
14531 Context::Scope context_scope(context); | 14618 Context::Scope context_scope(context); |
14532 | 14619 |
14533 // Set up a property and a number of functions. | 14620 // Set up a property and a number of functions. |
14534 context->Global()->Set(v8_str("a"), v8_num(1)); | 14621 context->Global()->Set(v8_str("a"), v8_num(1)); |
14535 CompileRun("function f1() {return a;}" | 14622 CompileRun("function f1() {return a;}" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14599 } | 14686 } |
14600 | 14687 |
14601 | 14688 |
14602 THREADED_TEST(TurnOnAccessCheckAndRecompile) { | 14689 THREADED_TEST(TurnOnAccessCheckAndRecompile) { |
14603 v8::Isolate* isolate = CcTest::isolate(); | 14690 v8::Isolate* isolate = CcTest::isolate(); |
14604 v8::HandleScope handle_scope(isolate); | 14691 v8::HandleScope handle_scope(isolate); |
14605 | 14692 |
14606 // Create an environment with access check to the global object disabled by | 14693 // Create an environment with access check to the global object disabled by |
14607 // default. When the registered access checker will block access to properties | 14694 // default. When the registered access checker will block access to properties |
14608 // a and h. | 14695 // a and h. |
14609 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 14696 v8::Handle<v8::ObjectTemplate> global_template = |
| 14697 v8::ObjectTemplate::New(isolate); |
14610 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, | 14698 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, |
14611 IndexedGetAccessBlocker, | 14699 IndexedGetAccessBlocker, |
14612 v8::Handle<v8::Value>(), | 14700 v8::Handle<v8::Value>(), |
14613 false); | 14701 false); |
14614 v8::Local<Context> context = Context::New(isolate, NULL, global_template); | 14702 v8::Local<Context> context = Context::New(isolate, NULL, global_template); |
14615 Context::Scope context_scope(context); | 14703 Context::Scope context_scope(context); |
14616 | 14704 |
14617 // Set up a property and a number of functions. | 14705 // Set up a property and a number of functions. |
14618 context->Global()->Set(v8_str("a"), v8_num(1)); | 14706 context->Global()->Set(v8_str("a"), v8_num(1)); |
14619 static const char* source = "function f1() {return a;}" | 14707 static const char* source = "function f1() {return a;}" |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15159 | 15247 |
15160 #endif // V8_INTERPRETED_REGEXP | 15248 #endif // V8_INTERPRETED_REGEXP |
15161 | 15249 |
15162 | 15250 |
15163 // Test that we cannot set a property on the global object if there | 15251 // Test that we cannot set a property on the global object if there |
15164 // is a read-only property in the prototype chain. | 15252 // is a read-only property in the prototype chain. |
15165 TEST(ReadOnlyPropertyInGlobalProto) { | 15253 TEST(ReadOnlyPropertyInGlobalProto) { |
15166 i::FLAG_es5_readonly = true; | 15254 i::FLAG_es5_readonly = true; |
15167 v8::Isolate* isolate = CcTest::isolate(); | 15255 v8::Isolate* isolate = CcTest::isolate(); |
15168 v8::HandleScope scope(isolate); | 15256 v8::HandleScope scope(isolate); |
15169 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15257 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15170 LocalContext context(0, templ); | 15258 LocalContext context(0, templ); |
15171 v8::Handle<v8::Object> global = context->Global(); | 15259 v8::Handle<v8::Object> global = context->Global(); |
15172 v8::Handle<v8::Object> global_proto = | 15260 v8::Handle<v8::Object> global_proto = |
15173 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); | 15261 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); |
15174 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15262 global_proto->Set(v8_str("x"), v8::Integer::New(isolate, 0), v8::ReadOnly); |
15175 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); | 15263 global_proto->Set(v8_str("y"), v8::Integer::New(isolate, 0), v8::ReadOnly); |
15176 // Check without 'eval' or 'with'. | 15264 // Check without 'eval' or 'with'. |
15177 v8::Handle<v8::Value> res = | 15265 v8::Handle<v8::Value> res = |
15178 CompileRun("function f() { x = 42; return x; }; f()"); | 15266 CompileRun("function f() { x = 42; return x; }; f()"); |
15179 CHECK_EQ(v8::Integer::New(isolate, 0), res); | 15267 CHECK_EQ(v8::Integer::New(isolate, 0), res); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15213 } | 15301 } |
15214 | 15302 |
15215 | 15303 |
15216 TEST(ForceSet) { | 15304 TEST(ForceSet) { |
15217 force_set_get_count = 0; | 15305 force_set_get_count = 0; |
15218 force_set_set_count = 0; | 15306 force_set_set_count = 0; |
15219 pass_on_get = false; | 15307 pass_on_get = false; |
15220 | 15308 |
15221 v8::Isolate* isolate = CcTest::isolate(); | 15309 v8::Isolate* isolate = CcTest::isolate(); |
15222 v8::HandleScope scope(isolate); | 15310 v8::HandleScope scope(isolate); |
15223 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15311 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15224 v8::Handle<v8::String> access_property = | 15312 v8::Handle<v8::String> access_property = |
15225 v8::String::NewFromUtf8(isolate, "a"); | 15313 v8::String::NewFromUtf8(isolate, "a"); |
15226 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); | 15314 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); |
15227 LocalContext context(NULL, templ); | 15315 LocalContext context(NULL, templ); |
15228 v8::Handle<v8::Object> global = context->Global(); | 15316 v8::Handle<v8::Object> global = context->Global(); |
15229 | 15317 |
15230 // Ordinary properties | 15318 // Ordinary properties |
15231 v8::Handle<v8::String> simple_property = | 15319 v8::Handle<v8::String> simple_property = |
15232 v8::String::NewFromUtf8(isolate, "p"); | 15320 v8::String::NewFromUtf8(isolate, "p"); |
15233 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); | 15321 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); |
(...skipping 24 matching lines...) Expand all Loading... |
15258 } | 15346 } |
15259 | 15347 |
15260 | 15348 |
15261 TEST(ForceSetWithInterceptor) { | 15349 TEST(ForceSetWithInterceptor) { |
15262 force_set_get_count = 0; | 15350 force_set_get_count = 0; |
15263 force_set_set_count = 0; | 15351 force_set_set_count = 0; |
15264 pass_on_get = false; | 15352 pass_on_get = false; |
15265 | 15353 |
15266 v8::Isolate* isolate = CcTest::isolate(); | 15354 v8::Isolate* isolate = CcTest::isolate(); |
15267 v8::HandleScope scope(isolate); | 15355 v8::HandleScope scope(isolate); |
15268 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15356 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15269 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); | 15357 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); |
15270 LocalContext context(NULL, templ); | 15358 LocalContext context(NULL, templ); |
15271 v8::Handle<v8::Object> global = context->Global(); | 15359 v8::Handle<v8::Object> global = context->Global(); |
15272 | 15360 |
15273 v8::Handle<v8::String> some_property = | 15361 v8::Handle<v8::String> some_property = |
15274 v8::String::NewFromUtf8(isolate, "a"); | 15362 v8::String::NewFromUtf8(isolate, "a"); |
15275 CHECK_EQ(0, force_set_set_count); | 15363 CHECK_EQ(0, force_set_set_count); |
15276 CHECK_EQ(0, force_set_get_count); | 15364 CHECK_EQ(0, force_set_get_count); |
15277 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 15365 CHECK_EQ(3, global->Get(some_property)->Int32Value()); |
15278 // Setting the property shouldn't override it, just call the setter | 15366 // Setting the property shouldn't override it, just call the setter |
(...skipping 25 matching lines...) Expand all Loading... |
15304 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) | 15392 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) |
15305 ->Int32Value()); | 15393 ->Int32Value()); |
15306 CHECK_EQ(1, force_set_set_count); | 15394 CHECK_EQ(1, force_set_set_count); |
15307 CHECK_EQ(6, force_set_get_count); | 15395 CHECK_EQ(6, force_set_get_count); |
15308 } | 15396 } |
15309 | 15397 |
15310 | 15398 |
15311 THREADED_TEST(ForceDelete) { | 15399 THREADED_TEST(ForceDelete) { |
15312 v8::Isolate* isolate = CcTest::isolate(); | 15400 v8::Isolate* isolate = CcTest::isolate(); |
15313 v8::HandleScope scope(isolate); | 15401 v8::HandleScope scope(isolate); |
15314 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15402 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15315 LocalContext context(NULL, templ); | 15403 LocalContext context(NULL, templ); |
15316 v8::Handle<v8::Object> global = context->Global(); | 15404 v8::Handle<v8::Object> global = context->Global(); |
15317 | 15405 |
15318 // Ordinary properties | 15406 // Ordinary properties |
15319 v8::Handle<v8::String> simple_property = | 15407 v8::Handle<v8::String> simple_property = |
15320 v8::String::NewFromUtf8(isolate, "p"); | 15408 v8::String::NewFromUtf8(isolate, "p"); |
15321 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete); | 15409 global->Set(simple_property, v8::Int32::New(isolate, 4), v8::DontDelete); |
15322 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 15410 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); |
15323 // This should fail because the property is dont-delete. | 15411 // This should fail because the property is dont-delete. |
15324 CHECK(!global->Delete(simple_property)); | 15412 CHECK(!global->Delete(simple_property)); |
(...skipping 16 matching lines...) Expand all Loading... |
15341 info.GetReturnValue().Set(true); | 15429 info.GetReturnValue().Set(true); |
15342 } | 15430 } |
15343 | 15431 |
15344 | 15432 |
15345 THREADED_TEST(ForceDeleteWithInterceptor) { | 15433 THREADED_TEST(ForceDeleteWithInterceptor) { |
15346 force_delete_interceptor_count = 0; | 15434 force_delete_interceptor_count = 0; |
15347 pass_on_delete = false; | 15435 pass_on_delete = false; |
15348 | 15436 |
15349 v8::Isolate* isolate = CcTest::isolate(); | 15437 v8::Isolate* isolate = CcTest::isolate(); |
15350 v8::HandleScope scope(isolate); | 15438 v8::HandleScope scope(isolate); |
15351 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 15439 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
15352 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); | 15440 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); |
15353 LocalContext context(NULL, templ); | 15441 LocalContext context(NULL, templ); |
15354 v8::Handle<v8::Object> global = context->Global(); | 15442 v8::Handle<v8::Object> global = context->Global(); |
15355 | 15443 |
15356 v8::Handle<v8::String> some_property = | 15444 v8::Handle<v8::String> some_property = |
15357 v8::String::NewFromUtf8(isolate, "a"); | 15445 v8::String::NewFromUtf8(isolate, "a"); |
15358 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete); | 15446 global->Set(some_property, v8::Integer::New(isolate, 42), v8::DontDelete); |
15359 | 15447 |
15360 // Deleting a property should get intercepted and nothing should | 15448 // Deleting a property should get intercepted and nothing should |
15361 // happen. | 15449 // happen. |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15970 uint32_t index, | 16058 uint32_t index, |
15971 Local<Value> value, | 16059 Local<Value> value, |
15972 const v8::PropertyCallbackInfo<v8::Value>& info) { | 16060 const v8::PropertyCallbackInfo<v8::Value>& info) { |
15973 ApiTestFuzzer::Fuzz(); | 16061 ApiTestFuzzer::Fuzz(); |
15974 } | 16062 } |
15975 | 16063 |
15976 | 16064 |
15977 THREADED_TEST(PixelArrayWithInterceptor) { | 16065 THREADED_TEST(PixelArrayWithInterceptor) { |
15978 LocalContext context; | 16066 LocalContext context; |
15979 i::Factory* factory = CcTest::i_isolate()->factory(); | 16067 i::Factory* factory = CcTest::i_isolate()->factory(); |
15980 v8::HandleScope scope(context->GetIsolate()); | 16068 v8::Isolate* isolate = context->GetIsolate(); |
| 16069 v8::HandleScope scope(isolate); |
15981 const int kElementCount = 260; | 16070 const int kElementCount = 260; |
15982 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 16071 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
15983 i::Handle<i::ExternalPixelArray> pixels = | 16072 i::Handle<i::ExternalPixelArray> pixels = |
15984 i::Handle<i::ExternalPixelArray>::cast( | 16073 i::Handle<i::ExternalPixelArray>::cast( |
15985 factory->NewExternalArray(kElementCount, | 16074 factory->NewExternalArray(kElementCount, |
15986 v8::kExternalPixelArray, | 16075 v8::kExternalPixelArray, |
15987 pixel_data)); | 16076 pixel_data)); |
15988 for (int i = 0; i < kElementCount; i++) { | 16077 for (int i = 0; i < kElementCount; i++) { |
15989 pixels->set(i, i % 256); | 16078 pixels->set(i, i % 256); |
15990 } | 16079 } |
15991 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); | 16080 v8::Handle<v8::ObjectTemplate> templ = |
| 16081 v8::ObjectTemplate::New(context->GetIsolate()); |
15992 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, | 16082 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter, |
15993 NotHandledIndexedPropertySetter); | 16083 NotHandledIndexedPropertySetter); |
15994 v8::Handle<v8::Object> obj = templ->NewInstance(); | 16084 v8::Handle<v8::Object> obj = templ->NewInstance(); |
15995 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 16085 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
15996 context->Global()->Set(v8_str("pixels"), obj); | 16086 context->Global()->Set(v8_str("pixels"), obj); |
15997 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); | 16087 v8::Handle<v8::Value> result = CompileRun("pixels[1]"); |
15998 CHECK_EQ(1, result->Int32Value()); | 16088 CHECK_EQ(1, result->Int32Value()); |
15999 result = CompileRun("var sum = 0;" | 16089 result = CompileRun("var sum = 0;" |
16000 "for (var i = 0; i < 8; i++) {" | 16090 "for (var i = 0; i < 8; i++) {" |
16001 " sum += pixels[i] = pixels[i] = -i;" | 16091 " sum += pixels[i] = pixels[i] = -i;" |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16956 | 17046 |
16957 | 17047 |
16958 // Tests the C++ StackTrace API. | 17048 // Tests the C++ StackTrace API. |
16959 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. | 17049 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. |
16960 // THREADED_TEST(CaptureStackTrace) { | 17050 // THREADED_TEST(CaptureStackTrace) { |
16961 TEST(CaptureStackTrace) { | 17051 TEST(CaptureStackTrace) { |
16962 v8::Isolate* isolate = CcTest::isolate(); | 17052 v8::Isolate* isolate = CcTest::isolate(); |
16963 v8::HandleScope scope(isolate); | 17053 v8::HandleScope scope(isolate); |
16964 v8::Handle<v8::String> origin = | 17054 v8::Handle<v8::String> origin = |
16965 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); | 17055 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); |
16966 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17056 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
16967 templ->Set(v8_str("AnalyzeStackInNativeCode"), | 17057 templ->Set(v8_str("AnalyzeStackInNativeCode"), |
16968 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); | 17058 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); |
16969 LocalContext context(0, templ); | 17059 LocalContext context(0, templ); |
16970 | 17060 |
16971 // Test getting OVERVIEW information. Should ignore information that is not | 17061 // Test getting OVERVIEW information. Should ignore information that is not |
16972 // script name, function name, line number, and column offset. | 17062 // script name, function name, line number, and column offset. |
16973 const char *overview_source = | 17063 const char *overview_source = |
16974 "function bar() {\n" | 17064 "function bar() {\n" |
16975 " var y; AnalyzeStackInNativeCode(1);\n" | 17065 " var y; AnalyzeStackInNativeCode(1);\n" |
16976 "}\n" | 17066 "}\n" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17207 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 17297 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17208 CHECK(!name.IsEmpty()); | 17298 CHECK(!name.IsEmpty()); |
17209 CHECK_EQ(url, name); | 17299 CHECK_EQ(url, name); |
17210 } | 17300 } |
17211 } | 17301 } |
17212 | 17302 |
17213 | 17303 |
17214 TEST(SourceURLInStackTrace) { | 17304 TEST(SourceURLInStackTrace) { |
17215 v8::Isolate* isolate = CcTest::isolate(); | 17305 v8::Isolate* isolate = CcTest::isolate(); |
17216 v8::HandleScope scope(isolate); | 17306 v8::HandleScope scope(isolate); |
17217 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17307 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17218 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), | 17308 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), |
17219 v8::FunctionTemplate::New(isolate, | 17309 v8::FunctionTemplate::New(isolate, |
17220 AnalyzeStackOfEvalWithSourceURL)); | 17310 AnalyzeStackOfEvalWithSourceURL)); |
17221 LocalContext context(0, templ); | 17311 LocalContext context(0, templ); |
17222 | 17312 |
17223 const char *source = | 17313 const char *source = |
17224 "function outer() {\n" | 17314 "function outer() {\n" |
17225 "function bar() {\n" | 17315 "function bar() {\n" |
17226 " AnalyzeStackOfEvalWithSourceURL();\n" | 17316 " AnalyzeStackOfEvalWithSourceURL();\n" |
17227 "}\n" | 17317 "}\n" |
(...skipping 23 matching lines...) Expand all Loading... |
17251 CHECK_EQ(2, stackTrace->GetFrameCount()); | 17341 CHECK_EQ(2, stackTrace->GetFrameCount()); |
17252 for (int i = 0; i < 2; i++) { | 17342 for (int i = 0; i < 2; i++) { |
17253 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); | 17343 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); |
17254 } | 17344 } |
17255 } | 17345 } |
17256 | 17346 |
17257 | 17347 |
17258 TEST(ScriptIdInStackTrace) { | 17348 TEST(ScriptIdInStackTrace) { |
17259 v8::Isolate* isolate = CcTest::isolate(); | 17349 v8::Isolate* isolate = CcTest::isolate(); |
17260 v8::HandleScope scope(isolate); | 17350 v8::HandleScope scope(isolate); |
17261 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17351 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17262 templ->Set(v8_str("AnalyzeScriptIdInStack"), | 17352 templ->Set(v8_str("AnalyzeScriptIdInStack"), |
17263 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); | 17353 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); |
17264 LocalContext context(0, templ); | 17354 LocalContext context(0, templ); |
17265 | 17355 |
17266 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 17356 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( |
17267 isolate, | 17357 isolate, |
17268 "function foo() {\n" | 17358 "function foo() {\n" |
17269 " AnalyzeScriptIdInStack();" | 17359 " AnalyzeScriptIdInStack();" |
17270 "}\n" | 17360 "}\n" |
17271 "foo();\n"); | 17361 "foo();\n"); |
(...skipping 18 matching lines...) Expand all Loading... |
17290 for (int i = 0; i < 3; i++) { | 17380 for (int i = 0; i < 3; i++) { |
17291 v8::Handle<v8::String> name = | 17381 v8::Handle<v8::String> name = |
17292 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 17382 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17293 CHECK(!name.IsEmpty()); | 17383 CHECK(!name.IsEmpty()); |
17294 CHECK_EQ(url, name); | 17384 CHECK_EQ(url, name); |
17295 } | 17385 } |
17296 } | 17386 } |
17297 | 17387 |
17298 | 17388 |
17299 TEST(InlineScriptWithSourceURLInStackTrace) { | 17389 TEST(InlineScriptWithSourceURLInStackTrace) { |
17300 v8::HandleScope scope(CcTest::isolate()); | 17390 v8::Isolate* isolate = CcTest::isolate(); |
17301 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17391 v8::HandleScope scope(isolate); |
| 17392 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17302 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), | 17393 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), |
17303 v8::FunctionTemplate::New( | 17394 v8::FunctionTemplate::New( |
17304 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL)); | 17395 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL)); |
17305 LocalContext context(0, templ); | 17396 LocalContext context(0, templ); |
17306 | 17397 |
17307 const char *source = | 17398 const char *source = |
17308 "function outer() {\n" | 17399 "function outer() {\n" |
17309 "function bar() {\n" | 17400 "function bar() {\n" |
17310 " AnalyzeStackOfInlineScriptWithSourceURL();\n" | 17401 " AnalyzeStackOfInlineScriptWithSourceURL();\n" |
17311 "}\n" | 17402 "}\n" |
(...skipping 23 matching lines...) Expand all Loading... |
17335 for (int i = 0; i < 3; i++) { | 17426 for (int i = 0; i < 3; i++) { |
17336 v8::Handle<v8::String> name = | 17427 v8::Handle<v8::String> name = |
17337 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 17428 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
17338 CHECK(!name.IsEmpty()); | 17429 CHECK(!name.IsEmpty()); |
17339 CHECK_EQ(url, name); | 17430 CHECK_EQ(url, name); |
17340 } | 17431 } |
17341 } | 17432 } |
17342 | 17433 |
17343 | 17434 |
17344 TEST(DynamicWithSourceURLInStackTrace) { | 17435 TEST(DynamicWithSourceURLInStackTrace) { |
17345 v8::HandleScope scope(CcTest::isolate()); | 17436 v8::Isolate* isolate = CcTest::isolate(); |
17346 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 17437 v8::HandleScope scope(isolate); |
| 17438 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17347 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), | 17439 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), |
17348 v8::FunctionTemplate::New( | 17440 v8::FunctionTemplate::New( |
17349 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL)); | 17441 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL)); |
17350 LocalContext context(0, templ); | 17442 LocalContext context(0, templ); |
17351 | 17443 |
17352 const char *source = | 17444 const char *source = |
17353 "function outer() {\n" | 17445 "function outer() {\n" |
17354 "function bar() {\n" | 17446 "function bar() {\n" |
17355 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" | 17447 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" |
17356 "}\n" | 17448 "}\n" |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18201 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18293 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18202 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); | 18294 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
18203 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); | 18295 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
18204 if (!name->Equals(v8_str("foo"))) return; | 18296 if (!name->Equals(v8_str("foo"))) return; |
18205 info.This()->Set(v8_str("y"), v8_num(23)); | 18297 info.This()->Set(v8_str("y"), v8_num(23)); |
18206 info.GetReturnValue().Set(v8_num(23)); | 18298 info.GetReturnValue().Set(v8_num(23)); |
18207 } | 18299 } |
18208 | 18300 |
18209 | 18301 |
18210 TEST(SetterOnConstructorPrototype) { | 18302 TEST(SetterOnConstructorPrototype) { |
18211 v8::HandleScope scope(CcTest::isolate()); | 18303 v8::Isolate* isolate = CcTest::isolate(); |
18212 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 18304 v8::HandleScope scope(isolate); |
| 18305 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18213 templ->SetAccessor(v8_str("x"), | 18306 templ->SetAccessor(v8_str("x"), |
18214 GetterWhichReturns42, | 18307 GetterWhichReturns42, |
18215 SetterWhichSetsYOnThisTo23); | 18308 SetterWhichSetsYOnThisTo23); |
18216 LocalContext context; | 18309 LocalContext context; |
18217 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 18310 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
18218 CompileRun("function C1() {" | 18311 CompileRun("function C1() {" |
18219 " this.x = 23;" | 18312 " this.x = 23;" |
18220 "};" | 18313 "};" |
18221 "C1.prototype = P;" | 18314 "C1.prototype = P;" |
18222 "function C2() {" | 18315 "function C2() {" |
(...skipping 30 matching lines...) Expand all Loading... |
18253 Local<String> name, | 18346 Local<String> name, |
18254 Local<Value> value, | 18347 Local<Value> value, |
18255 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18348 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18256 if (name->Equals(v8_str("x"))) { | 18349 if (name->Equals(v8_str("x"))) { |
18257 info.This()->Set(v8_str("y"), v8_num(23)); | 18350 info.This()->Set(v8_str("y"), v8_num(23)); |
18258 } | 18351 } |
18259 } | 18352 } |
18260 | 18353 |
18261 | 18354 |
18262 THREADED_TEST(InterceptorOnConstructorPrototype) { | 18355 THREADED_TEST(InterceptorOnConstructorPrototype) { |
18263 v8::HandleScope scope(CcTest::isolate()); | 18356 v8::Isolate* isolate = CcTest::isolate(); |
18264 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 18357 v8::HandleScope scope(isolate); |
| 18358 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18265 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, | 18359 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, |
18266 NamedPropertySetterWhichSetsYOnThisTo23); | 18360 NamedPropertySetterWhichSetsYOnThisTo23); |
18267 LocalContext context; | 18361 LocalContext context; |
18268 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 18362 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
18269 CompileRun("function C1() {" | 18363 CompileRun("function C1() {" |
18270 " this.x = 23;" | 18364 " this.x = 23;" |
18271 "};" | 18365 "};" |
18272 "C1.prototype = P;" | 18366 "C1.prototype = P;" |
18273 "function C2() {" | 18367 "function C2() {" |
18274 " this.x = 23" | 18368 " this.x = 23" |
(...skipping 18 matching lines...) Expand all Loading... |
18293 } | 18387 } |
18294 | 18388 |
18295 | 18389 |
18296 TEST(Regress618) { | 18390 TEST(Regress618) { |
18297 const char* source = "function C1() {" | 18391 const char* source = "function C1() {" |
18298 " this.x = 23;" | 18392 " this.x = 23;" |
18299 "};" | 18393 "};" |
18300 "C1.prototype = P;"; | 18394 "C1.prototype = P;"; |
18301 | 18395 |
18302 LocalContext context; | 18396 LocalContext context; |
18303 v8::HandleScope scope(context->GetIsolate()); | 18397 v8::Isolate* isolate = context->GetIsolate(); |
| 18398 v8::HandleScope scope(isolate); |
18304 v8::Local<v8::Script> script; | 18399 v8::Local<v8::Script> script; |
18305 | 18400 |
18306 // Use a simple object as prototype. | 18401 // Use a simple object as prototype. |
18307 v8::Local<v8::Object> prototype = v8::Object::New(context->GetIsolate()); | 18402 v8::Local<v8::Object> prototype = v8::Object::New(isolate); |
18308 prototype->Set(v8_str("y"), v8_num(42)); | 18403 prototype->Set(v8_str("y"), v8_num(42)); |
18309 context->Global()->Set(v8_str("P"), prototype); | 18404 context->Global()->Set(v8_str("P"), prototype); |
18310 | 18405 |
18311 // This compile will add the code to the compilation cache. | 18406 // This compile will add the code to the compilation cache. |
18312 CompileRun(source); | 18407 CompileRun(source); |
18313 | 18408 |
18314 script = v8::Script::Compile(v8_str("new C1();")); | 18409 script = v8::Script::Compile(v8_str("new C1();")); |
18315 // Allow enough iterations for the inobject slack tracking logic | 18410 // Allow enough iterations for the inobject slack tracking logic |
18316 // to finalize instance size and install the fast construct stub. | 18411 // to finalize instance size and install the fast construct stub. |
18317 for (int i = 0; i < 256; i++) { | 18412 for (int i = 0; i < 256; i++) { |
18318 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18413 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); |
18319 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 18414 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); |
18320 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 18415 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); |
18321 } | 18416 } |
18322 | 18417 |
18323 // Use an API object with accessors as prototype. | 18418 // Use an API object with accessors as prototype. |
18324 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 18419 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18325 templ->SetAccessor(v8_str("x"), | 18420 templ->SetAccessor(v8_str("x"), |
18326 GetterWhichReturns42, | 18421 GetterWhichReturns42, |
18327 SetterWhichSetsYOnThisTo23); | 18422 SetterWhichSetsYOnThisTo23); |
18328 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 18423 context->Global()->Set(v8_str("P"), templ->NewInstance()); |
18329 | 18424 |
18330 // This compile will get the code from the compilation cache. | 18425 // This compile will get the code from the compilation cache. |
18331 CompileRun(source); | 18426 CompileRun(source); |
18332 | 18427 |
18333 script = v8::Script::Compile(v8_str("new C1();")); | 18428 script = v8::Script::Compile(v8_str("new C1();")); |
18334 for (int i = 0; i < 10; i++) { | 18429 for (int i = 0; i < 10; i++) { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18751 } | 18846 } |
18752 | 18847 |
18753 | 18848 |
18754 TEST(GCInFailedAccessCheckCallback) { | 18849 TEST(GCInFailedAccessCheckCallback) { |
18755 // Install a failed access check callback that performs a GC on each | 18850 // Install a failed access check callback that performs a GC on each |
18756 // invocation. Then force the callback to be called from va | 18851 // invocation. Then force the callback to be called from va |
18757 | 18852 |
18758 v8::V8::Initialize(); | 18853 v8::V8::Initialize(); |
18759 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); | 18854 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); |
18760 | 18855 |
18761 v8::HandleScope scope(CcTest::isolate()); | 18856 v8::Isolate* isolate = CcTest::isolate(); |
| 18857 v8::HandleScope scope(isolate); |
18762 | 18858 |
18763 // Create an ObjectTemplate for global objects and install access | 18859 // Create an ObjectTemplate for global objects and install access |
18764 // check callbacks that will block access. | 18860 // check callbacks that will block access. |
18765 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 18861 v8::Handle<v8::ObjectTemplate> global_template = |
| 18862 v8::ObjectTemplate::New(isolate); |
18766 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, | 18863 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, |
18767 IndexedGetAccessBlocker, | 18864 IndexedGetAccessBlocker, |
18768 v8::Handle<v8::Value>(), | 18865 v8::Handle<v8::Value>(), |
18769 false); | 18866 false); |
18770 | 18867 |
18771 // Create a context and set an x property on it's global object. | 18868 // Create a context and set an x property on it's global object. |
18772 LocalContext context0(NULL, global_template); | 18869 LocalContext context0(NULL, global_template); |
18773 context0->Global()->Set(v8_str("x"), v8_num(42)); | 18870 context0->Global()->Set(v8_str("x"), v8_num(42)); |
18774 v8::Handle<v8::Object> global0 = context0->Global(); | 18871 v8::Handle<v8::Object> global0 = context0->Global(); |
18775 | 18872 |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19515 | 19612 |
19516 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 19613 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
19517 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); | 19614 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); |
19518 result->Set(0, v8_str("universalAnswer")); | 19615 result->Set(0, v8_str("universalAnswer")); |
19519 info.GetReturnValue().Set(result); | 19616 info.GetReturnValue().Set(result); |
19520 } | 19617 } |
19521 | 19618 |
19522 | 19619 |
19523 TEST(NamedEnumeratorAndForIn) { | 19620 TEST(NamedEnumeratorAndForIn) { |
19524 LocalContext context; | 19621 LocalContext context; |
19525 v8::HandleScope handle_scope(context->GetIsolate()); | 19622 v8::Isolate* isolate = context->GetIsolate(); |
| 19623 v8::HandleScope handle_scope(isolate); |
19526 v8::Context::Scope context_scope(context.local()); | 19624 v8::Context::Scope context_scope(context.local()); |
19527 | 19625 |
19528 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 19626 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); |
19529 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 19627 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
19530 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 19628 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
19531 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 19629 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
19532 "var result = []; for (var k in o) result.push(k); result")); | 19630 "var result = []; for (var k in o) result.push(k); result")); |
19533 CHECK_EQ(1, result->Length()); | 19631 CHECK_EQ(1, result->Length()); |
19534 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 19632 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
19535 } | 19633 } |
19536 | 19634 |
19537 | 19635 |
19538 TEST(DefinePropertyPostDetach) { | 19636 TEST(DefinePropertyPostDetach) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19699 | 19797 |
19700 void HasOwnPropertyAccessorGetter( | 19798 void HasOwnPropertyAccessorGetter( |
19701 Local<String> property, | 19799 Local<String> property, |
19702 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19800 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19703 info.GetReturnValue().Set(v8_str("yes")); | 19801 info.GetReturnValue().Set(v8_str("yes")); |
19704 } | 19802 } |
19705 | 19803 |
19706 | 19804 |
19707 TEST(HasOwnProperty) { | 19805 TEST(HasOwnProperty) { |
19708 LocalContext env; | 19806 LocalContext env; |
19709 v8::HandleScope scope(env->GetIsolate()); | 19807 v8::Isolate* isolate = env->GetIsolate(); |
| 19808 v8::HandleScope scope(isolate); |
19710 { // Check normal properties and defined getters. | 19809 { // Check normal properties and defined getters. |
19711 Handle<Value> value = CompileRun( | 19810 Handle<Value> value = CompileRun( |
19712 "function Foo() {" | 19811 "function Foo() {" |
19713 " this.foo = 11;" | 19812 " this.foo = 11;" |
19714 " this.__defineGetter__('baz', function() { return 1; });" | 19813 " this.__defineGetter__('baz', function() { return 1; });" |
19715 "};" | 19814 "};" |
19716 "function Bar() { " | 19815 "function Bar() { " |
19717 " this.bar = 13;" | 19816 " this.bar = 13;" |
19718 " this.__defineGetter__('bla', function() { return 2; });" | 19817 " this.__defineGetter__('bla', function() { return 2; });" |
19719 "};" | 19818 "};" |
19720 "Bar.prototype = new Foo();" | 19819 "Bar.prototype = new Foo();" |
19721 "new Bar();"); | 19820 "new Bar();"); |
19722 CHECK(value->IsObject()); | 19821 CHECK(value->IsObject()); |
19723 Handle<Object> object = value->ToObject(); | 19822 Handle<Object> object = value->ToObject(); |
19724 CHECK(object->Has(v8_str("foo"))); | 19823 CHECK(object->Has(v8_str("foo"))); |
19725 CHECK(!object->HasOwnProperty(v8_str("foo"))); | 19824 CHECK(!object->HasOwnProperty(v8_str("foo"))); |
19726 CHECK(object->HasOwnProperty(v8_str("bar"))); | 19825 CHECK(object->HasOwnProperty(v8_str("bar"))); |
19727 CHECK(object->Has(v8_str("baz"))); | 19826 CHECK(object->Has(v8_str("baz"))); |
19728 CHECK(!object->HasOwnProperty(v8_str("baz"))); | 19827 CHECK(!object->HasOwnProperty(v8_str("baz"))); |
19729 CHECK(object->HasOwnProperty(v8_str("bla"))); | 19828 CHECK(object->HasOwnProperty(v8_str("bla"))); |
19730 } | 19829 } |
19731 { // Check named getter interceptors. | 19830 { // Check named getter interceptors. |
19732 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19831 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19733 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); | 19832 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter); |
19734 Handle<Object> instance = templ->NewInstance(); | 19833 Handle<Object> instance = templ->NewInstance(); |
19735 CHECK(!instance->HasOwnProperty(v8_str("42"))); | 19834 CHECK(!instance->HasOwnProperty(v8_str("42"))); |
19736 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19835 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
19737 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19836 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
19738 } | 19837 } |
19739 { // Check indexed getter interceptors. | 19838 { // Check indexed getter interceptors. |
19740 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19839 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19741 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); | 19840 templ->SetIndexedPropertyHandler(HasOwnPropertyIndexedPropertyGetter); |
19742 Handle<Object> instance = templ->NewInstance(); | 19841 Handle<Object> instance = templ->NewInstance(); |
19743 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19842 CHECK(instance->HasOwnProperty(v8_str("42"))); |
19744 CHECK(!instance->HasOwnProperty(v8_str("43"))); | 19843 CHECK(!instance->HasOwnProperty(v8_str("43"))); |
19745 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19844 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
19746 } | 19845 } |
19747 { // Check named query interceptors. | 19846 { // Check named query interceptors. |
19748 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19847 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19749 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); | 19848 templ->SetNamedPropertyHandler(0, 0, HasOwnPropertyNamedPropertyQuery); |
19750 Handle<Object> instance = templ->NewInstance(); | 19849 Handle<Object> instance = templ->NewInstance(); |
19751 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19850 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
19752 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19851 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
19753 } | 19852 } |
19754 { // Check indexed query interceptors. | 19853 { // Check indexed query interceptors. |
19755 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19854 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19756 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); | 19855 templ->SetIndexedPropertyHandler(0, 0, HasOwnPropertyIndexedPropertyQuery); |
19757 Handle<Object> instance = templ->NewInstance(); | 19856 Handle<Object> instance = templ->NewInstance(); |
19758 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19857 CHECK(instance->HasOwnProperty(v8_str("42"))); |
19759 CHECK(!instance->HasOwnProperty(v8_str("41"))); | 19858 CHECK(!instance->HasOwnProperty(v8_str("41"))); |
19760 } | 19859 } |
19761 { // Check callbacks. | 19860 { // Check callbacks. |
19762 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19861 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19763 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | 19862 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
19764 Handle<Object> instance = templ->NewInstance(); | 19863 Handle<Object> instance = templ->NewInstance(); |
19765 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19864 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
19766 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19865 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
19767 } | 19866 } |
19768 { // Check that query wins on disagreement. | 19867 { // Check that query wins on disagreement. |
19769 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19868 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19770 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, | 19869 templ->SetNamedPropertyHandler(HasOwnPropertyNamedPropertyGetter, |
19771 0, | 19870 0, |
19772 HasOwnPropertyNamedPropertyQuery2); | 19871 HasOwnPropertyNamedPropertyQuery2); |
19773 Handle<Object> instance = templ->NewInstance(); | 19872 Handle<Object> instance = templ->NewInstance(); |
19774 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19873 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
19775 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 19874 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
19776 } | 19875 } |
19777 } | 19876 } |
19778 | 19877 |
19779 | 19878 |
19780 TEST(IndexedInterceptorWithStringProto) { | 19879 TEST(IndexedInterceptorWithStringProto) { |
19781 v8::HandleScope scope(CcTest::isolate()); | 19880 v8::Isolate* isolate = CcTest::isolate(); |
19782 Handle<ObjectTemplate> templ = ObjectTemplate::New(); | 19881 v8::HandleScope scope(isolate); |
| 19882 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19783 templ->SetIndexedPropertyHandler(NULL, | 19883 templ->SetIndexedPropertyHandler(NULL, |
19784 NULL, | 19884 NULL, |
19785 HasOwnPropertyIndexedPropertyQuery); | 19885 HasOwnPropertyIndexedPropertyQuery); |
19786 LocalContext context; | 19886 LocalContext context; |
19787 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 19887 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
19788 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); | 19888 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); |
19789 // These should be intercepted. | 19889 // These should be intercepted. |
19790 CHECK(CompileRun("42 in obj")->BooleanValue()); | 19890 CHECK(CompileRun("42 in obj")->BooleanValue()); |
19791 CHECK(CompileRun("'42' in obj")->BooleanValue()); | 19891 CHECK(CompileRun("'42' in obj")->BooleanValue()); |
19792 // These should fall through to the String prototype. | 19892 // These should fall through to the String prototype. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19899 v8::FunctionTemplate::New(isolate, NonObjectThis); | 19999 v8::FunctionTemplate::New(isolate, NonObjectThis); |
19900 Handle<Function> function = templ->GetFunction(); | 20000 Handle<Function> function = templ->GetFunction(); |
19901 context->Global()->Set(v8_str("f"), function); | 20001 context->Global()->Set(v8_str("f"), function); |
19902 TryCatch try_catch; | 20002 TryCatch try_catch; |
19903 CompileRun("f.call(2)"); | 20003 CompileRun("f.call(2)"); |
19904 } | 20004 } |
19905 | 20005 |
19906 | 20006 |
19907 // Regression test for issue 1470. | 20007 // Regression test for issue 1470. |
19908 THREADED_TEST(ReadOnlyIndexedProperties) { | 20008 THREADED_TEST(ReadOnlyIndexedProperties) { |
19909 v8::HandleScope scope(CcTest::isolate()); | 20009 v8::Isolate* isolate = CcTest::isolate(); |
19910 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20010 v8::HandleScope scope(isolate); |
| 20011 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19911 | 20012 |
19912 LocalContext context; | 20013 LocalContext context; |
19913 Local<v8::Object> obj = templ->NewInstance(); | 20014 Local<v8::Object> obj = templ->NewInstance(); |
19914 context->Global()->Set(v8_str("obj"), obj); | 20015 context->Global()->Set(v8_str("obj"), obj); |
19915 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); | 20016 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); |
19916 obj->Set(v8_str("1"), v8_str("foobar")); | 20017 obj->Set(v8_str("1"), v8_str("foobar")); |
19917 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); | 20018 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); |
19918 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); | 20019 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); |
19919 obj->Set(v8_num(2), v8_str("foobar")); | 20020 obj->Set(v8_num(2), v8_str("foobar")); |
19920 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); | 20021 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19968 | 20069 |
19969 return true; | 20070 return true; |
19970 } | 20071 } |
19971 | 20072 |
19972 | 20073 |
19973 THREADED_TEST(Regress93759) { | 20074 THREADED_TEST(Regress93759) { |
19974 v8::Isolate* isolate = CcTest::isolate(); | 20075 v8::Isolate* isolate = CcTest::isolate(); |
19975 HandleScope scope(isolate); | 20076 HandleScope scope(isolate); |
19976 | 20077 |
19977 // Template for object with security check. | 20078 // Template for object with security check. |
19978 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); | 20079 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(isolate); |
19979 // We don't do indexing, so any callback can be used for that. | 20080 // We don't do indexing, so any callback can be used for that. |
19980 no_proto_template->SetAccessCheckCallbacks( | 20081 no_proto_template->SetAccessCheckCallbacks( |
19981 BlockProtoNamedSecurityTestCallback, | 20082 BlockProtoNamedSecurityTestCallback, |
19982 IndexedSecurityTestCallback); | 20083 IndexedSecurityTestCallback); |
19983 | 20084 |
19984 // Templates for objects with hidden prototypes and possibly security check. | 20085 // Templates for objects with hidden prototypes and possibly security check. |
19985 Local<FunctionTemplate> hidden_proto_template = | 20086 Local<FunctionTemplate> hidden_proto_template = |
19986 v8::FunctionTemplate::New(isolate); | 20087 v8::FunctionTemplate::New(isolate); |
19987 hidden_proto_template->SetHiddenPrototype(true); | 20088 hidden_proto_template->SetHiddenPrototype(true); |
19988 | 20089 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20023 Local<Object> protected_hidden_prototype = | 20124 Local<Object> protected_hidden_prototype = |
20024 protected_hidden_proto_template->GetFunction()->NewInstance(); | 20125 protected_hidden_proto_template->GetFunction()->NewInstance(); |
20025 Local<Object> object_with_protected_hidden = | 20126 Local<Object> object_with_protected_hidden = |
20026 Object::New(isolate); | 20127 Object::New(isolate); |
20027 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); | 20128 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); |
20028 | 20129 |
20029 context->Exit(); | 20130 context->Exit(); |
20030 | 20131 |
20031 // Template for object for second context. Values to test are put on it as | 20132 // Template for object for second context. Values to test are put on it as |
20032 // properties. | 20133 // properties. |
20033 Local<ObjectTemplate> global_template = ObjectTemplate::New(); | 20134 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); |
20034 global_template->Set(v8_str("simple"), simple_object); | 20135 global_template->Set(v8_str("simple"), simple_object); |
20035 global_template->Set(v8_str("protected"), protected_object); | 20136 global_template->Set(v8_str("protected"), protected_object); |
20036 global_template->Set(v8_str("global"), global_object); | 20137 global_template->Set(v8_str("global"), global_object); |
20037 global_template->Set(v8_str("proxy"), proxy_object); | 20138 global_template->Set(v8_str("proxy"), proxy_object); |
20038 global_template->Set(v8_str("hidden"), object_with_hidden); | 20139 global_template->Set(v8_str("hidden"), object_with_hidden); |
20039 global_template->Set(v8_str("phidden"), object_with_protected_hidden); | 20140 global_template->Set(v8_str("phidden"), object_with_protected_hidden); |
20040 | 20141 |
20041 LocalContext context2(NULL, global_template); | 20142 LocalContext context2(NULL, global_template); |
20042 | 20143 |
20043 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); | 20144 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20649 CHECK_EQ(6, message->GetLineNumber()); | 20750 CHECK_EQ(6, message->GetLineNumber()); |
20650 } | 20751 } |
20651 } | 20752 } |
20652 | 20753 |
20653 | 20754 |
20654 static void Helper137002(bool do_store, | 20755 static void Helper137002(bool do_store, |
20655 bool polymorphic, | 20756 bool polymorphic, |
20656 bool remove_accessor, | 20757 bool remove_accessor, |
20657 bool interceptor) { | 20758 bool interceptor) { |
20658 LocalContext context; | 20759 LocalContext context; |
20659 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20760 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); |
20660 if (interceptor) { | 20761 if (interceptor) { |
20661 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor); | 20762 templ->SetNamedPropertyHandler(FooGetInterceptor, FooSetInterceptor); |
20662 } else { | 20763 } else { |
20663 templ->SetAccessor(v8_str("foo"), | 20764 templ->SetAccessor(v8_str("foo"), |
20664 GetterWhichReturns42, | 20765 GetterWhichReturns42, |
20665 SetterWhichSetsYOnThisTo23); | 20766 SetterWhichSetsYOnThisTo23); |
20666 } | 20767 } |
20667 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20768 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
20668 | 20769 |
20669 // Turn monomorphic on slow object with native accessor, then turn | 20770 // Turn monomorphic on slow object with native accessor, then turn |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20704 v8::HandleScope scope(CcTest::isolate()); | 20805 v8::HandleScope scope(CcTest::isolate()); |
20705 for (int i = 0; i < 16; i++) { | 20806 for (int i = 0; i < 16; i++) { |
20706 Helper137002(i & 8, i & 4, i & 2, i & 1); | 20807 Helper137002(i & 8, i & 4, i & 2, i & 1); |
20707 } | 20808 } |
20708 } | 20809 } |
20709 | 20810 |
20710 | 20811 |
20711 THREADED_TEST(Regress137002b) { | 20812 THREADED_TEST(Regress137002b) { |
20712 i::FLAG_allow_natives_syntax = true; | 20813 i::FLAG_allow_natives_syntax = true; |
20713 LocalContext context; | 20814 LocalContext context; |
20714 v8::HandleScope scope(context->GetIsolate()); | 20815 v8::Isolate* isolate = context->GetIsolate(); |
20715 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20816 v8::HandleScope scope(isolate); |
| 20817 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
20716 templ->SetAccessor(v8_str("foo"), | 20818 templ->SetAccessor(v8_str("foo"), |
20717 GetterWhichReturns42, | 20819 GetterWhichReturns42, |
20718 SetterWhichSetsYOnThisTo23); | 20820 SetterWhichSetsYOnThisTo23); |
20719 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20821 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
20720 | 20822 |
20721 // Turn monomorphic on slow object with native accessor, then just | 20823 // Turn monomorphic on slow object with native accessor, then just |
20722 // delete the property and fail. | 20824 // delete the property and fail. |
20723 CompileRun("function load(x) { return x.foo; }" | 20825 CompileRun("function load(x) { return x.foo; }" |
20724 "function store(x) { x.foo = void 0; }" | 20826 "function store(x) { x.foo = void 0; }" |
20725 "function keyed_load(x, key) { return x[key]; }" | 20827 "function keyed_load(x, key) { return x[key]; }" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20772 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); | 20874 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); |
20773 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); | 20875 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); |
20774 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); | 20876 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); |
20775 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); | 20877 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); |
20776 } | 20878 } |
20777 | 20879 |
20778 | 20880 |
20779 THREADED_TEST(Regress142088) { | 20881 THREADED_TEST(Regress142088) { |
20780 i::FLAG_allow_natives_syntax = true; | 20882 i::FLAG_allow_natives_syntax = true; |
20781 LocalContext context; | 20883 LocalContext context; |
20782 v8::HandleScope scope(context->GetIsolate()); | 20884 v8::Isolate* isolate = context->GetIsolate(); |
20783 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20885 v8::HandleScope scope(isolate); |
| 20886 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
20784 templ->SetAccessor(v8_str("foo"), | 20887 templ->SetAccessor(v8_str("foo"), |
20785 GetterWhichReturns42, | 20888 GetterWhichReturns42, |
20786 SetterWhichSetsYOnThisTo23); | 20889 SetterWhichSetsYOnThisTo23); |
20787 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20890 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
20788 | 20891 |
20789 CompileRun("function load(x) { return x.foo; }" | 20892 CompileRun("function load(x) { return x.foo; }" |
20790 "var o = Object.create(obj);" | 20893 "var o = Object.create(obj);" |
20791 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" | 20894 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" |
20792 "load(o); load(o); load(o); load(o);"); | 20895 "load(o); load(o); load(o); load(o);"); |
20793 } | 20896 } |
(...skipping 18 matching lines...) Expand all Loading... |
20812 v8::HandleScope scope(context->GetIsolate()); | 20915 v8::HandleScope scope(context->GetIsolate()); |
20813 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 20916 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
20814 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); | 20917 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); |
20815 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); | 20918 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); |
20816 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); | 20919 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); |
20817 } | 20920 } |
20818 | 20921 |
20819 | 20922 |
20820 THREADED_TEST(Regress157124) { | 20923 THREADED_TEST(Regress157124) { |
20821 LocalContext context; | 20924 LocalContext context; |
20822 v8::HandleScope scope(context->GetIsolate()); | 20925 v8::Isolate* isolate = context->GetIsolate(); |
20823 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 20926 v8::HandleScope scope(isolate); |
| 20927 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
20824 Local<Object> obj = templ->NewInstance(); | 20928 Local<Object> obj = templ->NewInstance(); |
20825 obj->GetIdentityHash(); | 20929 obj->GetIdentityHash(); |
20826 obj->DeleteHiddenValue(v8_str("Bug")); | 20930 obj->DeleteHiddenValue(v8_str("Bug")); |
20827 } | 20931 } |
20828 | 20932 |
20829 | 20933 |
20830 THREADED_TEST(Regress2535) { | 20934 THREADED_TEST(Regress2535) { |
20831 i::FLAG_harmony_collections = true; | 20935 i::FLAG_harmony_collections = true; |
20832 LocalContext context; | 20936 LocalContext context; |
20833 v8::HandleScope scope(context->GetIsolate()); | 20937 v8::HandleScope scope(context->GetIsolate()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20968 } | 21072 } |
20969 | 21073 |
20970 | 21074 |
20971 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 21075 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
20972 CHECK(false); | 21076 CHECK(false); |
20973 } | 21077 } |
20974 | 21078 |
20975 | 21079 |
20976 TEST(JSONStringifyAccessCheck) { | 21080 TEST(JSONStringifyAccessCheck) { |
20977 v8::V8::Initialize(); | 21081 v8::V8::Initialize(); |
20978 v8::HandleScope scope(CcTest::isolate()); | 21082 v8::Isolate* isolate = CcTest::isolate(); |
| 21083 v8::HandleScope scope(isolate); |
20979 | 21084 |
20980 // Create an ObjectTemplate for global objects and install access | 21085 // Create an ObjectTemplate for global objects and install access |
20981 // check callbacks that will block access. | 21086 // check callbacks that will block access. |
20982 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 21087 v8::Handle<v8::ObjectTemplate> global_template = |
| 21088 v8::ObjectTemplate::New(isolate); |
20983 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, | 21089 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, |
20984 IndexAccessAlwaysBlocked); | 21090 IndexAccessAlwaysBlocked); |
20985 | 21091 |
20986 // Create a context and set an x property on it's global object. | 21092 // Create a context and set an x property on it's global object. |
20987 LocalContext context0(NULL, global_template); | 21093 LocalContext context0(NULL, global_template); |
20988 v8::Handle<v8::Object> global0 = context0->Global(); | 21094 v8::Handle<v8::Object> global0 = context0->Global(); |
20989 global0->Set(v8_str("x"), v8_num(42)); | 21095 global0->Set(v8_str("x"), v8_num(42)); |
20990 ExpectString("JSON.stringify(this)", "{\"x\":42}"); | 21096 ExpectString("JSON.stringify(this)", "{\"x\":42}"); |
20991 | 21097 |
20992 for (int i = 0; i < 2; i++) { | 21098 for (int i = 0; i < 2; i++) { |
20993 if (i == 1) { | 21099 if (i == 1) { |
20994 // Install a toJSON function on the second run. | 21100 // Install a toJSON function on the second run. |
20995 v8::Handle<v8::FunctionTemplate> toJSON = | 21101 v8::Handle<v8::FunctionTemplate> toJSON = |
20996 v8::FunctionTemplate::New(CcTest::isolate(), UnreachableCallback); | 21102 v8::FunctionTemplate::New(isolate, UnreachableCallback); |
20997 | 21103 |
20998 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); | 21104 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); |
20999 } | 21105 } |
21000 // Create a context with a different security token so that the | 21106 // Create a context with a different security token so that the |
21001 // failed access check callback will be called on each access. | 21107 // failed access check callback will be called on each access. |
21002 LocalContext context1(NULL, global_template); | 21108 LocalContext context1(NULL, global_template); |
21003 context1->Global()->Set(v8_str("other"), global0); | 21109 context1->Global()->Set(v8_str("other"), global0); |
21004 | 21110 |
21005 ExpectString("JSON.stringify(other)", "{}"); | 21111 ExpectString("JSON.stringify(other)", "{}"); |
21006 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", | 21112 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", |
21007 "{\"a\":{},\"b\":[\"c\"]}"); | 21113 "{\"a\":{},\"b\":[\"c\"]}"); |
21008 ExpectString("JSON.stringify([other, 'b', 'c'])", | 21114 ExpectString("JSON.stringify([other, 'b', 'c'])", |
21009 "[{},\"b\",\"c\"]"); | 21115 "[{},\"b\",\"c\"]"); |
21010 | 21116 |
21011 v8::Handle<v8::Array> array = v8::Array::New(CcTest::isolate(), 2); | 21117 v8::Handle<v8::Array> array = v8::Array::New(isolate, 2); |
21012 array->Set(0, v8_str("a")); | 21118 array->Set(0, v8_str("a")); |
21013 array->Set(1, v8_str("b")); | 21119 array->Set(1, v8_str("b")); |
21014 context1->Global()->Set(v8_str("array"), array); | 21120 context1->Global()->Set(v8_str("array"), array); |
21015 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]"); | 21121 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]"); |
21016 array->TurnOnAccessCheck(); | 21122 array->TurnOnAccessCheck(); |
21017 ExpectString("JSON.stringify(array)", "[]"); | 21123 ExpectString("JSON.stringify(array)", "[]"); |
21018 ExpectString("JSON.stringify([array])", "[[]]"); | 21124 ExpectString("JSON.stringify([array])", "[[]]"); |
21019 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}"); | 21125 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}"); |
21020 } | 21126 } |
21021 } | 21127 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21066 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); | 21172 CompileRun("try { [1, 2, 3].sort(); } catch (e) { catcher(e) };"); |
21067 CHECK(!access_check_fail_thrown); | 21173 CHECK(!access_check_fail_thrown); |
21068 CHECK(!catch_callback_called); | 21174 CHECK(!catch_callback_called); |
21069 } | 21175 } |
21070 | 21176 |
21071 | 21177 |
21072 TEST(AccessCheckThrows) { | 21178 TEST(AccessCheckThrows) { |
21073 i::FLAG_allow_natives_syntax = true; | 21179 i::FLAG_allow_natives_syntax = true; |
21074 v8::V8::Initialize(); | 21180 v8::V8::Initialize(); |
21075 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); | 21181 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); |
21076 v8::HandleScope scope(CcTest::isolate()); | 21182 v8::Isolate* isolate = CcTest::isolate(); |
| 21183 v8::HandleScope scope(isolate); |
21077 | 21184 |
21078 // Create an ObjectTemplate for global objects and install access | 21185 // Create an ObjectTemplate for global objects and install access |
21079 // check callbacks that will block access. | 21186 // check callbacks that will block access. |
21080 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 21187 v8::Handle<v8::ObjectTemplate> global_template = |
| 21188 v8::ObjectTemplate::New(isolate); |
21081 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, | 21189 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked, |
21082 IndexAccessAlwaysBlocked); | 21190 IndexAccessAlwaysBlocked); |
21083 | 21191 |
21084 // Create a context and set an x property on it's global object. | 21192 // Create a context and set an x property on it's global object. |
21085 LocalContext context0(NULL, global_template); | 21193 LocalContext context0(NULL, global_template); |
21086 context0->Global()->Set(v8_str("x"), v8_num(42)); | 21194 context0->Global()->Set(v8_str("x"), v8_num(42)); |
21087 v8::Handle<v8::Object> global0 = context0->Global(); | 21195 v8::Handle<v8::Object> global0 = context0->Global(); |
21088 | 21196 |
21089 // Create a context with a different security token so that the | 21197 // Create a context with a different security token so that the |
21090 // failed access check callback will be called on each access. | 21198 // failed access check callback will be called on each access. |
21091 LocalContext context1(NULL, global_template); | 21199 LocalContext context1(NULL, global_template); |
21092 context1->Global()->Set(v8_str("other"), global0); | 21200 context1->Global()->Set(v8_str("other"), global0); |
21093 | 21201 |
21094 v8::Handle<v8::FunctionTemplate> catcher_fun = | 21202 v8::Handle<v8::FunctionTemplate> catcher_fun = |
21095 v8::FunctionTemplate::New(CcTest::isolate(), CatcherCallback); | 21203 v8::FunctionTemplate::New(isolate, CatcherCallback); |
21096 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); | 21204 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); |
21097 | 21205 |
21098 v8::Handle<v8::FunctionTemplate> has_own_property_fun = | 21206 v8::Handle<v8::FunctionTemplate> has_own_property_fun = |
21099 v8::FunctionTemplate::New(CcTest::isolate(), HasOwnPropertyCallback); | 21207 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback); |
21100 context1->Global()->Set(v8_str("has_own_property"), | 21208 context1->Global()->Set(v8_str("has_own_property"), |
21101 has_own_property_fun->GetFunction()); | 21209 has_own_property_fun->GetFunction()); |
21102 | 21210 |
21103 { v8::TryCatch try_catch; | 21211 { v8::TryCatch try_catch; |
21104 access_check_fail_thrown = false; | 21212 access_check_fail_thrown = false; |
21105 CompileRun("other.x;"); | 21213 CompileRun("other.x;"); |
21106 CHECK(access_check_fail_thrown); | 21214 CHECK(access_check_fail_thrown); |
21107 CHECK(try_catch.HasCaught()); | 21215 CHECK(try_catch.HasCaught()); |
21108 } | 21216 } |
21109 | 21217 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21541 } | 21649 } |
21542 for (int i = 0; i < runs; i++) { | 21650 for (int i = 0; i < runs; i++) { |
21543 Local<String> expected; | 21651 Local<String> expected; |
21544 if (i != 0) { | 21652 if (i != 0) { |
21545 CHECK_EQ(v8_str("escape value"), values[i]); | 21653 CHECK_EQ(v8_str("escape value"), values[i]); |
21546 } else { | 21654 } else { |
21547 CHECK(values[i].IsEmpty()); | 21655 CHECK(values[i].IsEmpty()); |
21548 } | 21656 } |
21549 } | 21657 } |
21550 } | 21658 } |
OLD | NEW |