Bug 1218499 - Make FetchEvent.request nullable; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Oct 2015 15:50:50 -0400
changeset 269692 253416fea6438c102e6d9c5c3b2c6f04fe62896e
parent 269691 097d7c881a891078e951d7b2720d4470aa98a9ed
child 269693 9c01b4d30bddd2b48ad2e43fe9d06da3558409c9
push id15905
push usercbook@mozilla.com
push dateTue, 27 Oct 2015 09:59:36 +0000
treeherderfx-team@60acc8a9cfb5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1218499
milestone44.0a1
Bug 1218499 - Make FetchEvent.request nullable; r=bzbarsky
dom/webidl/FetchEvent.webidl
dom/workers/ServiceWorkerEvents.h
dom/workers/test/serviceworkers/fetch/fetch_tests.js
dom/workers/test/serviceworkers/fetch_event_worker.js
--- a/dom/webidl/FetchEvent.webidl
+++ b/dom/webidl/FetchEvent.webidl
@@ -6,17 +6,17 @@
  * For more information on this interface, please see
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  */
 
 [Constructor(DOMString type, optional FetchEventInit eventInitDict),
  Func="mozilla::dom::workers::ServiceWorkerVisible",
  Exposed=(ServiceWorker)]
 interface FetchEvent : ExtendableEvent {
-  [SameObject] readonly attribute Request request;
+  [SameObject] readonly attribute Request? request;
   readonly attribute boolean isReload;
 
   [Throws]
   void respondWith(Promise<Response> r);
 };
 
 dictionary FetchEventInit : EventInit {
   Request request;
--- a/dom/workers/ServiceWorkerEvents.h
+++ b/dom/workers/ServiceWorkerEvents.h
@@ -131,17 +131,17 @@ public:
 
   bool
   WaitToRespond() const
   {
     return mWaitToRespond;
   }
 
   Request*
-  Request_() const
+  GetRequest_() const
   {
     return mRequest;
   }
 
   bool
   IsReload() const
   {
     return mIsReload;
--- a/dom/workers/test/serviceworkers/fetch/fetch_tests.js
+++ b/dom/workers/test/serviceworkers/fetch/fetch_tests.js
@@ -382,8 +382,20 @@ fetch('fetchevent-extendable')
   return res.text();
 }).then(function(body) {
   my_ok(body == "extendable", "FetchEvent inherits from ExtendableEvent");
   finish();
 }, function(err) {
   my_ok(false, "A promise was rejected with " + err);
   finish();
 });
+
+expectAsyncResult();
+fetch('fetchevent-request')
+.then(function(res) {
+  return res.text();
+}).then(function(body) {
+  my_ok(body == "nullable", "FetchEvent.request must be nullable");
+  finish();
+}, function(err) {
+  my_ok(false, "A promise was rejected with " + err);
+  finish();
+});
--- a/dom/workers/test/serviceworkers/fetch_event_worker.js
+++ b/dom/workers/test/serviceworkers/fetch_event_worker.js
@@ -286,9 +286,17 @@ onfetch = function(ev) {
 
   else if (ev.request.url.includes('fetchevent-extendable')) {
     if (ev instanceof ExtendableEvent) {
       ev.respondWith(new Response("extendable"));
     } else {
       ev.respondWith(Promise.reject());
     }
   }
+
+  else if (ev.request.url.includes('fetchevent-request')) {
+    if ((new FetchEvent("foo")).request === null) {
+      ev.respondWith(new Response("nullable"));
+    } else {
+      ev.respondWith(Promise.reject());
+    }
+  }
 };