1// Copyright 2013 The Flutter 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/scopes/dart_isolate_scope.h"
6
7namespace tonic {
8
9DartIsolateScope::DartIsolateScope(Dart_Isolate isolate) {
10 isolate_ = isolate;
11 previous_ = Dart_CurrentIsolate();
12 if (previous_ == isolate_)
13 return;
14 if (previous_)
15 Dart_ExitIsolate();
16 Dart_EnterIsolate(isolate_);
17}
18
19DartIsolateScope::~DartIsolateScope() {
20 Dart_Isolate current = Dart_CurrentIsolate();
21 TONIC_DCHECK(!current || current == isolate_);
22 if (previous_ == isolate_)
23 return;
24 if (current)
25 Dart_ExitIsolate();
26 if (previous_)
27 Dart_EnterIsolate(previous_);
28}
29
30} // namespace tonic
31