| OLD | NEW |
| (Empty) |
| 1 dart_library.library('dart/isolate', null, /* Imports */[ | |
| 2 'dart/_runtime', | |
| 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 const _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 _isolate_helper.IsolateNatives.spawnFunction(entryPoint, message,
paused).then(dart.fn(msg => new Isolate(dart.as(msg[dartx.get](1), SendPort), {
pauseCapability: dart.as(msg[dartx.get](2), Capability), terminateCapability: da
rt.as(msg[dartx.get](3), Capability)}), Isolate, [core.List])); | |
| 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) dart.throw(new core.UnimplementedError("packageRo
ot")); | |
| 56 try { | |
| 57 if (dart.is(args, core.List)) { | |
| 58 for (let i = 0; i < dart.notNull(args[dartx.length]); i++) { | |
| 59 if (!(typeof args[dartx.get](i) == 'string')) { | |
| 60 dart.throw(new core.ArgumentError(`Args must be a list of Strings
${args}`)); | |
| 61 } | |
| 62 } | |
| 63 } else if (args != null) { | |
| 64 dart.throw(new core.ArgumentError(`Args must be a list of Strings ${ar
gs}`)); | |
| 65 } | |
| 66 return _isolate_helper.IsolateNatives.spawnUri(uri, args, message, pause
d).then(dart.fn(msg => new Isolate(dart.as(msg[dartx.get](1), SendPort), {pauseC
apability: dart.as(msg[dartx.get](2), Capability), terminateCapability: dart.as(
msg[dartx.get](3), Capability)}), Isolate, [core.List])); | |
| 67 } catch (e) { | |
| 68 let st = dart.stackTrace(e); | |
| 69 return async.Future$(Isolate).error(e, st); | |
| 70 } | |
| 71 | |
| 72 } | |
| 73 pause(resumeCapability) { | |
| 74 if (resumeCapability === void 0) resumeCapability = null; | |
| 75 if (resumeCapability == null) resumeCapability = Capability.new(); | |
| 76 this[_pause](resumeCapability); | |
| 77 return resumeCapability; | |
| 78 } | |
| 79 [_pause](resumeCapability) { | |
| 80 let message = core.List.new(3); | |
| 81 message[dartx.set](0, "pause"); | |
| 82 message[dartx.set](1, this.pauseCapability); | |
| 83 message[dartx.set](2, resumeCapability); | |
| 84 this.controlPort.send(message); | |
| 85 } | |
| 86 resume(resumeCapability) { | |
| 87 let message = core.List.new(2); | |
| 88 message[dartx.set](0, "resume"); | |
| 89 message[dartx.set](1, resumeCapability); | |
| 90 this.controlPort.send(message); | |
| 91 } | |
| 92 addOnExitListener(responsePort) { | |
| 93 let message = core.List.new(2); | |
| 94 message[dartx.set](0, "add-ondone"); | |
| 95 message[dartx.set](1, responsePort); | |
| 96 this.controlPort.send(message); | |
| 97 } | |
| 98 removeOnExitListener(responsePort) { | |
| 99 let message = core.List.new(2); | |
| 100 message[dartx.set](0, "remove-ondone"); | |
| 101 message[dartx.set](1, responsePort); | |
| 102 this.controlPort.send(message); | |
| 103 } | |
| 104 setErrorsFatal(errorsAreFatal) { | |
| 105 let message = core.List.new(3); | |
| 106 message[dartx.set](0, "set-errors-fatal"); | |
| 107 message[dartx.set](1, this.terminateCapability); | |
| 108 message[dartx.set](2, errorsAreFatal); | |
| 109 this.controlPort.send(message); | |
| 110 } | |
| 111 kill(priority) { | |
| 112 if (priority === void 0) priority = Isolate.BEFORE_NEXT_EVENT; | |
| 113 this.controlPort.send(dart.list(["kill", this.terminateCapability, priorit
y], core.Object)); | |
| 114 } | |
| 115 ping(responsePort, pingType) { | |
| 116 if (pingType === void 0) pingType = Isolate.IMMEDIATE; | |
| 117 let message = core.List.new(3); | |
| 118 message[dartx.set](0, "ping"); | |
| 119 message[dartx.set](1, responsePort); | |
| 120 message[dartx.set](2, pingType); | |
| 121 this.controlPort.send(message); | |
| 122 } | |
| 123 addErrorListener(port) { | |
| 124 let message = core.List.new(2); | |
| 125 message[dartx.set](0, "getErrors"); | |
| 126 message[dartx.set](1, port); | |
| 127 this.controlPort.send(message); | |
| 128 } | |
| 129 removeErrorListener(port) { | |
| 130 let message = core.List.new(2); | |
| 131 message[dartx.set](0, "stopErrors"); | |
| 132 message[dartx.set](1, port); | |
| 133 this.controlPort.send(message); | |
| 134 } | |
| 135 get errors() { | |
| 136 let controller = null; | |
| 137 let port = null; | |
| 138 function handleError(message) { | |
| 139 let errorDescription = dart.as(dart.dindex(message, 0), core.String); | |
| 140 let stackDescription = dart.as(dart.dindex(message, 1), core.String); | |
| 141 let error = new RemoteError(errorDescription, stackDescription); | |
| 142 controller.addError(error, error.stackTrace); | |
| 143 } | |
| 144 dart.fn(handleError, dart.void, [dart.dynamic]); | |
| 145 controller = async.StreamController.broadcast({sync: true, onListen: dart.
fn(() => { | |
| 146 port = RawReceivePort.new(handleError); | |
| 147 this.addErrorListener(port.sendPort); | |
| 148 }, dart.void, []), onCancel: dart.fn(() => { | |
| 149 this.removeErrorListener(port.sendPort); | |
| 150 port.close(); | |
| 151 port = null; | |
| 152 }, dart.void, [])}); | |
| 153 return controller.stream; | |
| 154 } | |
| 155 } | |
| 156 dart.setSignature(Isolate, { | |
| 157 constructors: () => ({Isolate: [Isolate, [SendPort], {pauseCapability: Capab
ility, terminateCapability: Capability}]}), | |
| 158 methods: () => ({ | |
| 159 pause: [Capability, [], [Capability]], | |
| 160 [_pause]: [dart.void, [Capability]], | |
| 161 resume: [dart.void, [Capability]], | |
| 162 addOnExitListener: [dart.void, [SendPort]], | |
| 163 removeOnExitListener: [dart.void, [SendPort]], | |
| 164 setErrorsFatal: [dart.void, [core.bool]], | |
| 165 kill: [dart.void, [], [core.int]], | |
| 166 ping: [dart.void, [SendPort], [core.int]], | |
| 167 addErrorListener: [dart.void, [SendPort]], | |
| 168 removeErrorListener: [dart.void, [SendPort]] | |
| 169 }), | |
| 170 statics: () => ({ | |
| 171 spawn: [async.Future$(Isolate), [dart.functionType(dart.void, [dart.dynami
c]), dart.dynamic], {paused: core.bool}], | |
| 172 spawnUri: [async.Future$(Isolate), [core.Uri, core.List$(core.String), dar
t.dynamic], {paused: core.bool, packageRoot: core.Uri}] | |
| 173 }), | |
| 174 names: ['spawn', 'spawnUri'] | |
| 175 }); | |
| 176 Isolate.IMMEDIATE = 0; | |
| 177 Isolate.BEFORE_NEXT_EVENT = 1; | |
| 178 Isolate.AS_EVENT = 2; | |
| 179 dart.defineLazyProperties(Isolate, { | |
| 180 get _currentIsolateCache() { | |
| 181 return _isolate_helper.IsolateNatives.currentIsolate; | |
| 182 } | |
| 183 }); | |
| 184 class SendPort extends core.Object {} | |
| 185 SendPort[dart.implements] = () => [Capability]; | |
| 186 class ReceivePort extends core.Object { | |
| 187 static new() { | |
| 188 return new _isolate_helper.ReceivePortImpl(); | |
| 189 } | |
| 190 static fromRawReceivePort(rawPort) { | |
| 191 return new _isolate_helper.ReceivePortImpl.fromRawReceivePort(rawPort); | |
| 192 } | |
| 193 } | |
| 194 ReceivePort[dart.implements] = () => [async.Stream]; | |
| 195 dart.setSignature(ReceivePort, { | |
| 196 constructors: () => ({ | |
| 197 new: [ReceivePort, []], | |
| 198 fromRawReceivePort: [ReceivePort, [RawReceivePort]] | |
| 199 }) | |
| 200 }); | |
| 201 class RawReceivePort extends core.Object { | |
| 202 static new(handler) { | |
| 203 if (handler === void 0) handler = null; | |
| 204 return new _isolate_helper.RawReceivePortImpl(handler); | |
| 205 } | |
| 206 } | |
| 207 dart.setSignature(RawReceivePort, { | |
| 208 constructors: () => ({new: [RawReceivePort, [], [dart.functionType(dart.void
, [dart.dynamic])]]}) | |
| 209 }); | |
| 210 class _IsolateUnhandledException extends core.Object { | |
| 211 _IsolateUnhandledException(message, source, stackTrace) { | |
| 212 this.message = message; | |
| 213 this.source = source; | |
| 214 this.stackTrace = stackTrace; | |
| 215 } | |
| 216 toString() { | |
| 217 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 ")}`; | |
| 218 } | |
| 219 } | |
| 220 _IsolateUnhandledException[dart.implements] = () => [core.Exception]; | |
| 221 dart.setSignature(_IsolateUnhandledException, { | |
| 222 constructors: () => ({_IsolateUnhandledException: [_IsolateUnhandledExceptio
n, [dart.dynamic, dart.dynamic, core.StackTrace]]}) | |
| 223 }); | |
| 224 const _description = Symbol('_description'); | |
| 225 class RemoteError extends core.Object { | |
| 226 RemoteError(description, stackDescription) { | |
| 227 this[_description] = description; | |
| 228 this.stackTrace = new _RemoteStackTrace(stackDescription); | |
| 229 } | |
| 230 toString() { | |
| 231 return this[_description]; | |
| 232 } | |
| 233 } | |
| 234 RemoteError[dart.implements] = () => [core.Error]; | |
| 235 dart.setSignature(RemoteError, { | |
| 236 constructors: () => ({RemoteError: [RemoteError, [core.String, core.String]]
}) | |
| 237 }); | |
| 238 const _trace = Symbol('_trace'); | |
| 239 class _RemoteStackTrace extends core.Object { | |
| 240 _RemoteStackTrace(trace) { | |
| 241 this[_trace] = trace; | |
| 242 } | |
| 243 toString() { | |
| 244 return this[_trace]; | |
| 245 } | |
| 246 } | |
| 247 _RemoteStackTrace[dart.implements] = () => [core.StackTrace]; | |
| 248 dart.setSignature(_RemoteStackTrace, { | |
| 249 constructors: () => ({_RemoteStackTrace: [_RemoteStackTrace, [core.String]]}
) | |
| 250 }); | |
| 251 // Exports: | |
| 252 exports.Capability = Capability; | |
| 253 exports.IsolateSpawnException = IsolateSpawnException; | |
| 254 exports.Isolate = Isolate; | |
| 255 exports.SendPort = SendPort; | |
| 256 exports.ReceivePort = ReceivePort; | |
| 257 exports.RawReceivePort = RawReceivePort; | |
| 258 exports.RemoteError = RemoteError; | |
| 259 }); | |
| OLD | NEW |