Bug 927735 - TypeError check for URL API. r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 18 Oct 2013 10:17:03 -0400
changeset 166114 9475a31892560d0afd2b9b7e4c8d310dfe364344
parent 166113 48d6dad2df1630c9ca59755f5948024c6d2e2aec
child 166115 2c07714a7a821531dfbd8b4dccadaff45ef3830c
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs927735
milestone27.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 927735 - TypeError check for URL API. r=ehsan
dom/base/URL.cpp
dom/base/test/test_urlExceptions.html
dom/bindings/Errors.msg
--- a/dom/base/URL.cpp
+++ b/dom/base/URL.cpp
@@ -41,17 +41,18 @@ URL::Constructor(const GlobalObject& aGl
     aRv.Throw(rv);
     return nullptr;
   }
 
   nsCOMPtr<nsIURI> uri;
   rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aUrl), nullptr, aBase.GetURI(),
                          getter_AddRefs(uri));
   if (NS_FAILED(rv)) {
-    aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+    nsAutoString label(aUrl);
+    aRv.ThrowTypeError(MSG_INVALID_URL, &label);
     return nullptr;
   }
 
   nsRefPtr<URL> url = new URL(uri);
   return url.forget();
 }
 
 /* static */ already_AddRefed<URL>
@@ -64,25 +65,27 @@ URL::Constructor(const GlobalObject& aGl
     aRv.Throw(rv);
     return nullptr;
   }
 
   nsCOMPtr<nsIURI> baseUri;
   rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aBase), nullptr, nullptr,
                          getter_AddRefs(baseUri));
   if (NS_FAILED(rv)) {
-    aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+    nsAutoString label(aBase);
+    aRv.ThrowTypeError(MSG_INVALID_URL, &label);
     return nullptr;
   }
 
   nsCOMPtr<nsIURI> uri;
   rv = ioService->NewURI(NS_ConvertUTF16toUTF8(aUrl), nullptr, baseUri,
                          getter_AddRefs(uri));
   if (NS_FAILED(rv)) {
-    aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+    nsAutoString label(aUrl);
+    aRv.ThrowTypeError(MSG_INVALID_URL, &label);
     return nullptr;
   }
 
   nsRefPtr<URL> url = new URL(uri);
   return url.forget();
 }
 
 void
@@ -198,17 +201,18 @@ URL::SetHref(const nsAString& aHref, Err
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
 
   nsCOMPtr<nsIURI> uri;
   rv = ioService->NewURI(href, nullptr, nullptr, getter_AddRefs(uri));
   if (NS_FAILED(rv)) {
-    aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
+    nsAutoString label(aHref);
+    aRv.ThrowTypeError(MSG_INVALID_URL, &label);
     return;
   }
 
   aRv = mURI->SetSpec(href);
 }
 
 void
 URL::GetOrigin(nsString& aOrigin) const
--- a/dom/base/test/test_urlExceptions.html
+++ b/dom/base/test/test_urlExceptions.html
@@ -19,39 +19,39 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 </pre>
   <script type="application/javascript">
 
   // URL.href throws
   var url = new URL('http://www.example.com');
   ok(url, "URL created");
 
-  var status = false;
   try {
     url.href = '42';
+    ok(false, "url.href = 42 should throw");
   } catch(e) {
-    status = true;
+    ok(true, "url.href = 42 should throw");
+    ok(e instanceof TypeError, "error type typeError");
   }
-  ok(status, "url.href = 42 should throw");
 
   url.href = 'http://www.example.org';
   ok(true, "url.href should not throw");
 
-  status = false
   try {
     new URL('42');
+    ok(false, "new URL(42) should throw");
   } catch(e) {
-    status = true;
+    ok(true, "new URL(42) should throw");
+    ok(e instanceof TypeError, "error type typeError");
   }
-  ok(status, "new URL(42) should throw");
 
-  status = false
   try {
     new URL('http://www.example.com', '42');
+    ok(false, "new URL(something, 42) should throw");
   } catch(e) {
-    status = true;
+    ok(true, "new URL(something, 42) should throw");
+    ok(e instanceof TypeError, "error type typeError");
   }
-  ok(status, "new URL(something, 42) should throw");
 
   </script>
 </body>
 </html>
 
--- a/dom/bindings/Errors.msg
+++ b/dom/bindings/Errors.msg
@@ -42,8 +42,9 @@ MSG_DEF(MSG_ENCODING_NOT_SUPPORTED, 1, "
 MSG_DEF(MSG_DOM_ENCODING_NOT_UTF, 0, "The encoding must be utf-8, utf-16, or utf-16be.")
 MSG_DEF(MSG_NOT_FINITE, 1, "{0} is not a finite floating-point value.")
 MSG_DEF(MSG_INVALID_VERSION, 0, "0 (Zero) is not a valid database version.")
 MSG_DEF(MSG_INVALID_BYTESTRING, 2, "Cannot convert string to ByteString because the character"
         " at index {0} has value {1} which is greater than 255.")
 MSG_DEF(MSG_NOT_DATE, 1, "{0} is not a date.")
 MSG_DEF(MSG_INVALID_ADVANCE_COUNT, 0, "0 (Zero) is not a valid advance count.")
 MSG_DEF(MSG_DEFINEPROPERTY_ON_GSP, 0, "Not allowed to define a property on the named properties object.")
+MSG_DEF(MSG_INVALID_URL, 1, "{0} is not a valid URL.")