Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // TODO(ngeoffray): enable when the parser accepts it. | 6 // TODO(ngeoffray): enable when the parser accepts it. |
| 7 // obj = obj.toString(); | 7 // obj = obj.toString(); |
| 8 var hasConsole = JS(@"typeof console == 'object'"); | 8 var hasConsole = JS(@"typeof console == 'object'"); |
| 9 if (hasConsole) { | 9 if (hasConsole) { |
| 10 JS(@"console.log($0)", obj); | 10 JS(@"console.log($0)", obj); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 return JS(@"$0.length", receiver); | 238 return JS(@"$0.length", receiver); |
| 239 } | 239 } |
| 240 throw "Unimplemented user-defined length."; | 240 throw "Unimplemented user-defined length."; |
| 241 } | 241 } |
| 242 | 242 |
| 243 class int {} | 243 class int {} |
| 244 class double {} | 244 class double {} |
| 245 class String {} | 245 class String {} |
| 246 class bool {} | 246 class bool {} |
| 247 class Object {} | 247 class Object {} |
| 248 class List<T> {} | 248 class List<T> { |
| 249 factory List(int n) { | |
| 250 return JS(@"new Array($0)", n); | |
|
kasperl
2011/12/22 11:34:42
Should we be checking that i is an int here (at le
ngeoffray
2011/12/22 13:07:02
Done.
| |
| 251 } | |
| 252 } | |
| 249 | 253 |
| 250 class Stopwatch { | 254 class Stopwatch { |
| 251 double startMs; | 255 double startMs; |
| 252 double elapsedMs; | 256 double elapsedMs; |
| 253 | 257 |
| 254 Stopwatch() { | 258 Stopwatch() { |
| 255 elapsedMs = 0.0; | 259 elapsedMs = 0.0; |
| 256 } | 260 } |
| 257 | 261 |
| 258 void start() { | 262 void start() { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 286 return JS(@"Math.floor($0)", elapsedMs); | 290 return JS(@"Math.floor($0)", elapsedMs); |
| 287 } else { | 291 } else { |
| 288 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); | 292 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); |
| 289 } | 293 } |
| 290 } | 294 } |
| 291 | 295 |
| 292 int frequency() { | 296 int frequency() { |
| 293 return 1000; | 297 return 1000; |
| 294 } | 298 } |
| 295 } | 299 } |
| OLD | NEW |