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

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

Issue 2220883004: Use metadata annotation @patch for patch classes (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: wip Created 4 years, 4 months 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
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 import "dart:_internal"; 6 import "dart:_internal";
7 7
8 patch class ReceivePort { 8 @patch class ReceivePort {
9 /* patch */ factory ReceivePort() = _ReceivePortImpl; 9 /* @patch */ factory ReceivePort() = _ReceivePortImpl;
10 10
11 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = 11 /* @patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) =
12 _ReceivePortImpl.fromRawReceivePort; 12 _ReceivePortImpl.fromRawReceivePort;
13 } 13 }
14 14
15 patch class Capability { 15 @patch class Capability {
16 /* patch */ factory Capability() = _CapabilityImpl; 16 /* @patch */ factory Capability() = _CapabilityImpl;
17 } 17 }
18 18
19 class _CapabilityImpl implements Capability { 19 class _CapabilityImpl implements Capability {
20 factory _CapabilityImpl() native "CapabilityImpl_factory"; 20 factory _CapabilityImpl() native "CapabilityImpl_factory";
21 21
22 bool operator==(var other) { 22 bool operator==(var other) {
23 return (other is _CapabilityImpl) && _equals(other); 23 return (other is _CapabilityImpl) && _equals(other);
24 } 24 }
25 25
26 int get hashCode { 26 int get hashCode {
27 return _get_hashcode(); 27 return _get_hashcode();
28 } 28 }
29 29
30 _equals(other) native "CapabilityImpl_equals"; 30 _equals(other) native "CapabilityImpl_equals";
31 _get_hashcode() native "CapabilityImpl_get_hashcode"; 31 _get_hashcode() native "CapabilityImpl_get_hashcode";
32 } 32 }
33 33
34 patch class RawReceivePort { 34 @patch class RawReceivePort {
35 /** 35 /**
36 * Opens a long-lived port for receiving messages. 36 * Opens a long-lived port for receiving messages.
37 * 37 *
38 * A [RawReceivePort] is low level and does not work with [Zone]s. It 38 * A [RawReceivePort] is low level and does not work with [Zone]s. It
39 * can not be paused. The data-handler must be set before the first 39 * can not be paused. The data-handler must be set before the first
40 * event is received. 40 * event is received.
41 */ 41 */
42 /* patch */ factory RawReceivePort([void handler(event)]) { 42 /* @patch */ factory RawReceivePort([void handler(event)]) {
43 _RawReceivePortImpl result = new _RawReceivePortImpl(); 43 _RawReceivePortImpl result = new _RawReceivePortImpl();
44 result.handler = handler; 44 result.handler = handler;
45 return result; 45 return result;
46 } 46 }
47 } 47 }
48 48
49 class _ReceivePortImpl extends Stream implements ReceivePort { 49 class _ReceivePortImpl extends Stream implements ReceivePort {
50 _ReceivePortImpl() : this.fromRawReceivePort(new RawReceivePort()); 50 _ReceivePortImpl() : this.fromRawReceivePort(new RawReceivePort());
51 51
52 _ReceivePortImpl.fromRawReceivePort(this._rawPort) { 52 _ReceivePortImpl.fromRawReceivePort(this._rawPort) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 entryPoint(); 261 entryPoint();
262 } 262 }
263 } else { 263 } else {
264 entryPoint(message); 264 entryPoint(message);
265 } 265 }
266 }; 266 };
267 // Make sure the message handler is triggered. 267 // Make sure the message handler is triggered.
268 port.sendPort.send(null); 268 port.sendPort.send(null);
269 } 269 }
270 270
271 patch class Isolate { 271 @patch class Isolate {
272 static final _currentIsolate = _getCurrentIsolate(); 272 static final _currentIsolate = _getCurrentIsolate();
273 static final _rootUri = _getCurrentRootUri(); 273 static final _rootUri = _getCurrentRootUri();
274 274
275 /* patch */ static Isolate get current => _currentIsolate; 275 /* @patch */ static Isolate get current => _currentIsolate;
276 276
277 /* patch */ static Future<Uri> get packageRoot { 277 /* @patch */ static Future<Uri> get packageRoot {
278 var hook = VMLibraryHooks.packageRootUriFuture; 278 var hook = VMLibraryHooks.packageRootUriFuture;
279 if (hook == null) { 279 if (hook == null) {
280 throw new UnsupportedError("Isolate.packageRoot"); 280 throw new UnsupportedError("Isolate.packageRoot");
281 } 281 }
282 return hook(); 282 return hook();
283 } 283 }
284 284
285 /* patch */ static Future<Uri> get packageConfig { 285 /* @patch */ static Future<Uri> get packageConfig {
286 var hook = VMLibraryHooks.packageConfigUriFuture; 286 var hook = VMLibraryHooks.packageConfigUriFuture;
287 if (hook == null) { 287 if (hook == null) {
288 throw new UnsupportedError("Isolate.packageConfig"); 288 throw new UnsupportedError("Isolate.packageConfig");
289 } 289 }
290 return hook(); 290 return hook();
291 } 291 }
292 292
293 /* patch */ static Future<Uri> resolvePackageUri(Uri packageUri) { 293 /* @patch */ static Future<Uri> resolvePackageUri(Uri packageUri) {
294 var hook = VMLibraryHooks.resolvePackageUriFuture; 294 var hook = VMLibraryHooks.resolvePackageUriFuture;
295 if (hook == null) { 295 if (hook == null) {
296 throw new UnsupportedError("Isolate.resolvePackageUri"); 296 throw new UnsupportedError("Isolate.resolvePackageUri");
297 } 297 }
298 return hook(packageUri); 298 return hook(packageUri);
299 } 299 }
300 300
301 static bool _packageSupported() => 301 static bool _packageSupported() =>
302 (VMLibraryHooks.packageRootUriFuture != null) && 302 (VMLibraryHooks.packageRootUriFuture != null) &&
303 (VMLibraryHooks.packageConfigUriFuture != null) && 303 (VMLibraryHooks.packageConfigUriFuture != null) &&
304 (VMLibraryHooks.resolvePackageUriFuture != null); 304 (VMLibraryHooks.resolvePackageUriFuture != null);
305 305
306 /* patch */ static Future<Isolate> spawn( 306 /* @patch */ static Future<Isolate> spawn(
307 void entryPoint(message), var message, 307 void entryPoint(message), var message,
308 {bool paused: false, bool errorsAreFatal, 308 {bool paused: false, bool errorsAreFatal,
309 SendPort onExit, SendPort onError}) async { 309 SendPort onExit, SendPort onError}) async {
310 // `paused` isn't handled yet. 310 // `paused` isn't handled yet.
311 RawReceivePort readyPort; 311 RawReceivePort readyPort;
312 try { 312 try {
313 // The VM will invoke [_startIsolate] with entryPoint as argument. 313 // The VM will invoke [_startIsolate] with entryPoint as argument.
314 readyPort = new RawReceivePort(); 314 readyPort = new RawReceivePort();
315 315
316 // We do not inherit the package root or package config settings 316 // We do not inherit the package root or package config settings
(...skipping 16 matching lines...) Expand all
333 packageRoot, packageConfig); 333 packageRoot, packageConfig);
334 return await _spawnCommon(readyPort); 334 return await _spawnCommon(readyPort);
335 } catch (e, st) { 335 } catch (e, st) {
336 if (readyPort != null) { 336 if (readyPort != null) {
337 readyPort.close(); 337 readyPort.close();
338 } 338 }
339 return await new Future<Isolate>.error(e, st); 339 return await new Future<Isolate>.error(e, st);
340 } 340 }
341 } 341 }
342 342
343 /* patch */ static Future<Isolate> spawnUri( 343 /* @patch */ static Future<Isolate> spawnUri(
344 Uri uri, List<String> args, var message, 344 Uri uri, List<String> args, var message,
345 {bool paused: false, 345 {bool paused: false,
346 SendPort onExit, 346 SendPort onExit,
347 SendPort onError, 347 SendPort onError,
348 bool errorsAreFatal, 348 bool errorsAreFatal,
349 bool checked, 349 bool checked,
350 Map<String, String> environment, 350 Map<String, String> environment,
351 Uri packageRoot, 351 Uri packageRoot,
352 Uri packageConfig, 352 Uri packageConfig,
353 bool automaticPackageResolution: false}) async { 353 bool automaticPackageResolution: false}) async {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 static void _spawnUri(SendPort readyPort, String uri, 471 static void _spawnUri(SendPort readyPort, String uri,
472 List<String> args, var message, 472 List<String> args, var message,
473 bool paused, SendPort onExit, SendPort onError, 473 bool paused, SendPort onExit, SendPort onError,
474 bool errorsAreFatal, bool checked, 474 bool errorsAreFatal, bool checked,
475 List environment, 475 List environment,
476 String packageRoot, String packageConfig) 476 String packageRoot, String packageConfig)
477 native "Isolate_spawnUri"; 477 native "Isolate_spawnUri";
478 478
479 static void _sendOOB(port, msg) native "Isolate_sendOOB"; 479 static void _sendOOB(port, msg) native "Isolate_sendOOB";
480 480
481 /* patch */ void _pause(Capability resumeCapability) { 481 /* @patch */ void _pause(Capability resumeCapability) {
482 var msg = new List(4) 482 var msg = new List(4)
483 ..[0] = 0 // Make room for OOB message type. 483 ..[0] = 0 // Make room for OOB message type.
484 ..[1] = _PAUSE 484 ..[1] = _PAUSE
485 ..[2] = pauseCapability 485 ..[2] = pauseCapability
486 ..[3] = resumeCapability; 486 ..[3] = resumeCapability;
487 _sendOOB(controlPort, msg); 487 _sendOOB(controlPort, msg);
488 } 488 }
489 489
490 /* patch */ void resume(Capability resumeCapability) { 490 /* @patch */ void resume(Capability resumeCapability) {
491 var msg = new List(4) 491 var msg = new List(4)
492 ..[0] = 0 // Make room for OOB message type. 492 ..[0] = 0 // Make room for OOB message type.
493 ..[1] = _RESUME 493 ..[1] = _RESUME
494 ..[2] = pauseCapability 494 ..[2] = pauseCapability
495 ..[3] = resumeCapability; 495 ..[3] = resumeCapability;
496 _sendOOB(controlPort, msg); 496 _sendOOB(controlPort, msg);
497 } 497 }
498 498
499 /* patch */ void addOnExitListener(SendPort responsePort, 499 /* @patch */ void addOnExitListener(SendPort responsePort,
500 {Object response}) { 500 {Object response}) {
501 var msg = new List(4) 501 var msg = new List(4)
502 ..[0] = 0 // Make room for OOB message type. 502 ..[0] = 0 // Make room for OOB message type.
503 ..[1] = _ADD_EXIT 503 ..[1] = _ADD_EXIT
504 ..[2] = responsePort 504 ..[2] = responsePort
505 ..[3] = response; 505 ..[3] = response;
506 _sendOOB(controlPort, msg); 506 _sendOOB(controlPort, msg);
507 } 507 }
508 508
509 /* patch */ void removeOnExitListener(SendPort responsePort) { 509 /* @patch */ void removeOnExitListener(SendPort responsePort) {
510 var msg = new List(3) 510 var msg = new List(3)
511 ..[0] = 0 // Make room for OOB message type. 511 ..[0] = 0 // Make room for OOB message type.
512 ..[1] = _DEL_EXIT 512 ..[1] = _DEL_EXIT
513 ..[2] = responsePort; 513 ..[2] = responsePort;
514 _sendOOB(controlPort, msg); 514 _sendOOB(controlPort, msg);
515 } 515 }
516 516
517 /* patch */ void setErrorsFatal(bool errorsAreFatal) { 517 /* @patch */ void setErrorsFatal(bool errorsAreFatal) {
518 var msg = new List(4) 518 var msg = new List(4)
519 ..[0] = 0 // Make room for OOB message type. 519 ..[0] = 0 // Make room for OOB message type.
520 ..[1] = _ERROR_FATAL 520 ..[1] = _ERROR_FATAL
521 ..[2] = terminateCapability 521 ..[2] = terminateCapability
522 ..[3] = errorsAreFatal; 522 ..[3] = errorsAreFatal;
523 _sendOOB(controlPort, msg); 523 _sendOOB(controlPort, msg);
524 } 524 }
525 525
526 /* patch */ void kill({int priority: BEFORE_NEXT_EVENT}) { 526 /* @patch */ void kill({int priority: BEFORE_NEXT_EVENT}) {
527 var msg = new List(4) 527 var msg = new List(4)
528 ..[0] = 0 // Make room for OOB message type. 528 ..[0] = 0 // Make room for OOB message type.
529 ..[1] = _KILL 529 ..[1] = _KILL
530 ..[2] = terminateCapability 530 ..[2] = terminateCapability
531 ..[3] = priority; 531 ..[3] = priority;
532 _sendOOB(controlPort, msg); 532 _sendOOB(controlPort, msg);
533 } 533 }
534 534
535 /* patch */ void ping(SendPort responsePort, {Object response, 535 /* @patch */ void ping(SendPort responsePort, {Object response,
536 int priority: IMMEDIATE}) { 536 int priority: IMMEDIATE}) {
537 var msg = new List(5) 537 var msg = new List(5)
538 ..[0] = 0 // Make room for OOM message type. 538 ..[0] = 0 // Make room for OOM message type.
539 ..[1] = _PING 539 ..[1] = _PING
540 ..[2] = responsePort 540 ..[2] = responsePort
541 ..[3] = priority 541 ..[3] = priority
542 ..[4] = response; 542 ..[4] = response;
543 _sendOOB(controlPort, msg); 543 _sendOOB(controlPort, msg);
544 } 544 }
545 545
546 /* patch */ void addErrorListener(SendPort port) { 546 /* @patch */ void addErrorListener(SendPort port) {
547 var msg = new List(3) 547 var msg = new List(3)
548 ..[0] = 0 // Make room for OOB message type. 548 ..[0] = 0 // Make room for OOB message type.
549 ..[1] = _ADD_ERROR 549 ..[1] = _ADD_ERROR
550 ..[2] = port; 550 ..[2] = port;
551 _sendOOB(controlPort, msg); 551 _sendOOB(controlPort, msg);
552 } 552 }
553 553
554 /* patch */ void removeErrorListener(SendPort port) { 554 /* @patch */ void removeErrorListener(SendPort port) {
555 var msg = new List(3) 555 var msg = new List(3)
556 ..[0] = 0 // Make room for OOB message type. 556 ..[0] = 0 // Make room for OOB message type.
557 ..[1] = _DEL_ERROR 557 ..[1] = _DEL_ERROR
558 ..[2] = port; 558 ..[2] = port;
559 _sendOOB(controlPort, msg); 559 _sendOOB(controlPort, msg);
560 } 560 }
561 561
562 static Isolate _getCurrentIsolate() { 562 static Isolate _getCurrentIsolate() {
563 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); 563 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate();
564 return new Isolate(portAndCapabilities[0], 564 return new Isolate(portAndCapabilities[0],
565 pauseCapability: portAndCapabilities[1], 565 pauseCapability: portAndCapabilities[1],
566 terminateCapability: portAndCapabilities[2]); 566 terminateCapability: portAndCapabilities[2]);
567 } 567 }
568 568
569 static List _getPortAndCapabilitiesOfCurrentIsolate() 569 static List _getPortAndCapabilitiesOfCurrentIsolate()
570 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; 570 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate";
571 571
572 static Uri _getCurrentRootUri() { 572 static Uri _getCurrentRootUri() {
573 try { 573 try {
574 return Uri.parse(_getCurrentRootUriStr()); 574 return Uri.parse(_getCurrentRootUriStr());
575 } catch (e, s) { 575 } catch (e, s) {
576 return null; 576 return null;
577 } 577 }
578 } 578 }
579 579
580 static String _getCurrentRootUriStr() 580 static String _getCurrentRootUriStr()
581 native "Isolate_getCurrentRootUriStr"; 581 native "Isolate_getCurrentRootUriStr";
582 } 582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698