Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: frog/leg/lib/core.dart

Issue 9148021: Implement for-in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | frog/leg/resolver.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 void print(var obj) { 5 void print(var obj) {
6 obj = obj.toString(); 6 obj = obj.toString();
7 var hasConsole = JS("bool", @"typeof console == 'object'"); 7 var hasConsole = JS("bool", @"typeof console == 'object'");
8 if (hasConsole) { 8 if (hasConsole) {
9 JS("void", @"console.log($0)", obj); 9 JS("void", @"console.log($0)", obj);
10 } else { 10 } else {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return UNINTERCEPTED(value.toString()); 288 return UNINTERCEPTED(value.toString());
289 } 289 }
290 if (JS("bool", @"$0 === 0 && (1 / $0) < 0", value)) { 290 if (JS("bool", @"$0 === 0 && (1 / $0) < 0", value)) {
291 return "-0.0"; 291 return "-0.0";
292 } 292 }
293 if (value === null) return "null"; 293 if (value === null) return "null";
294 return JS("string", @"String($0)", value); 294 return JS("string", @"String($0)", value);
295 } 295 }
296 296
297 297
298 builtin$iterator$0(var receiver) {
299 if (isJSArray(receiver)) {
300 return new ListIterator(receiver);
301 }
302 return UNINTERCEPTED(receiver.iterator());
303 }
304
305
298 bool isInt(var v) { 306 bool isInt(var v) {
299 return JS("bool", @"($0 | 0) === $1", v, v); 307 return JS("bool", @"($0 | 0) === $1", v, v);
300 } 308 }
301 309
310 /* Include when interfaces are implemented
311 interface Iterable<T> {
312 Iterator<T> iterator();
313 }
314
315 interface Iterator<T> {
316 bool hasNext();
317 T next();
318 }
319 */
302 class int {} 320 class int {}
303 class double {} 321 class double {}
304 class String {} 322 class String {}
305 class bool {} 323 class bool {}
306 class Object {} 324 class Object {}
307 class List<T> { 325 class List<T> /* implements Iterable<T> */ {
308 static void _checkConstructorInput(n) { 326 static void _checkConstructorInput(n) {
309 // TODO(ngeoffray): Inline once we support optional parameters or 327 // TODO(ngeoffray): Inline once we support optional parameters or
310 // bailout. 328 // bailout.
311 if (!isInt(n)) throw "Invalid argument"; 329 if (!isInt(n)) throw "Invalid argument";
312 if (n < 0) throw "Negative size"; 330 if (n < 0) throw "Negative size";
313 } 331 }
314 332
315 factory List(n) { 333 factory List(n) {
316 // TODO(ngeoffray): Adjust to optional parameters. 334 // TODO(ngeoffray): Adjust to optional parameters.
317 if (JS("bool", @"$0 === (void 0)", n)) return JS("Object", @"new Array()"); 335 if (JS("bool", @"$0 === (void 0)", n)) return JS("Object", @"new Array()");
318 _checkConstructorInput(n); 336 _checkConstructorInput(n);
319 return JS("Object", @"new Array($0)", n); 337 return JS("Object", @"new Array($0)", n);
320 } 338 }
321 } 339 }
322 340
341 class ListIterator<T> /* implements Iterator<T> */ {
ngeoffray 2012/01/11 10:09:22 I'd prefer calling it ForeignListIterator.
342 int i;
343 List<T> list;
344 ListIterator(List<T> list) : this.list = list, i = 0;
345 bool hasNext() => i < JS("int", @"$0.length", list);
346 T next() {
347 var value = JS("Object", @"$0[$1]", list, i);
348 i += 1;
349 return value;
350 }
351 }
352
323 class Expect { 353 class Expect {
324 static void equals(var expected, var actual) { 354 static void equals(var expected, var actual) {
325 if (expected == actual) return; 355 if (expected == actual) return;
326 _fail('Expect.equals(expected: <$expected>, actual:<$actual> fails.'); 356 _fail('Expect.equals(expected: <$expected>, actual:<$actual> fails.');
327 } 357 }
328 358
329 static void fail(String message) { 359 static void fail(String message) {
330 _fail("Expect.fail('$message')"); 360 _fail("Expect.fail('$message')");
331 } 361 }
332 362
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } else { 410 } else {
381 return 411 return
382 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); 412 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs);
383 } 413 }
384 } 414 }
385 415
386 int frequency() { 416 int frequency() {
387 return 1000; 417 return 1000;
388 } 418 }
389 } 419 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | frog/leg/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698