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

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..7eea246c54d3debd287a20348c809d781aef0792 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,30 @@ 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);
haraken 2016/06/01 12:16:59 Given that both objects have wrappers, can we use
+ 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.
+ return;
+ }
+ DCHECK(event->IsObject());
+ // Sets an hidden value in order to teach V8 the dependency from
haraken 2016/06/01 12:16:59 a hidden value
yhirano 2016/06/03 02:09:45 Done.
+ // the event to the request.
+ V8HiddenValue::setHiddenValue(scriptState, event.As<v8::Object>(), V8HiddenValue::requestInFetchEvent(scriptState->isolate()), request);
haraken 2016/06/01 12:16:59 yukishiino@ is replacing V8HiddenValue with V8Priv
yhirano 2016/06/01 12:22:51 Does it work with M52? If this CL fixes crashes, I
Yuki 2016/06/02 04:51:12 No, V8PrivateProperty gets supported since M53. P
+ // As written above, we don't check the return value.
+ // TODO(yhirano): Add an assertion.
+ }
}
DEFINE_TRACE(FetchEvent)

Powered by Google App Engine
This is Rietveld 408576698