cctest.h 22.7 KB
Newer Older
1
// Copyright 2008 the V8 project authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef CCTEST_H_
#define CCTEST_H_

31 32
#include <memory>

33
#include "include/libplatform/libplatform.h"
34
#include "include/v8-platform.h"
35
#include "src/debug/debug-interface.h"
36
#include "src/flags.h"
37
#include "src/heap/factory.h"
38
#include "src/isolate.h"
39
#include "src/objects.h"
40
#include "src/register-configuration.h"
41
#include "src/utils.h"
42
#include "src/v8.h"
43
#include "src/zone/accounting-allocator.h"
44

45 46 47 48 49 50 51 52 53
namespace v8 {
namespace base {

class RandomNumberGenerator;

}  // namespace base

namespace internal {

54 55
const auto GetRegConfig = RegisterConfiguration::Default;

56 57 58 59 60 61 62
class HandleScope;
class Zone;

}  // namespace internal

}  // namespace v8

63
#ifndef TEST
64 65 66
#define TEST(Name)                                                      \
  static void Test##Name();                                             \
  CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, true); \
67 68 69 70
  static void Test##Name()
#endif

#ifndef UNINITIALIZED_TEST
71 72 73
#define UNINITIALIZED_TEST(Name)                                         \
  static void Test##Name();                                              \
  CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, false); \
74 75 76
  static void Test##Name()
#endif

77
#ifndef DISABLED_TEST
78 79 80
#define DISABLED_TEST(Name)                                              \
  static void Test##Name();                                              \
  CcTest register_test_##Name(Test##Name, __FILE__, #Name, false, true); \
81 82 83
  static void Test##Name()
#endif

84 85 86 87 88
#define EXTENSION_LIST(V)                                                      \
  V(GC_EXTENSION,       "v8/gc")                                               \
  V(PRINT_EXTENSION,    "v8/print")                                            \
  V(PROFILER_EXTENSION, "v8/profiler")                                         \
  V(TRACE_EXTENSION,    "v8/trace")
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

#define DEFINE_EXTENSION_ID(Name, Ident) Name##_ID,
enum CcTestExtensionIds {
  EXTENSION_LIST(DEFINE_EXTENSION_ID)
  kMaxExtensions
};
#undef DEFINE_EXTENSION_ID

typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
#define DEFINE_EXTENSION_FLAG(Name, Ident)                               \
  static const CcTestExtensionFlags Name(1 << Name##_ID);
  static const CcTestExtensionFlags NO_EXTENSIONS(0);
  static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1);
  EXTENSION_LIST(DEFINE_EXTENSION_FLAG)
#undef DEFINE_EXTENSION_FLAG

105

106 107 108
class CcTest {
 public:
  typedef void (TestFunction)();
109
  CcTest(TestFunction* callback, const char* file, const char* name,
110
         bool enabled, bool initialize);
111
  ~CcTest() { i::DeleteArray(file_); }
112
  void Run();
113
  static CcTest* last() { return last_; }
114 115 116
  CcTest* prev() { return prev_; }
  const char* file() { return file_; }
  const char* name() { return name_; }
117
  bool enabled() { return enabled_; }
118

119
  static v8::Isolate* isolate() {
120
    CHECK_NOT_NULL(isolate_);
121
    v8::base::Relaxed_Store(&isolate_used_, 1);
122
    return isolate_;
123
  }
124

125 126 127 128 129
  static i::Isolate* InitIsolateOnce() {
    if (!initialize_called_) InitializeVM();
    return i_isolate();
  }

130
  static i::Isolate* i_isolate() {
131
    return reinterpret_cast<i::Isolate*>(isolate());
132 133
  }

134
  static i::Heap* heap();
135

136
  static void CollectGarbage(i::AllocationSpace space);
137 138 139
  static void CollectAllGarbage(i::Isolate* isolate = nullptr);
  static void CollectAllAvailableGarbage(i::Isolate* isolate = nullptr);
  static void PreciseCollectAllGarbage(i::Isolate* isolate = nullptr);
140

141
  static v8::base::RandomNumberGenerator* random_number_generator();
142

143
  static v8::Local<v8::Object> global();
144

145 146 147 148 149 150 151 152 153
  static v8::ArrayBuffer::Allocator* array_buffer_allocator() {
    return allocator_;
  }

