| Index: test/cctest/cctest.h
|
| diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h
|
| index ceb97743eb81ecedcdf89b8aca2558b0fc14c5bb..122d36d5b8383fb30abbcb4fbb359f22ebfc21fb 100644
|
| --- a/test/cctest/cctest.h
|
| +++ b/test/cctest/cctest.h
|
| @@ -31,23 +31,30 @@
|
| #include "v8.h"
|
|
|
| #ifndef TEST
|
| -#define TEST(Name) \
|
| - static void Test##Name(); \
|
| - CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true); \
|
| +#define TEST(Name) \
|
| + static void Test##Name(); \
|
| + CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, true); \
|
| + static void Test##Name()
|
| +#endif
|
| +
|
| +#ifndef UNINITIALIZED_TEST
|
| +#define UNINITIALIZED_TEST(Name) \
|
| + static void Test##Name(); \
|
| + CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, false); \
|
| static void Test##Name()
|
| #endif
|
|
|
| #ifndef DEPENDENT_TEST
|
| -#define DEPENDENT_TEST(Name, Dep) \
|
| - static void Test##Name(); \
|
| - CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true); \
|
| +#define DEPENDENT_TEST(Name, Dep) \
|
| + static void Test##Name(); \
|
| + CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true, true); \
|
| static void Test##Name()
|
| #endif
|
|
|
| #ifndef DISABLED_TEST
|
| -#define DISABLED_TEST(Name) \
|
| - static void Test##Name(); \
|
| - CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false); \
|
| +#define DISABLED_TEST(Name) \
|
| + static void Test##Name(); \
|
| + CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false, true); \
|
| static void Test##Name()
|
| #endif
|
|
|
| @@ -71,51 +78,62 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
|
| EXTENSION_LIST(DEFINE_EXTENSION_FLAG)
|
| #undef DEFINE_EXTENSION_FLAG
|
|
|
| -// Temporary macros for accessing current isolate and its subobjects.
|
| -// They provide better readability, especially when used a lot in the code.
|
| -#define HEAP (v8::internal::Isolate::Current()->heap())
|
|
|
| class CcTest {
|
| public:
|
| typedef void (TestFunction)();
|
| CcTest(TestFunction* callback, const char* file, const char* name,
|
| - const char* dependency, bool enabled);
|
| - void Run() { callback_(); }
|
| + const char* dependency, bool enabled, bool initialize);
|
| + void Run();
|
| static CcTest* last() { return last_; }
|
| CcTest* prev() { return prev_; }
|
| const char* file() { return file_; }
|
| const char* name() { return name_; }
|
| const char* dependency() { return dependency_; }
|
| bool enabled() { return enabled_; }
|
| - static v8::Isolate* default_isolate() { return default_isolate_; }
|
|
|
| - static v8::Handle<v8::Context> env() {
|
| - return v8::Local<v8::Context>::New(default_isolate_, context_);
|
| + static v8::Isolate* isolate() {
|
| + isolate_used_ = true;
|
| + return isolate_;
|
| }
|
|
|
| - static v8::Isolate* isolate() { return default_isolate_; }
|
| -
|
| static i::Isolate* i_isolate() {
|
| - return reinterpret_cast<i::Isolate*>(default_isolate_);
|
| + return reinterpret_cast<i::Isolate*>(isolate());
|
| + }
|
| +
|
| + static i::Heap* heap() {
|
| + return i_isolate()->heap();
|
| + }
|
| +
|
| + // TODO(dcarney): Remove.
|
| + // This must be called first in a test.
|
| + static void InitializeVM() {
|
| + CHECK(!isolate_used_);
|
| + CHECK(!initialize_called_);
|
| + initialize_called_ = true;
|
| + v8::HandleScope handle_scope(CcTest::isolate());
|
| + v8::Context::New(CcTest::isolate())->Enter();
|
| }
|
|
|
| - // Helper function to initialize the VM.
|
| - static void InitializeVM(CcTestExtensionFlags extensions = NO_EXTENSIONS);
|
| + // Helper function to configure a context.
|
| + // Must be in a HandleScope.
|
| + static v8::Local<v8::Context> NewContext(
|
| + CcTestExtensionFlags extensions,
|
| + v8::Isolate* isolate = CcTest::isolate());
|
|
|
| private:
|
| friend int main(int argc, char** argv);
|
| - static void set_default_isolate(v8::Isolate* default_isolate) {
|
| - default_isolate_ = default_isolate;
|
| - }
|
| TestFunction* callback_;
|
| const char* file_;
|
| const char* name_;
|
| const char* dependency_;
|
| bool enabled_;
|
| + bool initialize_;
|
| CcTest* prev_;
|
| static CcTest* last_;
|
| - static v8::Isolate* default_isolate_;
|
| - static v8::Persistent<v8::Context> context_;
|
| + static v8::Isolate* isolate_;
|
| + static bool initialize_called_;
|
| + static bool isolate_used_;
|
| };
|
|
|
| // Switches between all the Api tests using the threading support.
|
| @@ -211,20 +229,19 @@ class RegisterThreadedTest {
|
| // A LocalContext holds a reference to a v8::Context.
|
| class LocalContext {
|
| public:
|
| + LocalContext(v8::Isolate* isolate,
|
| + v8::ExtensionConfiguration* extensions = 0,
|
| + v8::Handle<v8::ObjectTemplate> global_template =
|
| + v8::Handle<v8::ObjectTemplate>(),
|
| + v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
|
| + Initialize(isolate, extensions, global_template, global_object);
|
| + }
|
| +
|
| LocalContext(v8::ExtensionConfiguration* extensions = 0,
|
| v8::Handle<v8::ObjectTemplate> global_template =
|
| v8::Handle<v8::ObjectTemplate>(),
|
| v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
|
| - v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
| - v8::HandleScope scope(isolate);
|
| - v8::Local<v8::Context> context = v8::Context::New(isolate,
|
| - extensions,
|
| - global_template,
|
| - global_object);
|
| - context_.Reset(isolate, context);
|
| - context->Enter();
|
| - // We can't do this later perhaps because of a fatal error.
|
| - isolate_ = context->GetIsolate();
|
| + Initialize(CcTest::isolate(), extensions, global_template, global_object);
|
| }
|
|
|
| virtual ~LocalContext() {
|
| @@ -244,6 +261,21 @@ class LocalContext {
|
| }
|
|
|
| private:
|
| + void Initialize(v8::Isolate* isolate,
|
| + v8::ExtensionConfiguration* extensions,
|
| + v8::Handle<v8::ObjectTemplate> global_template,
|
| + v8::Handle<v8::Value> global_object) {
|
| + v8::HandleScope scope(isolate);
|
| + v8::Local<v8::Context> context = v8::Context::New(isolate,
|
| + extensions,
|
| + global_template,
|
| + global_object);
|
| + context_.Reset(isolate, context);
|
| + context->Enter();
|
| + // We can't do this later perhaps because of a fatal error.
|
| + isolate_ = isolate;
|
| + }
|
| +
|
| v8::Persistent<v8::Context> context_;
|
| v8::Isolate* isolate_;
|
| };
|
|
|