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

Side by Side Diff: test/cctest/test-object-observe.cc

Issue 1424703005: Remove JSBuiltinsObject. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/objects.h ('K') | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 .FromJust(); 745 .FromJust();
746 CHECK(CompileRun("Object.getNotifier(obj)")->IsObject()); 746 CHECK(CompileRun("Object.getNotifier(obj)")->IsObject());
747 } 747 }
748 } 748 }
749 749
750 750
751 static int GetGlobalObjectsCount() { 751 static int GetGlobalObjectsCount() {
752 int count = 0; 752 int count = 0;
753 i::HeapIterator it(CcTest::heap()); 753 i::HeapIterator it(CcTest::heap());
754 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) 754 for (i::HeapObject* object = it.next(); object != NULL; object = it.next())
755 if (object->IsJSGlobalObject()) count++; 755 if (object->IsJSGlobalObject()) {
756 return count; 756 i::JSGlobalObject* g = i::JSGlobalObject::cast(object);
757 // Skip dummy global object.
758 if (i::GlobalDictionary::cast(g->properties())->NumberOfElements() != 0) {
759 count++;
760 }
761 }
762 // Subtract one to compensate for the code stub context that is always present
763 return count - 1;
757 } 764 }
758 765
759 766
760 static void CheckSurvivingGlobalObjectsCount(int expected) { 767 static void CheckSurvivingGlobalObjectsCount(int expected) {
761 // We need to collect all garbage twice to be sure that everything 768 // We need to collect all garbage twice to be sure that everything
762 // has been collected. This is because inline caches are cleared in 769 // has been collected. This is because inline caches are cleared in
763 // the first garbage collection but some of the maps have already 770 // the first garbage collection but some of the maps have already
764 // been marked at that point. Therefore some of the maps are not 771 // been marked at that point. Therefore some of the maps are not
765 // collected until the second garbage collection. 772 // collected until the second garbage collection.
766 CcTest::heap()->CollectAllGarbage(); 773 CcTest::heap()->CollectAllGarbage();
(...skipping 20 matching lines...) Expand all
787 context2->Global() 794 context2->Global()
788 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"), 795 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"),
789 object) 796 object)
790 .FromJust(); 797 .FromJust();
791 CompileRun("function observer() {};" 798 CompileRun("function observer() {};"
792 "Object.observe(obj, observer, ['foo', 'bar', 'baz']);" 799 "Object.observe(obj, observer, ['foo', 'bar', 'baz']);"
793 "Object.unobserve(obj, observer);"); 800 "Object.unobserve(obj, observer);");
794 } 801 }
795 802
796 CcTest::isolate()->ContextDisposedNotification(); 803 CcTest::isolate()->ContextDisposedNotification();
797 CheckSurvivingGlobalObjectsCount(2); 804 CheckSurvivingGlobalObjectsCount(1);
798 } 805 }
799 806
800 807
801 TEST(DontLeakContextOnGetNotifier) { 808 TEST(DontLeakContextOnGetNotifier) {
802 HandleScope scope(CcTest::isolate()); 809 HandleScope scope(CcTest::isolate());
803 Local<Value> foo = v8_str("foo"); 810 Local<Value> foo = v8_str("foo");
804 LocalContext context(CcTest::isolate()); 811 LocalContext context(CcTest::isolate());
805 context->SetSecurityToken(foo); 812 context->SetSecurityToken(foo);
806 CompileRun("var obj = {};"); 813 CompileRun("var obj = {};");
807 Local<Value> object = CompileRun("obj"); 814 Local<Value> object = CompileRun("obj");
808 { 815 {
809 HandleScope scope(CcTest::isolate()); 816 HandleScope scope(CcTest::isolate());
810 LocalContext context2(CcTest::isolate()); 817 LocalContext context2(CcTest::isolate());
811 context2->SetSecurityToken(foo); 818 context2->SetSecurityToken(foo);
812 context2->Global() 819 context2->Global()
813 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"), 820 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"),
814 object) 821 object)
815 .FromJust(); 822 .FromJust();
816 CompileRun("Object.getNotifier(obj);"); 823 CompileRun("Object.getNotifier(obj);");
817 } 824 }
818 825
819 CcTest::isolate()->ContextDisposedNotification(); 826 CcTest::isolate()->ContextDisposedNotification();
820 CheckSurvivingGlobalObjectsCount(2); 827 CheckSurvivingGlobalObjectsCount(1);
821 } 828 }
822 829
823 830
824 TEST(DontLeakContextOnNotifierPerformChange) { 831 TEST(DontLeakContextOnNotifierPerformChange) {
825 HandleScope scope(CcTest::isolate()); 832 HandleScope scope(CcTest::isolate());
826 Local<Value> foo = v8_str("foo"); 833 Local<Value> foo = v8_str("foo");
827 LocalContext context(CcTest::isolate()); 834 LocalContext context(CcTest::isolate());
828 context->SetSecurityToken(foo); 835 context->SetSecurityToken(foo);
829 CompileRun("var obj = {};"); 836 CompileRun("var obj = {};");
830 Local<Value> object = CompileRun("obj"); 837 Local<Value> object = CompileRun("obj");
(...skipping 10 matching lines...) Expand all
841 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), 848 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(),
842 v8_str("notifier"), notifier) 849 v8_str("notifier"), notifier)
843 .FromJust(); 850 .FromJust();
844 CompileRun("var obj2 = {};" 851 CompileRun("var obj2 = {};"
845 "var notifier2 = Object.getNotifier(obj2);" 852 "var notifier2 = Object.getNotifier(obj2);"
846 "notifier2.performChange.call(" 853 "notifier2.performChange.call("
847 "notifier, 'foo', function(){})"); 854 "notifier, 'foo', function(){})");
848 } 855 }
849 856
850 CcTest::isolate()->ContextDisposedNotification(); 857 CcTest::isolate()->ContextDisposedNotification();
851 CheckSurvivingGlobalObjectsCount(2); 858 CheckSurvivingGlobalObjectsCount(1);
852 } 859 }
853 860
854 861
855 static void ObserverCallback(const FunctionCallbackInfo<Value>& args) { 862 static void ObserverCallback(const FunctionCallbackInfo<Value>& args) {
856 *static_cast<int*>(Local<External>::Cast(args.Data())->Value()) = 863 *static_cast<int*>(Local<External>::Cast(args.Data())->Value()) =
857 Local<Array>::Cast(args[0])->Length(); 864 Local<Array>::Cast(args[0])->Length();
858 } 865 }
859 866
860 867
861 TEST(ObjectObserveCallsCppFunction) { 868 TEST(ObjectObserveCallsCppFunction) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 v8::Isolate::GetCurrent()->GetCurrentContext()) 1034 v8::Isolate::GetCurrent()->GetCurrentContext())
1028 .ToLocalChecked(); 1035 .ToLocalChecked();
1029 env->Global() 1036 env->Global()
1030 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"), 1037 ->Set(v8::Isolate::GetCurrent()->GetCurrentContext(), v8_str("obj"),
1031 new_instance) 1038 new_instance)
1032 .FromJust(); 1039 .FromJust();
1033 v8::TryCatch try_catch(isolate); 1040 v8::TryCatch try_catch(isolate);
1034 CompileRun("Object.getNotifier(obj)"); 1041 CompileRun("Object.getNotifier(obj)");
1035 CHECK(try_catch.HasCaught()); 1042 CHECK(try_catch.HasCaught());
1036 } 1043 }
OLDNEW
« src/objects.h ('K') | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698