  static void set_array_buffer_allocator(
      v8::ArrayBuffer::Allocator* allocator) {
    allocator_ = allocator;
  }

154 155
  // TODO(dcarney): Remove.
  // This must be called first in a test.
156
  static void InitializeVM();
157

158 159 160
  // Only for UNINITIALIZED_TESTs
  static void DisableAutomaticDispose();

161 162 163 164 165
  // Helper function to configure a context.
  // Must be in a HandleScope.
  static v8::Local<v8::Context> NewContext(
      CcTestExtensionFlags extensions,
      v8::Isolate* isolate = CcTest::isolate());
166

167
  static void TearDown();
168

169
 private:
170
  friend int main(int argc, char** argv);
171 172 173
  TestFunction* callback_;
  const char* file_;
  const char* name_;
174
  bool enabled_;
175
  bool initialize_;
176
  CcTest* prev_;
177
  static CcTest* last_;
178
  static v8::ArrayBuffer::Allocator* allocator_;
179 180
  static v8::Isolate* isolate_;
  static bool initialize_called_;
181
  static v8::base::Atomic32 isolate_used_;
182 183
};

184 185 186 187 188 189 190 191 192 193
// Switches between all the Api tests using the threading support.
// In order to get a surprising but repeatable pattern of thread
// switching it has extra semaphores to control the order in which
// the tests alternate, not relying solely on the big V8 lock.
//
// A test is augmented with calls to ApiTestFuzzer::Fuzz() in its
// callbacks.  This will have no effect when we are not running the
// thread fuzzing test.  In the thread fuzzing test it will
// pseudorandomly select a successor thread and switch execution
// to that thread, suspending the current test.
194
class ApiTestFuzzer: public v8::base::Thread {
195 196 197 198
 public:
  void CallTest();

  // The ApiTestFuzzer is also a Thread, so it has a Run method.
199
  void Run() override;
200

201 202 203 204 205 206 207 208 209 210 211
  enum PartOfTest {
    FIRST_PART,
    SECOND_PART,
    THIRD_PART,
    FOURTH_PART,
    FIFTH_PART,
    SIXTH_PART,
    SEVENTH_PART,
    EIGHTH_PART,
    LAST_PART = EIGHTH_PART
  };
212

213
  static void SetUp(PartOfTest part);
214 215 216 217 218
  static void RunAllTests();
  static void TearDown();
  // This method switches threads if we are running the Threading test.
  // Otherwise it does nothing.
  static void Fuzz();
219

220
 private:
221
  explicit ApiTestFuzzer(int num)
222
      : Thread(Options("ApiTestFuzzer")),
223
        test_number_(num),
224
        gate_(0),
225
        active_(true) {}
226
  ~ApiTestFuzzer() override = default;
227

228 229 230 231 232 233
  static bool fuzzing_;
  static int tests_being_run_;
  static int current_;
  static int active_tests_;
  static bool NextThread();
  int test_number_;
234
  v8::base::Semaphore gate_;
235 236 237
  bool active_;
  void ContextSwitch();
  static int GetNextTestNumber();
238
  static v8::base::Semaphore all_tests_done_;
239 240 241 242 243 244 245 246 247 248 249 250
};


#define THREADED_TEST(Name)                                          \
  static void Test##Name();                                          \
  RegisterThreadedTest register_##Name(Test##Name, #Name);           \
  /* */ TEST(Name)

class RegisterThreadedTest {
 public:
  explicit RegisterThreadedTest(CcTest::TestFunction* callback,
                                const char* name)
251
      : fuzzer_(nullptr), callback_(callback), name_(name) {
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    prev_ = first_;
    first_ = this;
    count_++;
  }
  static int count() { return count_; }
  static RegisterThreadedTest* nth(int i) {
    CHECK(i < count());
    RegisterThreadedTest* current = first_;
    while (i > 0) {
      i--;
      current = current->prev_;
    }
    return current;
  }
  CcTest::TestFunction* callback() { return callback_; }
  ApiTestFuzzer* fuzzer_;
  const char* name() { return name_; }

