Fix error message for deleteRule()

Previous to this CL, deleteRule on an empty style sheet would throw a
confusingly-worded IndexSizeError. Now, it properly throws a RangeError.

For example:

const styleEl = document.createElement('style');
document.head.appendChild(styleEl);
styleEl.sheet.deleteRule(0);
--> Uncaught RangeError: Failed to execute 'deleteRule' on 'CSSStyleSheet': The index provided (0) is outside the range [0, 0).

Bug: 949523
Change-Id: I306409f53be88f4bead261dd171466fd3aad5565
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1561410
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650697}
diff --git a/third_party/blink/renderer/core/css/css_style_sheet.cc b/third_party/blink/renderer/core/css/css_style_sheet.cc
index e011bff..1734eda 100644
--- a/third_party/blink/renderer/core/css/css_style_sheet.cc
+++ b/third_party/blink/renderer/core/css/css_style_sheet.cc
@@ -42,6 +42,7 @@
 #include "third_party/blink/renderer/core/html_names.h"
 #include "third_party/blink/renderer/core/probe/core_probes.h"
 #include "third_party/blink/renderer/core/svg/svg_style_element.h"
+#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
 #include "third_party/blink/renderer/platform/bindings/script_state.h"
 #include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
@@ -413,11 +414,10 @@
          child_rule_cssom_wrappers_.size() == contents_->RuleCount());
 
   if (index >= length()) {
-    exception_state.ThrowDOMException(
-        DOMExceptionCode::kIndexSizeError,
-        "The index provided (" + String::Number(index) +
-            ") is larger than the maximum index (" +
-            String::Number(length() - 1) + ").");
+    exception_state.ThrowRangeError(
+        ExceptionMessages::IndexOutsideRange<unsigned>(
+            "index", index, 0, ExceptionMessages::kInclusiveBound, length(),
+            ExceptionMessages::kExclusiveBound));
     return;
   }
   RuleMutationScope mutation_scope(this);
diff --git a/third_party/blink/web_tests/external/wpt/css/cssom/stylesheet-deleterule-error.html b/third_party/blink/web_tests/external/wpt/css/cssom/stylesheet-deleterule-error.html
new file mode 100644
index 0000000..e01aa01
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/css/cssom/stylesheet-deleterule-error.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSSStyleSheet.prototype.deleteRule error message</title>
+<link rel="author" title="Mason Freed" href="mailto:masonfreed@chromium.org">
+<link rel="help" href="https://heycam.github.io/webidl/#indexsizeerror">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+test(function () {
+    const styleEl = document.createElement('style');
+    document.head.appendChild(styleEl);
+    try {
+        styleEl.sheet.deleteRule(0);
+        assert_fail("deleteRule on an empty style sheet should throw a RangeError");
+    } catch (e) {
+        assert_equals(e.name,"RangeError");
+        assert_true(e instanceof RangeError);
+    }
+}, 'deleteRule should throw RangeError');
+</script>