| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // BSD-style license that can be found in the LICENSE file. |  | 
| 4 |  | 
| 5 #library("dart:core"); |  | 
| 6 #import("dart:coreimpl"); |  | 
| 7 |  | 
| 8 // TODO(jimhug): Better way to map in standard corelib |  | 
| 9 #source("../../corelib/src/bool.dart"); |  | 
| 10 #source("../../corelib/src/collection.dart"); |  | 
| 11 #source("../../corelib/src/comparable.dart"); |  | 
| 12 #source("../../corelib/src/date.dart"); |  | 
| 13 #source("../../corelib/src/double.dart"); |  | 
| 14 #source("../../corelib/src/duration.dart"); |  | 
| 15 #source("../../corelib/src/exceptions.dart"); |  | 
| 16 #source("../../corelib/src/expect.dart"); |  | 
| 17 #source("../../corelib/src/function.dart"); |  | 
| 18 #source("../../corelib/src/future.dart"); |  | 
| 19 #source("../../corelib/src/hashable.dart"); |  | 
| 20 #source("../../corelib/src/int.dart"); |  | 
| 21 #source("../../corelib/src/iterable.dart"); |  | 
| 22 #source("../../corelib/src/iterator.dart"); |  | 
| 23 #source("../../corelib/src/list.dart"); |  | 
| 24 #source("../../corelib/src/map.dart"); |  | 
| 25 #source("math.dart"); // overriden to be more directly native |  | 
| 26 #source("natives.dart"); // native helpers generated by the compiler |  | 
| 27 #source("num.dart"); // overriden to include int members on num - weird typing |  | 
| 28 #source("../../corelib/src/options.dart"); |  | 
| 29 #source("../../corelib/src/pattern.dart"); |  | 
| 30 #source("../../corelib/src/queue.dart"); |  | 
| 31 #source("../../corelib/src/regexp.dart"); |  | 
| 32 #source("../../corelib/src/set.dart"); |  | 
| 33 #source("../../corelib/src/stopwatch.dart"); |  | 
| 34 #source("../../corelib/src/string.dart"); |  | 
| 35 #source("../../corelib/src/strings.dart"); |  | 
| 36 #source("../../corelib/src/string_buffer.dart"); |  | 
| 37 |  | 
| 38 // TODO(jimhug): Ad-hoc cut-paste-and-edit from compiler/lib below: |  | 
| 39 // Conceptual change is moving to more true natives. |  | 
| 40 |  | 
| 41 /** |  | 
| 42  * The class [Clock] provides access to a monotonically incrementing clock |  | 
| 43  * device. |  | 
| 44  */ |  | 
| 45 class Clock { |  | 
| 46   /** Returns the current clock tick. */ |  | 
| 47   static int now() native 'return new Date().getTime();'; |  | 
| 48 |  | 
| 49   /** Returns the frequency of clock ticks in Hz. */ |  | 
| 50   // TODO(jimhug): Why isn't this a property? |  | 
| 51   static int frequency() => 1000; |  | 
| 52 } |  | 
| 53 |  | 
| 54 // TODO(jmesserly): this is working around a name conflict with "window.print". |  | 
| 55 void print(Object obj) => _print(obj); |  | 
| 56 void _print(Object obj) native @'''if (typeof console == 'object') { |  | 
| 57   if (obj) obj = obj.toString(); |  | 
| 58   console.log(obj); |  | 
| 59 } else if (typeof write === 'function') { |  | 
| 60   write(obj); |  | 
| 61   write('\n'); |  | 
| 62 }''' { |  | 
| 63   // ensure toString is generated |  | 
| 64   obj.toString(); |  | 
| 65 } |  | 
| 66 |  | 
| 67 // Exceptions thrown by the generated JS code. |  | 
| 68 |  | 
| 69 class AssertionError { |  | 
| 70   final String failedAssertion; |  | 
| 71 |  | 
| 72   // TODO(jmesserly): I don't think these should be here. They are properties of |  | 
| 73   // the stack trace |  | 
| 74   final String url; |  | 
| 75   final int line; |  | 
| 76   final int column; |  | 
| 77 |  | 
| 78   AssertionError._internal(this.failedAssertion, this.url, this.line, this.colum
     n); |  | 
| 79 |  | 
| 80   String toString() { |  | 
| 81     return "Failed assertion: '$failedAssertion' is not true " + |  | 
| 82         "in $url at line $line, column $column."; |  | 
| 83   } |  | 
| 84 } |  | 
| 85 |  | 
| 86 // TODO(jmesserly): fix the strange interaction with JS TypeError, such as |  | 
| 87 // toString(). Ideally this would generate to a different JS name but I'm not |  | 
| 88 // sure how to force that. |  | 
| 89 class TypeError extends AssertionError native 'TypeError' { |  | 
| 90   final String srcType; |  | 
| 91   final String dstType; |  | 
| 92 |  | 
| 93   // TODO: make this non-native once $typeNameOf and toString issues are fixed. |  | 
| 94   TypeError._internal(Object src, String dstType) native @''' |  | 
| 95 this.srcType = (src == null ? "Null" : src.$typeNameOf()); |  | 
| 96 this.dstType = dstType; |  | 
| 97 this.toString = function() { |  | 
| 98   return ("Failed type check: type " + this.srcType + |  | 
| 99       " is not assignable to type " + this.dstType); |  | 
| 100 }'''; |  | 
| 101 } |  | 
| 102 |  | 
| 103 class FallThroughError { |  | 
| 104   const FallThroughError(); |  | 
| 105 |  | 
| 106   String toString() => "Switch case fall-through."; |  | 
| 107 } |  | 
| 108 |  | 
| 109 // Dart core library. |  | 
| 110 |  | 
| 111 class Object native "Object" { |  | 
| 112 |  | 
| 113   const Object() native; |  | 
| 114 |  | 
| 115   bool operator ==(Object other) native; |  | 
| 116   String toString() native; |  | 
| 117 |  | 
| 118   // TODO(jmesserly): optimize this. No need to call it, unless it's overridden. |  | 
| 119   // Notes: "use strict" prevents boxing. |  | 
| 120   // The Dart "return this" might help with type inference. |  | 
| 121   get dynamic() native '"use strict"; return this;' { return this; } |  | 
| 122 |  | 
| 123   // TODO(jmesserly): add named args. For now stay compatible with the VM. |  | 
| 124   noSuchMethod(String name, List args) { |  | 
| 125     throw new NoSuchMethodException(this, name, args); |  | 
| 126   } |  | 
| 127 } |  | 
| 128 |  | 
| 129 void _assert(var test, String text, String url, int line, int column) { |  | 
| 130   if (test is Function) test = test(); |  | 
| 131   if (!test) throw new AssertionError._internal(text, url, line, column); |  | 
| 132 } |  | 
| OLD | NEW | 
|---|