| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Concepts used here: | 6 * Concepts used here: |
| 7 * | 7 * |
| 8 * "manager" - A manager contains one or more isolates, schedules their | 8 * "manager" - A manager contains one or more isolates, schedules their |
| 9 * execution, and performs other plumbing on their behalf. The isolate | 9 * execution, and performs other plumbing on their behalf. The isolate |
| 10 * present at the creation of the manager is designated as its "root isolate". | 10 * present at the creation of the manager is designated as its "root isolate". |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void _nativeDetectEnvironment() native @""" | 133 void _nativeDetectEnvironment() native @""" |
| 134 this.isWorker = $isWorker; | 134 this.isWorker = $isWorker; |
| 135 this.supportsWorkers = $supportsWorkers; | 135 this.supportsWorkers = $supportsWorkers; |
| 136 this.fromCommandLine = typeof(window) == 'undefined'; | 136 this.fromCommandLine = typeof(window) == 'undefined'; |
| 137 """; | 137 """; |
| 138 | 138 |
| 139 void _nativeInitWorkerMessageHandler() native @""" | 139 void _nativeInitWorkerMessageHandler() native @""" |
| 140 $globalThis.onmessage = function (e) { | 140 $globalThis.onmessage = function (e) { |
| 141 _IsolateNatives._processWorkerMessage(this.mainManager, e); | 141 _IsolateNatives._processWorkerMessage(this.mainManager, e); |
| 142 } | 142 } |
| 143 """; |
| 144 /*: TODO: check that _processWorkerMessage is not discarded while treeshaking. |
| 143 """ { | 145 """ { |
| 144 _IsolateNatives._processWorkerMessage(null, null); | 146 _IsolateNatives._processWorkerMessage(null, null); |
| 145 } | 147 } |
| 148 */ |
| 149 |
| 146 | 150 |
| 147 /** Close the worker running this code if all isolates are done. */ | 151 /** Close the worker running this code if all isolates are done. */ |
| 148 void maybeCloseWorker() { | 152 void maybeCloseWorker() { |
| 149 if (isolates.isEmpty()) { | 153 if (isolates.isEmpty()) { |
| 150 mainManager.postMessage(_serializeMessage({'command': 'close'})); | 154 mainManager.postMessage(_serializeMessage({'command': 'close'})); |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 } | 157 } |
| 154 | 158 |
| 155 /** Context information tracked for each isolate. */ | 159 /** Context information tracked for each isolate. */ |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 'command': 'start2', | 637 'command': 'start2', |
| 634 'id': workerId, | 638 'id': workerId, |
| 635 // Note: we serialize replyPort twice because the child worker needs to | 639 // Note: we serialize replyPort twice because the child worker needs to |
| 636 // first deserialize the worker id, before it can correctly deserialize | 640 // first deserialize the worker id, before it can correctly deserialize |
| 637 // the port (port deserialization is sensitive to what is the current | 641 // the port (port deserialization is sensitive to what is the current |
| 638 // workerId). | 642 // workerId). |
| 639 'replyTo': _serializeMessage(replyPort), | 643 'replyTo': _serializeMessage(replyPort), |
| 640 'functionName': functionName })); | 644 'functionName': functionName })); |
| 641 } | 645 } |
| 642 } | 646 } |
| OLD | NEW |