OLD | NEW |
1 var _isolate_helper; | 1 var _isolate_helper; |
2 (function(_isolate_helper) { | 2 (function(exports) { |
3 'use strict'; | 3 'use strict'; |
4 // Function _callInIsolate: (_IsolateContext, Function) → dynamic | 4 // Function _callInIsolate: (_IsolateContext, Function) → dynamic |
5 function _callInIsolate(isolate, function) { | 5 function _callInIsolate(isolate, function) { |
6 let result = isolate.eval(function); | 6 let result = isolate.eval(function); |
7 _isolate_helper._globalState.topEventLoop.run(); | 7 exports._globalState.topEventLoop.run(); |
8 return result; | 8 return result; |
9 } | 9 } |
10 // Function enterJsAsync: () → dynamic | 10 // Function enterJsAsync: () → dynamic |
11 function enterJsAsync() { | 11 function enterJsAsync() { |
12 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount++; | 12 exports._globalState.topEventLoop._activeJsAsyncCount++; |
13 } | 13 } |
14 // Function leaveJsAsync: () → dynamic | 14 // Function leaveJsAsync: () → dynamic |
15 function leaveJsAsync() { | 15 function leaveJsAsync() { |
16 _isolate_helper._globalState.topEventLoop._activeJsAsyncCount--; | 16 exports._globalState.topEventLoop._activeJsAsyncCount--; |
17 dart.assert(_isolate_helper._globalState.topEventLoop._activeJsAsyncCount >=
0); | 17 dart.assert(exports._globalState.topEventLoop._activeJsAsyncCount >= 0); |
18 } | 18 } |
19 // Function isWorker: () → bool | 19 // Function isWorker: () → bool |
20 function isWorker() { | 20 function isWorker() { |
21 return _isolate_helper._globalState.isWorker; | 21 return exports._globalState.isWorker; |
22 } | 22 } |
23 // Function _currentIsolate: () → _IsolateContext | 23 // Function _currentIsolate: () → _IsolateContext |
24 function _currentIsolate() { | 24 function _currentIsolate() { |
25 return _isolate_helper._globalState.currentContext; | 25 return exports._globalState.currentContext; |
26 } | 26 } |
27 // Function startRootIsolate: (dynamic, dynamic) → void | 27 // Function startRootIsolate: (dynamic, dynamic) → void |
28 function startRootIsolate(entry, args) { | 28 function startRootIsolate(entry, args) { |
29 args = args; | 29 args = args; |
30 if (args === null) | 30 if (args === null) |
31 args = new List.from([]); | 31 args = new List.from([]); |
32 if (!dart.is(args, core.List)) { | 32 if (!dart.is(args, core.List)) { |
33 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); | 33 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); |
34 } | 34 } |
35 _isolate_helper._globalState = new _Manager(dart.as(entry, core.Function)); | 35 exports._globalState = new _Manager(dart.as(entry, core.Function)); |
36 if (_isolate_helper._globalState.isWorker) | 36 if (exports._globalState.isWorker) |
37 return; | 37 return; |
38 let rootContext = new _IsolateContext(); | 38 let rootContext = new _IsolateContext(); |
39 _isolate_helper._globalState.rootContext = rootContext; | 39 exports._globalState.rootContext = rootContext; |
40 _isolate_helper._globalState.currentContext = rootContext; | 40 exports._globalState.currentContext = rootContext; |
41 if (dart.is(entry, _MainFunctionArgs)) { | 41 if (dart.is(entry, _MainFunctionArgs)) { |
42 rootContext.eval(() => { | 42 rootContext.eval(() => { |
43 dart.dinvokef(entry, args); | 43 dart.dinvokef(entry, args); |
44 }); | 44 }); |
45 } else if (dart.is(entry, _MainFunctionArgsMessage)) { | 45 } else if (dart.is(entry, _MainFunctionArgsMessage)) { |
46 rootContext.eval(() => { | 46 rootContext.eval(() => { |
47 dart.dinvokef(entry, args, null); | 47 dart.dinvokef(entry, args, null); |
48 }); | 48 }); |
49 } else { | 49 } else { |
50 rootContext.eval(dart.as(entry, core.Function)); | 50 rootContext.eval(dart.as(entry, core.Function)); |
51 } | 51 } |
52 _isolate_helper._globalState.topEventLoop.run(); | 52 exports._globalState.topEventLoop.run(); |
53 } | 53 } |
54 dart.copyProperties(_isolate_helper, { | 54 dart.copyProperties(exports, { |
55 get _globalState() { | 55 get _globalState() { |
56 return dart.as(init.globalState, _Manager); | 56 return dart.as(init.globalState, _Manager); |
57 }, | 57 }, |
58 set _globalState(val) { | 58 set _globalState(val) { |
59 init.globalState = val; | 59 init.globalState = val; |
60 } | 60 } |
61 }); | 61 }); |
62 class _Manager extends dart.Object { | 62 class _Manager extends dart.Object { |
63 get useWorkers() { | 63 get useWorkers() { |
64 return this.supportsWorkers; | 64 return this.supportsWorkers; |
(...skipping 15 matching lines...) Expand all Loading... |
80 this._nativeDetectEnvironment(); | 80 this._nativeDetectEnvironment(); |
81 this.topEventLoop = new _EventLoop(); | 81 this.topEventLoop = new _EventLoop(); |
82 this.isolates = new core.Map(); | 82 this.isolates = new core.Map(); |
83 this.managers = new core.Map(); | 83 this.managers = new core.Map(); |
84 if (this.isWorker) { | 84 if (this.isWorker) { |
85 this.mainManager = new _MainManagerStub(); | 85 this.mainManager = new _MainManagerStub(); |
86 this._nativeInitWorkerMessageHandler(); | 86 this._nativeInitWorkerMessageHandler(); |
87 } | 87 } |
88 } | 88 } |
89 _nativeDetectEnvironment() { | 89 _nativeDetectEnvironment() { |
90 let isWindowDefined = _isolate_helper.globalWindow !== null; | 90 let isWindowDefined = exports.globalWindow !== null; |
91 let isWorkerDefined = _isolate_helper.globalWorker !== null; | 91 let isWorkerDefined = exports.globalWorker !== null; |
92 this.isWorker = dart.notNull(!dart.notNull(isWindowDefined)) && dart.notNu
ll(_isolate_helper.globalPostMessageDefined); | 92 this.isWorker = dart.notNull(!dart.notNull(isWindowDefined)) && dart.notNu
ll(exports.globalPostMessageDefined); |
93 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(dart.no
tNull(isWorkerDefined) && dart.notNull(IsolateNatives.thisScript !== null)); | 93 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(dart.no
tNull(isWorkerDefined) && dart.notNull(IsolateNatives.thisScript !== null)); |
94 this.fromCommandLine = dart.notNull(!dart.notNull(isWindowDefined)) && dar
t.notNull(!dart.notNull(this.isWorker)); | 94 this.fromCommandLine = dart.notNull(!dart.notNull(isWindowDefined)) && dar
t.notNull(!dart.notNull(this.isWorker)); |
95 } | 95 } |
96 _nativeInitWorkerMessageHandler() { | 96 _nativeInitWorkerMessageHandler() { |
97 let function = function(f, a) { | 97 let function = function(f, a) { |
98 return function(e) { | 98 return function(e) { |
99 f(a, e); | 99 f(a, e); |
100 }; | 100 }; |
101 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage)
, this.mainManager); | 101 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage)
, this.mainManager); |
102 self.onmessage = function; | 102 self.onmessage = function; |
(...skipping 11 matching lines...) Expand all Loading... |
114 return _serializeMessage(dart.map({command: "print", msg: object})); | 114 return _serializeMessage(dart.map({command: "print", msg: object})); |
115 } | 115 } |
116 maybeCloseWorker() { | 116 maybeCloseWorker() { |
117 if (dart.notNull(dart.notNull(this.isWorker) && dart.notNull(this.isolates
.isEmpty)) && dart.notNull(this.topEventLoop._activeJsAsyncCount === 0)) { | 117 if (dart.notNull(dart.notNull(this.isWorker) && dart.notNull(this.isolates
.isEmpty)) && dart.notNull(this.topEventLoop._activeJsAsyncCount === 0)) { |
118 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); | 118 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
122 class _IsolateContext extends dart.Object { | 122 class _IsolateContext extends dart.Object { |
123 _IsolateContext() { | 123 _IsolateContext() { |
124 this.id = _isolate_helper._globalState.nextIsolateId++; | 124 this.id = exports._globalState.nextIsolateId++; |
125 this.ports = new core.Map(); | 125 this.ports = new core.Map(); |
126 this.weakPorts = new core.Set(); | 126 this.weakPorts = new core.Set(); |
127 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); | 127 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); |
128 this.controlPort = new RawReceivePortImpl._controlPort(); | 128 this.controlPort = new RawReceivePortImpl._controlPort(); |
129 this.pauseCapability = new isolate.Capability(); | 129 this.pauseCapability = new isolate.Capability(); |
130 this.terminateCapability = new isolate.Capability(); | 130 this.terminateCapability = new isolate.Capability(); |
131 this.delayedEvents = dart.as(new List.from([]), core.List$(_IsolateEvent))
; | 131 this.delayedEvents = dart.as(new List.from([]), core.List$(_IsolateEvent))
; |
132 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability)); | 132 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability)); |
133 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort)); | 133 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort)); |
134 this.initialized = false; | 134 this.initialized = false; |
(...skipping 12 matching lines...) Expand all Loading... |
147 } | 147 } |
148 this._updateGlobalState(); | 148 this._updateGlobalState(); |
149 } | 149 } |
150 removePause(resume) { | 150 removePause(resume) { |
151 if (!dart.notNull(this.isPaused)) | 151 if (!dart.notNull(this.isPaused)) |
152 return; | 152 return; |
153 this.pauseTokens.remove(resume); | 153 this.pauseTokens.remove(resume); |
154 if (this.pauseTokens.isEmpty) { | 154 if (this.pauseTokens.isEmpty) { |
155 while (this.delayedEvents.isNotEmpty) { | 155 while (this.delayedEvents.isNotEmpty) { |
156 let event = this.delayedEvents.removeLast(); | 156 let event = this.delayedEvents.removeLast(); |
157 _isolate_helper._globalState.topEventLoop.prequeue(event); | 157 exports._globalState.topEventLoop.prequeue(event); |
158 } | 158 } |
159 this.isPaused = false; | 159 this.isPaused = false; |
160 } | 160 } |
161 this._updateGlobalState(); | 161 this._updateGlobalState(); |
162 } | 162 } |
163 addDoneListener(responsePort) { | 163 addDoneListener(responsePort) { |
164 if (this.doneHandlers === null) { | 164 if (this.doneHandlers === null) { |
165 this.doneHandlers = new List.from([]); | 165 this.doneHandlers = new List.from([]); |
166 } | 166 } |
167 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) | 167 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) |
(...skipping 13 matching lines...) Expand all Loading... |
181 handlePing(responsePort, pingType) { | 181 handlePing(responsePort, pingType) { |
182 if (dart.notNull(pingType === isolate.Isolate.IMMEDIATE) || dart.notNull(d
art.notNull(pingType === isolate.Isolate.BEFORE_NEXT_EVENT) && dart.notNull(!dar
t.notNull(this._isExecutingEvent)))) { | 182 if (dart.notNull(pingType === isolate.Isolate.IMMEDIATE) || dart.notNull(d
art.notNull(pingType === isolate.Isolate.BEFORE_NEXT_EVENT) && dart.notNull(!dar
t.notNull(this._isExecutingEvent)))) { |
183 responsePort.send(null); | 183 responsePort.send(null); |
184 return; | 184 return; |
185 } | 185 } |
186 // Function respond: () → void | 186 // Function respond: () → void |
187 function respond() { | 187 function respond() { |
188 responsePort.send(null); | 188 responsePort.send(null); |
189 } | 189 } |
190 if (pingType === isolate.Isolate.AS_EVENT) { | 190 if (pingType === isolate.Isolate.AS_EVENT) { |
191 _isolate_helper._globalState.topEventLoop.enqueue(this, respond, "ping")
; | 191 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); |
192 return; | 192 return; |
193 } | 193 } |
194 dart.assert(pingType === isolate.Isolate.BEFORE_NEXT_EVENT); | 194 dart.assert(pingType === isolate.Isolate.BEFORE_NEXT_EVENT); |
195 if (this._scheduledControlEvents === null) { | 195 if (this._scheduledControlEvents === null) { |
196 this._scheduledControlEvents = new collection.Queue(); | 196 this._scheduledControlEvents = new collection.Queue(); |
197 } | 197 } |
198 dart.dinvoke(this._scheduledControlEvents, 'addLast', respond); | 198 dart.dinvoke(this._scheduledControlEvents, 'addLast', respond); |
199 } | 199 } |
200 handleKill(authentification, priority) { | 200 handleKill(authentification, priority) { |
201 if (!dart.equals(this.terminateCapability, authentification)) | 201 if (!dart.equals(this.terminateCapability, authentification)) |
202 return; | 202 return; |
203 if (dart.notNull(priority === isolate.Isolate.IMMEDIATE) || dart.notNull(d
art.notNull(priority === isolate.Isolate.BEFORE_NEXT_EVENT) && dart.notNull(!dar
t.notNull(this._isExecutingEvent)))) { | 203 if (dart.notNull(priority === isolate.Isolate.IMMEDIATE) || dart.notNull(d
art.notNull(priority === isolate.Isolate.BEFORE_NEXT_EVENT) && dart.notNull(!dar
t.notNull(this._isExecutingEvent)))) { |
204 this.kill(); | 204 this.kill(); |
205 return; | 205 return; |
206 } | 206 } |
207 if (priority === isolate.Isolate.AS_EVENT) { | 207 if (priority === isolate.Isolate.AS_EVENT) { |
208 _isolate_helper._globalState.topEventLoop.enqueue(this, this.kill, "kill
"); | 208 exports._globalState.topEventLoop.enqueue(this, this.kill, "kill"); |
209 return; | 209 return; |
210 } | 210 } |
211 dart.assert(priority === isolate.Isolate.BEFORE_NEXT_EVENT); | 211 dart.assert(priority === isolate.Isolate.BEFORE_NEXT_EVENT); |
212 if (this._scheduledControlEvents === null) { | 212 if (this._scheduledControlEvents === null) { |
213 this._scheduledControlEvents = new collection.Queue(); | 213 this._scheduledControlEvents = new collection.Queue(); |
214 } | 214 } |
215 dart.dinvoke(this._scheduledControlEvents, 'addLast', this.kill); | 215 dart.dinvoke(this._scheduledControlEvents, 'addLast', this.kill); |
216 } | 216 } |
217 addErrorListener(port) { | 217 addErrorListener(port) { |
218 this.errorPorts.add(port); | 218 this.errorPorts.add(port); |
219 } | 219 } |
220 removeErrorListener(port) { | 220 removeErrorListener(port) { |
221 this.errorPorts.remove(port); | 221 this.errorPorts.remove(port); |
222 } | 222 } |
223 handleUncaughtError(error, stackTrace) { | 223 handleUncaughtError(error, stackTrace) { |
224 if (this.errorPorts.isEmpty) { | 224 if (this.errorPorts.isEmpty) { |
225 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, _isolate_helper._globalState.rootContext))) { | 225 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { |
226 return; | 226 return; |
227 } | 227 } |
228 if (self.console && self.console.error) { | 228 if (self.console && self.console.error) { |
229 self.console.error(error, stackTrace); | 229 self.console.error(error, stackTrace); |
230 } else { | 230 } else { |
231 core.print(error); | 231 core.print(error); |
232 if (stackTrace !== null) | 232 if (stackTrace !== null) |
233 core.print(stackTrace); | 233 core.print(stackTrace); |
234 } | 234 } |
235 return; | 235 return; |
236 } | 236 } |
237 let message = new core.List(2); | 237 let message = new core.List(2); |
238 message.set(0, dart.dinvoke(error, 'toString')); | 238 message.set(0, dart.dinvoke(error, 'toString')); |
239 message.set(1, stackTrace === null ? null : stackTrace.toString()); | 239 message.set(1, stackTrace === null ? null : stackTrace.toString()); |
240 for (let port of this.errorPorts) | 240 for (let port of this.errorPorts) |
241 port.send(message); | 241 port.send(message); |
242 } | 242 } |
243 eval(code) { | 243 eval(code) { |
244 let old = _isolate_helper._globalState.currentContext; | 244 let old = exports._globalState.currentContext; |
245 _isolate_helper._globalState.currentContext = this; | 245 exports._globalState.currentContext = this; |
246 this._setGlobals(); | 246 this._setGlobals(); |
247 let result = null; | 247 let result = null; |
248 this._isExecutingEvent = true; | 248 this._isExecutingEvent = true; |
249 try { | 249 try { |
250 result = dart.dinvokef(code); | 250 result = dart.dinvokef(code); |
251 } catch (e) { | 251 } catch (e) { |
252 let s = dart.stackTrace(e); | 252 let s = dart.stackTrace(e); |
253 this.handleUncaughtError(e, s); | 253 this.handleUncaughtError(e, s); |
254 if (this.errorsAreFatal) { | 254 if (this.errorsAreFatal) { |
255 this.kill(); | 255 this.kill(); |
256 if (core.identical(this, _isolate_helper._globalState.rootContext)) { | 256 if (core.identical(this, exports._globalState.rootContext)) { |
257 dart.throw_("Unimplemented RethrowExpression: rethrow"); | 257 dart.throw_("Unimplemented RethrowExpression: rethrow"); |
258 } | 258 } |
259 } | 259 } |
260 } | 260 } |
261 finally { | 261 finally { |
262 this._isExecutingEvent = false; | 262 this._isExecutingEvent = false; |
263 _isolate_helper._globalState.currentContext = old; | 263 exports._globalState.currentContext = old; |
264 if (old !== null) | 264 if (old !== null) |
265 old._setGlobals(); | 265 old._setGlobals(); |
266 if (this._scheduledControlEvents !== null) { | 266 if (this._scheduledControlEvents !== null) { |
267 while (dart.dload(this._scheduledControlEvents, 'isNotEmpty')) { | 267 while (dart.dload(this._scheduledControlEvents, 'isNotEmpty')) { |
268 dart.dinvokef(dart.dinvoke(this._scheduledControlEvents, 'removeFirs
t')); | 268 dart.dinvokef(dart.dinvoke(this._scheduledControlEvents, 'removeFirs
t')); |
269 } | 269 } |
270 } | 270 } |
271 } | 271 } |
272 return result; | 272 return result; |
273 } | 273 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 register(portId, port) { | 318 register(portId, port) { |
319 this._addRegistration(portId, port); | 319 this._addRegistration(portId, port); |
320 this._updateGlobalState(); | 320 this._updateGlobalState(); |
321 } | 321 } |
322 registerWeak(portId, port) { | 322 registerWeak(portId, port) { |
323 this.weakPorts.add(portId); | 323 this.weakPorts.add(portId); |
324 this._addRegistration(portId, port); | 324 this._addRegistration(portId, port); |
325 } | 325 } |
326 _updateGlobalState() { | 326 _updateGlobalState() { |
327 if (dart.notNull(dart.notNull(this.ports.length - this.weakPorts.length >
0) || dart.notNull(this.isPaused)) || dart.notNull(!dart.notNull(this.initialize
d))) { | 327 if (dart.notNull(dart.notNull(this.ports.length - this.weakPorts.length >
0) || dart.notNull(this.isPaused)) || dart.notNull(!dart.notNull(this.initialize
d))) { |
328 _isolate_helper._globalState.isolates.set(this.id, this); | 328 exports._globalState.isolates.set(this.id, this); |
329 } else { | 329 } else { |
330 this.kill(); | 330 this.kill(); |
331 } | 331 } |
332 } | 332 } |
333 kill() { | 333 kill() { |
334 if (this._scheduledControlEvents !== null) { | 334 if (this._scheduledControlEvents !== null) { |
335 dart.dinvoke(this._scheduledControlEvents, 'clear'); | 335 dart.dinvoke(this._scheduledControlEvents, 'clear'); |
336 } | 336 } |
337 for (let port of this.ports.values) { | 337 for (let port of this.ports.values) { |
338 dart.dinvoke(port, '_close'); | 338 dart.dinvoke(port, '_close'); |
339 } | 339 } |
340 this.ports.clear(); | 340 this.ports.clear(); |
341 this.weakPorts.clear(); | 341 this.weakPorts.clear(); |
342 _isolate_helper._globalState.isolates.remove(this.id); | 342 exports._globalState.isolates.remove(this.id); |
343 this.errorPorts.clear(); | 343 this.errorPorts.clear(); |
344 if (this.doneHandlers !== null) { | 344 if (this.doneHandlers !== null) { |
345 for (let port of this.doneHandlers) { | 345 for (let port of this.doneHandlers) { |
346 port.send(null); | 346 port.send(null); |
347 } | 347 } |
348 this.doneHandlers = null; | 348 this.doneHandlers = null; |
349 } | 349 } |
350 } | 350 } |
351 unregister(portId) { | 351 unregister(portId) { |
352 this.ports.remove(portId); | 352 this.ports.remove(portId); |
(...skipping 11 matching lines...) Expand all Loading... |
364 } | 364 } |
365 prequeue(event) { | 365 prequeue(event) { |
366 this.events.addFirst(event); | 366 this.events.addFirst(event); |
367 } | 367 } |
368 dequeue() { | 368 dequeue() { |
369 if (this.events.isEmpty) | 369 if (this.events.isEmpty) |
370 return null; | 370 return null; |
371 return this.events.removeFirst(); | 371 return this.events.removeFirst(); |
372 } | 372 } |
373 checkOpenReceivePortsFromCommandLine() { | 373 checkOpenReceivePortsFromCommandLine() { |
374 if (dart.notNull(dart.notNull(dart.notNull(_isolate_helper._globalState.ro
otContext !== null) && dart.notNull(_isolate_helper._globalState.isolates.contai
nsKey(_isolate_helper._globalState.rootContext.id))) && dart.notNull(_isolate_he
lper._globalState.fromCommandLine)) && dart.notNull(_isolate_helper._globalState
.rootContext.ports.isEmpty)) { | 374 if (dart.notNull(dart.notNull(dart.notNull(exports._globalState.rootContex
t !== null) && dart.notNull(exports._globalState.isolates.containsKey(exports._g
lobalState.rootContext.id))) && dart.notNull(exports._globalState.fromCommandLin
e)) && dart.notNull(exports._globalState.rootContext.ports.isEmpty)) { |
375 throw new core.Exception("Program exited with open ReceivePorts."); | 375 throw new core.Exception("Program exited with open ReceivePorts."); |
376 } | 376 } |
377 } | 377 } |
378 runIteration() { | 378 runIteration() { |
379 let event = this.dequeue(); | 379 let event = this.dequeue(); |
380 if (event === null) { | 380 if (event === null) { |
381 this.checkOpenReceivePortsFromCommandLine(); | 381 this.checkOpenReceivePortsFromCommandLine(); |
382 _isolate_helper._globalState.maybeCloseWorker(); | 382 exports._globalState.maybeCloseWorker(); |
383 return false; | 383 return false; |
384 } | 384 } |
385 event.process(); | 385 event.process(); |
386 return true; | 386 return true; |
387 } | 387 } |
388 _runHelper() { | 388 _runHelper() { |
389 if (_isolate_helper.globalWindow !== null) { | 389 if (exports.globalWindow !== null) { |
390 // Function next: () → void | 390 // Function next: () → void |
391 function next() { | 391 function next() { |
392 if (!dart.notNull(this.runIteration())) | 392 if (!dart.notNull(this.runIteration())) |
393 return; | 393 return; |
394 async.Timer.run(next); | 394 async.Timer.run(next); |
395 } | 395 } |
396 next(); | 396 next(); |
397 } else { | 397 } else { |
398 while (this.runIteration()) { | 398 while (this.runIteration()) { |
399 } | 399 } |
400 } | 400 } |
401 } | 401 } |
402 run() { | 402 run() { |
403 if (!dart.notNull(_isolate_helper._globalState.isWorker)) { | 403 if (!dart.notNull(exports._globalState.isWorker)) { |
404 this._runHelper(); | 404 this._runHelper(); |
405 } else { | 405 } else { |
406 try { | 406 try { |
407 this._runHelper(); | 407 this._runHelper(); |
408 } catch (e) { | 408 } catch (e) { |
409 let trace = dart.stackTrace(e); | 409 let trace = dart.stackTrace(e); |
410 _isolate_helper._globalState.mainManager.postMessage(_serializeMessage
(dart.map({command: 'error', msg: `${e}\n${trace}`}))); | 410 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma
p({command: 'error', msg: `${e}\n${trace}`}))); |
411 } | 411 } |
412 | 412 |
413 } | 413 } |
414 } | 414 } |
415 } | 415 } |
416 class _IsolateEvent extends dart.Object { | 416 class _IsolateEvent extends dart.Object { |
417 _IsolateEvent(isolate, fn, message) { | 417 _IsolateEvent(isolate, fn, message) { |
418 this.isolate = isolate; | 418 this.isolate = isolate; |
419 this.fn = fn; | 419 this.fn = fn; |
420 this.message = message; | 420 this.message = message; |
421 } | 421 } |
422 process() { | 422 process() { |
423 if (this.isolate.isPaused) { | 423 if (this.isolate.isPaused) { |
424 this.isolate.delayedEvents.add(this); | 424 this.isolate.delayedEvents.add(this); |
425 return; | 425 return; |
426 } | 426 } |
427 this.isolate.eval(this.fn); | 427 this.isolate.eval(this.fn); |
428 } | 428 } |
429 } | 429 } |
430 class _MainManagerStub extends dart.Object { | 430 class _MainManagerStub extends dart.Object { |
431 postMessage(msg) { | 431 postMessage(msg) { |
432 _js_helper.requiresPreamble(); | 432 _js_helper.requiresPreamble(); |
433 self.postMessage(msg); | 433 self.postMessage(msg); |
434 } | 434 } |
435 } | 435 } |
436 let _SPAWNED_SIGNAL = "spawned"; | 436 let _SPAWNED_SIGNAL = "spawned"; |
437 let _SPAWN_FAILED_SIGNAL = "spawn failed"; | 437 let _SPAWN_FAILED_SIGNAL = "spawn failed"; |
438 dart.copyProperties(_isolate_helper, { | 438 dart.copyProperties(exports, { |
439 get globalWindow() { | 439 get globalWindow() { |
440 _js_helper.requiresPreamble(); | 440 _js_helper.requiresPreamble(); |
441 return self.window; | 441 return self.window; |
442 }, | 442 }, |
443 get globalWorker() { | 443 get globalWorker() { |
444 _js_helper.requiresPreamble(); | 444 _js_helper.requiresPreamble(); |
445 return self.Worker; | 445 return self.Worker; |
446 }, | 446 }, |
447 get globalPostMessageDefined() { | 447 get globalPostMessageDefined() { |
448 _js_helper.requiresPreamble(); | 448 _js_helper.requiresPreamble(); |
449 return !!self.postMessage; | 449 return !!self.postMessage; |
450 } | 450 } |
451 }); | 451 }); |
452 class IsolateNatives extends dart.Object { | 452 class IsolateNatives extends dart.Object { |
453 static computeThisScript() { | 453 static computeThisScript() { |
454 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb
edded_names.CURRENT_SCRIPT, core.String)); | 454 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb
edded_names.CURRENT_SCRIPT, core.String)); |
455 if (currentScript !== null) { | 455 if (currentScript !== null) { |
456 return String(currentScript.src); | 456 return String(currentScript.src); |
457 } | 457 } |
458 if (_js_helper.Primitives.isD8) | 458 if (_js_helper.Primitives.isD8) |
459 return computeThisScriptD8(); | 459 return computeThisScriptD8(); |
460 if (_js_helper.Primitives.isJsshell) | 460 if (_js_helper.Primitives.isJsshell) |
461 return computeThisScriptJsshell(); | 461 return computeThisScriptJsshell(); |
462 if (_isolate_helper._globalState.isWorker) | 462 if (exports._globalState.isWorker) |
463 return computeThisScriptFromTrace(); | 463 return computeThisScriptFromTrace(); |
464 return null; | 464 return null; |
465 } | 465 } |
466 static computeThisScriptJsshell() { | 466 static computeThisScriptJsshell() { |
467 return dart.as(thisFilename(), core.String); | 467 return dart.as(thisFilename(), core.String); |
468 } | 468 } |
469 static computeThisScriptD8() { | 469 static computeThisScriptD8() { |
470 return computeThisScriptFromTrace(); | 470 return computeThisScriptFromTrace(); |
471 } | 471 } |
472 static computeThisScriptFromTrace() { | 472 static computeThisScriptFromTrace() { |
(...skipping 21 matching lines...) Expand all Loading... |
494 return matches[1]; | 494 return matches[1]; |
495 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); | 495 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); |
496 } | 496 } |
497 static _getEventData(e) { | 497 static _getEventData(e) { |
498 return e.data; | 498 return e.data; |
499 } | 499 } |
500 static _processWorkerMessage(sender, e) { | 500 static _processWorkerMessage(sender, e) { |
501 let msg = _deserializeMessage(_getEventData(e)); | 501 let msg = _deserializeMessage(_getEventData(e)); |
502 switch (dart.dindex(msg, 'command')) { | 502 switch (dart.dindex(msg, 'command')) { |
503 case 'start': | 503 case 'start': |
504 _isolate_helper._globalState.currentManagerId = dart.as(dart.dindex(ms
g, 'id'), core.int); | 504 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); |
505 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); | 505 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); |
506 let entryPoint = dart.as(functionName === null ? _isolate_helper._glob
alState.entry : _getJSFunctionFromName(functionName), core.Function); | 506 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : _getJSFunctionFromName(functionName), core.Function); |
507 let args = dart.dindex(msg, 'args'); | 507 let args = dart.dindex(msg, 'args'); |
508 let message = _deserializeMessage(dart.dindex(msg, 'msg')); | 508 let message = _deserializeMessage(dart.dindex(msg, 'msg')); |
509 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); | 509 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); |
510 let startPaused = dart.dindex(msg, 'startPaused'); | 510 let startPaused = dart.dindex(msg, 'startPaused'); |
511 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); | 511 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); |
512 let context = new _IsolateContext(); | 512 let context = new _IsolateContext(); |
513 _isolate_helper._globalState.topEventLoop.enqueue(context, () => { | 513 exports._globalState.topEventLoop.enqueue(context, () => { |
514 _startIsolate(entryPoint, dart.as(args, core.List$(core.String)), me
ssage, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core.bool), dart.as(
replyTo, isolate.SendPort)); | 514 _startIsolate(entryPoint, dart.as(args, core.List$(core.String)), me
ssage, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core.bool), dart.as(
replyTo, isolate.SendPort)); |
515 }, 'worker-start'); | 515 }, 'worker-start'); |
516 _isolate_helper._globalState.currentContext = context; | 516 exports._globalState.currentContext = context; |
517 _isolate_helper._globalState.topEventLoop.run(); | 517 exports._globalState.topEventLoop.run(); |
518 break; | 518 break; |
519 case 'spawn-worker': | 519 case 'spawn-worker': |
520 if (enableSpawnWorker !== null) | 520 if (enableSpawnWorker !== null) |
521 handleSpawnWorkerRequest(msg); | 521 handleSpawnWorkerRequest(msg); |
522 break; | 522 break; |
523 case 'message': | 523 case 'message': |
524 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); | 524 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); |
525 if (port !== null) { | 525 if (port !== null) { |
526 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); | 526 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); |
527 } | 527 } |
528 _isolate_helper._globalState.topEventLoop.run(); | 528 exports._globalState.topEventLoop.run(); |
529 break; | 529 break; |
530 case 'close': | 530 case 'close': |
531 _isolate_helper._globalState.managers.remove(workerIds.get(sender)); | 531 exports._globalState.managers.remove(workerIds.get(sender)); |
532 sender.terminate(); | 532 sender.terminate(); |
533 _isolate_helper._globalState.topEventLoop.run(); | 533 exports._globalState.topEventLoop.run(); |
534 break; | 534 break; |
535 case 'log': | 535 case 'log': |
536 _log(dart.dindex(msg, 'msg')); | 536 _log(dart.dindex(msg, 'msg')); |
537 break; | 537 break; |
538 case 'print': | 538 case 'print': |
539 if (_isolate_helper._globalState.isWorker) { | 539 if (exports._globalState.isWorker) { |
540 _isolate_helper._globalState.mainManager.postMessage(_serializeMessa
ge(dart.map({command: 'print', msg: msg}))); | 540 exports._globalState.mainManager.postMessage(_serializeMessage(dart.
map({command: 'print', msg: msg}))); |
541 } else { | 541 } else { |
542 core.print(dart.dindex(msg, 'msg')); | 542 core.print(dart.dindex(msg, 'msg')); |
543 } | 543 } |
544 break; | 544 break; |
545 case 'error': | 545 case 'error': |
546 throw dart.dindex(msg, 'msg'); | 546 throw dart.dindex(msg, 'msg'); |
547 } | 547 } |
548 } | 548 } |
549 static handleSpawnWorkerRequest(msg) { | 549 static handleSpawnWorkerRequest(msg) { |
550 let replyPort = dart.dindex(msg, 'replyPort'); | 550 let replyPort = dart.dindex(msg, 'replyPort'); |
551 spawn(dart.as(dart.dindex(msg, 'functionName'), core.String), dart.as(dart
.dindex(msg, 'uri'), core.String), dart.as(dart.dindex(msg, 'args'), core.List$(
core.String)), dart.dindex(msg, 'msg'), false, dart.as(dart.dindex(msg, 'isSpawn
Uri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.bool)).then((ms
g) => { | 551 spawn(dart.as(dart.dindex(msg, 'functionName'), core.String), dart.as(dart
.dindex(msg, 'uri'), core.String), dart.as(dart.dindex(msg, 'args'), core.List$(
core.String)), dart.dindex(msg, 'msg'), false, dart.as(dart.dindex(msg, 'isSpawn
Uri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.bool)).then((ms
g) => { |
552 dart.dinvoke(replyPort, 'send', msg); | 552 dart.dinvoke(replyPort, 'send', msg); |
553 }, { | 553 }, { |
554 onError: (errorMessage) => { | 554 onError: (errorMessage) => { |
555 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); | 555 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); |
556 } | 556 } |
557 }); | 557 }); |
558 } | 558 } |
559 static _log(msg) { | 559 static _log(msg) { |
560 if (_isolate_helper._globalState.isWorker) { | 560 if (exports._globalState.isWorker) { |
561 _isolate_helper._globalState.mainManager.postMessage(_serializeMessage(d
art.map({command: 'log', msg: msg}))); | 561 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); |
562 } else { | 562 } else { |
563 try { | 563 try { |
564 _consoleLog(msg); | 564 _consoleLog(msg); |
565 } catch (e) { | 565 } catch (e) { |
566 let trace = dart.stackTrace(e); | 566 let trace = dart.stackTrace(e); |
567 throw new core.Exception(trace); | 567 throw new core.Exception(trace); |
568 } | 568 } |
569 | 569 |
570 } | 570 } |
571 } | 571 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); | 606 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); |
607 port.first.then(((msg) => { | 607 port.first.then(((msg) => { |
608 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { | 608 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { |
609 completer.complete(msg); | 609 completer.complete(msg); |
610 } else { | 610 } else { |
611 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); | 611 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); |
612 completer.completeError(dart.dindex(msg, 1)); | 612 completer.completeError(dart.dindex(msg, 1)); |
613 } | 613 } |
614 }).bind(this)); | 614 }).bind(this)); |
615 let signalReply = port.sendPort; | 615 let signalReply = port.sendPort; |
616 if (dart.notNull(_isolate_helper._globalState.useWorkers) && dart.notNull(
!dart.notNull(isLight))) { | 616 if (dart.notNull(exports._globalState.useWorkers) && dart.notNull(!dart.no
tNull(isLight))) { |
617 _startWorker(functionName, uri, args, message, isSpawnUri, startPaused,
signalReply, ((message) => completer.completeError(message)).bind(this)); | 617 _startWorker(functionName, uri, args, message, isSpawnUri, startPaused,
signalReply, ((message) => completer.completeError(message)).bind(this)); |
618 } else { | 618 } else { |
619 _startNonWorker(functionName, uri, args, message, isSpawnUri, startPause
d, signalReply); | 619 _startNonWorker(functionName, uri, args, message, isSpawnUri, startPause
d, signalReply); |
620 } | 620 } |
621 return completer.future; | 621 return completer.future; |
622 } | 622 } |
623 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 623 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { |
624 if (args !== null) | 624 if (args !== null) |
625 args = new core.List.from(args); | 625 args = new core.List.from(args); |
626 if (_isolate_helper._globalState.isWorker) { | 626 if (exports._globalState.isWorker) { |
627 _isolate_helper._globalState.mainManager.postMessage(_serializeMessage(d
art.map({command: 'spawn-worker', functionName: functionName, args: args, msg: m
essage, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: r
eplyPort}))); | 627 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); |
628 } else { | 628 } else { |
629 _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
replyPort, onError); | 629 _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
replyPort, onError); |
630 } | 630 } |
631 } | 631 } |
632 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { | 632 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { |
633 if (uri !== null) { | 633 if (uri !== null) { |
634 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); | 634 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); |
635 } | 635 } |
636 message = _clone(message); | 636 message = _clone(message); |
637 if (args !== null) | 637 if (args !== null) |
638 args = new core.List.from(args); | 638 args = new core.List.from(args); |
639 _isolate_helper._globalState.topEventLoop.enqueue(new _IsolateContext(), (
) => { | 639 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { |
640 let func = _getJSFunctionFromName(functionName); | 640 let func = _getJSFunctionFromName(functionName); |
641 _startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, s
tartPaused, replyPort); | 641 _startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, s
tartPaused, replyPort); |
642 }, 'nonworker start'); | 642 }, 'nonworker start'); |
643 } | 643 } |
644 static get currentIsolate() { | 644 static get currentIsolate() { |
645 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 645 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
646 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); | 646 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
647 } | 647 } |
648 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { | 648 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { |
649 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 649 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
650 _js_helper.Primitives.initializeStatics(context.id); | 650 _js_helper.Primitives.initializeStatics(context.id); |
651 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); | 651 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); |
652 // Function runStartFunction: () → void | 652 // Function runStartFunction: () → void |
653 function runStartFunction() { | 653 function runStartFunction() { |
654 context.initialized = true; | 654 context.initialized = true; |
655 if (!dart.notNull(isSpawnUri)) { | 655 if (!dart.notNull(isSpawnUri)) { |
656 dart.dinvokef(topLevel, message); | 656 dart.dinvokef(topLevel, message); |
657 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { | 657 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { |
658 dart.dinvokef(topLevel, args, message); | 658 dart.dinvokef(topLevel, args, message); |
659 } else if (dart.is(topLevel, _MainFunctionArgs)) { | 659 } else if (dart.is(topLevel, _MainFunctionArgs)) { |
660 dart.dinvokef(topLevel, args); | 660 dart.dinvokef(topLevel, args); |
661 } else { | 661 } else { |
662 dart.dinvokef(topLevel); | 662 dart.dinvokef(topLevel); |
663 } | 663 } |
664 } | 664 } |
665 if (startPaused) { | 665 if (startPaused) { |
666 context.addPause(context.pauseCapability, context.pauseCapability); | 666 context.addPause(context.pauseCapability, context.pauseCapability); |
667 _isolate_helper._globalState.topEventLoop.enqueue(context, runStartFunct
ion, 'start isolate'); | 667 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); |
668 } else { | 668 } else { |
669 runStartFunction(); | 669 runStartFunction(); |
670 } | 670 } |
671 } | 671 } |
672 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 672 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { |
673 if (uri === null) | 673 if (uri === null) |
674 uri = thisScript; | 674 uri = thisScript; |
675 let worker = new Worker(uri); | 675 let worker = new Worker(uri); |
676 let onerrorTrampoline = function(f, u, c) { | 676 let onerrorTrampoline = function(f, u, c) { |
677 return function(e) { | 677 return function(e) { |
678 return f(e, u, c); | 678 return f(e, u, c); |
679 }; | 679 }; |
680 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError); | 680 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError); |
681 worker.onerror = onerrorTrampoline; | 681 worker.onerror = onerrorTrampoline; |
682 let processWorkerMessageTrampoline = function(f, a) { | 682 let processWorkerMessageTrampoline = function(f, a) { |
683 return function(e) { | 683 return function(e) { |
684 e.onerror = null; | 684 e.onerror = null; |
685 return f(a, e); | 685 return f(a, e); |
686 }; | 686 }; |
687 }(_foreign_helper.DART_CLOSURE_TO_JS(_processWorkerMessage), worker); | 687 }(_foreign_helper.DART_CLOSURE_TO_JS(_processWorkerMessage), worker); |
688 worker.onmessage = processWorkerMessageTrampoline; | 688 worker.onmessage = processWorkerMessageTrampoline; |
689 let workerId = _isolate_helper._globalState.nextManagerId++; | 689 let workerId = exports._globalState.nextManagerId++; |
690 workerIds.set(worker, workerId); | 690 workerIds.set(worker, workerId); |
691 _isolate_helper._globalState.managers.set(workerId, worker); | 691 exports._globalState.managers.set(workerId, worker); |
692 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); | 692 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); |
693 } | 693 } |
694 static workerOnError(event, uri, onError) { | 694 static workerOnError(event, uri, onError) { |
695 event.preventDefault(); | 695 event.preventDefault(); |
696 let message = dart.as(event.message, core.String); | 696 let message = dart.as(event.message, core.String); |
697 if (message === null) { | 697 if (message === null) { |
698 message = `Error spawning worker for ${uri}`; | 698 message = `Error spawning worker for ${uri}`; |
699 } else { | 699 } else { |
700 message = `Error spawning worker for ${uri} (${message})`; | 700 message = `Error spawning worker for ${uri} (${message})`; |
701 } | 701 } |
(...skipping 20 matching lines...) Expand all Loading... |
722 throw new core.Exception("SendPort.send: Illegal replyTo port type"); | 722 throw new core.Exception("SendPort.send: Illegal replyTo port type"); |
723 } | 723 } |
724 } | 724 } |
725 } | 725 } |
726 class _NativeJsSendPort extends _BaseSendPort { | 726 class _NativeJsSendPort extends _BaseSendPort { |
727 _NativeJsSendPort(_receivePort, isolateId) { | 727 _NativeJsSendPort(_receivePort, isolateId) { |
728 this._receivePort = _receivePort; | 728 this._receivePort = _receivePort; |
729 super._BaseSendPort(isolateId); | 729 super._BaseSendPort(isolateId); |
730 } | 730 } |
731 send(message) { | 731 send(message) { |
732 let isolate = _isolate_helper._globalState.isolates.get(this._isolateId); | 732 let isolate = exports._globalState.isolates.get(this._isolateId); |
733 if (isolate === null) | 733 if (isolate === null) |
734 return; | 734 return; |
735 if (this._receivePort._isClosed) | 735 if (this._receivePort._isClosed) |
736 return; | 736 return; |
737 let msg = _clone(message); | 737 let msg = _clone(message); |
738 if (dart.equals(isolate.controlPort, this._receivePort)) { | 738 if (dart.equals(isolate.controlPort, this._receivePort)) { |
739 isolate.handleControlMessage(msg); | 739 isolate.handleControlMessage(msg); |
740 return; | 740 return; |
741 } | 741 } |
742 _isolate_helper._globalState.topEventLoop.enqueue(isolate, (() => { | 742 exports._globalState.topEventLoop.enqueue(isolate, (() => { |
743 if (!dart.notNull(this._receivePort._isClosed)) { | 743 if (!dart.notNull(this._receivePort._isClosed)) { |
744 this._receivePort._add(msg); | 744 this._receivePort._add(msg); |
745 } | 745 } |
746 }).bind(this), `receive ${message}`); | 746 }).bind(this), `receive ${message}`); |
747 } | 747 } |
748 ['=='](other) { | 748 ['=='](other) { |
749 return dart.notNull(dart.is(other, _NativeJsSendPort)) && dart.notNull(dar
t.equals(this._receivePort, dart.dload(other, '_receivePort'))); | 749 return dart.notNull(dart.is(other, _NativeJsSendPort)) && dart.notNull(dar
t.equals(this._receivePort, dart.dload(other, '_receivePort'))); |
750 } | 750 } |
751 get hashCode() { | 751 get hashCode() { |
752 return this._receivePort._id; | 752 return this._receivePort._id; |
753 } | 753 } |
754 } | 754 } |
755 class _WorkerSendPort extends _BaseSendPort { | 755 class _WorkerSendPort extends _BaseSendPort { |
756 _WorkerSendPort(_workerId, isolateId, _receivePortId) { | 756 _WorkerSendPort(_workerId, isolateId, _receivePortId) { |
757 this._workerId = _workerId; | 757 this._workerId = _workerId; |
758 this._receivePortId = _receivePortId; | 758 this._receivePortId = _receivePortId; |
759 super._BaseSendPort(isolateId); | 759 super._BaseSendPort(isolateId); |
760 } | 760 } |
761 send(message) { | 761 send(message) { |
762 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); | 762 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); |
763 if (_isolate_helper._globalState.isWorker) { | 763 if (exports._globalState.isWorker) { |
764 _isolate_helper._globalState.mainManager.postMessage(workerMessage); | 764 exports._globalState.mainManager.postMessage(workerMessage); |
765 } else { | 765 } else { |
766 let manager = _isolate_helper._globalState.managers.get(this._workerId); | 766 let manager = exports._globalState.managers.get(this._workerId); |
767 if (manager !== null) { | 767 if (manager !== null) { |
768 manager.postMessage(workerMessage); | 768 manager.postMessage(workerMessage); |
769 } | 769 } |
770 } | 770 } |
771 } | 771 } |
772 ['=='](other) { | 772 ['=='](other) { |
773 return dart.notNull(dart.notNull(dart.notNull(dart.is(other, _WorkerSendPo
rt)) && dart.notNull(this._workerId === dart.dload(other, '_workerId'))) && dart
.notNull(this._isolateId === dart.dload(other, '_isolateId'))) && dart.notNull(t
his._receivePortId === dart.dload(other, '_receivePortId')); | 773 return dart.notNull(dart.notNull(dart.notNull(dart.is(other, _WorkerSendPo
rt)) && dart.notNull(this._workerId === dart.dload(other, '_workerId'))) && dart
.notNull(this._isolateId === dart.dload(other, '_isolateId'))) && dart.notNull(t
his._receivePortId === dart.dload(other, '_receivePortId')); |
774 } | 774 } |
775 get hashCode() { | 775 get hashCode() { |
776 return this._workerId << 16 ^ this._isolateId << 8 ^ this._receivePortId; | 776 return this._workerId << 16 ^ this._isolateId << 8 ^ this._receivePortId; |
777 } | 777 } |
778 } | 778 } |
779 class RawReceivePortImpl extends dart.Object { | 779 class RawReceivePortImpl extends dart.Object { |
780 RawReceivePortImpl(_handler) { | 780 RawReceivePortImpl(_handler) { |
781 this._handler = _handler; | 781 this._handler = _handler; |
782 this._id = _nextFreeId++; | 782 this._id = _nextFreeId++; |
783 this._isClosed = false; | 783 this._isClosed = false; |
784 _isolate_helper._globalState.currentContext.register(this._id, this); | 784 exports._globalState.currentContext.register(this._id, this); |
785 } | 785 } |
786 RawReceivePortImpl$weak(_handler) { | 786 RawReceivePortImpl$weak(_handler) { |
787 this._handler = _handler; | 787 this._handler = _handler; |
788 this._id = _nextFreeId++; | 788 this._id = _nextFreeId++; |
789 this._isClosed = false; | 789 this._isClosed = false; |
790 _isolate_helper._globalState.currentContext.registerWeak(this._id, this); | 790 exports._globalState.currentContext.registerWeak(this._id, this); |
791 } | 791 } |
792 RawReceivePortImpl$_controlPort() { | 792 RawReceivePortImpl$_controlPort() { |
793 this._handler = null; | 793 this._handler = null; |
794 this._id = 0; | 794 this._id = 0; |
795 this._isClosed = false; | 795 this._isClosed = false; |
796 } | 796 } |
797 set handler(newHandler) { | 797 set handler(newHandler) { |
798 this._handler = newHandler; | 798 this._handler = newHandler; |
799 } | 799 } |
800 _close() { | 800 _close() { |
801 this._isClosed = true; | 801 this._isClosed = true; |
802 this._handler = null; | 802 this._handler = null; |
803 } | 803 } |
804 close() { | 804 close() { |
805 if (this._isClosed) | 805 if (this._isClosed) |
806 return; | 806 return; |
807 this._isClosed = true; | 807 this._isClosed = true; |
808 this._handler = null; | 808 this._handler = null; |
809 _isolate_helper._globalState.currentContext.unregister(this._id); | 809 exports._globalState.currentContext.unregister(this._id); |
810 } | 810 } |
811 _add(dataEvent) { | 811 _add(dataEvent) { |
812 if (this._isClosed) | 812 if (this._isClosed) |
813 return; | 813 return; |
814 dart.dinvokef(this._handler, dataEvent); | 814 dart.dinvokef(this._handler, dataEvent); |
815 } | 815 } |
816 get sendPort() { | 816 get sendPort() { |
817 return new _NativeJsSendPort(this, _isolate_helper._globalState.currentCon
text.id); | 817 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; |
818 } | 818 } |
819 } | 819 } |
820 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); | 820 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); |
821 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); | 821 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); |
822 RawReceivePortImpl._nextFreeId = 1; | 822 RawReceivePortImpl._nextFreeId = 1; |
823 class ReceivePortImpl extends async.Stream { | 823 class ReceivePortImpl extends async.Stream { |
824 ReceivePortImpl() { | 824 ReceivePortImpl() { |
825 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); | 825 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); |
826 } | 826 } |
827 ReceivePortImpl$weak() { | 827 ReceivePortImpl$weak() { |
(...skipping 20 matching lines...) Expand all Loading... |
848 return this._rawPort.sendPort; | 848 return this._rawPort.sendPort; |
849 } | 849 } |
850 } | 850 } |
851 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); | 851 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); |
852 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); | 852 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); |
853 class TimerImpl extends dart.Object { | 853 class TimerImpl extends dart.Object { |
854 TimerImpl(milliseconds, callback) { | 854 TimerImpl(milliseconds, callback) { |
855 this._once = true; | 855 this._once = true; |
856 this._inEventLoop = false; | 856 this._inEventLoop = false; |
857 this._handle = dart.as(null, core.int); | 857 this._handle = dart.as(null, core.int); |
858 if (dart.notNull(milliseconds === 0) && dart.notNull(dart.notNull(!dart.no
tNull(hasTimer())) || dart.notNull(_isolate_helper._globalState.isWorker))) { | 858 if (dart.notNull(milliseconds === 0) && dart.notNull(dart.notNull(!dart.no
tNull(hasTimer())) || dart.notNull(exports._globalState.isWorker))) { |
859 // Function internalCallback: () → void | 859 // Function internalCallback: () → void |
860 function internalCallback() { | 860 function internalCallback() { |
861 this._handle = dart.as(null, core.int); | 861 this._handle = dart.as(null, core.int); |
862 callback(); | 862 callback(); |
863 } | 863 } |
864 this._handle = 1; | 864 this._handle = 1; |
865 _isolate_helper._globalState.topEventLoop.enqueue(_isolate_helper._globa
lState.currentContext, internalCallback, 'timer'); | 865 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); |
866 this._inEventLoop = true; | 866 this._inEventLoop = true; |
867 } else if (hasTimer()) { | 867 } else if (hasTimer()) { |
868 // Function internalCallback: () → void | 868 // Function internalCallback: () → void |
869 function internalCallback() { | 869 function internalCallback() { |
870 this._handle = dart.as(null, core.int); | 870 this._handle = dart.as(null, core.int); |
871 leaveJsAsync(); | 871 leaveJsAsync(); |
872 callback(); | 872 callback(); |
873 } | 873 } |
874 enterJsAsync(); | 874 enterJsAsync(); |
875 this._handle = self.setTimeout(_js_helper.convertDartClosureToJS(interna
lCallback, 0), milliseconds); | 875 this._handle = self.setTimeout(_js_helper.convertDartClosureToJS(interna
lCallback, 0), milliseconds); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 return new List.from(['js-object', keys, values]); | 1065 return new List.from(['js-object', keys, values]); |
1066 } | 1066 } |
1067 serializeWorkerSendPort(x) { | 1067 serializeWorkerSendPort(x) { |
1068 if (this._serializeSendPorts) { | 1068 if (this._serializeSendPorts) { |
1069 return new List.from(['sendport', x._workerId, x._isolateId, x._receiveP
ortId]); | 1069 return new List.from(['sendport', x._workerId, x._isolateId, x._receiveP
ortId]); |
1070 } | 1070 } |
1071 return new List.from(['raw sendport', x]); | 1071 return new List.from(['raw sendport', x]); |
1072 } | 1072 } |
1073 serializeJsSendPort(x) { | 1073 serializeJsSendPort(x) { |
1074 if (this._serializeSendPorts) { | 1074 if (this._serializeSendPorts) { |
1075 let workerId = _isolate_helper._globalState.currentManagerId; | 1075 let workerId = exports._globalState.currentManagerId; |
1076 return new List.from(['sendport', workerId, x._isolateId, x._receivePort
._id]); | 1076 return new List.from(['sendport', workerId, x._isolateId, x._receivePort
._id]); |
1077 } | 1077 } |
1078 return new List.from(['raw sendport', x]); | 1078 return new List.from(['raw sendport', x]); |
1079 } | 1079 } |
1080 serializeCapability(x) { | 1080 serializeCapability(x) { |
1081 return new List.from(['capability', x._id]); | 1081 return new List.from(['capability', x._id]); |
1082 } | 1082 } |
1083 serializeClosure(x) { | 1083 serializeClosure(x) { |
1084 let name = IsolateNatives._getJSFunctionName(x); | 1084 let name = IsolateNatives._getJSFunctionName(x); |
1085 if (name === null) { | 1085 if (name === null) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 result.set(keys.get(i), this.deserialize(values.get(i))); | 1201 result.set(keys.get(i), this.deserialize(values.get(i))); |
1202 } | 1202 } |
1203 return result; | 1203 return result; |
1204 } | 1204 } |
1205 deserializeSendPort(x) { | 1205 deserializeSendPort(x) { |
1206 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); | 1206 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); |
1207 let managerId = dart.as(dart.dindex(x, 1), core.int); | 1207 let managerId = dart.as(dart.dindex(x, 1), core.int); |
1208 let isolateId = dart.as(dart.dindex(x, 2), core.int); | 1208 let isolateId = dart.as(dart.dindex(x, 2), core.int); |
1209 let receivePortId = dart.as(dart.dindex(x, 3), core.int); | 1209 let receivePortId = dart.as(dart.dindex(x, 3), core.int); |
1210 let result = null; | 1210 let result = null; |
1211 if (managerId === _isolate_helper._globalState.currentManagerId) { | 1211 if (managerId === exports._globalState.currentManagerId) { |
1212 let isolate = _isolate_helper._globalState.isolates.get(isolateId); | 1212 let isolate = exports._globalState.isolates.get(isolateId); |
1213 if (isolate === null) | 1213 if (isolate === null) |
1214 return null; | 1214 return null; |
1215 let receivePort = isolate.lookup(receivePortId); | 1215 let receivePort = isolate.lookup(receivePortId); |
1216 if (receivePort === null) | 1216 if (receivePort === null) |
1217 return null; | 1217 return null; |
1218 result = new _NativeJsSendPort(receivePort, isolateId); | 1218 result = new _NativeJsSendPort(receivePort, isolateId); |
1219 } else { | 1219 } else { |
1220 result = new _WorkerSendPort(managerId, isolateId, receivePortId); | 1220 result = new _WorkerSendPort(managerId, isolateId, receivePortId); |
1221 } | 1221 } |
1222 this.deserializedObjects.add(result); | 1222 this.deserializedObjects.add(result); |
(...skipping 29 matching lines...) Expand all Loading... |
1252 let fields = dart.as(dart.dindex(x, 2), core.List); | 1252 let fields = dart.as(dart.dindex(x, 2), core.List); |
1253 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_
js_embedded_names.INSTANCE_FROM_CLASS_ID, core.String)); | 1253 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_
js_embedded_names.INSTANCE_FROM_CLASS_ID, core.String)); |
1254 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_
embedded_names.INITIALIZE_EMPTY_INSTANCE, core.String)); | 1254 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_
embedded_names.INITIALIZE_EMPTY_INSTANCE, core.String)); |
1255 let emptyInstance = instanceFromClassId(classId); | 1255 let emptyInstance = instanceFromClassId(classId); |
1256 this.deserializedObjects.add(emptyInstance); | 1256 this.deserializedObjects.add(emptyInstance); |
1257 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray)); | 1257 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray)); |
1258 return initializeObject(classId, emptyInstance, fields); | 1258 return initializeObject(classId, emptyInstance, fields); |
1259 } | 1259 } |
1260 } | 1260 } |
1261 // Exports: | 1261 // Exports: |
1262 _isolate_helper.enterJsAsync = enterJsAsync; | 1262 exports.enterJsAsync = enterJsAsync; |
1263 _isolate_helper.leaveJsAsync = leaveJsAsync; | 1263 exports.leaveJsAsync = leaveJsAsync; |
1264 _isolate_helper.isWorker = isWorker; | 1264 exports.isWorker = isWorker; |
1265 _isolate_helper.startRootIsolate = startRootIsolate; | 1265 exports.startRootIsolate = startRootIsolate; |
1266 _isolate_helper.globalWindow = globalWindow; | 1266 exports.globalWindow = globalWindow; |
1267 _isolate_helper.globalWorker = globalWorker; | 1267 exports.globalWorker = globalWorker; |
1268 _isolate_helper.globalPostMessageDefined = globalPostMessageDefined; | 1268 exports.globalPostMessageDefined = globalPostMessageDefined; |
1269 _isolate_helper.IsolateNatives = IsolateNatives; | 1269 exports.IsolateNatives = IsolateNatives; |
1270 _isolate_helper.RawReceivePortImpl = RawReceivePortImpl; | 1270 exports.RawReceivePortImpl = RawReceivePortImpl; |
1271 _isolate_helper.ReceivePortImpl = ReceivePortImpl; | 1271 exports.ReceivePortImpl = ReceivePortImpl; |
1272 _isolate_helper.TimerImpl = TimerImpl; | 1272 exports.TimerImpl = TimerImpl; |
1273 _isolate_helper.hasTimer = hasTimer; | 1273 exports.hasTimer = hasTimer; |
1274 _isolate_helper.CapabilityImpl = CapabilityImpl; | 1274 exports.CapabilityImpl = CapabilityImpl; |
1275 })(_isolate_helper || (_isolate_helper = {})); | 1275 })(_isolate_helper || (_isolate_helper = {})); |
OLD | NEW |