Bug 1257919 part 8. Make the line/column number getters on JSStackFrame take an explicit JSContext. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 22 Mar 2016 13:50:31 -0400
changeset 289968 5481e58d87350c8c90aca096519c999fbb06c320
parent 289967 eb6d3712cf624751707fa56a2a9ba1ca598ad861
child 289969 1091b24a1f23ba682040e13405da1585f07f1e31
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1257919
milestone48.0a1
Bug 1257919 part 8. Make the line/column number getters on JSStackFrame take an explicit JSContext. r=khuey
dom/base/Console.cpp
dom/base/DOMException.cpp
dom/base/DOMException.h
dom/base/nsHostObjectProtocolHandler.cpp
dom/bindings/Bindings.conf
dom/bindings/Exceptions.cpp
dom/workers/ServiceWorkerEvents.cpp
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
security/sandbox/linux/glue/SandboxCrash.cpp
xpcom/base/nsIException.idl
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -1037,23 +1037,23 @@ StackFrameToStackEntry(JSContext* aCx, n
                        ConsoleStackEntry& aStackEntry)
 {
   MOZ_ASSERT(aStackFrame);
 
   nsresult rv = aStackFrame->GetFilename(aCx, aStackEntry.mFilename);
   NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t lineNumber;
-  rv = aStackFrame->GetLineNumber(&lineNumber);
+  rv = aStackFrame->GetLineNumber(aCx, &lineNumber);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aStackEntry.mLineNumber = lineNumber;
 
   int32_t columnNumber;
-  rv = aStackFrame->GetColumnNumber(&columnNumber);
+  rv = aStackFrame->GetColumnNumber(aCx, &columnNumber);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aStackEntry.mColumnNumber = columnNumber;
 
   rv = aStackFrame->GetName(aCx, aStackEntry.mFunctionName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsString cause;
--- a/dom/base/DOMException.cpp
+++ b/dom/base/DOMException.cpp
@@ -316,24 +316,24 @@ Exception::GetFilename(JSContext* aCx, n
     return mLocation->GetFilename(aCx, aFilename);
   }
 
   aFilename.Assign(mFilename);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-Exception::GetLineNumber(uint32_t *aLineNumber)
+Exception::GetLineNumber(JSContext* aCx, uint32_t *aLineNumber)
 {
   NS_ENSURE_ARG_POINTER(aLineNumber);
   NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
 
   if (mLocation) {
     int32_t lineno;
-    nsresult rv = mLocation->GetLineNumber(&lineno);
+    nsresult rv = mLocation->GetLineNumber(aCx, &lineno);
     *aLineNumber = lineno;
     return rv;
   }
 
   *aLineNumber = mLineNumber;
   return NS_OK;
 }
 
@@ -469,21 +469,21 @@ Exception::GetName(nsString& retval)
   DebugOnly<nsresult> rv =
 #endif
   GetName(str);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   CopyUTF8toUTF16(str, retval);
 }
 
 uint32_t
-Exception::LineNumber() const
+Exception::LineNumber(JSContext* aCx) const
 {
   if (mLocation) {
     int32_t lineno;
-    if (NS_SUCCEEDED(mLocation->GetLineNumber(&lineno))) {
+    if (NS_SUCCEEDED(mLocation->GetLineNumber(aCx, &lineno))) {
       return lineno;
     }
     return 0;
   }
 
   return mLineNumber;
 }
 
--- a/dom/base/DOMException.h
+++ b/dom/base/DOMException.h
@@ -73,17 +73,17 @@ public:
 
   uint32_t Result() const;
 
   void GetName(nsString& retval);
 
   // The XPCOM GetFilename does the right thing.  It might throw, but we want to
   // return an empty filename in that case anyway, instead of throwing.
 
-  uint32_t LineNumber() const;
+  uint32_t LineNumber(JSContext* aCx) const;
 
   uint32_t ColumnNumber() const;
 
   already_AddRefed<nsIStackFrame> GetLocation() const;
 
   already_AddRefed<nsISupports> GetData() const;
 
   void GetStack(nsAString& aStack, ErrorResult& aRv) const;
--- a/dom/base/nsHostObjectProtocolHandler.cpp
+++ b/dom/base/nsHostObjectProtocolHandler.cpp
@@ -216,17 +216,17 @@ class BlobURLsReporter final : public ns
     // GetCurrentJSStack() hand out the JSContext it found.
     JSContext* cx = frame ? nsContentUtils::GetCurrentJSContext() : nullptr;
 
     for (uint32_t i = 0; frame; ++i) {
       nsString fileNameUTF16;
       int32_t lineNumber = 0;
 
       frame->GetFilename(cx, fileNameUTF16);
-      frame->GetLineNumber(&lineNumber);
+      frame->GetLineNumber(cx, &lineNumber);
 
       if (!fileNameUTF16.IsEmpty()) {
         NS_ConvertUTF16toUTF8 fileName(fileNameUTF16);
         stack += "js(";
         if (!origin.IsEmpty()) {
           // Make the file name root-relative for conciseness if possible.
           const char* originData;
           uint32_t originLen;
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -404,17 +404,17 @@ DOMInterfaces = {
 'DominatorTree': {
     'nativeType': 'mozilla::devtools::DominatorTree'
 },
 
 'DOMException': {
     'binaryNames': {
         'message': 'messageMoz',
     },
-    'implicitJSContext': [ 'filename' ],
+    'implicitJSContext': [ 'filename', 'lineNumber' ],
 },
 
 'DOMMatrixReadOnly': {
     'headerFile': 'mozilla/dom/DOMMatrix.h',
     'concrete': False,
 },
 
 'DOMPointReadOnly': {
@@ -474,17 +474,17 @@ DOMInterfaces = {
     'jsImplParent': 'mozilla::DOMEventTargetHelper'
 },
 
 'Exception': {
     'headerFile': 'mozilla/dom/DOMException.h',
     'binaryNames': {
         'message': 'messageMoz',
     },
-    'implicitJSContext': [ '__stringifier', 'filename' ],
+    'implicitJSContext': [ '__stringifier', 'filename', 'lineNumber' ],
 },
 
 'ExtendableEvent': {
     'headerFile': 'mozilla/dom/ServiceWorkerEvents.h',
     'nativeType': 'mozilla::dom::workers::ExtendableEvent',
     'implicitJSContext': [ 'waitUntil' ],
 },
 
--- a/dom/bindings/Exceptions.cpp
+++ b/dom/bindings/Exceptions.cpp
@@ -207,19 +207,19 @@ public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(JSStackFrame)
   NS_DECL_NSISTACKFRAME
 
   // aStack must not be null.
   explicit JSStackFrame(JS::Handle<JSObject*> aStack);
 
 protected:
-  int32_t GetLineno();
+  int32_t GetLineno(JSContext* aCx);
 
-  int32_t GetColNo();
+  int32_t GetColNo(JSContext* aCx);
 
 private:
   virtual ~JSStackFrame();
 
   JS::Heap<JSObject*> mStack;
   nsString mFormattedStack;
 
   nsCOMPtr<nsIStackFrame> mCaller;
@@ -403,74 +403,73 @@ NS_IMETHODIMP JSStackFrame::GetName(JSCo
     mFunname = aFunction;
     mFunnameInitialized = true;
   }
 
   return NS_OK;
 }
 
 int32_t
-JSStackFrame::GetLineno()
+JSStackFrame::GetLineno(JSContext* aCx)
 {
   if (!mStack) {
     return 0;
   }
 
-  ThreadsafeAutoJSContext cx;
   uint32_t line;
   bool canCache = false, useCachedValue = false;
-  GetValueIfNotCached(cx, mStack, JS::GetSavedFrameLine, mLinenoInitialized,
+  GetValueIfNotCached(aCx, mStack, JS::GetSavedFrameLine, mLinenoInitialized,
                       &canCache, &useCachedValue, &line);
 
   if (useCachedValue) {
     return mLineno;
   }
 
   if (canCache) {
     mLineno = line;
     mLinenoInitialized = true;
   }
 
   return line;
 }
 
-NS_IMETHODIMP JSStackFrame::GetLineNumber(int32_t* aLineNumber)
+NS_IMETHODIMP JSStackFrame::GetLineNumber(JSContext* aCx, int32_t* aLineNumber)
 {
-  *aLineNumber = GetLineno();
+  *aLineNumber = GetLineno(aCx);
   return NS_OK;
 }
 
 int32_t
-JSStackFrame::GetColNo()
+JSStackFrame::GetColNo(JSContext* aCx)
 {
   if (!mStack) {
     return 0;
   }
 
-  ThreadsafeAutoJSContext cx;
   uint32_t col;
   bool canCache = false, useCachedValue = false;
-  GetValueIfNotCached(cx, mStack, JS::GetSavedFrameColumn, mColNoInitialized,
+  GetValueIfNotCached(aCx, mStack, JS::GetSavedFrameColumn, mColNoInitialized,
                       &canCache, &useCachedValue, &col);
 
   if (useCachedValue) {
     return mColNo;
   }
 
   if (canCache) {
     mColNo = col;
     mColNoInitialized = true;
   }
 
   return col;
 }
 
-NS_IMETHODIMP JSStackFrame::GetColumnNumber(int32_t* aColumnNumber)
+NS_IMETHODIMP JSStackFrame::GetColumnNumber(JSContext* aCx,
+                                            int32_t* aColumnNumber)
 {
-  *aColumnNumber = GetColNo();
+  *aColumnNumber = GetColNo(aCx);
   return NS_OK;
 }
 
 NS_IMETHODIMP JSStackFrame::GetSourceLine(nsACString& aSourceLine)
 {
   aSourceLine.Truncate();
   return NS_OK;
 }
@@ -645,17 +644,17 @@ NS_IMETHODIMP JSStackFrame::ToString(JSC
   nsString funname;
   rv = GetName(aCx, funname);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (funname.IsEmpty()) {
     funname.AssignLiteral("<TOP_LEVEL>");
   }
 
-  int32_t lineno = GetLineno();
+  int32_t lineno = GetLineno(aCx);
 
   static const char format[] = "JS frame :: %s :: %s :: line %d";
   _retval.AppendPrintf(format,
                        NS_ConvertUTF16toUTF8(filename).get(),
                        NS_ConvertUTF16toUTF8(funname).get(),
                        lineno);
   return NS_OK;
 }
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -426,17 +426,17 @@ ExtractErrorValues(JSContext* aCx, JS::H
 
     // Next, try to unwrap the rejection value as a DOMException.
     else if(NS_SUCCEEDED(UNWRAP_OBJECT(DOMException, obj, domException))) {
 
       nsAutoString filename;
       domException->GetFilename(aCx, filename);
       if (!filename.IsEmpty()) {
         CopyUTF16toUTF8(filename, aSourceSpecOut);
-        *aLineOut = domException->LineNumber();
+        *aLineOut = domException->LineNumber(aCx);
         *aColumnOut = domException->ColumnNumber();
       }
 
       domException->GetName(aMessageOut);
       aMessageOut.AppendLiteral(": ");
 
       nsAutoString message;
       domException->GetMessageMoz(message);
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1575,17 +1575,17 @@ AssembleSandboxMemoryReporterName(JSCont
     nsCOMPtr<nsIStackFrame> frame;
     xpc->GetCurrentJSStack(getter_AddRefs(frame));
 
     // Append the caller's location information.
     if (frame) {
         nsString location;
         int32_t lineNumber = 0;
         frame->GetFilename(cx, location);
-        frame->GetLineNumber(&lineNumber);
+        frame->GetLineNumber(cx, &lineNumber);
 
         sandboxName.AppendLiteral(" (from: ");
         sandboxName.Append(NS_ConvertUTF16toUTF8(location));
         sandboxName.Append(':');
         sandboxName.AppendInt(lineNumber);
         sandboxName.Append(')');
     }
 
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2318,17 +2318,17 @@ nsXPCComponents_Utils::ReportError(Handl
 
     nsString fileName;
     int32_t lineNo = 0;
 
     if (!scripterr) {
         nsCOMPtr<nsIStackFrame> frame = dom::GetCurrentJSStack();
         if (frame) {
             frame->GetFilename(cx, fileName);
-            frame->GetLineNumber(&lineNo);
+            frame->GetLineNumber(cx, &lineNo);
             JS::Rooted<JS::Value> stack(cx);
             nsresult rv = frame->GetNativeSavedFrame(&stack);
             if (NS_SUCCEEDED(rv) && stack.isObject()) {
               JS::Rooted<JSObject*> stackObj(cx, &stack.toObject());
               scripterr = new nsScriptErrorWithStack(stackObj);
             }
         }
     }
@@ -2426,17 +2426,17 @@ nsXPCComponents_Utils::EvalInSandbox(con
         NS_ENSURE_SUCCESS(rv, rv);
 
         nsCOMPtr<nsIStackFrame> frame;
         xpc->GetCurrentJSStack(getter_AddRefs(frame));
         if (frame) {
             nsString frameFile;
             frame->GetFilename(cx, frameFile);
             CopyUTF16toUTF8(frameFile, filename);
-            frame->GetLineNumber(&lineNo);
+            frame->GetLineNumber(cx, &lineNo);
         }
     }
 
     return xpc::EvalInSandbox(cx, sandbox, source, filename, lineNo,
                               jsVersion, retval);
 }
 
 NS_IMETHODIMP
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -912,17 +912,17 @@ nsXPCWrappedJSClass::CheckForException(X
                                 int32_t lineNumber = 0;
                                 nsString sourceName;
 
                                 nsCOMPtr<nsIStackFrame> location;
                                 xpc_exception->
                                     GetLocation(getter_AddRefs(location));
                                 if (location) {
                                     // Get line number w/o checking; 0 is ok.
-                                    location->GetLineNumber(&lineNumber);
+                                    location->GetLineNumber(cx, &lineNumber);
 
                                     // get a filename.
                                     rv = location->GetFilename(cx, sourceName);
                                 }
 
                                 rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(newMessage),
                                                                    sourceName,
                                                                    EmptyString(),
--- a/security/sandbox/linux/glue/SandboxCrash.cpp
+++ b/security/sandbox/linux/glue/SandboxCrash.cpp
@@ -52,17 +52,17 @@ SandboxLogJSStack(void)
   for (int i = 0; frame != nullptr; ++i) {
     nsAutoString fileName, funName;
     int32_t lineNumber;
 
     // Don't stop unwinding if an attribute can't be read.
     fileName.SetIsVoid(true);
     Unused << frame->GetFilename(cx, fileName);
     lineNumber = 0;
-    Unused << frame->GetLineNumber(&lineNumber);
+    Unused << frame->GetLineNumber(cx, &lineNumber);
     funName.SetIsVoid(true);
     Unused << frame->GetName(cx, funName);
 
     if (!funName.IsVoid() || !fileName.IsVoid()) {
       SANDBOX_LOG_ERROR("JS frame %d: %s %s line %d", i,
                         funName.IsVoid() ?
                         "(anonymous)" : NS_ConvertUTF16toUTF8(funName).get(),
                         fileName.IsVoid() ?
--- a/xpcom/base/nsIException.idl
+++ b/xpcom/base/nsIException.idl
@@ -16,17 +16,19 @@ interface nsIStackFrame : nsISupports
     // see nsIProgrammingLanguage for list of language consts
     readonly attribute uint32_t                language;
     readonly attribute AUTF8String             languageName;
     [implicit_jscontext]
     readonly attribute AString                 filename;
     [implicit_jscontext]
     readonly attribute AString                 name;
     // Valid line numbers begin at '1'. '0' indicates unknown.
+    [implicit_jscontext]
     readonly attribute int32_t                 lineNumber;
+    [implicit_jscontext]
     readonly attribute int32_t                 columnNumber;
     readonly attribute AUTF8String             sourceLine;
     readonly attribute AString                 asyncCause;
     readonly attribute nsIStackFrame           asyncCaller;
     readonly attribute nsIStackFrame           caller;
 
     // Returns a formatted stack string that looks like the sort of
     // string that would be returned by .stack on JS Error objects.
@@ -57,16 +59,17 @@ interface nsIException : nsISupports
     // the same location as their top stack entry.  File
     // parsers may put the location of the file they were parsing,
     // etc.
 
     // null indicates "no data"
     [implicit_jscontext]
     readonly attribute AString                 filename;
     // Valid line numbers begin at '1'. '0' indicates unknown.
+    [implicit_jscontext]
     readonly attribute uint32_t                lineNumber;
     // Valid column numbers begin at 0.
     // We don't have an unambiguous indicator for unknown.
     readonly attribute uint32_t                columnNumber;
 
     // A stack trace, if available.
     readonly attribute nsIStackFrame           location;