Bug 1215140 P5 Report the line number where respondWith() was called. r=bz a=ritu l10n=ritu
authorBen Kelly <ben@wanderview.com>
Thu, 29 Oct 2015 19:53:25 -0700
changeset 305430 325d05344d2f3984e06cc7db66762341e9e84433
parent 305429 2b3597ed05d8c2e512730dfad0628d0dd9e0822a
child 305431 3eb450d0732dba2748966dbefc3428afd4b7a8e4
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, ritu
bugs1215140
milestone44.0a2
Bug 1215140 P5 Report the line number where respondWith() was called. r=bz a=ritu l10n=ritu
dom/bindings/Bindings.conf
dom/workers/ServiceWorkerEvents.cpp
dom/workers/ServiceWorkerEvents.h
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -490,16 +490,17 @@ DOMInterfaces = {
 },
 
 'FetchEvent': {
     'headerFile': 'ServiceWorkerEvents.h',
     'nativeType': 'mozilla::dom::workers::FetchEvent',
     'binaryNames': {
         'request': 'request_'
     },
+    'implicitJSContext': [ 'respondWith' ],
 },
 
 'FileReader': {
     'nativeType': 'nsDOMFileReader',
     'implicitJSContext': [ 'readAsArrayBuffer' ],
 },
 
 'FileReaderSync': {
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -193,29 +193,38 @@ public:
 
 class RespondWithHandler final : public PromiseNativeHandler
 {
   nsMainThreadPtrHandle<nsIInterceptedChannel> mInterceptedChannel;
   const RequestMode mRequestMode;
   const DebugOnly<bool> mIsClientRequest;
   const bool mIsNavigationRequest;
   const nsCString mScriptSpec;
+  const nsCString mRespondWithScriptSpec;
+  const uint32_t mRespondWithLineNumber;
+  const uint32_t mRespondWithColumnNumber;
   bool mRequestWasHandled;
 public:
   NS_DECL_ISUPPORTS
 
   RespondWithHandler(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
                      RequestMode aRequestMode, bool aIsClientRequest,
                      bool aIsNavigationRequest,
-                     const nsACString& aScriptSpec)
+                     const nsACString& aScriptSpec,
+                     const nsACString& aRespondWithScriptSpec,
+                     uint32_t aRespondWithLineNumber,
+                     uint32_t aRespondWithColumnNumber)
     : mInterceptedChannel(aChannel)
     , mRequestMode(aRequestMode)
     , mIsClientRequest(aIsClientRequest)
     , mIsNavigationRequest(aIsNavigationRequest)
     , mScriptSpec(aScriptSpec)
+    , mRespondWithScriptSpec(aRespondWithScriptSpec)
+    , mRespondWithLineNumber(aRespondWithLineNumber)
+    , mRespondWithColumnNumber(aRespondWithColumnNumber)
     , mRequestWasHandled(false)
   {
   }
 
   void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
 
   void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
 
@@ -445,39 +454,50 @@ RespondWithHandler::AsyncLog(const nsACS
   // TODO: pass rejection value
   nsCOMPtr<nsIChannel> inner;
   mInterceptedChannel->GetChannel(getter_AddRefs(inner));
   nsCOMPtr<nsIConsoleReportCollector> reporter = do_QueryInterface(inner);
   if (reporter) {
     reporter->AddConsoleReport(nsIScriptError::errorFlag,
                                NS_LITERAL_CSTRING("Service Worker Interception"),
                                nsContentUtils::eDOM_PROPERTIES,
-                               mScriptSpec,
-                               0, 0,
+                               mRespondWithScriptSpec,
+                               mRespondWithLineNumber,
+                               mRespondWithColumnNumber,
                                aMessageName,
                                nsTArray<nsString>());
   }
 }
 
 } // namespace
 
 void
-FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv)
+FetchEvent::RespondWith(JSContext* aCx, Promise& aArg, ErrorResult& aRv)
 {
   if (EventPhase() == nsIDOMEvent::NONE || mWaitToRespond) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
+
+  // Record where respondWith() was called in the script so we can include the
+  // information in any error reporting.  We should be guaranteed not to get
+  // a file:// string here because service workers require http/https.
+  nsCString spec;
+  uint32_t line = 0;
+  uint32_t column = 0;
+  nsJSUtils::GetCallingLocation(aCx, spec, &line, &column);
+
   RefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
   StopImmediatePropagation();
   mWaitToRespond = true;
   RefPtr<RespondWithHandler> handler =
     new RespondWithHandler(mChannel, mRequest->Mode(), ir->IsClientRequest(),
-                           ir->IsNavigationRequest(), mScriptSpec);
+                           ir->IsNavigationRequest(), mScriptSpec,
+                           spec, line, column);
   aArg.AppendNativeHandler(handler);
 
   WaitUntil(aArg, aRv);
 }
 
 NS_IMPL_ADDREF_INHERITED(FetchEvent, ExtendableEvent)
 NS_IMPL_RELEASE_INHERITED(FetchEvent, ExtendableEvent)
 
--- a/dom/workers/ServiceWorkerEvents.h
+++ b/dom/workers/ServiceWorkerEvents.h
@@ -142,17 +142,17 @@ public:
 
   bool
   IsReload() const
   {
     return mIsReload;
   }
 
   void
-  RespondWith(Promise& aArg, ErrorResult& aRv);
+  RespondWith(JSContext* aCx, Promise& aArg, ErrorResult& aRv);
 
   already_AddRefed<Promise>
   ForwardTo(const nsAString& aUrl);
 
   already_AddRefed<Promise>
   Default();
 };