Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp

Issue 2025143003: [Fetch API] Request's JS wrapper should be kept alive in FetchEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp b/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
index acfcff1569bcfc6c8c274ebd8bc0476e5d65650e..5346f5580750c5b11f3fcaa28f3ea02678a5797c 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
@@ -4,6 +4,8 @@
#include "modules/serviceworkers/FetchEvent.h"
+#include "bindings/core/v8/ToV8.h"
+#include "bindings/core/v8/V8HiddenValue.h"
#include "modules/fetch/Request.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
#include "wtf/RefPtr.h"
@@ -15,14 +17,14 @@ FetchEvent* FetchEvent::create()
return new FetchEvent();
}
-FetchEvent* FetchEvent::create(const AtomicString& type, const FetchEventInit& initializer)
+FetchEvent* FetchEvent::create(ScriptState* scriptState, const AtomicString& type, const FetchEventInit& initializer)
{
- return new FetchEvent(type, initializer, nullptr);
+ return new FetchEvent(scriptState, type, initializer, nullptr);
}
-FetchEvent* FetchEvent::create(const AtomicString& type, const FetchEventInit& initializer, RespondWithObserver* observer)
+FetchEvent* FetchEvent::create(ScriptState* scriptState, const AtomicString& type, const FetchEventInit& initializer, RespondWithObserver* observer)
{
- return new FetchEvent(type, initializer, observer);
+ return new FetchEvent(scriptState, type, initializer, observer);
}
Request* FetchEvent::request() const
@@ -57,14 +59,32 @@ FetchEvent::FetchEvent()
{
}
-FetchEvent::FetchEvent(const AtomicString& type, const FetchEventInit& initializer, RespondWithObserver* observer)
+FetchEvent::FetchEvent(ScriptState* scriptState, const AtomicString& type, const FetchEventInit& initializer, RespondWithObserver* observer)
: ExtendableEvent(type, initializer)
, m_observer(observer)
{
- if (initializer.hasRequest())
- m_request = initializer.request();
m_clientId = initializer.clientId();
m_isReload = initializer.isReload();
+ if (initializer.hasRequest()) {
+ ScriptState::Scope scope(scriptState);
+ m_request = initializer.request();
+ v8::Local<v8::Value> request = toV8(m_request, scriptState);
+ v8::Local<v8::Value> event = toV8(this, scriptState);
+ if (event.IsEmpty()) {
+ // |toV8| can return an empty handle when the worker is terminating.
+ // We don't want the renderer to crash in such cases.
+ // TODO(yhirano): Replace this branch with an assertion when the
+ // graceful shutdown mechanism is introduced.
+ return;
+ }
+ DCHECK(event->IsObject());
+ // Sets a hidden value in order to teach V8 the dependency from
+ // the event to the request.
+ V8HiddenValue::setHiddenValue(scriptState, event.As<v8::Object>(), V8HiddenValue::requestInFetchEvent(scriptState->isolate()), request);
+ // From the same reason as above, setHiddenValue can return false.
+ // TODO(yhirano): Add an assertion that it returns true once the
+ // graceful shutdown mechanism is introduced.
+ }
}
DEFINE_TRACE(FetchEvent)

Powered by Google App Engine
This is Rietveld 408576698