Index: sdk/lib/_internal/lib/js_string.dart |
diff --git a/sdk/lib/_internal/lib/js_string.dart b/sdk/lib/_internal/lib/js_string.dart |
index 2da5ed4c17aef3e6feede8366e911a1dc5920efe..be707c0de69e622247e409ef43db1f813350f81d 100644 |
--- a/sdk/lib/_internal/lib/js_string.dart |
+++ b/sdk/lib/_internal/lib/js_string.dart |
@@ -85,15 +85,19 @@ class JSString extends Interceptor implements String, JSIndexable { |
} |
} |
- bool startsWith(Pattern pattern) { |
+ bool startsWith(Pattern pattern, [int index = 0]) { |
+ if (index < 0 || index > this.length) { |
+ throw new RangeError.range(index, 0, this.length); |
+ } |
if (pattern is String) { |
String other = pattern; |
int otherLength = other.length; |
- if (otherLength > length) return false; |
+ int endIndex = index + otherLength; |
+ if (endIndex > length) return false; |
return JS('bool', r'# == #', other, |
- JS('String', r'#.substring(0, #)', this, otherLength)); |
+ JS('String', r'#.substring(#, #)', this, index, endIndex)); |
} |
- return pattern.matchAsPrefix(this, 0) != null; |
+ return pattern.matchAsPrefix(this, index) != null; |
} |
String substring(int startIndex, [int endIndex]) { |