| OLD | NEW |
| (Empty) |
| 1 dart_library.library('dart/isolate', null, /* Imports */[ | |
| 2 "dart_runtime/dart", | |
| 3 'dart/core', | |
| 4 'dart/async' | |
| 5 ], /* Lazy imports */[ | |
| 6 'dart/_isolate_helper' | |
| 7 ], function(exports, dart, core, async, _isolate_helper) { | |
| 8 'use strict'; | |
| 9 let dartx = dart.dartx; | |
| 10 class Capability extends core.Object { | |
| 11 static new() { | |
| 12 return new _isolate_helper.CapabilityImpl(); | |
| 13 } | |
| 14 } | |
| 15 dart.setSignature(Capability, { | |
| 16 constructors: () => ({new: [Capability, []]}) | |
| 17 }); | |
| 18 class IsolateSpawnException extends core.Object { | |
| 19 IsolateSpawnException(message) { | |
| 20 this.message = message; | |
| 21 } | |
| 22 toString() { | |
| 23 return `IsolateSpawnException: ${this.message}`; | |
| 24 } | |
| 25 } | |
| 26 IsolateSpawnException[dart.implements] = () => [core.Exception]; | |
| 27 dart.setSignature(IsolateSpawnException, { | |
| 28 constructors: () => ({IsolateSpawnException: [IsolateSpawnException, [core.S
tring]]}) | |
| 29 }); | |
| 30 let _pause = Symbol('_pause'); | |
| 31 class Isolate extends core.Object { | |
| 32 Isolate(controlPort, opts) { | |
| 33 let pauseCapability = opts && 'pauseCapability' in opts ? opts.pauseCapabi
lity : null; | |
| 34 let terminateCapability = opts && 'terminateCapability' in opts ? opts.ter
minateCapability : null; | |
| 35 this.controlPort = controlPort; | |
| 36 this.pauseCapability = pauseCapability; | |
| 37 this.terminateCapability = terminateCapability; | |
| 38 } | |
| 39 static get current() { | |
| 40 return Isolate._currentIsolateCache; | |
| 41 } | |
| 42 static spawn(entryPoint, message, opts) { | |
| 43 let paused = opts && 'paused' in opts ? opts.paused : false; | |
| 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, [dart.dynamic])),
async.Future$(Isolate)); | |
| 46 } catch (e) { | |
| 47 let st = dart.stackTrace(e); | |
| 48 return async.Future$(Isolate).error(e, st); | |
| 49 } | |
| 50 | |
| 51 } | |
| 52 static spawnUri(uri, args, message, opts) { | |
| 53 let paused = opts && 'paused' in opts ? opts.paused : false; | |
| 54 let packageRoot = opts && 'packageRoot' in opts ? opts.packageRoot : null; | |
| 55 if (packageRoot != null) | |
| 56 dart.throw(new core.UnimplementedError("packageRoot")); | |
| 57 try { | |
| 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) { | |
| 60 if (!(typeof args[dartx.get](i) == 'string')) { | |
| 61 dart.throw(new core.ArgumentError(`Args must be a list of Strings
${args}`)); | |
| 62 } | |
| 63 } | |
| 64 } else if (args != null) { | |
| 65 dart.throw(new core.ArgumentError(`Args must be a list of Strings ${ar
gs}`)); | |
| 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, [dart.dynamic])), async
.Future$(Isolate)); | |
| 68 } catch (e) { | |
| 69 let st = dart.stackTrace(e); | |
| 70 return async.Future$(Isolate).error(e, st); | |
| 71 } | |
| 72 | |
| 73 } | |
| 74 pause(resumeCapability) { | |
| 75 if (resumeCapability === void 0) | |
| 76 resumeCapability = null; | |
| 77 if (resumeCapability == null) | |
| 78 resumeCapability = Capability.new(); | |
| 79 this[_pause](resumeCapability); | |
| 80 return resumeCapability; | |
| 81 } | |
| 82 [_pause](resumeCapability) { | |
| 83 let message = core.List.new(3); | |
| 84 message[dartx.set](0, "pause"); | |
| 85 message[dartx.set](1, this.pauseCapability); | |
| 86 message[dartx.set](2, resumeCapability); | |
| 87 this.controlPort.send(message); | |
| 88 } | |
| 89 resume(resumeCapability) { | |
| 90 let message = core.List.new(2); | |
| 91 message[dartx.set](0, "resume"); | |
| 92 message[dartx.set](1, resumeCapability); | |
| 93 this.controlPort.send(message); | |
| 94 } | |
| 95 addOnExitListener(responsePort) { | |
| 96 let message = core.List.new(2); | |
| 97 message[dartx.set](0, "add-ondone"); | |
| 98 message[dartx.set](1, responsePort); | |
| 99 this.controlPort.send(message); | |
| 100 } | |
| 101 removeOnExitListener(responsePort) { | |
| 102 let message = core.List.new(2); | |
| 103 message[dartx.set](0, "remove-ondone"); | |
| 104 message[dartx.set](1, responsePort); | |
| 105 this.controlPort.send(message); | |
| 106 } | |
| 107 setErrorsFatal(errorsAreFatal) { | |
| 108 let message = core.List.new(3); | |
| 109 message[dartx.set](0, "set-errors-fatal"); | |
| 110 message[dartx.set](1, this.terminateCapability); | |
| 111 message[dartx.set](2, errorsAreFatal); | |
| 112 this.controlPort.send(message); | |
| 113 } | |
| 114 kill(priority) { | |
| 115 if (priority === void 0) | |
| 116 priority = Isolate.BEFORE_NEXT_EVENT; | |
| 117 this.controlPort.send(["kill", this.terminateCapability, priority]); | |
| 118 } | |
| 119 ping(responsePort, pingType) { | |
| 120 if (pingType === void 0) | |
| 121 pingType = Isolate.IMMEDIATE; | |
| 122 let message = core.List.new(3); | |
| 123 message[dartx.set](0, "ping"); | |
| 124 message[dartx.set](1, responsePort); | |
| 125 message[dartx.set](2, pingType); | |
| 126 this.controlPort.send(message); | |
| 127 } | |
| 128 addErrorListener(port) { | |
| 129 let message = core.List.new(2); | |
| 130 message[dartx.set](0, "getErrors"); | |
| 131 message[dartx.set](1, port); | |
| 132 this.controlPort.send(message); | |
| 133 } | |
| 134 removeErrorListener(port) { | |
| 135 let message = core.List.new(2); | |
| 136 message[dartx.set](0, "stopErrors"); | |
| 137 message[dartx.set](1, port); | |
| 138 this.controlPort.send(message); | |
| 139 } | |
| 140 get errors() { | |
| 141 let controller = null; | |
| 142 let port = null; | |
| 143 function handleError(message) { | |
| 144 let errorDescription = dart.as(dart.dindex(message, 0), core.String); | |
| 145 let stackDescription = dart.as(dart.dindex(message, 1), core.String); | |
| 146 let error = new RemoteError(errorDescription, stackDescription); | |
| 147 controller.addError(error, error.stackTrace); | |
| 148 } | |
| 149 dart.fn(handleError, dart.void, [dart.dynamic]); | |
| 150 controller = async.StreamController.broadcast({sync: true, onListen: dart.
fn((() => { | |
| 151 port = RawReceivePort.new(handleError); | |
| 152 this.addErrorListener(port.sendPort); | |
| 153 }).bind(this)), onCancel: dart.fn((() => { | |
| 154 this.removeErrorListener(port.sendPort); | |
| 155 port.close(); | |
| 156 port = null; | |
| 157 }).bind(this))}); | |
| 158 return controller.stream; | |
| 159 } | |
| 160 } | |
| 161 dart.setSignature(Isolate, { | |
| 162 constructors: () => ({Isolate: [Isolate, [SendPort], {pauseCapability: Capab
ility, terminateCapability: Capability}]}), | |
| 163 methods: () => ({ | |
| 164 pause: [Capability, [], [Capability]], | |
| 165 [_pause]: [dart.void, [Capability]], | |
| 166 resume: [dart.void, [Capability]], | |
| 167 addOnExitListener: [dart.void, [SendPort]], | |
| 168 removeOnExitListener: [dart.void, [SendPort]], | |
| 169 setErrorsFatal: [dart.void, [core.bool]], | |
| 170 kill: [dart.void, [], [core.int]], | |
| 171 ping: [dart.void, [SendPort], [core.int]], | |
| 172 addErrorListener: [dart.void, [SendPort]], | |
| 173 removeErrorListener: [dart.void, [SendPort]] | |
| 174 }), | |
| 175 statics: () => ({ | |
| 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), dar
t.dynamic], {paused: core.bool, packageRoot: core.Uri}] | |
| 178 }), | |
| 179 names: ['spawn', 'spawnUri'] | |
| 180 }); | |
| 181 Isolate.IMMEDIATE = 0; | |
| 182 Isolate.BEFORE_NEXT_EVENT = 1; | |
| 183 Isolate.AS_EVENT = 2; | |
| 184 dart.defineLazyProperties(Isolate, { | |
| 185 get _currentIsolateCache() { | |
| 186 return _isolate_helper.IsolateNatives.currentIsolate; | |
| 187 } | |
| 188 }); | |
| 189 class SendPort extends core.Object {} | |
| 190 SendPort[dart.implements] = () => [Capability]; | |
| 191 class ReceivePort extends core.Object { | |
| 192 static new() { | |
| 193 return new _isolate_helper.ReceivePortImpl(); | |
| 194 } | |
| 195 static fromRawReceivePort(rawPort) { | |
| 196 return new _isolate_helper.ReceivePortImpl.fromRawReceivePort(rawPort); | |
| 197 } | |
| 198 } | |
| 199 ReceivePort[dart.implements] = () => [async.Stream]; | |
| 200 dart.setSignature(ReceivePort, { | |
| 201 constructors: () => ({ | |
| 202 new: [ReceivePort, []], | |
| 203 fromRawReceivePort: [ReceivePort, [RawReceivePort]] | |
| 204 }) | |
| 205 }); | |
| 206 class RawReceivePort extends core.Object { | |
| 207 static new(handler) { | |
| 208 if (handler === void 0) | |
| 209 handler = null; | |
| 210 return new _isolate_helper.RawReceivePortImpl(handler); | |
| 211 } | |
| 212 } | |
| 213 dart.setSignature(RawReceivePort, { | |
| 214 constructors: () => ({new: [RawReceivePort, [], [dart.functionType(dart.void
, [dart.dynamic])]]}) | |
| 215 }); | |
| 216 class _IsolateUnhandledException extends core.Object { | |
| 217 _IsolateUnhandledException(message, source, stackTrace) { | |
| 218 this.message = message; | |
| 219 this.source = source; | |
| 220 this.stackTrace = stackTrace; | |
| 221 } | |
| 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 ")}`; | |
| 224 } | |
| 225 } | |
| 226 _IsolateUnhandledException[dart.implements] = () => [core.Exception]; | |
| 227 dart.setSignature(_IsolateUnhandledException, { | |
| 228 constructors: () => ({_IsolateUnhandledException: [_IsolateUnhandledExceptio
n, [dart.dynamic, dart.dynamic, core.StackTrace]]}) | |
| 229 }); | |
| 230 let _description = Symbol('_description'); | |
| 231 class RemoteError extends core.Object { | |
| 232 RemoteError(description, stackDescription) { | |
| 233 this[_description] = description; | |
| 234 this.stackTrace = new _RemoteStackTrace(stackDescription); | |
| 235 } | |
| 236 toString() { | |
| 237 return this[_description]; | |
| 238 } | |
| 239 } | |
| 240 RemoteError[dart.implements] = () => [core.Error]; | |
| 241 dart.setSignature(RemoteError, { | |
| 242 constructors: () => ({RemoteError: [RemoteError, [core.String, core.String]]
}) | |
| 243 }); | |
| 244 let _trace = Symbol('_trace'); | |
| 245 class _RemoteStackTrace extends core.Object { | |
| 246 _RemoteStackTrace(trace) { | |
| 247 this[_trace] = trace; | |
| 248 } | |
| 249 toString() { | |
| 250 return this[_trace]; | |
| 251 } | |
| 252 } | |
| 253 _RemoteStackTrace[dart.implements] = () => [core.StackTrace]; | |
| 254 dart.setSignature(_RemoteStackTrace, { | |
| 255 constructors: () => ({_RemoteStackTrace: [_RemoteStackTrace, [core.String]]}
) | |
| 256 }); | |
| 257 // Exports: | |
| 258 exports.Capability = Capability; | |
| 259 exports.IsolateSpawnException = IsolateSpawnException; | |
| 260 exports.Isolate = Isolate; | |
| 261 exports.SendPort = SendPort; | |
| 262 exports.ReceivePort = ReceivePort; | |
| 263 exports.RawReceivePort = RawReceivePort; | |
| 264 exports.RemoteError = RemoteError; | |
| 265 }); | |
| OLD | NEW |