Commit 29c89bf2 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

Converting DomTimer from EagerSweeping to PreFinalizer

Replaced DomTimer destructor with a prefinalizer that calls Stop().
Added flag is_stopped_ to make sure second call to Stop() (from
TimerBase dtor) is noop.

Bug: 981043
Change-Id: Iab1473fe2d96fd9d6bfaf0ff2d7e46099796670f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1688928
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675710}
parent 331b7ed1
...@@ -95,12 +95,16 @@ DOMTimer::DOMTimer(ExecutionContext* context, ...@@ -95,12 +95,16 @@ DOMTimer::DOMTimer(ExecutionContext* context,
context, single_shot ? "setTimeout" : "setInterval", this); context, single_shot ? "setTimeout" : "setInterval", this);
} }
DOMTimer::~DOMTimer() { DOMTimer::~DOMTimer() = default;
if (action_)
action_->Dispose(); void DOMTimer::Dispose() {
Stop();
} }
void DOMTimer::Stop() { void DOMTimer::Stop() {
if (!action_)
return;
const bool is_interval = !RepeatInterval().is_zero(); const bool is_interval = !RepeatInterval().is_zero();
probe::AsyncTaskCanceledBreakable( probe::AsyncTaskCanceledBreakable(
GetExecutionContext(), is_interval ? "clearInterval" : "clearTimeout", GetExecutionContext(), is_interval ? "clearInterval" : "clearTimeout",
......
...@@ -45,6 +45,7 @@ class CORE_EXPORT DOMTimer final : public GarbageCollectedFinalized<DOMTimer>, ...@@ -45,6 +45,7 @@ class CORE_EXPORT DOMTimer final : public GarbageCollectedFinalized<DOMTimer>,
public TimerBase, public TimerBase,
public NameClient { public NameClient {
USING_GARBAGE_COLLECTED_MIXIN(DOMTimer); USING_GARBAGE_COLLECTED_MIXIN(DOMTimer);
USING_PRE_FINALIZER(DOMTimer, Dispose);
public: public:
// Creates a new timer owned by the ExecutionContext, starts it and returns // Creates a new timer owned by the ExecutionContext, starts it and returns
...@@ -65,11 +66,12 @@ class CORE_EXPORT DOMTimer final : public GarbageCollectedFinalized<DOMTimer>, ...@@ -65,11 +66,12 @@ class CORE_EXPORT DOMTimer final : public GarbageCollectedFinalized<DOMTimer>,
// ContextLifecycleObserver // ContextLifecycleObserver
void ContextDestroyed(ExecutionContext*) override; void ContextDestroyed(ExecutionContext*) override;
// Eager finalization is needed to promptly stop this Timer object. // Pre finalizer is needed to promptly stop this Timer object.
// Otherwise timer events might fire at an object that's slated for // Otherwise timer events might fire at an object that's slated for
// destruction (when lazily swept), but some of its members (m_action) may // destruction (when lazily swept), but some of its members (m_action) may
// already have been finalized & must not be accessed. // already have been finalized & must not be accessed.
EAGERLY_FINALIZE(); void Dispose();
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
const char* NameInHeapSnapshot() const override { return "DOMTimer"; } const char* NameInHeapSnapshot() const override { return "DOMTimer"; }
......
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