OLD | NEW |
1 var _isolate_helper; | 1 var _isolate_helper; |
2 (function(exports) { | 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 exports._globalState.topEventLoop.run(); | 7 exports._globalState.topEventLoop.run(); |
8 return result; | 8 return result; |
9 } | 9 } |
| 10 let _activeJsAsyncCount = Symbol('_activeJsAsyncCount'); |
10 // Function enterJsAsync: () → dynamic | 11 // Function enterJsAsync: () → dynamic |
11 function enterJsAsync() { | 12 function enterJsAsync() { |
12 exports._globalState.topEventLoop._activeJsAsyncCount++; | 13 exports._globalState.topEventLoop[_activeJsAsyncCount]++; |
13 } | 14 } |
14 // Function leaveJsAsync: () → dynamic | 15 // Function leaveJsAsync: () → dynamic |
15 function leaveJsAsync() { | 16 function leaveJsAsync() { |
16 exports._globalState.topEventLoop._activeJsAsyncCount--; | 17 exports._globalState.topEventLoop[_activeJsAsyncCount]--; |
17 dart.assert(exports._globalState.topEventLoop._activeJsAsyncCount >= 0); | 18 dart.assert(exports._globalState.topEventLoop[_activeJsAsyncCount] >= 0); |
18 } | 19 } |
19 // Function isWorker: () → bool | 20 // Function isWorker: () → bool |
20 function isWorker() { | 21 function isWorker() { |
21 return exports._globalState.isWorker; | 22 return exports._globalState.isWorker; |
22 } | 23 } |
23 // Function _currentIsolate: () → _IsolateContext | 24 // Function _currentIsolate: () → _IsolateContext |
24 function _currentIsolate() { | 25 function _currentIsolate() { |
25 return exports._globalState.currentContext; | 26 return exports._globalState.currentContext; |
26 } | 27 } |
27 // Function startRootIsolate: (dynamic, dynamic) → void | 28 // Function startRootIsolate: (dynamic, dynamic) → void |
(...skipping 24 matching lines...) Expand all Loading... |
52 exports._globalState.topEventLoop.run(); | 53 exports._globalState.topEventLoop.run(); |
53 } | 54 } |
54 dart.copyProperties(exports, { | 55 dart.copyProperties(exports, { |
55 get _globalState() { | 56 get _globalState() { |
56 return dart.as(init.globalState, _Manager); | 57 return dart.as(init.globalState, _Manager); |
57 }, | 58 }, |
58 set _globalState(val) { | 59 set _globalState(val) { |
59 init.globalState = val; | 60 init.globalState = val; |
60 } | 61 } |
61 }); | 62 }); |
| 63 let _nativeDetectEnvironment = Symbol('_nativeDetectEnvironment'); |
| 64 let _nativeInitWorkerMessageHandler = Symbol('_nativeInitWorkerMessageHandler'
); |
| 65 let _processWorkerMessage = Symbol('_processWorkerMessage'); |
| 66 let _serializePrintMessage = Symbol('_serializePrintMessage'); |
62 class _Manager extends dart.Object { | 67 class _Manager extends dart.Object { |
63 get useWorkers() { | 68 get useWorkers() { |
64 return this.supportsWorkers; | 69 return this.supportsWorkers; |
65 } | 70 } |
66 _Manager(entry) { | 71 _Manager(entry) { |
67 this.entry = entry; | 72 this.entry = entry; |
68 this.nextIsolateId = 0; | 73 this.nextIsolateId = 0; |
69 this.currentManagerId = 0; | 74 this.currentManagerId = 0; |
70 this.nextManagerId = 1; | 75 this.nextManagerId = 1; |
71 this.currentContext = null; | 76 this.currentContext = null; |
72 this.rootContext = null; | 77 this.rootContext = null; |
73 this.topEventLoop = null; | 78 this.topEventLoop = null; |
74 this.fromCommandLine = null; | 79 this.fromCommandLine = null; |
75 this.isWorker = null; | 80 this.isWorker = null; |
76 this.supportsWorkers = null; | 81 this.supportsWorkers = null; |
77 this.isolates = null; | 82 this.isolates = null; |
78 this.mainManager = null; | 83 this.mainManager = null; |
79 this.managers = null; | 84 this.managers = null; |
80 this._nativeDetectEnvironment(); | 85 this[_nativeDetectEnvironment](); |
81 this.topEventLoop = new _EventLoop(); | 86 this.topEventLoop = new _EventLoop(); |
82 this.isolates = new core.Map(); | 87 this.isolates = new core.Map(); |
83 this.managers = new core.Map(); | 88 this.managers = new core.Map(); |
84 if (this.isWorker) { | 89 if (this.isWorker) { |
85 this.mainManager = new _MainManagerStub(); | 90 this.mainManager = new _MainManagerStub(); |
86 this._nativeInitWorkerMessageHandler(); | 91 this[_nativeInitWorkerMessageHandler](); |
87 } | 92 } |
88 } | 93 } |
89 _nativeDetectEnvironment() { | 94 [_nativeDetectEnvironment]() { |
90 let isWindowDefined = exports.globalWindow !== null; | 95 let isWindowDefined = exports.globalWindow !== null; |
91 let isWorkerDefined = exports.globalWorker !== null; | 96 let isWorkerDefined = exports.globalWorker !== null; |
92 this.isWorker = dart.notNull(!dart.notNull(isWindowDefined)) && dart.notNu
ll(exports.globalPostMessageDefined); | 97 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)); | 98 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)); | 99 this.fromCommandLine = dart.notNull(!dart.notNull(isWindowDefined)) && dar
t.notNull(!dart.notNull(this.isWorker)); |
95 } | 100 } |
96 _nativeInitWorkerMessageHandler() { | 101 [_nativeInitWorkerMessageHandler]() { |
97 let function = function(f, a) { | 102 let function = function(f, a) { |
98 return function(e) { | 103 return function(e) { |
99 f(a, e); | 104 f(a, e); |
100 }; | 105 }; |
101 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage)
, this.mainManager); | 106 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), this.mainManager); |
102 self.onmessage = function; | 107 self.onmessage = function; |
103 self.dartPrint = self.dartPrint || function(serialize) { | 108 self.dartPrint = self.dartPrint || function(serialize) { |
104 return function(object) { | 109 return function(object) { |
105 if (self.console && self.console.log) { | 110 if (self.console && self.console.log) { |
106 self.console.log(object); | 111 self.console.log(object); |
107 } else { | 112 } else { |
108 self.postMessage(serialize(object)); | 113 self.postMessage(serialize(object)); |
109 } | 114 } |
110 }; | 115 }; |
111 }(_foreign_helper.DART_CLOSURE_TO_JS(_serializePrintMessage)); | 116 }(_foreign_helper.DART_CLOSURE_TO_JS(_serializePrintMessage)); |
112 } | 117 } |
113 static _serializePrintMessage(object) { | 118 static [_serializePrintMessage](object) { |
114 return _serializeMessage(dart.map({command: "print", msg: object})); | 119 return _serializeMessage(dart.map({command: "print", msg: object})); |
115 } | 120 } |
116 maybeCloseWorker() { | 121 maybeCloseWorker() { |
117 if (dart.notNull(dart.notNull(this.isWorker) && dart.notNull(this.isolates
.isEmpty)) && dart.notNull(this.topEventLoop._activeJsAsyncCount === 0)) { | 122 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
'}))); | 123 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); |
119 } | 124 } |
120 } | 125 } |
121 } | 126 } |
| 127 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); |
| 128 let _isExecutingEvent = Symbol('_isExecutingEvent'); |
| 129 let _id = Symbol('_id'); |
| 130 let _updateGlobalState = Symbol('_updateGlobalState'); |
| 131 let _setGlobals = Symbol('_setGlobals'); |
| 132 let _addRegistration = Symbol('_addRegistration'); |
122 class _IsolateContext extends dart.Object { | 133 class _IsolateContext extends dart.Object { |
123 _IsolateContext() { | 134 _IsolateContext() { |
124 this.id = exports._globalState.nextIsolateId++; | 135 this.id = exports._globalState.nextIsolateId++; |
125 this.ports = new core.Map(); | 136 this.ports = new core.Map(); |
126 this.weakPorts = new core.Set(); | 137 this.weakPorts = new core.Set(); |
127 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); | 138 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); |
128 this.controlPort = new RawReceivePortImpl._controlPort(); | 139 this.controlPort = new RawReceivePortImpl._controlPort(); |
129 this.pauseCapability = new isolate.Capability(); | 140 this.pauseCapability = new isolate.Capability(); |
130 this.terminateCapability = new isolate.Capability(); | 141 this.terminateCapability = new isolate.Capability(); |
131 this.delayedEvents = dart.as(new List.from([]), core.List$(_IsolateEvent))
; | 142 this.delayedEvents = dart.as(new List.from([]), core.List$(_IsolateEvent))
; |
132 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability)); | 143 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability)); |
133 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort)); | 144 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort)); |
134 this.initialized = false; | 145 this.initialized = false; |
135 this.isPaused = false; | 146 this.isPaused = false; |
136 this.doneHandlers = null; | 147 this.doneHandlers = null; |
137 this._scheduledControlEvents = null; | 148 this[_scheduledControlEvents] = null; |
138 this._isExecutingEvent = false; | 149 this[_isExecutingEvent] = false; |
139 this.errorsAreFatal = true; | 150 this.errorsAreFatal = true; |
140 this.registerWeak(this.controlPort._id, this.controlPort); | 151 this.registerWeak(this.controlPort[_id], this.controlPort); |
141 } | 152 } |
142 addPause(authentification, resume) { | 153 addPause(authentification, resume) { |
143 if (!dart.equals(this.pauseCapability, authentification)) | 154 if (!dart.equals(this.pauseCapability, authentification)) |
144 return; | 155 return; |
145 if (dart.notNull(this.pauseTokens.add(resume)) && dart.notNull(!dart.notNu
ll(this.isPaused))) { | 156 if (dart.notNull(this.pauseTokens.add(resume)) && dart.notNull(!dart.notNu
ll(this.isPaused))) { |
146 this.isPaused = true; | 157 this.isPaused = true; |
147 } | 158 } |
148 this._updateGlobalState(); | 159 this[_updateGlobalState](); |
149 } | 160 } |
150 removePause(resume) { | 161 removePause(resume) { |
151 if (!dart.notNull(this.isPaused)) | 162 if (!dart.notNull(this.isPaused)) |
152 return; | 163 return; |
153 this.pauseTokens.remove(resume); | 164 this.pauseTokens.remove(resume); |
154 if (this.pauseTokens.isEmpty) { | 165 if (this.pauseTokens.isEmpty) { |
155 while (this.delayedEvents.isNotEmpty) { | 166 while (this.delayedEvents.isNotEmpty) { |
156 let event = this.delayedEvents.removeLast(); | 167 let event = this.delayedEvents.removeLast(); |
157 exports._globalState.topEventLoop.prequeue(event); | 168 exports._globalState.topEventLoop.prequeue(event); |
158 } | 169 } |
159 this.isPaused = false; | 170 this.isPaused = false; |
160 } | 171 } |
161 this._updateGlobalState(); | 172 this[_updateGlobalState](); |
162 } | 173 } |
163 addDoneListener(responsePort) { | 174 addDoneListener(responsePort) { |
164 if (this.doneHandlers === null) { | 175 if (this.doneHandlers === null) { |
165 this.doneHandlers = new List.from([]); | 176 this.doneHandlers = new List.from([]); |
166 } | 177 } |
167 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) | 178 if (dart.dinvoke(this.doneHandlers, 'contains', responsePort)) |
168 return; | 179 return; |
169 dart.dinvoke(this.doneHandlers, 'add', responsePort); | 180 dart.dinvoke(this.doneHandlers, 'add', responsePort); |
170 } | 181 } |
171 removeDoneListener(responsePort) { | 182 removeDoneListener(responsePort) { |
172 if (this.doneHandlers === null) | 183 if (this.doneHandlers === null) |
173 return; | 184 return; |
174 dart.dinvoke(this.doneHandlers, 'remove', responsePort); | 185 dart.dinvoke(this.doneHandlers, 'remove', responsePort); |
175 } | 186 } |
176 setErrorsFatal(authentification, errorsAreFatal) { | 187 setErrorsFatal(authentification, errorsAreFatal) { |
177 if (!dart.equals(this.terminateCapability, authentification)) | 188 if (!dart.equals(this.terminateCapability, authentification)) |
178 return; | 189 return; |
179 this.errorsAreFatal = errorsAreFatal; | 190 this.errorsAreFatal = errorsAreFatal; |
180 } | 191 } |
181 handlePing(responsePort, pingType) { | 192 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)))) { | 193 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); | 194 responsePort.send(null); |
184 return; | 195 return; |
185 } | 196 } |
186 // Function respond: () → void | 197 // Function respond: () → void |
187 function respond() { | 198 function respond() { |
188 responsePort.send(null); | 199 responsePort.send(null); |
189 } | 200 } |
190 if (pingType === isolate.Isolate.AS_EVENT) { | 201 if (pingType === isolate.Isolate.AS_EVENT) { |
191 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); | 202 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); |
192 return; | 203 return; |
193 } | 204 } |
194 dart.assert(pingType === isolate.Isolate.BEFORE_NEXT_EVENT); | 205 dart.assert(pingType === isolate.Isolate.BEFORE_NEXT_EVENT); |
195 if (this._scheduledControlEvents === null) { | 206 if (this[_scheduledControlEvents] === null) { |
196 this._scheduledControlEvents = new collection.Queue(); | 207 this[_scheduledControlEvents] = new collection.Queue(); |
197 } | 208 } |
198 dart.dinvoke(this._scheduledControlEvents, 'addLast', respond); | 209 dart.dinvoke(this[_scheduledControlEvents], 'addLast', respond); |
199 } | 210 } |
200 handleKill(authentification, priority) { | 211 handleKill(authentification, priority) { |
201 if (!dart.equals(this.terminateCapability, authentification)) | 212 if (!dart.equals(this.terminateCapability, authentification)) |
202 return; | 213 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)))) { | 214 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(); | 215 this.kill(); |
205 return; | 216 return; |
206 } | 217 } |
207 if (priority === isolate.Isolate.AS_EVENT) { | 218 if (priority === isolate.Isolate.AS_EVENT) { |
208 exports._globalState.topEventLoop.enqueue(this, this.kill, "kill"); | 219 exports._globalState.topEventLoop.enqueue(this, this.kill, "kill"); |
209 return; | 220 return; |
210 } | 221 } |
211 dart.assert(priority === isolate.Isolate.BEFORE_NEXT_EVENT); | 222 dart.assert(priority === isolate.Isolate.BEFORE_NEXT_EVENT); |
212 if (this._scheduledControlEvents === null) { | 223 if (this[_scheduledControlEvents] === null) { |
213 this._scheduledControlEvents = new collection.Queue(); | 224 this[_scheduledControlEvents] = new collection.Queue(); |
214 } | 225 } |
215 dart.dinvoke(this._scheduledControlEvents, 'addLast', this.kill); | 226 dart.dinvoke(this[_scheduledControlEvents], 'addLast', this.kill); |
216 } | 227 } |
217 addErrorListener(port) { | 228 addErrorListener(port) { |
218 this.errorPorts.add(port); | 229 this.errorPorts.add(port); |
219 } | 230 } |
220 removeErrorListener(port) { | 231 removeErrorListener(port) { |
221 this.errorPorts.remove(port); | 232 this.errorPorts.remove(port); |
222 } | 233 } |
223 handleUncaughtError(error, stackTrace) { | 234 handleUncaughtError(error, stackTrace) { |
224 if (this.errorPorts.isEmpty) { | 235 if (this.errorPorts.isEmpty) { |
225 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { | 236 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { |
(...skipping 12 matching lines...) Expand all Loading... |
238 message.set(0, dart.dinvoke(error, 'toString')); | 249 message.set(0, dart.dinvoke(error, 'toString')); |
239 message.set(1, stackTrace === null ? null : stackTrace.toString()); | 250 message.set(1, stackTrace === null ? null : stackTrace.toString()); |
240 for (let port of this.errorPorts) | 251 for (let port of this.errorPorts) |
241 port.send(message); | 252 port.send(message); |
242 } | 253 } |
243 eval(code) { | 254 eval(code) { |
244 let old = exports._globalState.currentContext; | 255 let old = exports._globalState.currentContext; |
245 exports._globalState.currentContext = this; | 256 exports._globalState.currentContext = this; |
246 this._setGlobals(); | 257 this._setGlobals(); |
247 let result = null; | 258 let result = null; |
248 this._isExecutingEvent = true; | 259 this[_isExecutingEvent] = true; |
249 try { | 260 try { |
250 result = dart.dinvokef(code); | 261 result = dart.dinvokef(code); |
251 } catch (e) { | 262 } catch (e) { |
252 let s = dart.stackTrace(e); | 263 let s = dart.stackTrace(e); |
253 this.handleUncaughtError(e, s); | 264 this.handleUncaughtError(e, s); |
254 if (this.errorsAreFatal) { | 265 if (this.errorsAreFatal) { |
255 this.kill(); | 266 this.kill(); |
256 if (core.identical(this, exports._globalState.rootContext)) { | 267 if (core.identical(this, exports._globalState.rootContext)) { |
257 throw e; | 268 throw e; |
258 } | 269 } |
259 } | 270 } |
260 } | 271 } |
261 finally { | 272 finally { |
262 this._isExecutingEvent = false; | 273 this[_isExecutingEvent] = false; |
263 exports._globalState.currentContext = old; | 274 exports._globalState.currentContext = old; |
264 if (old !== null) | 275 if (old !== null) |
265 old._setGlobals(); | 276 old._setGlobals(); |
266 if (this._scheduledControlEvents !== null) { | 277 if (this[_scheduledControlEvents] !== null) { |
267 while (dart.dload(this._scheduledControlEvents, 'isNotEmpty')) { | 278 while (dart.dload(this[_scheduledControlEvents], 'isNotEmpty')) { |
268 dart.dinvokef(dart.dinvoke(this._scheduledControlEvents, 'removeFirs
t')); | 279 dart.dinvokef(dart.dinvoke(this[_scheduledControlEvents], 'removeFir
st')); |
269 } | 280 } |
270 } | 281 } |
271 } | 282 } |
272 return result; | 283 return result; |
273 } | 284 } |
274 _setGlobals() { | 285 [_setGlobals]() { |
275 _foreign_helper.JS_SET_CURRENT_ISOLATE(this.isolateStatics); | 286 _foreign_helper.JS_SET_CURRENT_ISOLATE(this.isolateStatics); |
276 } | 287 } |
277 handleControlMessage(message) { | 288 handleControlMessage(message) { |
278 switch (dart.dindex(message, 0)) { | 289 switch (dart.dindex(message, 0)) { |
279 case "pause": | 290 case "pause": |
280 this.addPause(dart.as(dart.dindex(message, 1), isolate.Capability), da
rt.as(dart.dindex(message, 2), isolate.Capability)); | 291 this.addPause(dart.as(dart.dindex(message, 1), isolate.Capability), da
rt.as(dart.dindex(message, 2), isolate.Capability)); |
281 break; | 292 break; |
282 case "resume": | 293 case "resume": |
283 this.removePause(dart.as(dart.dindex(message, 1), isolate.Capability))
; | 294 this.removePause(dart.as(dart.dindex(message, 1), isolate.Capability))
; |
284 break; | 295 break; |
(...skipping 17 matching lines...) Expand all Loading... |
302 break; | 313 break; |
303 case "stopErrors": | 314 case "stopErrors": |
304 this.removeErrorListener(dart.as(dart.dindex(message, 1), isolate.Send
Port)); | 315 this.removeErrorListener(dart.as(dart.dindex(message, 1), isolate.Send
Port)); |
305 break; | 316 break; |
306 default: | 317 default: |
307 } | 318 } |
308 } | 319 } |
309 lookup(portId) { | 320 lookup(portId) { |
310 return this.ports.get(portId); | 321 return this.ports.get(portId); |
311 } | 322 } |
312 _addRegistration(portId, port) { | 323 [_addRegistration](portId, port) { |
313 if (this.ports.containsKey(portId)) { | 324 if (this.ports.containsKey(portId)) { |
314 throw new core.Exception("Registry: ports must be registered only once."
); | 325 throw new core.Exception("Registry: ports must be registered only once."
); |
315 } | 326 } |
316 this.ports.set(portId, port); | 327 this.ports.set(portId, port); |
317 } | 328 } |
318 register(portId, port) { | 329 register(portId, port) { |
319 this._addRegistration(portId, port); | 330 this[_addRegistration](portId, port); |
320 this._updateGlobalState(); | 331 this[_updateGlobalState](); |
321 } | 332 } |
322 registerWeak(portId, port) { | 333 registerWeak(portId, port) { |
323 this.weakPorts.add(portId); | 334 this.weakPorts.add(portId); |
324 this._addRegistration(portId, port); | 335 this[_addRegistration](portId, port); |
325 } | 336 } |
326 _updateGlobalState() { | 337 [_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))) { | 338 if (dart.notNull(dart.notNull(this.ports.length - this.weakPorts.length >
0) || dart.notNull(this.isPaused)) || dart.notNull(!dart.notNull(this.initialize
d))) { |
328 exports._globalState.isolates.set(this.id, this); | 339 exports._globalState.isolates.set(this.id, this); |
329 } else { | 340 } else { |
330 this.kill(); | 341 this.kill(); |
331 } | 342 } |
332 } | 343 } |
333 kill() { | 344 kill() { |
334 if (this._scheduledControlEvents !== null) { | 345 if (this[_scheduledControlEvents] !== null) { |
335 dart.dinvoke(this._scheduledControlEvents, 'clear'); | 346 dart.dinvoke(this[_scheduledControlEvents], 'clear'); |
336 } | 347 } |
337 for (let port of this.ports.values) { | 348 for (let port of this.ports.values) { |
338 dart.dinvoke(port, '_close'); | 349 dart.dinvoke(port, '_close'); |
339 } | 350 } |
340 this.ports.clear(); | 351 this.ports.clear(); |
341 this.weakPorts.clear(); | 352 this.weakPorts.clear(); |
342 exports._globalState.isolates.remove(this.id); | 353 exports._globalState.isolates.remove(this.id); |
343 this.errorPorts.clear(); | 354 this.errorPorts.clear(); |
344 if (this.doneHandlers !== null) { | 355 if (this.doneHandlers !== null) { |
345 for (let port of this.doneHandlers) { | 356 for (let port of this.doneHandlers) { |
346 port.send(null); | 357 port.send(null); |
347 } | 358 } |
348 this.doneHandlers = null; | 359 this.doneHandlers = null; |
349 } | 360 } |
350 } | 361 } |
351 unregister(portId) { | 362 unregister(portId) { |
352 this.ports.remove(portId); | 363 this.ports.remove(portId); |
353 this.weakPorts.remove(portId); | 364 this.weakPorts.remove(portId); |
354 this._updateGlobalState(); | 365 this[_updateGlobalState](); |
355 } | 366 } |
356 } | 367 } |
| 368 let _runHelper = Symbol('_runHelper'); |
357 class _EventLoop extends dart.Object { | 369 class _EventLoop extends dart.Object { |
358 _EventLoop() { | 370 _EventLoop() { |
359 this.events = new collection.Queue(); | 371 this.events = new collection.Queue(); |
360 this._activeJsAsyncCount = 0; | 372 this[_activeJsAsyncCount] = 0; |
361 } | 373 } |
362 enqueue(isolate, fn, msg) { | 374 enqueue(isolate, fn, msg) { |
363 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d
art.as(fn, core.Function), dart.as(msg, core.String))); | 375 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d
art.as(fn, core.Function), dart.as(msg, core.String))); |
364 } | 376 } |
365 prequeue(event) { | 377 prequeue(event) { |
366 this.events.addFirst(event); | 378 this.events.addFirst(event); |
367 } | 379 } |
368 dequeue() { | 380 dequeue() { |
369 if (this.events.isEmpty) | 381 if (this.events.isEmpty) |
370 return null; | 382 return null; |
371 return this.events.removeFirst(); | 383 return this.events.removeFirst(); |
372 } | 384 } |
373 checkOpenReceivePortsFromCommandLine() { | 385 checkOpenReceivePortsFromCommandLine() { |
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)) { | 386 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."); | 387 throw new core.Exception("Program exited with open ReceivePorts."); |
376 } | 388 } |
377 } | 389 } |
378 runIteration() { | 390 runIteration() { |
379 let event = this.dequeue(); | 391 let event = this.dequeue(); |
380 if (event === null) { | 392 if (event === null) { |
381 this.checkOpenReceivePortsFromCommandLine(); | 393 this.checkOpenReceivePortsFromCommandLine(); |
382 exports._globalState.maybeCloseWorker(); | 394 exports._globalState.maybeCloseWorker(); |
383 return false; | 395 return false; |
384 } | 396 } |
385 event.process(); | 397 event.process(); |
386 return true; | 398 return true; |
387 } | 399 } |
388 _runHelper() { | 400 [_runHelper]() { |
389 if (exports.globalWindow !== null) { | 401 if (exports.globalWindow !== null) { |
390 // Function next: () → void | 402 // Function next: () → void |
391 function next() { | 403 function next() { |
392 if (!dart.notNull(this.runIteration())) | 404 if (!dart.notNull(this.runIteration())) |
393 return; | 405 return; |
394 async.Timer.run(next); | 406 async.Timer.run(next); |
395 } | 407 } |
396 next(); | 408 next(); |
397 } else { | 409 } else { |
398 while (this.runIteration()) { | 410 while (this.runIteration()) { |
399 } | 411 } |
400 } | 412 } |
401 } | 413 } |
402 run() { | 414 run() { |
403 if (!dart.notNull(exports._globalState.isWorker)) { | 415 if (!dart.notNull(exports._globalState.isWorker)) { |
404 this._runHelper(); | 416 this[_runHelper](); |
405 } else { | 417 } else { |
406 try { | 418 try { |
407 this._runHelper(); | 419 this[_runHelper](); |
408 } catch (e) { | 420 } catch (e) { |
409 let trace = dart.stackTrace(e); | 421 let trace = dart.stackTrace(e); |
410 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma
p({command: 'error', msg: `${e}\n${trace}`}))); | 422 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma
p({command: 'error', msg: `${e}\n${trace}`}))); |
411 } | 423 } |
412 | 424 |
413 } | 425 } |
414 } | 426 } |
415 } | 427 } |
416 class _IsolateEvent extends dart.Object { | 428 class _IsolateEvent extends dart.Object { |
417 _IsolateEvent(isolate, fn, message) { | 429 _IsolateEvent(isolate, fn, message) { |
(...skipping 24 matching lines...) Expand all Loading... |
442 }, | 454 }, |
443 get globalWorker() { | 455 get globalWorker() { |
444 _js_helper.requiresPreamble(); | 456 _js_helper.requiresPreamble(); |
445 return self.Worker; | 457 return self.Worker; |
446 }, | 458 }, |
447 get globalPostMessageDefined() { | 459 get globalPostMessageDefined() { |
448 _js_helper.requiresPreamble(); | 460 _js_helper.requiresPreamble(); |
449 return !!self.postMessage; | 461 return !!self.postMessage; |
450 } | 462 } |
451 }); | 463 }); |
| 464 let _getEventData = Symbol('_getEventData'); |
| 465 let _log = Symbol('_log'); |
| 466 let _consoleLog = Symbol('_consoleLog'); |
| 467 let _getJSFunctionFromName = Symbol('_getJSFunctionFromName'); |
| 468 let _getJSFunctionName = Symbol('_getJSFunctionName'); |
| 469 let _allocate = Symbol('_allocate'); |
| 470 let _startWorker = Symbol('_startWorker'); |
| 471 let _startNonWorker = Symbol('_startNonWorker'); |
| 472 let _startIsolate = Symbol('_startIsolate'); |
| 473 let _spawnWorker = Symbol('_spawnWorker'); |
452 class IsolateNatives extends dart.Object { | 474 class IsolateNatives extends dart.Object { |
453 static computeThisScript() { | 475 static computeThisScript() { |
454 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb
edded_names.CURRENT_SCRIPT, core.String)); | 476 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_emb
edded_names.CURRENT_SCRIPT, core.String)); |
455 if (currentScript !== null) { | 477 if (currentScript !== null) { |
456 return String(currentScript.src); | 478 return String(currentScript.src); |
457 } | 479 } |
458 if (_js_helper.Primitives.isD8) | 480 if (_js_helper.Primitives.isD8) |
459 return computeThisScriptD8(); | 481 return computeThisScriptD8(); |
460 if (_js_helper.Primitives.isJsshell) | 482 if (_js_helper.Primitives.isJsshell) |
461 return computeThisScriptJsshell(); | 483 return computeThisScriptJsshell(); |
(...skipping 25 matching lines...) Expand all Loading... |
487 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); | 509 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); |
488 matches = stack.match(pattern); | 510 matches = stack.match(pattern); |
489 if (matches !== null) | 511 if (matches !== null) |
490 return matches[1]; | 512 return matches[1]; |
491 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); | 513 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); |
492 matches = stack.match(pattern); | 514 matches = stack.match(pattern); |
493 if (matches !== null) | 515 if (matches !== null) |
494 return matches[1]; | 516 return matches[1]; |
495 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); | 517 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); |
496 } | 518 } |
497 static _getEventData(e) { | 519 static [_getEventData](e) { |
498 return e.data; | 520 return e.data; |
499 } | 521 } |
500 static _processWorkerMessage(sender, e) { | 522 static [_processWorkerMessage](sender, e) { |
501 let msg = _deserializeMessage(_getEventData(e)); | 523 let msg = _deserializeMessage(_getEventData(e)); |
502 switch (dart.dindex(msg, 'command')) { | 524 switch (dart.dindex(msg, 'command')) { |
503 case 'start': | 525 case 'start': |
504 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); | 526 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); |
505 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); | 527 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); |
506 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : _getJSFunctionFromName(functionName), core.Function); | 528 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : _getJSFunctionFromName(functionName), core.Function); |
507 let args = dart.dindex(msg, 'args'); | 529 let args = dart.dindex(msg, 'args'); |
508 let message = _deserializeMessage(dart.dindex(msg, 'msg')); | 530 let message = _deserializeMessage(dart.dindex(msg, 'msg')); |
509 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); | 531 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); |
510 let startPaused = dart.dindex(msg, 'startPaused'); | 532 let startPaused = dart.dindex(msg, 'startPaused'); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 static handleSpawnWorkerRequest(msg) { | 571 static handleSpawnWorkerRequest(msg) { |
550 let replyPort = dart.dindex(msg, 'replyPort'); | 572 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) => { | 573 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); | 574 dart.dinvoke(replyPort, 'send', msg); |
553 }, { | 575 }, { |
554 onError: (errorMessage) => { | 576 onError: (errorMessage) => { |
555 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); | 577 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); |
556 } | 578 } |
557 }); | 579 }); |
558 } | 580 } |
559 static _log(msg) { | 581 static [_log](msg) { |
560 if (exports._globalState.isWorker) { | 582 if (exports._globalState.isWorker) { |
561 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); | 583 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); |
562 } else { | 584 } else { |
563 try { | 585 try { |
564 _consoleLog(msg); | 586 _consoleLog(msg); |
565 } catch (e) { | 587 } catch (e) { |
566 let trace = dart.stackTrace(e); | 588 let trace = dart.stackTrace(e); |
567 throw new core.Exception(trace); | 589 throw new core.Exception(trace); |
568 } | 590 } |
569 | 591 |
570 } | 592 } |
571 } | 593 } |
572 static _consoleLog(msg) { | 594 static [_consoleLog](msg) { |
573 _js_helper.requiresPreamble(); | 595 _js_helper.requiresPreamble(); |
574 self.console.log(msg); | 596 self.console.log(msg); |
575 } | 597 } |
576 static _getJSFunctionFromName(functionName) { | 598 static [_getJSFunctionFromName](functionName) { |
577 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", dart
.as(_js_embedded_names.GLOBAL_FUNCTIONS, core.String)); | 599 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", dart
.as(_js_embedded_names.GLOBAL_FUNCTIONS, core.String)); |
578 return globalFunctionsContainer[functionName](); | 600 return globalFunctionsContainer[functionName](); |
579 } | 601 } |
580 static _getJSFunctionName(f) { | 602 static [_getJSFunctionName](f) { |
581 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); | 603 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); |
582 } | 604 } |
583 static _allocate(ctor) { | 605 static [_allocate](ctor) { |
584 return new ctor(); | 606 return new ctor(); |
585 } | 607 } |
586 static spawnFunction(topLevelFunction, message, startPaused) { | 608 static spawnFunction(topLevelFunction, message, startPaused) { |
587 IsolateNatives.enableSpawnWorker = true; | 609 IsolateNatives.enableSpawnWorker = true; |
588 let name = _getJSFunctionName(topLevelFunction); | 610 let name = _getJSFunctionName(topLevelFunction); |
589 if (name === null) { | 611 if (name === null) { |
590 throw new core.UnsupportedError("only top-level functions can be spawned
."); | 612 throw new core.UnsupportedError("only top-level functions can be spawned
."); |
591 } | 613 } |
592 let isLight = false; | 614 let isLight = false; |
593 let isSpawnUri = false; | 615 let isSpawnUri = false; |
(...skipping 19 matching lines...) Expand all Loading... |
613 } | 635 } |
614 }).bind(this)); | 636 }).bind(this)); |
615 let signalReply = port.sendPort; | 637 let signalReply = port.sendPort; |
616 if (dart.notNull(exports._globalState.useWorkers) && dart.notNull(!dart.no
tNull(isLight))) { | 638 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)); | 639 _startWorker(functionName, uri, args, message, isSpawnUri, startPaused,
signalReply, ((message) => completer.completeError(message)).bind(this)); |
618 } else { | 640 } else { |
619 _startNonWorker(functionName, uri, args, message, isSpawnUri, startPause
d, signalReply); | 641 _startNonWorker(functionName, uri, args, message, isSpawnUri, startPause
d, signalReply); |
620 } | 642 } |
621 return completer.future; | 643 return completer.future; |
622 } | 644 } |
623 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 645 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
624 if (args !== null) | 646 if (args !== null) |
625 args = new core.List.from(args); | 647 args = new core.List.from(args); |
626 if (exports._globalState.isWorker) { | 648 if (exports._globalState.isWorker) { |
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
}))); | 649 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 { | 650 } else { |
629 _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
replyPort, onError); | 651 _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
replyPort, onError); |
630 } | 652 } |
631 } | 653 } |
632 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { | 654 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start
Paused, replyPort) { |
633 if (uri !== null) { | 655 if (uri !== null) { |
634 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); | 656 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); |
635 } | 657 } |
636 message = _clone(message); | 658 message = _clone(message); |
637 if (args !== null) | 659 if (args !== null) |
638 args = new core.List.from(args); | 660 args = new core.List.from(args); |
639 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { | 661 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { |
640 let func = _getJSFunctionFromName(functionName); | 662 let func = _getJSFunctionFromName(functionName); |
641 _startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, s
tartPaused, replyPort); | 663 _startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, s
tartPaused, replyPort); |
642 }, 'nonworker start'); | 664 }, 'nonworker start'); |
643 } | 665 } |
644 static get currentIsolate() { | 666 static get currentIsolate() { |
645 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 667 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}); | 668 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
647 } | 669 } |
648 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { | 670 static [_startIsolate](topLevel, args, message, isSpawnUri, startPaused, rep
lyTo) { |
649 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 671 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
650 _js_helper.Primitives.initializeStatics(context.id); | 672 _js_helper.Primitives.initializeStatics(context.id); |
651 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); | 673 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); |
652 // Function runStartFunction: () → void | 674 // Function runStartFunction: () → void |
653 function runStartFunction() { | 675 function runStartFunction() { |
654 context.initialized = true; | 676 context.initialized = true; |
655 if (!dart.notNull(isSpawnUri)) { | 677 if (!dart.notNull(isSpawnUri)) { |
656 dart.dinvokef(topLevel, message); | 678 dart.dinvokef(topLevel, message); |
657 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { | 679 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { |
658 dart.dinvokef(topLevel, args, message); | 680 dart.dinvokef(topLevel, args, message); |
659 } else if (dart.is(topLevel, _MainFunctionArgs)) { | 681 } else if (dart.is(topLevel, _MainFunctionArgs)) { |
660 dart.dinvokef(topLevel, args); | 682 dart.dinvokef(topLevel, args); |
661 } else { | 683 } else { |
662 dart.dinvokef(topLevel); | 684 dart.dinvokef(topLevel); |
663 } | 685 } |
664 } | 686 } |
665 if (startPaused) { | 687 if (startPaused) { |
666 context.addPause(context.pauseCapability, context.pauseCapability); | 688 context.addPause(context.pauseCapability, context.pauseCapability); |
667 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); | 689 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); |
668 } else { | 690 } else { |
669 runStartFunction(); | 691 runStartFunction(); |
670 } | 692 } |
671 } | 693 } |
672 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 694 static [_spawnWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
673 if (uri === null) | 695 if (uri === null) |
674 uri = thisScript; | 696 uri = thisScript; |
675 let worker = new Worker(uri); | 697 let worker = new Worker(uri); |
676 let onerrorTrampoline = function(f, u, c) { | 698 let onerrorTrampoline = function(f, u, c) { |
677 return function(e) { | 699 return function(e) { |
678 return f(e, u, c); | 700 return f(e, u, c); |
679 }; | 701 }; |
680 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError); | 702 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError); |
681 worker.onerror = onerrorTrampoline; | 703 worker.onerror = onerrorTrampoline; |
682 let processWorkerMessageTrampoline = function(f, a) { | 704 let processWorkerMessageTrampoline = function(f, a) { |
(...skipping 23 matching lines...) Expand all Loading... |
706 IsolateNatives.enableSpawnWorker = null; | 728 IsolateNatives.enableSpawnWorker = null; |
707 dart.defineLazyProperties(IsolateNatives, { | 729 dart.defineLazyProperties(IsolateNatives, { |
708 get thisScript() { | 730 get thisScript() { |
709 return computeThisScript(); | 731 return computeThisScript(); |
710 }, | 732 }, |
711 set thisScript() {}, | 733 set thisScript() {}, |
712 get workerIds() { | 734 get workerIds() { |
713 return new core.Expando(); | 735 return new core.Expando(); |
714 } | 736 } |
715 }); | 737 }); |
| 738 let _isolateId = Symbol('_isolateId'); |
| 739 let _checkReplyTo = Symbol('_checkReplyTo'); |
716 class _BaseSendPort extends dart.Object { | 740 class _BaseSendPort extends dart.Object { |
717 _BaseSendPort(_isolateId) { | 741 _BaseSendPort($_isolateId) { |
718 this._isolateId = _isolateId; | 742 this[_isolateId] = $_isolateId; |
719 } | 743 } |
720 _checkReplyTo(replyTo) { | 744 [_checkReplyTo](replyTo) { |
721 if (dart.notNull(dart.notNull(replyTo !== null) && dart.notNull(!dart.is(r
eplyTo, _NativeJsSendPort))) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))
) { | 745 if (dart.notNull(dart.notNull(replyTo !== null) && dart.notNull(!dart.is(r
eplyTo, _NativeJsSendPort))) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))
) { |
722 throw new core.Exception("SendPort.send: Illegal replyTo port type"); | 746 throw new core.Exception("SendPort.send: Illegal replyTo port type"); |
723 } | 747 } |
724 } | 748 } |
725 } | 749 } |
| 750 let _receivePort = Symbol('_receivePort'); |
| 751 let _isClosed = Symbol('_isClosed'); |
726 class _NativeJsSendPort extends _BaseSendPort { | 752 class _NativeJsSendPort extends _BaseSendPort { |
727 _NativeJsSendPort(_receivePort, isolateId) { | 753 _NativeJsSendPort($_receivePort, isolateId) { |
728 this._receivePort = _receivePort; | 754 this[_receivePort] = $_receivePort; |
729 super._BaseSendPort(isolateId); | 755 super._BaseSendPort(isolateId); |
730 } | 756 } |
731 send(message) { | 757 send(message) { |
732 let isolate = exports._globalState.isolates.get(this._isolateId); | 758 let isolate = exports._globalState.isolates.get(this[_isolateId]); |
733 if (isolate === null) | 759 if (isolate === null) |
734 return; | 760 return; |
735 if (this._receivePort._isClosed) | 761 if (this[_receivePort][_isClosed]) |
736 return; | 762 return; |
737 let msg = _clone(message); | 763 let msg = _clone(message); |
738 if (dart.equals(isolate.controlPort, this._receivePort)) { | 764 if (dart.equals(isolate.controlPort, this[_receivePort])) { |
739 isolate.handleControlMessage(msg); | 765 isolate.handleControlMessage(msg); |
740 return; | 766 return; |
741 } | 767 } |
742 exports._globalState.topEventLoop.enqueue(isolate, (() => { | 768 exports._globalState.topEventLoop.enqueue(isolate, (() => { |
743 if (!dart.notNull(this._receivePort._isClosed)) { | 769 if (!dart.notNull(this[_receivePort][_isClosed])) { |
744 this._receivePort._add(msg); | 770 this[_receivePort]._add(msg); |
745 } | 771 } |
746 }).bind(this), `receive ${message}`); | 772 }).bind(this), `receive ${message}`); |
747 } | 773 } |
748 ['=='](other) { | 774 ['=='](other) { |
749 return dart.notNull(dart.is(other, _NativeJsSendPort)) && dart.notNull(dar
t.equals(this._receivePort, dart.dload(other, '_receivePort'))); | 775 return dart.notNull(dart.is(other, _NativeJsSendPort)) && dart.notNull(dar
t.equals(this[_receivePort], dart.dload(other, '_receivePort'))); |
750 } | 776 } |
751 get hashCode() { | 777 get hashCode() { |
752 return this._receivePort._id; | 778 return this[_receivePort][_id]; |
753 } | 779 } |
754 } | 780 } |
| 781 let _workerId = Symbol('_workerId'); |
| 782 let _receivePortId = Symbol('_receivePortId'); |
755 class _WorkerSendPort extends _BaseSendPort { | 783 class _WorkerSendPort extends _BaseSendPort { |
756 _WorkerSendPort(_workerId, isolateId, _receivePortId) { | 784 _WorkerSendPort($_workerId, isolateId, $_receivePortId) { |
757 this._workerId = _workerId; | 785 this[_workerId] = $_workerId; |
758 this._receivePortId = _receivePortId; | 786 this[_receivePortId] = $_receivePortId; |
759 super._BaseSendPort(isolateId); | 787 super._BaseSendPort(isolateId); |
760 } | 788 } |
761 send(message) { | 789 send(message) { |
762 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); | 790 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); |
763 if (exports._globalState.isWorker) { | 791 if (exports._globalState.isWorker) { |
764 exports._globalState.mainManager.postMessage(workerMessage); | 792 exports._globalState.mainManager.postMessage(workerMessage); |
765 } else { | 793 } else { |
766 let manager = exports._globalState.managers.get(this._workerId); | 794 let manager = exports._globalState.managers.get(this[_workerId]); |
767 if (manager !== null) { | 795 if (manager !== null) { |
768 manager.postMessage(workerMessage); | 796 manager.postMessage(workerMessage); |
769 } | 797 } |
770 } | 798 } |
771 } | 799 } |
772 ['=='](other) { | 800 ['=='](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')); | 801 return dart.notNull(dart.notNull(dart.notNull(dart.is(other, _WorkerSendPo
rt)) && dart.notNull(this[_workerId] === dart.dload(other, '_workerId'))) && dar
t.notNull(this[_isolateId] === dart.dload(other, '_isolateId'))) && dart.notNull
(this[_receivePortId] === dart.dload(other, '_receivePortId')); |
774 } | 802 } |
775 get hashCode() { | 803 get hashCode() { |
776 return this._workerId << 16 ^ this._isolateId << 8 ^ this._receivePortId; | 804 return this[_workerId] << 16 ^ this[_isolateId] << 8 ^ this[_receivePortId
]; |
777 } | 805 } |
778 } | 806 } |
| 807 let _handler = Symbol('_handler'); |
| 808 let _close = Symbol('_close'); |
| 809 let _add = Symbol('_add'); |
779 class RawReceivePortImpl extends dart.Object { | 810 class RawReceivePortImpl extends dart.Object { |
780 RawReceivePortImpl(_handler) { | 811 RawReceivePortImpl($_handler) { |
781 this._handler = _handler; | 812 this[_handler] = $_handler; |
782 this._id = _nextFreeId++; | 813 this[_id] = _nextFreeId++; |
783 this._isClosed = false; | 814 this[_isClosed] = false; |
784 exports._globalState.currentContext.register(this._id, this); | 815 exports._globalState.currentContext.register(this[_id], this); |
785 } | 816 } |
786 RawReceivePortImpl$weak(_handler) { | 817 RawReceivePortImpl$weak($_handler) { |
787 this._handler = _handler; | 818 this[_handler] = $_handler; |
788 this._id = _nextFreeId++; | 819 this[_id] = _nextFreeId++; |
789 this._isClosed = false; | 820 this[_isClosed] = false; |
790 exports._globalState.currentContext.registerWeak(this._id, this); | 821 exports._globalState.currentContext.registerWeak(this[_id], this); |
791 } | 822 } |
792 RawReceivePortImpl$_controlPort() { | 823 RawReceivePortImpl$_controlPort() { |
793 this._handler = null; | 824 this[_handler] = null; |
794 this._id = 0; | 825 this[_id] = 0; |
795 this._isClosed = false; | 826 this[_isClosed] = false; |
796 } | 827 } |
797 set handler(newHandler) { | 828 set handler(newHandler) { |
798 this._handler = newHandler; | 829 this[_handler] = newHandler; |
799 } | 830 } |
800 _close() { | 831 [_close]() { |
801 this._isClosed = true; | 832 this[_isClosed] = true; |
802 this._handler = null; | 833 this[_handler] = null; |
803 } | 834 } |
804 close() { | 835 close() { |
805 if (this._isClosed) | 836 if (this[_isClosed]) |
806 return; | 837 return; |
807 this._isClosed = true; | 838 this[_isClosed] = true; |
808 this._handler = null; | 839 this[_handler] = null; |
809 exports._globalState.currentContext.unregister(this._id); | 840 exports._globalState.currentContext.unregister(this[_id]); |
810 } | 841 } |
811 _add(dataEvent) { | 842 [_add](dataEvent) { |
812 if (this._isClosed) | 843 if (this[_isClosed]) |
813 return; | 844 return; |
814 dart.dinvokef(this._handler, dataEvent); | 845 dart.dinvokef(this[_handler], dataEvent); |
815 } | 846 } |
816 get sendPort() { | 847 get sendPort() { |
817 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; | 848 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; |
818 } | 849 } |
819 } | 850 } |
820 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); | 851 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); |
821 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); | 852 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); |
822 RawReceivePortImpl._nextFreeId = 1; | 853 RawReceivePortImpl._nextFreeId = 1; |
| 854 let _rawPort = Symbol('_rawPort'); |
| 855 let _controller = Symbol('_controller'); |
823 class ReceivePortImpl extends async.Stream { | 856 class ReceivePortImpl extends async.Stream { |
824 ReceivePortImpl() { | 857 ReceivePortImpl() { |
825 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); | 858 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); |
826 } | 859 } |
827 ReceivePortImpl$weak() { | 860 ReceivePortImpl$weak() { |
828 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl.weak(null))
; | 861 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl.weak(null))
; |
829 } | 862 } |
830 ReceivePortImpl$fromRawReceivePort(_rawPort) { | 863 ReceivePortImpl$fromRawReceivePort($_rawPort) { |
831 this._rawPort = _rawPort; | 864 this[_rawPort] = $_rawPort; |
832 this._controller = null; | 865 this[_controller] = null; |
833 super.Stream(); | 866 super.Stream(); |
834 this._controller = new async.StreamController({onCancel: this.close, sync:
true}); | 867 this[_controller] = new async.StreamController({onCancel: this.close, sync
: true}); |
835 this._rawPort.handler = this._controller.add; | 868 this[_rawPort].handler = this[_controller].add; |
836 } | 869 } |
837 listen(onData, opt$) { | 870 listen(onData, opt$) { |
838 let onError = opt$.onError === void 0 ? null : opt$.onError; | 871 let onError = opt$.onError === void 0 ? null : opt$.onError; |
839 let onDone = opt$.onDone === void 0 ? null : opt$.onDone; | 872 let onDone = opt$.onDone === void 0 ? null : opt$.onDone; |
840 let cancelOnError = opt$.cancelOnError === void 0 ? null : opt$.cancelOnEr
ror; | 873 let cancelOnError = opt$.cancelOnError === void 0 ? null : opt$.cancelOnEr
ror; |
841 return this._controller.stream.listen(onData, {onError: onError, onDone: o
nDone, cancelOnError: cancelOnError}); | 874 return this[_controller].stream.listen(onData, {onError: onError, onDone:
onDone, cancelOnError: cancelOnError}); |
842 } | 875 } |
843 close() { | 876 close() { |
844 this._rawPort.close(); | 877 this[_rawPort].close(); |
845 this._controller.close(); | 878 this[_controller].close(); |
846 } | 879 } |
847 get sendPort() { | 880 get sendPort() { |
848 return this._rawPort.sendPort; | 881 return this[_rawPort].sendPort; |
849 } | 882 } |
850 } | 883 } |
851 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); | 884 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); |
852 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); | 885 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); |
| 886 let _once = Symbol('_once'); |
| 887 let _inEventLoop = Symbol('_inEventLoop'); |
| 888 let _handle = Symbol('_handle'); |
853 class TimerImpl extends dart.Object { | 889 class TimerImpl extends dart.Object { |
854 TimerImpl(milliseconds, callback) { | 890 TimerImpl(milliseconds, callback) { |
855 this._once = true; | 891 this[_once] = true; |
856 this._inEventLoop = false; | 892 this[_inEventLoop] = false; |
857 this._handle = dart.as(null, core.int); | 893 this[_handle] = dart.as(null, core.int); |
858 if (dart.notNull(milliseconds === 0) && dart.notNull(dart.notNull(!dart.no
tNull(hasTimer())) || dart.notNull(exports._globalState.isWorker))) { | 894 if (dart.notNull(milliseconds === 0) && dart.notNull(dart.notNull(!dart.no
tNull(hasTimer())) || dart.notNull(exports._globalState.isWorker))) { |
859 // Function internalCallback: () → void | 895 // Function internalCallback: () → void |
860 function internalCallback() { | 896 function internalCallback() { |
861 this._handle = dart.as(null, core.int); | 897 this[_handle] = dart.as(null, core.int); |
862 callback(); | 898 callback(); |
863 } | 899 } |
864 this._handle = 1; | 900 this[_handle] = 1; |
865 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); | 901 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); |
866 this._inEventLoop = true; | 902 this[_inEventLoop] = true; |
867 } else if (hasTimer()) { | 903 } else if (hasTimer()) { |
868 // Function internalCallback: () → void | 904 // Function internalCallback: () → void |
869 function internalCallback() { | 905 function internalCallback() { |
870 this._handle = dart.as(null, core.int); | 906 this[_handle] = dart.as(null, core.int); |
871 leaveJsAsync(); | 907 leaveJsAsync(); |
872 callback(); | 908 callback(); |
873 } | 909 } |
874 enterJsAsync(); | 910 enterJsAsync(); |
875 this._handle = self.setTimeout(_js_helper.convertDartClosureToJS(interna
lCallback, 0), milliseconds); | 911 this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(intern
alCallback, 0), milliseconds); |
876 } else { | 912 } else { |
877 dart.assert(milliseconds > 0); | 913 dart.assert(milliseconds > 0); |
878 throw new core.UnsupportedError("Timer greater than 0."); | 914 throw new core.UnsupportedError("Timer greater than 0."); |
879 } | 915 } |
880 } | 916 } |
881 TimerImpl$periodic(milliseconds, callback) { | 917 TimerImpl$periodic(milliseconds, callback) { |
882 this._once = false; | 918 this[_once] = false; |
883 this._inEventLoop = false; | 919 this[_inEventLoop] = false; |
884 this._handle = dart.as(null, core.int); | 920 this[_handle] = dart.as(null, core.int); |
885 if (hasTimer()) { | 921 if (hasTimer()) { |
886 enterJsAsync(); | 922 enterJsAsync(); |
887 this._handle = self.setInterval(_js_helper.convertDartClosureToJS((() =>
{ | 923 this[_handle] = self.setInterval(_js_helper.convertDartClosureToJS((() =
> { |
888 callback(this); | 924 callback(this); |
889 }).bind(this), 0), milliseconds); | 925 }).bind(this), 0), milliseconds); |
890 } else { | 926 } else { |
891 throw new core.UnsupportedError("Periodic timer."); | 927 throw new core.UnsupportedError("Periodic timer."); |
892 } | 928 } |
893 } | 929 } |
894 cancel() { | 930 cancel() { |
895 if (hasTimer()) { | 931 if (hasTimer()) { |
896 if (this._inEventLoop) { | 932 if (this[_inEventLoop]) { |
897 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); | 933 throw new core.UnsupportedError("Timer in event loop cannot be cancele
d."); |
898 } | 934 } |
899 if (this._handle === null) | 935 if (this[_handle] === null) |
900 return; | 936 return; |
901 leaveJsAsync(); | 937 leaveJsAsync(); |
902 if (this._once) { | 938 if (this[_once]) { |
903 self.clearTimeout(this._handle); | 939 self.clearTimeout(this[_handle]); |
904 } else { | 940 } else { |
905 self.clearInterval(this._handle); | 941 self.clearInterval(this[_handle]); |
906 } | 942 } |
907 this._handle = dart.as(null, core.int); | 943 this[_handle] = dart.as(null, core.int); |
908 } else { | 944 } else { |
909 throw new core.UnsupportedError("Canceling a timer."); | 945 throw new core.UnsupportedError("Canceling a timer."); |
910 } | 946 } |
911 } | 947 } |
912 get isActive() { | 948 get isActive() { |
913 return this._handle !== null; | 949 return this[_handle] !== null; |
914 } | 950 } |
915 } | 951 } |
916 dart.defineNamedConstructor(TimerImpl, 'periodic'); | 952 dart.defineNamedConstructor(TimerImpl, 'periodic'); |
917 // Function hasTimer: () → bool | 953 // Function hasTimer: () → bool |
918 function hasTimer() { | 954 function hasTimer() { |
919 _js_helper.requiresPreamble(); | 955 _js_helper.requiresPreamble(); |
920 return self.setTimeout !== null; | 956 return self.setTimeout !== null; |
921 } | 957 } |
922 class CapabilityImpl extends dart.Object { | 958 class CapabilityImpl extends dart.Object { |
923 CapabilityImpl() { | 959 CapabilityImpl() { |
924 this.CapabilityImpl$_internal(_js_helper.random64()); | 960 this.CapabilityImpl$_internal(_js_helper.random64()); |
925 } | 961 } |
926 CapabilityImpl$_internal(_id) { | 962 CapabilityImpl$_internal($_id) { |
927 this._id = _id; | 963 this[_id] = $_id; |
928 } | 964 } |
929 get hashCode() { | 965 get hashCode() { |
930 let hash = this._id; | 966 let hash = this[_id]; |
931 hash = hash >> 0 ^ (hash / 4294967296).truncate(); | 967 hash = hash >> 0 ^ (hash / 4294967296).truncate(); |
932 hash = ~hash + (hash << 15) & 4294967295; | 968 hash = ~hash + (hash << 15) & 4294967295; |
933 hash = hash >> 12; | 969 hash = hash >> 12; |
934 hash = hash * 5 & 4294967295; | 970 hash = hash * 5 & 4294967295; |
935 hash = hash >> 4; | 971 hash = hash >> 4; |
936 hash = hash * 2057 & 4294967295; | 972 hash = hash * 2057 & 4294967295; |
937 hash = hash >> 16; | 973 hash = hash >> 16; |
938 return hash; | 974 return hash; |
939 } | 975 } |
940 ['=='](other) { | 976 ['=='](other) { |
941 if (core.identical(other, this)) | 977 if (core.identical(other, this)) |
942 return true; | 978 return true; |
943 if (dart.is(other, CapabilityImpl)) { | 979 if (dart.is(other, CapabilityImpl)) { |
944 return core.identical(this._id, other._id); | 980 return core.identical(this[_id], other[_id]); |
945 } | 981 } |
946 return false; | 982 return false; |
947 } | 983 } |
948 } | 984 } |
949 dart.defineNamedConstructor(CapabilityImpl, '_internal'); | 985 dart.defineNamedConstructor(CapabilityImpl, '_internal'); |
950 // Function _serializeMessage: (dynamic) → dynamic | 986 // Function _serializeMessage: (dynamic) → dynamic |
951 function _serializeMessage(message) { | 987 function _serializeMessage(message) { |
952 return new _Serializer().serialize(message); | 988 return new _Serializer().serialize(message); |
953 } | 989 } |
954 // Function _deserializeMessage: (dynamic) → dynamic | 990 // Function _deserializeMessage: (dynamic) → dynamic |
955 function _deserializeMessage(message) { | 991 function _deserializeMessage(message) { |
956 return new _Deserializer().deserialize(message); | 992 return new _Deserializer().deserialize(message); |
957 } | 993 } |
958 // Function _clone: (dynamic) → dynamic | 994 // Function _clone: (dynamic) → dynamic |
959 function _clone(message) { | 995 function _clone(message) { |
960 let serializer = new _Serializer({serializeSendPorts: false}); | 996 let serializer = new _Serializer({serializeSendPorts: false}); |
961 let deserializer = new _Deserializer(); | 997 let deserializer = new _Deserializer(); |
962 return deserializer.deserialize(serializer.serialize(message)); | 998 return deserializer.deserialize(serializer.serialize(message)); |
963 } | 999 } |
| 1000 let _serializeSendPorts = Symbol('_serializeSendPorts'); |
964 class _Serializer extends dart.Object { | 1001 class _Serializer extends dart.Object { |
965 _Serializer(opt$) { | 1002 _Serializer(opt$) { |
966 let serializeSendPorts = opt$.serializeSendPorts === void 0 ? true : opt$.
serializeSendPorts; | 1003 let serializeSendPorts = opt$.serializeSendPorts === void 0 ? true : opt$.
serializeSendPorts; |
967 this.serializedObjectIds = new core.Map.identity(); | 1004 this.serializedObjectIds = new core.Map.identity(); |
968 this._serializeSendPorts = dart.as(serializeSendPorts, core.bool); | 1005 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); |
969 } | 1006 } |
970 serialize(x) { | 1007 serialize(x) { |
971 if (this.isPrimitive(x)) | 1008 if (this.isPrimitive(x)) |
972 return this.serializePrimitive(x); | 1009 return this.serializePrimitive(x); |
973 let serializationId = this.serializedObjectIds.get(x); | 1010 let serializationId = this.serializedObjectIds.get(x); |
974 if (serializationId !== null) | 1011 if (serializationId !== null) |
975 return this.makeRef(serializationId); | 1012 return this.makeRef(serializationId); |
976 serializationId = this.serializedObjectIds.length; | 1013 serializationId = this.serializedObjectIds.length; |
977 this.serializedObjectIds.set(x, serializationId); | 1014 this.serializedObjectIds.set(x, serializationId); |
978 if (dart.is(x, _native_typed_data.NativeByteBuffer)) | 1015 if (dart.is(x, _native_typed_data.NativeByteBuffer)) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 } | 1095 } |
1059 let keys = dart.as(Object.keys(x), core.List); | 1096 let keys = dart.as(Object.keys(x), core.List); |
1060 let values = new List.from([]); | 1097 let values = new List.from([]); |
1061 values.length = keys.length; | 1098 values.length = keys.length; |
1062 for (let i = 0; i < keys.length; i++) { | 1099 for (let i = 0; i < keys.length; i++) { |
1063 values.set(i, this.serialize(x[keys.get(i)])); | 1100 values.set(i, this.serialize(x[keys.get(i)])); |
1064 } | 1101 } |
1065 return new List.from(['js-object', keys, values]); | 1102 return new List.from(['js-object', keys, values]); |
1066 } | 1103 } |
1067 serializeWorkerSendPort(x) { | 1104 serializeWorkerSendPort(x) { |
1068 if (this._serializeSendPorts) { | 1105 if (this[_serializeSendPorts]) { |
1069 return new List.from(['sendport', x._workerId, x._isolateId, x._receiveP
ortId]); | 1106 return new List.from(['sendport', x[_workerId], x[_isolateId], x[_receiv
ePortId]]); |
1070 } | 1107 } |
1071 return new List.from(['raw sendport', x]); | 1108 return new List.from(['raw sendport', x]); |
1072 } | 1109 } |
1073 serializeJsSendPort(x) { | 1110 serializeJsSendPort(x) { |
1074 if (this._serializeSendPorts) { | 1111 if (this[_serializeSendPorts]) { |
1075 let workerId = exports._globalState.currentManagerId; | 1112 let workerId = exports._globalState.currentManagerId; |
1076 return new List.from(['sendport', workerId, x._isolateId, x._receivePort
._id]); | 1113 return new List.from(['sendport', workerId, x[_isolateId], x[_receivePor
t][_id]]); |
1077 } | 1114 } |
1078 return new List.from(['raw sendport', x]); | 1115 return new List.from(['raw sendport', x]); |
1079 } | 1116 } |
1080 serializeCapability(x) { | 1117 serializeCapability(x) { |
1081 return new List.from(['capability', x._id]); | 1118 return new List.from(['capability', x[_id]]); |
1082 } | 1119 } |
1083 serializeClosure(x) { | 1120 serializeClosure(x) { |
1084 let name = IsolateNatives._getJSFunctionName(x); | 1121 let name = IsolateNatives._getJSFunctionName(x); |
1085 if (name === null) { | 1122 if (name === null) { |
1086 this.unsupported(x, "Closures can't be transmitted:"); | 1123 this.unsupported(x, "Closures can't be transmitted:"); |
1087 } | 1124 } |
1088 return new List.from(['function', name]); | 1125 return new List.from(['function', name]); |
1089 } | 1126 } |
1090 serializeDartObject(x) { | 1127 serializeDartObject(x) { |
1091 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_em
bedded_names.CLASS_ID_EXTRACTOR, core.String)); | 1128 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_em
bedded_names.CLASS_ID_EXTRACTOR, core.String)); |
1092 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_e
mbedded_names.CLASS_FIELDS_EXTRACTOR, core.String)); | 1129 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', dart.as(_js_e
mbedded_names.CLASS_FIELDS_EXTRACTOR, core.String)); |
1093 let classId = classExtractor(x); | 1130 let classId = classExtractor(x); |
1094 let fields = dart.as(fieldsExtractor(x), core.List); | 1131 let fields = dart.as(fieldsExtractor(x), core.List); |
1095 return new List.from(['dart', classId, this.serializeArrayInPlace(dart.as(
fields, _interceptors.JSArray))]); | 1132 return new List.from(['dart', classId, this.serializeArrayInPlace(dart.as(
fields, _interceptors.JSArray))]); |
1096 } | 1133 } |
1097 } | 1134 } |
| 1135 let _adjustSendPorts = Symbol('_adjustSendPorts'); |
1098 class _Deserializer extends dart.Object { | 1136 class _Deserializer extends dart.Object { |
1099 _Deserializer(opt$) { | 1137 _Deserializer(opt$) { |
1100 let adjustSendPorts = opt$.adjustSendPorts === void 0 ? true : opt$.adjust
SendPorts; | 1138 let adjustSendPorts = opt$.adjustSendPorts === void 0 ? true : opt$.adjust
SendPorts; |
1101 this.deserializedObjects = new core.List(); | 1139 this.deserializedObjects = new core.List(); |
1102 this._adjustSendPorts = dart.as(adjustSendPorts, core.bool); | 1140 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); |
1103 } | 1141 } |
1104 deserialize(x) { | 1142 deserialize(x) { |
1105 if (this.isPrimitive(x)) | 1143 if (this.isPrimitive(x)) |
1106 return this.deserializePrimitive(x); | 1144 return this.deserializePrimitive(x); |
1107 if (!dart.is(x, _interceptors.JSArray)) | 1145 if (!dart.is(x, _interceptors.JSArray)) |
1108 throw new core.ArgumentError(`Bad serialized message: ${x}`); | 1146 throw new core.ArgumentError(`Bad serialized message: ${x}`); |
1109 switch (dart.dload(x, 'first')) { | 1147 switch (dart.dload(x, 'first')) { |
1110 case "ref": | 1148 case "ref": |
1111 return this.deserializeRef(x); | 1149 return this.deserializeRef(x); |
1112 case "buffer": | 1150 case "buffer": |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 exports.globalWindow = globalWindow; | 1304 exports.globalWindow = globalWindow; |
1267 exports.globalWorker = globalWorker; | 1305 exports.globalWorker = globalWorker; |
1268 exports.globalPostMessageDefined = globalPostMessageDefined; | 1306 exports.globalPostMessageDefined = globalPostMessageDefined; |
1269 exports.IsolateNatives = IsolateNatives; | 1307 exports.IsolateNatives = IsolateNatives; |
1270 exports.RawReceivePortImpl = RawReceivePortImpl; | 1308 exports.RawReceivePortImpl = RawReceivePortImpl; |
1271 exports.ReceivePortImpl = ReceivePortImpl; | 1309 exports.ReceivePortImpl = ReceivePortImpl; |
1272 exports.TimerImpl = TimerImpl; | 1310 exports.TimerImpl = TimerImpl; |
1273 exports.hasTimer = hasTimer; | 1311 exports.hasTimer = hasTimer; |
1274 exports.CapabilityImpl = CapabilityImpl; | 1312 exports.CapabilityImpl = CapabilityImpl; |
1275 })(_isolate_helper || (_isolate_helper = {})); | 1313 })(_isolate_helper || (_isolate_helper = {})); |
OLD | NEW |