Bug 949471. history.state should be null, not undefined, when there is no state. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 12 Dec 2013 16:11:56 -0500
changeset 160272 47efe38fe54098339f94b196f9a964474d151468
parent 160271 46e29a05206dddce17a4ceabb29ca5c47d829085
child 160273 372f481bc7ad4c6dd0fc6da22943eaf8cf8ccf43
push id25827
push userkwierso@gmail.com
push dateFri, 13 Dec 2013 03:13:04 +0000
treeherdermozilla-central@1bc33fa19b24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs949471
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 949471. history.state should be null, not undefined, when there is no state. r=smaug
dom/base/nsHistory.cpp
dom/base/test/mochitest.ini
dom/base/test/test_history_state_null.html
dom/tests/mochitest/whatwg/test_bug500328.html
--- a/dom/base/nsHistory.cpp
+++ b/dom/base/nsHistory.cpp
@@ -134,17 +134,17 @@ nsHistory::GetState(JSContext* aCx, Erro
     if (!JS_WrapValue(aCx, &jsData)) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
       return JS::UndefinedValue();
     }
 
     return jsData;
   }
 
-  return JS::UndefinedValue();
+  return JS::NullValue();
 }
 
 void
 nsHistory::Go(int32_t aDelta, ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mInnerWindow));
   if (!win || !win->HasActiveDocument()) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -14,16 +14,17 @@ support-files =
 [test_domcursor.html]
 [test_domrequest.html]
 [test_e4x_for_each.html]
 [test_error.html]
 [test_gsp-qualified.html]
 [test_gsp-quirks.html]
 [test_gsp-standards.html]
 [test_history_document_open.html]
+[test_history_state_null.html]
 [test_innersize_scrollport.html]
 [test_messageChannel.html]
 [test_messageChannel_cloning.html]
 [test_messageChannel_pingpong.html]
 [test_messageChannel_post.html]
 [test_messageChannel_pref.html]
 [test_messageChannel_start.html]
 [test_messageChannel_transferable.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_history_state_null.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=949471
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 949471</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+  /** Test for Bug 949471 **/
+    ise(history.state, null, "history.state should be null by default");
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949471">Mozilla Bug 949471</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
--- a/dom/tests/mochitest/whatwg/test_bug500328.html
+++ b/dom/tests/mochitest/whatwg/test_bug500328.html
@@ -273,39 +273,39 @@ function runTest() {
      "Wrong state object popped after going back to page 1.");
   ok(gLastPopStateEvent.state === iframeCw.history.state,
      "Wrong state object in document after going back to page 1.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html$/),
       "Going back to page 1 hould take us to original page.");
 
   iframeCw.history.back();
   popstateExpected("Going back to page 0 should trigger a popstate.");
-  is(gLastPopStateEvent.state, null,
+  ise(gLastPopStateEvent.state, null,
       "Going back to page 0 should pop a null state.");
-  is(iframeCw.history.state, null,
+  ise(iframeCw.history.state, null,
       "Going back to page 0 should pop a null state.");
-  is(iframeCw.location.search, "",
+  ise(iframeCw.location.search, "",
       "Going back to page 0 should clear the querystring.");
 
   iframeCw.history.forward();
   popstateExpected("Going forward to page 1 should trigger a popstate.");
   is(JSON.stringify(gLastPopStateEvent.state), JSON.stringify(testObj1),
       "Wrong state object popped after going forward to page 1.");
-  ok(gLastPopStateEvent.state === iframeCw.history.state,
+  ise(gLastPopStateEvent.state, iframeCw.history.state,
       "Wrong state object in document after going forward to page 1.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html$/),
       "Going forward to page 1 should leave us at original page.");
 
   statusMsg("About to go forward to page 2.");
   iframeCw.history.forward();
   statusMsg("Awake after going forward to page 2.");
   popstateExpected("Going forward to page 2 should trigger a popstate.");
   is(JSON.stringify(gLastPopStateEvent.state), JSON.stringify(testObj2),
      "Wrong state object popped after going forward to page 2.");
-  ok(iframeCw.history.state === gLastPopStateEvent.state,
+  ise(iframeCw.history.state, gLastPopStateEvent.state,
      "Wrong state object in document after going forward to page 2.");
   ok(iframeCw.location.toString().match(/file_bug500328_1.html\?test1#foo$/),
      "Going forward to page 2 took us to " + iframeCw.location.toString());
 
   statusMsg("About to reload page 2.");
   iframeCw.location.reload();
   enableChildLoadCallback();
   yield undefined;
@@ -324,17 +324,17 @@ function runTest() {
   enableChildPopStateCallback();
   sendMouseEvent({type:'click'}, 'link-anchor1', iframeCw);
   yield undefined;
   popstateExpected("Clicking on link-anchor1 should trigger a popstate.");
   is(iframeCw.location.search, "?test1",
       "search should be ?test1 after clicking link.");
   is(iframeCw.location.hash, "#1",
       "hash should be #1 after clicking link.");
-  ok(iframeCw.history.state === null,
+  ise(iframeCw.history.state, null,
      "Wrong state object in document after clicking link to hash '#1'.");
 
   /*
    * Reload file_bug500328_1.html; we're now going to test that link hrefs
    * and colors are updated correctly on push/popstates.
    */
 
   iframe.onload = onChildLoad;