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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 1181003005: Use ArgumentError.value in more places in js_lib. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library _js_helper; 5 library _js_helper;
6 6
7 import 'dart:_async_await_error_codes' as async_error_codes; 7 import 'dart:_async_await_error_codes' as async_error_codes;
8 8
9 import 'dart:_js_embedded_names' show 9 import 'dart:_js_embedded_names' show
10 DEFERRED_LIBRARY_URIS, 10 DEFERRED_LIBRARY_URIS,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return JS('String', r'"" + (#)', value); 203 return JS('String', r'"" + (#)', value);
204 } 204 }
205 } else if (true == value) { 205 } else if (true == value) {
206 return 'true'; 206 return 'true';
207 } else if (false == value) { 207 } else if (false == value) {
208 return 'false'; 208 return 'false';
209 } else if (value == null) { 209 } else if (value == null) {
210 return 'null'; 210 return 'null';
211 } 211 }
212 var res = value.toString(); 212 var res = value.toString();
213 if (res is !String) throw _argumentError(value); 213 if (res is !String) throw argumentErrorValue(value);
214 return res; 214 return res;
215 } 215 }
216 216
217 createInvocationMirror(String name, internalName, kind, arguments, 217 createInvocationMirror(String name, internalName, kind, arguments,
218 argumentNames) { 218 argumentNames) {
219 return new JSInvocationMirror(name, 219 return new JSInvocationMirror(name,
220 internalName, 220 internalName,
221 kind, 221 kind,
222 arguments, 222 arguments,
223 argumentNames); 223 argumentNames);
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 result = JS('String', 874 result = JS('String',
875 r'# + String.fromCharCode.apply(null, #.slice(#, #))', 875 r'# + String.fromCharCode.apply(null, #.slice(#, #))',
876 result, array, i, chunkEnd); 876 result, array, i, chunkEnd);
877 } 877 }
878 return result; 878 return result;
879 } 879 }
880 880
881 static String stringFromCodePoints(codePoints) { 881 static String stringFromCodePoints(codePoints) {
882 List<int> a = <int>[]; 882 List<int> a = <int>[];
883 for (var i in codePoints) { 883 for (var i in codePoints) {
884 if (i is !int) throw _argumentError(i); 884 if (i is !int) throw argumentErrorValue(i);
885 if (i <= 0xffff) { 885 if (i <= 0xffff) {
886 a.add(i); 886 a.add(i);
887 } else if (i <= 0x10ffff) { 887 } else if (i <= 0x10ffff) {
888 a.add(0xd800 + ((((i - 0x10000) >> 10) & 0x3ff))); 888 a.add(0xd800 + ((((i - 0x10000) >> 10) & 0x3ff)));
889 a.add(0xdc00 + (i & 0x3ff)); 889 a.add(0xdc00 + (i & 0x3ff));
890 } else { 890 } else {
891 throw _argumentError(i); 891 throw argumentErrorValue(i);
892 } 892 }
893 } 893 }
894 return _fromCharCodeApply(a); 894 return _fromCharCodeApply(a);
895 } 895 }
896 896
897 static String stringFromCharCodes(charCodes) { 897 static String stringFromCharCodes(charCodes) {
898 for (var i in charCodes) { 898 for (var i in charCodes) {
899 if (i is !int) throw _argumentError(i); 899 if (i is !int) throw argumentErrorValue(i);
900 if (i < 0) throw _argumentError(i); 900 if (i < 0) throw argumentErrorValue(i);
901 if (i > 0xffff) return stringFromCodePoints(charCodes); 901 if (i > 0xffff) return stringFromCodePoints(charCodes);
902 } 902 }
903 return _fromCharCodeApply(charCodes); 903 return _fromCharCodeApply(charCodes);
904 } 904 }
905 905
906 // [start] and [end] are validated. 906 // [start] and [end] are validated.
907 static String stringFromNativeUint8List( 907 static String stringFromNativeUint8List(
908 NativeUint8List charCodes, int start, int end) { 908 NativeUint8List charCodes, int start, int end) {
909 const kMaxApply = 500; 909 const kMaxApply = 500;
910 if (end <= kMaxApply && start == 0 && end == charCodes.length) { 910 if (end <= kMaxApply && start == 0 && end == charCodes.length) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 1079
1080 static getWeekday(receiver) { 1080 static getWeekday(receiver) {
1081 int weekday = (receiver.isUtc) 1081 int weekday = (receiver.isUtc)
1082 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver)) 1082 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver))
1083 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver)); 1083 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver));
1084 // Adjust by one because JS weeks start on Sunday. 1084 // Adjust by one because JS weeks start on Sunday.
1085 return (weekday + 6) % 7 + 1; 1085 return (weekday + 6) % 7 + 1;
1086 } 1086 }
1087 1087
1088 static valueFromDateString(str) { 1088 static valueFromDateString(str) {
1089 if (str is !String) throw _argumentError(str); 1089 if (str is !String) throw argumentErrorValue(str);
1090 var value = JS('num', r'Date.parse(#)', str); 1090 var value = JS('num', r'Date.parse(#)', str);
1091 if (value.isNaN) throw _argumentError(str); 1091 if (value.isNaN) throw argumentErrorValue(str);
1092 return value; 1092 return value;
1093 } 1093 }
1094 1094
1095 static getProperty(object, key) { 1095 static getProperty(object, key) {
1096 if (object == null || object is bool || object is num || object is String) { 1096 if (object == null || object is bool || object is num || object is String) {
1097 throw _argumentError(object); 1097 throw argumentErrorValue(object);
1098 } 1098 }
1099 return JS('var', '#[#]', object, key); 1099 return JS('var', '#[#]', object, key);
1100 } 1100 }
1101 1101
1102 static void setProperty(object, key, value) { 1102 static void setProperty(object, key, value) {
1103 if (object == null || object is bool || object is num || object is String) { 1103 if (object == null || object is bool || object is num || object is String) {
1104 throw _argumentError(object); 1104 throw argumentErrorValue(object);
1105 } 1105 }
1106 JS('void', '#[#] = #', object, key, value); 1106 JS('void', '#[#] = #', object, key, value);
1107 } 1107 }
1108 1108
1109 static functionNoSuchMethod(function, 1109 static functionNoSuchMethod(function,
1110 List positionalArguments, 1110 List positionalArguments,
1111 Map<String, dynamic> namedArguments) { 1111 Map<String, dynamic> namedArguments) {
1112 int argumentCount = 0; 1112 int argumentCount = 0;
1113 List arguments = []; 1113 List arguments = [];
1114 List namedArgumentList = []; 1114 List namedArgumentList = [];
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 } 1383 }
1384 } 1384 }
1385 1385
1386 /** 1386 /**
1387 * Called by generated code to throw an illegal-argument exception, 1387 * Called by generated code to throw an illegal-argument exception,
1388 * for example, if a non-integer index is given to an optimized 1388 * for example, if a non-integer index is given to an optimized
1389 * indexed access. 1389 * indexed access.
1390 */ 1390 */
1391 @NoInline() 1391 @NoInline()
1392 iae(argument) { 1392 iae(argument) {
1393 throw _argumentError(argument); 1393 throw argumentErrorValue(argument);
1394 } 1394 }
1395 1395
1396 /** 1396 /**
1397 * Called by generated code to throw an index-out-of-range exception, for 1397 * Called by generated code to throw an index-out-of-range exception, for
1398 * example, if a bounds check fails in an optimized indexed access. This may 1398 * example, if a bounds check fails in an optimized indexed access. This may
1399 * also be called when the index is not an integer, in which case it throws an 1399 * also be called when the index is not an integer, in which case it throws an
1400 * illegal-argument exception instead, like [iae], or when the receiver is null. 1400 * illegal-argument exception instead, like [iae], or when the receiver is null.
1401 */ 1401 */
1402 @NoInline() 1402 @NoInline()
1403 ioore(receiver, index) { 1403 ioore(receiver, index) {
(...skipping 18 matching lines...) Expand all
1422 return new RangeError.value(index, 'index'); 1422 return new RangeError.value(index, 'index');
1423 } 1423 }
1424 1424
1425 1425
1426 stringLastIndexOfUnchecked(receiver, element, start) 1426 stringLastIndexOfUnchecked(receiver, element, start)
1427 => JS('int', r'#.lastIndexOf(#, #)', receiver, element, start); 1427 => JS('int', r'#.lastIndexOf(#, #)', receiver, element, start);
1428 1428
1429 1429
1430 /// 'factory' for constructing ArgumentError.value to keep the call sites small. 1430 /// 'factory' for constructing ArgumentError.value to keep the call sites small.
1431 @NoInline() 1431 @NoInline()
1432 ArgumentError _argumentError(object) { 1432 ArgumentError argumentErrorValue(object) {
1433 return new ArgumentError.value(object); 1433 return new ArgumentError.value(object);
1434 } 1434 }
1435 1435
1436 checkNull(object) { 1436 checkNull(object) {
1437 if (object == null) throw _argumentError(object); 1437 if (object == null) throw argumentErrorValue(object);
1438 return object; 1438 return object;
1439 } 1439 }
1440 1440
1441 checkNum(value) { 1441 checkNum(value) {
1442 if (value is !num) throw _argumentError(value); 1442 if (value is !num) throw argumentErrorValue(value);
1443 return value; 1443 return value;
1444 } 1444 }
1445 1445
1446 checkInt(value) { 1446 checkInt(value) {
1447 if (value is !int) throw _argumentError(value); 1447 if (value is !int) throw argumentErrorValue(value);
1448 return value; 1448 return value;
1449 } 1449 }
1450 1450
1451 checkBool(value) { 1451 checkBool(value) {
1452 if (value is !bool) throw _argumentError(value); 1452 if (value is !bool) throw argumentErrorValue(value);
1453 return value; 1453 return value;
1454 } 1454 }
1455 1455
1456 checkString(value) { 1456 checkString(value) {
1457 if (value is !String) throw _argumentError(value); 1457 if (value is !String) throw argumentErrorValue(value);
1458 return value; 1458 return value;
1459 } 1459 }
1460 1460
1461 /** 1461 /**
1462 * Wrap the given Dart object and record a stack trace. 1462 * Wrap the given Dart object and record a stack trace.
1463 * 1463 *
1464 * The code in [unwrapException] deals with getting the original Dart 1464 * The code in [unwrapException] deals with getting the original Dart
1465 * object out of the wrapper again. 1465 * object out of the wrapper again.
1466 */ 1466 */
1467 @NoInline() 1467 @NoInline()
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after
4129 // This is a function that will return a helper function that does the 4129 // This is a function that will return a helper function that does the
4130 // iteration of the sync*. 4130 // iteration of the sync*.
4131 // 4131 //
4132 // Each invocation should give a body with fresh state. 4132 // Each invocation should give a body with fresh state.
4133 final dynamic /* js function */ _outerHelper; 4133 final dynamic /* js function */ _outerHelper;
4134 4134
4135 SyncStarIterable(this._outerHelper); 4135 SyncStarIterable(this._outerHelper);
4136 4136
4137 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); 4137 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper));
4138 } 4138 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_array.dart ('k') | sdk/lib/_internal/compiler/js_lib/js_number.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698