summaryrefslogtreecommitdiffstats
path: root/gin/test/v8_test.cc
blob: a02251128a2c1bd13f776e1ca7b6a6fe405749eb (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
// Copyright 2013 The Chromium 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 "gin/test/v8_test.h"

#include "gin/array_buffer.h"
#include "gin/public/isolate_holder.h"

#ifdef V8_USE_EXTERNAL_STARTUP_DATA
#include "gin/public/isolate_holder.h"
#endif

using v8::Context;
using v8::Local;
using v8::HandleScope;

namespace gin {

V8Test::V8Test() {
}

V8Test::~V8Test() {
}

void V8Test::SetUp() {
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
  gin::IsolateHolder::LoadV8Snapshot();
#endif
  gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
                                 gin::ArrayBufferAllocator::SharedInstance());
  instance_.reset(new gin::IsolateHolder);
  instance_->isolate()->Enter();
  HandleScope handle_scope(instance_->isolate());
  context_.Reset(instance_->isolate(), Context::New(instance_->isolate()));
  Local<Context>::New(instance_->isolate(), context_)->Enter();
}

void V8Test::TearDown() {
  {
    HandleScope handle_scope(instance_->isolate());
    Local<Context>::New(instance_->isolate(), context_)->Exit();
    context_.Reset();
  }
  instance_->isolate()->Exit();
  instance_.reset();
}

}  // namespace gin