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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/isolate_patch.dart

Issue 1212513002: sdk files reorganization to make dart2js a proper package (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: renamed Created 5 years, 6 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Patch file for the dart:isolate library.
6
7 import 'dart:_js_helper' show patch;
8 import 'dart:_isolate_helper' show CapabilityImpl,
9 CloseToken,
10 IsolateNatives,
11 JsIsolateSink,
12 ReceivePortImpl,
13 RawReceivePortImpl;
14
15 @patch
16 class Isolate {
17 static final _currentIsolateCache = IsolateNatives.currentIsolate;
18
19 // `current` must be a getter, not just a final field,
20 // to match the external declaration.
21 @patch
22 static Isolate get current => _currentIsolateCache;
23
24 @patch
25 static Future<Isolate> spawn(void entryPoint(message), var message,
26 { bool paused: false }) {
27 try {
28 return IsolateNatives.spawnFunction(entryPoint, message, paused)
29 .then((msg) => new Isolate(msg[1],
30 pauseCapability: msg[2],
31 terminateCapability: msg[3]));
32 } catch (e, st) {
33 return new Future<Isolate>.error(e, st);
34 }
35 }
36
37 @patch
38 static Future<Isolate> spawnUri(
39 Uri uri, List<String> args, var message, { bool paused: false,
40 bool checked,
41 Uri packageRoot }) {
42 if (packageRoot != null) throw new UnimplementedError("packageRoot");
43 try {
44 if (args is List<String>) {
45 for (int i = 0; i < args.length; i++) {
46 if (args[i] is! String) {
47 throw new ArgumentError("Args must be a list of Strings $args");
48 }
49 }
50 } else if (args != null) {
51 throw new ArgumentError("Args must be a list of Strings $args");
52 }
53 return IsolateNatives.spawnUri(uri, args, message, paused)
54 .then((msg) => new Isolate(msg[1],
55 pauseCapability: msg[2],
56 terminateCapability: msg[3]));
57 } catch (e, st) {
58 return new Future<Isolate>.error(e, st);
59 }
60 }
61
62 @patch
63 void _pause(Capability resumeCapability) {
64 var message = new List(3)
65 ..[0] = "pause"
66 ..[1] = pauseCapability
67 ..[2] = resumeCapability;
68 controlPort.send(message);
69 }
70
71 @patch
72 void resume(Capability resumeCapability) {
73 var message = new List(2)
74 ..[0] = "resume"
75 ..[1] = resumeCapability;
76 controlPort.send(message);
77 }
78
79 @patch
80 void addOnExitListener(SendPort responsePort, {Object response}) {
81 // TODO(lrn): Can we have an internal method that checks if the receiving
82 // isolate of a SendPort is still alive?
83 var message = new List(3)
84 ..[0] = "add-ondone"
85 ..[1] = responsePort
86 ..[2] = response;
87 controlPort.send(message);
88 }
89
90 @patch
91 void removeOnExitListener(SendPort responsePort) {
92 var message = new List(2)
93 ..[0] = "remove-ondone"
94 ..[1] = responsePort;
95 controlPort.send(message);
96 }
97
98 @patch
99 void setErrorsFatal(bool errorsAreFatal) {
100 var message = new List(3)
101 ..[0] = "set-errors-fatal"
102 ..[1] = terminateCapability
103 ..[2] = errorsAreFatal;
104 controlPort.send(message);
105 }
106
107 @patch
108 void kill({int priority: BEFORE_NEXT_EVENT}) {
109 controlPort.send(["kill", terminateCapability, priority]);
110 }
111
112 @patch
113 void ping(SendPort responsePort, {Object response,
114 int priority: IMMEDIATE}) {
115 var message = new List(4)
116 ..[0] = "ping"
117 ..[1] = responsePort
118 ..[2] = priority
119 ..[3] = response;
120 controlPort.send(message);
121 }
122
123 @patch
124 void addErrorListener(SendPort port) {
125 var message = new List(2)
126 ..[0] = "getErrors"
127 ..[1] = port;
128 controlPort.send(message);
129 }
130
131 @patch
132 void removeErrorListener(SendPort port) {
133 var message = new List(2)
134 ..[0] = "stopErrors"
135 ..[1] = port;
136 controlPort.send(message);
137 }
138 }
139
140 /** Default factory for receive ports. */
141 @patch
142 class ReceivePort {
143 @patch
144 factory ReceivePort() = ReceivePortImpl;
145
146 @patch
147 factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) {
148 return new ReceivePortImpl.fromRawReceivePort(rawPort);
149 }
150 }
151
152 @patch
153 class RawReceivePort {
154 @patch
155 factory RawReceivePort([void handler(event)]) {
156 return new RawReceivePortImpl(handler);
157 }
158 }
159
160 @patch
161 class Capability {
162 @patch
163 factory Capability() = CapabilityImpl;
164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698