Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 22nd, 2012  |  syntax: None  |  size: 15.80 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //  ********** Library dart:core **************
  2. //  ********** Natives dart:core **************
  3. function $defProp(obj, prop, value) {
  4.   Object.defineProperty(obj, prop,
  5.       {value: value, enumerable: false, writable: true, configurable: true});
  6. }
  7. function $throw(e) {
  8.   // If e is not a value, we can use V8's captureStackTrace utility method.
  9.   // TODO(jmesserly): capture the stack trace on other JS engines.
  10.   if (e && (typeof e == 'object') && Error.captureStackTrace) {
  11.     // TODO(jmesserly): this will clobber the e.stack property
  12.     Error.captureStackTrace(e, $throw);
  13.   }
  14.   throw e;
  15. }
  16. $defProp(Object.prototype, '$index', function(i) {
  17.   $throw(new NoSuchMethodException(this, "operator []", [i]));
  18. });
  19. $defProp(Array.prototype, '$index', function(index) {
  20.   var i = index | 0;
  21.   if (i !== index) {
  22.     throw new IllegalArgumentException('index is not int');
  23.   } else if (i < 0 || i >= this.length) {
  24.     throw new IndexOutOfRangeException(index);
  25.   }
  26.   return this[i];
  27. });
  28. $defProp(String.prototype, '$index', function(i) {
  29.   return this[i];
  30. });
  31. function $add$complex$(x, y) {
  32.   if (typeof(x) == 'number') {
  33.     $throw(new IllegalArgumentException(y));
  34.   } else if (typeof(x) == 'string') {
  35.     var str = (y == null) ? 'null' : y.toString();
  36.     if (typeof(str) != 'string') {
  37.       throw new Error("calling toString() on right hand operand of operator " +
  38.       "+ did not return a String");
  39.     }
  40.     return x + str;
  41.   } else if (typeof(x) == 'object') {
  42.     return x.$add(y);
  43.   } else {
  44.     $throw(new NoSuchMethodException(x, "operator +", [y]));
  45.   }
  46. }
  47.  
  48. function $add$(x, y) {
  49.   if (typeof(x) == 'number' && typeof(y) == 'number') return x + y;
  50.   return $add$complex$(x, y);
  51. }
  52. function $eq$(x, y) {
  53.   if (x == null) return y == null;
  54.   return (typeof(x) != 'object') ? x === y : x.$eq(y);
  55. }
  56. // TODO(jimhug): Should this or should it not match equals?
  57. $defProp(Object.prototype, '$eq', function(other) {
  58.   return this === other;
  59. });
  60. // ********** Code for Object **************
  61. $defProp(Object.prototype, "is$Collection", function() {
  62.   return false;
  63. });
  64. $defProp(Object.prototype, "is$List", function() {
  65.   return false;
  66. });
  67. $defProp(Object.prototype, "is$Map", function() {
  68.   return false;
  69. });
  70. // ********** Code for IndexOutOfRangeException **************
  71. function IndexOutOfRangeException(_index) {
  72.   this._index = _index;
  73. }
  74. IndexOutOfRangeException.prototype.is$IndexOutOfRangeException = function(){return true};
  75. IndexOutOfRangeException.prototype.toString = function() {
  76.   return ("IndexOutOfRangeException: " + this._index);
  77. }
  78. // ********** Code for NoSuchMethodException **************
  79. function NoSuchMethodException(_receiver, _functionName, _arguments, _existingArgumentNames) {
  80.   this._receiver = _receiver;
  81.   this._functionName = _functionName;
  82.   this._arguments = _arguments;
  83.   this._existingArgumentNames = _existingArgumentNames;
  84. }
  85. NoSuchMethodException.prototype.is$NoSuchMethodException = function(){return true};
  86. NoSuchMethodException.prototype.toString = function() {
  87.   var sb = new StringBufferImpl("");
  88.   for (var i = (0);
  89.    i < this._arguments.get$length(); i++) {
  90.     if (i > (0)) {
  91.       sb.add(", ");
  92.     }
  93.     sb.add(this._arguments.$index(i));
  94.   }
  95.   if (null == this._existingArgumentNames) {
  96.     return (("NoSuchMethodException : method not found: '" + this._functionName + "'\n") + ("Receiver: " + this._receiver + "\n") + ("Arguments: [" + sb + "]"));
  97.   }
  98.   else {
  99.     var actualParameters = sb.toString();
  100.     sb = new StringBufferImpl("");
  101.     for (var i = (0);
  102.      i < this._existingArgumentNames.get$length(); i++) {
  103.       if (i > (0)) {
  104.         sb.add(", ");
  105.       }
  106.       sb.add(this._existingArgumentNames.$index(i));
  107.     }
  108.     var formalParameters = sb.toString();
  109.     return ("NoSuchMethodException: incorrect number of arguments passed to " + ("method named '" + this._functionName + "'\nReceiver: " + this._receiver + "\n") + ("Tried calling: " + this._functionName + "(" + actualParameters + ")\n") + ("Found: " + this._functionName + "(" + formalParameters + ")"));
  110.   }
  111. }
  112. // ********** Code for ClosureArgumentMismatchException **************
  113. function ClosureArgumentMismatchException() {
  114.  
  115. }
  116. ClosureArgumentMismatchException.prototype.toString = function() {
  117.   return "Closure argument mismatch";
  118. }
  119. // ********** Code for IllegalArgumentException **************
  120. function IllegalArgumentException(arg) {
  121.   this._arg = arg;
  122. }
  123. IllegalArgumentException.prototype.is$IllegalArgumentException = function(){return true};
  124. IllegalArgumentException.prototype.toString = function() {
  125.   return ("Illegal argument(s): " + this._arg);
  126. }
  127. // ********** Code for NoMoreElementsException **************
  128. function NoMoreElementsException() {
  129.  
  130. }
  131. NoMoreElementsException.prototype.toString = function() {
  132.   return "NoMoreElementsException";
  133. }
  134. // ********** Code for dart_core_Function **************
  135. Function.prototype.to$call$1 = function() {
  136.   this.call$1 = this._genStub(1);
  137.   this.to$call$1 = function() { return this.call$1; };
  138.   return this.call$1;
  139. };
  140. Function.prototype.call$1 = function($0) {
  141.   return this.to$call$1()($0);
  142. };
  143. function to$call$1(f) { return f && f.to$call$1(); }
  144. Function.prototype.to$call$2 = function() {
  145.   this.call$2 = this._genStub(2);
  146.   this.to$call$2 = function() { return this.call$2; };
  147.   return this.call$2;
  148. };
  149. Function.prototype.call$2 = function($0, $1) {
  150.   return this.to$call$2()($0, $1);
  151. };
  152. function to$call$2(f) { return f && f.to$call$2(); }
  153. // ********** Code for top level **************
  154. function print$(obj) {
  155.   return _print(obj);
  156. }
  157. function _print(obj) {
  158.   if (typeof console == 'object') {
  159.     if (obj) obj = obj.toString();
  160.     console.log(obj);
  161.   } else if (typeof write === 'function') {
  162.     write(obj);
  163.     write('\n');
  164.   }
  165. }
  166. //  ********** Library dart:coreimpl **************
  167. // ********** Code for ListFactory **************
  168. ListFactory = Array;
  169. $defProp(ListFactory.prototype, "is$List", function(){return true});
  170. $defProp(ListFactory.prototype, "is$Collection", function(){return true});
  171. $defProp(ListFactory.prototype, "get$length", function() { return this.length; });
  172. $defProp(ListFactory.prototype, "set$length", function(value) { return this.length = value; });
  173. $defProp(ListFactory.prototype, "add", function(value) {
  174.   this.push(value);
  175. });
  176. $defProp(ListFactory.prototype, "clear", function() {
  177.   this.set$length((0));
  178. });
  179. $defProp(ListFactory.prototype, "removeLast", function() {
  180.   return this.pop();
  181. });
  182. $defProp(ListFactory.prototype, "iterator", function() {
  183.   return new ListIterator(this);
  184. });
  185. $defProp(ListFactory.prototype, "toString", function() {
  186.   return Collections.collectionToString(this);
  187. });
  188. // ********** Code for ListIterator **************
  189. function ListIterator(array) {
  190.   this._array = array;
  191.   this._pos = (0);
  192. }
  193. ListIterator.prototype.hasNext = function() {
  194.   return this._array.get$length() > this._pos;
  195. }
  196. ListIterator.prototype.next = function() {
  197.   if (!this.hasNext()) {
  198.     $throw(const$0000);
  199.   }
  200.   return this._array.$index(this._pos++);
  201. }
  202. // ********** Code for NumImplementation **************
  203. NumImplementation = Number;
  204. // ********** Code for Collections **************
  205. function Collections() {}
  206. Collections.collectionToString = function(c) {
  207.   var result = new StringBufferImpl("");
  208.   Collections._emitCollection(c, result, new Array());
  209.   return result.toString();
  210. }
  211. Collections._emitCollection = function(c, result, visiting) {
  212.   visiting.add(c);
  213.   var isList = !!(c && c.is$List());
  214.   result.add(isList ? "[" : "{");
  215.   var first = true;
  216.   for (var $$i = c.iterator(); $$i.hasNext(); ) {
  217.     var e = $$i.next();
  218.     if (!first) {
  219.       result.add(", ");
  220.     }
  221.     first = false;
  222.     Collections._emitObject(e, result, visiting);
  223.   }
  224.   result.add(isList ? "]" : "}");
  225.   visiting.removeLast();
  226. }
  227. Collections._emitObject = function(o, result, visiting) {
  228.   if (!!(o && o.is$Collection())) {
  229.     if (Collections._containsRef(visiting, o)) {
  230.       result.add(!!(o && o.is$List()) ? "[...]" : "{...}");
  231.     }
  232.     else {
  233.       Collections._emitCollection(o, result, visiting);
  234.     }
  235.   }
  236.   else if (!!(o && o.is$Map())) {
  237.     if (Collections._containsRef(visiting, o)) {
  238.       result.add("{...}");
  239.     }
  240.     else {
  241.       Maps._emitMap(o, result, visiting);
  242.     }
  243.   }
  244.   else {
  245.     result.add($eq$(o) ? "null" : o);
  246.   }
  247. }
  248. Collections._containsRef = function(c, ref) {
  249.   for (var $$i = c.iterator(); $$i.hasNext(); ) {
  250.     var e = $$i.next();
  251.     if ((null == e ? null == (ref) : e === ref)) return true;
  252.   }
  253.   return false;
  254. }
  255. // ********** Code for HashMapImplementation **************
  256. function HashMapImplementation() {}
  257. HashMapImplementation.prototype.is$Map = function(){return true};
  258. HashMapImplementation.prototype.forEach = function(f) {
  259.   var length = this._keys.get$length();
  260.   for (var i = (0);
  261.    i < length; i++) {
  262.     var key = this._keys.$index(i);
  263.     if ((null != key) && ((null == key ? null != (const$0001) : key !== const$0001))) {
  264.       f(key, this._values.$index(i));
  265.     }
  266.   }
  267. }
  268. HashMapImplementation.prototype.toString = function() {
  269.   return Maps.mapToString(this);
  270. }
  271. // ********** Code for _DeletedKeySentinel **************
  272. function _DeletedKeySentinel() {
  273.  
  274. }
  275. // ********** Code for Maps **************
  276. function Maps() {}
  277. Maps.mapToString = function(m) {
  278.   var result = new StringBufferImpl("");
  279.   Maps._emitMap(m, result, new Array());
  280.   return result.toString();
  281. }
  282. Maps._emitMap = function(m, result, visiting) {
  283.   visiting.add(m);
  284.   result.add("{");
  285.   var first = true;
  286.   m.forEach((function (k, v) {
  287.     if (!first) {
  288.       result.add(", ");
  289.     }
  290.     first = false;
  291.     Collections._emitObject(k, result, visiting);
  292.     result.add(": ");
  293.     Collections._emitObject(v, result, visiting);
  294.   })
  295.   );
  296.   result.add("}");
  297.   visiting.removeLast();
  298. }
  299. // ********** Code for DoubleLinkedQueue **************
  300. function DoubleLinkedQueue() {}
  301. DoubleLinkedQueue.prototype.is$Collection = function(){return true};
  302. DoubleLinkedQueue.prototype.iterator = function() {
  303.   return new _DoubleLinkedQueueIterator(this._sentinel);
  304. }
  305. DoubleLinkedQueue.prototype.toString = function() {
  306.   return Collections.collectionToString(this);
  307. }
  308. // ********** Code for _DoubleLinkedQueueIterator **************
  309. function _DoubleLinkedQueueIterator(_sentinel) {
  310.   this._sentinel = _sentinel;
  311.   this._currentEntry = this._sentinel;
  312. }
  313. _DoubleLinkedQueueIterator.prototype.hasNext = function() {
  314.   var $0;
  315.   return (($0 = this._currentEntry._next) == null ? null != (this._sentinel) : $0 !== this._sentinel);
  316. }
  317. _DoubleLinkedQueueIterator.prototype.next = function() {
  318.   if (!this.hasNext()) {
  319.     $throw(const$0000);
  320.   }
  321.   this._currentEntry = this._currentEntry._next;
  322.   return this._currentEntry.get$element();
  323. }
  324. // ********** Code for StringBufferImpl **************
  325. function StringBufferImpl(content) {
  326.   this.clear();
  327.   this.add(content);
  328. }
  329. StringBufferImpl.prototype.add = function(obj) {
  330.   var str = obj.toString();
  331.   if (null == str || str.isEmpty()) return this;
  332.   this._buffer.add(str);
  333.   this._length = this._length + str.length;
  334.   return this;
  335. }
  336. StringBufferImpl.prototype.clear = function() {
  337.   this._buffer = new Array();
  338.   this._length = (0);
  339.   return this;
  340. }
  341. StringBufferImpl.prototype.toString = function() {
  342.   if (this._buffer.get$length() == (0)) return "";
  343.   if (this._buffer.get$length() == (1)) return this._buffer.$index((0));
  344.   var result = StringBase.concatAll(this._buffer);
  345.   this._buffer.clear();
  346.   this._buffer.add(result);
  347.   return result;
  348. }
  349. // ********** Code for StringBase **************
  350. function StringBase() {}
  351. StringBase.join = function(strings, separator) {
  352.   if (strings.get$length() == (0)) return "";
  353.   var s = strings.$index((0));
  354.   for (var i = (1);
  355.    i < strings.get$length(); i++) {
  356.     s = $add$($add$(s, separator), strings.$index(i));
  357.   }
  358.   return s;
  359. }
  360. StringBase.concatAll = function(strings) {
  361.   return StringBase.join(strings, "");
  362. }
  363. // ********** Code for StringImplementation **************
  364. StringImplementation = String;
  365. StringImplementation.prototype.isEmpty = function() {
  366.   return this.length == (0);
  367. }
  368. // ********** Code for _ArgumentMismatchException **************
  369. /** Implements extends for Dart classes on JavaScript prototypes. */
  370. function $inherits(child, parent) {
  371.   if (child.prototype.__proto__) {
  372.     child.prototype.__proto__ = parent.prototype;
  373.   } else {
  374.     function tmp() {};
  375.     tmp.prototype = parent.prototype;
  376.     child.prototype = new tmp();
  377.     child.prototype.constructor = child;
  378.   }
  379. }
  380. $inherits(_ArgumentMismatchException, ClosureArgumentMismatchException);
  381. function _ArgumentMismatchException(_message) {
  382.   this._dart_coreimpl_message = _message;
  383.   ClosureArgumentMismatchException.call(this);
  384. }
  385. _ArgumentMismatchException.prototype.toString = function() {
  386.   return ("Closure argument mismatch: " + this._dart_coreimpl_message);
  387. }
  388. // ********** Code for _FunctionImplementation **************
  389. _FunctionImplementation = Function;
  390. _FunctionImplementation.prototype._genStub = function(argsLength, names) {
  391.       // Fast path #1: if no named arguments and arg count matches.
  392.       var thisLength = this.$length || this.length;
  393.       if (thisLength == argsLength && !names) {
  394.         return this;
  395.       }
  396.  
  397.       var paramsNamed = this.$optional ? (this.$optional.length / 2) : 0;
  398.       var paramsBare = thisLength - paramsNamed;
  399.       var argsNamed = names ? names.length : 0;
  400.       var argsBare = argsLength - argsNamed;
  401.  
  402.       // Check we got the right number of arguments
  403.       if (argsBare < paramsBare || argsLength > thisLength ||
  404.           argsNamed > paramsNamed) {
  405.         return function() {
  406.           $throw(new _ArgumentMismatchException(
  407.             'Wrong number of arguments to function. Expected ' + paramsBare +
  408.             ' positional arguments and at most ' + paramsNamed +
  409.             ' named arguments, but got ' + argsBare +
  410.             ' positional arguments and ' + argsNamed + ' named arguments.'));
  411.         };
  412.       }
  413.  
  414.       // First, fill in all of the default values
  415.       var p = new Array(paramsBare);
  416.       if (paramsNamed) {
  417.         p = p.concat(this.$optional.slice(paramsNamed));
  418.       }
  419.       // Fill in positional args
  420.       var a = new Array(argsLength);
  421.       for (var i = 0; i < argsBare; i++) {
  422.         p[i] = a[i] = '$' + i;
  423.       }
  424.       // Then overwrite with supplied values for optional args
  425.       var lastParameterIndex;
  426.       var namesInOrder = true;
  427.       for (var i = 0; i < argsNamed; i++) {
  428.         var name = names[i];
  429.         a[i + argsBare] = name;
  430.         var j = this.$optional.indexOf(name);
  431.         if (j < 0 || j >= paramsNamed) {
  432.           return function() {
  433.             $throw(new _ArgumentMismatchException(
  434.               'Named argument "' + name + '" was not expected by function.' +
  435.               ' Did you forget to mark the function parameter [optional]?'));
  436.           };
  437.         } else if (lastParameterIndex && lastParameterIndex > j) {
  438.           namesInOrder = false;
  439.         }
  440.         p[j + paramsBare] = name;
  441.         lastParameterIndex = j;
  442.       }
  443.  
  444.       if (thisLength == argsLength && namesInOrder) {
  445.         // Fast path #2: named arguments, but they're in order and all supplied.
  446.         return this;
  447.       }
  448.  
  449.       // Note: using Function instead of 'eval' to get a clean scope.
  450.       // TODO(jmesserly): evaluate the performance of these stubs.
  451.       var f = 'function(' + a.join(',') + '){return $f(' + p.join(',') + ');}';
  452.       return new Function('$f', 'return ' + f + '').call(null, this);
  453.    
  454. }
  455. // ********** Code for top level **************
  456. //  ********** Library hello **************
  457. // ********** Code for HelloDartTest **************
  458. function HelloDartTest() {}
  459. HelloDartTest.testMain = function() {
  460.   print$("Hello, Darter!");
  461. }
  462. // ********** Code for top level **************
  463. function main() {
  464.   HelloDartTest.testMain();
  465. }
  466. //  ********** Globals **************
  467. function $static_init(){
  468. }
  469. var const$0000 = Object.create(NoMoreElementsException.prototype, {});
  470. var const$0001 = Object.create(_DeletedKeySentinel.prototype, {});
  471. $static_init();
  472. if (typeof window != 'undefined' && typeof document != 'undefined' &&
  473.     window.addEventListener && document.readyState == 'loading') {
  474.   window.addEventListener('DOMContentLoaded', function(e) {
  475.     main();
  476.   });
  477. } else {
  478.   main();
  479. }