Bug 562433 - Change location.host and location.hostname to return "" for host-less URIs instead of throwing. r=bz
authorSaint Wesonga <wesongathedeveloper@yahoo.com>
Sat, 07 Aug 2010 09:11:43 +0200
changeset 49134 fc754baf4c59371f75ca4936157d8db26fa422e0
parent 49133 e601f6dcd81ae8029f96071d028b844bc116de73
child 49135 4ed5db7f396ac92898f6d3b19939c50fa214827e
push id14914
push userdgottwald@mozilla.com
push dateSat, 07 Aug 2010 07:19:25 +0000
treeherdermozilla-central@2cf6079d86dd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs562433
milestone2.0b4pre
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 562433 - Change location.host and location.hostname to return "" for host-less URIs instead of throwing. r=bz
dom/base/nsLocation.cpp
dom/tests/mochitest/bugs/Makefile.in
dom/tests/mochitest/bugs/test_bug562433.html
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -399,17 +399,17 @@ nsLocation::GetHost(nsAString& aHost)
 
     result = uri->GetHostPort(hostport);
 
     if (NS_SUCCEEDED(result)) {
       AppendUTF8toUTF16(hostport, aHost);
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLocation::SetHost(const nsAString& aHost)
 {
   nsCOMPtr<nsIURI> uri;
   nsresult rv = GetWritableURI(getter_AddRefs(uri));
 
@@ -438,17 +438,17 @@ nsLocation::GetHostname(nsAString& aHost
 
     result = uri->GetHost(host);
 
     if (NS_SUCCEEDED(result)) {
       AppendUTF8toUTF16(host, aHostname);
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLocation::SetHostname(const nsAString& aHostname)
 {
   nsCOMPtr<nsIURI> uri;
   nsresult rv = GetWritableURI(getter_AddRefs(uri));
 
--- a/dom/tests/mochitest/bugs/Makefile.in
+++ b/dom/tests/mochitest/bugs/Makefile.in
@@ -111,15 +111,16 @@ include $(topsrcdir)/config/rules.mk
 		test_bug531176.html \
 		test_bug531542.html \
 		test_bug456151.html \
 		test_bug534149.html \
 		test_bug558973.html \
 		test_bug563487.html \
 		test_bug545314.html \
 		test_bug548828.html \
+		test_bug562433.html \
 		test_DOMWindowCreated_chromeonly.html \
 		test_bug581072.html \
 		test_bug583225.html \
 		$(NULL)
 
 libs:: 	$(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/bugs/test_bug562433.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=562433
+-->
+<head>
+  <title>Test for Bug 562433</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=562433">Mozilla Bug 562433</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 562433 **/
+
+var w = window.open("");
+
+// The new window's location.host and location.hostname must be the empty
+// string (instead of throwing an exception)
+
+is(w.location.host, "", 'w.location.host should be ""');
+is(w.location.hostname, "", 'w.location.hostname should be ""');
+
+w.close();
+
+</script>
+</pre>
+</body>
+</html>