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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-observe.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-object-observe.cc
diff --git a/test/cctest/test-object-observe.cc b/test/cctest/test-object-observe.cc
index 64634ad79a6a0d3642034b7601e06ce5faeb43b6..50e2230fbac82c6cea87264704b03e08726f7ba8 100644
--- a/test/cctest/test-object-observe.cc
+++ b/test/cctest/test-object-observe.cc
@@ -834,3 +834,54 @@ TEST(APIAccessorsShouldNotNotify) {
CompileRun("Object.defineProperty(obj, 'accessor', { value: 44 });");
CHECK(CompileRun("records")->IsNull());
}
+
+
+namespace {
+
+int* global_use_counts = NULL;
+
+void MockUseCounterCallback(v8::Isolate* isolate,
+ v8::Isolate::UseCounterFeature feature) {
+ ++global_use_counts[feature];
+}
+}
+
+
+TEST(UseCountObjectObserve) {
+ i::Isolate* isolate = CcTest::i_isolate();
+ i::HandleScope scope(isolate);
+ LocalContext env;
+ int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
+ global_use_counts = use_counts;
+ CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
+ CompileRun(
+ "var obj = {};"
+ "Object.observe(obj, function(){})");
+ CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
+ CompileRun(
+ "var obj2 = {};"
+ "Object.observe(obj2, function(){})");
+ // Only counts the first use of observe in a given context.
+ CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
+ {
+ LocalContext env2;
+ CompileRun(
+ "var obj = {};"
+ "Object.observe(obj, function(){})");
+ }
+ // Counts different contexts separately.
+ CHECK_EQ(2, use_counts[v8::Isolate::kObjectObserve]);
+}
+
+
+TEST(UseCountObjectGetNotifier) {
+ i::Isolate* isolate = CcTest::i_isolate();
+ i::HandleScope scope(isolate);
+ LocalContext env;
+ int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
+ global_use_counts = use_counts;
+ CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
+ CompileRun("var obj = {}");
+ CompileRun("Object.getNotifier(obj)");
+ CHECK_EQ(1, use_counts[v8::Isolate::kObjectObserve]);
+}
« 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