public
Last active

Dart Compilation

  • Download Gist
HelloDartTest.dart
Dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Simple test program invoked with an option to eagerly
// compile all code that is loaded in the isolate.
// Compiled using frog, the in-progress self-hosted compiler:
// dart/frog$ ./frogsh --out=hello.js --compile-only samples/hello.dart
 
class HelloDartTest {
static testMain() {
print("Hello, Darter!");
}
}
 
 
main() {
HelloDartTest.testMain();
}
hello.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// ********** Library dart:core **************
// ********** Natives dart:core **************
// ********** Code for Object **************
// ********** Code for BadNumberFormatException **************
function BadNumberFormatException() {}
// ********** Code for top level **************
function print(obj) {
if (typeof console == 'object') {
if (obj) obj = obj.toString();
console.log(obj);
} else {
write(obj);
write('\n');
}
}
// ********** Library dart:coreimpl **************
// ********** Code for NumImplementation **************
NumImplementation = Number;
// ********** Code for StringImplementation **************
StringImplementation = String;
StringImplementation.prototype.contains = function(pattern, startIndex) {
return this.indexOf(pattern, startIndex) >= 0;
}
// ********** Code for top level **************
// ********** Library hello **************
// ********** Code for HelloDartTest **************
function HelloDartTest() {}
HelloDartTest.testMain = function() {
print("Hello, Darter!");
}
// ********** Code for top level **************
function main() {
HelloDartTest.testMain();
}
main();

To everyone checking this out, you can minimize the above all the way down to:

main() => print("hello, Darter!");

Doesn't print() overwrite window.print() in browser implementations? Why do this?

Yeah, you're correct. In this example the output is stomping on window.print. I asked one of our compiler guys and he says this bug is fixed now. It should be renaming functions that collide with ones on window. (The other option the compiler could take is to wrap everything in a big function. The choice between the two is mostly a performance one and we haven't tried comparing yet.)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.