| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library dart.core_patch; | 5 library dart.core_patch; |
| 6 | 6 |
| 7 import 'dart:fletch._system' as fletch; | 7 import 'dart:dartino._system' as dartino; |
| 8 import 'dart:fletch._system' show patch; | 8 import 'dart:dartino._system' show patch; |
| 9 import 'dart:collection' show LinkedHashMap, UnmodifiableMapView; | 9 import 'dart:collection' show LinkedHashMap, UnmodifiableMapView; |
| 10 | 10 |
| 11 part 'bigint.dart'; | 11 part 'bigint.dart'; |
| 12 part 'case.dart'; | 12 part 'case.dart'; |
| 13 part 'double.dart'; | 13 part 'double.dart'; |
| 14 part 'int.dart'; | 14 part 'int.dart'; |
| 15 part 'regexp.dart'; | 15 part 'regexp.dart'; |
| 16 part 'string.dart'; | 16 part 'string.dart'; |
| 17 | 17 |
| 18 @patch external bool identical(Object a, Object b); | 18 @patch external bool identical(Object a, Object b); |
| 19 | 19 |
| 20 @patch int identityHashCode(Object object) { | 20 @patch int identityHashCode(Object object) { |
| 21 if (object is int) return object; | 21 if (object is int) return object; |
| 22 return _identityHashCode(object); | 22 return _identityHashCode(object); |
| 23 } | 23 } |
| 24 | 24 |
| 25 @fletch.native external _identityHashCode(Object object); | 25 @dartino.native external _identityHashCode(Object object); |
| 26 | 26 |
| 27 @patch class Object { | 27 @patch class Object { |
| 28 @patch String toString() => '[object Object]'; | 28 @patch String toString() => '[object Object]'; |
| 29 | 29 |
| 30 @patch int get hashCode => _identityHashCode(this); | 30 @patch int get hashCode => _identityHashCode(this); |
| 31 | 31 |
| 32 @patch noSuchMethod(Invocation invocation) { | 32 @patch noSuchMethod(Invocation invocation) { |
| 33 if (invocation is fletch.FletchInvocation) { | 33 if (invocation is dartino.DartinoInvocation) { |
| 34 throw invocation.asNoSuchMethodError; | 34 throw invocation.asNoSuchMethodError; |
| 35 } | 35 } |
| 36 // TODO(ahe): Get rid of this call. | 36 // TODO(ahe): Get rid of this call. |
| 37 fletch.unresolved("<unknown>"); | 37 dartino.unresolved("<unknown>"); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // The noSuchMethod helper is automatically called from the | 40 // The noSuchMethod helper is automatically called from the |
| 41 // trampoline and it is passed the selector. The arguments | 41 // trampoline and it is passed the selector. The arguments |
| 42 // to the original call are still present on the stack, so | 42 // to the original call are still present on the stack, so |
| 43 // it is possible to dig them out if need be. | 43 // it is possible to dig them out if need be. |
| 44 _noSuchMethod(receiver, receiverClass, receiverSelector) { | 44 _noSuchMethod(receiver, receiverClass, receiverSelector) { |
| 45 // NOTE: The number and type of arguments here must be kept in sync with: | 45 // NOTE: The number and type of arguments here must be kept in sync with: |
| 46 // src/vm/interpreter.cc:HandleEnterNoSuchMethod | 46 // src/vm/interpreter.cc:HandleEnterNoSuchMethod |
| 47 return noSuchMethod(new fletch.FletchInvocation( | 47 return noSuchMethod(new dartino.DartinoInvocation( |
| 48 receiver, receiverClass, receiverSelector)); | 48 receiver, receiverClass, receiverSelector)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // The noSuchMethod trampoline is automatically generated | 51 // The noSuchMethod trampoline is automatically generated |
| 52 // by the compiler. It calls the noSuchMethod helper and | 52 // by the compiler. It calls the noSuchMethod helper and |
| 53 // takes care off removing an arbitrary number of arguments | 53 // takes care off removing an arbitrary number of arguments |
| 54 // from the caller stack before it returns. | 54 // from the caller stack before it returns. |
| 55 external _noSuchMethodTrampoline(); | 55 external _noSuchMethodTrampoline(); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 return '[object Object]'; | 182 return '[object Object]'; |
| 183 } | 183 } |
| 184 | 184 |
| 185 @patch StackTrace get stackTrace { | 185 @patch StackTrace get stackTrace { |
| 186 throw "getter stackTrace is unimplemented"; | 186 throw "getter stackTrace is unimplemented"; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 @patch class Stopwatch { | 190 @patch class Stopwatch { |
| 191 @patch @fletch.native external static int _now(); | 191 @patch @dartino.native external static int _now(); |
| 192 | 192 |
| 193 @patch static int _initTicker() { | 193 @patch static int _initTicker() { |
| 194 _frequency = _fletchNative_frequency(); | 194 _frequency = _dartinoNative_frequency(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 @fletch.native external static int _fletchNative_frequency(); | 197 @dartino.native external static int _dartinoNative_frequency(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 @patch class RegExp { | 200 @patch class RegExp { |
| 201 @patch factory RegExp(String source, {bool multiLine: false, | 201 @patch factory RegExp(String source, {bool multiLine: false, |
| 202 bool caseSensitive: true}) { | 202 bool caseSensitive: true}) { |
| 203 return new _MiniExp(source, multiLine, caseSensitive); | 203 return new _MiniExp(source, multiLine, caseSensitive); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 @patch class List { | 207 @patch class List { |
| 208 @patch factory List([int length]) { | 208 @patch factory List([int length]) { |
| 209 return fletch.newList(length); | 209 return dartino.newList(length); |
| 210 } | 210 } |
| 211 | 211 |
| 212 @patch factory List.filled(int length, E fill) { | 212 @patch factory List.filled(int length, E fill) { |
| 213 // All error handling on the length parameter is done at the implementation | 213 // All error handling on the length parameter is done at the implementation |
| 214 // of new _List. | 214 // of new _List. |
| 215 var result = fletch.newList(length); | 215 var result = dartino.newList(length); |
| 216 if (fill != null) { | 216 if (fill != null) { |
| 217 for (int i = 0; i < length; i++) { | 217 for (int i = 0; i < length; i++) { |
| 218 result[i] = fill; | 218 result[i] = fill; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 return result; | 221 return result; |
| 222 } | 222 } |
| 223 | 223 |
| 224 @patch factory List.from(Iterable elements, {bool growable: true}) { | 224 @patch factory List.from(Iterable elements, {bool growable: true}) { |
| 225 // TODO(ajohnsen): elements.length can be slow if not a List. Consider | 225 // TODO(ajohnsen): elements.length can be slow if not a List. Consider |
| 226 // fast-path non-list & growable, and create internal helper for non-list & | 226 // fast-path non-list & growable, and create internal helper for non-list & |
| 227 // non-growable. | 227 // non-growable. |
| 228 int length = elements.length; | 228 int length = elements.length; |
| 229 var list; | 229 var list; |
| 230 if (growable) { | 230 if (growable) { |
| 231 list = fletch.newList(null); | 231 list = dartino.newList(null); |
| 232 list.length = length; | 232 list.length = length; |
| 233 } else { | 233 } else { |
| 234 list = fletch.newList(length); | 234 list = dartino.newList(length); |
| 235 } | 235 } |
| 236 if (elements is List) { | 236 if (elements is List) { |
| 237 for (int i = 0; i < length; i++) { | 237 for (int i = 0; i < length; i++) { |
| 238 list[i] = elements[i]; | 238 list[i] = elements[i]; |
| 239 } | 239 } |
| 240 } else { | 240 } else { |
| 241 int i = 0; | 241 int i = 0; |
| 242 elements.forEach((e) { list[i++] = e; }); | 242 elements.forEach((e) { list[i++] = e; }); |
| 243 } | 243 } |
| 244 return list; | 244 return list; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 source.startsWith('+0x')) { | 287 source.startsWith('+0x')) { |
| 288 if (onError != null) return onError(source); | 288 if (onError != null) return onError(source); |
| 289 throw new FormatException("Can't parse string as integer", source); | 289 throw new FormatException("Can't parse string as integer", source); |
| 290 } | 290 } |
| 291 } else { | 291 } else { |
| 292 if (radix < 2 || radix > 36) throw new ArgumentError(radix); | 292 if (radix < 2 || radix > 36) throw new ArgumentError(radix); |
| 293 } | 293 } |
| 294 return _parse(source, radix, onError); | 294 return _parse(source, radix, onError); |
| 295 } | 295 } |
| 296 | 296 |
| 297 @fletch.native static int _parse( | 297 @dartino.native static int _parse( |
| 298 String source, | 298 String source, |
| 299 int radix, | 299 int radix, |
| 300 int onError(String source)) { | 300 int onError(String source)) { |
| 301 switch (fletch.nativeError) { | 301 switch (dartino.nativeError) { |
| 302 case fletch.wrongArgumentType: | 302 case dartino.wrongArgumentType: |
| 303 throw new ArgumentError(source); | 303 throw new ArgumentError(source); |
| 304 case fletch.indexOutOfBounds: | 304 case dartino.indexOutOfBounds: |
| 305 if (onError != null) return onError(source); | 305 if (onError != null) return onError(source); |
| 306 throw new FormatException("Can't parse string as integer", source); | 306 throw new FormatException("Can't parse string as integer", source); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 @patch factory int.fromEnvironment( | 310 @patch factory int.fromEnvironment( |
| 311 String name, | 311 String name, |
| 312 {int defaultValue}) => defaultValue; | 312 {int defaultValue}) => defaultValue; |
| 313 } | 313 } |
| 314 | 314 |
| 315 @patch class double { | 315 @patch class double { |
| 316 @patch static double parse(String source, [double onError(String source)]) { | 316 @patch static double parse(String source, [double onError(String source)]) { |
| 317 return _parse(source.trim(), onError); | 317 return _parse(source.trim(), onError); |
| 318 } | 318 } |
| 319 | 319 |
| 320 @fletch.native static double _parse( | 320 @dartino.native static double _parse( |
| 321 String source, | 321 String source, |
| 322 double onError(String source)) { | 322 double onError(String source)) { |
| 323 switch (fletch.nativeError) { | 323 switch (dartino.nativeError) { |
| 324 case fletch.wrongArgumentType: | 324 case dartino.wrongArgumentType: |
| 325 throw new ArgumentError(source); | 325 throw new ArgumentError(source); |
| 326 case fletch.indexOutOfBounds: | 326 case dartino.indexOutOfBounds: |
| 327 if (onError != null) return onError(source); | 327 if (onError != null) return onError(source); |
| 328 throw new FormatException("Can't parse string as double", source); | 328 throw new FormatException("Can't parse string as double", source); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 @patch class DateTime { | 333 @patch class DateTime { |
| 334 static const _MILLISECOND_INDEX = 0; | 334 static const _MILLISECOND_INDEX = 0; |
| 335 static const _SECOND_INDEX = 1; | 335 static const _SECOND_INDEX = 1; |
| 336 static const _MINUTE_INDEX = 2; | 336 static const _MINUTE_INDEX = 2; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { | 650 static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { |
| 651 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 651 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |
| 652 return _timeZoneOffset(equivalentSeconds); | 652 return _timeZoneOffset(equivalentSeconds); |
| 653 } | 653 } |
| 654 | 654 |
| 655 static String _timeZoneName(int millisecondsSinceEpoch) { | 655 static String _timeZoneName(int millisecondsSinceEpoch) { |
| 656 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 656 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |
| 657 return _timeZone(equivalentSeconds); | 657 return _timeZone(equivalentSeconds); |
| 658 } | 658 } |
| 659 | 659 |
| 660 @fletch.native external static int _getCurrentMs(); | 660 @dartino.native external static int _getCurrentMs(); |
| 661 | 661 |
| 662 @fletch.native external static String _timeZone(int clampedSecondsSinceEpoch); | 662 @dartino.native external static String _timeZone(int clampedSecondsSinceEpoch)
; |
| 663 | 663 |
| 664 @fletch.native external static int _timeZoneOffset( | 664 @dartino.native external static int _timeZoneOffset( |
| 665 int clampedSecondsSinceEpoch); | 665 int clampedSecondsSinceEpoch); |
| 666 | 666 |
| 667 @fletch.native external static int _localTimeZoneOffset(); | 667 @dartino.native external static int _localTimeZoneOffset(); |
| 668 } | 668 } |
| 669 | 669 |
| 670 @patch class Uri { | 670 @patch class Uri { |
| 671 @patch static Uri get base { | 671 @patch static Uri get base { |
| 672 return new Uri.file(_base()); | 672 return new Uri.file(_base()); |
| 673 } | 673 } |
| 674 | 674 |
| 675 @patch static bool get _isWindows => false; | 675 @patch static bool get _isWindows => false; |
| 676 | 676 |
| 677 @fletch.native static String _base() { | 677 @dartino.native static String _base() { |
| 678 throw new RangeError("The Uri.base path is too large"); | 678 throw new RangeError("The Uri.base path is too large"); |
| 679 } | 679 } |
| 680 | 680 |
| 681 /// Encodes all characters in the string [text] except for those | 681 /// Encodes all characters in the string [text] except for those |
| 682 /// that appear in [canonicalTable], and returns the escaped string. | 682 /// that appear in [canonicalTable], and returns the escaped string. |
| 683 @patch static String _uriEncode( | 683 @patch static String _uriEncode( |
| 684 List<int> canonicalTable, | 684 List<int> canonicalTable, |
| 685 String text, | 685 String text, |
| 686 Encoding encoding, | 686 Encoding encoding, |
| 687 bool spaceToPlus) { | 687 bool spaceToPlus) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 703 } else if (spaceToPlus && byte == _SPACE) { | 703 } else if (spaceToPlus && byte == _SPACE) { |
| 704 result.writeCharCode(_PLUS); | 704 result.writeCharCode(_PLUS); |
| 705 } else { | 705 } else { |
| 706 result.writeCharCode(_PERCENT); | 706 result.writeCharCode(_PERCENT); |
| 707 byteToHex(byte, result); | 707 byteToHex(byte, result); |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 return result.toString(); | 710 return result.toString(); |
| 711 } | 711 } |
| 712 } | 712 } |
| OLD | NEW |