enum InitializationState {kUnset, kUnintialized, kInitialized};
static InitializationState initialization_state_ = kUnset;
+static bool disable_automatic_dispose_ = false;
CcTest* CcTest::last_ = NULL;
bool CcTest::initialize_called_ = false;
if (!initialize_) {
CHECK(initialization_state_ != kInitialized);
initialization_state_ = kUnintialized;
- // TODO(dcarney): Remove this when default isolate is gone.
- if (isolate_ == NULL) {
- isolate_ = v8::Isolate::GetCurrent();
- }
+ CHECK(CcTest::isolate_ == NULL);
} else {
CHECK(initialization_state_ != kUnintialized);
initialization_state_ = kInitialized;
- i::Isolate::SetCrashIfDefaultIsolateInitialized();
if (isolate_ == NULL) {
isolate_ = v8::Isolate::New();
}
}
+void CcTest::DisableAutomaticDispose() {
+ CHECK_EQ(kUnintialized, initialization_state_);
+ disable_automatic_dispose_ = true;
+}
+
+
static void PrintTestList(CcTest* current) {
if (current == NULL) return;
PrintTestList(current->prev());
int main(int argc, char* argv[]) {
v8::V8::InitializeICU();
+ i::Isolate::SetCrashIfDefaultIsolateInitialized();
v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
}
if (print_run_count && tests_run != 1)
printf("Ran %i tests.\n", tests_run);
- v8::V8::Dispose();
+ if (!disable_automatic_dispose_) v8::V8::Dispose();
return 0;
}
bool enabled() { return enabled_; }
static v8::Isolate* isolate() {
+ CHECK(isolate_ != NULL);
isolate_used_ = true;
return isolate_;
}
v8::Context::New(CcTest::isolate())->Enter();
}
+ // Only for UNINITIALIZED_TESTs
+ static void DisableAutomaticDispose();
+
// Helper function to configure a context.
// Must be in a HandleScope.
static v8::Local<v8::Context> NewContext(
// Lets not be needlessly self-referential.
-UNINITIALIZED_TEST(Threading1) {
+TEST(Threading1) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
-UNINITIALIZED_TEST(Threading2) {
+TEST(Threading2) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
-UNINITIALIZED_TEST(Threading3) {
+TEST(Threading3) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
-UNINITIALIZED_TEST(Threading4) {
+TEST(Threading4) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
void ApiTestFuzzer::CallTest() {
+ v8::Isolate::Scope scope(CcTest::isolate());
if (kLogThreading)
printf("Start test %d\n", test_number_);
CallTestNumber(test_number_);
while (gc_during_regexp_ < kRequiredGCs) {
{
v8::Locker lock(CcTest::isolate());
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
// TODO(lrn): Perhaps create some garbage before collecting.
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
gc_count_++;
// Test that a regular expression execution can be interrupted and
// survive a garbage collection.
-UNINITIALIZED_TEST(RegExpInterruption) {
+TEST(RegExpInterruption) {
v8::Locker lock(CcTest::isolate());
- v8::V8::Initialize();
v8::HandleScope scope(CcTest::isolate());
Local<Context> local_env;
{
while (gc_during_apply_ < kRequiredGCs) {
{
v8::Locker lock(CcTest::isolate());
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
gc_count_++;
}
// Test that nothing bad happens if we get a preemption just when we were
// about to do an apply().
-UNINITIALIZED_TEST(ApplyInterruption) {
+TEST(ApplyInterruption) {
v8::Locker lock(CcTest::isolate());
v8::V8::Initialize();
v8::HandleScope scope(CcTest::isolate());
morphs_ < kMaxModifications) {
{
v8::Locker lock(CcTest::isolate());
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
// Swap string between ascii and two-byte representation.
i::String* string = *input_;
MorphAString(string, &ascii_resource_, &uc16_resource_);
// Test that a regular expression execution can be interrupted and
// the string changed without failing.
-UNINITIALIZED_TEST(RegExpStringModification) {
+TEST(RegExpStringModification) {
v8::Locker lock(CcTest::isolate());
- v8::V8::Initialize();
v8::HandleScope scope(CcTest::isolate());
Local<Context> local_env;
{
UNINITIALIZED_TEST(IsolateEmbedderData) {
- v8::Isolate* isolate = CcTest::isolate();
+ CcTest::DisableAutomaticDispose();
+ v8::Isolate* isolate = v8::Isolate::New();
+ isolate->Enter();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
CHECK_EQ(NULL, isolate->GetData());
CHECK_EQ(NULL, i_isolate->GetData());
"\n"
"foo();\n";
- v8::V8::Initialize();
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
DebugLocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
}
-UNINITIALIZED_TEST(ThreadedDebugging) {
+TEST(ThreadedDebugging) {
DebuggerThread debugger_thread;
V8Thread v8_thread;
const char* source_2 = "cat(17);\n"
"cat(19);\n";
- v8::V8::Initialize();
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::Isolate::Scope isolate_scope(isolate);
DebugLocalContext env;
- v8::HandleScope scope(env->GetIsolate());
+ v8::HandleScope scope(isolate);
v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
CompileRun(source_1);
v8::Isolate* isolate = CcTest::isolate();
+ v8::Isolate::Scope isolate_scope(isolate);
// v8 thread initializes, runs source_1
breakpoints_barriers->barrier_1.Wait();
// 1:Set breakpoint in cat() (will get id 1).
}
-UNINITIALIZED_TEST(RecursiveBreakpoints) {
+TEST(RecursiveBreakpoints) {
TestRecursiveBreakpointsGeneric(false);
}
-UNINITIALIZED_TEST(RecursiveBreakpointsGlobal) {
+TEST(RecursiveBreakpointsGlobal) {
TestRecursiveBreakpointsGeneric(true);
}
"\n";
const char* source_2 = "cat(17);\n";
- v8::V8::Initialize();
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
DebugLocalContext env;
v8::HandleScope scope(env->GetIsolate());
}
-UNINITIALIZED_TEST(DebuggerHostDispatch) {
+TEST(DebuggerHostDispatch) {
HostDispatchDebuggerThread host_dispatch_debugger_thread;
HostDispatchV8Thread host_dispatch_v8_thread;
i::FLAG_debugger_auto_break = true;
void DebugMessageDispatchV8Thread::Run() {
- v8::V8::Initialize();
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
DebugLocalContext env;
v8::HandleScope scope(env->GetIsolate());
}
-UNINITIALIZED_TEST(DebuggerDebugMessageDispatch) {
+TEST(DebuggerDebugMessageDispatch) {
DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
// Keep forcing breaks.
if (break_point_hit_count < 20) {
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(CcTest::isolate());
}
}
}
-UNINITIALIZED_TEST(RegExpDebugBreak) {
+TEST(RegExpDebugBreak) {
// This test only applies to native regexps.
DebugLocalContext env;
v8::HandleScope scope(env->GetIsolate());
// Test that if DebugBreak is forced it is ignored when code from
// debug-delay.js is executed.
-UNINITIALIZED_TEST(NoDebugBreakInAfterCompileMessageHandler) {
+TEST(NoDebugBreakInAfterCompileMessageHandler) {
DebugLocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Debug::SetMessageHandler2(BreakMessageHandler);
// Set the debug break flag.
- v8::Debug::DebugBreak();
+ v8::Debug::DebugBreak(env->GetIsolate());
// Create a function for testing stepping.
const char* src = "function f() { eval('var x = 10;'); } ";
virtual void Run() {
v8::Locker lock1(CcTest::isolate());
{
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
v8::HandleScope handle_scope(CcTest::isolate());
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(CcTest::isolate(), context_);
v8::Unlocker unlock1(CcTest::isolate());
{
v8::Locker lock2(CcTest::isolate());
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
v8::HandleScope handle_scope(CcTest::isolate());
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(CcTest::isolate(), context_);
// Locker inside an Unlocker inside a Locker for default isolate.
-UNINITIALIZED_TEST(LockUnlockLockDefaultIsolateMultithreaded) {
+TEST(LockUnlockLockDefaultIsolateMultithreaded) {
#if V8_TARGET_ARCH_MIPS
const int kNThreads = 50;
#else
i::List<JoinableThread*> threads(kNThreads);
{
v8::Locker locker_(CcTest::isolate());
+ v8::Isolate::Scope isolate_scope(CcTest::isolate());
v8::HandleScope handle_scope(CcTest::isolate());
context = v8::Context::New(CcTest::isolate());
for (int i = 0; i < kNThreads; i++) {
}
-UNINITIALIZED_TEST(LogCallbacks) {
+TEST(LogCallbacks) {
ScopedLoggerInitializer initialize_logger;
Logger* logger = initialize_logger.logger();
}
-UNINITIALIZED_TEST(LogAccessorCallbacks) {
+TEST(LogAccessorCallbacks) {
ScopedLoggerInitializer initialize_logger;
Logger* logger = initialize_logger.logger();
// Test that logging of code create / move events is equivalent to traversal of
// a resulting heap.
-UNINITIALIZED_TEST(EquivalenceOfLoggingAndTraversal) {
+TEST(EquivalenceOfLoggingAndTraversal) {
// This test needs to be run on a "clean" V8 to ensure that snapshot log
// is loaded. This is always true when running using tools/test.py because
// it launches a new cctest instance for every test. To be sure that launching
}
-UNINITIALIZED_TEST(Errors) {
- V8::Initialize(NULL);
+TEST(Errors) {
const char* kEndBackslash = "\\ at end of pattern";
ExpectError("\\", kEndBackslash);
const char* kUnterminatedGroup = "Unterminated group";
// Test that the whole heap can be serialized.
-UNINITIALIZED_TEST(Serialize) {
+TEST(Serialize) {
if (!Snapshot::HaveASnapshotToStartFrom()) {
Serializer::Enable(CcTest::i_isolate());
v8::V8::Initialize();
// Test that heap serialization is non-destructive.
-UNINITIALIZED_TEST(SerializeTwice) {
+TEST(SerializeTwice) {
if (!Snapshot::HaveASnapshotToStartFrom()) {
Serializer::Enable(CcTest::i_isolate());
v8::V8::Initialize();
}
-UNINITIALIZED_TEST(PartialSerialization) {
+TEST(PartialSerialization) {
if (!Snapshot::HaveASnapshotToStartFrom()) {
Isolate* isolate = CcTest::i_isolate();
Serializer::Enable(isolate);
}
-UNINITIALIZED_TEST(ContextSerialization) {
+TEST(ContextSerialization) {
if (!Snapshot::HaveASnapshotToStartFrom()) {
Isolate* isolate = CcTest::i_isolate();
Serializer::Enable(isolate);
void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::V8::TerminateExecution(args.GetIsolate());
}
void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) {
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Handle<v8::String> source =
v8::String::New("try { doloop(); fail(); } catch(e) { fail(); }");
v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run();
CHECK(result.IsEmpty());
- CHECK(v8::V8::IsExecutionTerminating());
+ CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
}
void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::TryCatch try_catch;
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Script::Compile(v8::String::New("function f() {"
" var term = true;"
" try {"
CHECK(try_catch.Exception()->IsNull());
CHECK(try_catch.Message().IsEmpty());
CHECK(!try_catch.CanContinue());
- CHECK(v8::V8::IsExecutionTerminating());
+ CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
}
void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::TryCatch try_catch;
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Script::Compile(v8::String::New("var term = true;"
"while(true) {"
" if (term) terminate();"
CHECK(try_catch.Exception()->IsNull());
CHECK(try_catch.Message().IsEmpty());
CHECK(!try_catch.CanContinue());
- CHECK(v8::V8::IsExecutionTerminating());
+ CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
}
v8::Handle<v8::Context> context =
v8::Context::New(CcTest::isolate(), NULL, global);
v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Run a loop that will be infinite if thread termination does not work.
v8::Handle<v8::String> source =
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
v8::Script::Compile(source)->Run();
// Test that we can run the code again after thread termination.
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
v8::Script::Compile(source)->Run();
}
v8::Handle<v8::Context> context =
v8::Context::New(CcTest::isolate(), NULL, global);
v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Run a loop that will be infinite if thread termination does not work.
v8::Handle<v8::String> source =
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
v8::Script::Compile(source)->Run();
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Test that we can run the code again after thread termination.
v8::Script::Compile(source)->Run();
}
v8::Handle<v8::Context> context =
v8::Context::New(CcTest::isolate(), NULL, global);
v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Run a loop that will be infinite if thread termination does not work.
v8::Handle<v8::String> source =
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (++call_count == 10) {
- CHECK(!v8::V8::IsExecutionTerminating());
- v8::V8::TerminateExecution();
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
+ v8::V8::TerminateExecution(args.GetIsolate());
return;
}
v8::Local<v8::Object> result = v8::Object::New();
void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::TryCatch try_catch;
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Script::Compile(v8::String::New("function f() {"
" try {"
" while(true) {"
CHECK(try_catch.Exception()->IsNull());
CHECK(try_catch.Message().IsEmpty());
CHECK(!try_catch.CanContinue());
- CHECK(v8::V8::IsExecutionTerminating());
+ CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
}
// Test that we correctly handle termination exceptions if they are
// triggered by the creation of error objects in connection with ICs.
-UNINITIALIZED_TEST(TerminateLoadICException) {
+TEST(TerminateLoadICException) {
v8::HandleScope scope(CcTest::isolate());
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::New("terminate_or_return_object"),
v8::Handle<v8::Context> context =
v8::Context::New(CcTest::isolate(), NULL, global);
v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Run a loop that will be infinite if thread termination does not work.
v8::Handle<v8::String> source =
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
call_count = 0;
v8::Script::Compile(source)->Run();
// Test that we can run the code again after thread termination.
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
call_count = 0;
v8::Script::Compile(source)->Run();
}
void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::TryCatch try_catch;
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Script::Compile(v8::String::New("function f() {"
" var term = true;"
" try {"
CHECK(try_catch.Exception()->IsNull());
CHECK(try_catch.Message().IsEmpty());
CHECK(!try_catch.CanContinue());
- CHECK(v8::V8::IsExecutionTerminating());
+ CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate()));
v8::Script::Compile(v8::String::New("function f() { fail(); } f()"))->Run();
}
v8::Handle<v8::String> source =
v8::String::New("try { loop(); fail(); } catch(e) { fail(); }");
v8::Script::Compile(source)->Run();
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
// Check we can run JS again after termination.
CHECK(v8::Script::Compile(v8::String::New("function f() { return true; }"
"f()"))->Run()->IsTrue());
CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate);
v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global);
v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
+ CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate()));
v8::Handle<v8::String> source =
v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
// Check that execution completed with correct return value.
void Run() {
v8::Isolate* isolate = CcTest::isolate();
v8::Locker locker(isolate);
+ v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
v8::Handle<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
{
v8::Isolate* isolate = CcTest::isolate();
v8::Locker locker(isolate);
+ v8::Isolate::Scope isolate_scope(isolate);
if (turn == CLEAN_CACHE) {
v8::HandleScope scope(isolate);
v8::Handle<v8::Context> context = v8::Context::New(isolate);
};
-UNINITIALIZED_TEST(JSFunctionResultCachesInTwoThreads) {
- v8::V8::Initialize();
-
+TEST(JSFunctionResultCachesInTwoThreads) {
ThreadA threadA;
ThreadB threadB;