| OLD | NEW |
| 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' |
| 9 checkInt, | 9 show |
| 10 getRuntimeType, | 10 patch, |
| 11 jsonEncodeNative, | 11 checkInt, |
| 12 JsLinkedHashMap, | 12 getRuntimeType, |
| 13 JSSyntaxRegExp, | 13 jsonEncodeNative, |
| 14 Primitives, | 14 JsLinkedHashMap, |
| 15 stringJoinUnchecked, | 15 JSSyntaxRegExp, |
| 16 objectHashCode, | 16 Primitives, |
| 17 getTraceFromException; | 17 stringJoinUnchecked, |
| 18 objectHashCode, |
| 19 getTraceFromException; |
| 18 | 20 |
| 19 import 'dart:_foreign_helper' show JS; | 21 import 'dart:_foreign_helper' show JS; |
| 20 | 22 |
| 21 import 'dart:_native_typed_data' show NativeUint8List; | 23 import 'dart:_native_typed_data' show NativeUint8List; |
| 22 | 24 |
| 23 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 25 String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
| 24 | 26 |
| 25 @patch | 27 @patch |
| 26 int identityHashCode(Object object) => objectHashCode(object); | 28 int identityHashCode(Object object) => objectHashCode(object); |
| 27 | 29 |
| 28 // Patch for Object implementation. | 30 // Patch for Object implementation. |
| 29 @patch | 31 @patch |
| 30 class Object { | 32 class Object { |
| 31 @patch | 33 @patch |
| 32 bool operator==(other) => identical(this, other); | 34 bool operator ==(other) => identical(this, other); |
| 33 | 35 |
| 34 @patch | 36 @patch |
| 35 int get hashCode => Primitives.objectHashCode(this); | 37 int get hashCode => Primitives.objectHashCode(this); |
| 36 | 38 |
| 37 @patch | 39 @patch |
| 38 String toString() => Primitives.objectToString(this); | 40 String toString() => Primitives.objectToString(this); |
| 39 | 41 |
| 40 @patch | 42 @patch |
| 41 dynamic noSuchMethod(Invocation invocation) { | 43 dynamic noSuchMethod(Invocation invocation) { |
| 42 throw new NoSuchMethodError( | 44 throw new NoSuchMethodError(this, invocation.memberName, |
| 43 this, | 45 invocation.positionalArguments, invocation.namedArguments); |
| 44 invocation.memberName, | |
| 45 invocation.positionalArguments, | |
| 46 invocation.namedArguments); | |
| 47 } | 46 } |
| 48 | 47 |
| 49 @patch | 48 @patch |
| 50 Type get runtimeType => | 49 Type get runtimeType => |
| 51 JS('Type', 'dart.wrapType(dart.getReifiedType(#))', this); | 50 JS('Type', 'dart.wrapType(dart.getReifiedType(#))', this); |
| 52 } | 51 } |
| 53 | 52 |
| 54 @patch | 53 @patch |
| 55 class Null { | 54 class Null { |
| 56 @patch | 55 @patch |
| 57 int get hashCode => super.hashCode; | 56 int get hashCode => super.hashCode; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // Patch for Function implementation. | 59 // Patch for Function implementation. |
| 61 @patch | 60 @patch |
| 62 class Function { | 61 class Function { |
| 63 @patch | 62 @patch |
| 64 static apply(Function f, | 63 static apply(Function f, List positionalArguments, |
| 65 List positionalArguments, | 64 [Map<Symbol, dynamic> namedArguments]) { |
| 66 [Map<Symbol, dynamic> namedArguments]) { | |
| 67 positionalArguments ??= []; | 65 positionalArguments ??= []; |
| 68 // dcall expects the namedArguments as a JS map in the last slot. | 66 // dcall expects the namedArguments as a JS map in the last slot. |
| 69 if (namedArguments != null && namedArguments.isNotEmpty) { | 67 if (namedArguments != null && namedArguments.isNotEmpty) { |
| 70 var map = JS('', '{}'); | 68 var map = JS('', '{}'); |
| 71 namedArguments.forEach((symbol, arg) { | 69 namedArguments.forEach((symbol, arg) { |
| 72 JS('', '#[#] = #', map, _symbolToString(symbol), arg); | 70 JS('', '#[#] = #', map, _symbolToString(symbol), arg); |
| 73 }); | 71 }); |
| 74 positionalArguments = new List.from(positionalArguments)..add(map); | 72 positionalArguments = new List.from(positionalArguments)..add(map); |
| 75 } | 73 } |
| 76 return JS('', 'dart.dcall.apply(null, [#].concat(#))', f, positionalArgument
s); | 74 return JS( |
| 75 '', 'dart.dcall.apply(null, [#].concat(#))', f, positionalArguments); |
| 77 } | 76 } |
| 78 | 77 |
| 79 static Map<String, dynamic> _toMangledNames( | 78 static Map<String, dynamic> _toMangledNames( |
| 80 Map<Symbol, dynamic> namedArguments) { | 79 Map<Symbol, dynamic> namedArguments) { |
| 81 Map<String, dynamic> result = {}; | 80 Map<String, dynamic> result = {}; |
| 82 namedArguments.forEach((symbol, value) { | 81 namedArguments.forEach((symbol, value) { |
| 83 result[_symbolToString(symbol)] = value; | 82 result[_symbolToString(symbol)] = value; |
| 84 }); | 83 }); |
| 85 return result; | 84 return result; |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 // TODO(jmesserly): switch to WeakMap | 88 // TODO(jmesserly): switch to WeakMap |
| 90 // Patch for Expando implementation. | 89 // Patch for Expando implementation. |
| 91 @patch | 90 @patch |
| 92 class Expando<T> { | 91 class Expando<T> { |
| 93 @patch | 92 @patch |
| 94 Expando([String name]) : this.name = name; | 93 Expando([String name]) : this.name = name; |
| 95 | 94 |
| 96 @patch | 95 @patch |
| 97 T operator[](Object object) { | 96 T operator [](Object object) { |
| 98 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); | 97 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); |
| 99 return (values == null) ? null : Primitives.getProperty(values, _getKey()); | 98 return (values == null) ? null : Primitives.getProperty(values, _getKey()); |
| 100 } | 99 } |
| 101 | 100 |
| 102 @patch | 101 @patch |
| 103 void operator[]=(Object object, T value) { | 102 void operator []=(Object object, T value) { |
| 104 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); | 103 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); |
| 105 if (values == null) { | 104 if (values == null) { |
| 106 values = new Object(); | 105 values = new Object(); |
| 107 Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values); | 106 Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values); |
| 108 } | 107 } |
| 109 Primitives.setProperty(values, _getKey(), value); | 108 Primitives.setProperty(values, _getKey(), value); |
| 110 } | 109 } |
| 111 | 110 |
| 112 String _getKey() { | 111 String _getKey() { |
| 113 String key = Primitives.getProperty(this, _KEY_PROPERTY_NAME); | 112 String key = Primitives.getProperty(this, _KEY_PROPERTY_NAME); |
| 114 if (key == null) { | 113 if (key == null) { |
| 115 key = "expando\$key\$${_keyCount++}"; | 114 key = "expando\$key\$${_keyCount++}"; |
| 116 Primitives.setProperty(this, _KEY_PROPERTY_NAME, key); | 115 Primitives.setProperty(this, _KEY_PROPERTY_NAME, key); |
| 117 } | 116 } |
| 118 return key; | 117 return key; |
| 119 } | 118 } |
| 120 | 119 |
| 121 static const String _KEY_PROPERTY_NAME = 'expando\$key'; | 120 static const String _KEY_PROPERTY_NAME = 'expando\$key'; |
| 122 static const String _EXPANDO_PROPERTY_NAME = 'expando\$values'; | 121 static const String _EXPANDO_PROPERTY_NAME = 'expando\$values'; |
| 123 static int _keyCount = 0; | 122 static int _keyCount = 0; |
| 124 } | 123 } |
| 125 | 124 |
| 126 @patch | 125 @patch |
| 127 class int { | 126 class int { |
| 128 @patch | 127 @patch |
| 129 static int parse(String source, | 128 static int parse(String source, {int radix, int onError(String source)}) { |
| 130 { int radix, | |
| 131 int onError(String source) }) { | |
| 132 return Primitives.parseInt(source, radix, onError); | 129 return Primitives.parseInt(source, radix, onError); |
| 133 } | 130 } |
| 134 | 131 |
| 135 @patch | 132 @patch |
| 136 factory int.fromEnvironment(String name, {int defaultValue}) { | 133 factory int.fromEnvironment(String name, {int defaultValue}) { |
| 137 throw new UnsupportedError( | 134 throw new UnsupportedError( |
| 138 'int.fromEnvironment can only be used as a const constructor'); | 135 'int.fromEnvironment can only be used as a const constructor'); |
| 139 } | 136 } |
| 140 } | 137 } |
| 141 | 138 |
| 142 @patch | 139 @patch |
| 143 class double { | 140 class double { |
| 144 @patch | 141 @patch |
| 145 static double parse(String source, | 142 static double parse(String source, [double onError(String source)]) { |
| 146 [double onError(String source)]) { | |
| 147 return Primitives.parseDouble(source, onError); | 143 return Primitives.parseDouble(source, onError); |
| 148 } | 144 } |
| 149 } | 145 } |
| 150 | 146 |
| 151 @patch | 147 @patch |
| 152 class Error { | 148 class Error { |
| 153 @patch | 149 @patch |
| 154 static String _objectToString(Object object) { | 150 static String _objectToString(Object object) { |
| 155 return Primitives.objectToString(object); | 151 return Primitives.objectToString(object); |
| 156 } | 152 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 177 } | 173 } |
| 178 | 174 |
| 179 /// An interface type for all Strong-mode errors. | 175 /// An interface type for all Strong-mode errors. |
| 180 class StrongModeError extends Error {} | 176 class StrongModeError extends Error {} |
| 181 | 177 |
| 182 // Patch for DateTime implementation. | 178 // Patch for DateTime implementation. |
| 183 @patch | 179 @patch |
| 184 class DateTime { | 180 class DateTime { |
| 185 @patch | 181 @patch |
| 186 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, | 182 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, |
| 187 {bool isUtc: false}) | 183 {bool isUtc: false}) |
| 188 : this._withValue(millisecondsSinceEpoch, isUtc: isUtc); | 184 : this._withValue(millisecondsSinceEpoch, isUtc: isUtc); |
| 189 | 185 |
| 190 @patch | 186 @patch |
| 191 DateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, | 187 DateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, |
| 192 {bool isUtc: false}) | 188 {bool isUtc: false}) |
| 193 : this._withValue( | 189 : this._withValue( |
| 194 _microsecondInRoundedMilliseconds(microsecondsSinceEpoch), | 190 _microsecondInRoundedMilliseconds(microsecondsSinceEpoch), |
| 195 isUtc: isUtc); | 191 isUtc: isUtc); |
| 196 | 192 |
| 197 @patch | 193 @patch |
| 198 DateTime._internal(int year, | 194 DateTime._internal(int year, int month, int day, int hour, int minute, |
| 199 int month, | 195 int second, int millisecond, int microsecond, bool isUtc) |
| 200 int day, | 196 // checkBool is manually inlined here because dart2js doesn't inline it |
| 201 int hour, | 197 // and [isUtc] is usually a constant. |
| 202 int minute, | |
| 203 int second, | |
| 204 int millisecond, | |
| 205 int microsecond, | |
| 206 bool isUtc) | |
| 207 // checkBool is manually inlined here because dart2js doesn't inline it | |
| 208 // and [isUtc] is usually a constant. | |
| 209 : this.isUtc = isUtc is bool | 198 : this.isUtc = isUtc is bool |
| 210 ? isUtc | 199 ? isUtc |
| 211 : throw new ArgumentError.value(isUtc, 'isUtc'), | 200 : throw new ArgumentError.value(isUtc, 'isUtc'), |
| 212 _value = checkInt(Primitives.valueFromDecomposedDate( | 201 _value = checkInt(Primitives.valueFromDecomposedDate( |
| 213 year, month, day, hour, minute, second, | 202 year, |
| 203 month, |
| 204 day, |
| 205 hour, |
| 206 minute, |
| 207 second, |
| 214 millisecond + _microsecondInRoundedMilliseconds(microsecond), | 208 millisecond + _microsecondInRoundedMilliseconds(microsecond), |
| 215 isUtc)); | 209 isUtc)); |
| 216 | 210 |
| 217 @patch | 211 @patch |
| 218 DateTime._now() | 212 DateTime._now() |
| 219 : isUtc = false, | 213 : isUtc = false, |
| 220 _value = Primitives.dateNow(); | 214 _value = Primitives.dateNow(); |
| 221 | 215 |
| 222 /// Rounds the given [microsecond] to the nearest milliseconds value. | 216 /// Rounds the given [microsecond] to the nearest milliseconds value. |
| 223 /// | 217 /// |
| 224 /// For example, invoked with argument `2600` returns `3`. | 218 /// For example, invoked with argument `2600` returns `3`. |
| 225 static int _microsecondInRoundedMilliseconds(int microsecond) { | 219 static int _microsecondInRoundedMilliseconds(int microsecond) { |
| 226 return (microsecond / 1000).round(); | 220 return (microsecond / 1000).round(); |
| 227 } | 221 } |
| 228 | 222 |
| 229 @patch | 223 @patch |
| 230 static int _brokenDownDateToValue( | 224 static int _brokenDownDateToValue(int year, int month, int day, int hour, |
| 231 int year, int month, int day, int hour, int minute, int second, | 225 int minute, int second, int millisecond, int microsecond, bool isUtc) { |
| 232 int millisecond, int microsecond, bool isUtc) { | |
| 233 return Primitives.valueFromDecomposedDate( | 226 return Primitives.valueFromDecomposedDate( |
| 234 year, month, day, hour, minute, second, | 227 year, |
| 228 month, |
| 229 day, |
| 230 hour, |
| 231 minute, |
| 232 second, |
| 235 millisecond + _microsecondInRoundedMilliseconds(microsecond), | 233 millisecond + _microsecondInRoundedMilliseconds(microsecond), |
| 236 isUtc); | 234 isUtc); |
| 237 } | 235 } |
| 238 | 236 |
| 239 @patch | 237 @patch |
| 240 String get timeZoneName { | 238 String get timeZoneName { |
| 241 if (isUtc) return "UTC"; | 239 if (isUtc) return "UTC"; |
| 242 return Primitives.getTimeZoneName(this); | 240 return Primitives.getTimeZoneName(this); |
| 243 } | 241 } |
| 244 | 242 |
| 245 @patch | 243 @patch |
| 246 Duration get timeZoneOffset { | 244 Duration get timeZoneOffset { |
| 247 if (isUtc) return new Duration(); | 245 if (isUtc) return new Duration(); |
| 248 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); | 246 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); |
| 249 } | 247 } |
| 250 | 248 |
| 251 @patch | 249 @patch |
| 252 DateTime add(Duration duration) { | 250 DateTime add(Duration duration) { |
| 253 return new DateTime._withValue( | 251 return new DateTime._withValue(_value + duration.inMilliseconds, |
| 254 _value + duration.inMilliseconds, isUtc: isUtc); | 252 isUtc: isUtc); |
| 255 } | 253 } |
| 256 | 254 |
| 257 @patch | 255 @patch |
| 258 DateTime subtract(Duration duration) { | 256 DateTime subtract(Duration duration) { |
| 259 return new DateTime._withValue( | 257 return new DateTime._withValue(_value - duration.inMilliseconds, |
| 260 _value - duration.inMilliseconds, isUtc: isUtc); | 258 isUtc: isUtc); |
| 261 } | 259 } |
| 262 | 260 |
| 263 @patch | 261 @patch |
| 264 Duration difference(DateTime other) { | 262 Duration difference(DateTime other) { |
| 265 return new Duration(milliseconds: _value - other._value); | 263 return new Duration(milliseconds: _value - other._value); |
| 266 } | 264 } |
| 267 | 265 |
| 268 @patch | 266 @patch |
| 269 int get millisecondsSinceEpoch => _value; | 267 int get millisecondsSinceEpoch => _value; |
| 270 | 268 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 292 @patch | 290 @patch |
| 293 int get millisecond => Primitives.getMilliseconds(this); | 291 int get millisecond => Primitives.getMilliseconds(this); |
| 294 | 292 |
| 295 @patch | 293 @patch |
| 296 int get microsecond => 0; | 294 int get microsecond => 0; |
| 297 | 295 |
| 298 @patch | 296 @patch |
| 299 int get weekday => Primitives.getWeekday(this); | 297 int get weekday => Primitives.getWeekday(this); |
| 300 } | 298 } |
| 301 | 299 |
| 302 | |
| 303 // Patch for Stopwatch implementation. | 300 // Patch for Stopwatch implementation. |
| 304 @patch | 301 @patch |
| 305 class Stopwatch { | 302 class Stopwatch { |
| 306 @patch | 303 @patch |
| 307 static void _initTicker() { | 304 static void _initTicker() { |
| 308 Primitives.initTicker(); | 305 Primitives.initTicker(); |
| 309 _frequency = Primitives.timerFrequency; | 306 _frequency = Primitives.timerFrequency; |
| 310 } | 307 } |
| 311 | 308 |
| 312 @patch | 309 @patch |
| 313 static int _now() => Primitives.timerTicks(); | 310 static int _now() => Primitives.timerTicks(); |
| 314 } | 311 } |
| 315 | 312 |
| 316 // Patch for List implementation. | 313 // Patch for List implementation. |
| 317 @patch | 314 @patch |
| 318 class List<E> { | 315 class List<E> { |
| 319 @patch | 316 @patch |
| 320 factory List([int length]) { | 317 factory List([int length]) { |
| 321 dynamic list; | 318 dynamic list; |
| 322 if (length == null) { | 319 if (length == null) { |
| 323 list = JS('', '[]'); | 320 list = JS('', '[]'); |
| 324 } else { | 321 } else { |
| 325 // Explicit type test is necessary to guard against JavaScript conversions | 322 // Explicit type test is necessary to guard against JavaScript conversions |
| 326 // in unchecked mode. | 323 // in unchecked mode. |
| 327 if ((length is !int) || (length < 0)) { | 324 if ((length is! int) || (length < 0)) { |
| 328 throw new ArgumentError("Length must be a non-negative integer: $length"
); | 325 throw new ArgumentError( |
| 326 "Length must be a non-negative integer: $length"); |
| 329 } | 327 } |
| 330 list = JSArray.markFixedList(JS('', 'new Array(#)', length)); | 328 list = JSArray.markFixedList(JS('', 'new Array(#)', length)); |
| 331 } | 329 } |
| 332 return new JSArray<E>.typed(list); | 330 return new JSArray<E>.typed(list); |
| 333 } | 331 } |
| 334 | 332 |
| 335 @patch | 333 @patch |
| 336 factory List.filled(int length, E fill) { | 334 factory List.filled(int length, E fill) { |
| 337 List<E> result = new List<E>(length); | 335 List<E> result = new List<E>(length); |
| 338 if (length != 0 && fill != null) { | 336 if (length != 0 && fill != null) { |
| 339 for (int i = 0; i < result.length; i++) { | 337 for (int i = 0; i < result.length; i++) { |
| 340 result[i] = fill; | 338 result[i] = fill; |
| 341 } | 339 } |
| 342 } | 340 } |
| 343 return result; | 341 return result; |
| 344 } | 342 } |
| 345 | 343 |
| 346 @patch | 344 @patch |
| 347 factory List.from(Iterable elements, { bool growable: true }) { | 345 factory List.from(Iterable elements, {bool growable: true}) { |
| 348 List<E> list = new List<E>(); | 346 List<E> list = new List<E>(); |
| 349 for (var e in elements) { | 347 for (var e in elements) { |
| 350 list.add(e); | 348 list.add(e); |
| 351 } | 349 } |
| 352 if (growable) return list; | 350 if (growable) return list; |
| 353 return makeListFixedLength/*<E>*/(list); | 351 return makeListFixedLength/*<E>*/(list); |
| 354 } | 352 } |
| 355 | 353 |
| 356 @patch | 354 @patch |
| 357 factory List.unmodifiable(Iterable elements) { | 355 factory List.unmodifiable(Iterable elements) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 368 } | 366 } |
| 369 | 367 |
| 370 @patch | 368 @patch |
| 371 factory Map() = JsLinkedHashMap<K, V>.es6; | 369 factory Map() = JsLinkedHashMap<K, V>.es6; |
| 372 } | 370 } |
| 373 | 371 |
| 374 @patch | 372 @patch |
| 375 class String { | 373 class String { |
| 376 @patch | 374 @patch |
| 377 factory String.fromCharCodes(Iterable<int> charCodes, | 375 factory String.fromCharCodes(Iterable<int> charCodes, |
| 378 [int start = 0, int end]) { | 376 [int start = 0, int end]) { |
| 379 if (charCodes is JSArray) { | 377 if (charCodes is JSArray) { |
| 380 return _stringFromJSArray(charCodes, start, end); | 378 return _stringFromJSArray(charCodes, start, end); |
| 381 } | 379 } |
| 382 if (charCodes is NativeUint8List) { | 380 if (charCodes is NativeUint8List) { |
| 383 return _stringFromUint8List(charCodes, start, end); | 381 return _stringFromUint8List(charCodes, start, end); |
| 384 } | 382 } |
| 385 return _stringFromIterable(charCodes, start, end); | 383 return _stringFromIterable(charCodes, start, end); |
| 386 } | 384 } |
| 387 | 385 |
| 388 @patch | 386 @patch |
| 389 factory String.fromCharCode(int charCode) { | 387 factory String.fromCharCode(int charCode) { |
| 390 return Primitives.stringFromCharCode(charCode); | 388 return Primitives.stringFromCharCode(charCode); |
| 391 } | 389 } |
| 392 | 390 |
| 393 @patch | 391 @patch |
| 394 factory String.fromEnvironment(String name, {String defaultValue}) { | 392 factory String.fromEnvironment(String name, {String defaultValue}) { |
| 395 throw new UnsupportedError( | 393 throw new UnsupportedError( |
| 396 'String.fromEnvironment can only be used as a const constructor'); | 394 'String.fromEnvironment can only be used as a const constructor'); |
| 397 } | 395 } |
| 398 | 396 |
| 399 static String _stringFromJSArray( | 397 static String _stringFromJSArray( |
| 400 /*=JSArray<int>*/ list, int start, int endOrNull) { | 398 /*=JSArray<int>*/ list, |
| 399 int start, |
| 400 int endOrNull) { |
| 401 int len = list.length; | 401 int len = list.length; |
| 402 int end = RangeError.checkValidRange(start, endOrNull, len); | 402 int end = RangeError.checkValidRange(start, endOrNull, len); |
| 403 if (start > 0 || end < len) { | 403 if (start > 0 || end < len) { |
| 404 list = list.sublist(start, end); | 404 list = list.sublist(start, end); |
| 405 } | 405 } |
| 406 return Primitives.stringFromCharCodes(list); | 406 return Primitives.stringFromCharCodes(list); |
| 407 } | 407 } |
| 408 | 408 |
| 409 static String _stringFromUint8List( | 409 static String _stringFromUint8List( |
| 410 NativeUint8List charCodes, int start, int endOrNull) { | 410 NativeUint8List charCodes, int start, int endOrNull) { |
| 411 int len = charCodes.length; | 411 int len = charCodes.length; |
| 412 int end = RangeError.checkValidRange(start, endOrNull, len); | 412 int end = RangeError.checkValidRange(start, endOrNull, len); |
| 413 return Primitives.stringFromNativeUint8List(charCodes, start, end); | 413 return Primitives.stringFromNativeUint8List(charCodes, start, end); |
| 414 } | 414 } |
| 415 | 415 |
| 416 static String _stringFromIterable(Iterable<int> charCodes, | 416 static String _stringFromIterable( |
| 417 int start, int end) { | 417 Iterable<int> charCodes, int start, int end) { |
| 418 if (start < 0) throw new RangeError.range(start, 0, charCodes.length); | 418 if (start < 0) throw new RangeError.range(start, 0, charCodes.length); |
| 419 if (end != null && end < start) { | 419 if (end != null && end < start) { |
| 420 throw new RangeError.range(end, start, charCodes.length); | 420 throw new RangeError.range(end, start, charCodes.length); |
| 421 } | 421 } |
| 422 var it = charCodes.iterator; | 422 var it = charCodes.iterator; |
| 423 for (int i = 0; i < start; i++) { | 423 for (int i = 0; i < start; i++) { |
| 424 if (!it.moveNext()) { | 424 if (!it.moveNext()) { |
| 425 throw new RangeError.range(start, 0, i); | 425 throw new RangeError.range(start, 0, i); |
| 426 } | 426 } |
| 427 } | 427 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 442 | 442 |
| 443 @patch | 443 @patch |
| 444 class bool { | 444 class bool { |
| 445 @patch | 445 @patch |
| 446 factory bool.fromEnvironment(String name, {bool defaultValue: false}) { | 446 factory bool.fromEnvironment(String name, {bool defaultValue: false}) { |
| 447 throw new UnsupportedError( | 447 throw new UnsupportedError( |
| 448 'bool.fromEnvironment can only be used as a const constructor'); | 448 'bool.fromEnvironment can only be used as a const constructor'); |
| 449 } | 449 } |
| 450 | 450 |
| 451 @patch | 451 @patch |
| 452 int get hashCode => super.hashCode; | 452 int get hashCode => super.hashCode; |
| 453 } | 453 } |
| 454 | 454 |
| 455 @patch | 455 @patch |
| 456 class RegExp { | 456 class RegExp { |
| 457 @patch | 457 @patch |
| 458 factory RegExp(String source, | 458 factory RegExp(String source, |
| 459 {bool multiLine: false, | 459 {bool multiLine: false, bool caseSensitive: true}) => |
| 460 bool caseSensitive: true}) | 460 new JSSyntaxRegExp(source, |
| 461 => new JSSyntaxRegExp(source, | 461 multiLine: multiLine, caseSensitive: caseSensitive); |
| 462 multiLine: multiLine, | |
| 463 caseSensitive: caseSensitive); | |
| 464 } | 462 } |
| 465 | 463 |
| 466 // Patch for 'identical' function. | 464 // Patch for 'identical' function. |
| 467 @patch | 465 @patch |
| 468 bool identical(Object a, Object b) { | 466 bool identical(Object a, Object b) { |
| 469 return JS('bool', '(# == null ? # == null : # === #)', a, b, a, b); | 467 return JS('bool', '(# == null ? # == null : # === #)', a, b, a, b); |
| 470 } | 468 } |
| 471 | 469 |
| 472 @patch | 470 @patch |
| 473 class StringBuffer { | 471 class StringBuffer { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 527 } |
| 530 | 528 |
| 531 static String _writeOne(String string, Object obj) { | 529 static String _writeOne(String string, Object obj) { |
| 532 return Primitives.stringConcatUnchecked(string, '$obj'); | 530 return Primitives.stringConcatUnchecked(string, '$obj'); |
| 533 } | 531 } |
| 534 } | 532 } |
| 535 | 533 |
| 536 @patch | 534 @patch |
| 537 class NoSuchMethodError { | 535 class NoSuchMethodError { |
| 538 @patch | 536 @patch |
| 539 NoSuchMethodError(Object receiver, | 537 NoSuchMethodError(Object receiver, Symbol memberName, |
| 540 Symbol memberName, | 538 List positionalArguments, Map<Symbol, dynamic> namedArguments, |
| 541 List positionalArguments, | 539 [List existingArgumentNames = null]) |
| 542 Map<Symbol, dynamic> namedArguments, | |
| 543 [List existingArgumentNames = null]) | |
| 544 : _receiver = receiver, | 540 : _receiver = receiver, |
| 545 _memberName = memberName, | 541 _memberName = memberName, |
| 546 _arguments = positionalArguments, | 542 _arguments = positionalArguments, |
| 547 _namedArguments = namedArguments, | 543 _namedArguments = namedArguments, |
| 548 _existingArgumentNames = existingArgumentNames; | 544 _existingArgumentNames = existingArgumentNames; |
| 549 | 545 |
| 550 @patch | 546 @patch |
| 551 String toString() { | 547 String toString() { |
| 552 StringBuffer sb = new StringBuffer(); | 548 StringBuffer sb = new StringBuffer(); |
| 553 int i = 0; | 549 int i = 0; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 // component. This corresponds to [_unreservedTable], i.e. characters that | 608 // component. This corresponds to [_unreservedTable], i.e. characters that |
| 613 // are not encoded by any encoding table. | 609 // are not encoded by any encoding table. |
| 614 static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$'); | 610 static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$'); |
| 615 | 611 |
| 616 /** | 612 /** |
| 617 * This is the internal implementation of JavaScript's encodeURI function. | 613 * This is the internal implementation of JavaScript's encodeURI function. |
| 618 * It encodes all characters in the string [text] except for those | 614 * It encodes all characters in the string [text] except for those |
| 619 * that appear in [canonicalTable], and returns the escaped string. | 615 * that appear in [canonicalTable], and returns the escaped string. |
| 620 */ | 616 */ |
| 621 @patch | 617 @patch |
| 622 static String _uriEncode(List<int> canonicalTable, | 618 static String _uriEncode(List<int> canonicalTable, String text, |
| 623 String text, | 619 Encoding encoding, bool spaceToPlus) { |
| 624 Encoding encoding, | |
| 625 bool spaceToPlus) { | |
| 626 if (identical(encoding, UTF8) && _needsNoEncoding.hasMatch(text)) { | 620 if (identical(encoding, UTF8) && _needsNoEncoding.hasMatch(text)) { |
| 627 return text; | 621 return text; |
| 628 } | 622 } |
| 629 | 623 |
| 630 // Encode the string into bytes then generate an ASCII only string | 624 // Encode the string into bytes then generate an ASCII only string |
| 631 // by percent encoding selected bytes. | 625 // by percent encoding selected bytes. |
| 632 StringBuffer result = new StringBuffer(''); | 626 StringBuffer result = new StringBuffer(''); |
| 633 var bytes = encoding.encode(text); | 627 var bytes = encoding.encode(text); |
| 634 for (int i = 0; i < bytes.length; i++) { | 628 for (int i = 0; i < bytes.length; i++) { |
| 635 int byte = bytes[i]; | 629 int byte = bytes[i]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 650 } | 644 } |
| 651 | 645 |
| 652 @patch | 646 @patch |
| 653 class StackTrace { | 647 class StackTrace { |
| 654 @patch | 648 @patch |
| 655 @NoInline() | 649 @NoInline() |
| 656 static StackTrace get current { | 650 static StackTrace get current { |
| 657 return getTraceFromException(JS('', 'new Error()')); | 651 return getTraceFromException(JS('', 'new Error()')); |
| 658 } | 652 } |
| 659 } | 653 } |
| OLD | NEW |