| 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  |    9  | 
|   10 part 'bigint.dart'; |   10 part 'bigint.dart'; | 
|   11 part 'case.dart'; |   11 part 'case.dart'; | 
|   12 part 'double.dart'; |   12 part 'double.dart'; | 
|   13 part 'int.dart'; |   13 part 'int.dart'; | 
|   14 part 'string.dart'; |   14 part 'string.dart'; | 
|   15  |   15  | 
|   16 // TODO(sigurdm): move the following a to part file shared with "core.patch" |   16 // TODO(sigurdm): move the following a to part file shared with "core.patch" | 
|   17 // when part files can contain patch-classes. |   17 // when part files can contain patch-classes. | 
|   18  |   18  | 
|   19 @patch external bool identical(Object a, Object b); |   19 @patch external bool identical(Object a, Object b); | 
|   20  |   20  | 
|   21 @patch int identityHashCode(Object object) { |   21 @patch int identityHashCode(Object object) { | 
|   22   if (object is int) return object; |   22   if (object is int) return object; | 
|   23   return _identityHashCode(object); |   23   return _identityHashCode(object); | 
|   24 } |   24 } | 
|   25  |   25  | 
|   26 @fletch.native external _identityHashCode(Object object); |   26 @dartino.native external _identityHashCode(Object object); | 
|   27  |   27  | 
|   28 @patch class Object { |   28 @patch class Object { | 
|   29   @patch String toString() => '[object Object]'; |   29   @patch String toString() => '[object Object]'; | 
|   30  |   30  | 
|   31   @patch int get hashCode => _identityHashCode(this); |   31   @patch int get hashCode => _identityHashCode(this); | 
|   32  |   32  | 
|   33   @patch noSuchMethod(Invocation invocation) { |   33   @patch noSuchMethod(Invocation invocation) { | 
|   34     if (invocation is fletch.FletchInvocation) { |   34     if (invocation is dartino.DartinoInvocation) { | 
|   35       throw invocation.asNoSuchMethodError; |   35       throw invocation.asNoSuchMethodError; | 
|   36     } |   36     } | 
|   37     // TODO(ahe): Get rid of this call. |   37     // TODO(ahe): Get rid of this call. | 
|   38     fletch.unresolved("<unknown>"); |   38     dartino.unresolved("<unknown>"); | 
|   39   } |   39   } | 
|   40  |   40  | 
|   41   // The noSuchMethod helper is automatically called from the |   41   // The noSuchMethod helper is automatically called from the | 
|   42   // trampoline and it is passed the selector. The arguments |   42   // trampoline and it is passed the selector. The arguments | 
|   43   // to the original call are still present on the stack, so |   43   // to the original call are still present on the stack, so | 
|   44   // it is possible to dig them out if need be. |   44   // it is possible to dig them out if need be. | 
|   45   _noSuchMethod(receiver, receiverClass, receiverSelector) { |   45   _noSuchMethod(receiver, receiverClass, receiverSelector) { | 
|   46     // NOTE: The number and type of arguments here must be kept in sync with: |   46     // NOTE: The number and type of arguments here must be kept in sync with: | 
|   47     //     src/vm/interpreter.cc:HandleEnterNoSuchMethod |   47     //     src/vm/interpreter.cc:HandleEnterNoSuchMethod | 
|   48     return noSuchMethod(new fletch.FletchInvocation( |   48     return noSuchMethod(new dartino.DartinoInvocation( | 
|   49         receiver, receiverClass, receiverSelector)); |   49         receiver, receiverClass, receiverSelector)); | 
|   50   } |   50   } | 
|   51  |   51  | 
|   52   // The noSuchMethod trampoline is automatically generated |   52   // The noSuchMethod trampoline is automatically generated | 
|   53   // by the compiler. It calls the noSuchMethod helper and |   53   // by the compiler. It calls the noSuchMethod helper and | 
|   54   // takes care off removing an arbitrary number of arguments |   54   // takes care off removing an arbitrary number of arguments | 
|   55   // from the caller stack before it returns. |   55   // from the caller stack before it returns. | 
|   56   external _noSuchMethodTrampoline(); |   56   external _noSuchMethodTrampoline(); | 
|   57 } |   57 } | 
|   58  |   58  | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  183     } |  183     } | 
|  184     return '[object Object]'; |  184     return '[object Object]'; | 
|  185   } |  185   } | 
|  186  |  186  | 
|  187   @patch StackTrace get stackTrace { |  187   @patch StackTrace get stackTrace { | 
|  188     throw "getter stackTrace is unimplemented"; |  188     throw "getter stackTrace is unimplemented"; | 
|  189   } |  189   } | 
|  190 } |  190 } | 
|  191  |  191  | 
|  192 @patch class Stopwatch { |  192 @patch class Stopwatch { | 
|  193   @patch @fletch.native external static int _now(); |  193   @patch @dartino.native external static int _now(); | 
|  194  |  194  | 
|  195   @patch static int _initTicker() { |  195   @patch static int _initTicker() { | 
|  196     _frequency = _fletchNative_frequency(); |  196     _frequency = _dartinoNative_frequency(); | 
|  197   } |  197   } | 
|  198  |  198  | 
|  199   @fletch.native external static int _fletchNative_frequency(); |  199   @dartino.native external static int _dartinoNative_frequency(); | 
|  200 } |  200 } | 
|  201  |  201  | 
|  202 @patch class List { |  202 @patch class List { | 
|  203   @patch factory List([int length]) { |  203   @patch factory List([int length]) { | 
|  204     return fletch.newList(length); |  204     return dartino.newList(length); | 
|  205   } |  205   } | 
|  206  |  206  | 
|  207   @patch factory List.filled(int length, E fill) { |  207   @patch factory List.filled(int length, E fill) { | 
|  208     // All error handling on the length parameter is done at the implementation |  208     // All error handling on the length parameter is done at the implementation | 
|  209     // of new _List. |  209     // of new _List. | 
|  210     var result = fletch.newList(length); |  210     var result = dartino.newList(length); | 
|  211     if (fill != null) { |  211     if (fill != null) { | 
|  212       for (int i = 0; i < length; i++) { |  212       for (int i = 0; i < length; i++) { | 
|  213         result[i] = fill; |  213         result[i] = fill; | 
|  214       } |  214       } | 
|  215     } |  215     } | 
|  216     return result; |  216     return result; | 
|  217   } |  217   } | 
|  218  |  218  | 
|  219   @patch factory List.from(Iterable elements, {bool growable: true}) { |  219   @patch factory List.from(Iterable elements, {bool growable: true}) { | 
|  220     // TODO(ajohnsen): elements.length can be slow if not a List. Consider |  220     // TODO(ajohnsen): elements.length can be slow if not a List. Consider | 
|  221     // fast-path non-list & growable, and create internal helper for non-list & |  221     // fast-path non-list & growable, and create internal helper for non-list & | 
|  222     // non-growable. |  222     // non-growable. | 
|  223     int length = elements.length; |  223     int length = elements.length; | 
|  224     var list; |  224     var list; | 
|  225     if (growable) { |  225     if (growable) { | 
|  226       list = fletch.newList(null); |  226       list = dartino.newList(null); | 
|  227       list.length = length; |  227       list.length = length; | 
|  228     } else { |  228     } else { | 
|  229       list = fletch.newList(length); |  229       list = dartino.newList(length); | 
|  230     } |  230     } | 
|  231     if (elements is List) { |  231     if (elements is List) { | 
|  232       for (int i = 0; i < length; i++) { |  232       for (int i = 0; i < length; i++) { | 
|  233         list[i] = elements[i]; |  233         list[i] = elements[i]; | 
|  234       } |  234       } | 
|  235     } else { |  235     } else { | 
|  236       int i = 0; |  236       int i = 0; | 
|  237       elements.forEach((e) { list[i++] = e; }); |  237       elements.forEach((e) { list[i++] = e; }); | 
|  238     } |  238     } | 
|  239     return list; |  239     return list; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  282           source.startsWith('+0x')) { |  282           source.startsWith('+0x')) { | 
|  283         if (onError != null) return onError(source); |  283         if (onError != null) return onError(source); | 
|  284         throw new FormatException("Can't parse string as integer", source); |  284         throw new FormatException("Can't parse string as integer", source); | 
|  285       } |  285       } | 
|  286     } else { |  286     } else { | 
|  287       if (radix < 2 || radix > 36) throw new ArgumentError(radix); |  287       if (radix < 2 || radix > 36) throw new ArgumentError(radix); | 
|  288     } |  288     } | 
|  289     return _parse(source, radix, onError); |  289     return _parse(source, radix, onError); | 
|  290   } |  290   } | 
|  291  |  291  | 
|  292   @fletch.native static int _parse( |  292   @dartino.native static int _parse( | 
|  293       String source, |  293       String source, | 
|  294       int radix, |  294       int radix, | 
|  295       int onError(String source)) { |  295       int onError(String source)) { | 
|  296     switch (fletch.nativeError) { |  296     switch (dartino.nativeError) { | 
|  297       case fletch.wrongArgumentType: |  297       case dartino.wrongArgumentType: | 
|  298         throw new ArgumentError(source); |  298         throw new ArgumentError(source); | 
|  299       case fletch.indexOutOfBounds: |  299       case dartino.indexOutOfBounds: | 
|  300         if (onError != null) return onError(source); |  300         if (onError != null) return onError(source); | 
|  301         throw new FormatException("Can't parse string as integer", source); |  301         throw new FormatException("Can't parse string as integer", source); | 
|  302     } |  302     } | 
|  303   } |  303   } | 
|  304  |  304  | 
|  305   @patch factory int.fromEnvironment( |  305   @patch factory int.fromEnvironment( | 
|  306       String name, |  306       String name, | 
|  307       {int defaultValue}) => defaultValue; |  307       {int defaultValue}) => defaultValue; | 
|  308 } |  308 } | 
|  309  |  309  | 
|  310 @patch class double { |  310 @patch class double { | 
|  311   @patch static double parse(String source, [double onError(String source)]) { |  311   @patch static double parse(String source, [double onError(String source)]) { | 
|  312     return _parse(source.trim(), onError); |  312     return _parse(source.trim(), onError); | 
|  313   } |  313   } | 
|  314  |  314  | 
|  315   @fletch.native static double _parse( |  315   @dartino.native static double _parse( | 
|  316       String source, |  316       String source, | 
|  317       double onError(String source)) { |  317       double onError(String source)) { | 
|  318     switch (fletch.nativeError) { |  318     switch (dartino.nativeError) { | 
|  319       case fletch.wrongArgumentType: |  319       case dartino.wrongArgumentType: | 
|  320         throw new ArgumentError(source); |  320         throw new ArgumentError(source); | 
|  321       case fletch.indexOutOfBounds: |  321       case dartino.indexOutOfBounds: | 
|  322         if (onError != null) return onError(source); |  322         if (onError != null) return onError(source); | 
|  323         throw new FormatException("Can't parse string as double", source); |  323         throw new FormatException("Can't parse string as double", source); | 
|  324     } |  324     } | 
|  325   } |  325   } | 
|  326 } |  326 } | 
|  327  |  327  | 
|  328 @patch class DateTime { |  328 @patch class DateTime { | 
|  329   static const _MILLISECOND_INDEX = 0; |  329   static const _MILLISECOND_INDEX = 0; | 
|  330   static const _SECOND_INDEX = 1; |  330   static const _SECOND_INDEX = 1; | 
|  331   static const _MINUTE_INDEX = 2; |  331   static const _MINUTE_INDEX = 2; | 
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  646   static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { |  646   static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { | 
|  647     int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |  647     int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 
|  648     return _timeZoneOffset(equivalentSeconds); |  648     return _timeZoneOffset(equivalentSeconds); | 
|  649   } |  649   } | 
|  650  |  650  | 
|  651   static String _timeZoneName(int millisecondsSinceEpoch) { |  651   static String _timeZoneName(int millisecondsSinceEpoch) { | 
|  652     int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |  652     int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 
|  653     return _timeZone(equivalentSeconds); |  653     return _timeZone(equivalentSeconds); | 
|  654   } |  654   } | 
|  655  |  655  | 
|  656   @fletch.native external static int _getCurrentMs(); |  656   @dartino.native external static int _getCurrentMs(); | 
|  657  |  657  | 
|  658   @fletch.native external static String _timeZone(int clampedSecondsSinceEpoch); |  658   @dartino.native external static String _timeZone(int clampedSecondsSinceEpoch)
     ; | 
|  659  |  659  | 
|  660   @fletch.native external static int _timeZoneOffset( |  660   @dartino.native external static int _timeZoneOffset( | 
|  661       int clampedSecondsSinceEpoch); |  661       int clampedSecondsSinceEpoch); | 
|  662  |  662  | 
|  663   @fletch.native external static int _localTimeZoneOffset(); |  663   @dartino.native external static int _localTimeZoneOffset(); | 
|  664 } |  664 } | 
| OLD | NEW |