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

Side by Side Diff: lib/runtime/dart/_isolate_helper.js

Issue 1207313002: initial sync*, part of #221 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « no previous file | lib/runtime/dart/_js_helper.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 dart_library.library('dart/_isolate_helper', null, /* Imports */[ 1 dart_library.library('dart/_isolate_helper', null, /* Imports */[
2 "dart_runtime/dart", 2 "dart_runtime/dart",
3 'dart/core', 3 'dart/core',
4 'dart/_interceptors', 4 'dart/_interceptors',
5 'dart/_js_helper', 5 'dart/_js_helper',
6 'dart/isolate', 6 'dart/isolate',
7 'dart/_foreign_helper', 7 'dart/_foreign_helper',
8 'dart/collection', 8 'dart/collection',
9 'dart/async' 9 'dart/async'
10 ], /* Lazy imports */[ 10 ], /* Lazy imports */[
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 495 }
496 } 496 }
497 [_nativeDetectEnvironment]() { 497 [_nativeDetectEnvironment]() {
498 let isWindowDefined = exports.globalWindow != null; 498 let isWindowDefined = exports.globalWindow != null;
499 let isWorkerDefined = exports.globalWorker != null; 499 let isWorkerDefined = exports.globalWorker != null;
500 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo balPostMessageDefined); 500 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo balPostMessageDefined);
501 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke rDefined) && IsolateNatives.thisScript != null; 501 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke rDefined) && IsolateNatives.thisScript != null;
502 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi s.isWorker); 502 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi s.isWorker);
503 } 503 }
504 [_nativeInitWorkerMessageHandler]() { 504 [_nativeInitWorkerMessageHandler]() {
505 let func = function(f, a) { 505 let func = (function(f, a) {
506 return function(e) { 506 return function(e) {
507 f(a, e); 507 f(a, e);
508 }; 508 };
509 }(IsolateNatives._processWorkerMessage, this.mainManager); 509 })(IsolateNatives._processWorkerMessage, this.mainManager);
510 self.onmessage = func; 510 self.onmessage = func;
511 self.dartPrint = self.dartPrint || function(serialize) { 511 self.dartPrint = self.dartPrint || (function(serialize) {
512 return function(object) { 512 return function(object) {
513 if (self.console && self.console.log) { 513 if (self.console && self.console.log) {
514 self.console.log(object); 514 self.console.log(object);
515 } else { 515 } else {
516 self.postMessage(serialize(object)); 516 self.postMessage(serialize(object));
517 } 517 }
518 }; 518 };
519 }(_Manager._serializePrintMessage); 519 })(_Manager._serializePrintMessage);
520 } 520 }
521 static _serializePrintMessage(object) { 521 static _serializePrintMessage(object) {
522 return _serializeMessage(dart.map({command: "print", msg: object})); 522 return _serializeMessage(dart.map({command: "print", msg: object}));
523 } 523 }
524 maybeCloseWorker() { 524 maybeCloseWorker() {
525 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) && this.topEventLoop[_activeJsAsyncCount] == 0) { 525 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) && this.topEventLoop[_activeJsAsyncCount] == 0) {
526 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '}))); 526 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '})));
527 } 527 }
528 } 528 }
529 } 529 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 setErrorsFatal(authentification, errorsAreFatal) { 604 setErrorsFatal(authentification, errorsAreFatal) {
605 if (!dart.equals(this.terminateCapability, authentification)) 605 if (!dart.equals(this.terminateCapability, authentification))
606 return; 606 return;
607 this.errorsAreFatal = errorsAreFatal; 607 this.errorsAreFatal = errorsAreFatal;
608 } 608 }
609 handlePing(responsePort, pingType) { 609 handlePing(responsePort, pingType) {
610 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { 610 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) {
611 responsePort.send(null); 611 responsePort.send(null);
612 return; 612 return;
613 } 613 }
614 let respond = () => { 614 function respond() {
615 responsePort.send(null); 615 responsePort.send(null);
616 }; 616 }
617 dart.fn(respond, dart.void, []); 617 dart.fn(respond, dart.void, []);
618 if (pingType == isolate.Isolate.AS_EVENT) { 618 if (pingType == isolate.Isolate.AS_EVENT) {
619 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); 619 exports._globalState.topEventLoop.enqueue(this, respond, "ping");
620 return; 620 return;
621 } 621 }
622 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); 622 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT);
623 if (this[_scheduledControlEvents] == null) { 623 if (this[_scheduledControlEvents] == null) {
624 this[_scheduledControlEvents] = collection.Queue.new(); 624 this[_scheduledControlEvents] = collection.Queue.new();
625 } 625 }
626 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); 626 dart.dsend(this[_scheduledControlEvents], 'addLast', respond);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 if (event == null) { 853 if (event == null) {
854 this.checkOpenReceivePortsFromCommandLine(); 854 this.checkOpenReceivePortsFromCommandLine();
855 exports._globalState.maybeCloseWorker(); 855 exports._globalState.maybeCloseWorker();
856 return false; 856 return false;
857 } 857 }
858 event.process(); 858 event.process();
859 return true; 859 return true;
860 } 860 }
861 [_runHelper]() { 861 [_runHelper]() {
862 if (exports.globalWindow != null) { 862 if (exports.globalWindow != null) {
863 let next = () => { 863 let next = (function() {
864 if (!dart.notNull(this.runIteration())) 864 if (!dart.notNull(this.runIteration()))
865 return; 865 return;
866 async.Timer.run(next); 866 async.Timer.run(next);
867 }; 867 }).bind(this);
868 dart.fn(next); 868 dart.fn(next);
869 next(); 869 next();
870 } else { 870 } else {
871 while (dart.notNull(this.runIteration())) { 871 while (dart.notNull(this.runIteration())) {
872 } 872 }
873 } 873 }
874 } 874 }
875 run() { 875 run() {
876 if (!dart.notNull(exports._globalState.isWorker)) { 876 if (!dart.notNull(exports._globalState.isWorker)) {
877 this[_runHelper](); 877 this[_runHelper]();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 } 956 }
957 static computeThisScriptJsshell() { 957 static computeThisScriptJsshell() {
958 return dart.as(thisFilename(), core.String); 958 return dart.as(thisFilename(), core.String);
959 } 959 }
960 static computeThisScriptD8() { 960 static computeThisScriptD8() {
961 return IsolateNatives.computeThisScriptFromTrace(); 961 return IsolateNatives.computeThisScriptFromTrace();
962 } 962 }
963 static computeThisScriptFromTrace() { 963 static computeThisScriptFromTrace() {
964 let stack = new Error().stack; 964 let stack = new Error().stack;
965 if (stack == null) { 965 if (stack == null) {
966 stack = function() { 966 stack = (function() {
967 try { 967 try {
968 throw new Error(); 968 throw new Error();
969 } catch (e) { 969 } catch (e) {
970 return e.stack; 970 return e.stack;
971 } 971 }
972 972
973 }(); 973 })();
974 if (stack == null) 974 if (stack == null)
975 throw new core.UnsupportedError('No stack trace'); 975 throw new core.UnsupportedError('No stack trace');
976 } 976 }
977 let pattern = null, matches = null; 977 let pattern = null, matches = null;
978 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); 978 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m");
979 matches = stack.match(pattern); 979 matches = stack.match(pattern);
980 if (matches != null) 980 if (matches != null)
981 return matches[1]; 981 return matches[1];
982 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); 982 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m");
983 matches = stack.match(pattern); 983 matches = stack.match(pattern);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 }), 'nonworker start'); 1145 }), 'nonworker start');
1146 } 1146 }
1147 static get currentIsolate() { 1147 static get currentIsolate() {
1148 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext); 1148 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext);
1149 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability}); 1149 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability});
1150 } 1150 }
1151 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply To) { 1151 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply To) {
1152 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext); 1152 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext);
1153 _js_helper.Primitives.initializeStatics(context.id); 1153 _js_helper.Primitives.initializeStatics(context.id);
1154 replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pause Capability, context.terminateCapability]); 1154 replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pause Capability, context.terminateCapability]);
1155 let runStartFunction = () => { 1155 function runStartFunction() {
1156 context.initialized = true; 1156 context.initialized = true;
1157 if (!dart.notNull(isSpawnUri)) { 1157 if (!dart.notNull(isSpawnUri)) {
1158 dart.dcall(topLevel, message); 1158 dart.dcall(topLevel, message);
1159 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { 1159 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) {
1160 dart.dcall(topLevel, args, message); 1160 dart.dcall(topLevel, args, message);
1161 } else if (dart.is(topLevel, _MainFunctionArgs)) { 1161 } else if (dart.is(topLevel, _MainFunctionArgs)) {
1162 dart.dcall(topLevel, args); 1162 dart.dcall(topLevel, args);
1163 } else { 1163 } else {
1164 dart.dcall(topLevel); 1164 dart.dcall(topLevel);
1165 } 1165 }
1166 }; 1166 }
1167 dart.fn(runStartFunction, dart.void, []); 1167 dart.fn(runStartFunction, dart.void, []);
1168 if (dart.notNull(startPaused)) { 1168 if (dart.notNull(startPaused)) {
1169 context.addPause(context.pauseCapability, context.pauseCapability); 1169 context.addPause(context.pauseCapability, context.pauseCapability);
1170 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st art isolate'); 1170 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st art isolate');
1171 } else { 1171 } else {
1172 runStartFunction(); 1172 runStartFunction();
1173 } 1173 }
1174 } 1174 }
1175 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) { 1175 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) {
1176 if (uri == null) 1176 if (uri == null)
1177 uri = IsolateNatives.thisScript; 1177 uri = IsolateNatives.thisScript;
1178 let worker = new Worker(uri); 1178 let worker = new Worker(uri);
1179 let onerrorTrampoline = function(f, u, c) { 1179 let onerrorTrampoline = (function(f, u, c) {
1180 return function(e) { 1180 return function(e) {
1181 return f(e, u, c); 1181 return f(e, u, c);
1182 }; 1182 };
1183 }(IsolateNatives.workerOnError, uri, onError); 1183 })(IsolateNatives.workerOnError, uri, onError);
1184 worker.onerror = onerrorTrampoline; 1184 worker.onerror = onerrorTrampoline;
1185 let processWorkerMessageTrampoline = function(f, a) { 1185 let processWorkerMessageTrampoline = (function(f, a) {
1186 return function(e) { 1186 return function(e) {
1187 e.onerror = null; 1187 e.onerror = null;
1188 return f(a, e); 1188 return f(a, e);
1189 }; 1189 };
1190 }(IsolateNatives._processWorkerMessage, worker); 1190 })(IsolateNatives._processWorkerMessage, worker);
1191 worker.onmessage = processWorkerMessageTrampoline; 1191 worker.onmessage = processWorkerMessageTrampoline;
1192 let o = exports._globalState; 1192 let o = exports._globalState;
1193 let workerId = o.nextManagerId; 1193 let workerId = o.nextManagerId;
1194 o.nextManagerId = dart.notNull(workerId) + 1; 1194 o.nextManagerId = dart.notNull(workerId) + 1;
1195 IsolateNatives.workerIds.set(worker, workerId); 1195 IsolateNatives.workerIds.set(worker, workerId);
1196 exports._globalState.managers.set(workerId, worker); 1196 exports._globalState.managers.set(workerId, worker);
1197 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio nName}))); 1197 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio nName})));
1198 } 1198 }
1199 static workerOnError(event, uri, onError) { 1199 static workerOnError(event, uri, onError) {
1200 event.preventDefault(); 1200 event.preventDefault();
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 }); 1436 });
1437 let _once = Symbol('_once'); 1437 let _once = Symbol('_once');
1438 let _inEventLoop = Symbol('_inEventLoop'); 1438 let _inEventLoop = Symbol('_inEventLoop');
1439 let _handle = Symbol('_handle'); 1439 let _handle = Symbol('_handle');
1440 class TimerImpl extends core.Object { 1440 class TimerImpl extends core.Object {
1441 TimerImpl(milliseconds, callback) { 1441 TimerImpl(milliseconds, callback) {
1442 this[_once] = true; 1442 this[_once] = true;
1443 this[_inEventLoop] = false; 1443 this[_inEventLoop] = false;
1444 this[_handle] = null; 1444 this[_handle] = null;
1445 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export s._globalState.isWorker))) { 1445 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export s._globalState.isWorker))) {
1446 let internalCallback = () => { 1446 let internalCallback = (function() {
1447 this[_handle] = null; 1447 this[_handle] = null;
1448 callback(); 1448 callback();
1449 }; 1449 }).bind(this);
1450 dart.fn(internalCallback, dart.void, []); 1450 dart.fn(internalCallback, dart.void, []);
1451 this[_handle] = 1; 1451 this[_handle] = 1;
1452 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo ntext, internalCallback, 'timer'); 1452 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo ntext, internalCallback, 'timer');
1453 this[_inEventLoop] = true; 1453 this[_inEventLoop] = true;
1454 } else if (dart.notNull(hasTimer())) { 1454 } else if (dart.notNull(hasTimer())) {
1455 let internalCallback = () => { 1455 let internalCallback = (function() {
1456 this[_handle] = null; 1456 this[_handle] = null;
1457 leaveJsAsync(); 1457 leaveJsAsync();
1458 callback(); 1458 callback();
1459 }; 1459 }).bind(this);
1460 dart.fn(internalCallback, dart.void, []); 1460 dart.fn(internalCallback, dart.void, []);
1461 enterJsAsync(); 1461 enterJsAsync();
1462 this[_handle] = self.setTimeout(internalCallback, milliseconds); 1462 this[_handle] = self.setTimeout(internalCallback, milliseconds);
1463 } else { 1463 } else {
1464 dart.assert(dart.notNull(milliseconds) > 0); 1464 dart.assert(dart.notNull(milliseconds) > 0);
1465 throw new core.UnsupportedError("Timer greater than 0."); 1465 throw new core.UnsupportedError("Timer greater than 0.");
1466 } 1466 }
1467 } 1467 }
1468 periodic(milliseconds, callback) { 1468 periodic(milliseconds, callback) {
1469 this[_once] = false; 1469 this[_once] = false;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 exports.leaveJsAsync = leaveJsAsync; 1554 exports.leaveJsAsync = leaveJsAsync;
1555 exports.isWorker = isWorker; 1555 exports.isWorker = isWorker;
1556 exports.startRootIsolate = startRootIsolate; 1556 exports.startRootIsolate = startRootIsolate;
1557 exports.IsolateNatives = IsolateNatives; 1557 exports.IsolateNatives = IsolateNatives;
1558 exports.RawReceivePortImpl = RawReceivePortImpl; 1558 exports.RawReceivePortImpl = RawReceivePortImpl;
1559 exports.ReceivePortImpl = ReceivePortImpl; 1559 exports.ReceivePortImpl = ReceivePortImpl;
1560 exports.TimerImpl = TimerImpl; 1560 exports.TimerImpl = TimerImpl;
1561 exports.hasTimer = hasTimer; 1561 exports.hasTimer = hasTimer;
1562 exports.CapabilityImpl = CapabilityImpl; 1562 exports.CapabilityImpl = CapabilityImpl;
1563 }); 1563 });
OLDNEW
« no previous file with comments | « no previous file | lib/runtime/dart/_js_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698