| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 var isolate$current = null; | 5 var isolate$current = null; |
| 6 var isolate$rootIsolate = null; // Will only be set in the main worker. | 6 var isolate$rootIsolate = null; // Will only be set in the main worker. |
| 7 var isolate$inits = []; | 7 var isolate$inits = []; |
| 8 var isolate$globalThis = this; | 8 var isolate$globalThis = this; |
| 9 | 9 |
| 10 // These declarations are needed to avoid errors from the Closure Compiler | 10 // These declarations are needed to avoid errors from the Closure Compiler |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (id in this.map) { | 105 if (id in this.map) { |
| 106 delete this.map[id]; | 106 delete this.map[id]; |
| 107 this.count--; | 107 this.count--; |
| 108 } | 108 } |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 isolate$Registry.prototype.get = function(id) { | 111 isolate$Registry.prototype.get = function(id) { |
| 112 return this.map[id]; | 112 return this.map[id]; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 isolate$Registry.prototype.contains = function(id) { |
| 116 return this.map[id] !== void 0; |
| 117 }; |
| 118 |
| 115 isolate$Registry.prototype.isEmpty = function() { | 119 isolate$Registry.prototype.isEmpty = function() { |
| 116 return this.count === 0; | 120 return this.count === 0; |
| 117 }; | 121 }; |
| 118 | 122 |
| 119 | 123 |
| 120 // ------- Worker registry ------- | 124 // ------- Worker registry ------- |
| 121 // Only used in the main worker. | 125 // Only used in the main worker. |
| 122 var isolate$workerRegistry = new isolate$Registry(); | 126 var isolate$workerRegistry = new isolate$Registry(); |
| 123 | 127 |
| 124 // ------- Isolate registry ------- | 128 // ------- Isolate registry ------- |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 isolate$mainWorker.postMessage( { command: 'close' } ); | 385 isolate$mainWorker.postMessage( { command: 'close' } ); |
| 382 } | 386 } |
| 383 | 387 |
| 384 function isolate$doOneEventLoopIteration() { | 388 function isolate$doOneEventLoopIteration() { |
| 385 var CONTINUE_LOOP = true; | 389 var CONTINUE_LOOP = true; |
| 386 var STOP_LOOP = false; | 390 var STOP_LOOP = false; |
| 387 var event = isolate$IsolateEvent.dequeue(); | 391 var event = isolate$IsolateEvent.dequeue(); |
| 388 if (!event) { | 392 if (!event) { |
| 389 if (isolate$inWorker) { | 393 if (isolate$inWorker) { |
| 390 isolate$closeWorkerIfNecessary(); | 394 isolate$closeWorkerIfNecessary(); |
| 391 } else if (!isolate$isolateRegistry.isEmpty() && | 395 } else if (isolate$isolateRegistry.contains(isolate$rootIsolate.id) && |
| 392 isolate$workerRegistry.isEmpty() && | 396 isolate$workerRegistry.isEmpty() && |
| 393 !isolate$supportsWorkers && (typeof(window) == 'undefined')) { | 397 !isolate$supportsWorkers && (typeof(window) == 'undefined')) { |
| 394 // This should only trigger when running on the command-line. | 398 // No events anymore, but the main-worker still has open receive-ports. |
| 395 // We don't want this check to execute in the browser where the isolate | 399 // This simulates the VM's behavior (which instead times out). |
| 396 // might still be alive due to DOM callbacks. | 400 // We only trigger this message when we run on the console (where we |
| 397 // throw Error("Program exited with open ReceivePorts."); | 401 // don't have workers). We don't want this check to execute in the browser |
| 402 // where the isolate might still be alive due to DOM callbacks. |
| 403 throw Error("Program exited with open ReceivePorts."); |
| 398 } | 404 } |
| 399 return STOP_LOOP; | 405 return STOP_LOOP; |
| 400 } else { | 406 } else { |
| 401 event.process(); | 407 event.process(); |
| 402 return CONTINUE_LOOP; | 408 return CONTINUE_LOOP; |
| 403 } | 409 } |
| 404 } | 410 } |
| 405 | 411 |
| 406 function isolate$doRunEventLoop() { | 412 function isolate$doRunEventLoop() { |
| 407 if (typeof window != 'undefined' && window.setTimeout) { | 413 if (typeof window != 'undefined' && window.setTimeout) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 513 } |
| 508 | 514 |
| 509 function isolate$deserializeMessage(message) { | 515 function isolate$deserializeMessage(message) { |
| 510 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) { | 516 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) { |
| 511 return native__IsolateJsUtil__deserializeMessage(message); | 517 return native__IsolateJsUtil__deserializeMessage(message); |
| 512 } else { | 518 } else { |
| 513 // Nothing more to do. | 519 // Nothing more to do. |
| 514 return message; | 520 return message; |
| 515 } | 521 } |
| 516 } | 522 } |
| OLD | NEW |