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

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

Issue 9027002: Support factory methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 | « frog/leg/emitter.dart ('k') | frog/leg/namer.dart » ('j') | no next file with comments »
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 // 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
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);
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
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 }
OLDNEW
« no previous file with comments | « frog/leg/emitter.dart ('k') | frog/leg/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698