Commit ae782ad1 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

Make V8IntersectionObserverDelegate inherit from ContextClient

We should use ContextClient instead of storing ScriptState because
ContextClient can check whether the context is destroyed.

Bug: 785553
Change-Id: Icf85fb6c3f97c9a50f85de812b812999669b96f5
Reviewed-on: https://chromium-review.googlesource.com/776136Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517318}
parent 5c2b1c55
......@@ -17,7 +17,8 @@ namespace blink {
V8IntersectionObserverDelegate::V8IntersectionObserverDelegate(
V8IntersectionObserverCallback* callback,
ScriptState* script_state)
: callback_(callback), script_state_(script_state) {}
: ContextClient(ExecutionContext::From(script_state)),
callback_(callback) {}
V8IntersectionObserverDelegate::~V8IntersectionObserverDelegate() {}
......@@ -27,9 +28,14 @@ void V8IntersectionObserverDelegate::Deliver(
callback_->call(&observer, entries, &observer);
}
ExecutionContext* V8IntersectionObserverDelegate::GetExecutionContext() const {
return ContextClient::GetExecutionContext();
}
void V8IntersectionObserverDelegate::Trace(blink::Visitor* visitor) {
visitor->Trace(callback_);
IntersectionObserverDelegate::Trace(visitor);
ContextClient::Trace(visitor);
}
void V8IntersectionObserverDelegate::TraceWrappers(
......
......@@ -6,6 +6,7 @@
#define V8IntersectionObserverDelegate_h
#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/dom/ExecutionContext.h"
#include "core/intersection_observer/IntersectionObserverDelegate.h"
#include "platform/bindings/DOMWrapperWorld.h"
......@@ -17,26 +18,25 @@ namespace blink {
class V8IntersectionObserverCallback;
class V8IntersectionObserverDelegate final
: public IntersectionObserverDelegate {
: public IntersectionObserverDelegate,
public ContextClient {
USING_GARBAGE_COLLECTED_MIXIN(V8IntersectionObserverDelegate);
public:
CORE_EXPORT V8IntersectionObserverDelegate(V8IntersectionObserverCallback*,
ScriptState*);
~V8IntersectionObserverDelegate() override;
ExecutionContext* GetExecutionContext() const override;
virtual void Trace(blink::Visitor*);
virtual void TraceWrappers(const ScriptWrappableVisitor*) const;
void Deliver(const HeapVector<Member<IntersectionObserverEntry>>&,
IntersectionObserver&) override;
ExecutionContext* GetExecutionContext() const override {
return ExecutionContext::From(script_state_.get());
}
private:
TraceWrapperMember<V8IntersectionObserverCallback> callback_;
// TODO(bashi): Use ContextClient rather than holding ScriptState.
scoped_refptr<ScriptState> script_state_;
};
} // namespace blink
......
......@@ -329,6 +329,7 @@ String IntersectionObserver::rootMargin() const {
void IntersectionObserver::EnqueueIntersectionObserverEntry(
IntersectionObserverEntry& entry) {
DCHECK(delegate_->GetExecutionContext());
entries_.push_back(&entry);
ToDocument(delegate_->GetExecutionContext())
->EnsureIntersectionObserverController()
......
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