 private:
  static RegisterThreadedTest* first_;
  static int count_;
  CcTest::TestFunction* callback_;
  RegisterThreadedTest* prev_;
  const char* name_;
};

// A LocalContext holds a reference to a v8::Context.
class LocalContext {
 public:
281 282
  LocalContext(v8::Isolate* isolate,
               v8::ExtensionConfiguration* extensions = nullptr,
283 284 285
               v8::Local<v8::ObjectTemplate> global_template =
                   v8::Local<v8::ObjectTemplate>(),
               v8::Local<v8::Value> global_object = v8::Local<v8::Value>()) {
286 287 288
    Initialize(isolate, extensions, global_template, global_object);
  }

289
  LocalContext(v8::ExtensionConfiguration* extensions = nullptr,
290 291 292
               v8::Local<v8::ObjectTemplate> global_template =
                   v8::Local<v8::ObjectTemplate>(),
               v8::Local<v8::Value> global_object = v8::Local<v8::Value>()) {
293
    Initialize(CcTest::isolate(), extensions, global_template, global_object);
294 295
  }

296
  virtual ~LocalContext();
297

298 299 300 301
  v8::Context* operator->() {
    return *reinterpret_cast<v8::Context**>(&context_);
  }
  v8::Context* operator*() { return operator->(); }
302 303 304
  bool IsReady() { return !context_.IsEmpty(); }

  v8::Local<v8::Context> local() {
305
    return v8::Local<v8::Context>::New(isolate_, context_);
306 307 308
  }

 private:
309 310
  void Initialize(v8::Isolate* isolate, v8::ExtensionConfiguration* extensions,
                  v8::Local<v8::ObjectTemplate> global_template,
311
                  v8::Local<v8::Value> global_object);
312

313
  v8::Persistent<v8::Context> context_;
314
  v8::Isolate* isolate_;
315 316
};

317 318 319 320 321 322 323 324

static inline uint16_t* AsciiToTwoByteString(const char* source) {
  int array_length = i::StrLength(source) + 1;
  uint16_t* converted = i::NewArray<uint16_t>(array_length);
  for (int i = 0; i < array_length; i++) converted[i] = source[i];
  return converted;
}

325 326 327 328 329 330 331
template <typename T>
static inline i::Handle<T> GetGlobal(const char* name) {
  i::Isolate* isolate = CcTest::i_isolate();
  i::Handle<i::String> str_name =
      isolate->factory()->InternalizeUtf8String(name);

  i::Handle<i::Object> value =
332
      i::Object::GetProperty(isolate, isolate->global_object(), str_name)
333 334 335
          .ToHandleChecked();
  return i::Handle<T>::cast(value);
}
336

337
static inline v8::Local<v8::Value> v8_num(double x) {
338
  return v8::Number::New(v8::Isolate::GetCurrent(), x);
339 340
}

341 342 343
static inline v8::Local<v8::Integer> v8_int(int32_t x) {
  return v8::Integer::New(v8::Isolate::GetCurrent(), x);
}
344 345

static inline v8::Local<v8::String> v8_str(const char* x) {
346 347 348
  return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x,
                                 v8::NewStringType::kNormal)
      .ToLocalChecked();
349 350 351
}


352 353 354 355 356 357 358
static inline v8::Local<v8::String> v8_str(v8::Isolate* isolate,
                                           const char* x) {
  return v8::String::NewFromUtf8(isolate, x, v8::NewStringType::kNormal)
      .ToLocalChecked();
}


359 360 361 362 363
static inline v8::Local<v8::Symbol> v8_symbol(const char* name) {
  return v8::Symbol::New(v8::Isolate::GetCurrent(), v8_str(name));
}


364 365 366 367 368 369 370
static inline v8::Local<v8::Script> v8_compile(v8::Local<v8::String> x) {
  v8::Local<v8::Script> result;
  if (v8::Script::Compile(v8::Isolate::GetCurrent()->GetCurrentContext(), x)
          .ToLocal(&result)) {
    return result;
  }
  return v8::Local<v8::Script>();
371 372 373
}


374 375
static inline v8::Local<v8::Script> v8_compile(const char* x) {
  return v8_compile(v8_str(x));
376 377 378
}


