| Index: test/cctest/cctest.cc
|
| diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc
|
| index 616c6a3a6bdf85dcd26433b3403be3cc2a45b03c..962dc02e2f6d29358caf2e8bd47a9b7d54e01a6c 100644
|
| --- a/test/cctest/cctest.cc
|
| +++ b/test/cctest/cctest.cc
|
| @@ -29,13 +29,19 @@
|
| #include "cctest.h"
|
| #include "debug.h"
|
|
|
| +enum InitializationState {kUnset, kUnintialized, kInitialized};
|
| +static InitializationState initialization_state_ = kUnset;
|
|
|
| CcTest* CcTest::last_ = NULL;
|
| +bool CcTest::initialize_called_ = false;
|
| +bool CcTest::isolate_used_ = false;
|
| +v8::Isolate* CcTest::isolate_ = NULL;
|
|
|
|
|
| CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
|
| - const char* dependency, bool enabled)
|
| - : callback_(callback), name_(name), dependency_(dependency), prev_(last_) {
|
| + const char* dependency, bool enabled, bool initialize)
|
| + : callback_(callback), name_(name), dependency_(dependency),
|
| + enabled_(enabled), initialize_(initialize), prev_(last_) {
|
| // Find the base name of this test (const_cast required on Windows).
|
| char *basename = strrchr(const_cast<char *>(file), '/');
|
| if (!basename) {
|
| @@ -51,35 +57,47 @@ CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
|
| if (extension) *extension = 0;
|
| // Install this test in the list of tests
|
| file_ = basename;
|
| - enabled_ = enabled;
|
| prev_ = last_;
|
| last_ = this;
|
| }
|
|
|
|
|
| -v8::Persistent<v8::Context> CcTest::context_;
|
| +void CcTest::Run() {
|
| + 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();
|
| + }
|
| + } else {
|
| + CHECK(initialization_state_ != kUnintialized);
|
| + initialization_state_ = kInitialized;
|
| + i::Isolate::SetCrashIfDefaultIsolateInitialized();
|
| + if (isolate_ == NULL) {
|
| + isolate_ = v8::Isolate::New();
|
| + }
|
| + isolate_->Enter();
|
| + }
|
| + callback_();
|
| + if (initialize_) {
|
| + isolate_->Exit();
|
| + }
|
| +}
|
|
|
|
|
| -void CcTest::InitializeVM(CcTestExtensionFlags extensions) {
|
| - const char* extension_names[kMaxExtensions];
|
| - int extension_count = 0;
|
| -#define CHECK_EXTENSION_FLAG(Name, Id) \
|
| - if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
|
| - EXTENSION_LIST(CHECK_EXTENSION_FLAG)
|
| -#undef CHECK_EXTENSION_FLAG
|
| - v8::Isolate* isolate = default_isolate();
|
| - if (context_.IsEmpty()) {
|
| - v8::HandleScope scope(isolate);
|
| +v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions,
|
| + v8::Isolate* isolate) {
|
| + const char* extension_names[kMaxExtensions];
|
| + int extension_count = 0;
|
| + #define CHECK_EXTENSION_FLAG(Name, Id) \
|
| + if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
|
| + EXTENSION_LIST(CHECK_EXTENSION_FLAG)
|
| + #undef CHECK_EXTENSION_FLAG
|
| v8::ExtensionConfiguration config(extension_count, extension_names);
|
| v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
|
| - context_.Reset(isolate, context);
|
| - }
|
| - {
|
| - v8::HandleScope scope(isolate);
|
| - v8::Local<v8::Context> context =
|
| - v8::Local<v8::Context>::New(isolate, context_);
|
| - context->Enter();
|
| - }
|
| + CHECK(!context.IsEmpty());
|
| + return context;
|
| }
|
|
|
|
|
| @@ -95,9 +113,6 @@ static void PrintTestList(CcTest* current) {
|
| }
|
|
|
|
|
| -v8::Isolate* CcTest::default_isolate_;
|
| -
|
| -
|
| class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
| virtual void* Allocate(size_t length) { return malloc(length); }
|
| virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
|
| @@ -115,13 +130,13 @@ static void SuggestTestHarness(int tests) {
|
|
|
|
|
| int main(int argc, char* argv[]) {
|
| + v8::V8::InitializeICU();
|
| +
|
| v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
|
|
|
| CcTestArrayBufferAllocator array_buffer_allocator;
|
| v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
|
|
|
| - CcTest::set_default_isolate(v8::Isolate::GetCurrent());
|
| - CHECK(CcTest::default_isolate() != NULL);
|
| int tests_run = 0;
|
| bool print_run_count = true;
|
| for (int i = 1; i < argc; i++) {
|
|
|