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

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 4e1bc4cbe5c79386812570fbbe2618f7ca552b72..fd68d4d73c62baa8afd8fdd35597425cee158585 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);
}
@@ -872,14 +874,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);
@@ -887,8 +889,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);
@@ -1077,22 +1079,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);
}
@@ -1384,7 +1386,7 @@ class JsCache {
* indexed access.
*/
iae(argument) {
- throw new ArgumentError(argument);
+ throw _ArgumentError(argument);
}
/**
@@ -1404,36 +1406,34 @@ stringLastIndexOfUnchecked(receiver, element, start)
=> JS('int', r'#.lastIndexOf(#, #)', receiver, element, start);
+/// 'factory' for constructing ArgumentError.value.
+@NoInline()
+ArgumentError _ArgumentError(object) {
floitsch 2015/05/13 05:11:29 it's a function. -> lower case. (even if it's to
sra1 2015/05/13 22:17:48 Done.
+ 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