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

Side by Side Diff: tool/input_sdk/private/js_string.dart

Issue 1348453004: fix some errors in our SDK, mostly around numbers (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « tool/input_sdk/private/js_number.dart ('k') | tool/input_sdk/private/native_typed_data.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart._interceptors; 5 part of dart._interceptors;
6 6
7 /** 7 /**
8 * The interceptor class for [String]. The compiler recognizes this 8 * The interceptor class for [String]. The compiler recognizes this
9 * class as an interceptor, and changes references to [:this:] to 9 * class as an interceptor, and changes references to [:this:] to
10 * actually use the receiver of the method, which is generated as an extra 10 * actually use the receiver of the method, which is generated as an extra
11 * argument added to each member. 11 * argument added to each member.
12 */ 12 */
13 @JsPeerInterface(name: 'String') 13 @JsPeerInterface(name: 'String')
14 class JSString extends Interceptor implements String, JSIndexable { 14 class JSString extends Interceptor implements String, JSIndexable {
15 const JSString(); 15 const JSString();
16 16
17 int codeUnitAt(int index) { 17 int codeUnitAt(int index) {
18 if (index is !int) throw new ArgumentError(index); 18 if (index is !int) throw new ArgumentError(index);
19 if (index < 0) throw new RangeError.value(index); 19 if (index < 0) throw new RangeError.value(index);
20 if (index >= length) throw new RangeError.value(index); 20 if (index >= length) throw new RangeError.value(index);
21 return JS('JSUInt31', r'#.charCodeAt(#)', this, index); 21 return JS('int', r'#.charCodeAt(#)', this, index);
22 } 22 }
23 23
24 Iterable<Match> allMatches(String string, [int start = 0]) { 24 Iterable<Match> allMatches(String string, [int start = 0]) {
25 checkString(string); 25 checkString(string);
26 checkInt(start); 26 checkInt(start);
27 if (0 > start || start > string.length) { 27 if (0 > start || start > string.length) {
28 throw new RangeError.range(start, 0, string.length); 28 throw new RangeError.range(start, 0, string.length);
29 } 29 }
30 return allMatchesInStringUnchecked(this, string, start); 30 return allMatchesInStringUnchecked(this, string, start);
31 } 31 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 326 }
327 327
328 if (endIndex == result.length) return result; 328 if (endIndex == result.length) return result;
329 if (endIndex == 0) return ""; 329 if (endIndex == 0) return "";
330 return JS('String', r'#.substring(#, #)', result, 0, endIndex); 330 return JS('String', r'#.substring(#, #)', result, 0, endIndex);
331 } 331 }
332 332
333 String operator*(int times) { 333 String operator*(int times) {
334 if (0 >= times) return ''; // Unnecessary but hoists argument type check. 334 if (0 >= times) return ''; // Unnecessary but hoists argument type check.
335 if (times == 1 || this.length == 0) return this; 335 if (times == 1 || this.length == 0) return this;
336 if (times != JS('JSUInt32', '# >>> 0', times)) { 336 if (times != JS('int', '# >>> 0', times)) {
337 // times >= 2^32. We can't create a string that big. 337 // times >= 2^32. We can't create a string that big.
338 throw const OutOfMemoryError(); 338 throw const OutOfMemoryError();
339 } 339 }
340 var result = ''; 340 var result = '';
341 var s = this; 341 String s = this;
342 while (true) { 342 while (true) {
343 if (times & 1 == 1) result = s + result; 343 if (times & 1 == 1) result = s + result;
344 times = JS('JSUInt31', '# >>> 1', times); 344 times = JS('int', '# >>> 1', times);
345 if (times == 0) break; 345 if (times == 0) break;
346 s += s; 346 s += s;
347 } 347 }
348 return result; 348 return result;
349 } 349 }
350 350
351 String padLeft(int width, [String padding = ' ']) { 351 String padLeft(int width, [String padding = ' ']) {
352 int delta = width - this.length; 352 int delta = width - this.length;
353 if (delta <= 0) return this; 353 if (delta <= 0) return this;
354 return padding * delta + this; 354 return padding * delta + this;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 */ 463 */
464 class _CodeUnits extends UnmodifiableListBase<int> { 464 class _CodeUnits extends UnmodifiableListBase<int> {
465 /** The string that this is the code units of. */ 465 /** The string that this is the code units of. */
466 String _string; 466 String _string;
467 467
468 _CodeUnits(this._string); 468 _CodeUnits(this._string);
469 469
470 int get length => _string.length; 470 int get length => _string.length;
471 int operator[](int i) => _string.codeUnitAt(i); 471 int operator[](int i) => _string.codeUnitAt(i);
472 } 472 }
OLDNEW
« no previous file with comments | « tool/input_sdk/private/js_number.dart ('k') | tool/input_sdk/private/native_typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698