Commit 76c35f61 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

Use phantom handle in GCObservation

The GCObservation handle is always set and empty state implies that the
observed object was garbage collection. Use phantom reference which
avoids clearing out the reference manually.

Bug: 903586, 843903
Change-Id: I77e6e9d9ef4625d4bb91b3907b0d1b69c17f2208
Reviewed-on: https://chromium-review.googlesource.com/c/1340320Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608771}
parent a2643896
...@@ -32,20 +32,10 @@ ...@@ -32,20 +32,10 @@
namespace blink { namespace blink {
static void SetWeakCallbackForGCObservation(
const v8::WeakCallbackInfo<GCObservation>& data) {
data.GetParameter()->SetWasCollected();
}
void GCObservation::SetWasCollected() {
DCHECK(!wasCollected());
observed_.Clear();
collected_ = true;
}
GCObservation::GCObservation(v8::Local<v8::Value> observed_value) GCObservation::GCObservation(v8::Local<v8::Value> observed_value)
: observed_(v8::Isolate::GetCurrent(), observed_value), collected_(false) { : observed_(v8::Isolate::GetCurrent(), observed_value) {
observed_.SetWeak(this, SetWeakCallbackForGCObservation); CHECK(!wasCollected());
observed_.SetPhantom();
} }
} // namespace blink } // namespace blink
...@@ -50,14 +50,12 @@ class GCObservation final : public ScriptWrappable { ...@@ -50,14 +50,12 @@ class GCObservation final : public ScriptWrappable {
// "near death"; it may have been kept alive through a weak // "near death"; it may have been kept alive through a weak
// handle. After reaching near-death, having been collected is the // handle. After reaching near-death, having been collected is the
// common case. // common case.
bool wasCollected() const { return collected_; } bool wasCollected() const { return observed_.IsEmpty(); }
void SetWasCollected();
private: private:
explicit GCObservation(v8::Local<v8::Value>); explicit GCObservation(v8::Local<v8::Value>);
ScopedPersistent<v8::Value> observed_; ScopedPersistent<v8::Value> observed_;
bool collected_;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment