Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Dart code
- void main() {
- Cat cat = getAnimal('cat');
- cat.greet();
- }
- getAnimal(String type) {
- if(type == 'cat') {
- return new Cat();
- } else if(type == 'dog') {
- return new Dog();
- }
- return null;
- }
- class Cat {
- greet() {
- print('Meow.');
- }
- }
- class Dog {
- greet() {
- print('Woof!');
- }
- }
- // JS created through dart2js compiler:
- // Generated by dart2js, the Dart to JavaScript compiler version: 1.8.0.
- // The code supports the following hooks:
- // dartPrint(message):
- // if this function is defined it is called instead of the Dart [print]
- // method.
- //
- // dartMainRunner(main, args):
- // if this function is defined, the Dart [main] method will not be invoked
- // directly. Instead, a closure that will invoke [main], and its arguments
- // [args] is passed to [dartMainRunner].
- (function($) {
- function dart() {
- this.x = 0;
- delete this.x;
- }
- var A = new dart;
- var B = new dart;
- var C = new dart;
- var D = new dart;
- var E = new dart;
- var F = new dart;
- var G = new dart;
- var H = new dart;
- var J = new dart;
- var K = new dart;
- var L = new dart;
- var M = new dart;
- var N = new dart;
- var O = new dart;
- var P = new dart;
- var Q = new dart;
- var R = new dart;
- var S = new dart;
- var T = new dart;
- var U = new dart;
- var V = new dart;
- var W = new dart;
- var X = new dart;
- var Y = new dart;
- var Z = new dart;
- function Isolate() {}
- init();
- $ = Isolate.$isolateProperties;
- var $$ = Object.create(null);
- (function(reflectionData) {
- "use strict";
- function map(x) {
- x = Object.create(null);
- x.x = 0;
- delete x.x;
- return x;
- }
- function processStatics(descriptor) {
- for (var property in descriptor) {
- if (!hasOwnProperty.call(descriptor, property))
- continue;
- if (property === "^")
- continue;
- var element = descriptor[property];
- var firstChar = property.substring(0, 1);
- var previousProperty;
- if (firstChar === "+") {
- mangledGlobalNames[previousProperty] = property.substring(1);
- var flag = descriptor[property];
- if (flag > 0)
- descriptor[previousProperty].$reflectable = flag;
- if (element && element.length)
- init.typeInformation[previousProperty] = element;
- } else if (firstChar === "@") {
- property = property.substring(1);
- $[property]["@"] = element;
- } else if (firstChar === "*") {
- globalObject[previousProperty].$defaultValues = element;
- var optionalMethods = descriptor.$methodsWithOptionalArguments;
- if (!optionalMethods) {
- descriptor.$methodsWithOptionalArguments = optionalMethods = {};
- }
- optionalMethods[property] = previousProperty;
- } else if (typeof element === "function") {
- globalObject[previousProperty = property] = element;
- functions.push(property);
- init.globalFunctions[property] = element;
- } else if (element.constructor === Array) {
- addStubs(globalObject, element, property, true, descriptor, functions);
- } else {
- previousProperty = property;
- var newDesc = {};
- var previousProp;
- for (var prop in element) {
- if (!hasOwnProperty.call(element, prop))
- continue;
- firstChar = prop.substring(0, 1);
- if (prop === "static") {
- processStatics(init.statics[property] = element[prop]);
- } else if (firstChar === "+") {
- mangledNames[previousProp] = prop.substring(1);
- var flag = element[prop];
- if (flag > 0)
- element[previousProp].$reflectable = flag;
- } else if (firstChar === "@" && prop !== "@") {
- newDesc[prop.substring(1)]["@"] = element[prop];
- } else if (firstChar === "*") {
- newDesc[previousProp].$defaultValues = element[prop];
- var optionalMethods = newDesc.$methodsWithOptionalArguments;
- if (!optionalMethods) {
- newDesc.$methodsWithOptionalArguments = optionalMethods = {};
- }
- optionalMethods[prop] = previousProp;
- } else {
- var elem = element[prop];
- if (prop !== "^" && elem != null && elem.constructor === Array && prop !== "<>") {
- addStubs(newDesc, elem, prop, false, element, []);
- } else {
- newDesc[previousProp = prop] = elem;
- }
- }
- }
- $$[property] = [globalObject, newDesc];
- classes.push(property);
- }
- }
- }
- function addStubs(descriptor, array, name, isStatic, originalDescriptor, functions) {
- var f, funcs = [originalDescriptor[name] = descriptor[name] = f = array[0]];
- f.$stubName = name;
- functions.push(name);
- for (var index = 0; index < array.length; index += 2) {
- f = array[index + 1];
- if (typeof f != "function")
- break;
- f.$stubName = array[index + 2];
- funcs.push(f);
- if (f.$stubName) {
- originalDescriptor[f.$stubName] = descriptor[f.$stubName] = f;
- functions.push(f.$stubName);
- }
- }
- for (var i = 0; i < funcs.length; index++, i++) {
- funcs[i].$callName = array[index + 1];
- }
- var getterStubName = array[++index];
- array = array.slice(++index);
- var requiredParameterInfo = array[0];
- var requiredParameterCount = requiredParameterInfo >> 1;
- var isAccessor = (requiredParameterInfo & 1) === 1;
- var isSetter = requiredParameterInfo === 3;
- var isGetter = requiredParameterInfo === 1;
- var optionalParameterInfo = array[1];
- var optionalParameterCount = optionalParameterInfo >> 1;
- var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1;
- var isIntercepted = requiredParameterCount + optionalParameterCount != funcs[0].length;
- var functionTypeIndex = array[2];
- var unmangledNameIndex = 2 * optionalParameterCount + requiredParameterCount + 3;
- var isReflectable = array.length > unmangledNameIndex;
- if (getterStubName) {
- f = tearOff(funcs, array, isStatic, name, isIntercepted);
- descriptor[name].$getter = f;
- f.$getterStub = true;
- if (isStatic)
- init.globalFunctions[name] = f;
- originalDescriptor[getterStubName] = descriptor[getterStubName] = f;
- funcs.push(f);
- if (getterStubName)
- functions.push(getterStubName);
- f.$stubName = getterStubName;
- f.$callName = null;
- if (isIntercepted)
- init.interceptedNames[getterStubName] = true;
- }
- if (isReflectable) {
- for (var i = 0; i < funcs.length; i++) {
- funcs[i].$reflectable = 1;
- funcs[i].$reflectionInfo = array;
- }
- var mangledNames = isStatic ? init.mangledGlobalNames : init.mangledNames;
- var unmangledName = array[unmangledNameIndex];
- var reflectionName = unmangledName;
- if (getterStubName)
- mangledNames[getterStubName] = reflectionName;
- if (isSetter) {
- reflectionName += "=";
- } else if (!isGetter) {
- reflectionName += ":" + requiredParameterCount + ":" + optionalParameterCount;
- }
- mangledNames[name] = reflectionName;
- funcs[0].$reflectionName = reflectionName;
- funcs[0].$metadataIndex = unmangledNameIndex + 1;
- if (optionalParameterCount)
- descriptor[unmangledName + "*"] = funcs[0];
- }
- }
- function tearOffGetterNoCsp(funcs, reflectionInfo, name, isIntercepted) {
- return isIntercepted ? new Function("funcs", "reflectionInfo", "name", "H", "c", "return function tearOff_" + name + functionCounter++ + "(x) {" + "if (c === null) c = H.closureFromTearOff(" + "this, funcs, reflectionInfo, false, [x], name);" + "return new c(this, funcs[0], x, name);" + "}")(funcs, reflectionInfo, name, H, null) : new Function("funcs", "reflectionInfo", "name", "H", "c", "return function tearOff_" + name + functionCounter++ + "() {" + "if (c === null) c = H.closureFromTearOff(" + "this, funcs, reflectionInfo, false, [], name);" + "return new c(this, funcs[0], null, name);" + "}")(funcs, reflectionInfo, name, H, null);
- }
- function tearOffGetterCsp(funcs, reflectionInfo, name, isIntercepted) {
- var cache = null;
- return isIntercepted ? function(x) {
- if (cache === null)
- cache = H.closureFromTearOff(this, funcs, reflectionInfo, false, [x], name);
- return new cache(this, funcs[0], x, name);
- } : function() {
- if (cache === null)
- cache = H.closureFromTearOff(this, funcs, reflectionInfo, false, [], name);
- return new cache(this, funcs[0], null, name);
- };
- }
- function tearOff(funcs, reflectionInfo, isStatic, name, isIntercepted) {
- var cache;
- return isStatic ? function() {
- if (cache === void 0)
- cache = H.closureFromTearOff(this, funcs, reflectionInfo, true, [], name).prototype;
- return cache;
- } : tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
- }
- var functionCounter = 0;
- var tearOffGetter = typeof dart_precompiled == "function" ? tearOffGetterCsp : tearOffGetterNoCsp;
- if (!init.libraries)
- init.libraries = [];
- if (!init.mangledNames)
- init.mangledNames = map();
- if (!init.mangledGlobalNames)
- init.mangledGlobalNames = map();
- if (!init.statics)
- init.statics = map();
- if (!init.typeInformation)
- init.typeInformation = map();
- if (!init.globalFunctions)
- init.globalFunctions = map();
- if (!init.interceptedNames)
- init.interceptedNames = map();
- var libraries = init.libraries;
- var mangledNames = init.mangledNames;
- var mangledGlobalNames = init.mangledGlobalNames;
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- var length = reflectionData.length;
- for (var i = 0; i < length; i++) {
- var data = reflectionData[i];
- var name = data[0];
- var uri = data[1];
- var metadata = data[2];
- var globalObject = data[3];
- var descriptor = data[4];
- var isRoot = !!data[5];
- var fields = descriptor && descriptor["^"];
- if (fields instanceof Array)
- fields = fields[0];
- var classes = [];
- var functions = [];
- processStatics(descriptor);
- libraries.push([name, uri, classes, functions, metadata, fields, isRoot, globalObject]);
- }
- })([
- ["dart.core", "dart:core", , P, {
- "^": "",
- print: function(object) {
- H.printString(object);
- },
- Object: {
- "^": ";"
- }
- }],
- ["dart2js._js_primitives", "dart:_js_primitives", , H, {
- "^": "",
- printString: function(string) {
- if (typeof dartPrint == "function") {
- dartPrint(string);
- return;
- }
- if (typeof console == "object" && typeof console.log != "undefined") {
- console.log(string);
- return;
- }
- if (typeof window == "object")
- return;
- if (typeof print == "function") {
- print(string);
- return;
- }
- throw "Unable to print message: " + String(string);
- }
- }],
- ["", "main.dart", , F, {
- "^": "",
- main: function() {
- F.getAnimal("cat").toString;
- P.print("Meow.");
- },
- getAnimal: function(type) {
- if (type === "cat")
- return new F.Cat();
- else if (type === "dog")
- return new F.Dog();
- return;
- },
- Cat: {
- "^": "Object;"
- },
- Dog: {
- "^": "Object;"
- }
- },
- 1],
- ]);
- Isolate.$finishClasses($$, $, null);
- $$ = null;
- // Runtime type support
- // getInterceptor methods
- init.isHunkLoaded = function(hunkHash) {
- return !!$dart_deferred_initializers[hunkHash];
- };
- init.initializeLoadedHunk = function(hunkHash) {
- $dart_deferred_initializers[hunkHash](globalsHolder, $);
- };
- init.deferredLibraryUris = {};
- init.deferredLibraryHashes = {};
- $.Closure_functionCounter = 0;
- $.BoundClosure_selfFieldNameCache = null;
- $.BoundClosure_receiverFieldNameCache = null;
- $.printToZone = null;
- init.metadata = [];
- $ = null;
- Isolate = Isolate.$finishIsolateConstructor(Isolate);
- $ = new Isolate();
- function convertToFastObject(properties) {
- function MyClass() {
- }
- MyClass.prototype = properties;
- new MyClass();
- return properties;
- }
- ;
- A = convertToFastObject(A);
- B = convertToFastObject(B);
- C = convertToFastObject(C);
- D = convertToFastObject(D);
- E = convertToFastObject(E);
- F = convertToFastObject(F);
- G = convertToFastObject(G);
- H = convertToFastObject(H);
- J = convertToFastObject(J);
- K = convertToFastObject(K);
- L = convertToFastObject(L);
- M = convertToFastObject(M);
- N = convertToFastObject(N);
- O = convertToFastObject(O);
- P = convertToFastObject(P);
- Q = convertToFastObject(Q);
- R = convertToFastObject(R);
- S = convertToFastObject(S);
- T = convertToFastObject(T);
- U = convertToFastObject(U);
- V = convertToFastObject(V);
- W = convertToFastObject(W);
- X = convertToFastObject(X);
- Y = convertToFastObject(Y);
- Z = convertToFastObject(Z);
- function init() {
- Isolate.$isolateProperties = Object.create(null);
- function generateAccessor(fieldDescriptor, accessors, cls) {
- var fieldInformation = fieldDescriptor.split("-");
- var field = fieldInformation[0];
- var len = field.length;
- var code = field.charCodeAt(len - 1);
- var reflectable;
- if (fieldInformation.length > 1)
- reflectable = true;
- else
- reflectable = false;
- code = code >= 60 && code <= 64 ? code - 59 : code >= 123 && code <= 126 ? code - 117 : code >= 37 && code <= 43 ? code - 27 : 0;
- if (code) {
- var getterCode = code & 3;
- var setterCode = code >> 2;
- var accessorName = field = field.substring(0, len - 1);
- var divider = field.indexOf(":");
- if (divider > 0) {
- accessorName = field.substring(0, divider);
- field = field.substring(divider + 1);
- }
- if (getterCode) {
- var args = getterCode & 2 ? "receiver" : "";
- var receiver = getterCode & 1 ? "this" : "receiver";
- var body = "return " + receiver + "." + field;
- var property = cls + ".prototype.get$" + accessorName + "=";
- var fn = "function(" + args + "){" + body + "}";
- if (reflectable)
- accessors.push(property + "$reflectable(" + fn + ");\n");
- else
- accessors.push(property + fn + ";\n");
- }
- if (setterCode) {
- var args = setterCode & 2 ? "receiver, value" : "value";
- var receiver = setterCode & 1 ? "this" : "receiver";
- var body = receiver + "." + field + " = value";
- var property = cls + ".prototype.set$" + accessorName + "=";
- var fn = "function(" + args + "){" + body + "}";
- if (reflectable)
- accessors.push(property + "$reflectable(" + fn + ");\n");
- else
- accessors.push(property + fn + ";\n");
- }
- }
- return field;
- }
- Isolate.$isolateProperties.$generateAccessor = generateAccessor;
- function defineClass(name, cls, fields) {
- var accessors = [];
- var str = "function " + cls + "(";
- var body = "";
- for (var i = 0; i < fields.length; i++) {
- if (i != 0)
- str += ", ";
- var field = generateAccessor(fields[i], accessors, cls);
- var parameter = "parameter_" + field;
- str += parameter;
- body += "this." + field + " = " + parameter + ";\n";
- }
- str += ") {\n" + body + "}\n";
- str += cls + ".builtin$cls=\"" + name + "\";\n";
- str += "$desc=$collectedClasses." + cls + ";\n";
- str += "if($desc instanceof Array) $desc = $desc[1];\n";
- str += cls + ".prototype = $desc;\n";
- if (typeof defineClass.name != "string") {
- str += cls + ".name=\"" + cls + "\";\n";
- }
- str += accessors.join("");
- return str;
- }
- var inheritFrom = function() {
- function tmp() {
- }
- function tmp() {
- }
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- return function(constructor, superConstructor) {
- tmp.prototype = superConstructor.prototype;
- var object = new tmp();
- var properties = constructor.prototype;
- for (var member in properties) {
- if (hasOwnProperty.call(properties, member)) {
- object[member] = properties[member];
- }
- }
- object.constructor = constructor;
- constructor.prototype = object;
- return object;
- };
- }();
- Isolate.$finishClasses = function(collectedClasses, isolateProperties, existingIsolateProperties) {
- var pendingClasses = Object.create(null);
- var allClasses = init.allClasses;
- var constructors;
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- if (typeof dart_precompiled == "function") {
- constructors = dart_precompiled(collectedClasses);
- } else {
- var combinedConstructorFunction = "function $reflectable(fn){fn.$reflectable=1;return fn};\n" + "var $desc;\n";
- var constructorsList = [];
- }
- for (var cls in collectedClasses) {
- var desc = collectedClasses[cls];
- if (desc instanceof Array)
- desc = desc[1];
- var classData = desc["^"], supr, name = cls, fields = classData;
- if (typeof classData == "string") {
- var split = classData.split("/");
- if (split.length == 2) {
- name = split[0];
- fields = split[1];
- }
- }
- var s = fields.split(";");
- fields = s[1] == "" ? [] : s[1].split(",");
- supr = s[0];
- split = supr.split(":");
- if (split.length == 2) {
- supr = split[0];
- var functionSignature = split[1];
- if (functionSignature)
- desc.$signature = function(s) {
- return function() {
- return init.metadata[s];
- };
- }(functionSignature);
- }
- if (typeof dart_precompiled != "function") {
- combinedConstructorFunction += defineClass(name, cls, fields);
- constructorsList.push(cls);
- }
- if (supr)
- pendingClasses[cls] = supr;
- }
- if (typeof dart_precompiled != "function") {
- combinedConstructorFunction += "return [\n " + constructorsList.join(",\n ") + "\n]";
- var constructors = new Function("$collectedClasses", combinedConstructorFunction)(collectedClasses);
- combinedConstructorFunction = null;
- }
- for (var i = 0; i < constructors.length; i++) {
- var constructor = constructors[i];
- var cls = constructor.name;
- var desc = collectedClasses[cls];
- var globalObject = isolateProperties;
- if (desc instanceof Array) {
- globalObject = desc[0] || isolateProperties;
- desc = desc[1];
- }
- allClasses[cls] = constructor;
- globalObject[cls] = constructor;
- }
- constructors = null;
- var finishedClasses = init.finishedClasses;
- function finishClass(cls) {
- if (finishedClasses[cls])
- return;
- finishedClasses[cls] = true;
- var superclass = pendingClasses[cls];
- if (!superclass || typeof superclass != "string")
- return;
- finishClass(superclass);
- var constructor = allClasses[cls];
- var superConstructor = allClasses[superclass];
- if (!superConstructor)
- superConstructor = existingIsolateProperties[superclass];
- var prototype = inheritFrom(constructor, superConstructor);
- }
- for (var cls in pendingClasses)
- finishClass(cls);
- };
- (function() {
- init.allClasses = Object.create(null);
- init.interceptorsByTag = Object.create(null);
- init.leafTags = Object.create(null);
- init.finishedClasses = Object.create(null);
- })();
- Isolate.$lazy = function(prototype, staticName, fieldName, getterName, lazyValue) {
- if (!init.lazies)
- init.lazies = Object.create(null);
- init.lazies[fieldName] = getterName;
- var sentinelUndefined = {};
- var sentinelInProgress = {};
- prototype[fieldName] = sentinelUndefined;
- prototype[getterName] = function() {
- var result = $[fieldName];
- try {
- if (result === sentinelUndefined) {
- $[fieldName] = sentinelInProgress;
- try {
- result = $[fieldName] = lazyValue();
- } finally {
- if (result === sentinelUndefined)
- $[fieldName] = null;
- }
- } else {
- if (result === sentinelInProgress)
- H.throwCyclicInit(staticName);
- }
- return result;
- } finally {
- $[getterName] = function() {
- return this[fieldName];
- };
- }
- };
- };
- Isolate.$finishIsolateConstructor = function(oldIsolate) {
- var isolateProperties = oldIsolate.$isolateProperties;
- function Isolate() {
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- for (var staticName in isolateProperties)
- if (hasOwnProperty.call(isolateProperties, staticName))
- this[staticName] = isolateProperties[staticName];
- var lazies = init.lazies;
- for (var lazyInit in lazies) {
- this[lazies[lazyInit]] = null;
- }
- function ForceEfficientMap() {
- }
- ForceEfficientMap.prototype = this;
- new ForceEfficientMap();
- for (var lazyInit in lazies) {
- var lazyInitName = lazies[lazyInit];
- this[lazyInitName] = isolateProperties[lazyInitName];
- }
- }
- Isolate.prototype = oldIsolate.prototype;
- Isolate.prototype.constructor = Isolate;
- Isolate.$isolateProperties = isolateProperties;
- Isolate.$finishClasses = oldIsolate.$finishClasses;
- return Isolate;
- };
- }
- // BEGIN invoke [main].
- ;(function(callback) {
- if (typeof document === "undefined") {
- callback(null);
- return;
- }
- if (document.currentScript) {
- callback(document.currentScript);
- return;
- }
- var scripts = document.scripts;
- function onLoad(event) {
- for (var i = 0; i < scripts.length; ++i) {
- scripts[i].removeEventListener("load", onLoad, false);
- }
- callback(event.target);
- }
- for (var i = 0; i < scripts.length; ++i) {
- scripts[i].addEventListener("load", onLoad, false);
- }
- })(function(currentScript) {
- init.currentScript = currentScript;
- if (typeof dartMainRunner === "function") {
- dartMainRunner(F.main, []);
- } else {
- F.main([]);
- }
- });
- ;
- // END invoke [main].
- })()
- //# sourceMappingURL=test.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement