blob: 2a3b3006dd3d56b667177f2f7b4ec6f0ade51a0b [file] [log] [blame]
John McCutchan080c33e2015-07-16 12:35:35 -07001// Copyright 2015 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.
4
5#include "tonic/dart_state.h"
6
7#include "tonic/dart_class_library.h"
8#include "tonic/dart_converter.h"
9#include "tonic/dart_exception_factory.h"
10#include "tonic/dart_library_loader.h"
John McCutchan080c33e2015-07-16 12:35:35 -070011#include "tonic/dart_timer_heap.h"
12
John McCutchandeace8f2015-07-21 08:01:40 -070013namespace tonic {
John McCutchan080c33e2015-07-16 12:35:35 -070014
15DartState::Scope::Scope(DartState* dart_state) : scope_(dart_state->isolate()) {
16}
17
18DartState::Scope::~Scope() {
19}
20
21DartState::DartState()
22 : isolate_(NULL),
23 class_library_(std::unique_ptr<DartClassLibrary>(new DartClassLibrary)),
24 exception_factory_(std::unique_ptr<DartExceptionFactory>(
25 new DartExceptionFactory(this))),
26 library_loader_(std::unique_ptr<DartLibraryLoader>(
27 new DartLibraryLoader(this))),
John McCutchan080c33e2015-07-16 12:35:35 -070028 timer_heap_(std::unique_ptr<DartTimerHeap>(
29 new DartTimerHeap())),
30 weak_factory_(this) {
31}
32
33DartState::~DartState() {
34}
35
36void DartState::SetIsolate(Dart_Isolate isolate) {
37 isolate_ = isolate;
38 if (!isolate_)
39 return;
40
John McCutchan080c33e2015-07-16 12:35:35 -070041 DidSetIsolate();
42}
43
44DartState* DartState::From(Dart_Isolate isolate) {
45 return static_cast<DartState*>(Dart_IsolateData(isolate));
46}
47
48DartState* DartState::Current() {
49 return static_cast<DartState*>(Dart_CurrentIsolateData());
50}
51
52base::WeakPtr<DartState> DartState::GetWeakPtr() {
53 return weak_factory_.GetWeakPtr();
54}
55
John McCutchandeace8f2015-07-21 08:01:40 -070056} // namespace tonic