[API] Remove deprecated WeakCallbackData and related functions.
This removes: - PersistentBase::SetWeak that takes WeakCallbackData. The embedders should use the version that takes WeakCallbackInfo. - PersistentBase::SetPhantom. The embedders should SetWeak that takes WeakCallbackInfo. Functions in DefaultPersistentValueMapTraits are changed to accept WeakCallbackInfo instead of WeakCallbackData. BUG=chromium:609808 LOG=NO Review-Url: https://codereview.chromium.org/1953263002 Cr-Commit-Position: refs/heads/master@{#36079}
This commit is contained in:
parent
fbe0f303a2
commit
82dcb2beee
@ -95,12 +95,12 @@ class DefaultPersistentValueMapTraits : public StdMapTraits<K, V> {
|
||||
MapType* map, const K& key, Local<V> value) {
|
||||
return NULL;
|
||||
}
|
||||
static MapType* MapFromWeakCallbackData(
|
||||
const WeakCallbackData<V, WeakCallbackDataType>& data) {
|
||||
static MapType* MapFromWeakCallbackInfo(
|
||||
const WeakCallbackInfo<WeakCallbackDataType>& data) {
|
||||
return NULL;
|
||||
}
|
||||
static K KeyFromWeakCallbackData(
|
||||
const WeakCallbackData<V, WeakCallbackDataType>& data) {
|
||||
static K KeyFromWeakCallbackInfo(
|
||||
const WeakCallbackInfo<WeakCallbackDataType>& data) {
|
||||
return K();
|
||||
}
|
||||
static void DisposeCallbackData(WeakCallbackDataType* data) { }
|
||||
@ -413,11 +413,11 @@ class PersistentValueMap : public PersistentValueMapBase<K, V, Traits> {
|
||||
|
||||
private:
|
||||
static void WeakCallback(
|
||||
const WeakCallbackData<V, typename Traits::WeakCallbackDataType>& data) {
|
||||
const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) {
|
||||
if (Traits::kCallbackType != kNotWeak) {
|
||||
PersistentValueMap<K, V, Traits>* persistentValueMap =
|
||||
Traits::MapFromWeakCallbackData(data);
|
||||
K key = Traits::KeyFromWeakCallbackData(data);
|
||||
Traits::MapFromWeakCallbackInfo(data);
|
||||
K key = Traits::KeyFromWeakCallbackInfo(data);
|
||||
Traits::Dispose(data.GetIsolate(),
|
||||
persistentValueMap->Remove(key).Pass(), key);
|
||||
Traits::DisposeCallbackData(data.GetParameter());
|
||||
|
85
include/v8.h
85
include/v8.h
@ -457,29 +457,6 @@ class WeakCallbackInfo {
|
||||
};
|
||||
|
||||
|
||||
template <class T, class P>
|
||||
class WeakCallbackData {
|
||||
public:
|
||||
typedef void (*Callback)(const WeakCallbackData<T, P>& data);
|
||||
|
||||
WeakCallbackData(Isolate* isolate, P* parameter, Local<T> handle)
|
||||
: isolate_(isolate), parameter_(parameter), handle_(handle) {}
|
||||
|
||||
V8_INLINE Isolate* GetIsolate() const { return isolate_; }
|
||||
V8_INLINE P* GetParameter() const { return parameter_; }
|
||||
V8_INLINE Local<T> GetValue() const { return handle_; }
|
||||
|
||||
private:
|
||||
Isolate* isolate_;
|
||||
P* parameter_;
|
||||
Local<T> handle_;
|
||||
};
|
||||
|
||||
|
||||
// TODO(dcarney): delete this with WeakCallbackData
|
||||
template <class T>
|
||||
using PhantomCallbackData = WeakCallbackInfo<T>;
|
||||
|
||||
// kParameter will pass a void* parameter back to the callback, kInternalFields
|
||||
// will pass the first two internal fields back to the callback, kFinalizer
|
||||
// will pass a void* parameter back, but is invoked before the object is
|
||||
@ -564,32 +541,6 @@ template <class T> class PersistentBase {
|
||||
* critical form of resource management!
|
||||
*/
|
||||
template <typename P>
|
||||
V8_INLINE V8_DEPRECATED(
|
||||
"use WeakCallbackInfo version",
|
||||
void SetWeak(P* parameter,
|
||||
typename WeakCallbackData<T, P>::Callback callback));
|
||||
|
||||
template <typename S, typename P>
|
||||
V8_INLINE V8_DEPRECATED(
|
||||
"use WeakCallbackInfo version",
|
||||
void SetWeak(P* parameter,
|
||||
typename WeakCallbackData<S, P>::Callback callback));
|
||||
|
||||
// Phantom persistents work like weak persistents, except that the pointer to
|
||||
// the object being collected is not available in the finalization callback.
|
||||
// This enables the garbage collector to collect the object and any objects
|
||||
// it references transitively in one GC cycle. At the moment you can either
|
||||
// specify a parameter for the callback or the location of two internal
|
||||
// fields in the dying object.
|
||||
template <typename P>
|
||||
V8_INLINE V8_DEPRECATED(
|
||||
"use SetWeak",
|
||||
void SetPhantom(P* parameter,
|
||||
typename WeakCallbackInfo<P>::Callback callback,
|
||||
int internal_field_index1 = -1,
|
||||
int internal_field_index2 = -1));
|
||||
|
||||
template <typename P>
|
||||
V8_INLINE void SetWeak(P* parameter,
|
||||
typename WeakCallbackInfo<P>::Callback callback,
|
||||
WeakCallbackType type);
|
||||
@ -6677,9 +6628,6 @@ class V8_EXPORT V8 {
|
||||
internal::Object** handle);
|
||||
static internal::Object** CopyPersistent(internal::Object** handle);
|
||||
static void DisposeGlobal(internal::Object** global_handle);
|
||||
typedef WeakCallbackData<Value, void>::Callback WeakCallback;
|
||||
static void MakeWeak(internal::Object** global_handle, void* data,
|
||||
WeakCallback weak_callback);
|
||||
static void MakeWeak(internal::Object** global_handle, void* data,
|
||||
WeakCallbackInfo<void>::Callback weak_callback,
|
||||
WeakCallbackType type);
|
||||
@ -7651,39 +7599,6 @@ void PersistentBase<T>::Reset(Isolate* isolate,
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
template <typename S, typename P>
|
||||
void PersistentBase<T>::SetWeak(
|
||||
P* parameter,
|
||||
typename WeakCallbackData<S, P>::Callback callback) {
|
||||
TYPE_CHECK(S, T);
|
||||
typedef typename WeakCallbackData<Value, void>::Callback Callback;
|
||||
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
|
||||
reinterpret_cast<Callback>(callback));
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
template <typename P>
|
||||
void PersistentBase<T>::SetWeak(
|
||||
P* parameter,
|
||||
typename WeakCallbackData<T, P>::Callback callback) {
|
||||
SetWeak<T, P>(parameter, callback);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
template <typename P>
|
||||
void PersistentBase<T>::SetPhantom(
|
||||
P* parameter, typename WeakCallbackInfo<P>::Callback callback,
|
||||
int internal_field_index1, int internal_field_index2) {
|
||||
typedef typename WeakCallbackInfo<void>::Callback Callback;
|
||||
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter,
|
||||
internal_field_index1, internal_field_index2,
|
||||
reinterpret_cast<Callback>(callback));
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
template <typename P>
|
||||
V8_INLINE void PersistentBase<T>::SetWeak(
|
||||
|
@ -683,11 +683,6 @@ void V8::RegisterExternallyReferencedObject(i::Object** object,
|
||||
isolate->heap()->RegisterExternallyReferencedObject(object);
|
||||
}
|
||||
|
||||
void V8::MakeWeak(i::Object** object, void* parameter,
|
||||
WeakCallback weak_callback) {
|
||||
i::GlobalHandles::MakeWeak(object, parameter, weak_callback);
|
||||
}
|
||||
|
||||
|
||||
void V8::MakeWeak(i::Object** object, void* parameter,
|
||||
int internal_field_index1, int internal_field_index2,
|
||||
|
@ -82,7 +82,6 @@ class GlobalHandles::Node {
|
||||
index_ = static_cast<uint8_t>(index);
|
||||
DCHECK(static_cast<int>(index_) == index);
|
||||
set_state(FREE);
|
||||
set_weakness_type(NORMAL_WEAK);
|
||||
set_in_new_space_list(false);
|
||||
parameter_or_next_free_.next_free = *first_free;
|
||||
*first_free = this;
|
||||
@ -197,16 +196,14 @@ class GlobalHandles::Node {
|
||||
|
||||
bool IsRetainer() const {
|
||||
return state() != FREE &&
|
||||
!(state() == NEAR_DEATH && weakness_type() != NORMAL_WEAK &&
|
||||
weakness_type() != FINALIZER_WEAK);
|
||||
!(state() == NEAR_DEATH && weakness_type() != FINALIZER_WEAK);
|
||||
}
|
||||
|
||||
bool IsStrongRetainer() const { return state() == NORMAL; }
|
||||
|
||||
bool IsWeakRetainer() const {
|
||||
return state() == WEAK || state() == PENDING ||
|
||||
(state() == NEAR_DEATH && (weakness_type() == NORMAL_WEAK ||
|
||||
weakness_type() == FINALIZER_WEAK));
|
||||
(state() == NEAR_DEATH && weakness_type() == FINALIZER_WEAK);
|
||||
}
|
||||
|
||||
void MarkPending() {
|
||||
@ -252,16 +249,6 @@ class GlobalHandles::Node {
|
||||
parameter_or_next_free_.next_free = value;
|
||||
}
|
||||
|
||||
void MakeWeak(void* parameter, WeakCallback weak_callback) {
|
||||
DCHECK(weak_callback != nullptr);
|
||||
DCHECK(IsInUse());
|
||||
CHECK_NE(object_, reinterpret_cast<Object*>(kGlobalHandleZapValue));
|
||||
set_state(WEAK);
|
||||
set_weakness_type(NORMAL_WEAK);
|
||||
set_parameter(parameter);
|
||||
weak_callback_ = weak_callback;
|
||||
}
|
||||
|
||||
void MakeWeak(void* parameter,
|
||||
WeakCallbackInfo<void>::Callback phantom_callback,
|
||||
v8::WeakCallbackType type) {
|
||||
@ -281,7 +268,7 @@ class GlobalHandles::Node {
|
||||
break;
|
||||
}
|
||||
set_parameter(parameter);
|
||||
weak_callback_ = reinterpret_cast<WeakCallback>(phantom_callback);
|
||||
weak_callback_ = phantom_callback;
|
||||
}
|
||||
|
||||
void* ClearWeakness() {
|
||||
@ -337,30 +324,18 @@ class GlobalHandles::Node {
|
||||
ExternalOneByteString::cast(object_)->resource() != NULL);
|
||||
DCHECK(!object_->IsExternalTwoByteString() ||
|
||||
ExternalTwoByteString::cast(object_)->resource() != NULL);
|
||||
if (weakness_type() != NORMAL_WEAK && weakness_type() != FINALIZER_WEAK) {
|
||||
if (weakness_type() != FINALIZER_WEAK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Leaving V8.
|
||||
VMState<EXTERNAL> vmstate(isolate);
|
||||
HandleScope handle_scope(isolate);
|
||||
if (weakness_type() == NORMAL_WEAK) {
|
||||
Object** object = location();
|
||||
Handle<Object> handle(*object, isolate);
|
||||
v8::WeakCallbackData<v8::Value, void> data(
|
||||
reinterpret_cast<v8::Isolate*>(isolate), parameter(),
|
||||
v8::Utils::ToLocal(handle));
|
||||
set_parameter(NULL);
|
||||
weak_callback_(data);
|
||||
} else {
|
||||
void* internal_fields[v8::kInternalFieldsInWeakCallback] = {nullptr,
|
||||
nullptr};
|
||||
v8::WeakCallbackInfo<void> data(reinterpret_cast<v8::Isolate*>(isolate),
|
||||
parameter(), internal_fields, nullptr);
|
||||
auto callback = reinterpret_cast<v8::WeakCallbackInfo<void>::Callback>(
|
||||
weak_callback_);
|
||||
callback(data);
|
||||
}
|
||||
void* internal_fields[v8::kInternalFieldsInWeakCallback] = {nullptr,
|
||||
nullptr};
|
||||
v8::WeakCallbackInfo<void> data(reinterpret_cast<v8::Isolate*>(isolate),
|
||||
parameter(), internal_fields, nullptr);
|
||||
weak_callback_(data);
|
||||
|
||||
// Absence of explicit cleanup or revival of weak handle
|
||||
// in most of the cases would lead to memory leak.
|
||||
@ -401,7 +376,7 @@ class GlobalHandles::Node {
|
||||
uint8_t flags_;
|
||||
|
||||
// Handle specific callback - might be a weak reference in disguise.
|
||||
WeakCallback weak_callback_;
|
||||
WeakCallbackInfo<void>::Callback weak_callback_;
|
||||
|
||||
// Provided data for callback. In FREE state, this is used for
|
||||
// the free list link.
|
||||
@ -617,12 +592,6 @@ void GlobalHandles::Destroy(Object** location) {
|
||||
}
|
||||
|
||||
|
||||
void GlobalHandles::MakeWeak(Object** location, void* parameter,
|
||||
WeakCallback weak_callback) {
|
||||
Node::FromLocation(location)->MakeWeak(parameter, weak_callback);
|
||||
}
|
||||
|
||||
|
||||
typedef v8::WeakCallbackInfo<void>::Callback GenericCallback;
|
||||
|
||||
|
||||
@ -668,7 +637,6 @@ void GlobalHandles::IterateWeakRoots(ObjectVisitor* v) {
|
||||
if (node->IsWeakRetainer()) {
|
||||
// Pending weak phantom handles die immediately. Everything else survives.
|
||||
if (node->state() == Node::PENDING &&
|
||||
node->weakness_type() != NORMAL_WEAK &&
|
||||
node->weakness_type() != FINALIZER_WEAK) {
|
||||
node->CollectPhantomCallbackData(isolate(),
|
||||
&pending_phantom_callbacks_);
|
||||
@ -730,7 +698,6 @@ void GlobalHandles::IterateNewSpaceWeakIndependentRoots(ObjectVisitor* v) {
|
||||
node->IsWeakRetainer()) {
|
||||
// Pending weak phantom handles die immediately. Everything else survives.
|
||||
if (node->state() == Node::PENDING &&
|
||||
node->weakness_type() != NORMAL_WEAK &&
|
||||
node->weakness_type() != FINALIZER_WEAK) {
|
||||
node->CollectPhantomCallbackData(isolate(),
|
||||
&pending_phantom_callbacks_);
|
||||
@ -774,7 +741,6 @@ void GlobalHandles::IterateNewSpaceWeakUnmodifiedRoots(ObjectVisitor* v) {
|
||||
node->IsWeakRetainer()) {
|
||||
// Pending weak phantom handles die immediately. Everything else survives.
|
||||
if (node->state() == Node::PENDING &&
|
||||
node->weakness_type() != NORMAL_WEAK &&
|
||||
node->weakness_type() != FINALIZER_WEAK) {
|
||||
node->CollectPhantomCallbackData(isolate(),
|
||||
&pending_phantom_callbacks_);
|
||||
|
@ -97,7 +97,6 @@ struct ObjectGroupRetainerInfo {
|
||||
};
|
||||
|
||||
enum WeaknessType {
|
||||
NORMAL_WEAK, // Embedder gets a handle to the dying object.
|
||||
// In the following cases, the embedder gets the parameter they passed in
|
||||
// earlier, and 0 or 2 first internal fields. Note that the internal
|
||||
// fields must contain aligned non-V8 pointers. Getting pointers to V8
|
||||
@ -105,7 +104,7 @@ enum WeaknessType {
|
||||
// embedder gets a null pointer instead.
|
||||
PHANTOM_WEAK,
|
||||
PHANTOM_WEAK_2_INTERNAL_FIELDS,
|
||||
// Like NORMAL_WEAK, but uses WeakCallbackInfo instead of WeakCallbackData.
|
||||
// Embedder gets a handle to the dying object.
|
||||
FINALIZER_WEAK,
|
||||
};
|
||||
|
||||
@ -122,14 +121,6 @@ class GlobalHandles {
|
||||
// Destroy a global handle.
|
||||
static void Destroy(Object** location);
|
||||
|
||||
typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
|
||||
|
||||
// For a phantom weak reference, the callback does not have access to the
|
||||
// dying object. Phantom weak references are preferred because they allow
|
||||
// memory to be reclaimed in one GC cycle rather than two. However, for
|
||||
// historical reasons the default is non-phantom.
|
||||
enum PhantomState { Nonphantom, Phantom };
|
||||
|
||||
// Make the global handle weak and set the callback parameter for the
|
||||
// handle. When the garbage collector recognizes that only weak global
|
||||
// handles point to an object the callback function is invoked (for each
|
||||
@ -139,11 +130,6 @@ class GlobalHandles {
|
||||
// GC. For a phantom weak handle the handle is cleared (set to a Smi)
|
||||
// before the callback is invoked, but the handle can still be identified
|
||||
// in the callback by using the location() of the handle.
|
||||
static void MakeWeak(Object** location, void* parameter,
|
||||
WeakCallback weak_callback);
|
||||
|
||||
// It would be nice to template this one, but it's really hard to get
|
||||
// the template instantiator to work right if you do.
|
||||
static void MakeWeak(Object** location, void* parameter,
|
||||
WeakCallbackInfo<void>::Callback weak_callback,
|
||||
v8::WeakCallbackType type);
|
||||
|
@ -306,9 +306,8 @@ AllocationTracker::UnresolvedLocation::UnresolvedLocation(
|
||||
info_(info) {
|
||||
script_ = Handle<Script>::cast(
|
||||
script->GetIsolate()->global_handles()->Create(script));
|
||||
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
|
||||
this,
|
||||
&HandleWeakScript);
|
||||
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()), this,
|
||||
&HandleWeakScript, v8::WeakCallbackType::kParameter);
|
||||
}
|
||||
|
||||
|
||||
@ -326,9 +325,8 @@ void AllocationTracker::UnresolvedLocation::Resolve() {
|
||||
info_->column = Script::GetColumnNumber(script_, start_position_);
|
||||
}
|
||||
|
||||
|
||||
void AllocationTracker::UnresolvedLocation::HandleWeakScript(
|
||||
const v8::WeakCallbackData<v8::Value, void>& data) {
|
||||
const v8::WeakCallbackInfo<void>& data) {
|
||||
UnresolvedLocation* loc =
|
||||
reinterpret_cast<UnresolvedLocation*>(data.GetParameter());
|
||||
GlobalHandles::Destroy(reinterpret_cast<Object**>(loc->script_.location()));
|
||||
|
@ -129,8 +129,7 @@ class AllocationTracker {
|
||||
void Resolve();
|
||||
|
||||
private:
|
||||
static void HandleWeakScript(
|
||||
const v8::WeakCallbackData<v8::Value, void>& data);
|
||||
static void HandleWeakScript(const v8::WeakCallbackInfo<void>& data);
|
||||
|
||||
Handle<Script> script_;
|
||||
int start_position_;
|
||||
|
Loading…
Reference in New Issue
Block a user