flutter_flutter/engine/tonic/dart_persistent_value.cc
Adam Barth d8d7db82a0 Really remove config.h
This CL generated by |sed -i '/sky\/engine\/config.h/d'| and a manual sweep to
catch some oddballs.

TBR=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1206763002.
2015-06-23 23:15:28 -07:00

49 lines
1.2 KiB
C++

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/tonic/dart_persistent_value.h"
#include "sky/engine/tonic/dart_isolate_scope.h"
#include "sky/engine/tonic/dart_state.h"
namespace blink {
DartPersistentValue::DartPersistentValue() : value_(nullptr) {
}
DartPersistentValue::DartPersistentValue(DartState* dart_state,
Dart_Handle value)
: value_(nullptr) {
Set(dart_state, value);
}
DartPersistentValue::~DartPersistentValue() {
Clear();
}
void DartPersistentValue::Set(DartState* dart_state, Dart_Handle value) {
DCHECK(is_empty());
dart_state_ = dart_state->GetWeakPtr();
value_ = Dart_NewPersistentHandle(value);
}
void DartPersistentValue::Clear() {
if (!value_ || !dart_state_.get())
return;
DartIsolateScope scope(dart_state_->isolate());
Dart_DeletePersistentHandle(value_);
dart_state_ = base::WeakPtr<DartState>();
value_ = nullptr;
}
Dart_Handle DartPersistentValue::Release() {
if (!value_)
return nullptr;
Dart_Handle local = Dart_HandleFromPersistent(value_);
Clear();
return local;
}
}