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

Side by Side Diff: frog/frogsh

Issue 8577003: Convert most of the javascript isolate code into Dart, inject JS code only when (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives dart:core ************** 3 // ********** Natives dart:core **************
4 /** 4 /**
5 * Generates a dynamic call stub for a function. 5 * Generates a dynamic call stub for a function.
6 * Our goal is to create a stub method like this on-the-fly: 6 * Our goal is to create a stub method like this on-the-fly:
7 * function($0, $1, capture) { this($0, $1, true, capture); } 7 * function($0, $1, capture) { this($0, $1, true, capture); }
8 * 8 *
9 * This stub then replaces the dynamic one on Function, with one that is 9 * This stub then replaces the dynamic one on Function, with one that is
10 * specialized for that particular function, taking into account its default 10 * specialized for that particular function, taking into account its default
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 function print(obj) { 847 function print(obj) {
848 if (typeof console == 'object') { 848 if (typeof console == 'object') {
849 if (obj) obj = obj.toString(); 849 if (obj) obj = obj.toString();
850 console.log(obj); 850 console.log(obj);
851 } else { 851 } else {
852 write(obj); 852 write(obj);
853 write('\n'); 853 write('\n');
854 } 854 }
855 } 855 }
856 // ********** Library dart:coreimpl ************** 856 // ********** Library dart:coreimpl **************
857 // ********** Natives isolate.js **************
858 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
859 // for details. All rights reserved. Use of this source code is governed by a
860 // BSD-style license that can be found in the LICENSE file.
861
862 var isolate$current = null;
863 var isolate$rootIsolate = null; // Will only be set in the main worker.
864 var isolate$inits = [];
865 var isolate$globalThis = this;
866
867 var isolate$inWorker =
868 (typeof isolate$globalThis['importScripts']) != "undefined";
869 var isolate$supportsWorkers =
870 isolate$inWorker || ((typeof isolate$globalThis['Worker']) != 'undefined');
871
872 var isolate$MAIN_WORKER_ID = 0;
873 // Non-main workers will update the id variable.
874 var isolate$thisWorkerId = isolate$MAIN_WORKER_ID;
875
876 // Whether to use web workers when implementing isolates.
877 var isolate$useWorkers = isolate$supportsWorkers;
878 // Uncomment this to not use web workers even if they're available.
879 // isolate$useWorkers = false;
880
881 // Whether to use the web-worker JSON-based message serialization protocol,
882 // even if not using web workers.
883 var isolate$useWorkerSerializationProtocol = false;
884 // Uncomment this to always use the web-worker JSON-based message
885 // serialization protocol, e.g. for testing purposes.
886 // isolate$useWorkerSerializationProtocol = true;
887
888
889 // ------- SendPort -------
890
891 function isolate$receiveMessage(port, isolate,
892 serializedMessage, serializedReplyTo) {
893 isolate$IsolateEvent.enqueue(isolate, function() {
894 var message = isolate$deserializeMessage(serializedMessage);
895 var replyTo = isolate$deserializeMessage(serializedReplyTo);
896 if (port._callback) port._callback(message, replyTo);
897 });
898 }
899
900 // -------- Registry ---------
901 function isolate$Registry() {
902 this.map = {};
903 this.count = 0;
904 }
905
906 isolate$Registry.prototype.register = function(id, val) {
907 if (this.map[id]) {
908 throw Error("Registry: Elements must be registered only once.");
909 }
910 this.map[id] = val;
911 this.count++;
912 };
913
914 isolate$Registry.prototype.unregister = function(id) {
915 if (id in this.map) {
916 delete this.map[id];
917 this.count--;
918 }
919 };
920
921 isolate$Registry.prototype.get = function(id) {
922 return this.map[id];
923 };
924
925 isolate$Registry.prototype.isEmpty = function() {
926 return this.count === 0;
927 };
928
929
930 // ------- Worker registry -------
931 // Only used in the main worker.
932 var isolate$workerRegistry = new isolate$Registry();
933
934 // ------- Isolate registry -------
935 // Isolates must be registered if, and only if, receive ports are alive.
936 // Normally no open receive-ports means that the isolate is dead, but
937 // DOM callbacks could resurrect it.
938 var isolate$isolateRegistry = new isolate$Registry();
939
940 // ------- Debugging log function -------
941 function isolate$log(msg) {
942 return;
943 if (isolate$inWorker) {
944 isolate$mainWorker.postMessage({ command: 'log', msg: msg });
945 } else {
946 try {
947 isolate$globalThis.console.log(msg);
948 } catch(e) {
949 throw String(e.stack);
950 }
951 }
952 }
953
954 function isolate$initializeWorker(workerId) {
955 isolate$thisWorkerId = workerId;
956 }
957
958 var isolate$workerPrint = false;
959 if (isolate$inWorker) {
960 isolate$workerPrint = function(msg){
961 isolate$mainWorker.postMessage({ command: 'print', msg: msg });
962 }
963 }
964
965 // ------- Message handler -------
966 function isolate$processWorkerMessage(sender, e) {
967 var msg = e.data;
968 switch (msg.command) {
969 case 'start':
970 isolate$log("starting worker: " + msg.id + " " + msg.factoryName);
971 isolate$initializeWorker(msg.id);
972 var runnerObject = new (isolate$globalThis[msg.factoryName])();
973 var serializedReplyTo = msg.replyTo;
974 isolate$IsolateEvent.enqueue(new isolate$Isolate(), function() {
975 var replyTo = isolate$deserializeMessage(serializedReplyTo);
976 _IsolateJsUtil._startIsolate(runnerObject, replyTo);
977 });
978 isolate$runEventLoop();
979 break;
980 case 'spawn-worker':
981 isolate$spawnWorker(msg.factoryName, msg.replyPort);
982 break;
983 case 'message':
984 IsolateNatives.sendMessage(
985 msg.workerId, msg.isolateId, msg.portId, msg.msg, msg.replyTo);
986 isolate$runEventLoop();
987 break;
988 case 'close':
989 isolate$log("Closing Worker");
990 isolate$workerRegistry.unregister(sender.id);
991 sender.terminate();
992 isolate$runEventLoop();
993 break;
994 case 'log':
995 isolate$log(msg.msg);
996 break;
997 case 'print':
998 _IsolateJsUtil._print(msg.msg);
999 break;
1000 case 'error':
1001 throw msg.msg;
1002 break;
1003 }
1004 }
1005
1006
1007 if (isolate$supportsWorkers) {
1008 isolate$globalThis.onmessage = function(e) {
1009 isolate$processWorkerMessage(isolate$mainWorker, e);
1010 };
1011 }
1012
1013 // ------- Default Worker -------
1014 function isolate$MainWorker() {
1015 this.id = isolate$MAIN_WORKER_ID;
1016 }
1017
1018 var isolate$mainWorker = new isolate$MainWorker();
1019 isolate$mainWorker.postMessage = function(msg) {
1020 isolate$globalThis.postMessage(msg);
1021 };
1022
1023 var isolate$nextFreeIsolateId = 1;
1024
1025 // Native methods for isolate functionality.
1026 /**
1027 * @constructor
1028 */
1029 function isolate$Isolate() {
1030 // The isolate ids is only unique within the current worker and frame.
1031 this.id = isolate$nextFreeIsolateId++;
1032 // When storing information on DOM nodes the isolate's id is not enough.
1033 // We instead use a token with a hashcode. The token can be stored in the
1034 // DOM node (since it is small and will not keep much data alive).
1035 this.token = new Object();
1036 this.token.hashCode = (Math.random() * 0xFFFFFFF) >>> 0;
1037 this.receivePorts = new isolate$Registry();
1038 this.run(function() {
1039 // The Dart-to-JavaScript compiler builds a list of functions that
1040 // need to run for each isolate to setup the state of static
1041 // variables. Run through the list and execute each function.
1042 for (var i = 0, len = isolate$inits.length; i < len; i++) {
1043 isolate$inits[i]();
1044 }
1045 });
1046 }
1047
1048 // It is allowed to stack 'run' calls. The stacked isolates can be different.
1049 // That is Isolate1.run could call the DOM which then calls Isolate2.run.
1050 isolate$Isolate.prototype.run = function(code) {
1051 var old = isolate$current;
1052 isolate$current = this;
1053 var result = null;
1054 try {
1055 result = code();
1056 } finally {
1057 isolate$current = old;
1058 }
1059 return result;
1060 };
1061
1062 isolate$Isolate.prototype.registerReceivePort = function(id, port) {
1063 if (this.receivePorts.isEmpty()) {
1064 isolate$isolateRegistry.register(this.id, this);
1065 }
1066 this.receivePorts.register(id, port);
1067 };
1068
1069 isolate$Isolate.prototype.unregisterReceivePort = function(id) {
1070 this.receivePorts.unregister(id);
1071 if (this.receivePorts.isEmpty()) {
1072 isolate$isolateRegistry.unregister(this.id);
1073 }
1074 };
1075
1076 isolate$Isolate.prototype.getReceivePortForId = function(id) {
1077 return this.receivePorts.get(id);
1078 };
1079
1080 var isolate$events = [];
1081
1082 /**
1083 * @constructor
1084 */
1085 function isolate$IsolateEvent(isolate, fn) {
1086 this.isolate = isolate;
1087 this.fn = fn;
1088 }
1089
1090 isolate$IsolateEvent.prototype.process = function() {
1091 this.isolate.run(this.fn);
1092 };
1093
1094 isolate$IsolateEvent.enqueue = function(isolate, fn) {
1095 isolate$events.push(new isolate$IsolateEvent(isolate, fn));
1096 };
1097
1098
1099 isolate$IsolateEvent.dequeue = function() {
1100 if (isolate$events.length == 0) return null;
1101 var result = isolate$events[0];
1102 isolate$events.splice(0, 1);
1103 return result;
1104 };
1105
1106 function IsolateNatives() {}
1107
1108 IsolateNatives.sendMessage = function (workerId, isolateId, receivePortId,
1109 message, replyTo) {
1110 // Both, the message and the replyTo are already serialized.
1111 if (workerId == isolate$thisWorkerId) {
1112 var isolate = isolate$isolateRegistry.get(isolateId);
1113 if (!isolate) return; // Isolate has been closed.
1114 var receivePort = isolate.getReceivePortForId(receivePortId);
1115 if (!receivePort) return; // ReceivePort has been closed.
1116 isolate$receiveMessage(receivePort, isolate, message, replyTo);
1117 } else {
1118 var worker;
1119 if (isolate$inWorker) {
1120 worker = isolate$mainWorker;
1121 } else {
1122 worker = isolate$workerRegistry.get(workerId);
1123 }
1124 worker.postMessage({ command: 'message',
1125 workerId: workerId,
1126 isolateId: isolateId,
1127 portId: receivePortId,
1128 msg: message,
1129 replyTo: replyTo });
1130 }
1131 }
1132
1133 // Wrap a 0-arg dom-callback to bind it with the current isolate:
1134 function $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }
1135 Function.prototype.wrap$call$0 = function() {
1136 var isolate = isolate$current;
1137 var self = this;
1138 this.wrap$0 = function() {
1139 isolate.run(function() {
1140 self();
1141 });
1142 isolate$runEventLoop();
1143 };
1144 this.wrap$call$0 = function() { return this.wrap$0; };
1145 return this.wrap$0;
1146 }
1147
1148 // Wrap a 1-arg dom-callback to bind it with the current isolate:
1149 function $wrap_call$1(fn) { return fn && fn.wrap$call$1(); }
1150 Function.prototype.wrap$call$1 = function() {
1151 var isolate = isolate$current;
1152 var self = this;
1153 this.wrap$1 = function(arg) {
1154 isolate.run(function() {
1155 self(arg);
1156 });
1157 isolate$runEventLoop();
1158 };
1159 this.wrap$call$1 = function() { return this.wrap$1; };
1160 return this.wrap$1;
1161 }
1162
1163 IsolateNatives._spawn = function(runnable, light, replyPort) {
1164 // TODO(floitsch): throw exception if runnable's class doesn't have a
1165 // default constructor.
1166 if (isolate$useWorkers && !light) {
1167 isolate$startWorker(runnable, replyPort);
1168 } else {
1169 isolate$startNonWorker(runnable, replyPort);
1170 }
1171 }
1172
1173 IsolateNatives.get$shouldSerialize = function() {
1174 return isolate$useWorkers || isolate$useWorkerSerializationProtocol;
1175 }
1176
1177 IsolateNatives.registerPort = function(id, port) {
1178 isolate$current.registerReceivePort(id, port);
1179 }
1180
1181 IsolateNatives.unregisterPort = function(id) {
1182 isolate$current.unregisterReceivePort(id);
1183 }
1184
1185 IsolateNatives._currentWorkerId = function() {
1186 return isolate$thisWorkerId;
1187 }
1188
1189 IsolateNatives._currentIsolateId = function() {
1190 return isolate$current.id;
1191 }
1192
1193 function isolate$startNonWorker(runnable, replyTo) {
1194 // Spawn a new isolate and create the receive port in it.
1195 var spawned = new isolate$Isolate();
1196
1197 // Instead of just running the provided runnable, we create a
1198 // new cloned instance of it with a fresh state in the spawned
1199 // isolate. This way, we do not get cross-isolate references
1200 // through the runnable.
1201 var ctor = runnable.constructor;
1202 isolate$IsolateEvent.enqueue(spawned, function() {
1203 _IsolateJsUtil._startIsolate(new ctor(), replyTo);
1204 });
1205 }
1206
1207 // This field is only used by the main worker.
1208 var isolate$nextFreeWorkerId = isolate$thisWorkerId + 1;
1209
1210 var isolate$thisScript = function() {
1211 if (!isolate$supportsWorkers || isolate$inWorker) return null;
1212
1213 // TODO(5334778): Find a cross-platform non-brittle way of getting the
1214 // currently running script.
1215 var scripts = document.getElementsByTagName('script');
1216 // The scripts variable only contains the scripts that have already been
1217 // executed. The last one is the currently running script.
1218 var script = scripts[scripts.length - 1];
1219 var src = script.src;
1220 if (!src) {
1221 // TODO()
1222 src = "FIXME:5407062" + "_" + Math.random().toString();
1223 script.src = src;
1224 }
1225 return src;
1226 }();
1227
1228 function isolate$startWorker(runnable, replyPort) {
1229 // TODO(sigmund): make this browser independent
1230 var factoryName = runnable.constructor.name;
1231 var serializedReplyPort = isolate$serializeMessage(replyPort);
1232 if (isolate$inWorker) {
1233 isolate$mainWorker.postMessage({ command: 'spawn-worker',
1234 factoryName: factoryName,
1235 replyPort: serializedReplyPort } );
1236 } else {
1237 isolate$spawnWorker(factoryName, serializedReplyPort);
1238 }
1239 }
1240
1241 function isolate$spawnWorker(factoryName, serializedReplyPort) {
1242 var worker = new Worker(isolate$thisScript);
1243 worker.onmessage = function(e) {
1244 isolate$processWorkerMessage(worker, e);
1245 };
1246 var workerId = isolate$nextFreeWorkerId++;
1247 // We also store the id on the worker itself so that we can unregister it.
1248 worker.id = workerId;
1249 isolate$workerRegistry.register(workerId, worker);
1250 worker.postMessage({ command: 'start',
1251 id: workerId,
1252 replyTo: serializedReplyPort,
1253 factoryName: factoryName });
1254 }
1255
1256 function isolate$closeWorkerIfNecessary() {
1257 if (!isolate$isolateRegistry.isEmpty()) return;
1258 isolate$mainWorker.postMessage( { command: 'close' } );
1259 }
1260
1261 function isolate$doOneEventLoopIteration() {
1262 var CONTINUE_LOOP = true;
1263 var STOP_LOOP = false;
1264 var event = isolate$IsolateEvent.dequeue();
1265 if (!event) {
1266 if (isolate$inWorker) {
1267 isolate$closeWorkerIfNecessary();
1268 } else if (!isolate$isolateRegistry.isEmpty() &&
1269 isolate$workerRegistry.isEmpty() &&
1270 !isolate$supportsWorkers && (typeof(window) == 'undefined')) {
1271 // This should only trigger when running on the command-line.
1272 // We don't want this check to execute in the browser where the isolate
1273 // might still be alive due to DOM callbacks.
1274 // throw Error("Program exited with open ReceivePorts.");
1275 }
1276 return STOP_LOOP;
1277 } else {
1278 event.process();
1279 return CONTINUE_LOOP;
1280 }
1281 }
1282
1283 function isolate$doRunEventLoop() {
1284 if (typeof window != 'undefined' && window.setTimeout) {
1285 (function next() {
1286 var continueLoop = isolate$doOneEventLoopIteration();
1287 if (!continueLoop) return;
1288 // TODO(kasperl): It might turn out to be too expensive to call
1289 // setTimeout for every single event. This needs more investigation.
1290 window.setTimeout(next, 0);
1291 })();
1292 } else {
1293 while (true) {
1294 var continueLoop = isolate$doOneEventLoopIteration();
1295 if (!continueLoop) break;
1296 }
1297 }
1298 }
1299
1300 function isolate$runEventLoop() {
1301 if (!isolate$inWorker) {
1302 isolate$doRunEventLoop();
1303 } else {
1304 try {
1305 isolate$doRunEventLoop();
1306 } catch(e) {
1307 // TODO(floitsch): try to send stack-trace to the other side.
1308 isolate$mainWorker.postMessage({ command: 'error', msg: "" + e });
1309 }
1310 }
1311 }
1312
1313 function RunEntry(entry, args) {
1314 // Don't start the main loop again, if we are in a worker.
1315 if (isolate$inWorker) return;
1316 var isolate = new isolate$Isolate();
1317 isolate$rootIsolate = isolate;
1318 isolate$IsolateEvent.enqueue(isolate, function() {
1319 entry(args);
1320 });
1321 isolate$runEventLoop();
1322
1323 // BUG(5151491): This should not be necessary, but because closures
1324 // passed to the DOM as event handlers do not bind their isolate
1325 // automatically we try to give them a reasonable context to live in
1326 // by having a "default" isolate (the first one created).
1327 isolate$current = isolate;
1328 }
1329
1330 // ------- Message Serializing and Deserializing -------
1331
1332 function isolate$serializeMessage(message) {
1333 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) {
1334 return _IsolateJsUtil._serializeObject(message);
1335 } else {
1336 return _IsolateJsUtil._copyObject(message);
1337 }
1338 }
1339
1340 function isolate$deserializeMessage(message_) {
1341 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) {
1342 return _IsolateJsUtil._deserializeMessage(message_);
1343 } else {
1344 // Nothing more to do.
1345 return message_;
1346 }
1347 }
1348
1349 function _IsolateJsUtil() {}
1350 // ********** Code for ListFactory ************** 857 // ********** Code for ListFactory **************
1351 ListFactory = Array; 858 ListFactory = Array;
1352 ListFactory.prototype.is$ListFactory = function(){return this;}; 859 ListFactory.prototype.is$ListFactory = function(){return this;};
1353 ListFactory.prototype.is$List = function(){return this;}; 860 ListFactory.prototype.is$List = function(){return this;};
1354 ListFactory.prototype.is$List$ArgumentNode = function(){return this;}; 861 ListFactory.prototype.is$List$ArgumentNode = function(){return this;};
1355 ListFactory.prototype.is$List$Definition = function(){return this;}; 862 ListFactory.prototype.is$List$Definition = function(){return this;};
1356 ListFactory.prototype.is$List$EvaluatedValue = function(){return this;}; 863 ListFactory.prototype.is$List$EvaluatedValue = function(){return this;};
1357 ListFactory.prototype.is$List$String = function(){return this;}; 864 ListFactory.prototype.is$List$String = function(){return this;};
1358 ListFactory.prototype.is$List$Type = function(){return this;}; 865 ListFactory.prototype.is$List$Type = function(){return this;};
1359 ListFactory.prototype.is$List$Value = function(){return this;}; 866 ListFactory.prototype.is$List$Value = function(){return this;};
(...skipping 10560 matching lines...) Expand 10 before | Expand all | Expand 10 after
11920 this.useStackTraceOf = false 11427 this.useStackTraceOf = false
11921 this.useToDartException = false 11428 this.useToDartException = false
11922 this.useThrow = false 11429 this.useThrow = false
11923 this.useVarMethod = false 11430 this.useVarMethod = false
11924 this.useGenStub = false 11431 this.useGenStub = false
11925 this.useMap = false 11432 this.useMap = false
11926 this.useAssert = false 11433 this.useAssert = false
11927 this.useNotNullBool = false 11434 this.useNotNullBool = false
11928 this.useIndex = false 11435 this.useIndex = false
11929 this.useSetIndex = false 11436 this.useSetIndex = false
11437 this.useWrap0 = false
11438 this.useWrap1 = false
11439 this.useIsolates = false
11930 this.useToString = false 11440 this.useToString = false
11931 this._usedOperators = $map([]); 11441 this._usedOperators = $map([]);
11932 // Initializers done 11442 // Initializers done
11933 } 11443 }
11934 CoreJs.prototype.useOperator = function(name) { 11444 CoreJs.prototype.useOperator = function(name) {
11935 if ($notnull_bool($ne(this._usedOperators.$index(name), null))) return; 11445 if ($notnull_bool($ne(this._usedOperators.$index(name), null))) return;
11936 var code; 11446 var code;
11937 switch (name) { 11447 switch (name) {
11938 case '\$ne': 11448 case '\$ne':
11939 11449
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
12014 } 11524 }
12015 if ($notnull_bool(this.useTypeNameOf)) { 11525 if ($notnull_bool(this.useTypeNameOf)) {
12016 w.writeln("Object.prototype.$typeNameOf = function() {\n if ((typeof(window ) != 'undefined' && window.constructor.name == 'DOMWindow')\n || typeof(pro cess) != 'undefined') { // fast-path for Chrome and Node\n return this.constr uctor.name;\n }\n var str = Object.prototype.toString.call(this);\n return st r.substring(8, str.length - 1);\n}"); 11526 w.writeln("Object.prototype.$typeNameOf = function() {\n if ((typeof(window ) != 'undefined' && window.constructor.name == 'DOMWindow')\n || typeof(pro cess) != 'undefined') { // fast-path for Chrome and Node\n return this.constr uctor.name;\n }\n var str = Object.prototype.toString.call(this);\n return st r.substring(8, str.length - 1);\n}");
12017 } 11527 }
12018 if ($notnull_bool(this.useIndex)) { 11528 if ($notnull_bool(this.useIndex)) {
12019 w.writeln("Object.prototype.$index = function(i) { return this[i]; }\nArray. prototype.$index = function(i) { return this[i]; }\nString.prototype.$index = fu nction(i) { return this[i]; }"); 11529 w.writeln("Object.prototype.$index = function(i) { return this[i]; }\nArray. prototype.$index = function(i) { return this[i]; }\nString.prototype.$index = fu nction(i) { return this[i]; }");
12020 } 11530 }
12021 if ($notnull_bool(this.useSetIndex)) { 11531 if ($notnull_bool(this.useSetIndex)) {
12022 w.writeln("Object.prototype.$setindex = function(i, value) { return this[i] = value; }\nArray.prototype.$setindex = function(i, value) { return this[i] = va lue; }"); 11532 w.writeln("Object.prototype.$setindex = function(i, value) { return this[i] = value; }\nArray.prototype.$setindex = function(i, value) { return this[i] = va lue; }");
12023 } 11533 }
11534 if ($notnull_bool(this.useIsolates)) {
11535 if ($notnull_bool(this.useWrap0)) {
11536 w.writeln("// Wrap a 0-arg dom-callback to bind it with the current isolat e:\nfunction $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }\nFunction.proto type.wrap$call$0 = function() {\n var isolate = $globalState.currentIsolate;\n var self = this;\n this.wrap$0 = function() {\n isolate.eval(self);\n $g lobalState.topEventLoop.run();\n };\n this.wrap$call$0 = function() { return t his.wrap$0; };\n return this.wrap$0;\n}");
11537 }
11538 if ($notnull_bool(this.useWrap1)) {
11539 w.writeln("// Wrap a 1-arg dom-callback to bind it with the current isolat e:\nfunction $wrap_call$1(fn) { return fn && fn.wrap$call$1(); }\nFunction.proto type.wrap$call$1 = function() {\n var isolate = $globalState.currentIsolate;\n var self = this;\n this.wrap$1 = function(arg) {\n isolate.eval(function() { self(arg); });\n $globalState.topEventLoop.run();\n };\n this.wrap$call$1 = function() { return this.wrap$1; };\n return this.wrap$1;\n}");
11540 }
11541 w.writeln("var $globalThis = this;\nvar $globalState = null;");
11542 }
11543 else {
11544 if ($notnull_bool(this.useWrap0)) {
11545 w.writeln("function $wrap_call$0(fn) { return fn; }");
11546 }
11547 if ($notnull_bool(this.useWrap1)) {
11548 w.writeln("function $wrap_call$1(fn) { return fn; }");
11549 }
11550 }
12024 var $list = orderValuesByKeys(this._usedOperators); 11551 var $list = orderValuesByKeys(this._usedOperators);
12025 for (var $i = 0;$i < $list.length; $i++) { 11552 for (var $i = 0;$i < $list.length; $i++) {
12026 var opImpl = $list.$index($i); 11553 var opImpl = $list.$index($i);
12027 w.writeln($assert_String(opImpl)); 11554 w.writeln($assert_String(opImpl));
12028 } 11555 }
12029 } 11556 }
12030 CoreJs.prototype.generate$1 = function($0) { 11557 CoreJs.prototype.generate$1 = function($0) {
12031 return this.generate(($0 && $0.is$CodeWriter())); 11558 return this.generate(($0 && $0.is$CodeWriter()));
12032 }; 11559 };
12033 // ********** Code for WorldGenerator ************** 11560 // ********** Code for WorldGenerator **************
12034 function WorldGenerator(main, writer) { 11561 function WorldGenerator(main, writer) {
12035 this._inheritsGenerated = false 11562 this._inheritsGenerated = false
12036 this.main = main; 11563 this.main = main;
12037 this.writer = writer; 11564 this.writer = writer;
12038 this.globals = $map([]); 11565 this.globals = $map([]);
12039 this.corejs = new CoreJs(); 11566 this.corejs = new CoreJs();
12040 // Initializers done 11567 // Initializers done
12041 } 11568 }
12042 WorldGenerator.prototype.run = function() { 11569 WorldGenerator.prototype.run = function() {
12043 var $0; 11570 var $0;
12044 var metaGen = new MethodGenerator(this.main, null); 11571 var metaGen = new MethodGenerator(this.main, null);
12045 var mainCall = this.main.invoke((metaGen && metaGen.is$MethodGenerator()), nul l, null, Arguments.get$EMPTY(), false); 11572 var mainCall = this.main.invoke((metaGen && metaGen.is$MethodGenerator()), nul l, null, Arguments.get$EMPTY(), false);
12046 this.main.declaringType.markUsed(); 11573 this.main.declaringType.markUsed();
12047 world.corelib.types.$index('BadNumberFormatException').markUsed$0(); 11574 world.corelib.types.$index('BadNumberFormatException').markUsed$0();
12048 world.get$coreimpl().types.$index('NumImplementation').markUsed$0(); 11575 world.get$coreimpl().types.$index('NumImplementation').markUsed$0();
12049 world.get$coreimpl().types.$index('StringImplementation').markUsed$0(); 11576 world.get$coreimpl().types.$index('StringImplementation').markUsed$0();
12050 world.get$coreimpl().types.$index('MatchImplementation').markUsed$0(); 11577 world.get$coreimpl().types.$index('MatchImplementation').markUsed$0();
12051 this.genMethod((($0 = world.get$coreimpl().types.$index('MatchImplementation') .getConstructor$1('')) && $0.is$Member())); 11578 this.genMethod((($0 = world.get$coreimpl().types.$index('MatchImplementation') .getConstructor$1('')) && $0.is$Member()));
12052 this.genMethod((($0 = world.get$coreimpl().types.$index('StringImplementation' ).getMember$1('contains')) && $0.is$Member())); 11579 this.genMethod((($0 = world.get$coreimpl().types.$index('StringImplementation' ).getMember$1('contains')) && $0.is$Member()));
11580 if ($notnull_bool(world.corelib.types.$index('Isolate').get$isUsed()) || $notn ull_bool(world.get$coreimpl().types.$index('ReceivePortImpl').get$isUsed())) {
11581 this.corejs.useIsolates = true;
11582 var isolateMain = (($0 = world.get$coreimpl().topType.resolveMember('startAs Isolate').members.$index(0)) && $0.is$MethodMember());
11583 mainCall = isolateMain.invoke((metaGen && metaGen.is$MethodGenerator()), nul l, null, new Arguments(null, [this.main._get((metaGen && metaGen.is$MethodGenera tor()), this.main.definition, null, false)]), false);
11584 }
12053 this.writeTypes(world.get$coreimpl()); 11585 this.writeTypes(world.get$coreimpl());
12054 this.writeTypes(world.corelib); 11586 this.writeTypes(world.corelib);
12055 this.writeTypes(this.main.declaringType.get$library()); 11587 this.writeTypes(this.main.declaringType.get$library());
12056 this._writeGlobals(); 11588 this._writeGlobals();
12057 this.writer.writeln(('RunEntry(function() {' + mainCall.code + ';}, []);')); 11589 this.writer.writeln(('' + mainCall.code + ';'));
12058 } 11590 }
12059 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe ndencies) { 11591 WorldGenerator.prototype.globalForStaticField = function(field, fieldValue, depe ndencies) {
12060 var $0; 11592 var $0;
12061 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname () + ""); 11593 var fullname = ("" + field.declaringType.get$jsname() + "." + field.get$jsname () + "");
12062 if (!this.globals.containsKey(fullname)) { 11594 if (!this.globals.containsKey(fullname)) {
12063 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory( field, fieldValue, dependencies)); 11595 this.globals.$setindex(fullname, GlobalValue.GlobalValue$fromStatic$factory( field, fieldValue, dependencies));
12064 } 11596 }
12065 return (($0 = this.globals.$index(fullname)) && $0.is$GlobalValue()); 11597 return (($0 = this.globals.$index(fullname)) && $0.is$GlobalValue());
12066 } 11598 }
12067 WorldGenerator.prototype.globalForConst = function(exp, dependencies) { 11599 WorldGenerator.prototype.globalForConst = function(exp, dependencies) {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
12564 else if ($notnull_bool(this.method.get$isStatic())) { 12096 else if ($notnull_bool(this.method.get$isStatic())) {
12565 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' + th is.method.get$jsname() + ' = function' + _params + ' {')); 12097 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.' + th is.method.get$jsname() + ' = function' + _params + ' {'));
12566 } 12098 }
12567 else { 12099 else {
12568 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.protot ype.') + ('' + this.method.get$jsname() + ' = function' + _params + ' {')); 12100 defWriter.enterBlock(('' + this.method.declaringType.get$jsname() + '.protot ype.') + ('' + this.method.get$jsname() + ' = function' + _params + ' {'));
12569 } 12101 }
12570 if ($notnull_bool(this.needsThis)) { 12102 if ($notnull_bool(this.needsThis)) {
12571 defWriter.writeln('var \$this = this; // closure support'); 12103 defWriter.writeln('var \$this = this; // closure support');
12572 } 12104 }
12573 if (this._usedTemps.get$length() > 0 || this._freeTemps.length > 0) { 12105 if (this._usedTemps.get$length() > 0 || this._freeTemps.length > 0) {
12574 $assert(this._usedTemps.get$length() == 0, "_usedTemps.length == 0", "gen.da rt", 696, 14); 12106 $assert(this._usedTemps.get$length() == 0, "_usedTemps.length == 0", "gen.da rt", 707, 14);
12575 this._freeTemps.addAll(this._usedTemps); 12107 this._freeTemps.addAll(this._usedTemps);
12576 this._freeTemps.sort((function (x, y) { 12108 this._freeTemps.sort((function (x, y) {
12577 return x.compareTo$1(y); 12109 return x.compareTo$1(y);
12578 }) 12110 })
12579 ); 12111 );
12580 defWriter.writeln(('var ' + Strings.join(this._freeTemps, ", ") + ';')); 12112 defWriter.writeln(('var ' + Strings.join(this._freeTemps, ", ") + ';'));
12581 } 12113 }
12582 defWriter.writeln(this.writer.get$text()); 12114 defWriter.writeln(this.writer.get$text());
12583 if ($notnull_bool($ne(names, null))) { 12115 if ($notnull_bool($ne(names, null))) {
12584 defWriter.exitBlock(('}).bind(null, ' + Strings.join((names && names.is$List $String()), ", ") + ')')); 12116 defWriter.exitBlock(('}).bind(null, ' + Strings.join((names && names.is$List $String()), ", ") + ')'));
(...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after
13713 } 13245 }
13714 MethodGenerator.prototype.visitSuperExpression = function(node) { 13246 MethodGenerator.prototype.visitSuperExpression = function(node) {
13715 return this._makeSuperValue(node); 13247 return this._makeSuperValue(node);
13716 } 13248 }
13717 MethodGenerator.prototype.visitNullExpression = function(node) { 13249 MethodGenerator.prototype.visitNullExpression = function(node) {
13718 return EvaluatedValue.EvaluatedValue$factory(world.varType, null, 'null', null ); 13250 return EvaluatedValue.EvaluatedValue$factory(world.varType, null, 'null', null );
13719 } 13251 }
13720 MethodGenerator.prototype.visitLiteralExpression = function(node) { 13252 MethodGenerator.prototype.visitLiteralExpression = function(node) {
13721 var $0; 13253 var $0;
13722 var type = node.type.type; 13254 var type = node.type.type;
13723 $assert($ne(type, null), "type != null", "gen.dart", 2084, 12); 13255 $assert($ne(type, null), "type != null", "gen.dart", 2095, 12);
13724 if (!!(($0 = node.value) && $0.is$List)) { 13256 if (!!(($0 = node.value) && $0.is$List)) {
13725 var items = []; 13257 var items = [];
13726 var $list = node.value; 13258 var $list = node.value;
13727 for (var $i = node.value.iterator$0(); $i.hasNext$0(); ) { 13259 for (var $i = node.value.iterator$0(); $i.hasNext$0(); ) {
13728 var item = $i.next$0(); 13260 var item = $i.next$0();
13729 var val = this.visitValue((item && item.is$lang_Expression())); 13261 var val = this.visitValue((item && item.is$lang_Expression()));
13730 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY()); 13262 val.invoke$4(this, 'toString', item, Arguments.get$EMPTY());
13731 var code = val.code; 13263 var code = val.code;
13732 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr ession)) { 13264 if ((item instanceof BinaryExpression) || (item instanceof ConditionalExpr ession)) {
13733 code = ('(' + code + ')'); 13265 code = ('(' + code + ')');
(...skipping 8009 matching lines...) Expand 10 before | Expand all | Expand 10 after
21743 return this._typeAssert(context, toType, node); 21275 return this._typeAssert(context, toType, node);
21744 } 21276 }
21745 else { 21277 else {
21746 return this; 21278 return this;
21747 } 21279 }
21748 } 21280 }
21749 Value.prototype._isDomCallback = function(toType) { 21281 Value.prototype._isDomCallback = function(toType) {
21750 return ((toType.get$definition() instanceof FunctionTypeDefinition) && $eq(toT ype.get$library(), world.get$dom())); 21282 return ((toType.get$definition() instanceof FunctionTypeDefinition) && $eq(toT ype.get$library(), world.get$dom()));
21751 } 21283 }
21752 Value.prototype._wrapDomCallback = function(toType, arity) { 21284 Value.prototype._wrapDomCallback = function(toType, arity) {
21285 if (arity == 0) {
21286 world.gen.corejs.useWrap0 = true;
21287 }
21288 else {
21289 world.gen.corejs.useWrap1 = true;
21290 }
21753 return new Value(toType, ('\$wrap_call\$' + arity + '(' + this.code + ')'), th is.span, true); 21291 return new Value(toType, ('\$wrap_call\$' + arity + '(' + this.code + ')'), th is.span, true);
21754 } 21292 }
21755 Value.prototype._typeAssert = function(context, toType, node) { 21293 Value.prototype._typeAssert = function(context, toType, node) {
21756 if ((toType instanceof ParameterType)) { 21294 if ((toType instanceof ParameterType)) {
21757 var p = (toType && toType.is$ParameterType()); 21295 var p = (toType && toType.is$ParameterType());
21758 toType = p.extendsType; 21296 toType = p.extendsType;
21759 } 21297 }
21760 if (toType.getCallMethod() != null) { 21298 if (toType.getCallMethod() != null) {
21761 return this; 21299 return this;
21762 } 21300 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
21837 for (var i = 0; 21375 for (var i = 0;
21838 i < args.get$length(); i++) { 21376 i < args.get$length(); i++) {
21839 argsCode.add$1(args.values.$index(i).code); 21377 argsCode.add$1(args.values.$index(i).code);
21840 } 21378 }
21841 pos = Strings.join((argsCode && argsCode.is$List$String()), ", "); 21379 pos = Strings.join((argsCode && argsCode.is$List$String()), ", ");
21842 } 21380 }
21843 var noSuchArgs = [new Value(world.stringType, ('"' + name + '"'), node.span, t rue), new Value(world.listType, ('[' + pos + ']'), node.span, true)]; 21381 var noSuchArgs = [new Value(world.stringType, ('"' + name + '"'), node.span, t rue), new Value(world.listType, ('[' + pos + ']'), node.span, true)];
21844 return this._resolveMember(context, 'noSuchMethod', node, false).invoke$4(cont ext, node, this, new Arguments(null, noSuchArgs)); 21382 return this._resolveMember(context, 'noSuchMethod', node, false).invoke$4(cont ext, node, this, new Arguments(null, noSuchArgs));
21845 } 21383 }
21846 Value.prototype.invokeSpecial = function(name, args, returnType) { 21384 Value.prototype.invokeSpecial = function(name, args, returnType) {
21847 $assert(name.startsWith('\$'), "name.startsWith('\\$')", "value.dart", 455, 12 ); 21385 $assert(name.startsWith('\$'), "name.startsWith('\\$')", "value.dart", 475, 12 );
21848 $assert(!$notnull_bool(args.get$hasNames()), "!args.hasNames", "value.dart", 4 56, 12); 21386 $assert(!$notnull_bool(args.get$hasNames()), "!args.hasNames", "value.dart", 4 76, 12);
21849 var argsString = args.getCode(); 21387 var argsString = args.getCode();
21850 if (name == '\$index' || name == '\$setindex') { 21388 if (name == '\$index' || name == '\$setindex') {
21851 return new Value(returnType, ('' + this.code + '.' + name + '(' + argsString + ')'), this.span, true); 21389 return new Value(returnType, ('' + this.code + '.' + name + '(' + argsString + ')'), this.span, true);
21852 } 21390 }
21853 else { 21391 else {
21854 if (argsString.length > 0) argsString = (', ' + argsString + ''); 21392 if (argsString.length > 0) argsString = (', ' + argsString + '');
21855 world.gen.corejs.useOperator(name); 21393 world.gen.corejs.useOperator(name);
21856 return new Value(returnType, ('' + name + '(' + this.code + '' + argsString + ')'), this.span, true); 21394 return new Value(returnType, ('' + name + '(' + this.code + '' + argsString + ')'), this.span, true);
21857 } 21395 }
21858 } 21396 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
22037 }; 21575 };
22038 // ********** Code for BareValue ************** 21576 // ********** Code for BareValue **************
22039 function BareValue(home, outermost, span) { 21577 function BareValue(home, outermost, span) {
22040 this.home = home; 21578 this.home = home;
22041 Value.call(this, outermost.method.declaringType, null, span, false); 21579 Value.call(this, outermost.method.declaringType, null, span, false);
22042 // Initializers done 21580 // Initializers done
22043 this.isType = outermost.get$isStatic(); 21581 this.isType = outermost.get$isStatic();
22044 } 21582 }
22045 $inherits(BareValue, Value); 21583 $inherits(BareValue, Value);
22046 BareValue.prototype._tryResolveMember = function(context, name) { 21584 BareValue.prototype._tryResolveMember = function(context, name) {
22047 $assert($eq(context, this.home), "context == home", "value.dart", 660, 12); 21585 $assert($eq(context, this.home), "context == home", "value.dart", 680, 12);
22048 var member = this.type.resolveMember(name); 21586 var member = this.type.resolveMember(name);
22049 if ($notnull_bool($ne(member, null))) { 21587 if ($notnull_bool($ne(member, null))) {
22050 $assert(this.code == null, "code == null", "value.dart", 665, 14); 21588 $assert(this.code == null, "code == null", "value.dart", 685, 14);
22051 if ($notnull_bool(this.isType)) { 21589 if ($notnull_bool(this.isType)) {
22052 this.code = this.type.get$jsname(); 21590 this.code = this.type.get$jsname();
22053 } 21591 }
22054 else { 21592 else {
22055 this.code = this.home._makeThisCode(); 21593 this.code = this.home._makeThisCode();
22056 } 21594 }
22057 return member; 21595 return member;
22058 } 21596 }
22059 member = this.home.get$library().lookup(name, this.span); 21597 member = this.home.get$library().lookup(name, this.span);
22060 if ($notnull_bool($ne(member, null))) { 21598 if ($notnull_bool($ne(member, null))) {
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
23142 IMPORT, 22680 IMPORT,
23143 INTERFACE, 22681 INTERFACE,
23144 LIBRARY, 22682 LIBRARY,
23145 NATIVE, 22683 NATIVE,
23146 NEGATE, 22684 NEGATE,
23147 OPERATOR, 22685 OPERATOR,
23148 SET, 22686 SET,
23149 SOURCE, 22687 SOURCE,
23150 STATIC, 22688 STATIC,
23151 TYPEDEF ]*/; 22689 TYPEDEF ]*/;
23152 RunEntry(function() {main();}, []); 22690 main();
jimhug 2011/11/16 18:00:45 Yay! 460 fewer lines! And this simple main() looks
OLDNEW
« no previous file with comments | « frog/corejs.dart ('k') | frog/gen.dart » ('j') | frog/lib/isolate.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698