Bug 801241 - Properly handle |false| return false from JS_DescribeScriptedCaller. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 17 Oct 2012 19:44:30 +0200
changeset 110705 6ed5f4767b57cf1638e2d94e9b8471eb31ec8735
parent 110704 e7ea9b548002ccfdc92b1c2dec4237249fbd4f8e
child 110706 9fcf07b50922ef4a4660ffcab5ca99becc96482d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbz
bugs801241
milestone19.0a1
Bug 801241 - Properly handle |false| return false from JS_DescribeScriptedCaller. r=bz
dom/base/nsLocation.cpp
js/xpconnect/tests/chrome/Makefile.in
js/xpconnect/tests/chrome/test_bug801241.xul
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -207,20 +207,23 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDo
     // Make the load's referrer reflect changes to the document's URI caused by
     // push/replaceState, if possible.  First, get the document corresponding to
     // fp.  If the document's original URI (i.e. its URI before
     // push/replaceState) matches the principal's URI, use the document's
     // current URI as the referrer.  If they don't match, use the principal's
     // URI.
 
     JSScript* script = nullptr;
-    if (!JS_DescribeScriptedCaller(cx, &script, nullptr))
-      return NS_ERROR_FAILURE;
-    nsCOMPtr<nsIDocument> doc = GetScriptDocument(cx, script);
+    nsCOMPtr<nsIDocument> doc;
     nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
+    // NB: A false return value from JS_DescribeScriptedCaller means no caller
+    // was found. It does not signal that an exception was thrown.
+    if (JS_DescribeScriptedCaller(cx, &script, nullptr)) {
+      doc = GetScriptDocument(cx, script);
+    }
     if (doc) {
       docOriginalURI = doc->GetOriginalURI();
       docCurrentURI = doc->GetDocumentURI();
       rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI));
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     bool urisEqual = false;
--- a/js/xpconnect/tests/chrome/Makefile.in
+++ b/js/xpconnect/tests/chrome/Makefile.in
@@ -38,16 +38,17 @@ MOCHITEST_CHROME_FILES = \
 		test_bug760109.xul \
 		test_bug763343.xul \
 		test_bug771429.xul \
 		test_bug773962.xul \
 		test_bug792280.xul \
 		test_bug793433.xul \
 		test_bug795275.xul \
 		test_bug799348.xul \
+		test_bug801241.xul \
 		test_APIExposer.xul \
 		test_chrometoSource.xul \
 		outoflinexulscript.js \
 		subscript.js \
 		test_cows.xul \
 		test_documentdomain.xul \
 		test_doublewrappedcompartments.xul \
 		test_evalInSandbox.xul \
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/chrome/test_bug801241.xul
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=801241
+-->
+<window title="Mozilla Bug 801241"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=801241"
+     target="_blank">Mozilla Bug 801241</a>
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+  /** Test for Bug 801241 **/
+  SimpleTest.waitForExplicitFinish();
+  const Cu = Components.utils;
+
+  // This is decompiled and run inside the sandbox;
+  function sbCode() {
+    try {
+      win.location = win.location;
+      ok(true, "Didn't throw setting from location");
+    } catch (e) {
+      ok(false, "Threw setting location from sandbox");
+    }
+  }
+
+  function go() {
+    var sb = new Cu.Sandbox(this);
+    sb.win = document.getElementById('ifr').contentWindow;
+    sb.ok = ok;
+    Cu.evalInSandbox('(' + sbCode.toSource() + ')()', sb);
+    SimpleTest.finish();
+  }
+
+  ]]>
+  </script>
+  <iframe id="ifr" onload="go();" type="content" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
+</window>