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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 } | 235 } |
| 236 | 236 |
| 237 | 237 |
| 238 builtin$get$length(var receiver) { | 238 builtin$get$length(var receiver) { |
| 239 if (JS(@"typeof $0 === 'string'", receiver) || isJSArray(receiver)) { | 239 if (JS(@"typeof $0 === 'string'", receiver) || isJSArray(receiver)) { |
| 240 return JS(@"$0.length", receiver); | 240 return JS(@"$0.length", receiver); |
| 241 } | 241 } |
| 242 throw "Unimplemented user-defined length."; | 242 throw "Unimplemented user-defined length."; |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool isInt(var v) { | |
| 246 return JS(@"($0 | 0) === $1", v, v); | |
|
ahe
2011/12/22 14:18:05
Why not:
JS(@"($0 | 0) === $0", v);
floitsch
2011/12/22 14:36:19
I asked him to do it this way. This way generating
ahe
2011/12/22 14:41:22
I'm not sure I understand. Are you saying that you
floitsch
2011/12/22 15:13:21
sorry for the confusion. I asked him to do b. I fi
| |
| 247 } | |
| 248 | |
| 245 class int {} | 249 class int {} |
| 246 class double {} | 250 class double {} |
| 247 class String {} | 251 class String {} |
| 248 class bool {} | 252 class bool {} |
| 249 class Object {} | 253 class Object {} |
| 250 class List<T> {} | 254 class List<T> { |
| 255 factory List(int n) { | |
| 256 if (!isInt(n)) throw "Invalid argument"; | |
| 257 if (n < 0) throw "Negative size"; | |
| 258 return JS(@"new Array($0)", n); | |
| 259 } | |
| 260 } | |
| 251 | 261 |
| 252 class Expect { | 262 class Expect { |
| 253 static void equals(var expected, var actual) { | 263 static void equals(var expected, var actual) { |
| 254 if (expected == actual) return; | 264 if (expected == actual) return; |
| 255 _fail('Expect.equals(expected: <' + expected.toString() + | 265 _fail('Expect.equals(expected: <' + expected.toString() + |
| 256 '>, actual:<' + actual.toString() + '> fails.'); | 266 '>, actual:<' + actual.toString() + '> fails.'); |
| 257 } | 267 } |
| 258 | 268 |
| 259 static void fail(String message) { | 269 static void fail(String message) { |
| 260 _fail("Expect.fail('" + message + "')"); | 270 _fail("Expect.fail('" + message + "')"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 return JS(@"Math.floor($0)", elapsedMs); | 314 return JS(@"Math.floor($0)", elapsedMs); |
| 305 } else { | 315 } else { |
| 306 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); | 316 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); |
| 307 } | 317 } |
| 308 } | 318 } |
| 309 | 319 |
| 310 int frequency() { | 320 int frequency() { |
| 311 return 1000; | 321 return 1000; |
| 312 } | 322 } |
| 313 } | 323 } |
| OLD | NEW |