summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/test-utils.cc
blob: 5d1c1f14f650c44210a7e0c123bab7bd4fecdd11 (plain)
1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "test/unittests/test-utils.h"

#include "src/base/platform/time.h"
#include "src/flags.h"
#include "src/isolate-inl.h"

namespace v8 {

std::ostream& operator<<(std::ostream& os, ExternalArrayType type) {
  switch (type) {
    case kExternalInt8Array:
      return os << "ExternalInt8Array";
    case kExternalUint8Array:
      return os << "ExternalUint8Array";
    case kExternalInt16Array:
      return os << "ExternalInt16Array";
    case kExternalUint16Array:
      return os << "ExternalUint16Array";
    case kExternalInt32Array:
      return os << "ExternalInt32Array";
    case kExternalUint32Array:
      return os << "ExternalUint32Array";
    case kExternalFloat32Array:
      return os << "ExternalFloat32Array";
    case kExternalFloat64Array:
      return os << "ExternalFloat64Array";
    case kExternalUint8ClampedArray:
      return os << "ExternalUint8ClampedArray";
  }
  UNREACHABLE();
  return os;
}


// static
Isolate* TestWithIsolate::isolate_ = NULL;


TestWithIsolate::TestWithIsolate()
    : isolate_scope_(isolate()), handle_scope_(isolate()) {}


TestWithIsolate::~TestWithIsolate() {}


// static
void TestWithIsolate::SetUpTestCase() {
  Test::SetUpTestCase();
  EXPECT_EQ(NULL, isolate_);
  isolate_ = v8::Isolate::New();
  EXPECT_TRUE(isolate_ != NULL);
}


// static
void TestWithIsolate::TearDownTestCase() {
  ASSERT_TRUE(isolate_ != NULL);
  isolate_->Dispose();
  isolate_ = NULL;
  Test::TearDownTestCase();
}


TestWithContext::TestWithContext()
    : context_(Context::New(isolate())), context_scope_(context_) {}


TestWithContext::~TestWithContext() {}


namespace base {
namespace {

inline int64_t GetRandomSeedFromFlag(int random_seed) {
  return random_seed ? random_seed : TimeTicks::Now().ToInternalValue();
}

}  // namespace

TestWithRandomNumberGenerator::TestWithRandomNumberGenerator()
    : rng_(GetRandomSeedFromFlag(internal::FLAG_random_seed)) {}


TestWithRandomNumberGenerator::~TestWithRandomNumberGenerator() {}

}  // namespace base


namespace internal {

TestWithIsolate::~TestWithIsolate() {}

TestWithIsolateAndZone::~TestWithIsolateAndZone() {}

Factory* TestWithIsolate::factory() const { return isolate()->factory(); }


base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const {
  return isolate()->random_number_generator();
}


TestWithZone::~TestWithZone() {}

}  // namespace internal
}  // namespace v8