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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 1137233004: Make more use of ArgumentError.value in js_lib. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | « no previous file | tests/corelib/errors_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index 68d1abac46b69d69782236feea8de5042fc71e79..1ee4c66743ebb0855765ca842247a82465212a38 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -194,7 +194,7 @@ String S(value) {
return 'null';
}
var res = value.toString();
- if (res is !String) throw new ArgumentError(value);
+ if (res is !String) throw _argumentError(value);
return res;
}
@@ -690,9 +690,11 @@ class Primitives {
return _parseIntError(source, handleError);
}
- if (radix is! int) throw new ArgumentError("Radix is not an integer");
+ if (radix is! int) {
+ throw new ArgumentError.value(radix, 'radix', 'is not an integer');
+ }
if (radix < 2 || radix > 36) {
- throw new RangeError.range(radix, 2, 36, "radix");
+ throw new RangeError.range(radix, 2, 36, 'radix');
}
if (radix == 10 && decimalMatch != null) {
// Cannot fail because we know that the digits are all decimal.
@@ -737,7 +739,7 @@ class Primitives {
static double _parseDoubleError(String source,
double handleError(String source)) {
if (handleError == null) {
- throw new FormatException("Invalid double", source);
+ throw new FormatException('Invalid double', source);
}
return handleError(source);
}
@@ -860,14 +862,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 _argumentError(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 _argumentError(i);
}
}
return _fromCharCodeApply(a);
@@ -875,8 +877,8 @@ 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 _argumentError(i);
+ if (i < 0) throw _argumentError(i);
if (i > 0xffff) return stringFromCodePoints(charCodes);
}
return _fromCharCodeApply(charCodes);
@@ -1065,22 +1067,22 @@ class Primitives {
}
static valueFromDateString(str) {
- if (str is !String) throw new ArgumentError(str);
+ if (str is !String) throw _argumentError(str);
var value = JS('num', r'Date.parse(#)', str);
- if (value.isNaN) throw new ArgumentError(str);
+ if (value.isNaN) throw _argumentError(str);
return value;
}
static getProperty(object, key) {
if (object == null || object is bool || object is num || object is String) {
- throw new ArgumentError(object);
+ throw _argumentError(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 _argumentError(object);
}
JS('void', '#[#] = #', object, key, value);
}
@@ -1372,7 +1374,7 @@ class JsCache {
* indexed access.
*/
iae(argument) {
- throw new ArgumentError(argument);
+ throw _argumentError(argument);
}
/**
@@ -1392,36 +1394,34 @@ stringLastIndexOfUnchecked(receiver, element, start)
=> JS('int', r'#.lastIndexOf(#, #)', receiver, element, start);
+/// 'factory' for constructing ArgumentError.value to keep the call sites small.
+@NoInline()
+ArgumentError _argumentError(object) {
+ return new ArgumentError.value(object);
+}
+
checkNull(object) {
- if (object == null) throw new ArgumentError(null);
+ if (object == null) throw _argumentError(object);
return object;
}
checkNum(value) {
- if (value is !num) {
- throw new ArgumentError(value);
- }
+ if (value is !num) throw _argumentError(value);
return value;
}
checkInt(value) {
- if (value is !int) {
- throw new ArgumentError(value);
- }
+ if (value is !int) throw _argumentError(value);
return value;
}
checkBool(value) {
- if (value is !bool) {
- throw new ArgumentError(value);
- }
+ if (value is !bool) throw _argumentError(value);
return value;
}
checkString(value) {
- if (value is !String) {
- throw new ArgumentError(value);
- }
+ if (value is !String) throw _argumentError(value);
return value;
}
« no previous file with comments | « no previous file | tests/corelib/errors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698