}
-static void EnsureNoSurvivingGlobalObjects() {
+static int GetSurvivingGlobalObjectsCount() {
int count = 0;
v8::internal::Heap::CollectAllGarbage();
v8::internal::HeapIterator it;
#ifdef DEBUG
if (count > 0) v8::internal::Heap::TracePathToGlobal();
#endif
- CHECK_EQ(0, count);
+ return count;
}
-// This test assumes that there are zero global objects when the
-// test starts. This is not going to be true if we are using the
-// API fuzzer.
TEST(DontLeakGlobalObjects) {
// Regression test for issues 1139850 and 1174891.
- v8::internal::V8::Initialize(NULL);
- if (v8::internal::Snapshot::IsEnabled()) return;
+ v8::V8::Initialize();
- EnsureNoSurvivingGlobalObjects();
+ int count = GetSurvivingGlobalObjectsCount();
for (int i = 0; i < 5; i++) {
{ v8::HandleScope scope;
LocalContext context;
}
- EnsureNoSurvivingGlobalObjects();
+ CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
{ v8::HandleScope scope;
LocalContext context;
v8_compile("Date")->Run();
}
- EnsureNoSurvivingGlobalObjects();
+ CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
{ v8::HandleScope scope;
LocalContext context;
v8_compile("/aaa/")->Run();
}
- EnsureNoSurvivingGlobalObjects();
+ CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
{ v8::HandleScope scope;
const char* extension_list[] = { "v8/gc" };
LocalContext context(&extensions);
v8_compile("gc();")->Run();
}
- EnsureNoSurvivingGlobalObjects();
+ CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
{ v8::HandleScope scope;
const char* extension_list[] = { "v8/print" };
LocalContext context(&extensions);
v8_compile("print('hest');")->Run();
}
- EnsureNoSurvivingGlobalObjects();
+ CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
}
}
THREADED_TEST(CheckForCrossContextObjectLiterals) {
- v8::internal::V8::Initialize(NULL);
- if (v8::internal::Snapshot::IsEnabled()) return;
+ v8::V8::Initialize();
const int nof = 2;
const char* sources[nof] = {
// This has to be updated if the number of native scripts change.
assertEquals(12, native_count);
+// If no snapshot is used, only the 'gc' extension is loaded.
+// If snapshot is used, all extensions are cached in the snapshot.
+assertTrue(extension_count == 1 || extension_count == 5);
assertEquals(2, normal_count); // This script and mjsunit.js.
// Test a builtins script.