379 380 381 382 383 384
static inline int32_t v8_run_int32value(v8::Local<v8::Script> script) {
  v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
  return script->Run(context).ToLocalChecked()->Int32Value(context).FromJust();
}


385 386 387
static inline v8::Local<v8::Script> CompileWithOrigin(
    v8::Local<v8::String> source, v8::Local<v8::String> origin_url) {
  v8::ScriptOrigin origin(origin_url);
388
  v8::ScriptCompiler::Source script_source(source, origin);
389
  return v8::ScriptCompiler::Compile(
390 391
             v8::Isolate::GetCurrent()->GetCurrentContext(), &script_source)
      .ToLocalChecked();
392 393 394 395 396
}


static inline v8::Local<v8::Script> CompileWithOrigin(
    v8::Local<v8::String> source, const char* origin_url) {
397 398 399 400 401 402 403
  return CompileWithOrigin(source, v8_str(origin_url));
}


static inline v8::Local<v8::Script> CompileWithOrigin(const char* source,
                                                      const char* origin_url) {
  return CompileWithOrigin(v8_str(source), v8_str(origin_url));
404 405 406 407
}


// Helper functions that compile and run the source.
408 409 410 411 412 413 414 415
static inline v8::MaybeLocal<v8::Value> CompileRun(
    v8::Local<v8::Context> context, const char* source) {
  return v8::Script::Compile(context, v8_str(source))
      .ToLocalChecked()
      ->Run(context);
}


416 417 418 419 420 421 422 423 424 425 426 427
static inline v8::Local<v8::Value> CompileRunChecked(v8::Isolate* isolate,
                                                     const char* source) {
  v8::Local<v8::String> source_string =
      v8::String::NewFromUtf8(isolate, source, v8::NewStringType::kNormal)
          .ToLocalChecked();
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
  v8::Local<v8::Script> script =
      v8::Script::Compile(context, source_string).ToLocalChecked();
  return script->Run(context).ToLocalChecked();
}


428 429 430 431 432 433 434 435
static inline v8::Local<v8::Value> CompileRun(v8::Local<v8::String> source) {
  v8::Local<v8::Value> result;
  if (v8_compile(source)
          ->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
          .ToLocal(&result)) {
    return result;
  }
  return v8::Local<v8::Value>();
436 437 438
}


439
// Helper functions that compile and run the source.
440 441
static inline v8::Local<v8::Value> CompileRun(const char* source) {
  return CompileRun(v8_str(source));
442 443 444
}


445 446 447 448 449 450 451 452 453 454 455
static inline v8::Local<v8::Value> CompileRun(
    v8::Local<v8::Context> context, v8::ScriptCompiler::Source* script_source,
    v8::ScriptCompiler::CompileOptions options) {
  v8::Local<v8::Value> result;
  if (v8::ScriptCompiler::Compile(context, script_source, options)
          .ToLocalChecked()
          ->Run(context)
          .ToLocal(&result)) {
    return result;
  }
  return v8::Local<v8::Value>();
456 457
}

458

459
// Helper functions that compile and run the source with given origin.
460 461 462 463
static inline v8::Local<v8::Value> CompileRunWithOrigin(const char* source,
                                                        const char* origin_url,
                                                        int line_number,
                                                        int column_number) {
464
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
465
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
466
  v8::ScriptOrigin origin(v8_str(origin_url),
467 468
                          v8::Integer::New(isolate, line_number),
                          v8::Integer::New(isolate, column_number));
469
  v8::ScriptCompiler::Source script_source(v8_str(source), origin);
470 471
  return CompileRun(context, &script_source,
                    v8::ScriptCompiler::CompileOptions());
472 473 474 475
}


static inline v8::Local<v8::Value> CompileRunWithOrigin(
476
    v8::Local<v8::String> source, const char* origin_url) {
477 478
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  v8::Local<v8::Context> context = isolate->GetCurrentContext();
479 480
  v8::ScriptCompiler::Source script_source(
      source, v8::ScriptOrigin(v8_str(origin_url)));
481 482
  return CompileRun(context, &script_source,
                    v8::ScriptCompiler::CompileOptions());
483 484 485 486 487 488
}


static inline v8::Local<v8::Value> CompileRunWithOrigin(
    const char* source, const char* origin_url) {
  return CompileRunWithOrigin(v8_str(source), origin_url);
489 490
}

