Created
May 10, 2012 21:33
-
-
Save usagi/2656043 to your computer and use it in GitHub Desktop.
hello.dart to hello.dart.js using frogc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
var name = 'World'; | |
print('Hello, ${name}!'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function $defProp(obj, prop, value) { | |
Object.defineProperty(obj, prop, | |
{value: value, enumerable: false, writable: true, configurable: true}); | |
} | |
function $throw(e) { | |
// If e is not a value, we can use V8's captureStackTrace utility method. | |
// TODO(jmesserly): capture the stack trace on other JS engines. | |
if (e && (typeof e == 'object') && Error.captureStackTrace) { | |
// TODO(jmesserly): this will clobber the e.stack property | |
Error.captureStackTrace(e, $throw); | |
} | |
throw e; | |
} | |
$defProp(Object.prototype, '$index', function(i) { | |
$throw(new NoSuchMethodException(this, "operator []", [i])); | |
}); | |
$defProp(Array.prototype, '$index', function(index) { | |
var i = index | 0; | |
if (i !== index) { | |
throw new IllegalArgumentException('index is not int'); | |
} else if (i < 0 || i >= this.length) { | |
throw new IndexOutOfRangeException(index); | |
} | |
return this[i]; | |
}); | |
$defProp(String.prototype, '$index', function(i) { | |
return this[i]; | |
}); | |
function $add$complex$(x, y) { | |
if (typeof(x) == 'number') { | |
$throw(new IllegalArgumentException(y)); | |
} else if (typeof(x) == 'string') { | |
var str = (y == null) ? 'null' : y.toString(); | |
if (typeof(str) != 'string') { | |
throw new Error("calling toString() on right hand operand of operator " + | |
"+ did not return a String"); | |
} | |
return x + str; | |
} else if (typeof(x) == 'object') { | |
return x.$add(y); | |
} else { | |
$throw(new NoSuchMethodException(x, "operator +", [y])); | |
} | |
} | |
function $add$(x, y) { | |
if (typeof(x) == 'number' && typeof(y) == 'number') return x + y; | |
return $add$complex$(x, y); | |
} | |
function $eq$(x, y) { | |
if (x == null) return y == null; | |
return (typeof(x) != 'object') ? x === y : x.$eq(y); | |
} | |
// TODO(jimhug): Should this or should it not match equals? | |
$defProp(Object.prototype, '$eq', function(other) { | |
return this === other; | |
}); | |
/** Implements extends for Dart classes on JavaScript prototypes. */ | |
function $inherits(child, parent) { | |
if (child.prototype.__proto__) { | |
child.prototype.__proto__ = parent.prototype; | |
} else { | |
function tmp() {}; | |
tmp.prototype = parent.prototype; | |
child.prototype = new tmp(); | |
child.prototype.constructor = child; | |
} | |
} | |
$defProp(Object.prototype, "is$Collection", function() { | |
return false; | |
}); | |
$defProp(Object.prototype, "is$List", function() { | |
return false; | |
}); | |
$defProp(Object.prototype, "is$Map", function() { | |
return false; | |
}); | |
function IndexOutOfRangeException(_index) { | |
this._index = _index; | |
} | |
IndexOutOfRangeException.prototype.is$IndexOutOfRangeException = function(){return true}; | |
IndexOutOfRangeException.prototype.toString = function() { | |
return ("IndexOutOfRangeException: " + this._index); | |
} | |
function NoSuchMethodException(_receiver, _functionName, _arguments, _existingArgumentNames) { | |
this._receiver = _receiver; | |
this._functionName = _functionName; | |
this._arguments = _arguments; | |
this._existingArgumentNames = _existingArgumentNames; | |
} | |
NoSuchMethodException.prototype.is$NoSuchMethodException = function(){return true}; | |
NoSuchMethodException.prototype.toString = function() { | |
var sb = new StringBufferImpl(""); | |
for (var i = (0); | |
i < this._arguments.get$length(); i++) { | |
if (i > (0)) { | |
sb.add(", "); | |
} | |
sb.add(this._arguments.$index(i)); | |
} | |
if (null == this._existingArgumentNames) { | |
return (("NoSuchMethodException : method not found: '" + this._functionName + "'\n") + ("Receiver: " + this._receiver + "\n") + ("Arguments: [" + sb + "]")); | |
} | |
else { | |
var actualParameters = sb.toString(); | |
sb = new StringBufferImpl(""); | |
for (var i = (0); | |
i < this._existingArgumentNames.get$length(); i++) { | |
if (i > (0)) { | |
sb.add(", "); | |
} | |
sb.add(this._existingArgumentNames.$index(i)); | |
} | |
var formalParameters = sb.toString(); | |
return ("NoSuchMethodException: incorrect number of arguments passed to " + ("method named '" + this._functionName + "'\nReceiver: " + this._receiver + "\n") + ("Tried calling: " + this._functionName + "(" + actualParameters + ")\n") + ("Found: " + this._functionName + "(" + formalParameters + ")")); | |
} | |
} | |
function ClosureArgumentMismatchException() { | |
} | |
ClosureArgumentMismatchException.prototype.toString = function() { | |
return "Closure argument mismatch"; | |
} | |
function IllegalArgumentException(arg) { | |
this._arg = arg; | |
} | |
IllegalArgumentException.prototype.is$IllegalArgumentException = function(){return true}; | |
IllegalArgumentException.prototype.toString = function() { | |
return ("Illegal argument(s): " + this._arg); | |
} | |
function NoMoreElementsException() { | |
} | |
NoMoreElementsException.prototype.toString = function() { | |
return "NoMoreElementsException"; | |
} | |
Function.prototype.to$call$1 = function() { | |
this.call$1 = this._genStub(1); | |
this.to$call$1 = function() { return this.call$1; }; | |
return this.call$1; | |
}; | |
Function.prototype.call$1 = function($0) { | |
return this.to$call$1()($0); | |
}; | |
function to$call$1(f) { return f && f.to$call$1(); } | |
Function.prototype.to$call$2 = function() { | |
this.call$2 = this._genStub(2); | |
this.to$call$2 = function() { return this.call$2; }; | |
return this.call$2; | |
}; | |
Function.prototype.call$2 = function($0, $1) { | |
return this.to$call$2()($0, $1); | |
}; | |
function to$call$2(f) { return f && f.to$call$2(); } | |
function print$(obj) { | |
return _print(obj); | |
} | |
function _print(obj) { | |
if (typeof console == 'object') { | |
if (obj) obj = obj.toString(); | |
console.log(obj); | |
} else if (typeof write === 'function') { | |
write(obj); | |
write('\n'); | |
} | |
} | |
var ListFactory = Array; | |
$defProp(ListFactory.prototype, "is$List", function(){return true}); | |
$defProp(ListFactory.prototype, "is$Collection", function(){return true}); | |
$defProp(ListFactory.prototype, "get$length", function() { return this.length; }); | |
$defProp(ListFactory.prototype, "set$length", function(value) { return this.length = value; }); | |
$defProp(ListFactory.prototype, "add", function(value) { | |
this.push(value); | |
}); | |
$defProp(ListFactory.prototype, "clear", function() { | |
this.set$length((0)); | |
}); | |
$defProp(ListFactory.prototype, "removeLast", function() { | |
return this.pop(); | |
}); | |
$defProp(ListFactory.prototype, "iterator", function() { | |
return new ListIterator(this); | |
}); | |
$defProp(ListFactory.prototype, "toString", function() { | |
return Collections.collectionToString(this); | |
}); | |
function ListIterator(array) { | |
this._array = array; | |
this._pos = (0); | |
} | |
ListIterator.prototype.hasNext = function() { | |
return this._array.get$length() > this._pos; | |
} | |
ListIterator.prototype.next = function() { | |
if (!this.hasNext()) { | |
$throw(const$0000); | |
} | |
return this._array.$index(this._pos++); | |
} | |
var NumImplementation = Number; | |
function Collections() {} | |
Collections.collectionToString = function(c) { | |
var result = new StringBufferImpl(""); | |
Collections._emitCollection(c, result, new Array()); | |
return result.toString(); | |
} | |
Collections._emitCollection = function(c, result, visiting) { | |
visiting.add(c); | |
var isList = !!(c && c.is$List()); | |
result.add(isList ? "[" : "{"); | |
var first = true; | |
for (var $$i = c.iterator(); $$i.hasNext(); ) { | |
var e = $$i.next(); | |
if (!first) { | |
result.add(", "); | |
} | |
first = false; | |
Collections._emitObject(e, result, visiting); | |
} | |
result.add(isList ? "]" : "}"); | |
visiting.removeLast(); | |
} | |
Collections._emitObject = function(o, result, visiting) { | |
if (!!(o && o.is$Collection())) { | |
if (Collections._containsRef(visiting, o)) { | |
result.add(!!(o && o.is$List()) ? "[...]" : "{...}"); | |
} | |
else { | |
Collections._emitCollection(o, result, visiting); | |
} | |
} | |
else if (!!(o && o.is$Map())) { | |
if (Collections._containsRef(visiting, o)) { | |
result.add("{...}"); | |
} | |
else { | |
Maps._emitMap(o, result, visiting); | |
} | |
} | |
else { | |
result.add($eq$(o) ? "null" : o); | |
} | |
} | |
Collections._containsRef = function(c, ref) { | |
for (var $$i = c.iterator(); $$i.hasNext(); ) { | |
var e = $$i.next(); | |
if ((null == e ? null == (ref) : e === ref)) return true; | |
} | |
return false; | |
} | |
function HashMapImplementation() {} | |
HashMapImplementation.prototype.is$Map = function(){return true}; | |
HashMapImplementation.prototype.forEach = function(f) { | |
var length = this._keys.get$length(); | |
for (var i = (0); | |
i < length; i++) { | |
var key = this._keys.$index(i); | |
if ((null != key) && ((null == key ? null != (const$0001) : key !== const$0001))) { | |
f(key, this._values.$index(i)); | |
} | |
} | |
} | |
HashMapImplementation.prototype.toString = function() { | |
return Maps.mapToString(this); | |
} | |
function _DeletedKeySentinel() { | |
} | |
function Maps() {} | |
Maps.mapToString = function(m) { | |
var result = new StringBufferImpl(""); | |
Maps._emitMap(m, result, new Array()); | |
return result.toString(); | |
} | |
Maps._emitMap = function(m, result, visiting) { | |
visiting.add(m); | |
result.add("{"); | |
var first = true; | |
m.forEach((function (k, v) { | |
if (!first) { | |
result.add(", "); | |
} | |
first = false; | |
Collections._emitObject(k, result, visiting); | |
result.add(": "); | |
Collections._emitObject(v, result, visiting); | |
}) | |
); | |
result.add("}"); | |
visiting.removeLast(); | |
} | |
function DoubleLinkedQueue() {} | |
DoubleLinkedQueue.prototype.is$Collection = function(){return true}; | |
DoubleLinkedQueue.prototype.iterator = function() { | |
return new _DoubleLinkedQueueIterator(this._sentinel); | |
} | |
DoubleLinkedQueue.prototype.toString = function() { | |
return Collections.collectionToString(this); | |
} | |
function _DoubleLinkedQueueIterator(_sentinel) { | |
this._sentinel = _sentinel; | |
this._currentEntry = this._sentinel; | |
} | |
_DoubleLinkedQueueIterator.prototype.hasNext = function() { | |
var $0; | |
return (($0 = this._currentEntry._next) == null ? null != (this._sentinel) : $0 !== this._sentinel); | |
} | |
_DoubleLinkedQueueIterator.prototype.next = function() { | |
if (!this.hasNext()) { | |
$throw(const$0000); | |
} | |
this._currentEntry = this._currentEntry._next; | |
return this._currentEntry.get$element(); | |
} | |
function StringBufferImpl(content) { | |
this.clear(); | |
this.add(content); | |
} | |
StringBufferImpl.prototype.add = function(obj) { | |
var str = obj.toString(); | |
if (null == str || str.isEmpty()) return this; | |
this._buffer.add(str); | |
this._length = this._length + str.length; | |
return this; | |
} | |
StringBufferImpl.prototype.clear = function() { | |
this._buffer = new Array(); | |
this._length = (0); | |
return this; | |
} | |
StringBufferImpl.prototype.toString = function() { | |
if (this._buffer.get$length() == (0)) return ""; | |
if (this._buffer.get$length() == (1)) return this._buffer.$index((0)); | |
var result = StringBase.concatAll(this._buffer); | |
this._buffer.clear(); | |
this._buffer.add(result); | |
return result; | |
} | |
function StringBase() {} | |
StringBase.join = function(strings, separator) { | |
if (strings.get$length() == (0)) return ""; | |
var s = strings.$index((0)); | |
for (var i = (1); | |
i < strings.get$length(); i++) { | |
s = $add$($add$(s, separator), strings.$index(i)); | |
} | |
return s; | |
} | |
StringBase.concatAll = function(strings) { | |
return StringBase.join(strings, ""); | |
} | |
var StringImplementation = String; | |
StringImplementation.prototype.isEmpty = function() { | |
return this.length == (0); | |
} | |
$inherits(_ArgumentMismatchException, ClosureArgumentMismatchException); | |
function _ArgumentMismatchException(_message) { | |
this._dart_coreimpl_message = _message; | |
ClosureArgumentMismatchException.call(this); | |
} | |
_ArgumentMismatchException.prototype.toString = function() { | |
return ("Closure argument mismatch: " + this._dart_coreimpl_message); | |
} | |
var _FunctionImplementation = Function; | |
_FunctionImplementation.prototype._genStub = function(argsLength, names) { | |
// Fast path #1: if no named arguments and arg count matches. | |
var thisLength = this.$length || this.length; | |
if (thisLength == argsLength && !names) { | |
return this; | |
} | |
var paramsNamed = this.$optional ? (this.$optional.length / 2) : 0; | |
var paramsBare = thisLength - paramsNamed; | |
var argsNamed = names ? names.length : 0; | |
var argsBare = argsLength - argsNamed; | |
// Check we got the right number of arguments | |
if (argsBare < paramsBare || argsLength > thisLength || | |
argsNamed > paramsNamed) { | |
return function() { | |
$throw(new _ArgumentMismatchException( | |
'Wrong number of arguments to function. Expected ' + paramsBare + | |
' positional arguments and at most ' + paramsNamed + | |
' named arguments, but got ' + argsBare + | |
' positional arguments and ' + argsNamed + ' named arguments.')); | |
}; | |
} | |
// First, fill in all of the default values | |
var p = new Array(paramsBare); | |
if (paramsNamed) { | |
p = p.concat(this.$optional.slice(paramsNamed)); | |
} | |
// Fill in positional args | |
var a = new Array(argsLength); | |
for (var i = 0; i < argsBare; i++) { | |
p[i] = a[i] = '$' + i; | |
} | |
// Then overwrite with supplied values for optional args | |
var lastParameterIndex; | |
var namesInOrder = true; | |
for (var i = 0; i < argsNamed; i++) { | |
var name = names[i]; | |
a[i + argsBare] = name; | |
var j = this.$optional.indexOf(name); | |
if (j < 0 || j >= paramsNamed) { | |
return function() { | |
$throw(new _ArgumentMismatchException( | |
'Named argument "' + name + '" was not expected by function.' + | |
' Did you forget to mark the function parameter [optional]?')); | |
}; | |
} else if (lastParameterIndex && lastParameterIndex > j) { | |
namesInOrder = false; | |
} | |
p[j + paramsBare] = name; | |
lastParameterIndex = j; | |
} | |
if (thisLength == argsLength && namesInOrder) { | |
// Fast path #2: named arguments, but they're in order and all supplied. | |
return this; | |
} | |
// Note: using Function instead of 'eval' to get a clean scope. | |
// TODO(jmesserly): evaluate the performance of these stubs. | |
var f = 'function(' + a.join(',') + '){return $f(' + p.join(',') + ');}'; | |
return new Function('$f', 'return ' + f + '').call(null, this); | |
} | |
function main() { | |
var name = "World"; | |
print$(("Hello, " + name + "!")); | |
} | |
function $static_init(){ | |
} | |
var const$0000 = Object.create(NoMoreElementsException.prototype, {}); | |
var const$0001 = Object.create(_DeletedKeySentinel.prototype, {}); | |
$static_init(); | |
if (typeof window != 'undefined' && typeof document != 'undefined' && | |
window.addEventListener && document.readyState == 'loading') { | |
window.addEventListener('DOMContentLoaded', function(e) { | |
main(); | |
}); | |
} else { | |
main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment