Remove now-rebaselined tests from skia_test_expectations.txt.
[chromium-blink-merge.git] / gin / isolate_holder.cc
blob3cc3238b585423bc869a3a8a2d636386950c8f89
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gin/public/isolate_holder.h"
7 #include <stdlib.h>
8 #include <string.h>
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/sys_info.h"
13 #include "gin/debug_impl.h"
14 #include "gin/function_template.h"
15 #include "gin/per_isolate_data.h"
16 #include "gin/run_microtasks_observer.h"
17 #include "gin/v8_initializer.h"
19 namespace gin {
21 namespace {
22 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
23 } // namespace
25 IsolateHolder::IsolateHolder() {
26 v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
27 CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
28 v8::Isolate::CreateParams params;
29 params.entry_hook = DebugImpl::GetFunctionEntryHook();
30 params.code_event_handler = DebugImpl::GetJitCodeEventHandler();
31 params.constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
32 base::SysInfo::AmountOfVirtualMemory(),
33 base::SysInfo::NumberOfProcessors());
34 isolate_ = v8::Isolate::New(params);
35 isolate_data_.reset(new PerIsolateData(isolate_, allocator));
36 #if defined(OS_WIN)
38 void* code_range;
39 size_t size;
40 isolate_->GetCodeRange(&code_range, &size);
41 Debug::CodeRangeCreatedCallback callback =
42 DebugImpl::GetCodeRangeCreatedCallback();
43 if (code_range && size && callback)
44 callback(code_range, size);
46 #endif
49 IsolateHolder::~IsolateHolder() {
50 if (task_observer_.get())
51 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
52 #if defined(OS_WIN)
54 void* code_range;
55 size_t size;
56 isolate_->GetCodeRange(&code_range, &size);
57 Debug::CodeRangeDeletedCallback callback =
58 DebugImpl::GetCodeRangeDeletedCallback();
59 if (code_range && callback)
60 callback(code_range);
62 #endif
63 isolate_data_.reset();
64 isolate_->Dispose();
65 isolate_ = NULL;
68 // static
69 void IsolateHolder::Initialize(ScriptMode mode,
70 v8::ArrayBuffer::Allocator* allocator) {
71 CHECK(allocator);
72 gin::V8Initializer::Initialize(mode, allocator);
73 g_array_buffer_allocator = allocator;
76 void IsolateHolder::AddRunMicrotasksObserver() {
77 DCHECK(!task_observer_.get());
78 task_observer_.reset(new RunMicrotasksObserver(isolate_));;
79 base::MessageLoop::current()->AddTaskObserver(task_observer_.get());
82 void IsolateHolder::RemoveRunMicrotasksObserver() {
83 DCHECK(task_observer_.get());
84 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
85 task_observer_.reset();
88 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
90 // static
91 bool IsolateHolder::LoadV8Snapshot() {
92 return V8Initializer::LoadV8Snapshot();
95 #endif // V8_USE_EXTERNAL_STARTUP_DATA
97 } // namespace gin