| OLD | NEW |
| (Empty) | |
| 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 "sky/engine/config.h" |
| 6 #include "sky/engine/tonic/dart_persistent_value.h" |
| 7 |
| 8 #include "sky/engine/tonic/dart_isolate_scope.h" |
| 9 #include "sky/engine/tonic/dart_state.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 DartPersistentValue::DartPersistentValue() : value_(nullptr) { |
| 14 } |
| 15 |
| 16 DartPersistentValue::DartPersistentValue(DartState* dart_state, |
| 17 Dart_Handle value) |
| 18 : value_(nullptr) { |
| 19 Set(dart_state, value); |
| 20 } |
| 21 |
| 22 DartPersistentValue::~DartPersistentValue() { |
| 23 Clear(); |
| 24 } |
| 25 |
| 26 void DartPersistentValue::Set(DartState* dart_state, Dart_Handle value) { |
| 27 DCHECK(is_empty()); |
| 28 dart_state_ = dart_state->GetWeakPtr(); |
| 29 value_ = Dart_NewPersistentHandle(value); |
| 30 } |
| 31 |
| 32 void DartPersistentValue::Clear() { |
| 33 if (!value_ || !dart_state_.get()) |
| 34 return; |
| 35 |
| 36 DartIsolateScope scope(dart_state_->isolate()); |
| 37 Dart_DeletePersistentHandle(value_); |
| 38 dart_state_ = base::WeakPtr<DartState>(); |
| 39 value_ = nullptr; |
| 40 } |
| 41 |
| 42 Dart_Handle DartPersistentValue::Release() { |
| 43 if (!value_) |
| 44 return nullptr; |
| 45 Dart_Handle local = Dart_HandleFromPersistent(value_); |
| 46 Clear(); |
| 47 return local; |
| 48 } |
| 49 } |
| OLD | NEW |