Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2118)

Unified Diff: tool/input_sdk/private/js_helper.dart

Issue 1947723002: Update core/errors.dart (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tool/input_sdk/lib/core/errors.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/private/js_helper.dart
diff --git a/tool/input_sdk/private/js_helper.dart b/tool/input_sdk/private/js_helper.dart
index 7ac7fb46ad1215b3dd2d989b8420fe72a3b187d4..fb930ac1701b40e3e1fbd04d9a96607a4017ad0e 100644
--- a/tool/input_sdk/private/js_helper.dart
+++ b/tool/input_sdk/private/js_helper.dart
@@ -243,14 +243,14 @@ class Primitives {
static String stringFromCodePoints(codePoints) {
List<int> a = <int>[];
for (var i in codePoints) {
- if (i is !int) throw new ArgumentError(i);
+ if (i is !int) throw argumentErrorValue(i);
if (i <= 0xffff) {
a.add(i);
} else if (i <= 0x10ffff) {
a.add(0xd800 + ((((i - 0x10000) >> 10) & 0x3ff)));
a.add(0xdc00 + (i & 0x3ff));
} else {
- throw new ArgumentError(i);
+ throw argumentErrorValue(i);
}
}
return _fromCharCodeApply(a);
@@ -258,14 +258,14 @@ class Primitives {
static String stringFromCharCodes(charCodes) {
for (var i in charCodes) {
- if (i is !int) throw new ArgumentError(i);
- if (i < 0) throw new ArgumentError(i);
+ if (i is !int) throw argumentErrorValue(i);
+ if (i < 0) throw argumentErrorValue(i);
if (i > 0xffff) return stringFromCodePoints(charCodes);
}
return _fromCharCodeApply(charCodes);
}
- static String stringFromCharCode(charCode) {
+ static String stringFromCharCode(int charCode) {
if (0 <= charCode) {
if (charCode <= 0xffff) {
return JS('String', 'String.fromCharCode(#)', charCode);
@@ -430,22 +430,22 @@ class Primitives {
}
static valueFromDateString(str) {
- if (str is !String) throw new ArgumentError(str);
+ if (str is !String) throw argumentErrorValue(str);
var value = JS('num', r'Date.parse(#)', str);
- if (value.isNaN) throw new ArgumentError(str);
+ if (value.isNaN) throw argumentErrorValue(str);
return value;
}
static getProperty(object, key) {
if (object == null || object is bool || object is num || object is String) {
- throw new ArgumentError(object);
+ throw argumentErrorValue(object);
}
return JS('var', '#[#]', object, key);
}
static void setProperty(object, key, value) {
if (object == null || object is bool || object is num || object is String) {
- throw new ArgumentError(object);
+ throw argumentErrorValue(object);
}
JS('void', '#[#] = #', object, key, value);
}
@@ -460,41 +460,79 @@ class Primitives {
return getTraceFromException(JS('', r'#.$thrownJsError', error));
}
}
+/**
+ * Diagnoses an indexing error. Returns the ArgumentError or RangeError that
+ * describes the problem.
+ */
+@NoInline()
+Error diagnoseIndexError(indexable, index) {
+ if (index is !int) return new ArgumentError.value(index, 'index');
+ int length = indexable.length;
+ // The following returns the same error that would be thrown by calling
+ // [RangeError.checkValidIndex] with no optional parameters provided.
+ if (index < 0 || index >= length) {
+ return new RangeError.index(index, indexable, 'index', null, length);
+ }
+ // The above should always match, but if it does not, use the following.
+ return new RangeError.value(index, 'index');
+}
+
+/**
+ * Diagnoses a range error. Returns the ArgumentError or RangeError that
+ * describes the problem.
+ */
+@NoInline()
+Error diagnoseRangeError(start, end, length) {
+ if (start is! int) {
+ return new ArgumentError.value(start, 'start');
+ }
+ if (start < 0 || start > length) {
+ return new RangeError.range(start, 0, length, 'start');
+ }
+ if (end != null) {
+ if (end is! int) {
+ return new ArgumentError.value(end, 'end');
+ }
+ if (end < start || end > length) {
+ return new RangeError.range(end, start, length, 'end');
+ }
+ }
+ // The above should always match, but if it does not, use the following.
+ return new ArgumentError.value(end, "end");
+}
stringLastIndexOfUnchecked(receiver, element, start)
=> JS('int', r'#.lastIndexOf(#, #)', receiver, element, start);
+/// 'factory' for constructing ArgumentError.value to keep the call sites small.
+@NoInline()
+ArgumentError argumentErrorValue(object) {
+ return new ArgumentError.value(object);
+}
+
checkNull(object) {
- if (object == null) throw new ArgumentError(null);
+ if (object == null) throw argumentErrorValue(object);
return object;
}
checkNum(value) {
- if (value is !num) {
- throw new ArgumentError(value);
- }
+ if (value is !num) throw argumentErrorValue(value);
return value;
}
checkInt(value) {
- if (value is !int) {
- throw new ArgumentError(value);
- }
+ if (value is !int) throw argumentErrorValue(value);
return value;
}
checkBool(value) {
- if (value is !bool) {
- throw new ArgumentError(value);
- }
+ if (value is !bool) throw argumentErrorValue(value);
return value;
}
checkString(value) {
- if (value is !String) {
- throw new ArgumentError(value);
- }
+ if (value is !String) throw argumentErrorValue(value);
return value;
}
« no previous file with comments | « tool/input_sdk/lib/core/errors.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698