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

Side by Side Diff: tool/input_sdk/patch/core_patch.dart

Issue 1952223006: Update String.fromCharCodes from sdk (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « tool/input_sdk/lib/core/core.dart ('k') | tool/input_sdk/patch/internal_patch.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 // Patch file for dart:core classes. 5 // Patch file for dart:core classes.
6 import "dart:_internal" as _symbol_dev; 6 import "dart:_internal" as _symbol_dev;
7 import 'dart:_interceptors'; 7 import 'dart:_interceptors';
8 import 'dart:_js_helper' show patch, 8 import 'dart:_js_helper' show patch,
9 checkInt, 9 checkInt,
10 getRuntimeType, 10 getRuntimeType,
11 jsonEncodeNative, 11 jsonEncodeNative,
12 JSSyntaxRegExp, 12 JSSyntaxRegExp,
13 Primitives, 13 Primitives,
14 stringJoinUnchecked, 14 stringJoinUnchecked,
15 objectHashCode, 15 objectHashCode,
16 getTraceFromException; 16 getTraceFromException;
17 17
18 import 'dart:_foreign_helper' show JS; 18 import 'dart:_foreign_helper' show JS;
19 19
20 import 'dart:_native_typed_data' show NativeUint8List;
21
20 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 22 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
21 23
22 @patch 24 @patch
23 int identityHashCode(Object object) => objectHashCode(object); 25 int identityHashCode(Object object) => objectHashCode(object);
24 26
25 // Patch for Object implementation. 27 // Patch for Object implementation.
26 @patch 28 @patch
27 class Object { 29 class Object {
28 @patch 30 @patch
29 int get hashCode => Primitives.objectHashCode(this); 31 int get hashCode => Primitives.objectHashCode(this);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 factory Map.unmodifiable(Map other) { 282 factory Map.unmodifiable(Map other) {
281 return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other)); 283 return new UnmodifiableMapView<K, V>(new Map<K, V>.from(other));
282 } 284 }
283 } 285 }
284 286
285 @patch 287 @patch
286 class String { 288 class String {
287 @patch 289 @patch
288 factory String.fromCharCodes(Iterable<int> charCodes, 290 factory String.fromCharCodes(Iterable<int> charCodes,
289 [int start = 0, int end]) { 291 [int start = 0, int end]) {
290 // If possible, recognize typed lists too. 292 if (charCodes is JSArray) {
291 if (charCodes is! JSArray) { 293 return _stringFromJSArray(charCodes, start, end);
292 return _stringFromIterable(charCodes, start, end);
293 } 294 }
294 295 if (charCodes is NativeUint8List) {
295 List list = charCodes; 296 return _stringFromUint8List(charCodes, start, end);
296 int len = list.length;
297 if (start < 0 || start > len) {
298 throw new RangeError.range(start, 0, len);
299 } 297 }
300 if (end == null) { 298 return _stringFromIterable(charCodes, start, end);
301 end = len;
302 } else if (end < start || end > len) {
303 throw new RangeError.range(end, start, len);
304 }
305
306 if (start > 0 || end < len) {
307 list = list.sublist(start, end);
308 }
309 return Primitives.stringFromCharCodes(list);
310 } 299 }
311 300
312 @patch 301 @patch
313 factory String.fromCharCode(int charCode) { 302 factory String.fromCharCode(int charCode) {
314 return Primitives.stringFromCharCode(charCode); 303 return Primitives.stringFromCharCode(charCode);
315 } 304 }
316 305
317 @patch 306 @patch
318 factory String.fromEnvironment(String name, {String defaultValue}) { 307 factory String.fromEnvironment(String name, {String defaultValue}) {
319 throw new UnsupportedError( 308 throw new UnsupportedError(
320 'String.fromEnvironment can only be used as a const constructor'); 309 'String.fromEnvironment can only be used as a const constructor');
321 } 310 }
322 311
312 static String _stringFromJSArray(List list, int start, int endOrNull) {
313 int len = list.length;
314 int end = RangeError.checkValidRange(start, endOrNull, len);
315 if (start > 0 || end < len) {
316 list = list.sublist(start, end);
317 }
318 return Primitives.stringFromCharCodes(list);
319 }
320
321 static String _stringFromUint8List(
322 NativeUint8List charCodes, int start, int endOrNull) {
323 int len = charCodes.length;
324 int end = RangeError.checkValidRange(start, endOrNull, len);
325 return Primitives.stringFromNativeUint8List(charCodes, start, end);
326 }
327
323 static String _stringFromIterable(Iterable<int> charCodes, 328 static String _stringFromIterable(Iterable<int> charCodes,
324 int start, int end) { 329 int start, int end) {
325 if (start < 0) throw new RangeError.range(start, 0, charCodes.length); 330 if (start < 0) throw new RangeError.range(start, 0, charCodes.length);
326 if (end != null && end < start) { 331 if (end != null && end < start) {
327 throw new RangeError.range(end, start, charCodes.length); 332 throw new RangeError.range(end, start, charCodes.length);
328 } 333 }
329 var it = charCodes.iterator; 334 var it = charCodes.iterator;
330 for (int i = 0; i < start; i++) { 335 for (int i = 0; i < start; i++) {
331 if (!it.moveNext()) { 336 if (!it.moveNext()) {
332 throw new RangeError.range(start, 0, i); 337 throw new RangeError.range(start, 0, i);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return getTraceFromException(error); 483 return getTraceFromException(error);
479 } 484 }
480 // Fallback if Error.captureStackTrace does not exist. 485 // Fallback if Error.captureStackTrace does not exist.
481 try { 486 try {
482 throw ''; 487 throw '';
483 } catch (_, stackTrace) { 488 } catch (_, stackTrace) {
484 return stackTrace; 489 return stackTrace;
485 } 490 }
486 } 491 }
487 } 492 }
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/core/core.dart ('k') | tool/input_sdk/patch/internal_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698