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 = []; | |
8 var isolate$globalThis = this; | 7 var isolate$globalThis = this; |
9 | 8 |
10 // These declarations are needed to avoid errors from the Closure Compiler | 9 // These declarations are needed to avoid errors from the Closure Compiler |
11 // optimizer. They are defined in client/dom/generated/dart_dom_wrapping.js. | 10 // optimizer. They are defined in client/dom/generated/dart_dom_wrapping.js. |
12 var __dom_wrap; | 11 var __dom_wrap; |
13 var __dom_unwrap; | 12 var __dom_unwrap; |
14 | 13 |
15 var isolate$inWorker = | 14 var isolate$inWorker = |
16 (typeof isolate$globalThis['importScripts']) != "undefined"; | 15 (typeof isolate$globalThis['importScripts']) != "undefined"; |
17 var isolate$supportsWorkers = | 16 var isolate$supportsWorkers = |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 */ | 216 */ |
218 function isolate$Isolate() { | 217 function isolate$Isolate() { |
219 // The isolate ids is only unique within the current worker and frame. | 218 // The isolate ids is only unique within the current worker and frame. |
220 this.id = isolate$nextFreeIsolateId++; | 219 this.id = isolate$nextFreeIsolateId++; |
221 // When storing information on DOM nodes the isolate's id is not enough. | 220 // When storing information on DOM nodes the isolate's id is not enough. |
222 // We instead use a token with a hashcode. The token can be stored in the | 221 // We instead use a token with a hashcode. The token can be stored in the |
223 // DOM node (since it is small and will not keep much data alive). | 222 // DOM node (since it is small and will not keep much data alive). |
224 this.token = new Object(); | 223 this.token = new Object(); |
225 this.token.hashCode = (Math.random() * 0xFFFFFFF) >>> 0; | 224 this.token.hashCode = (Math.random() * 0xFFFFFFF) >>> 0; |
226 this.receivePorts = new isolate$Registry(); | 225 this.receivePorts = new isolate$Registry(); |
227 this.run(function() { | |
228 // The Dart-to-JavaScript compiler builds a list of functions that | |
229 // need to run for each isolate to setup the state of static | |
230 // variables. Run through the list and execute each function. | |
231 for (var i = 0, len = isolate$inits.length; i < len; i++) { | |
232 isolate$inits[i](); | |
233 } | |
234 }); | |
235 } | 226 } |
236 | 227 |
237 // It is allowed to stack 'run' calls. The stacked isolates can be different. | 228 // It is allowed to stack 'run' calls. The stacked isolates can be different. |
238 // That is Isolate1.run could call the DOM which then calls Isolate2.run. | 229 // That is Isolate1.run could call the DOM which then calls Isolate2.run. |
239 isolate$Isolate.prototype.run = function(code) { | 230 isolate$Isolate.prototype.run = function(code) { |
240 var old = isolate$current; | 231 var old = isolate$current; |
241 isolate$current = this; | 232 isolate$current = this; |
242 var result = null; | 233 var result = null; |
243 try { | 234 try { |
244 result = code(); | 235 result = code(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // We also store the id on the worker itself so that we can unregister it. | 361 // We also store the id on the worker itself so that we can unregister it. |
371 worker.id = workerId; | 362 worker.id = workerId; |
372 isolate$workerRegistry.register(workerId, worker); | 363 isolate$workerRegistry.register(workerId, worker); |
373 worker.postMessage({ command: 'start', | 364 worker.postMessage({ command: 'start', |
374 id: workerId, | 365 id: workerId, |
375 replyTo: serializedReplyPort, | 366 replyTo: serializedReplyPort, |
376 factoryName: factoryName }); | 367 factoryName: factoryName }); |
377 } | 368 } |
378 | 369 |
379 function native_SendPortImpl__sendNow(message, replyTo) { | 370 function native_SendPortImpl__sendNow(message, replyTo) { |
380 if (replyTo !== $Dart$Null && !(replyTo instanceof SendPortImpl$Dart)) { | 371 if (replyTo !== $Dart$Null && !(replyTo.$implements$SendPortImpl$Dart)) { |
381 throw "SendPort::send: Illegal replyTo type."; | 372 throw "SendPort::send: Illegal replyTo type."; |
382 } | 373 } |
383 message = isolate$serializeMessage(message); | 374 message = isolate$serializeMessage(message); |
384 replyTo = isolate$serializeMessage(replyTo); | 375 replyTo = isolate$serializeMessage(replyTo); |
385 var workerId = native_SendPortImpl__getWorkerId(this); | 376 var workerId = native_SendPortImpl__getWorkerId(this); |
386 var isolateId = native_SendPortImpl__getIsolateId(this); | 377 var isolateId = native_SendPortImpl__getIsolateId(this); |
387 var receivePortId = native_SendPortImpl__getReceivePortId(this); | 378 var receivePortId = native_SendPortImpl__getReceivePortId(this); |
388 isolate$sendMessage(workerId, isolateId, receivePortId, message, replyTo); | 379 isolate$sendMessage(workerId, isolateId, receivePortId, message, replyTo); |
389 } | 380 } |
390 | 381 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 510 } |
520 | 511 |
521 function isolate$deserializeMessage(message) { | 512 function isolate$deserializeMessage(message) { |
522 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) { | 513 if (isolate$useWorkers || isolate$useWorkerSerializationProtocol) { |
523 return native__IsolateJsUtil__deserializeMessage(message); | 514 return native__IsolateJsUtil__deserializeMessage(message); |
524 } else { | 515 } else { |
525 // Nothing more to do. | 516 // Nothing more to do. |
526 return message; | 517 return message; |
527 } | 518 } |
528 } | 519 } |
OLD | NEW |