-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
v8_test_fixture.h
63 lines (50 loc) · 1.71 KB
/
v8_test_fixture.h
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
#ifndef TEST_V8_TEST_FIXTURE_H_
#define TEST_V8_TEST_FIXTURE_H_
#include <stdlib.h>
#include "gtest/gtest.h"
#include "v8.h"
#include "libplatform/libplatform.h"
#include "src/execution/isolate-inl.h"
extern void _v8_internal_Print_Object(void* object);
namespace i = v8::internal;
class V8TestFixture : public ::testing::Test {
public:
template<typename T>
static void print_local(v8::Local<T> obj) {
_v8_internal_Print_Object(*((v8::internal::Object**)*obj));
}
template<typename T>
static void print_handle(i::Handle<T> h) {
_v8_internal_Print_Object(*((v8::internal::Object**)h.location()));
}
protected:
static std::unique_ptr<v8::Platform> platform_;
static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_;
static v8::Isolate::CreateParams create_params_;
v8::Isolate* isolate_;
static void SetUpTestCase() {
v8::V8::InitializeExternalStartupData("fixture");
platform_ = v8::platform::NewDefaultPlatform();
allocator_.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
create_params_.array_buffer_allocator = allocator_.get();
v8::V8::InitializePlatform(platform_.get());
v8::V8::Initialize();
}
static void TearDownTestCase() {
v8::V8::ShutdownPlatform();
}
virtual void SetUp() {
isolate_ = v8::Isolate::New(create_params_);
}
virtual void TearDown() {
isolate_->Dispose();
}
v8::internal::Isolate* asInternal(v8::Isolate* isolate) {
return reinterpret_cast<v8::internal::Isolate*>(isolate);
}
private:
};
std::unique_ptr<v8::Platform> V8TestFixture::platform_;
v8::Isolate::CreateParams V8TestFixture::create_params_;
std::unique_ptr<v8::ArrayBuffer::Allocator> V8TestFixture::allocator_;
#endif // TEST_V8_TEST_FIXTURE_H_