| 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 * A native object that is shared across isolates. This object is visible to all | 6 * A native object that is shared across isolates. This object is visible to all |
| 7 * isolates running on the same worker (either UI or background web worker). | 7 * isolates running on the same worker (either UI or background web worker). |
| 8 * | 8 * |
| 9 * This is code that is intended to 'escape' the isolate boundaries in order to | 9 * This is code that is intended to 'escape' the isolate boundaries in order to |
| 10 * implement the semantics of isolates in JavaScript. Without this we would have | 10 * implement the semantics of isolates in JavaScript. Without this we would have |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 void postMessage(msg) native "return this.postMessage(msg);"; | 301 void postMessage(msg) native "return this.postMessage(msg);"; |
| 302 } | 302 } |
| 303 | 303 |
| 304 final String _SPAWNED_SIGNAL = "spawned"; | 304 final String _SPAWNED_SIGNAL = "spawned"; |
| 305 | 305 |
| 306 class _IsolateNatives { | 306 class _IsolateNatives { |
| 307 | 307 |
| 308 /** JavaScript-specific implementation to spawn an isolate. */ | 308 /** JavaScript-specific implementation to spawn an isolate. */ |
| 309 static Future<SendPort> spawn(Isolate isolate, bool isLight) { | 309 static Future<SendPort> spawn(Isolate isolate, bool isLight) { |
| 310 Completer<SendPort> completer = new Completer<SendPort>(); | 310 Completer<SendPort> completer = new Completer<SendPort>(); |
| 311 ReceivePort port = new ReceivePort.singleShot(); | 311 ReceivePort port = new ReceivePort(); |
| 312 port.receive((msg, SendPort replyPort) { | 312 port.receive((msg, SendPort replyPort) { |
| 313 port.close(); |
| 313 assert(msg == _SPAWNED_SIGNAL); | 314 assert(msg == _SPAWNED_SIGNAL); |
| 314 completer.complete(replyPort); | 315 completer.complete(replyPort); |
| 315 }); | 316 }); |
| 316 | 317 |
| 317 // TODO(floitsch): throw exception if isolate's class doesn't have a | 318 // TODO(floitsch): throw exception if isolate's class doesn't have a |
| 318 // default constructor. | 319 // default constructor. |
| 319 if (_globalState.useWorkers && !isLight) { | 320 if (_globalState.useWorkers && !isLight) { |
| 320 _startWorker(isolate, port.toSendPort()); | 321 _startWorker(isolate, port.toSendPort()); |
| 321 } else { | 322 } else { |
| 322 _startNonWorker(isolate, port.toSendPort()); | 323 _startNonWorker(isolate, port.toSendPort()); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 _fillStatics(_globalState.currentContext); | 552 _fillStatics(_globalState.currentContext); |
| 552 ReceivePort port = new ReceivePort(); | 553 ReceivePort port = new ReceivePort(); |
| 553 replyTo.send(_SPAWNED_SIGNAL, port.toSendPort()); | 554 replyTo.send(_SPAWNED_SIGNAL, port.toSendPort()); |
| 554 isolate._run(port); | 555 isolate._run(port); |
| 555 } | 556 } |
| 556 | 557 |
| 557 // TODO(sigmund): clean up above, after we make the new API the default: | 558 // TODO(sigmund): clean up above, after we make the new API the default: |
| 558 | 559 |
| 559 static _spawn2(String functionName, String uri, bool isLight) { | 560 static _spawn2(String functionName, String uri, bool isLight) { |
| 560 Completer<SendPort> completer = new Completer<SendPort>(); | 561 Completer<SendPort> completer = new Completer<SendPort>(); |
| 561 ReceivePort port = new ReceivePort.singleShot(); | 562 ReceivePort port = new ReceivePort(); |
| 562 port.receive((msg, SendPort replyPort) { | 563 port.receive((msg, SendPort replyPort) { |
| 564 port.close(); |
| 563 assert(msg == _SPAWNED_SIGNAL); | 565 assert(msg == _SPAWNED_SIGNAL); |
| 564 completer.complete(replyPort); | 566 completer.complete(replyPort); |
| 565 }); | 567 }); |
| 566 | 568 |
| 567 SendPort signalReply = port.toSendPort(); | 569 SendPort signalReply = port.toSendPort(); |
| 568 | 570 |
| 569 if (_globalState.useWorkers && !isLight) { | 571 if (_globalState.useWorkers && !isLight) { |
| 570 _startWorker2(functionName, uri, signalReply); | 572 _startWorker2(functionName, uri, signalReply); |
| 571 } else { | 573 } else { |
| 572 _startNonWorker2(functionName, uri, signalReply); | 574 _startNonWorker2(functionName, uri, signalReply); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 'command': 'start2', | 631 'command': 'start2', |
| 630 'id': workerId, | 632 'id': workerId, |
| 631 // Note: we serialize replyPort twice because the child worker needs to | 633 // Note: we serialize replyPort twice because the child worker needs to |
| 632 // first deserialize the worker id, before it can correctly deserialize | 634 // first deserialize the worker id, before it can correctly deserialize |
| 633 // the port (port deserialization is sensitive to what is the current | 635 // the port (port deserialization is sensitive to what is the current |
| 634 // workerId). | 636 // workerId). |
| 635 'replyTo': _serializeMessage(replyPort), | 637 'replyTo': _serializeMessage(replyPort), |
| 636 'functionName': functionName })); | 638 'functionName': functionName })); |
| 637 } | 639 } |
| 638 } | 640 } |
| OLD | NEW |