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

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

Issue 1048213002: Add a UseCounter for Object.observe (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use HandleScope instead of SealHandleScope in %GetObservationState Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-observe.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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 &AccessorSetter); 827 &AccessorSetter);
828 context->Global()->Set(String::NewFromUtf8(isolate, "obj"), object); 828 context->Global()->Set(String::NewFromUtf8(isolate, "obj"), object);
829 CompileRun( 829 CompileRun(
830 "var records = null;" 830 "var records = null;"
831 "Object.observe(obj, function(r) { records = r });" 831 "Object.observe(obj, function(r) { records = r });"
832 "obj.accessor = 43;"); 832 "obj.accessor = 43;");
833 CHECK(CompileRun("records")->IsNull()); 833 CHECK(CompileRun("records")->IsNull());
834 CompileRun("Object.defineProperty(obj, 'accessor', { value: 44 });"); 834 CompileRun("Object.defineProperty(obj, 'accessor', { value: 44 });");
835 CHECK(CompileRun("records")->IsNull()); 835 CHECK(CompileRun("records")->IsNull());
836 } 836 }
837
838
839 namespace {
840
841 int* global_use_counts = NULL;
842
843 void MockUseCounterCallback(v8::Isolate* isolate,
844 v8::Isolate::UseCounterFeature feature) {
845 ++global_use_counts[feature];
846 }
847 }
848
849
850 TEST(UseCountObjectObserve) {
851 i::Isolate* isolate = CcTest::i_isolate();
852 i::HandleScope scope(isolate);
853 LocalContext env;
854 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
855 global_use_counts = use_counts;
856 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
857 CompileRun(
858 "var obj = {};"
859 "Object.observe(obj, function(){})");
860 CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
861 CompileRun(
862 "var obj2 = {};"
863 "Object.observe(obj2, function(){})");
864 // Only counts the first use of observe in a given context.
865 CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
866 {
867 LocalContext env2;
868 CompileRun(
869 "var obj = {};"
870 "Object.observe(obj, function(){})");
871 }
872 // Counts different contexts separately.
873 CHECK_EQ(2, use_counts[v8::Isolate::kObjectObserve]);
874 }
875
876
877 TEST(UseCountObjectGetNotifier) {
878 i::Isolate* isolate = CcTest::i_isolate();
879 i::HandleScope scope(isolate);
880 LocalContext env;
881 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
882 global_use_counts = use_counts;
883 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
884 CompileRun("var obj = {}");
885 CompileRun("Object.getNotifier(obj)");
886 CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
887 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-observe.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698