Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: runtime/lib/isolate_patch.dart

Issue 771993003: Add Isolate.current getter, returning the current isolate as an Isolate object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 import "dart:collection" show HashMap; 5 import "dart:collection" show HashMap;
6 6
7 patch class ReceivePort { 7 patch class ReceivePort {
8 /* patch */ factory ReceivePort() = _ReceivePortImpl; 8 /* patch */ factory ReceivePort() = _ReceivePortImpl;
9 9
10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) =
11 _ReceivePortImpl.fromRawReceivePort; 11 _ReceivePortImpl.fromRawReceivePort;
12 } 12 }
13 13
14 patch class Capability { 14 patch class Capability {
15 /* patch */ factory Capability() = _CapabilityImpl; 15 /* patch */ factory Capability() = _CapabilityImpl;
16 } 16 }
17 17
18 class _CapabilityImpl implements Capability { 18 class _CapabilityImpl implements Capability {
19 factory _CapabilityImpl() native "CapabilityImpl_factory"; 19 factory _CapabilityImpl() native "CapabilityImpl_factory";
20
21 String toString() => "Capability#";
20 } 22 }
21 23
22 patch class RawReceivePort { 24 patch class RawReceivePort {
23 /** 25 /**
24 * Opens a long-lived port for receiving messages. 26 * Opens a long-lived port for receiving messages.
25 * 27 *
26 * A [RawReceivePort] is low level and does not work with [Zone]s. It 28 * A [RawReceivePort] is low level and does not work with [Zone]s. It
27 * can not be paused. The data-handler must be set before the first 29 * can not be paused. The data-handler must be set before the first
28 * event is received. 30 * event is received.
29 */ 31 */
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } else { 240 } else {
239 entryPoint(); 241 entryPoint();
240 } 242 }
241 } else { 243 } else {
242 entryPoint(message); 244 entryPoint(message);
243 } 245 }
244 _runPendingImmediateCallback(); 246 _runPendingImmediateCallback();
245 } 247 }
246 248
247 patch class Isolate { 249 patch class Isolate {
250 static final _currentIsolate = _getCurrentIsolate();
251
252 /* patch */ static Isolate get current => _currentIsolate;
253
248 /* patch */ static Future<Isolate> spawn( 254 /* patch */ static Future<Isolate> spawn(
249 void entryPoint(message), var message, { bool paused: false }) { 255 void entryPoint(message), var message, { bool paused: false }) {
250 // `paused` isn't handled yet. 256 // `paused` isn't handled yet.
251 RawReceivePort readyPort; 257 RawReceivePort readyPort;
252 try { 258 try {
253 // The VM will invoke [_startIsolate] with entryPoint as argument. 259 // The VM will invoke [_startIsolate] with entryPoint as argument.
254 readyPort = new RawReceivePort(); 260 readyPort = new RawReceivePort();
255 _spawnFunction(readyPort.sendPort, entryPoint, message); 261 _spawnFunction(readyPort.sendPort, entryPoint, message);
256 Completer completer = new Completer<Isolate>.sync(); 262 Completer completer = new Completer<Isolate>.sync();
257 readyPort.handler = (readyMessage) { 263 readyPort.handler = (readyMessage) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 throw new UnsupportedError("ping"); 367 throw new UnsupportedError("ping");
362 } 368 }
363 369
364 /* patch */ void addErrorListener(SendPort port) { 370 /* patch */ void addErrorListener(SendPort port) {
365 throw new UnsupportedError("addErrorListener"); 371 throw new UnsupportedError("addErrorListener");
366 } 372 }
367 373
368 /* patch */ void removeErrorListener(SendPort port) { 374 /* patch */ void removeErrorListener(SendPort port) {
369 throw new UnsupportedError("removeErrorListener"); 375 throw new UnsupportedError("removeErrorListener");
370 } 376 }
377
378 static Isolate _getCurrentIsolate() {
379 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate();
380 return new Isolate(portAndCapabilities[0],
381 pauseCapability: portAndCapabilities[1],
382 terminateCapability: portAndCapabilities[2]);
383 }
384
385 static List _getPortAndCapabilitiesOfCurrentIsolate()
386 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate";
371 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698