OLD | NEW |
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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }(_foreign_helper.DART_CLOSURE_TO_JS(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 }(_foreign_helper.DART_CLOSURE_TO_JS(_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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives.workerOnError), uri, o
nError); | 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 }(_foreign_helper.DART_CLOSURE_TO_JS(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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = () => { |
1456 this[_handle] = null; | 1456 this[_handle] = null; |
1457 leaveJsAsync(); | 1457 leaveJsAsync(); |
1458 callback(); | 1458 callback(); |
1459 }; | 1459 }; |
1460 dart.fn(internalCallback, dart.void, []); | 1460 dart.fn(internalCallback, dart.void, []); |
1461 enterJsAsync(); | 1461 enterJsAsync(); |
1462 this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(intern
alCallback, 0), 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; |
1470 this[_inEventLoop] = false; | 1470 this[_inEventLoop] = false; |
1471 this[_handle] = null; | 1471 this[_handle] = null; |
1472 if (dart.notNull(hasTimer())) { | 1472 if (dart.notNull(hasTimer())) { |
1473 enterJsAsync(); | 1473 enterJsAsync(); |
1474 this[_handle] = self.setInterval(_js_helper.convertDartClosureToJS(dart.
fn(() => { | 1474 this[_handle] = self.setInterval(dart.fn(() => { |
1475 callback(this); | 1475 callback(this); |
1476 }), 0), milliseconds); | 1476 }), milliseconds); |
1477 } else { | 1477 } else { |
1478 throw new core.UnsupportedError("Periodic timer."); | 1478 throw new core.UnsupportedError("Periodic timer."); |
1479 } | 1479 } |
1480 } | 1480 } |
1481 cancel() { | 1481 cancel() { |
1482 if (dart.notNull(hasTimer())) { | 1482 if (dart.notNull(hasTimer())) { |
1483 if (dart.notNull(this[_inEventLoop])) { | 1483 if (dart.notNull(this[_inEventLoop])) { |
1484 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); | 1484 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); |
1485 } | 1485 } |
1486 if (this[_handle] == null) | 1486 if (this[_handle] == null) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 }); |
OLD | NEW |