Index: test/cctest/test-heap-profiler.cc |
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc |
index eeb722c7fb5e405544be8c363dc21fa3bb6c5827..12972f2687bd4cbb4460ca9369c50b7733c7d622 100644 |
--- a/test/cctest/test-heap-profiler.cc |
+++ b/test/cctest/test-heap-profiler.cc |
@@ -3040,3 +3040,28 @@ TEST(SamplingHeapProfilerApiAllocation) { |
heap_profiler->StopSamplingHeapProfiler(); |
} |
+ |
+TEST(SamplingHeapProfilerLeftTrimming) { |
+ v8::HandleScope scope(v8::Isolate::GetCurrent()); |
+ LocalContext env; |
+ v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
+ |
+ // Suppress randomness to avoid flakiness in tests. |
+ v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true; |
+ |
+ heap_profiler->StartSamplingHeapProfiler(64); |
+ |
+ CompileRun( |
+ "for (var j = 0; j < 500; ++j) {\n" |
+ " var a = [];\n" |
+ " for (var i = 0; i < 5; ++i)\n" |
+ " a[i] = i;\n" |
+ " for (var i = 0; i < 3; ++i)\n" |
+ " a.shift();\n" |
+ "}\n"); |
+ |
+ CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); |
+ // Should not crash. |
+ |
+ heap_profiler->StopSamplingHeapProfiler(); |
+} |