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

Side by Side Diff: lib/runtime/dart/isolate.js

Issue 1138793002: Tag closures with their types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 7 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 var isolate = dart.defineLibrary(isolate, {}); 1 var isolate = dart.defineLibrary(isolate, {});
2 var core = dart.import(core); 2 var core = dart.import(core);
3 var _isolate_helper = dart.lazyImport(_isolate_helper); 3 var _isolate_helper = dart.lazyImport(_isolate_helper);
4 var async = dart.import(async); 4 var async = dart.import(async);
5 (function(exports, core, _isolate_helper, async) { 5 (function(exports, core, _isolate_helper, async) {
6 'use strict'; 6 'use strict';
7 class Capability extends core.Object { 7 class Capability extends core.Object {
8 Capability() { 8 Capability() {
9 return new _isolate_helper.CapabilityImpl(); 9 return new _isolate_helper.CapabilityImpl();
10 } 10 }
11 } 11 }
12 dart.setSignature(Capability, {});
12 class IsolateSpawnException extends core.Object { 13 class IsolateSpawnException extends core.Object {
13 IsolateSpawnException(message) { 14 IsolateSpawnException(message) {
14 this.message = message; 15 this.message = message;
15 } 16 }
16 toString() { 17 toString() {
17 return `IsolateSpawnException: ${this.message}`; 18 return `IsolateSpawnException: ${this.message}`;
18 } 19 }
19 } 20 }
20 IsolateSpawnException[dart.implements] = () => [core.Exception]; 21 IsolateSpawnException[dart.implements] = () => [core.Exception];
22 dart.setSignature(IsolateSpawnException, {
23 methods: () => ({toString: dart.functionType(core.String, [])})
24 });
21 let _pause = Symbol('_pause'); 25 let _pause = Symbol('_pause');
22 class Isolate extends core.Object { 26 class Isolate extends core.Object {
23 Isolate(controlPort, opts) { 27 Isolate(controlPort, opts) {
24 let pauseCapability = opts && 'pauseCapability' in opts ? opts.pauseCapabi lity : null; 28 let pauseCapability = opts && 'pauseCapability' in opts ? opts.pauseCapabi lity : null;
25 let terminateCapability = opts && 'terminateCapability' in opts ? opts.ter minateCapability : null; 29 let terminateCapability = opts && 'terminateCapability' in opts ? opts.ter minateCapability : null;
26 this.controlPort = controlPort; 30 this.controlPort = controlPort;
27 this.pauseCapability = pauseCapability; 31 this.pauseCapability = pauseCapability;
28 this.terminateCapability = terminateCapability; 32 this.terminateCapability = terminateCapability;
29 } 33 }
30 static get current() { 34 static get current() {
31 return Isolate._currentIsolateCache; 35 return Isolate._currentIsolateCache;
32 } 36 }
33 static spawn(entryPoint, message, opts) { 37 static spawn(entryPoint, message, opts) {
34 let paused = opts && 'paused' in opts ? opts.paused : false; 38 let paused = opts && 'paused' in opts ? opts.paused : false;
35 try { 39 try {
36 return dart.as(_isolate_helper.IsolateNatives.spawnFunction(entryPoint, message, paused).then(msg => new Isolate(dart.as(dart.dindex(msg, 1), SendPort), {pauseCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCapability : dart.as(dart.dindex(msg, 3), Capability)})), async.Future$(Isolate)); 40 return dart.as(_isolate_helper.IsolateNatives.spawnFunction(entryPoint, message, paused).then(dart.fn(msg => new Isolate(dart.as(dart.dindex(msg, 1), Se ndPort), {pauseCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCa pability: dart.as(dart.dindex(msg, 3), Capability)}), Isolate, [dart.dynamic])), async.Future$(Isolate));
37 } catch (e) { 41 } catch (e) {
38 let st = dart.stackTrace(e); 42 let st = dart.stackTrace(e);
39 return new (async.Future$(Isolate)).error(e, st); 43 return new (async.Future$(Isolate)).error(e, st);
40 } 44 }
41 45
42 } 46 }
43 static spawnUri(uri, args, message, opts) { 47 static spawnUri(uri, args, message, opts) {
44 let paused = opts && 'paused' in opts ? opts.paused : false; 48 let paused = opts && 'paused' in opts ? opts.paused : false;
45 let packageRoot = opts && 'packageRoot' in opts ? opts.packageRoot : null; 49 let packageRoot = opts && 'packageRoot' in opts ? opts.packageRoot : null;
46 if (packageRoot != null) 50 if (packageRoot != null)
47 throw new core.UnimplementedError("packageRoot"); 51 throw new core.UnimplementedError("packageRoot");
48 try { 52 try {
49 if (dart.is(args, core.List)) { 53 if (dart.is(args, core.List)) {
50 for (let i = 0; dart.notNull(i) < dart.notNull(args[core.$length]); i = dart.notNull(i) + 1) { 54 for (let i = 0; dart.notNull(i) < dart.notNull(args[core.$length]); i = dart.notNull(i) + 1) {
51 if (!(typeof args[core.$get](i) == 'string')) { 55 if (!(typeof args[core.$get](i) == 'string')) {
52 throw new core.ArgumentError(`Args must be a list of Strings ${arg s}`); 56 throw new core.ArgumentError(`Args must be a list of Strings ${arg s}`);
53 } 57 }
54 } 58 }
55 } else if (args != null) { 59 } else if (args != null) {
56 throw new core.ArgumentError(`Args must be a list of Strings ${args}`) ; 60 throw new core.ArgumentError(`Args must be a list of Strings ${args}`) ;
57 } 61 }
58 return dart.as(_isolate_helper.IsolateNatives.spawnUri(uri, args, messag e, paused).then(msg => new Isolate(dart.as(dart.dindex(msg, 1), SendPort), {paus eCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCapability: dart .as(dart.dindex(msg, 3), Capability)})), async.Future$(Isolate)); 62 return dart.as(_isolate_helper.IsolateNatives.spawnUri(uri, args, messag e, paused).then(dart.fn(msg => new Isolate(dart.as(dart.dindex(msg, 1), SendPort ), {pauseCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCapabili ty: dart.as(dart.dindex(msg, 3), Capability)}), Isolate, [dart.dynamic])), async .Future$(Isolate));
59 } catch (e) { 63 } catch (e) {
60 let st = dart.stackTrace(e); 64 let st = dart.stackTrace(e);
61 return new (async.Future$(Isolate)).error(e, st); 65 return new (async.Future$(Isolate)).error(e, st);
62 } 66 }
63 67
64 } 68 }
65 pause(resumeCapability) { 69 pause(resumeCapability) {
66 if (resumeCapability === void 0) 70 if (resumeCapability === void 0)
67 resumeCapability = null; 71 resumeCapability = null;
68 if (resumeCapability == null) 72 if (resumeCapability == null)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 128 }
125 removeErrorListener(port) { 129 removeErrorListener(port) {
126 let message = new core.List(2); 130 let message = new core.List(2);
127 message[core.$set](0, "stopErrors"); 131 message[core.$set](0, "stopErrors");
128 message[core.$set](1, port); 132 message[core.$set](1, port);
129 this.controlPort.send(message); 133 this.controlPort.send(message);
130 } 134 }
131 get errors() { 135 get errors() {
132 let controller = null; 136 let controller = null;
133 let port = null; 137 let port = null;
134 // Function handleError: (dynamic) → void
135 let handleError = message => { 138 let handleError = message => {
136 let errorDescription = dart.as(dart.dindex(message, 0), core.String); 139 let errorDescription = dart.as(dart.dindex(message, 0), core.String);
137 let stackDescription = dart.as(dart.dindex(message, 1), core.String); 140 let stackDescription = dart.as(dart.dindex(message, 1), core.String);
138 let error = new RemoteError(errorDescription, stackDescription); 141 let error = new RemoteError(errorDescription, stackDescription);
139 controller.addError(error, error.stackTrace); 142 controller.addError(error, error.stackTrace);
140 }; 143 };
141 controller = new async.StreamController.broadcast({ 144 dart.fn(handleError, dart.void, [dart.dynamic]);
142 sync: true, 145 controller = new async.StreamController.broadcast({sync: true, onListen: d art.fn((() => {
143 onListen: (() => {
144 port = new RawReceivePort(handleError); 146 port = new RawReceivePort(handleError);
145 this.addErrorListener(port.sendPort); 147 this.addErrorListener(port.sendPort);
146 }).bind(this), 148 }).bind(this)), onCancel: dart.fn((() => {
147 onCancel: (() => {
148 this.removeErrorListener(port.sendPort); 149 this.removeErrorListener(port.sendPort);
149 port.close(); 150 port.close();
150 port = null; 151 port = null;
151 }).bind(this) 152 }).bind(this))});
152 });
153 return controller.stream; 153 return controller.stream;
154 } 154 }
155 } 155 }
156 dart.setSignature(Isolate, {
157 methods: () => ({
158 pause: dart.functionType(Capability, [], [Capability]),
159 [_pause]: dart.functionType(dart.void, [Capability]),
160 resume: dart.functionType(dart.void, [Capability]),
161 addOnExitListener: dart.functionType(dart.void, [SendPort]),
162 removeOnExitListener: dart.functionType(dart.void, [SendPort]),
163 setErrorsFatal: dart.functionType(dart.void, [core.bool]),
164 kill: dart.functionType(dart.void, [], [core.int]),
165 ping: dart.functionType(dart.void, [SendPort], [core.int]),
166 addErrorListener: dart.functionType(dart.void, [SendPort]),
167 removeErrorListener: dart.functionType(dart.void, [SendPort])
168 }),
169 statics: () => ({
170 spawn: dart.functionType(async.Future$(Isolate), [dart.functionType(dart.v oid, [dart.dynamic]), dart.dynamic], {ause: core.bool}),
171 spawnUri: dart.functionType(async.Future$(Isolate), [core.Uri, core.List$( core.String), dart.dynamic], {ause: core.bool, ackageRoo: core.Uri})
172 }),
173 names: ['spawn', 'spawnUri']
174 });
156 Isolate.IMMEDIATE = 0; 175 Isolate.IMMEDIATE = 0;
157 Isolate.BEFORE_NEXT_EVENT = 1; 176 Isolate.BEFORE_NEXT_EVENT = 1;
158 Isolate.AS_EVENT = 2; 177 Isolate.AS_EVENT = 2;
159 dart.defineLazyProperties(Isolate, { 178 dart.defineLazyProperties(Isolate, {
160 get _currentIsolateCache() { 179 get _currentIsolateCache() {
161 return _isolate_helper.IsolateNatives.currentIsolate; 180 return _isolate_helper.IsolateNatives.currentIsolate;
162 } 181 }
163 }); 182 });
164 class SendPort extends core.Object {} 183 class SendPort extends core.Object {}
165 SendPort[dart.implements] = () => [Capability]; 184 SendPort[dart.implements] = () => [Capability];
185 dart.setSignature(SendPort, {});
166 class ReceivePort extends core.Object { 186 class ReceivePort extends core.Object {
167 ReceivePort() { 187 ReceivePort() {
168 return new _isolate_helper.ReceivePortImpl(); 188 return new _isolate_helper.ReceivePortImpl();
169 } 189 }
170 fromRawReceivePort(rawPort) { 190 fromRawReceivePort(rawPort) {
171 return new _isolate_helper.ReceivePortImpl.fromRawReceivePort(rawPort); 191 return new _isolate_helper.ReceivePortImpl.fromRawReceivePort(rawPort);
172 } 192 }
173 } 193 }
174 ReceivePort[dart.implements] = () => [async.Stream]; 194 ReceivePort[dart.implements] = () => [async.Stream];
175 dart.defineNamedConstructor(ReceivePort, 'fromRawReceivePort'); 195 dart.defineNamedConstructor(ReceivePort, 'fromRawReceivePort');
196 dart.setSignature(ReceivePort, {});
176 class RawReceivePort extends core.Object { 197 class RawReceivePort extends core.Object {
177 RawReceivePort(handler) { 198 RawReceivePort(handler) {
178 if (handler === void 0) 199 if (handler === void 0)
179 handler = null; 200 handler = null;
180 return new _isolate_helper.RawReceivePortImpl(handler); 201 return new _isolate_helper.RawReceivePortImpl(handler);
181 } 202 }
182 } 203 }
204 dart.setSignature(RawReceivePort, {});
183 class _IsolateUnhandledException extends core.Object { 205 class _IsolateUnhandledException extends core.Object {
184 _IsolateUnhandledException(message, source, stackTrace) { 206 _IsolateUnhandledException(message, source, stackTrace) {
185 this.message = message; 207 this.message = message;
186 this.source = source; 208 this.source = source;
187 this.stackTrace = stackTrace; 209 this.stackTrace = stackTrace;
188 } 210 }
189 toString() { 211 toString() {
190 return 'IsolateUnhandledException: exception while handling message: ' + ` ${this.message} \n ` + `${dart.toString(this.source).replaceAll("\n", "\n ")}\ n` + 'original stack trace:\n ' + `${dart.toString(this.stackTrace).replaceAll( "\n", "\n ")}`; 212 return 'IsolateUnhandledException: exception while handling message: ' + ` ${this.message} \n ` + `${dart.toString(this.source).replaceAll("\n", "\n ")}\ n` + 'original stack trace:\n ' + `${dart.toString(this.stackTrace).replaceAll( "\n", "\n ")}`;
191 } 213 }
192 } 214 }
193 _IsolateUnhandledException[dart.implements] = () => [core.Exception]; 215 _IsolateUnhandledException[dart.implements] = () => [core.Exception];
216 dart.setSignature(_IsolateUnhandledException, {
217 methods: () => ({toString: dart.functionType(core.String, [])})
218 });
194 let _description = Symbol('_description'); 219 let _description = Symbol('_description');
195 class RemoteError extends core.Object { 220 class RemoteError extends core.Object {
196 RemoteError(description, stackDescription) { 221 RemoteError(description, stackDescription) {
197 this[_description] = description; 222 this[_description] = description;
198 this.stackTrace = new _RemoteStackTrace(stackDescription); 223 this.stackTrace = new _RemoteStackTrace(stackDescription);
199 } 224 }
200 toString() { 225 toString() {
201 return this[_description]; 226 return this[_description];
202 } 227 }
203 } 228 }
204 RemoteError[dart.implements] = () => [core.Error]; 229 RemoteError[dart.implements] = () => [core.Error];
230 dart.setSignature(RemoteError, {
231 methods: () => ({toString: dart.functionType(core.String, [])})
232 });
205 let _trace = Symbol('_trace'); 233 let _trace = Symbol('_trace');
206 class _RemoteStackTrace extends core.Object { 234 class _RemoteStackTrace extends core.Object {
207 _RemoteStackTrace(trace) { 235 _RemoteStackTrace(trace) {
208 this[_trace] = trace; 236 this[_trace] = trace;
209 } 237 }
210 toString() { 238 toString() {
211 return this[_trace]; 239 return this[_trace];
212 } 240 }
213 } 241 }
214 _RemoteStackTrace[dart.implements] = () => [core.StackTrace]; 242 _RemoteStackTrace[dart.implements] = () => [core.StackTrace];
243 dart.setSignature(_RemoteStackTrace, {
244 methods: () => ({toString: dart.functionType(core.String, [])})
245 });
215 // Exports: 246 // Exports:
216 exports.Capability = Capability; 247 exports.Capability = Capability;
217 exports.IsolateSpawnException = IsolateSpawnException; 248 exports.IsolateSpawnException = IsolateSpawnException;
218 exports.Isolate = Isolate; 249 exports.Isolate = Isolate;
219 exports.SendPort = SendPort; 250 exports.SendPort = SendPort;
220 exports.ReceivePort = ReceivePort; 251 exports.ReceivePort = ReceivePort;
221 exports.RawReceivePort = RawReceivePort; 252 exports.RawReceivePort = RawReceivePort;
222 exports.RemoteError = RemoteError; 253 exports.RemoteError = RemoteError;
223 })(isolate, core, _isolate_helper, async); 254 })(isolate, core, _isolate_helper, async);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698