Bug 1541861 - Improve exception message for CSSStyleSheet.prototype.deleteRule r=emilio
authorBlito <pabloarubi@gmail.com>
Thu, 18 Jul 2019 17:51:39 +0000
changeset 483419 13a4951a9f46ab6b9d06fddcc4140d27094226dc
parent 483418 1c1e27b9d73bf90d0f785198f52b967c7c8fd08d
child 483420 c949fbdda08f81aef75b07a0306dee3f2fe8e747
push id36315
push useropoprus@mozilla.com
push dateFri, 19 Jul 2019 03:55:35 +0000
treeherdermozilla-central@5fff2a9bf078 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1541861
milestone70.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 1541861 - Improve exception message for CSSStyleSheet.prototype.deleteRule r=emilio CSSStyleSheet.prototype.deleteRule can throw an IndexSizeError. This change makes it so that the exception thrown has the max valid index for that function. Differential Revision: https://phabricator.services.mozilla.com/D38519
layout/style/StyleSheet.cpp
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -1187,17 +1187,22 @@ uint32_t StyleSheet::InsertRuleInternal(
 }
 
 void StyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) {
   MOZ_ASSERT(!IsReadOnly());
 
   // Ensure mRuleList is constructed.
   GetCssRulesInternal();
   if (aIndex >= mRuleList->Length()) {
-    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    aRv.ThrowDOMException(
+        NS_ERROR_DOM_INDEX_SIZE_ERR,
+        nsPrintfCString(
+            "Cannot delete rule at index %u"
+            " because the number of rules is only %u",
+            aIndex, mRuleList->Length()));
     return;
   }
 
   // Hold a strong ref to the rule so it doesn't die when we remove it
   // from the list. XXX We may not want to hold it if stylesheet change
   // event is not enabled.
   RefPtr<css::Rule> rule = mRuleList->GetRule(aIndex);
   aRv = mRuleList->DeleteRule(aIndex);