491

492 493 494 495

static inline void ExpectString(const char* code, const char* expected) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->IsString());
496
  v8::String::Utf8Value utf8(v8::Isolate::GetCurrent(), result);
497
  CHECK_EQ(0, strcmp(expected, *utf8));
498 499 500 501 502 503
}


static inline void ExpectInt32(const char* code, int expected) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->IsInt32());
504 505 506
  CHECK_EQ(expected,
           result->Int32Value(v8::Isolate::GetCurrent()->GetCurrentContext())
               .FromJust());
507 508 509 510 511 512
}


static inline void ExpectBoolean(const char* code, bool expected) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->IsBoolean());
513
  CHECK_EQ(expected, result->BooleanValue(v8::Isolate::GetCurrent()));
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
}


static inline void ExpectTrue(const char* code) {
  ExpectBoolean(code, true);
}


static inline void ExpectFalse(const char* code) {
  ExpectBoolean(code, false);
}


static inline void ExpectObject(const char* code,
                                v8::Local<v8::Value> expected) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->SameValue(expected));
}


static inline void ExpectUndefined(const char* code) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->IsUndefined());
}


540 541 542 543 544 545
static inline void ExpectNull(const char* code) {
  v8::Local<v8::Value> result = CompileRun(code);
  CHECK(result->IsNull());
}


546 547 548 549 550 551
static inline void CheckDoubleEquals(double expected, double actual) {
  const double kEpsilon = 1e-10;
  CHECK_LE(expected, actual + kEpsilon);
  CHECK_GE(expected, actual - kEpsilon);
}

552
static v8::debug::DebugDelegate dummy_delegate;
553

554
static inline void EnableDebugger(v8::Isolate* isolate) {
555
  v8::debug::SetDebugDelegate(isolate, &dummy_delegate);
556 557 558
}


559
static inline void DisableDebugger(v8::Isolate* isolate) {
560
  v8::debug::SetDebugDelegate(isolate, nullptr);
561
}
562 563


564 565
static inline void EmptyMessageQueues(v8::Isolate* isolate) {
  while (v8::platform::PumpMessageLoop(v8::internal::V8::GetCurrentPlatform(),
566 567
                                       isolate)) {
  }
568 569
}

570
class InitializedHandleScopeImpl;
571

572 573
class InitializedHandleScope {
 public:
574 575
  InitializedHandleScope();
  ~InitializedHandleScope();
576 577 578 579 580 581

  // Prefixing the below with main_ reduces a lot of naming clashes.
  i::Isolate* main_isolate() { return main_isolate_; }

 private:
  i::Isolate* main_isolate_;
582
  std::unique_ptr<InitializedHandleScopeImpl> initialized_handle_scope_impl_;
583 584 585 586
};

class HandleAndZoneScope : public InitializedHandleScope {
 public:
587 588
  HandleAndZoneScope();
  ~HandleAndZoneScope();
589 590

  // Prefixing the below with main_ reduces a lot of naming clashes.
591
  i::Zone* main_zone() { return main_zone_.get(); }
592 593

 private:
594
  v8::internal::AccountingAllocator allocator_;
595
  std::unique_ptr<i::Zone> main_zone_;
596 597
};

598 599 600 601
class StaticOneByteResource : public v8::String::ExternalOneByteStringResource {
 public:
  explicit StaticOneByteResource(const char* data) : data_(data) {}

602
  ~StaticOneByteResource() override = default;
603

604
  const char* data() const override { return data_; }
605

606
  size_t length() const override { return strlen(data_); }
607 608 609 610 611

 private:
  const char* data_;
};

