OLD | NEW |
1 dart_library.library('dart/isolate', null, /* Imports */[ | 1 dart_library.library('dart/isolate', null, /* Imports */[ |
2 "dart_runtime/dart", | 2 "dart_runtime/dart", |
3 'dart/core', | 3 'dart/core', |
4 'dart/async' | 4 'dart/async' |
5 ], /* Lazy imports */[ | 5 ], /* Lazy imports */[ |
6 'dart/_isolate_helper' | 6 'dart/_isolate_helper' |
7 ], function(exports, dart, core, async, _isolate_helper) { | 7 ], function(exports, dart, core, async, _isolate_helper) { |
8 'use strict'; | 8 'use strict'; |
9 let dartx = dart.dartx; | 9 let dartx = dart.dartx; |
10 class Capability extends core.Object { | 10 class Capability extends core.Object { |
(...skipping 24 matching lines...) Expand all Loading... |
35 this.controlPort = controlPort; | 35 this.controlPort = controlPort; |
36 this.pauseCapability = pauseCapability; | 36 this.pauseCapability = pauseCapability; |
37 this.terminateCapability = terminateCapability; | 37 this.terminateCapability = terminateCapability; |
38 } | 38 } |
39 static get current() { | 39 static get current() { |
40 return Isolate._currentIsolateCache; | 40 return Isolate._currentIsolateCache; |
41 } | 41 } |
42 static spawn(entryPoint, message, opts) { | 42 static spawn(entryPoint, message, opts) { |
43 let paused = opts && 'paused' in opts ? opts.paused : false; | 43 let paused = opts && 'paused' in opts ? opts.paused : false; |
44 try { | 44 try { |
45 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, [core.Object])),
async.Future$(Isolate)); | 45 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)); |
46 } catch (e) { | 46 } catch (e) { |
47 let st = dart.stackTrace(e); | 47 let st = dart.stackTrace(e); |
48 return async.Future$(Isolate).error(e, st); | 48 return async.Future$(Isolate).error(e, st); |
49 } | 49 } |
50 | 50 |
51 } | 51 } |
52 static spawnUri(uri, args, message, opts) { | 52 static spawnUri(uri, args, message, opts) { |
53 let paused = opts && 'paused' in opts ? opts.paused : false; | 53 let paused = opts && 'paused' in opts ? opts.paused : false; |
54 let packageRoot = opts && 'packageRoot' in opts ? opts.packageRoot : null; | 54 let packageRoot = opts && 'packageRoot' in opts ? opts.packageRoot : null; |
55 if (packageRoot != null) | 55 if (packageRoot != null) |
56 throw new core.UnimplementedError("packageRoot"); | 56 throw new core.UnimplementedError("packageRoot"); |
57 try { | 57 try { |
58 if (dart.is(args, core.List)) { | 58 if (dart.is(args, core.List)) { |
59 for (let i = 0; dart.notNull(i) < dart.notNull(args[dartx.length]); i
= dart.notNull(i) + 1) { | 59 for (let i = 0; dart.notNull(i) < dart.notNull(args[dartx.length]); i
= dart.notNull(i) + 1) { |
60 if (!(typeof args[dartx.get](i) == 'string')) { | 60 if (!(typeof args[dartx.get](i) == 'string')) { |
61 throw new core.ArgumentError(`Args must be a list of Strings ${arg
s}`); | 61 throw new core.ArgumentError(`Args must be a list of Strings ${arg
s}`); |
62 } | 62 } |
63 } | 63 } |
64 } else if (args != null) { | 64 } else if (args != null) { |
65 throw new core.ArgumentError(`Args must be a list of Strings ${args}`)
; | 65 throw new core.ArgumentError(`Args must be a list of Strings ${args}`)
; |
66 } | 66 } |
67 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, [core.Object])), async.
Future$(Isolate)); | 67 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)); |
68 } catch (e) { | 68 } catch (e) { |
69 let st = dart.stackTrace(e); | 69 let st = dart.stackTrace(e); |
70 return async.Future$(Isolate).error(e, st); | 70 return async.Future$(Isolate).error(e, st); |
71 } | 71 } |
72 | 72 |
73 } | 73 } |
74 pause(resumeCapability) { | 74 pause(resumeCapability) { |
75 if (resumeCapability === void 0) | 75 if (resumeCapability === void 0) |
76 resumeCapability = null; | 76 resumeCapability = null; |
77 if (resumeCapability == null) | 77 if (resumeCapability == null) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 get errors() { | 140 get errors() { |
141 let controller = null; | 141 let controller = null; |
142 let port = null; | 142 let port = null; |
143 let handleError = message => { | 143 let handleError = message => { |
144 let errorDescription = dart.as(dart.dindex(message, 0), core.String); | 144 let errorDescription = dart.as(dart.dindex(message, 0), core.String); |
145 let stackDescription = dart.as(dart.dindex(message, 1), core.String); | 145 let stackDescription = dart.as(dart.dindex(message, 1), core.String); |
146 let error = new RemoteError(errorDescription, stackDescription); | 146 let error = new RemoteError(errorDescription, stackDescription); |
147 controller.addError(error, error.stackTrace); | 147 controller.addError(error, error.stackTrace); |
148 }; | 148 }; |
149 dart.fn(handleError, dart.void, [core.Object]); | 149 dart.fn(handleError, dart.void, [dart.dynamic]); |
150 controller = async.StreamController.broadcast({sync: true, onListen: dart.
fn(() => { | 150 controller = async.StreamController.broadcast({sync: true, onListen: dart.
fn(() => { |
151 port = RawReceivePort.new(handleError); | 151 port = RawReceivePort.new(handleError); |
152 this.addErrorListener(port.sendPort); | 152 this.addErrorListener(port.sendPort); |
153 }), onCancel: dart.fn(() => { | 153 }), onCancel: dart.fn(() => { |
154 this.removeErrorListener(port.sendPort); | 154 this.removeErrorListener(port.sendPort); |
155 port.close(); | 155 port.close(); |
156 port = null; | 156 port = null; |
157 })}); | 157 })}); |
158 return controller.stream; | 158 return controller.stream; |
159 } | 159 } |
160 } | 160 } |
161 dart.setSignature(Isolate, { | 161 dart.setSignature(Isolate, { |
162 constructors: () => ({Isolate: [Isolate, [SendPort], {pauseCapability: Capab
ility, terminateCapability: Capability}]}), | 162 constructors: () => ({Isolate: [Isolate, [SendPort], {pauseCapability: Capab
ility, terminateCapability: Capability}]}), |
163 methods: () => ({ | 163 methods: () => ({ |
164 pause: [Capability, [], [Capability]], | 164 pause: [Capability, [], [Capability]], |
165 [_pause]: [dart.void, [Capability]], | 165 [_pause]: [dart.void, [Capability]], |
166 resume: [dart.void, [Capability]], | 166 resume: [dart.void, [Capability]], |
167 addOnExitListener: [dart.void, [SendPort]], | 167 addOnExitListener: [dart.void, [SendPort]], |
168 removeOnExitListener: [dart.void, [SendPort]], | 168 removeOnExitListener: [dart.void, [SendPort]], |
169 setErrorsFatal: [dart.void, [core.bool]], | 169 setErrorsFatal: [dart.void, [core.bool]], |
170 kill: [dart.void, [], [core.int]], | 170 kill: [dart.void, [], [core.int]], |
171 ping: [dart.void, [SendPort], [core.int]], | 171 ping: [dart.void, [SendPort], [core.int]], |
172 addErrorListener: [dart.void, [SendPort]], | 172 addErrorListener: [dart.void, [SendPort]], |
173 removeErrorListener: [dart.void, [SendPort]] | 173 removeErrorListener: [dart.void, [SendPort]] |
174 }), | 174 }), |
175 statics: () => ({ | 175 statics: () => ({ |
176 spawn: [async.Future$(Isolate), [dart.functionType(dart.void, [dart.bottom
]), core.Object], {paused: core.bool}], | 176 spawn: [async.Future$(Isolate), [dart.functionType(dart.void, [dart.dynami
c]), dart.dynamic], {paused: core.bool}], |
177 spawnUri: [async.Future$(Isolate), [core.Uri, core.List$(core.String), cor
e.Object], {paused: core.bool, packageRoot: core.Uri}] | 177 spawnUri: [async.Future$(Isolate), [core.Uri, core.List$(core.String), dar
t.dynamic], {paused: core.bool, packageRoot: core.Uri}] |
178 }), | 178 }), |
179 names: ['spawn', 'spawnUri'] | 179 names: ['spawn', 'spawnUri'] |
180 }); | 180 }); |
181 Isolate.IMMEDIATE = 0; | 181 Isolate.IMMEDIATE = 0; |
182 Isolate.BEFORE_NEXT_EVENT = 1; | 182 Isolate.BEFORE_NEXT_EVENT = 1; |
183 Isolate.AS_EVENT = 2; | 183 Isolate.AS_EVENT = 2; |
184 dart.defineLazyProperties(Isolate, { | 184 dart.defineLazyProperties(Isolate, { |
185 get _currentIsolateCache() { | 185 get _currentIsolateCache() { |
186 return _isolate_helper.IsolateNatives.currentIsolate; | 186 return _isolate_helper.IsolateNatives.currentIsolate; |
187 } | 187 } |
(...skipping 16 matching lines...) Expand all Loading... |
204 }) | 204 }) |
205 }); | 205 }); |
206 class RawReceivePort extends core.Object { | 206 class RawReceivePort extends core.Object { |
207 static new(handler) { | 207 static new(handler) { |
208 if (handler === void 0) | 208 if (handler === void 0) |
209 handler = null; | 209 handler = null; |
210 return new _isolate_helper.RawReceivePortImpl(handler); | 210 return new _isolate_helper.RawReceivePortImpl(handler); |
211 } | 211 } |
212 } | 212 } |
213 dart.setSignature(RawReceivePort, { | 213 dart.setSignature(RawReceivePort, { |
214 constructors: () => ({new: [RawReceivePort, [], [dart.functionType(dart.void
, [dart.bottom])]]}) | 214 constructors: () => ({new: [RawReceivePort, [], [dart.functionType(dart.void
, [dart.dynamic])]]}) |
215 }); | 215 }); |
216 class _IsolateUnhandledException extends core.Object { | 216 class _IsolateUnhandledException extends core.Object { |
217 _IsolateUnhandledException(message, source, stackTrace) { | 217 _IsolateUnhandledException(message, source, stackTrace) { |
218 this.message = message; | 218 this.message = message; |
219 this.source = source; | 219 this.source = source; |
220 this.stackTrace = stackTrace; | 220 this.stackTrace = stackTrace; |
221 } | 221 } |
222 toString() { | 222 toString() { |
223 return 'IsolateUnhandledException: exception while handling message: ' + `
${this.message} \n ` + `${dart.toString(this.source)[dartx.replaceAll]("\n", "\
n ")}\n` + 'original stack trace:\n ' + `${dart.toString(this.stackTrace)[dart
x.replaceAll]("\n", "\n ")}`; | 223 return 'IsolateUnhandledException: exception while handling message: ' + `
${this.message} \n ` + `${dart.toString(this.source)[dartx.replaceAll]("\n", "\
n ")}\n` + 'original stack trace:\n ' + `${dart.toString(this.stackTrace)[dart
x.replaceAll]("\n", "\n ")}`; |
224 } | 224 } |
225 } | 225 } |
226 _IsolateUnhandledException[dart.implements] = () => [core.Exception]; | 226 _IsolateUnhandledException[dart.implements] = () => [core.Exception]; |
227 dart.setSignature(_IsolateUnhandledException, { | 227 dart.setSignature(_IsolateUnhandledException, { |
228 constructors: () => ({_IsolateUnhandledException: [_IsolateUnhandledExceptio
n, [core.Object, core.Object, core.StackTrace]]}) | 228 constructors: () => ({_IsolateUnhandledException: [_IsolateUnhandledExceptio
n, [dart.dynamic, dart.dynamic, core.StackTrace]]}) |
229 }); | 229 }); |
230 let _description = Symbol('_description'); | 230 let _description = Symbol('_description'); |
231 class RemoteError extends core.Object { | 231 class RemoteError extends core.Object { |
232 RemoteError(description, stackDescription) { | 232 RemoteError(description, stackDescription) { |
233 this[_description] = description; | 233 this[_description] = description; |
234 this.stackTrace = new _RemoteStackTrace(stackDescription); | 234 this.stackTrace = new _RemoteStackTrace(stackDescription); |
235 } | 235 } |
236 toString() { | 236 toString() { |
237 return this[_description]; | 237 return this[_description]; |
238 } | 238 } |
(...skipping 17 matching lines...) Expand all Loading... |
256 }); | 256 }); |
257 // Exports: | 257 // Exports: |
258 exports.Capability = Capability; | 258 exports.Capability = Capability; |
259 exports.IsolateSpawnException = IsolateSpawnException; | 259 exports.IsolateSpawnException = IsolateSpawnException; |
260 exports.Isolate = Isolate; | 260 exports.Isolate = Isolate; |
261 exports.SendPort = SendPort; | 261 exports.SendPort = SendPort; |
262 exports.ReceivePort = ReceivePort; | 262 exports.ReceivePort = ReceivePort; |
263 exports.RawReceivePort = RawReceivePort; | 263 exports.RawReceivePort = RawReceivePort; |
264 exports.RemoteError = RemoteError; | 264 exports.RemoteError = RemoteError; |
265 }); | 265 }); |
OLD | NEW |