John McCutchan | 080c33e | 2015-07-16 12:35:35 -0700 | [diff] [blame] | 1 | // 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 McCutchan | 080c33e | 2015-07-16 12:35:35 -0700 | [diff] [blame] | 11 | #include "tonic/dart_timer_heap.h" |
| 12 | |
John McCutchan | deace8f | 2015-07-21 08:01:40 -0700 | [diff] [blame] | 13 | namespace tonic { |
John McCutchan | 080c33e | 2015-07-16 12:35:35 -0700 | [diff] [blame] | 14 | |
| 15 | DartState::Scope::Scope(DartState* dart_state) : scope_(dart_state->isolate()) { |
| 16 | } |
| 17 | |
| 18 | DartState::Scope::~Scope() { |
| 19 | } |
| 20 | |
| 21 | DartState::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 McCutchan | 080c33e | 2015-07-16 12:35:35 -0700 | [diff] [blame] | 28 | timer_heap_(std::unique_ptr<DartTimerHeap>( |
| 29 | new DartTimerHeap())), |
| 30 | weak_factory_(this) { |
| 31 | } |
| 32 | |
| 33 | DartState::~DartState() { |
| 34 | } |
| 35 | |
| 36 | void DartState::SetIsolate(Dart_Isolate isolate) { |
| 37 | isolate_ = isolate; |
| 38 | if (!isolate_) |
| 39 | return; |
| 40 | |
John McCutchan | 080c33e | 2015-07-16 12:35:35 -0700 | [diff] [blame] | 41 | DidSetIsolate(); |
| 42 | } |
| 43 | |
| 44 | DartState* DartState::From(Dart_Isolate isolate) { |
| 45 | return static_cast<DartState*>(Dart_IsolateData(isolate)); |
| 46 | } |
| 47 | |
| 48 | DartState* DartState::Current() { |
| 49 | return static_cast<DartState*>(Dart_CurrentIsolateData()); |
| 50 | } |
| 51 | |
| 52 | base::WeakPtr<DartState> DartState::GetWeakPtr() { |
| 53 | return weak_factory_.GetWeakPtr(); |
| 54 | } |
| 55 | |
John McCutchan | deace8f | 2015-07-21 08:01:40 -0700 | [diff] [blame] | 56 | } // namespace tonic |