612 613 614 615 616
class ManualGCScope {
 public:
  ManualGCScope()
      : flag_concurrent_marking_(i::FLAG_concurrent_marking),
        flag_concurrent_sweeping_(i::FLAG_concurrent_sweeping),
617
        flag_stress_incremental_marking_(i::FLAG_stress_incremental_marking),
618 619 620
        flag_parallel_marking_(i::FLAG_parallel_marking),
        flag_detect_ineffective_gcs_near_heap_limit_(
            i::FLAG_detect_ineffective_gcs_near_heap_limit) {
621 622 623
    i::FLAG_concurrent_marking = false;
    i::FLAG_concurrent_sweeping = false;
    i::FLAG_stress_incremental_marking = false;
624 625
    // Parallel marking has a dependency on concurrent marking.
    i::FLAG_parallel_marking = false;
626
    i::FLAG_detect_ineffective_gcs_near_heap_limit = false;
627 628 629 630 631
  }
  ~ManualGCScope() {
    i::FLAG_concurrent_marking = flag_concurrent_marking_;
    i::FLAG_concurrent_sweeping = flag_concurrent_sweeping_;
    i::FLAG_stress_incremental_marking = flag_stress_incremental_marking_;
632
    i::FLAG_parallel_marking = flag_parallel_marking_;
633 634
    i::FLAG_detect_ineffective_gcs_near_heap_limit =
        flag_detect_ineffective_gcs_near_heap_limit_;
635 636 637 638 639 640
  }

 private:
  bool flag_concurrent_marking_;
  bool flag_concurrent_sweeping_;
  bool flag_stress_incremental_marking_;
641
  bool flag_parallel_marking_;
642
  bool flag_detect_ineffective_gcs_near_heap_limit_;
643 644
};

645 646 647 648 649 650
// This is an abstract base class that can be overridden to implement a test
// platform. It delegates all operations to a given platform at the time
// of construction.
class TestPlatform : public v8::Platform {
 public:
  // v8::Platform implementation.
651 652 653 654
  v8::PageAllocator* GetPageAllocator() override {
    return old_platform_->GetPageAllocator();
  }

655 656 657 658
  void OnCriticalMemoryPressure() override {
    old_platform_->OnCriticalMemoryPressure();
  }

659 660 661 662
  bool OnCriticalMemoryPressure(size_t length) override {
    return old_platform_->OnCriticalMemoryPressure(length);
  }

663 664 665 666
  int NumberOfWorkerThreads() override {
    return old_platform_->NumberOfWorkerThreads();
  }

667 668 669 670 671
  std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
      v8::Isolate* isolate) override {
    return old_platform_->GetForegroundTaskRunner(isolate);
  }

672 673
  void CallOnWorkerThread(std::unique_ptr<v8::Task> task) override {
    old_platform_->CallOnWorkerThread(std::move(task));
674 675
  }

676 677 678 679 680
  void CallDelayedOnWorkerThread(std::unique_ptr<v8::Task> task,
                                 double delay_in_seconds) override {
    old_platform_->CallDelayedOnWorkerThread(std::move(task), delay_in_seconds);
  }

681
  void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override {
682 683
    // This is a deprecated function and should not be called anymore.
    UNREACHABLE();
684 685 686 687
  }

  void CallDelayedOnForegroundThread(v8::Isolate* isolate, v8::Task* task,
                                     double delay_in_seconds) override {
688 689
    // This is a deprecated function and should not be called anymore.
    UNREACHABLE();
690 691 692 693 694 695
  }

  double MonotonicallyIncreasingTime() override {
    return old_platform_->MonotonicallyIncreasingTime();
  }

696 697 698 699
  double CurrentClockTimeMillis() override {
    return old_platform_->CurrentClockTimeMillis();
  }

700 701
  void CallIdleOnForegroundThread(v8::Isolate* isolate,
                                  v8::IdleTask* task) override {
702 703
    // This is a deprecated function and should not be called anymore.
    UNREACHABLE();
704 705 706 707 708 709 710 711 712 713 714 715
  }

  bool IdleTasksEnabled(v8::Isolate* isolate) override {
    return old_platform_->IdleTasksEnabled(isolate);
  }

  v8::TracingController* GetTracingController() override {
    return old_platform_->GetTracingController();
  }

 protected:
  TestPlatform() : old_platform_(i::V8::GetCurrentPlatform()) {}
716
  ~TestPlatform() override { i::V8::SetPlatformForTesting(old_platform_); }
717 718 719 720 721 722 723 724 725

  v8::Platform* old_platform() const { return old_platform_; }

 private:
  v8::Platform* old_platform_;

  DISALLOW_COPY_AND_ASSIGN(TestPlatform);
};

726
#endif  // ifndef CCTEST_H_