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 16575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16586 v8::V8::SetFatalErrorHandler(CountingErrorCallback); | 16586 v8::V8::SetFatalErrorHandler(CountingErrorCallback); |
16587 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); | 16587 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); |
16588 i::Isolate::Current()->TearDown(); | 16588 i::Isolate::Current()->TearDown(); |
16589 CHECK(!i::Internals::IsInitialized(isolate)); | 16589 CHECK(!i::Internals::IsInitialized(isolate)); |
16590 CHECK_EQ(1, fatal_error_callback_counter); | 16590 CHECK_EQ(1, fatal_error_callback_counter); |
16591 CHECK(v8::String::Empty().IsEmpty()); | 16591 CHECK(v8::String::Empty().IsEmpty()); |
16592 CHECK_EQ(2, fatal_error_callback_counter); | 16592 CHECK_EQ(2, fatal_error_callback_counter); |
16593 CHECK(v8::String::Empty(isolate).IsEmpty()); | 16593 CHECK(v8::String::Empty(isolate).IsEmpty()); |
16594 CHECK_EQ(3, fatal_error_callback_counter); | 16594 CHECK_EQ(3, fatal_error_callback_counter); |
16595 } | 16595 } |
16596 | |
16597 | |
16598 static int instance_checked_getter_count = 0; | |
16599 static Handle<Value> InstanceCheckedGetter(Local<String> name, | |
16600 const AccessorInfo& info) { | |
16601 printf("InstanceCheckedGetter!\n"); | |
Sven Panne
2012/06/04 07:50:32
Hmmm, do we really need printf in unit tests?
Michael Starzinger
2012/06/04 09:11:15
Done. Ooops, forgot to remove that again.
| |
16602 CHECK_EQ(name, v8_str("foo")); | |
16603 instance_checked_getter_count++; | |
16604 return v8_num(11); | |
16605 } | |
16606 | |
16607 | |
16608 static int instance_checked_setter_count = 0; | |
16609 static void InstanceCheckedSetter(Local<String> name, | |
16610 Local<Value> value, | |
16611 const AccessorInfo& info) { | |
16612 printf("InstanceCheckedSetter!\n"); | |
16613 CHECK_EQ(name, v8_str("foo")); | |
16614 CHECK_EQ(value, v8_num(23)); | |
16615 instance_checked_setter_count++; | |
16616 } | |
16617 | |
16618 | |
16619 static void CheckInstanceCheckedResult(int getters, | |
16620 int setters, | |
16621 bool expects_callbacks, | |
16622 TryCatch* try_catch) { | |
16623 if (expects_callbacks) { | |
16624 CHECK(!try_catch->HasCaught()); | |
16625 CHECK_EQ(getters, instance_checked_getter_count); | |
16626 CHECK_EQ(setters, instance_checked_setter_count); | |
16627 } else { | |
16628 CHECK(try_catch->HasCaught()); | |
16629 CHECK_EQ(0, instance_checked_getter_count); | |
16630 CHECK_EQ(0, instance_checked_setter_count); | |
16631 } | |
16632 try_catch->Reset(); | |
16633 } | |
16634 | |
16635 | |
16636 static void CheckInstanceCheckedAccessors(bool expects_callbacks) { | |
16637 instance_checked_getter_count = 0; | |
16638 instance_checked_setter_count = 0; | |
16639 TryCatch try_catch; | |
16640 | |
16641 // Test path through generic runtime code. | |
16642 CompileRun("obj.foo"); | |
16643 CheckInstanceCheckedResult(1, 0, expects_callbacks, &try_catch); | |
16644 CompileRun("obj.foo = 23"); | |
16645 CheckInstanceCheckedResult(1, 1, expects_callbacks, &try_catch); | |
16646 | |
16647 // Test path through generated LoadIC and StoredIC. | |
16648 CompileRun("function test_get(o) { o.foo; }" | |
16649 "test_get(obj);"); | |
16650 CheckInstanceCheckedResult(2, 1, expects_callbacks, &try_catch); | |
16651 CompileRun("test_get(obj);"); | |
16652 CheckInstanceCheckedResult(3, 1, expects_callbacks, &try_catch); | |
16653 CompileRun("test_get(obj);"); | |
16654 CheckInstanceCheckedResult(4, 1, expects_callbacks, &try_catch); | |
16655 CompileRun("function test_set(o) { o.foo = 23; }" | |
16656 "test_set(obj);"); | |
16657 CheckInstanceCheckedResult(4, 2, expects_callbacks, &try_catch); | |
16658 CompileRun("test_set(obj);"); | |
16659 CheckInstanceCheckedResult(4, 3, expects_callbacks, &try_catch); | |
16660 CompileRun("test_set(obj);"); | |
16661 CheckInstanceCheckedResult(4, 4, expects_callbacks, &try_catch); | |
16662 | |
16663 // Test path through optimized code. | |
16664 CompileRun("%OptimizeFunctionOnNextCall(test_get);" | |
16665 "test_get(obj);"); | |
16666 CheckInstanceCheckedResult(5, 4, expects_callbacks, &try_catch); | |
16667 CompileRun("%OptimizeFunctionOnNextCall(test_set);" | |
16668 "test_set(obj);"); | |
16669 CheckInstanceCheckedResult(5, 5, expects_callbacks, &try_catch); | |
16670 | |
16671 // Cleanup so that closures start out fresh in next check. | |
16672 CompileRun("%DeoptimizeFunction(test_get);" | |
16673 "%ClearFunctionTypeFeedback(test_get);" | |
16674 "%DeoptimizeFunction(test_set);" | |
16675 "%ClearFunctionTypeFeedback(test_set);"); | |
16676 } | |
16677 | |
16678 | |
16679 THREADED_TEST(InstanceCheckOnInstanceAccessor) { | |
16680 v8::internal::FLAG_allow_natives_syntax = true; | |
16681 v8::HandleScope scope; | |
16682 LocalContext context; | |
16683 | |
16684 Local<FunctionTemplate> templ = FunctionTemplate::New(); | |
16685 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | |
16686 inst->SetAccessor(v8_str("foo"), | |
16687 InstanceCheckedGetter, InstanceCheckedSetter, | |
16688 Handle<Value>(), | |
16689 v8::DEFAULT, | |
16690 v8::None, | |
16691 templ); | |
16692 context->Global()->Set(v8_str("f"), templ->GetFunction()); | |
16693 | |
16694 printf("Testing positive ...\n"); | |
16695 CompileRun("var obj = new f();"); | |
16696 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16697 CheckInstanceCheckedAccessors(true); | |
16698 | |
16699 printf("Testing negative ...\n"); | |
16700 CompileRun("var obj = {};" | |
16701 "obj.__proto__ = new f();"); | |
16702 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16703 CheckInstanceCheckedAccessors(false); | |
16704 } | |
16705 | |
16706 | |
16707 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { | |
16708 v8::internal::FLAG_allow_natives_syntax = true; | |
16709 v8::HandleScope scope; | |
16710 LocalContext context; | |
16711 | |
16712 Local<FunctionTemplate> templ = FunctionTemplate::New(); | |
16713 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | |
16714 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); | |
16715 inst->SetAccessor(v8_str("foo"), | |
16716 InstanceCheckedGetter, InstanceCheckedSetter, | |
16717 Handle<Value>(), | |
16718 v8::DEFAULT, | |
16719 v8::None, | |
16720 templ); | |
16721 context->Global()->Set(v8_str("f"), templ->GetFunction()); | |
16722 | |
16723 printf("Testing positive ...\n"); | |
16724 CompileRun("var obj = new f();"); | |
16725 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16726 CheckInstanceCheckedAccessors(true); | |
16727 | |
16728 printf("Testing negative ...\n"); | |
16729 CompileRun("var obj = {};" | |
16730 "obj.__proto__ = new f();"); | |
16731 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16732 CheckInstanceCheckedAccessors(false); | |
16733 } | |
16734 | |
16735 | |
16736 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { | |
16737 v8::internal::FLAG_allow_natives_syntax = true; | |
16738 v8::HandleScope scope; | |
16739 LocalContext context; | |
16740 | |
16741 Local<FunctionTemplate> templ = FunctionTemplate::New(); | |
16742 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); | |
16743 proto->SetAccessor(v8_str("foo"), | |
16744 InstanceCheckedGetter, InstanceCheckedSetter, | |
16745 Handle<Value>(), | |
16746 v8::DEFAULT, | |
16747 v8::None, | |
16748 templ); | |
16749 context->Global()->Set(v8_str("f"), templ->GetFunction()); | |
16750 | |
16751 printf("Testing positive ...\n"); | |
16752 CompileRun("var obj = new f();"); | |
16753 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16754 CheckInstanceCheckedAccessors(true); | |
16755 | |
16756 printf("Testing negative ...\n"); | |
16757 CompileRun("var obj = {};" | |
16758 "obj.__proto__ = new f();"); | |
16759 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16760 CheckInstanceCheckedAccessors(false); | |
16761 | |
16762 printf("Testing positive with modified prototype chain ...\n"); | |
16763 CompileRun("var obj = new f();" | |
16764 "var pro = {};" | |
16765 "pro.__proto__ = obj.__proto__;" | |
16766 "obj.__proto__ = pro;"); | |
16767 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | |
16768 CheckInstanceCheckedAccessors(true); | |
16769 } | |
OLD | NEW |