Revision f230a1cf deps/v8/test/cctest/cctest.cc

View differences:

deps/v8/test/cctest/cctest.cc
29 29
#include "cctest.h"
30 30
#include "debug.h"
31 31

  
32
enum InitializationState {kUnset, kUnintialized, kInitialized};
33
static InitializationState initialization_state_  = kUnset;
34
static bool disable_automatic_dispose_ = false;
32 35

  
33 36
CcTest* CcTest::last_ = NULL;
37
bool CcTest::initialize_called_ = false;
38
bool CcTest::isolate_used_ = false;
39
v8::Isolate* CcTest::isolate_ = NULL;
34 40

  
35 41

  
36 42
CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
37
               const char* dependency, bool enabled)
38
    : callback_(callback), name_(name), dependency_(dependency), prev_(last_) {
43
               const char* dependency, bool enabled, bool initialize)
44
    : callback_(callback), name_(name), dependency_(dependency),
45
      enabled_(enabled), initialize_(initialize), prev_(last_) {
39 46
  // Find the base name of this test (const_cast required on Windows).
40 47
  char *basename = strrchr(const_cast<char *>(file), '/');
41 48
  if (!basename) {
......
51 58
  if (extension) *extension = 0;
52 59
  // Install this test in the list of tests
53 60
  file_ = basename;
54
  enabled_ = enabled;
55 61
  prev_ = last_;
56 62
  last_ = this;
57 63
}
58 64

  
59 65

  
60
v8::Persistent<v8::Context> CcTest::context_;
66
void CcTest::Run() {
67
  if (!initialize_) {
68
    CHECK(initialization_state_ != kInitialized);
69
    initialization_state_ = kUnintialized;
70
    CHECK(CcTest::isolate_ == NULL);
71
  } else {
72
    CHECK(initialization_state_ != kUnintialized);
73
    initialization_state_ = kInitialized;
74
    if (isolate_ == NULL) {
75
      isolate_ = v8::Isolate::New();
76
    }
77
    isolate_->Enter();
78
  }
79
  callback_();
80
  if (initialize_) {
81
    isolate_->Exit();
82
  }
83
}
61 84

  
62 85

  
63
void CcTest::InitializeVM(CcTestExtensionFlags extensions) {
64
  const char* extension_names[kMaxExtensions];
65
  int extension_count = 0;
66
#define CHECK_EXTENSION_FLAG(Name, Id) \
67
  if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
68
  EXTENSION_LIST(CHECK_EXTENSION_FLAG)
69
#undef CHECK_EXTENSION_FLAG
70
  v8::Isolate* isolate = default_isolate();
71
  if (context_.IsEmpty()) {
72
    v8::HandleScope scope(isolate);
86
v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions,
87
                                          v8::Isolate* isolate) {
88
    const char* extension_names[kMaxExtensions];
89
    int extension_count = 0;
90
  #define CHECK_EXTENSION_FLAG(Name, Id) \
91
    if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id;
92
    EXTENSION_LIST(CHECK_EXTENSION_FLAG)
93
  #undef CHECK_EXTENSION_FLAG
73 94
    v8::ExtensionConfiguration config(extension_count, extension_names);
74 95
    v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
75
    context_.Reset(isolate, context);
76
  }
77
  {
78
    v8::HandleScope scope(isolate);
79
    v8::Local<v8::Context> context =
80
        v8::Local<v8::Context>::New(isolate, context_);
81
    context->Enter();
82
  }
96
    CHECK(!context.IsEmpty());
97
    return context;
98
}
99

  
100

  
101
void CcTest::DisableAutomaticDispose() {
102
  CHECK_EQ(kUnintialized, initialization_state_);
103
  disable_automatic_dispose_ = true;
83 104
}
84 105

  
85 106

  
......
95 116
}
96 117

  
97 118

  
98
v8::Isolate* CcTest::default_isolate_;
99

  
100

  
101 119
class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
102 120
  virtual void* Allocate(size_t length) { return malloc(length); }
103 121
  virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
......
115 133

  
116 134

  
117 135
int main(int argc, char* argv[]) {
136
  v8::V8::InitializeICU();
137
  i::Isolate::SetCrashIfDefaultIsolateInitialized();
138

  
118 139
  v8::internal::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
119 140

  
120 141
  CcTestArrayBufferAllocator array_buffer_allocator;
121 142
  v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
122 143

  
123
  CcTest::set_default_isolate(v8::Isolate::GetCurrent());
124
  CHECK(CcTest::default_isolate() != NULL);
125 144
  int tests_run = 0;
126 145
  bool print_run_count = true;
127 146
  for (int i = 1; i < argc; i++) {
......
169 188
  }
170 189
  if (print_run_count && tests_run != 1)
171 190
    printf("Ran %i tests.\n", tests_run);
172
  v8::V8::Dispose();
191
  if (!disable_automatic_dispose_) v8::V8::Dispose();
173 192
  return 0;
174 193
}
175 194

  

Also available in: Unified diff