OLD | NEW |
1 dart_library.library('dart/_isolate_helper', null, /* Imports */[ | 1 dart_library.library('dart/_isolate_helper', null, /* Imports */[ |
2 "dart_runtime/dart", | 2 "dart_runtime/dart", |
3 'dart/core', | 3 'dart/core', |
4 'dart/_interceptors', | 4 'dart/_interceptors', |
5 'dart/_js_helper', | 5 'dart/_js_helper', |
6 'dart/isolate', | 6 'dart/isolate', |
7 'dart/_foreign_helper', | 7 'dart/_foreign_helper', |
8 'dart/collection', | 8 'dart/collection', |
9 'dart/async' | 9 'dart/async' |
10 ], /* Lazy imports */[ | 10 ], /* Lazy imports */[ |
11 'dart/_native_typed_data', | 11 'dart/_native_typed_data', |
12 'dart/_js_embedded_names' | 12 'dart/_js_embedded_names' |
13 ], function(exports, dart, core, _interceptors, _js_helper, isolate, _foreign_he
lper, collection, async, _native_typed_data, _js_embedded_names) { | 13 ], function(exports, dart, core, _interceptors, _js_helper, isolate, _foreign_he
lper, collection, async, _native_typed_data, _js_embedded_names) { |
14 'use strict'; | 14 'use strict'; |
15 let dartx = dart.dartx; | 15 let dartx = dart.dartx; |
16 function _serializeMessage(message) { | 16 function _serializeMessage(message) { |
17 return new _Serializer().serialize(message); | 17 return dart.dcall(new _Serializer().serialize, message); |
18 } | 18 } |
19 dart.fn(_serializeMessage); | 19 dart.fn(_serializeMessage); |
20 function _deserializeMessage(message) { | 20 function _deserializeMessage(message) { |
21 return new _Deserializer().deserialize(message); | 21 return dart.dcall(new _Deserializer().deserialize, message); |
22 } | 22 } |
23 dart.fn(_deserializeMessage); | 23 dart.fn(_deserializeMessage); |
24 function _clone(message) { | 24 function _clone(message) { |
25 let serializer = new _Serializer({serializeSendPorts: false}); | 25 let serializer = new _Serializer({serializeSendPorts: false}); |
26 let deserializer = new _Deserializer(); | 26 let deserializer = new _Deserializer(); |
27 return deserializer.deserialize(serializer.serialize(message)); | 27 return dart.dcall(deserializer.deserialize, dart.dcall(serializer.serialize,
message)); |
28 } | 28 } |
29 dart.fn(_clone); | 29 dart.fn(_clone); |
30 let _serializeSendPorts = Symbol('_serializeSendPorts'); | 30 let _serializeSendPorts = Symbol('_serializeSendPorts'); |
31 let _workerId = Symbol('_workerId'); | 31 let _workerId = Symbol('_workerId'); |
32 let _isolateId = Symbol('_isolateId'); | 32 let _isolateId = Symbol('_isolateId'); |
33 let _receivePortId = Symbol('_receivePortId'); | 33 let _receivePortId = Symbol('_receivePortId'); |
34 let _id = Symbol('_id'); | 34 let _id = Symbol('_id'); |
35 let _receivePort = Symbol('_receivePort'); | 35 let _receivePort = Symbol('_receivePort'); |
36 class _Serializer extends core.Object { | 36 class _Serializer extends core.Object { |
37 _Serializer(opts) { | 37 _Serializer(opts) { |
38 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; | 38 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; |
39 this.serializedObjectIds = core.Map$(dart.dynamic, core.int).identity(); | 39 this.serializedObjectIds = core.Map$(dart.dynamic, core.int).identity(); |
40 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); | 40 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); |
41 } | 41 } |
42 serialize(x) { | 42 serialize(x) { |
43 if (dart.notNull(this.isPrimitive(x))) | 43 if (dart.notNull(dart.dcall(this.isPrimitive, x))) |
44 return this.serializePrimitive(x); | 44 return dart.dcall(this.serializePrimitive, x); |
45 let serializationId = this.serializedObjectIds.get(x); | 45 let serializationId = this.serializedObjectIds.get(x); |
46 if (serializationId != null) | 46 if (serializationId != null) |
47 return this.makeRef(serializationId); | 47 return dart.dcall(this.makeRef, serializationId); |
48 serializationId = this.serializedObjectIds.length; | 48 serializationId = this.serializedObjectIds.length; |
49 this.serializedObjectIds.set(x, serializationId); | 49 this.serializedObjectIds.set(x, serializationId); |
50 if (dart.is(x, _native_typed_data.NativeByteBuffer)) | 50 if (dart.is(x, _native_typed_data.NativeByteBuffer)) |
51 return this.serializeByteBuffer(dart.as(x, _native_typed_data.NativeByte
Buffer)); | 51 return dart.dcall(this.serializeByteBuffer, x); |
52 if (dart.is(x, _native_typed_data.NativeTypedData)) | 52 if (dart.is(x, _native_typed_data.NativeTypedData)) |
53 return this.serializeTypedData(dart.as(x, _native_typed_data.NativeTyped
Data)); | 53 return dart.dcall(this.serializeTypedData, x); |
54 if (dart.is(x, _interceptors.JSIndexable)) | 54 if (dart.is(x, _interceptors.JSIndexable)) |
55 return this.serializeJSIndexable(dart.as(x, _interceptors.JSIndexable)); | 55 return dart.dcall(this.serializeJSIndexable, x); |
56 if (dart.is(x, _js_helper.InternalMap)) | 56 if (dart.is(x, _js_helper.InternalMap)) |
57 return this.serializeMap(dart.as(x, core.Map)); | 57 return dart.dcall(this.serializeMap, x); |
58 if (dart.is(x, _interceptors.JSObject)) | 58 if (dart.is(x, _interceptors.JSObject)) |
59 return this.serializeJSObject(dart.as(x, _interceptors.JSObject)); | 59 return dart.dcall(this.serializeJSObject, x); |
60 if (dart.is(x, _interceptors.Interceptor)) | 60 if (dart.is(x, _interceptors.Interceptor)) |
61 this.unsupported(x); | 61 dart.dcall(this.unsupported, x); |
62 if (dart.is(x, isolate.RawReceivePort)) { | 62 if (dart.is(x, isolate.RawReceivePort)) { |
63 this.unsupported(x, "RawReceivePorts can't be transmitted:"); | 63 dart.dcall(this.unsupported, x, "RawReceivePorts can't be transmitted:")
; |
64 } | 64 } |
65 if (dart.is(x, _NativeJsSendPort)) | 65 if (dart.is(x, _NativeJsSendPort)) |
66 return this.serializeJsSendPort(dart.as(x, _NativeJsSendPort)); | 66 return dart.dcall(this.serializeJsSendPort, x); |
67 if (dart.is(x, _WorkerSendPort)) | 67 if (dart.is(x, _WorkerSendPort)) |
68 return this.serializeWorkerSendPort(dart.as(x, _WorkerSendPort)); | 68 return dart.dcall(this.serializeWorkerSendPort, x); |
69 if (dart.is(x, core.Function)) | 69 if (dart.is(x, core.Function)) |
70 return this.serializeClosure(dart.as(x, core.Function)); | 70 return dart.dcall(this.serializeClosure, x); |
71 return this.serializeDartObject(x); | 71 return dart.dcall(this.serializeDartObject, x); |
72 } | 72 } |
73 unsupported(x, message) { | 73 unsupported(x, message) { |
74 if (message === void 0) | 74 if (message === void 0) |
75 message = null; | 75 message = null; |
76 if (message == null) | 76 if (message == null) |
77 message = "Can't transmit:"; | 77 message = "Can't transmit:"; |
78 dart.throw(new core.UnsupportedError(`${message} ${x}`)); | 78 dart.throw(new core.UnsupportedError(`${message} ${x}`)); |
79 } | 79 } |
80 makeRef(serializationId) { | 80 makeRef(serializationId) { |
81 return ["ref", serializationId]; | 81 return ["ref", serializationId]; |
82 } | 82 } |
83 isPrimitive(x) { | 83 isPrimitive(x) { |
84 return x == null || typeof x == 'string' || dart.is(x, core.num) || typeof
x == 'boolean'; | 84 return x == null || typeof x == 'string' || dart.is(x, core.num) || typeof
x == 'boolean'; |
85 } | 85 } |
86 serializePrimitive(primitive) { | 86 serializePrimitive(primitive) { |
87 return primitive; | 87 return primitive; |
88 } | 88 } |
89 serializeByteBuffer(buffer) { | 89 serializeByteBuffer(buffer) { |
90 return ["buffer", buffer]; | 90 return ["buffer", buffer]; |
91 } | 91 } |
92 serializeTypedData(data) { | 92 serializeTypedData(data) { |
93 return ["typed", data]; | 93 return ["typed", data]; |
94 } | 94 } |
95 serializeJSIndexable(indexable) { | 95 serializeJSIndexable(indexable) { |
96 dart.assert(!(typeof indexable == 'string')); | 96 dart.assert(!(typeof indexable == 'string')); |
97 let serialized = dart.as(this.serializeArray(dart.as(indexable, _intercept
ors.JSArray)), core.List); | 97 let serialized = dart.as(dart.dcall(this.serializeArray, indexable), core.
List); |
98 if (dart.is(indexable, _interceptors.JSFixedArray)) | 98 if (dart.is(indexable, _interceptors.JSFixedArray)) |
99 return ["fixed", serialized]; | 99 return ["fixed", serialized]; |
100 if (dart.is(indexable, _interceptors.JSExtendableArray)) | 100 if (dart.is(indexable, _interceptors.JSExtendableArray)) |
101 return ["extendable", serialized]; | 101 return ["extendable", serialized]; |
102 if (dart.is(indexable, _interceptors.JSMutableArray)) | 102 if (dart.is(indexable, _interceptors.JSMutableArray)) |
103 return ["mutable", serialized]; | 103 return ["mutable", serialized]; |
104 if (dart.is(indexable, _interceptors.JSArray)) | 104 if (dart.is(indexable, _interceptors.JSArray)) |
105 return ["const", serialized]; | 105 return ["const", serialized]; |
106 this.unsupported(indexable, "Can't serialize indexable: "); | 106 dart.dcall(this.unsupported, indexable, "Can't serialize indexable: "); |
107 return null; | 107 return null; |
108 } | 108 } |
109 serializeArray(x) { | 109 serializeArray(x) { |
110 let serialized = []; | 110 let serialized = []; |
111 serialized[dartx.length] = x[dartx.length]; | 111 serialized[dartx.length] = x[dartx.length]; |
112 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { | 112 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { |
113 serialized[dartx.set](i, this.serialize(x[dartx.get](i))); | 113 serialized[dartx.set](i, dart.dcall(this.serialize, x[dartx.get](i))); |
114 } | 114 } |
115 return serialized; | 115 return serialized; |
116 } | 116 } |
117 serializeArrayInPlace(x) { | 117 serializeArrayInPlace(x) { |
118 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { | 118 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { |
119 x[dartx.set](i, this.serialize(x[dartx.get](i))); | 119 x[dartx.set](i, dart.dcall(this.serialize, x[dartx.get](i))); |
120 } | 120 } |
121 return x; | 121 return x; |
122 } | 122 } |
123 serializeMap(x) { | 123 serializeMap(x) { |
124 let serializeTearOff = dart.bind(this, 'serialize'); | 124 let serializeTearOff = dart.bind(this, 'serialize'); |
125 return ['map', x.keys[dartx.map](dart.as(serializeTearOff, __CastType0))[d
artx.toList](), x.values[dartx.map](dart.as(serializeTearOff, dart.functionType(
dart.dynamic, [dart.dynamic])))[dartx.toList]()]; | 125 return ['map', dart.dcall(dart.dcall(x.keys[dartx.map], serializeTearOff)[
dartx.toList]), dart.dcall(dart.dcall(x.values[dartx.map], serializeTearOff)[dar
tx.toList])]; |
126 } | 126 } |
127 serializeJSObject(x) { | 127 serializeJSObject(x) { |
128 if (!!x.constructor && x.constructor !== Object) { | 128 if (dart.notNull(dart.as(!!x.constructor, core.bool)) && dart.notNull(dart
.as(x.constructor !== Object, core.bool))) { |
129 this.unsupported(x, "Only plain JS Objects are supported:"); | 129 dart.dcall(this.unsupported, x, "Only plain JS Objects are supported:"); |
130 } | 130 } |
131 let keys = dart.as(Object.keys(x), core.List); | 131 let keys = dart.as(Object.keys(x), core.List); |
132 let values = []; | 132 let values = []; |
133 values[dartx.length] = keys[dartx.length]; | 133 values[dartx.length] = keys[dartx.length]; |
134 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { | 134 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { |
135 values[dartx.set](i, this.serialize(x[keys[dartx.get](i)])); | 135 values[dartx.set](i, dart.dcall(this.serialize, x[keys[dartx.get](i)])); |
136 } | 136 } |
137 return ['js-object', keys, values]; | 137 return ['js-object', keys, values]; |
138 } | 138 } |
139 serializeWorkerSendPort(x) { | 139 serializeWorkerSendPort(x) { |
140 if (dart.notNull(this[_serializeSendPorts])) { | 140 if (dart.notNull(this[_serializeSendPorts])) { |
141 return ['sendport', x[_workerId], x[_isolateId], x[_receivePortId]]; | 141 return ['sendport', x[_workerId], x[_isolateId], x[_receivePortId]]; |
142 } | 142 } |
143 return ['raw sendport', x]; | 143 return ['raw sendport', x]; |
144 } | 144 } |
145 serializeJsSendPort(x) { | 145 serializeJsSendPort(x) { |
146 if (dart.notNull(this[_serializeSendPorts])) { | 146 if (dart.notNull(this[_serializeSendPorts])) { |
147 let workerId = exports._globalState.currentManagerId; | 147 let workerId = exports._globalState.currentManagerId; |
148 return ['sendport', workerId, x[_isolateId], x[_receivePort][_id]]; | 148 return ['sendport', workerId, x[_isolateId], x[_receivePort][_id]]; |
149 } | 149 } |
150 return ['raw sendport', x]; | 150 return ['raw sendport', x]; |
151 } | 151 } |
152 serializeCapability(x) { | 152 serializeCapability(x) { |
153 return ['capability', x[_id]]; | 153 return ['capability', x[_id]]; |
154 } | 154 } |
155 serializeClosure(x) { | 155 serializeClosure(x) { |
156 let name = IsolateNatives._getJSFunctionName(x); | 156 let name = dart.dcall(IsolateNatives._getJSFunctionName, x); |
157 if (name == null) { | 157 if (name == null) { |
158 this.unsupported(x, "Closures can't be transmitted:"); | 158 dart.dcall(this.unsupported, x, "Closures can't be transmitted:"); |
159 } | 159 } |
160 return ['function', name]; | 160 return ['function', name]; |
161 } | 161 } |
162 serializeDartObject(x) { | 162 serializeDartObject(x) { |
163 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n
ames.CLASS_ID_EXTRACTOR); | 163 let classExtractor = dart.dcall(_foreign_helper.JS_EMBEDDED_GLOBAL, '', _j
s_embedded_names.CLASS_ID_EXTRACTOR); |
164 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_
names.CLASS_FIELDS_EXTRACTOR); | 164 let fieldsExtractor = dart.dcall(_foreign_helper.JS_EMBEDDED_GLOBAL, '', _
js_embedded_names.CLASS_FIELDS_EXTRACTOR); |
165 let classId = classExtractor(x); | 165 let classId = dart.as(classExtractor(x), core.String); |
166 let fields = dart.as(fieldsExtractor(x), core.List); | 166 let fields = dart.as(fieldsExtractor(x), core.List); |
167 return ['dart', classId, this.serializeArrayInPlace(dart.as(fields, _inter
ceptors.JSArray))]; | 167 return ['dart', classId, dart.dcall(this.serializeArrayInPlace, fields)]; |
168 } | 168 } |
169 } | 169 } |
170 dart.setSignature(_Serializer, { | 170 dart.setSignature(_Serializer, { |
171 constructors: () => ({_Serializer: [_Serializer, [], {serializeSendPorts: da
rt.dynamic}]}), | 171 constructors: () => ({_Serializer: [_Serializer, [], {serializeSendPorts: da
rt.dynamic}]}), |
172 methods: () => ({ | 172 methods: () => ({ |
173 serialize: [dart.dynamic, [dart.dynamic]], | 173 serialize: [dart.dynamic, [dart.dynamic]], |
174 unsupported: [dart.void, [dart.dynamic], [core.String]], | 174 unsupported: [dart.void, [dart.dynamic], [core.String]], |
175 makeRef: [dart.dynamic, [core.int]], | 175 makeRef: [dart.dynamic, [core.int]], |
176 isPrimitive: [core.bool, [dart.dynamic]], | 176 isPrimitive: [core.bool, [dart.dynamic]], |
177 serializePrimitive: [dart.dynamic, [dart.dynamic]], | 177 serializePrimitive: [dart.dynamic, [dart.dynamic]], |
(...skipping 12 matching lines...) Expand all Loading... |
190 }) | 190 }) |
191 }); | 191 }); |
192 let _adjustSendPorts = Symbol('_adjustSendPorts'); | 192 let _adjustSendPorts = Symbol('_adjustSendPorts'); |
193 class _Deserializer extends core.Object { | 193 class _Deserializer extends core.Object { |
194 _Deserializer(opts) { | 194 _Deserializer(opts) { |
195 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP
orts : true; | 195 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP
orts : true; |
196 this.deserializedObjects = core.List.new(); | 196 this.deserializedObjects = core.List.new(); |
197 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); | 197 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); |
198 } | 198 } |
199 deserialize(x) { | 199 deserialize(x) { |
200 if (dart.notNull(this.isPrimitive(x))) | 200 if (dart.notNull(dart.dcall(this.isPrimitive, x))) |
201 return this.deserializePrimitive(x); | 201 return dart.dcall(this.deserializePrimitive, x); |
202 if (!dart.is(x, _interceptors.JSArray)) | 202 if (!dart.is(x, _interceptors.JSArray)) |
203 dart.throw(new core.ArgumentError(`Bad serialized message: ${x}`)); | 203 dart.throw(new core.ArgumentError(`Bad serialized message: ${x}`)); |
204 switch (dart.dload(x, 'first')) { | 204 switch (dart.dload(x, 'first')) { |
205 case "ref": | 205 case "ref": |
206 { | 206 { |
207 return this.deserializeRef(x); | 207 return dart.dcall(this.deserializeRef, x); |
208 } | 208 } |
209 case "buffer": | 209 case "buffer": |
210 { | 210 { |
211 return this.deserializeByteBuffer(x); | 211 return dart.dcall(this.deserializeByteBuffer, x); |
212 } | 212 } |
213 case "typed": | 213 case "typed": |
214 { | 214 { |
215 return this.deserializeTypedData(x); | 215 return dart.dcall(this.deserializeTypedData, x); |
216 } | 216 } |
217 case "fixed": | 217 case "fixed": |
218 { | 218 { |
219 return this.deserializeFixed(x); | 219 return dart.dcall(this.deserializeFixed, x); |
220 } | 220 } |
221 case "extendable": | 221 case "extendable": |
222 { | 222 { |
223 return this.deserializeExtendable(x); | 223 return dart.dcall(this.deserializeExtendable, x); |
224 } | 224 } |
225 case "mutable": | 225 case "mutable": |
226 { | 226 { |
227 return this.deserializeMutable(x); | 227 return dart.dcall(this.deserializeMutable, x); |
228 } | 228 } |
229 case "const": | 229 case "const": |
230 { | 230 { |
231 return this.deserializeConst(x); | 231 return dart.dcall(this.deserializeConst, x); |
232 } | 232 } |
233 case "map": | 233 case "map": |
234 { | 234 { |
235 return this.deserializeMap(x); | 235 return dart.dcall(this.deserializeMap, x); |
236 } | 236 } |
237 case "sendport": | 237 case "sendport": |
238 { | 238 { |
239 return this.deserializeSendPort(x); | 239 return dart.dcall(this.deserializeSendPort, x); |
240 } | 240 } |
241 case "raw sendport": | 241 case "raw sendport": |
242 { | 242 { |
243 return this.deserializeRawSendPort(x); | 243 return dart.dcall(this.deserializeRawSendPort, x); |
244 } | 244 } |
245 case "js-object": | 245 case "js-object": |
246 { | 246 { |
247 return this.deserializeJSObject(x); | 247 return dart.dcall(this.deserializeJSObject, x); |
248 } | 248 } |
249 case "function": | 249 case "function": |
250 { | 250 { |
251 return this.deserializeClosure(x); | 251 return dart.dcall(this.deserializeClosure, x); |
252 } | 252 } |
253 case "dart": | 253 case "dart": |
254 { | 254 { |
255 return this.deserializeDartObject(x); | 255 return dart.dcall(this.deserializeDartObject, x); |
256 } | 256 } |
257 default: | 257 default: |
258 { | 258 { |
259 dart.throw(`couldn't deserialize: ${x}`); | 259 dart.throw(`couldn't deserialize: ${x}`); |
260 } | 260 } |
261 } | 261 } |
262 } | 262 } |
263 isPrimitive(x) { | 263 isPrimitive(x) { |
264 return x == null || typeof x == 'string' || dart.is(x, core.num) || typeof
x == 'boolean'; | 264 return x == null || typeof x == 'string' || dart.is(x, core.num) || typeof
x == 'boolean'; |
265 } | 265 } |
266 deserializePrimitive(x) { | 266 deserializePrimitive(x) { |
267 return x; | 267 return x; |
268 } | 268 } |
269 deserializeRef(x) { | 269 deserializeRef(x) { |
270 dart.assert(dart.equals(dart.dindex(x, 0), 'ref')); | 270 dart.assert(dart.equals(dart.dindex(x, 0), 'ref')); |
271 let serializationId = dart.as(dart.dindex(x, 1), core.int); | 271 let serializationId = dart.as(dart.dindex(x, 1), core.int); |
272 return this.deserializedObjects[dartx.get](serializationId); | 272 return this.deserializedObjects[dartx.get](serializationId); |
273 } | 273 } |
274 deserializeByteBuffer(x) { | 274 deserializeByteBuffer(x) { |
275 dart.assert(dart.equals(dart.dindex(x, 0), 'buffer')); | 275 dart.assert(dart.equals(dart.dindex(x, 0), 'buffer')); |
276 let result = dart.as(dart.dindex(x, 1), _native_typed_data.NativeByteBuffe
r); | 276 let result = dart.as(dart.dindex(x, 1), _native_typed_data.NativeByteBuffe
r); |
277 this.deserializedObjects[dartx.add](result); | 277 dart.dcall(this.deserializedObjects[dartx.add], result); |
278 return result; | 278 return result; |
279 } | 279 } |
280 deserializeTypedData(x) { | 280 deserializeTypedData(x) { |
281 dart.assert(dart.equals(dart.dindex(x, 0), 'typed')); | 281 dart.assert(dart.equals(dart.dindex(x, 0), 'typed')); |
282 let result = dart.as(dart.dindex(x, 1), _native_typed_data.NativeTypedData
); | 282 let result = dart.as(dart.dindex(x, 1), _native_typed_data.NativeTypedData
); |
283 this.deserializedObjects[dartx.add](result); | 283 dart.dcall(this.deserializedObjects[dartx.add], result); |
284 return result; | 284 return result; |
285 } | 285 } |
286 deserializeArrayInPlace(x) { | 286 deserializeArrayInPlace(x) { |
287 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { | 287 for (let i = 0; dart.notNull(i) < dart.notNull(x[dartx.length]); i = dart.
notNull(i) + 1) { |
288 x[dartx.set](i, this.deserialize(x[dartx.get](i))); | 288 x[dartx.set](i, dart.dcall(this.deserialize, x[dartx.get](i))); |
289 } | 289 } |
290 return x; | 290 return x; |
291 } | 291 } |
292 deserializeFixed(x) { | 292 deserializeFixed(x) { |
293 dart.assert(dart.equals(dart.dindex(x, 0), 'fixed')); | 293 dart.assert(dart.equals(dart.dindex(x, 0), 'fixed')); |
294 let result = dart.as(dart.dindex(x, 1), core.List); | 294 let result = dart.as(dart.dindex(x, 1), core.List); |
295 this.deserializedObjects[dartx.add](result); | 295 dart.dcall(this.deserializedObjects[dartx.add], result); |
296 return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.a
s(result, _interceptors.JSArray))); | 296 return _interceptors.JSArray.markFixed(dart.dcall(this.deserializeArrayInP
lace, result)); |
297 } | 297 } |
298 deserializeExtendable(x) { | 298 deserializeExtendable(x) { |
299 dart.assert(dart.equals(dart.dindex(x, 0), 'extendable')); | 299 dart.assert(dart.equals(dart.dindex(x, 0), 'extendable')); |
300 let result = dart.as(dart.dindex(x, 1), core.List); | 300 let result = dart.as(dart.dindex(x, 1), core.List); |
301 this.deserializedObjects[dartx.add](result); | 301 dart.dcall(this.deserializedObjects[dartx.add], result); |
302 return _interceptors.JSArray.markGrowable(this.deserializeArrayInPlace(dar
t.as(result, _interceptors.JSArray))); | 302 return _interceptors.JSArray.markGrowable(dart.dcall(this.deserializeArray
InPlace, result)); |
303 } | 303 } |
304 deserializeMutable(x) { | 304 deserializeMutable(x) { |
305 dart.assert(dart.equals(dart.dindex(x, 0), 'mutable')); | 305 dart.assert(dart.equals(dart.dindex(x, 0), 'mutable')); |
306 let result = dart.as(dart.dindex(x, 1), core.List); | 306 let result = dart.as(dart.dindex(x, 1), core.List); |
307 this.deserializedObjects[dartx.add](result); | 307 dart.dcall(this.deserializedObjects[dartx.add], result); |
308 return this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)
); | 308 return dart.dcall(this.deserializeArrayInPlace, result); |
309 } | 309 } |
310 deserializeConst(x) { | 310 deserializeConst(x) { |
311 dart.assert(dart.equals(dart.dindex(x, 0), 'const')); | 311 dart.assert(dart.equals(dart.dindex(x, 0), 'const')); |
312 let result = dart.as(dart.dindex(x, 1), core.List); | 312 let result = dart.as(dart.dindex(x, 1), core.List); |
313 this.deserializedObjects[dartx.add](result); | 313 dart.dcall(this.deserializedObjects[dartx.add], result); |
314 return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.a
s(result, _interceptors.JSArray))); | 314 return _interceptors.JSArray.markFixed(dart.dcall(this.deserializeArrayInP
lace, result)); |
315 } | 315 } |
316 deserializeMap(x) { | 316 deserializeMap(x) { |
317 dart.assert(dart.equals(dart.dindex(x, 0), 'map')); | 317 dart.assert(dart.equals(dart.dindex(x, 0), 'map')); |
318 let keys = dart.as(dart.dindex(x, 1), core.List); | 318 let keys = dart.as(dart.dindex(x, 1), core.List); |
319 let values = dart.as(dart.dindex(x, 2), core.List); | 319 let values = dart.as(dart.dindex(x, 2), core.List); |
320 let result = dart.map(); | 320 let result = dart.map(); |
321 this.deserializedObjects[dartx.add](result); | 321 dart.dcall(this.deserializedObjects[dartx.add], result); |
322 keys = keys[dartx.map](dart.bind(this, 'deserialize'))[dartx.toList](); | 322 keys = dart.dcall(dart.dcall(keys[dartx.map], dart.bind(this, 'deserialize
'))[dartx.toList]); |
323 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { | 323 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { |
324 result.set(keys[dartx.get](i), this.deserialize(values[dartx.get](i))); | 324 result.set(keys[dartx.get](i), dart.dcall(this.deserialize, values[dartx
.get](i))); |
325 } | 325 } |
326 return result; | 326 return result; |
327 } | 327 } |
328 deserializeSendPort(x) { | 328 deserializeSendPort(x) { |
329 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); | 329 dart.assert(dart.equals(dart.dindex(x, 0), 'sendport')); |
330 let managerId = dart.as(dart.dindex(x, 1), core.int); | 330 let managerId = dart.as(dart.dindex(x, 1), core.int); |
331 let isolateId = dart.as(dart.dindex(x, 2), core.int); | 331 let isolateId = dart.as(dart.dindex(x, 2), core.int); |
332 let receivePortId = dart.as(dart.dindex(x, 3), core.int); | 332 let receivePortId = dart.as(dart.dindex(x, 3), core.int); |
333 let result = null; | 333 let result = null; |
334 if (managerId == exports._globalState.currentManagerId) { | 334 if (managerId == exports._globalState.currentManagerId) { |
335 let isolate = exports._globalState.isolates.get(isolateId); | 335 let isolate = exports._globalState.isolates.get(isolateId); |
336 if (isolate == null) | 336 if (isolate == null) |
337 return null; | 337 return null; |
338 let receivePort = isolate.lookup(receivePortId); | 338 let receivePort = dart.dsend(isolate, 'lookup', receivePortId); |
339 if (receivePort == null) | 339 if (receivePort == null) |
340 return null; | 340 return null; |
341 result = new _NativeJsSendPort(receivePort, isolateId); | 341 result = new _NativeJsSendPort(dart.as(receivePort, RawReceivePortImpl),
isolateId); |
342 } else { | 342 } else { |
343 result = new _WorkerSendPort(managerId, isolateId, receivePortId); | 343 result = new _WorkerSendPort(managerId, isolateId, receivePortId); |
344 } | 344 } |
345 this.deserializedObjects[dartx.add](result); | 345 dart.dcall(this.deserializedObjects[dartx.add], result); |
346 return result; | 346 return result; |
347 } | 347 } |
348 deserializeRawSendPort(x) { | 348 deserializeRawSendPort(x) { |
349 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport')); | 349 dart.assert(dart.equals(dart.dindex(x, 0), 'raw sendport')); |
350 let result = dart.as(dart.dindex(x, 1), isolate.SendPort); | 350 let result = dart.as(dart.dindex(x, 1), isolate.SendPort); |
351 this.deserializedObjects[dartx.add](result); | 351 dart.dcall(this.deserializedObjects[dartx.add], result); |
352 return result; | 352 return result; |
353 } | 353 } |
354 deserializeJSObject(x) { | 354 deserializeJSObject(x) { |
355 dart.assert(dart.equals(dart.dindex(x, 0), 'js-object')); | 355 dart.assert(dart.equals(dart.dindex(x, 0), 'js-object')); |
356 let keys = dart.as(dart.dindex(x, 1), core.List); | 356 let keys = dart.as(dart.dindex(x, 1), core.List); |
357 let values = dart.as(dart.dindex(x, 2), core.List); | 357 let values = dart.as(dart.dindex(x, 2), core.List); |
358 let o = {}; | 358 let o = {}; |
359 this.deserializedObjects[dartx.add](o); | 359 dart.dcall(this.deserializedObjects[dartx.add], o); |
360 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { | 360 for (let i = 0; dart.notNull(i) < dart.notNull(keys[dartx.length]); i = da
rt.notNull(i) + 1) { |
361 o[keys[dartx.get](i)] = this.deserialize(values[dartx.get](i)); | 361 o[keys[dartx.get](i)] = dart.dcall(this.deserialize, values[dartx.get](i
)); |
362 } | 362 } |
363 return o; | 363 return o; |
364 } | 364 } |
365 deserializeClosure(x) { | 365 deserializeClosure(x) { |
366 dart.assert(dart.equals(dart.dindex(x, 0), 'function')); | 366 dart.assert(dart.equals(dart.dindex(x, 0), 'function')); |
367 let name = dart.as(dart.dindex(x, 1), core.String); | 367 let name = dart.as(dart.dindex(x, 1), core.String); |
368 let result = dart.as(IsolateNatives._getJSFunctionFromName(name), core.Fun
ction); | 368 let result = dart.as(dart.dcall(IsolateNatives._getJSFunctionFromName, nam
e), core.Function); |
369 this.deserializedObjects[dartx.add](result); | 369 dart.dcall(this.deserializedObjects[dartx.add], result); |
370 return result; | 370 return result; |
371 } | 371 } |
372 deserializeDartObject(x) { | 372 deserializeDartObject(x) { |
373 dart.assert(dart.equals(dart.dindex(x, 0), 'dart')); | 373 dart.assert(dart.equals(dart.dindex(x, 0), 'dart')); |
374 let classId = dart.as(dart.dindex(x, 1), core.String); | 374 let classId = dart.as(dart.dindex(x, 1), core.String); |
375 let fields = dart.as(dart.dindex(x, 2), core.List); | 375 let fields = dart.as(dart.dindex(x, 2), core.List); |
376 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embed
ded_names.INSTANCE_FROM_CLASS_ID); | 376 let instanceFromClassId = dart.dcall(_foreign_helper.JS_EMBEDDED_GLOBAL, '
', _js_embedded_names.INSTANCE_FROM_CLASS_ID); |
377 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded
_names.INITIALIZE_EMPTY_INSTANCE); | 377 let initializeObject = dart.dcall(_foreign_helper.JS_EMBEDDED_GLOBAL, '',
_js_embedded_names.INITIALIZE_EMPTY_INSTANCE); |
378 let emptyInstance = instanceFromClassId(classId); | 378 let emptyInstance = instanceFromClassId(classId); |
379 this.deserializedObjects[dartx.add](emptyInstance); | 379 dart.dcall(this.deserializedObjects[dartx.add], emptyInstance); |
380 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray)); | 380 dart.dcall(this.deserializeArrayInPlace, fields); |
381 return initializeObject(classId, emptyInstance, fields); | 381 return initializeObject(classId, emptyInstance, fields); |
382 } | 382 } |
383 } | 383 } |
384 dart.setSignature(_Deserializer, { | 384 dart.setSignature(_Deserializer, { |
385 constructors: () => ({_Deserializer: [_Deserializer, [], {adjustSendPorts: d
art.dynamic}]}), | 385 constructors: () => ({_Deserializer: [_Deserializer, [], {adjustSendPorts: d
art.dynamic}]}), |
386 methods: () => ({ | 386 methods: () => ({ |
387 deserialize: [dart.dynamic, [dart.dynamic]], | 387 deserialize: [dart.dynamic, [dart.dynamic]], |
388 isPrimitive: [core.bool, [dart.dynamic]], | 388 isPrimitive: [core.bool, [dart.dynamic]], |
389 deserializePrimitive: [dart.dynamic, [dart.dynamic]], | 389 deserializePrimitive: [dart.dynamic, [dart.dynamic]], |
390 deserializeRef: [dart.dynamic, [dart.dynamic]], | 390 deserializeRef: [dart.dynamic, [dart.dynamic]], |
391 deserializeByteBuffer: [_native_typed_data.NativeByteBuffer, [dart.dynamic
]], | 391 deserializeByteBuffer: [_native_typed_data.NativeByteBuffer, [dart.dynamic
]], |
392 deserializeTypedData: [_native_typed_data.NativeTypedData, [dart.dynamic]]
, | 392 deserializeTypedData: [_native_typed_data.NativeTypedData, [dart.dynamic]]
, |
393 deserializeArrayInPlace: [core.List, [_interceptors.JSArray]], | 393 deserializeArrayInPlace: [core.List, [_interceptors.JSArray]], |
394 deserializeFixed: [core.List, [dart.dynamic]], | 394 deserializeFixed: [core.List, [dart.dynamic]], |
395 deserializeExtendable: [core.List, [dart.dynamic]], | 395 deserializeExtendable: [core.List, [dart.dynamic]], |
396 deserializeMutable: [core.List, [dart.dynamic]], | 396 deserializeMutable: [core.List, [dart.dynamic]], |
397 deserializeConst: [core.List, [dart.dynamic]], | 397 deserializeConst: [core.List, [dart.dynamic]], |
398 deserializeMap: [core.Map, [dart.dynamic]], | 398 deserializeMap: [core.Map, [dart.dynamic]], |
399 deserializeSendPort: [isolate.SendPort, [dart.dynamic]], | 399 deserializeSendPort: [isolate.SendPort, [dart.dynamic]], |
400 deserializeRawSendPort: [isolate.SendPort, [dart.dynamic]], | 400 deserializeRawSendPort: [isolate.SendPort, [dart.dynamic]], |
401 deserializeJSObject: [dart.dynamic, [dart.dynamic]], | 401 deserializeJSObject: [dart.dynamic, [dart.dynamic]], |
402 deserializeClosure: [core.Function, [dart.dynamic]], | 402 deserializeClosure: [core.Function, [dart.dynamic]], |
403 deserializeDartObject: [dart.dynamic, [dart.dynamic]] | 403 deserializeDartObject: [dart.dynamic, [dart.dynamic]] |
404 }) | 404 }) |
405 }); | 405 }); |
406 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.dyn
amic, [dart.dynamic])); | |
407 function _callInIsolate(isolate, func) { | 406 function _callInIsolate(isolate, func) { |
408 let result = isolate.eval(func); | 407 let result = dart.dcall(isolate.eval, func); |
409 exports._globalState.topEventLoop.run(); | 408 dart.dcall(exports._globalState.topEventLoop.run); |
410 return result; | 409 return result; |
411 } | 410 } |
412 dart.fn(_callInIsolate, () => dart.definiteFunctionType(dart.dynamic, [_Isolat
eContext, core.Function])); | 411 dart.fn(_callInIsolate, () => dart.definiteFunctionType(dart.dynamic, [_Isolat
eContext, core.Function])); |
413 let _activeJsAsyncCount = Symbol('_activeJsAsyncCount'); | 412 let _activeJsAsyncCount = Symbol('_activeJsAsyncCount'); |
414 function enterJsAsync() { | 413 function enterJsAsync() { |
415 let o = exports._globalState.topEventLoop; | 414 let o = exports._globalState.topEventLoop; |
416 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) + 1; | 415 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) + 1; |
417 } | 416 } |
418 dart.fn(enterJsAsync); | 417 dart.fn(enterJsAsync); |
419 function leaveJsAsync() { | 418 function leaveJsAsync() { |
(...skipping 14 matching lines...) Expand all Loading... |
434 args = args; | 433 args = args; |
435 if (args == null) | 434 if (args == null) |
436 args = []; | 435 args = []; |
437 if (!dart.is(args, core.List)) { | 436 if (!dart.is(args, core.List)) { |
438 dart.throw(new core.ArgumentError(`Arguments to main must be a List: ${arg
s}`)); | 437 dart.throw(new core.ArgumentError(`Arguments to main must be a List: ${arg
s}`)); |
439 } | 438 } |
440 exports._globalState = new _Manager(dart.as(entry, core.Function)); | 439 exports._globalState = new _Manager(dart.as(entry, core.Function)); |
441 if (dart.notNull(exports._globalState.isWorker)) | 440 if (dart.notNull(exports._globalState.isWorker)) |
442 return; | 441 return; |
443 let rootContext = new _IsolateContext(); | 442 let rootContext = new _IsolateContext(); |
444 exports._globalState.rootContext = rootContext; | 443 exports._globalState.rootContext = dart.as(rootContext, _IsolateContext); |
445 exports._globalState.currentContext = rootContext; | 444 exports._globalState.currentContext = dart.as(rootContext, _IsolateContext); |
446 if (dart.is(entry, _MainFunctionArgs)) { | 445 if (dart.is(entry, _MainFunctionArgs)) { |
447 rootContext.eval(dart.fn(() => { | 446 dart.dsend(rootContext, 'eval', dart.fn(() => { |
448 dart.dcall(entry, args); | 447 dart.dcall(entry, args); |
449 })); | 448 })); |
450 } else if (dart.is(entry, _MainFunctionArgsMessage)) { | 449 } else if (dart.is(entry, _MainFunctionArgsMessage)) { |
451 rootContext.eval(dart.fn(() => { | 450 dart.dsend(rootContext, 'eval', dart.fn(() => { |
452 dart.dcall(entry, args, null); | 451 dart.dcall(entry, args, null); |
453 })); | 452 })); |
454 } else { | 453 } else { |
455 rootContext.eval(dart.as(entry, core.Function)); | 454 dart.dsend(rootContext, 'eval', entry); |
456 } | 455 } |
457 exports._globalState.topEventLoop.run(); | 456 dart.dcall(exports._globalState.topEventLoop.run); |
458 } | 457 } |
459 dart.fn(startRootIsolate, dart.void, [dart.dynamic, dart.dynamic]); | 458 dart.fn(startRootIsolate, dart.void, [dart.dynamic, dart.dynamic]); |
460 dart.copyProperties(exports, { | 459 dart.copyProperties(exports, { |
461 get _globalState() { | 460 get _globalState() { |
462 return dart.as(dart.globalState, _Manager); | 461 return dart.as(dart.globalState, _Manager); |
463 }, | 462 }, |
464 set _globalState(val) { | 463 set _globalState(val) { |
465 dart.globalState = val; | 464 dart.globalState = val; |
466 } | 465 } |
467 }); | 466 }); |
(...skipping 10 matching lines...) Expand all Loading... |
478 this.nextManagerId = 1; | 477 this.nextManagerId = 1; |
479 this.currentContext = null; | 478 this.currentContext = null; |
480 this.rootContext = null; | 479 this.rootContext = null; |
481 this.topEventLoop = null; | 480 this.topEventLoop = null; |
482 this.fromCommandLine = null; | 481 this.fromCommandLine = null; |
483 this.isWorker = null; | 482 this.isWorker = null; |
484 this.supportsWorkers = null; | 483 this.supportsWorkers = null; |
485 this.isolates = null; | 484 this.isolates = null; |
486 this.mainManager = null; | 485 this.mainManager = null; |
487 this.managers = null; | 486 this.managers = null; |
488 this[_nativeDetectEnvironment](); | 487 dart.dcall(this[_nativeDetectEnvironment]); |
489 this.topEventLoop = new _EventLoop(); | 488 this.topEventLoop = new _EventLoop(); |
490 this.isolates = core.Map$(core.int, _IsolateContext).new(); | 489 this.isolates = core.Map$(core.int, _IsolateContext).new(); |
491 this.managers = core.Map$(core.int, dart.dynamic).new(); | 490 this.managers = core.Map$(core.int, dart.dynamic).new(); |
492 if (dart.notNull(this.isWorker)) { | 491 if (dart.notNull(this.isWorker)) { |
493 this.mainManager = new _MainManagerStub(); | 492 this.mainManager = new _MainManagerStub(); |
494 this[_nativeInitWorkerMessageHandler](); | 493 dart.dcall(this[_nativeInitWorkerMessageHandler]); |
495 } | 494 } |
496 } | 495 } |
497 [_nativeDetectEnvironment]() { | 496 [_nativeDetectEnvironment]() { |
498 let isWindowDefined = exports.globalWindow != null; | 497 let isWindowDefined = exports.globalWindow != null; |
499 let isWorkerDefined = exports.globalWorker != null; | 498 let isWorkerDefined = exports.globalWorker != null; |
500 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); | 499 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); |
501 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && IsolateNatives.thisScript != null; | 500 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && IsolateNatives.thisScript != null; |
502 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); | 501 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); |
503 } | 502 } |
504 [_nativeInitWorkerMessageHandler]() { | 503 [_nativeInitWorkerMessageHandler]() { |
505 let func = (function(f, a) { | 504 let func = (function(f, a) { |
506 return function(e) { | 505 return function(e) { |
507 f(a, e); | 506 f(a, e); |
508 }; | 507 }; |
509 })(IsolateNatives._processWorkerMessage, this.mainManager); | 508 })(IsolateNatives._processWorkerMessage, this.mainManager); |
510 self.onmessage = func; | 509 self.onmessage = func; |
511 self.dartPrint = self.dartPrint || (function(serialize) { | 510 self.dartPrint = self.dartPrint || (function(serialize) { |
512 return function(object) { | 511 return function(object) { |
513 if (self.console && self.console.log) { | 512 if (self.console && self.console.log) { |
514 self.console.log(object); | 513 self.console.log(object); |
515 } else { | 514 } else { |
516 self.postMessage(serialize(object)); | 515 self.postMessage(serialize(object)); |
517 } | 516 } |
518 }; | 517 }; |
519 })(_Manager._serializePrintMessage); | 518 })(_Manager._serializePrintMessage); |
520 } | 519 } |
521 static _serializePrintMessage(object) { | 520 static _serializePrintMessage(object) { |
522 return _serializeMessage(dart.map({command: "print", msg: object})); | 521 return dart.dcall(_serializeMessage, dart.map({command: "print", msg: obje
ct})); |
523 } | 522 } |
524 maybeCloseWorker() { | 523 maybeCloseWorker() { |
525 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] == 0) { | 524 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] == 0) { |
526 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); | 525 dart.dcall(this.mainManager.postMessage, dart.dcall(_serializeMessage, d
art.map({command: 'close'}))); |
527 } | 526 } |
528 } | 527 } |
529 } | 528 } |
530 dart.setSignature(_Manager, { | 529 dart.setSignature(_Manager, { |
531 constructors: () => ({_Manager: [_Manager, [core.Function]]}), | 530 constructors: () => ({_Manager: [_Manager, [core.Function]]}), |
532 methods: () => ({ | 531 methods: () => ({ |
533 [_nativeDetectEnvironment]: [dart.void, []], | 532 [_nativeDetectEnvironment]: [dart.void, []], |
534 [_nativeInitWorkerMessageHandler]: [dart.void, []], | 533 [_nativeInitWorkerMessageHandler]: [dart.void, []], |
535 maybeCloseWorker: [dart.void, []] | 534 maybeCloseWorker: [dart.void, []] |
536 }), | 535 }), |
537 statics: () => ({_serializePrintMessage: [dart.dynamic, [dart.dynamic]]}), | 536 statics: () => ({_serializePrintMessage: [dart.dynamic, [dart.dynamic]]}), |
538 names: ['_serializePrintMessage'] | 537 names: ['_serializePrintMessage'] |
539 }); | 538 }); |
540 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); | 539 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); |
541 let _isExecutingEvent = Symbol('_isExecutingEvent'); | 540 let _isExecutingEvent = Symbol('_isExecutingEvent'); |
542 let _updateGlobalState = Symbol('_updateGlobalState'); | 541 let _updateGlobalState = Symbol('_updateGlobalState'); |
543 let _setGlobals = Symbol('_setGlobals'); | 542 let _setGlobals = Symbol('_setGlobals'); |
544 let _addRegistration = Symbol('_addRegistration'); | 543 let _addRegistration = Symbol('_addRegistration'); |
545 let _close = Symbol('_close'); | 544 let _close = Symbol('_close'); |
546 class _IsolateContext extends core.Object { | 545 class _IsolateContext extends core.Object { |
547 _IsolateContext() { | 546 _IsolateContext() { |
548 this.id = (() => { | 547 this.id = (() => { |
549 let o = exports._globalState, x = o.nextIsolateId; | 548 let o = exports._globalState, x = o.nextIsolateId; |
550 o.nextIsolateId = dart.notNull(x) + 1; | 549 o.nextIsolateId = dart.notNull(x) + 1; |
551 return x; | 550 return x; |
552 })(); | 551 })(); |
553 this.ports = core.Map$(core.int, RawReceivePortImpl).new(); | 552 this.ports = core.Map$(core.int, RawReceivePortImpl).new(); |
554 this.weakPorts = core.Set$(core.int).new(); | 553 this.weakPorts = core.Set$(core.int).new(); |
555 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); | 554 this.isolateStatics = dart.dcall(_foreign_helper.JS_CREATE_ISOLATE); |
556 this.controlPort = new RawReceivePortImpl._controlPort(); | 555 this.controlPort = new RawReceivePortImpl._controlPort(); |
557 this.pauseCapability = isolate.Capability.new(); | 556 this.pauseCapability = isolate.Capability.new(); |
558 this.terminateCapability = isolate.Capability.new(); | 557 this.terminateCapability = isolate.Capability.new(); |
559 this.delayedEvents = dart.list([], _IsolateEvent); | 558 this.delayedEvents = dart.list([], _IsolateEvent); |
560 this.pauseTokens = core.Set$(isolate.Capability).new(); | 559 this.pauseTokens = core.Set$(isolate.Capability).new(); |
561 this.errorPorts = core.Set$(isolate.SendPort).new(); | 560 this.errorPorts = core.Set$(isolate.SendPort).new(); |
562 this.initialized = false; | 561 this.initialized = false; |
563 this.isPaused = false; | 562 this.isPaused = false; |
564 this.doneHandlers = null; | 563 this.doneHandlers = null; |
565 this[_scheduledControlEvents] = null; | 564 this[_scheduledControlEvents] = null; |
566 this[_isExecutingEvent] = false; | 565 this[_isExecutingEvent] = false; |
567 this.errorsAreFatal = true; | 566 this.errorsAreFatal = true; |
568 this.registerWeak(this.controlPort[_id], this.controlPort); | 567 dart.dcall(this.registerWeak, this.controlPort[_id], this.controlPort); |
569 } | 568 } |
570 addPause(authentification, resume) { | 569 addPause(authentification, resume) { |
571 if (!dart.equals(this.pauseCapability, authentification)) | 570 if (!dart.equals(this.pauseCapability, authentification)) |
572 return; | 571 return; |
573 if (dart.notNull(this.pauseTokens.add(resume)) && !dart.notNull(this.isPau
sed)) { | 572 if (dart.notNull(dart.dcall(this.pauseTokens.add, resume)) && !dart.notNul
l(this.isPaused)) { |
574 this.isPaused = true; | 573 this.isPaused = true; |
575 } | 574 } |
576 this[_updateGlobalState](); | 575 dart.dcall(this[_updateGlobalState]); |
577 } | 576 } |
578 removePause(resume) { | 577 removePause(resume) { |
579 if (!dart.notNull(this.isPaused)) | 578 if (!dart.notNull(this.isPaused)) |
580 return; | 579 return; |
581 this.pauseTokens.remove(resume); | 580 dart.dcall(this.pauseTokens.remove, resume); |
582 if (dart.notNull(this.pauseTokens.isEmpty)) { | 581 if (dart.notNull(this.pauseTokens.isEmpty)) { |
583 while (dart.notNull(this.delayedEvents[dartx.isNotEmpty])) { | 582 while (dart.notNull(this.delayedEvents[dartx.isNotEmpty])) { |
584 let event = this.delayedEvents[dartx.removeLast](); | 583 let event = dart.dcall(this.delayedEvents[dartx.removeLast]); |
585 exports._globalState.topEventLoop.prequeue(event); | 584 dart.dcall(exports._globalState.topEventLoop.prequeue, event); |
586 } | 585 } |
587 this.isPaused = false; | 586 this.isPaused = false; |
588 } | 587 } |
589 this[_updateGlobalState](); | 588 dart.dcall(this[_updateGlobalState]); |
590 } | 589 } |
591 addDoneListener(responsePort) { | 590 addDoneListener(responsePort) { |
592 if (this.doneHandlers == null) { | 591 if (this.doneHandlers == null) { |
593 this.doneHandlers = []; | 592 this.doneHandlers = []; |
594 } | 593 } |
595 if (dart.notNull(dart.as(dart.dsend(this.doneHandlers, 'contains', respons
ePort), core.bool))) | 594 if (dart.notNull(dart.as(dart.dsend(this.doneHandlers, 'contains', respons
ePort), core.bool))) |
596 return; | 595 return; |
597 dart.dsend(this.doneHandlers, 'add', responsePort); | 596 dart.dsend(this.doneHandlers, 'add', responsePort); |
598 } | 597 } |
599 removeDoneListener(responsePort) { | 598 removeDoneListener(responsePort) { |
600 if (this.doneHandlers == null) | 599 if (this.doneHandlers == null) |
601 return; | 600 return; |
602 dart.dsend(this.doneHandlers, 'remove', responsePort); | 601 dart.dsend(this.doneHandlers, 'remove', responsePort); |
603 } | 602 } |
604 setErrorsFatal(authentification, errorsAreFatal) { | 603 setErrorsFatal(authentification, errorsAreFatal) { |
605 if (!dart.equals(this.terminateCapability, authentification)) | 604 if (!dart.equals(this.terminateCapability, authentification)) |
606 return; | 605 return; |
607 this.errorsAreFatal = errorsAreFatal; | 606 this.errorsAreFatal = errorsAreFatal; |
608 } | 607 } |
609 handlePing(responsePort, pingType) { | 608 handlePing(responsePort, pingType) { |
610 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { | 609 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { |
611 responsePort.send(null); | 610 dart.dcall(responsePort.send, null); |
612 return; | 611 return; |
613 } | 612 } |
614 function respond() { | 613 function respond() { |
615 responsePort.send(null); | 614 dart.dcall(responsePort.send, null); |
616 } | 615 } |
617 dart.fn(respond, dart.void, []); | 616 dart.fn(respond, dart.void, []); |
618 if (pingType == isolate.Isolate.AS_EVENT) { | 617 if (pingType == isolate.Isolate.AS_EVENT) { |
619 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); | 618 dart.dcall(exports._globalState.topEventLoop.enqueue, this, respond, "pi
ng"); |
620 return; | 619 return; |
621 } | 620 } |
622 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); | 621 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); |
623 if (this[_scheduledControlEvents] == null) { | 622 if (this[_scheduledControlEvents] == null) { |
624 this[_scheduledControlEvents] = collection.Queue.new(); | 623 this[_scheduledControlEvents] = collection.Queue.new(); |
625 } | 624 } |
626 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); | 625 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); |
627 } | 626 } |
628 handleKill(authentification, priority) { | 627 handleKill(authentification, priority) { |
629 if (!dart.equals(this.terminateCapability, authentification)) | 628 if (!dart.equals(this.terminateCapability, authentification)) |
630 return; | 629 return; |
631 if (priority == isolate.Isolate.IMMEDIATE || priority == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { | 630 if (priority == isolate.Isolate.IMMEDIATE || priority == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { |
632 this.kill(); | 631 dart.dcall(this.kill); |
633 return; | 632 return; |
634 } | 633 } |
635 if (priority == isolate.Isolate.AS_EVENT) { | 634 if (priority == isolate.Isolate.AS_EVENT) { |
636 exports._globalState.topEventLoop.enqueue(this, dart.bind(this, 'kill'),
"kill"); | 635 dart.dcall(exports._globalState.topEventLoop.enqueue, this, dart.bind(th
is, 'kill'), "kill"); |
637 return; | 636 return; |
638 } | 637 } |
639 dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT); | 638 dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT); |
640 if (this[_scheduledControlEvents] == null) { | 639 if (this[_scheduledControlEvents] == null) { |
641 this[_scheduledControlEvents] = collection.Queue.new(); | 640 this[_scheduledControlEvents] = collection.Queue.new(); |
642 } | 641 } |
643 dart.dsend(this[_scheduledControlEvents], 'addLast', dart.bind(this, 'kill
')); | 642 dart.dsend(this[_scheduledControlEvents], 'addLast', dart.bind(this, 'kill
')); |
644 } | 643 } |
645 addErrorListener(port) { | 644 addErrorListener(port) { |
646 this.errorPorts.add(port); | 645 dart.dcall(this.errorPorts.add, port); |
647 } | 646 } |
648 removeErrorListener(port) { | 647 removeErrorListener(port) { |
649 this.errorPorts.remove(port); | 648 dart.dcall(this.errorPorts.remove, port); |
650 } | 649 } |
651 handleUncaughtError(error, stackTrace) { | 650 handleUncaughtError(error, stackTrace) { |
652 if (dart.notNull(this.errorPorts.isEmpty)) { | 651 if (dart.notNull(this.errorPorts.isEmpty)) { |
653 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { | 652 if (dart.notNull(this.errorsAreFatal) && dart.notNull(dart.dcall(core.id
entical, this, exports._globalState.rootContext))) { |
654 return; | 653 return; |
655 } | 654 } |
656 if (self.console && self.console.error) { | 655 if (dart.notNull(dart.as(self.console && self.console.error, core.bool))
) { |
657 self.console.error(error, stackTrace); | 656 self.console.error(error, stackTrace); |
658 } else { | 657 } else { |
659 core.print(error); | 658 dart.dcall(core.print, error); |
660 if (stackTrace != null) | 659 if (stackTrace != null) |
661 core.print(stackTrace); | 660 dart.dcall(core.print, stackTrace); |
662 } | 661 } |
663 return; | 662 return; |
664 } | 663 } |
665 let message = core.List.new(2); | 664 let message = core.List.new(2); |
666 message[dartx.set](0, dart.toString(error)); | 665 message[dartx.set](0, dart.dsend(error, 'toString')); |
667 message[dartx.set](1, stackTrace == null ? null : dart.toString(stackTrace
)); | 666 message[dartx.set](1, stackTrace == null ? null : dart.dcall(stackTrace.to
String)); |
668 for (let port of this.errorPorts) | 667 for (let port of this.errorPorts) |
669 port.send(message); | 668 dart.dcall(port.send, message); |
670 } | 669 } |
671 eval(code) { | 670 eval(code) { |
672 let old = exports._globalState.currentContext; | 671 let old = exports._globalState.currentContext; |
673 exports._globalState.currentContext = this; | 672 exports._globalState.currentContext = this; |
674 this[_setGlobals](); | 673 dart.dcall(this[_setGlobals]); |
675 let result = null; | 674 let result = null; |
676 this[_isExecutingEvent] = true; | 675 this[_isExecutingEvent] = true; |
677 try { | 676 try { |
678 result = dart.dcall(code); | 677 result = dart.dcall(code); |
679 } catch (e) { | 678 } catch (e) { |
680 let s = dart.stackTrace(e); | 679 let s = dart.stackTrace(e); |
681 this.handleUncaughtError(e, s); | 680 dart.dcall(this.handleUncaughtError, e, s); |
682 if (dart.notNull(this.errorsAreFatal)) { | 681 if (dart.notNull(this.errorsAreFatal)) { |
683 this.kill(); | 682 dart.dcall(this.kill); |
684 if (dart.notNull(core.identical(this, exports._globalState.rootContext
))) { | 683 if (dart.notNull(dart.dcall(core.identical, this, exports._globalState
.rootContext))) { |
685 throw e; | 684 throw e; |
686 } | 685 } |
687 } | 686 } |
688 } | 687 } |
689 finally { | 688 finally { |
690 this[_isExecutingEvent] = false; | 689 this[_isExecutingEvent] = false; |
691 exports._globalState.currentContext = old; | 690 exports._globalState.currentContext = dart.as(old, _IsolateContext); |
692 if (old != null) | 691 if (old != null) |
693 old[_setGlobals](); | 692 dart.dsend(old, _setGlobals); |
694 if (this[_scheduledControlEvents] != null) { | 693 if (this[_scheduledControlEvents] != null) { |
695 while (dart.notNull(dart.as(dart.dload(this[_scheduledControlEvents],
'isNotEmpty'), core.bool))) { | 694 while (dart.notNull(dart.as(dart.dload(this[_scheduledControlEvents],
'isNotEmpty'), core.bool))) { |
696 dart.dcall(dart.dsend(this[_scheduledControlEvents], 'removeFirst'))
; | 695 dart.dcall(dart.dsend(this[_scheduledControlEvents], 'removeFirst'))
; |
697 } | 696 } |
698 } | 697 } |
699 } | 698 } |
700 return result; | 699 return result; |
701 } | 700 } |
702 [_setGlobals]() { | 701 [_setGlobals]() { |
703 _foreign_helper.JS_SET_CURRENT_ISOLATE(this.isolateStatics); | 702 dart.dcall(_foreign_helper.JS_SET_CURRENT_ISOLATE, this.isolateStatics); |
704 } | 703 } |
705 handleControlMessage(message) { | 704 handleControlMessage(message) { |
706 switch (dart.dindex(message, 0)) { | 705 switch (dart.dindex(message, 0)) { |
707 case "pause": | 706 case "pause": |
708 { | 707 { |
709 this.addPause(dart.as(dart.dindex(message, 1), isolate.Capability), da
rt.as(dart.dindex(message, 2), isolate.Capability)); | 708 dart.dcall(this.addPause, dart.dindex(message, 1), dart.dindex(message
, 2)); |
710 break; | 709 break; |
711 } | 710 } |
712 case "resume": | 711 case "resume": |
713 { | 712 { |
714 this.removePause(dart.as(dart.dindex(message, 1), isolate.Capability))
; | 713 dart.dcall(this.removePause, dart.dindex(message, 1)); |
715 break; | 714 break; |
716 } | 715 } |
717 case 'add-ondone': | 716 case 'add-ondone': |
718 { | 717 { |
719 this.addDoneListener(dart.as(dart.dindex(message, 1), isolate.SendPort
)); | 718 dart.dcall(this.addDoneListener, dart.dindex(message, 1)); |
720 break; | 719 break; |
721 } | 720 } |
722 case 'remove-ondone': | 721 case 'remove-ondone': |
723 { | 722 { |
724 this.removeDoneListener(dart.as(dart.dindex(message, 1), isolate.SendP
ort)); | 723 dart.dcall(this.removeDoneListener, dart.dindex(message, 1)); |
725 break; | 724 break; |
726 } | 725 } |
727 case 'set-errors-fatal': | 726 case 'set-errors-fatal': |
728 { | 727 { |
729 this.setErrorsFatal(dart.as(dart.dindex(message, 1), isolate.Capabilit
y), dart.as(dart.dindex(message, 2), core.bool)); | 728 dart.dcall(this.setErrorsFatal, dart.dindex(message, 1), dart.dindex(m
essage, 2)); |
730 break; | 729 break; |
731 } | 730 } |
732 case "ping": | 731 case "ping": |
733 { | 732 { |
734 this.handlePing(dart.as(dart.dindex(message, 1), isolate.SendPort), da
rt.as(dart.dindex(message, 2), core.int)); | 733 dart.dcall(this.handlePing, dart.dindex(message, 1), dart.dindex(messa
ge, 2)); |
735 break; | 734 break; |
736 } | 735 } |
737 case "kill": | 736 case "kill": |
738 { | 737 { |
739 this.handleKill(dart.as(dart.dindex(message, 1), isolate.Capability),
dart.as(dart.dindex(message, 2), core.int)); | 738 dart.dcall(this.handleKill, dart.dindex(message, 1), dart.dindex(messa
ge, 2)); |
740 break; | 739 break; |
741 } | 740 } |
742 case "getErrors": | 741 case "getErrors": |
743 { | 742 { |
744 this.addErrorListener(dart.as(dart.dindex(message, 1), isolate.SendPor
t)); | 743 dart.dcall(this.addErrorListener, dart.dindex(message, 1)); |
745 break; | 744 break; |
746 } | 745 } |
747 case "stopErrors": | 746 case "stopErrors": |
748 { | 747 { |
749 this.removeErrorListener(dart.as(dart.dindex(message, 1), isolate.Send
Port)); | 748 dart.dcall(this.removeErrorListener, dart.dindex(message, 1)); |
750 break; | 749 break; |
751 } | 750 } |
752 default: | 751 default: |
753 } | 752 } |
754 } | 753 } |
755 lookup(portId) { | 754 lookup(portId) { |
756 return this.ports.get(portId); | 755 return this.ports.get(portId); |
757 } | 756 } |
758 [_addRegistration](portId, port) { | 757 [_addRegistration](portId, port) { |
759 if (dart.notNull(this.ports.containsKey(portId))) { | 758 if (dart.notNull(dart.dcall(this.ports.containsKey, portId))) { |
760 dart.throw(core.Exception.new("Registry: ports must be registered only o
nce.")); | 759 dart.throw(core.Exception.new("Registry: ports must be registered only o
nce.")); |
761 } | 760 } |
762 this.ports.set(portId, port); | 761 this.ports.set(portId, port); |
763 } | 762 } |
764 register(portId, port) { | 763 register(portId, port) { |
765 this[_addRegistration](portId, port); | 764 dart.dcall(this[_addRegistration], portId, port); |
766 this[_updateGlobalState](); | 765 dart.dcall(this[_updateGlobalState]); |
767 } | 766 } |
768 registerWeak(portId, port) { | 767 registerWeak(portId, port) { |
769 this.weakPorts.add(portId); | 768 dart.dcall(this.weakPorts.add, portId); |
770 this[_addRegistration](portId, port); | 769 dart.dcall(this[_addRegistration], portId, port); |
771 } | 770 } |
772 [_updateGlobalState]() { | 771 [_updateGlobalState]() { |
773 if (dart.notNull(this.ports.length) - dart.notNull(this.weakPorts.length)
> 0 || dart.notNull(this.isPaused) || !dart.notNull(this.initialized)) { | 772 if (dart.notNull(this.ports.length) - dart.notNull(this.weakPorts.length)
> 0 || dart.notNull(this.isPaused) || !dart.notNull(this.initialized)) { |
774 exports._globalState.isolates.set(this.id, this); | 773 exports._globalState.isolates.set(this.id, this); |
775 } else { | 774 } else { |
776 this.kill(); | 775 dart.dcall(this.kill); |
777 } | 776 } |
778 } | 777 } |
779 kill() { | 778 kill() { |
780 if (this[_scheduledControlEvents] != null) { | 779 if (this[_scheduledControlEvents] != null) { |
781 dart.dsend(this[_scheduledControlEvents], 'clear'); | 780 dart.dsend(this[_scheduledControlEvents], 'clear'); |
782 } | 781 } |
783 for (let port of this.ports.values) { | 782 for (let port of this.ports.values) { |
784 port[_close](); | 783 dart.dsend(port, _close); |
785 } | 784 } |
786 this.ports.clear(); | 785 dart.dcall(this.ports.clear); |
787 this.weakPorts.clear(); | 786 dart.dcall(this.weakPorts.clear); |
788 exports._globalState.isolates.remove(this.id); | 787 dart.dcall(exports._globalState.isolates.remove, this.id); |
789 this.errorPorts.clear(); | 788 dart.dcall(this.errorPorts.clear); |
790 if (this.doneHandlers != null) { | 789 if (this.doneHandlers != null) { |
791 for (let port of dart.as(this.doneHandlers, core.Iterable$(isolate.SendP
ort))) { | 790 for (let port of dart.as(this.doneHandlers, core.Iterable$(isolate.SendP
ort))) { |
792 port.send(null); | 791 dart.dcall(port.send, null); |
793 } | 792 } |
794 this.doneHandlers = null; | 793 this.doneHandlers = null; |
795 } | 794 } |
796 } | 795 } |
797 unregister(portId) { | 796 unregister(portId) { |
798 this.ports.remove(portId); | 797 dart.dcall(this.ports.remove, portId); |
799 this.weakPorts.remove(portId); | 798 dart.dcall(this.weakPorts.remove, portId); |
800 this[_updateGlobalState](); | 799 dart.dcall(this[_updateGlobalState]); |
801 } | 800 } |
802 } | 801 } |
803 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext]; | 802 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext]; |
804 dart.setSignature(_IsolateContext, { | 803 dart.setSignature(_IsolateContext, { |
805 constructors: () => ({_IsolateContext: [_IsolateContext, []]}), | 804 constructors: () => ({_IsolateContext: [_IsolateContext, []]}), |
806 methods: () => ({ | 805 methods: () => ({ |
807 addPause: [dart.void, [isolate.Capability, isolate.Capability]], | 806 addPause: [dart.void, [isolate.Capability, isolate.Capability]], |
808 removePause: [dart.void, [isolate.Capability]], | 807 removePause: [dart.void, [isolate.Capability]], |
809 addDoneListener: [dart.void, [isolate.SendPort]], | 808 addDoneListener: [dart.void, [isolate.SendPort]], |
810 removeDoneListener: [dart.void, [isolate.SendPort]], | 809 removeDoneListener: [dart.void, [isolate.SendPort]], |
(...skipping 15 matching lines...) Expand all Loading... |
826 unregister: [dart.void, [core.int]] | 825 unregister: [dart.void, [core.int]] |
827 }) | 826 }) |
828 }); | 827 }); |
829 let _runHelper = Symbol('_runHelper'); | 828 let _runHelper = Symbol('_runHelper'); |
830 class _EventLoop extends core.Object { | 829 class _EventLoop extends core.Object { |
831 _EventLoop() { | 830 _EventLoop() { |
832 this.events = collection.Queue$(_IsolateEvent).new(); | 831 this.events = collection.Queue$(_IsolateEvent).new(); |
833 this[_activeJsAsyncCount] = 0; | 832 this[_activeJsAsyncCount] = 0; |
834 } | 833 } |
835 enqueue(isolate, fn, msg) { | 834 enqueue(isolate, fn, msg) { |
836 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d
art.as(fn, core.Function), dart.as(msg, core.String))); | 835 dart.dcall(this.events.addLast, new _IsolateEvent(dart.as(isolate, _Isolat
eContext), dart.as(fn, core.Function), dart.as(msg, core.String))); |
837 } | 836 } |
838 prequeue(event) { | 837 prequeue(event) { |
839 this.events.addFirst(event); | 838 dart.dcall(this.events.addFirst, event); |
840 } | 839 } |
841 dequeue() { | 840 dequeue() { |
842 if (dart.notNull(this.events.isEmpty)) | 841 if (dart.notNull(this.events.isEmpty)) |
843 return null; | 842 return null; |
844 return this.events.removeFirst(); | 843 return dart.dcall(this.events.removeFirst); |
845 } | 844 } |
846 checkOpenReceivePortsFromCommandLine() { | 845 checkOpenReceivePortsFromCommandLine() { |
847 if (exports._globalState.rootContext != null && dart.notNull(exports._glob
alState.isolates.containsKey(exports._globalState.rootContext.id)) && dart.notNu
ll(exports._globalState.fromCommandLine) && dart.notNull(exports._globalState.ro
otContext.ports.isEmpty)) { | 846 if (exports._globalState.rootContext != null && dart.notNull(dart.dcall(ex
ports._globalState.isolates.containsKey, exports._globalState.rootContext.id)) &
& dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports._gl
obalState.rootContext.ports.isEmpty)) { |
848 dart.throw(core.Exception.new("Program exited with open ReceivePorts."))
; | 847 dart.throw(core.Exception.new("Program exited with open ReceivePorts."))
; |
849 } | 848 } |
850 } | 849 } |
851 runIteration() { | 850 runIteration() { |
852 let event = this.dequeue(); | 851 let event = dart.dcall(this.dequeue); |
853 if (event == null) { | 852 if (event == null) { |
854 this.checkOpenReceivePortsFromCommandLine(); | 853 dart.dcall(this.checkOpenReceivePortsFromCommandLine); |
855 exports._globalState.maybeCloseWorker(); | 854 dart.dcall(exports._globalState.maybeCloseWorker); |
856 return false; | 855 return false; |
857 } | 856 } |
858 event.process(); | 857 dart.dsend(event, 'process'); |
859 return true; | 858 return true; |
860 } | 859 } |
861 [_runHelper]() { | 860 [_runHelper]() { |
862 if (exports.globalWindow != null) { | 861 if (exports.globalWindow != null) { |
863 let next = (function() { | 862 let next = (function() { |
864 if (!dart.notNull(this.runIteration())) | 863 if (!dart.notNull(dart.dcall(this.runIteration))) |
865 return; | 864 return; |
866 async.Timer.run(next); | 865 dart.dcall(async.Timer.run, next); |
867 }).bind(this); | 866 }).bind(this); |
868 dart.fn(next); | 867 dart.fn(next); |
869 next(); | 868 dart.dcall(next); |
870 } else { | 869 } else { |
871 while (dart.notNull(this.runIteration())) { | 870 while (dart.notNull(dart.dcall(this.runIteration))) { |
872 } | 871 } |
873 } | 872 } |
874 } | 873 } |
875 run() { | 874 run() { |
876 if (!dart.notNull(exports._globalState.isWorker)) { | 875 if (!dart.notNull(exports._globalState.isWorker)) { |
877 this[_runHelper](); | 876 dart.dcall(this[_runHelper]); |
878 } else { | 877 } else { |
879 try { | 878 try { |
880 this[_runHelper](); | 879 dart.dcall(this[_runHelper]); |
881 } catch (e) { | 880 } catch (e) { |
882 let trace = dart.stackTrace(e); | 881 let trace = dart.stackTrace(e); |
883 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma
p({command: 'error', msg: `${e}\n${trace}`}))); | 882 dart.dcall(exports._globalState.mainManager.postMessage, dart.dcall(_s
erializeMessage, dart.map({command: 'error', msg: `${e}\n${trace}`}))); |
884 } | 883 } |
885 | 884 |
886 } | 885 } |
887 } | 886 } |
888 } | 887 } |
889 dart.setSignature(_EventLoop, { | 888 dart.setSignature(_EventLoop, { |
890 constructors: () => ({_EventLoop: [_EventLoop, []]}), | 889 constructors: () => ({_EventLoop: [_EventLoop, []]}), |
891 methods: () => ({ | 890 methods: () => ({ |
892 enqueue: [dart.void, [dart.dynamic, dart.dynamic, dart.dynamic]], | 891 enqueue: [dart.void, [dart.dynamic, dart.dynamic, dart.dynamic]], |
893 prequeue: [dart.void, [_IsolateEvent]], | 892 prequeue: [dart.void, [_IsolateEvent]], |
894 dequeue: [_IsolateEvent, []], | 893 dequeue: [_IsolateEvent, []], |
895 checkOpenReceivePortsFromCommandLine: [dart.void, []], | 894 checkOpenReceivePortsFromCommandLine: [dart.void, []], |
896 runIteration: [core.bool, []], | 895 runIteration: [core.bool, []], |
897 [_runHelper]: [dart.void, []], | 896 [_runHelper]: [dart.void, []], |
898 run: [dart.void, []] | 897 run: [dart.void, []] |
899 }) | 898 }) |
900 }); | 899 }); |
901 class _IsolateEvent extends core.Object { | 900 class _IsolateEvent extends core.Object { |
902 _IsolateEvent(isolate, fn, message) { | 901 _IsolateEvent(isolate, fn, message) { |
903 this.isolate = isolate; | 902 this.isolate = isolate; |
904 this.fn = fn; | 903 this.fn = fn; |
905 this.message = message; | 904 this.message = message; |
906 } | 905 } |
907 process() { | 906 process() { |
908 if (dart.notNull(this.isolate.isPaused)) { | 907 if (dart.notNull(this.isolate.isPaused)) { |
909 this.isolate.delayedEvents[dartx.add](this); | 908 dart.dcall(this.isolate.delayedEvents[dartx.add], this); |
910 return; | 909 return; |
911 } | 910 } |
912 this.isolate.eval(this.fn); | 911 dart.dcall(this.isolate.eval, this.fn); |
913 } | 912 } |
914 } | 913 } |
915 dart.setSignature(_IsolateEvent, { | 914 dart.setSignature(_IsolateEvent, { |
916 constructors: () => ({_IsolateEvent: [_IsolateEvent, [_IsolateContext, core.
Function, core.String]]}), | 915 constructors: () => ({_IsolateEvent: [_IsolateEvent, [_IsolateContext, core.
Function, core.String]]}), |
917 methods: () => ({process: [dart.void, []]}) | 916 methods: () => ({process: [dart.void, []]}) |
918 }); | 917 }); |
919 dart.defineLazyProperties(exports, { | 918 dart.defineLazyProperties(exports, { |
920 get _global() { | 919 get _global() { |
921 return typeof global == 'undefined' ? self : global; | 920 return typeof global == 'undefined' ? self : global; |
922 } | 921 } |
923 }); | 922 }); |
924 class _MainManagerStub extends core.Object { | 923 class _MainManagerStub extends core.Object { |
925 postMessage(msg) { | 924 postMessage(msg) { |
926 exports._global.postMessage(msg); | 925 exports._global.postMessage(msg); |
927 } | 926 } |
928 } | 927 } |
929 dart.setSignature(_MainManagerStub, { | 928 dart.setSignature(_MainManagerStub, { |
930 methods: () => ({postMessage: [dart.void, [dart.dynamic]]}) | 929 methods: () => ({postMessage: [dart.void, [dart.dynamic]]}) |
931 }); | 930 }); |
932 let _SPAWNED_SIGNAL = "spawned"; | 931 let _SPAWNED_SIGNAL = "spawned"; |
933 let _SPAWN_FAILED_SIGNAL = "spawn failed"; | 932 let _SPAWN_FAILED_SIGNAL = "spawn failed"; |
934 dart.copyProperties(exports, { | 933 dart.copyProperties(exports, { |
935 get globalWindow() { | 934 get globalWindow() { |
936 return exports._global.window; | 935 return exports._global.window; |
937 }, | 936 }, |
938 get globalWorker() { | 937 get globalWorker() { |
939 return exports._global.Worker; | 938 return exports._global.Worker; |
940 }, | 939 }, |
941 get globalPostMessageDefined() { | 940 get globalPostMessageDefined() { |
942 return !!exports._global.postMessage; | 941 return dart.as(!!exports._global.postMessage, core.bool); |
943 } | 942 } |
944 }); | 943 }); |
945 let _MainFunction = dart.typedef('_MainFunction', () => dart.functionType(dart
.dynamic, [])); | 944 let _MainFunction = dart.typedef('_MainFunction', () => dart.functionType(dart
.dynamic, [])); |
946 let _MainFunctionArgs = dart.typedef('_MainFunctionArgs', () => dart.functionT
ype(dart.dynamic, [dart.dynamic])); | 945 let _MainFunctionArgs = dart.typedef('_MainFunctionArgs', () => dart.functionT
ype(dart.dynamic, [dart.dynamic])); |
947 let _MainFunctionArgsMessage = dart.typedef('_MainFunctionArgsMessage', () =>
dart.functionType(dart.dynamic, [dart.dynamic, dart.dynamic])); | 946 let _MainFunctionArgsMessage = dart.typedef('_MainFunctionArgsMessage', () =>
dart.functionType(dart.dynamic, [dart.dynamic, dart.dynamic])); |
948 class IsolateNatives extends core.Object { | 947 class IsolateNatives extends core.Object { |
949 static computeThisScript() { | 948 static computeThisScript() { |
950 let currentScript = document.currentScript; | 949 let currentScript = document.currentScript; |
951 if (currentScript != null) { | 950 if (currentScript != null) { |
952 return String(currentScript.src); | 951 return dart.as(String(currentScript.src), core.String); |
953 } | 952 } |
954 if (dart.notNull(_js_helper.Primitives.isD8)) | 953 if (dart.notNull(_js_helper.Primitives.isD8)) |
955 return IsolateNatives.computeThisScriptD8(); | 954 return dart.dcall(IsolateNatives.computeThisScriptD8); |
956 if (dart.notNull(_js_helper.Primitives.isJsshell)) | 955 if (dart.notNull(_js_helper.Primitives.isJsshell)) |
957 return IsolateNatives.computeThisScriptJsshell(); | 956 return dart.dcall(IsolateNatives.computeThisScriptJsshell); |
958 if (exports._globalState != null && dart.notNull(exports._globalState.isWo
rker)) { | 957 if (exports._globalState != null && dart.notNull(exports._globalState.isWo
rker)) { |
959 return IsolateNatives.computeThisScriptFromTrace(); | 958 return dart.dcall(IsolateNatives.computeThisScriptFromTrace); |
960 } | 959 } |
961 return null; | 960 return null; |
962 } | 961 } |
963 static computeThisScriptJsshell() { | 962 static computeThisScriptJsshell() { |
964 return dart.as(thisFilename(), core.String); | 963 return dart.as(thisFilename(), core.String); |
965 } | 964 } |
966 static computeThisScriptD8() { | 965 static computeThisScriptD8() { |
967 return IsolateNatives.computeThisScriptFromTrace(); | 966 return dart.dcall(IsolateNatives.computeThisScriptFromTrace); |
968 } | 967 } |
969 static computeThisScriptFromTrace() { | 968 static computeThisScriptFromTrace() { |
970 let stack = new Error().stack; | 969 let stack = new Error().stack; |
971 if (stack == null) { | 970 if (stack == null) { |
972 stack = (function() { | 971 stack = (function() { |
973 try { | 972 try { |
974 throw new Error(); | 973 throw new Error(); |
975 } catch (e) { | 974 } catch (e) { |
976 return e.stack; | 975 return e.stack; |
977 } | 976 } |
978 | 977 |
979 })(); | 978 })(); |
980 if (stack == null) | 979 if (stack == null) |
981 dart.throw(new core.UnsupportedError('No stack trace')); | 980 dart.throw(new core.UnsupportedError('No stack trace')); |
982 } | 981 } |
983 let pattern = null, matches = null; | 982 let pattern = null, matches = null; |
984 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); | 983 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); |
985 matches = stack.match(pattern); | 984 matches = stack.match(pattern); |
986 if (matches != null) | 985 if (matches != null) |
987 return matches[1]; | 986 return dart.as(matches[1], core.String); |
988 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); | 987 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); |
989 matches = stack.match(pattern); | 988 matches = stack.match(pattern); |
990 if (matches != null) | 989 if (matches != null) |
991 return matches[1]; | 990 return dart.as(matches[1], core.String); |
992 dart.throw(new core.UnsupportedError(`Cannot extract URI from "${stack}"`)
); | 991 dart.throw(new core.UnsupportedError(`Cannot extract URI from "${stack}"`)
); |
993 } | 992 } |
994 static _getEventData(e) { | 993 static _getEventData(e) { |
995 return e.data; | 994 return e.data; |
996 } | 995 } |
997 static _processWorkerMessage(sender, e) { | 996 static _processWorkerMessage(sender, e) { |
998 let msg = _deserializeMessage(IsolateNatives._getEventData(e)); | 997 let msg = dart.dcall(_deserializeMessage, dart.dcall(IsolateNatives._getEv
entData, e)); |
999 switch (dart.dindex(msg, 'command')) { | 998 switch (dart.dindex(msg, 'command')) { |
1000 case 'start': | 999 case 'start': |
1001 { | 1000 { |
1002 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); | 1001 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); |
1003 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); | 1002 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); |
1004 let entryPoint = functionName == null ? exports._globalState.entry : d
art.as(IsolateNatives._getJSFunctionFromName(functionName), core.Function); | 1003 let entryPoint = functionName == null ? exports._globalState.entry : d
art.as(dart.dcall(IsolateNatives._getJSFunctionFromName, functionName), core.Fun
ction); |
1005 let args = dart.dindex(msg, 'args'); | 1004 let args = dart.dindex(msg, 'args'); |
1006 let message = _deserializeMessage(dart.dindex(msg, 'msg')); | 1005 let message = dart.dcall(_deserializeMessage, dart.dindex(msg, 'msg'))
; |
1007 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); | 1006 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); |
1008 let startPaused = dart.dindex(msg, 'startPaused'); | 1007 let startPaused = dart.dindex(msg, 'startPaused'); |
1009 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); | 1008 let replyTo = dart.dcall(_deserializeMessage, dart.dindex(msg, 'replyT
o')); |
1010 let context = new _IsolateContext(); | 1009 let context = new _IsolateContext(); |
1011 exports._globalState.topEventLoop.enqueue(context, dart.fn(() => { | 1010 dart.dcall(exports._globalState.topEventLoop.enqueue, context, dart.fn
(() => { |
1012 IsolateNatives._startIsolate(entryPoint, dart.as(args, core.List$(co
re.String)), message, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core.
bool), dart.as(replyTo, isolate.SendPort)); | 1011 dart.dcall(IsolateNatives._startIsolate, entryPoint, args, message,
isSpawnUri, startPaused, replyTo); |
1013 }), 'worker-start'); | 1012 }), 'worker-start'); |
1014 exports._globalState.currentContext = context; | 1013 exports._globalState.currentContext = dart.as(context, _IsolateContext
); |
1015 exports._globalState.topEventLoop.run(); | 1014 dart.dcall(exports._globalState.topEventLoop.run); |
1016 break; | 1015 break; |
1017 } | 1016 } |
1018 case 'spawn-worker': | 1017 case 'spawn-worker': |
1019 { | 1018 { |
1020 if (IsolateNatives.enableSpawnWorker != null) | 1019 if (IsolateNatives.enableSpawnWorker != null) |
1021 IsolateNatives.handleSpawnWorkerRequest(msg); | 1020 dart.dcall(IsolateNatives.handleSpawnWorkerRequest, msg); |
1022 break; | 1021 break; |
1023 } | 1022 } |
1024 case 'message': | 1023 case 'message': |
1025 { | 1024 { |
1026 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); | 1025 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); |
1027 if (port != null) { | 1026 if (port != null) { |
1028 dart.dsend(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg')
); | 1027 dart.dsend(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg')
); |
1029 } | 1028 } |
1030 exports._globalState.topEventLoop.run(); | 1029 dart.dcall(exports._globalState.topEventLoop.run); |
1031 break; | 1030 break; |
1032 } | 1031 } |
1033 case 'close': | 1032 case 'close': |
1034 { | 1033 { |
1035 exports._globalState.managers.remove(IsolateNatives.workerIds.get(send
er)); | 1034 dart.dcall(exports._globalState.managers.remove, IsolateNatives.worker
Ids.get(sender)); |
1036 sender.terminate(); | 1035 sender.terminate(); |
1037 exports._globalState.topEventLoop.run(); | 1036 dart.dcall(exports._globalState.topEventLoop.run); |
1038 break; | 1037 break; |
1039 } | 1038 } |
1040 case 'log': | 1039 case 'log': |
1041 { | 1040 { |
1042 IsolateNatives._log(dart.dindex(msg, 'msg')); | 1041 dart.dcall(IsolateNatives._log, dart.dindex(msg, 'msg')); |
1043 break; | 1042 break; |
1044 } | 1043 } |
1045 case 'print': | 1044 case 'print': |
1046 { | 1045 { |
1047 if (dart.notNull(exports._globalState.isWorker)) { | 1046 if (dart.notNull(exports._globalState.isWorker)) { |
1048 exports._globalState.mainManager.postMessage(_serializeMessage(dart.
map({command: 'print', msg: msg}))); | 1047 dart.dcall(exports._globalState.mainManager.postMessage, dart.dcall(
_serializeMessage, dart.map({command: 'print', msg: msg}))); |
1049 } else { | 1048 } else { |
1050 core.print(dart.dindex(msg, 'msg')); | 1049 dart.dcall(core.print, dart.dindex(msg, 'msg')); |
1051 } | 1050 } |
1052 break; | 1051 break; |
1053 } | 1052 } |
1054 case 'error': | 1053 case 'error': |
1055 { | 1054 { |
1056 dart.throw(dart.dindex(msg, 'msg')); | 1055 dart.throw(dart.dindex(msg, 'msg')); |
1057 } | 1056 } |
1058 } | 1057 } |
1059 } | 1058 } |
1060 static handleSpawnWorkerRequest(msg) { | 1059 static handleSpawnWorkerRequest(msg) { |
1061 let replyPort = dart.dindex(msg, 'replyPort'); | 1060 let replyPort = dart.dindex(msg, 'replyPort'); |
1062 IsolateNatives.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.dinde
x(msg, 'isSpawnUri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.
bool)).then(dart.fn(msg => { | 1061 dart.dcall(dart.dcall(IsolateNatives.spawn, dart.dindex(msg, 'functionName
'), dart.dindex(msg, 'uri'), dart.dindex(msg, 'args'), dart.dindex(msg, 'msg'),
false, dart.dindex(msg, 'isSpawnUri'), dart.dindex(msg, 'startPaused')).then, da
rt.fn(msg => { |
1063 dart.dsend(replyPort, 'send', msg); | 1062 dart.dsend(replyPort, 'send', msg); |
1064 }), {onError: dart.fn(errorMessage => { | 1063 }), {onError: dart.fn(errorMessage => { |
1065 dart.dsend(replyPort, 'send', [_SPAWN_FAILED_SIGNAL, errorMessage]); | 1064 dart.dsend(replyPort, 'send', [_SPAWN_FAILED_SIGNAL, errorMessage]); |
1066 }, dart.dynamic, [core.String])}); | 1065 }, dart.dynamic, [core.String])}); |
1067 } | 1066 } |
1068 static _log(msg) { | 1067 static _log(msg) { |
1069 if (dart.notNull(exports._globalState.isWorker)) { | 1068 if (dart.notNull(exports._globalState.isWorker)) { |
1070 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); | 1069 dart.dcall(exports._globalState.mainManager.postMessage, dart.dcall(_ser
ializeMessage, dart.map({command: 'log', msg: msg}))); |
1071 } else { | 1070 } else { |
1072 try { | 1071 try { |
1073 IsolateNatives._consoleLog(msg); | 1072 dart.dcall(IsolateNatives._consoleLog, msg); |
1074 } catch (e) { | 1073 } catch (e) { |
1075 let trace = dart.stackTrace(e); | 1074 let trace = dart.stackTrace(e); |
1076 dart.throw(core.Exception.new(trace)); | 1075 dart.throw(core.Exception.new(trace)); |
1077 } | 1076 } |
1078 | 1077 |
1079 } | 1078 } |
1080 } | 1079 } |
1081 static _consoleLog(msg) { | 1080 static _consoleLog(msg) { |
1082 self.console.log(msg); | 1081 self.console.log(msg); |
1083 } | 1082 } |
1084 static _getJSFunctionFromName(functionName) { | 1083 static _getJSFunctionFromName(functionName) { |
1085 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", _js_
embedded_names.GLOBAL_FUNCTIONS); | 1084 let globalFunctionsContainer = dart.dcall(_foreign_helper.JS_EMBEDDED_GLOB
AL, "", _js_embedded_names.GLOBAL_FUNCTIONS); |
1086 return globalFunctionsContainer[functionName](); | 1085 return globalFunctionsContainer[functionName](); |
1087 } | 1086 } |
1088 static _getJSFunctionName(f) { | 1087 static _getJSFunctionName(f) { |
1089 return dart.as(f.$name, core.String); | 1088 return dart.as(f.$name, core.String); |
1090 } | 1089 } |
1091 static _allocate(ctor) { | 1090 static _allocate(ctor) { |
1092 return new ctor(); | 1091 return new ctor(); |
1093 } | 1092 } |
1094 static spawnFunction(topLevelFunction, message, startPaused) { | 1093 static spawnFunction(topLevelFunction, message, startPaused) { |
1095 IsolateNatives.enableSpawnWorker = true; | 1094 IsolateNatives.enableSpawnWorker = true; |
1096 let name = IsolateNatives._getJSFunctionName(topLevelFunction); | 1095 let name = dart.dcall(IsolateNatives._getJSFunctionName, topLevelFunction)
; |
1097 if (name == null) { | 1096 if (name == null) { |
1098 dart.throw(new core.UnsupportedError("only top-level functions can be sp
awned.")); | 1097 dart.throw(new core.UnsupportedError("only top-level functions can be sp
awned.")); |
1099 } | 1098 } |
1100 let isLight = false; | 1099 let isLight = false; |
1101 let isSpawnUri = false; | 1100 let isSpawnUri = false; |
1102 return IsolateNatives.spawn(name, null, null, message, isLight, isSpawnUri
, startPaused); | 1101 return dart.dcall(IsolateNatives.spawn, name, null, null, message, isLight
, isSpawnUri, startPaused); |
1103 } | 1102 } |
1104 static spawnUri(uri, args, message, startPaused) { | 1103 static spawnUri(uri, args, message, startPaused) { |
1105 IsolateNatives.enableSpawnWorker = true; | 1104 IsolateNatives.enableSpawnWorker = true; |
1106 let isLight = false; | 1105 let isLight = false; |
1107 let isSpawnUri = true; | 1106 let isSpawnUri = true; |
1108 return IsolateNatives.spawn(null, dart.toString(uri), args, message, isLig
ht, isSpawnUri, startPaused); | 1107 return dart.dcall(IsolateNatives.spawn, null, dart.dcall(uri.toString), ar
gs, message, isLight, isSpawnUri, startPaused); |
1109 } | 1108 } |
1110 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { | 1109 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { |
1111 if (uri != null && dart.notNull(uri[dartx.endsWith](".dart"))) { | 1110 if (uri != null && dart.notNull(dart.dcall(uri[dartx.endsWith], ".dart")))
{ |
1112 uri = dart.notNull(uri) + ".js"; | 1111 uri = dart.notNull(uri) + ".js"; |
1113 } | 1112 } |
1114 let port = isolate.ReceivePort.new(); | 1113 let port = isolate.ReceivePort.new(); |
1115 let completer = async.Completer$(core.List).new(); | 1114 let completer = async.Completer$(core.List).new(); |
1116 port.first.then(dart.fn(msg => { | 1115 dart.dcall(port.first.then, dart.fn(msg => { |
1117 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { | 1116 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { |
1118 completer.complete(msg); | 1117 dart.dcall(completer.complete, msg); |
1119 } else { | 1118 } else { |
1120 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); | 1119 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); |
1121 completer.completeError(dart.dindex(msg, 1)); | 1120 dart.dcall(completer.completeError, dart.dindex(msg, 1)); |
1122 } | 1121 } |
1123 })); | 1122 })); |
1124 let signalReply = port.sendPort; | 1123 let signalReply = port.sendPort; |
1125 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { | 1124 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { |
1126 IsolateNatives._startWorker(functionName, uri, args, message, isSpawnUri
, startPaused, signalReply, dart.fn(message => completer.completeError(message),
dart.void, [core.String])); | 1125 dart.dcall(IsolateNatives._startWorker, functionName, uri, args, message
, isSpawnUri, startPaused, signalReply, dart.fn(message => dart.dcall(completer.
completeError, message), dart.void, [core.String])); |
1127 } else { | 1126 } else { |
1128 IsolateNatives._startNonWorker(functionName, uri, args, message, isSpawn
Uri, startPaused, signalReply); | 1127 dart.dcall(IsolateNatives._startNonWorker, functionName, uri, args, mess
age, isSpawnUri, startPaused, signalReply); |
1129 } | 1128 } |
1130 return completer.future; | 1129 return completer.future; |
1131 } | 1130 } |
1132 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 1131 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { |
1133 if (args != null) | 1132 if (args != null) |
1134 args = core.List$(core.String).from(args); | 1133 args = core.List$(core.String).from(args); |
1135 if (dart.notNull(exports._globalState.isWorker)) { | 1134 if (dart.notNull(exports._globalState.isWorker)) { |
1136 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); | 1135 dart.dcall(exports._globalState.mainManager.postMessage, dart.dcall(_ser
ializeMessage, dart.map({command: 'spawn-worker', functionName: functionName, ar
gs: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaus
ed, replyPort: replyPort}))); |
1137 } else { | 1136 } else { |
1138 IsolateNatives._spawnWorker(functionName, uri, args, message, isSpawnUri
, startPaused, replyPort, onError); | 1137 dart.dcall(IsolateNatives._spawnWorker, functionName, uri, args, message
, isSpawnUri, startPaused, replyPort, onError); |
1139 } | 1138 } |
1140 } | 1139 } |
1141 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { | 1140 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { |
1142 if (uri != null) { | 1141 if (uri != null) { |
1143 dart.throw(new core.UnsupportedError("Currently spawnUri is not supporte
d without web workers.")); | 1142 dart.throw(new core.UnsupportedError("Currently spawnUri is not supporte
d without web workers.")); |
1144 } | 1143 } |
1145 message = _clone(message); | 1144 message = dart.dcall(_clone, message); |
1146 if (args != null) | 1145 if (args != null) |
1147 args = core.List$(core.String).from(args); | 1146 args = core.List$(core.String).from(args); |
1148 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), dart.fn((
) => { | 1147 dart.dcall(exports._globalState.topEventLoop.enqueue, new _IsolateContext(
), dart.fn(() => { |
1149 let func = IsolateNatives._getJSFunctionFromName(functionName); | 1148 let func = dart.dcall(IsolateNatives._getJSFunctionFromName, functionNam
e); |
1150 IsolateNatives._startIsolate(dart.as(func, core.Function), args, message
, isSpawnUri, startPaused, replyPort); | 1149 dart.dcall(IsolateNatives._startIsolate, func, args, message, isSpawnUri
, startPaused, replyPort); |
1151 }), 'nonworker start'); | 1150 }), 'nonworker start'); |
1152 } | 1151 } |
1153 static get currentIsolate() { | 1152 static get currentIsolate() { |
1154 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 1153 let context = dart.as(dart.dcall(_foreign_helper.JS_CURRENT_ISOLATE_CONTEX
T), _IsolateContext); |
1155 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); | 1154 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
1156 } | 1155 } |
1157 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { | 1156 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { |
1158 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 1157 let context = dart.as(dart.dcall(_foreign_helper.JS_CURRENT_ISOLATE_CONTEX
T), _IsolateContext); |
1159 _js_helper.Primitives.initializeStatics(context.id); | 1158 dart.dcall(_js_helper.Primitives.initializeStatics, context.id); |
1160 replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pause
Capability, context.terminateCapability]); | 1159 dart.dcall(replyTo.send, [_SPAWNED_SIGNAL, context.controlPort.sendPort, c
ontext.pauseCapability, context.terminateCapability]); |
1161 function runStartFunction() { | 1160 function runStartFunction() { |
1162 context.initialized = true; | 1161 context.initialized = true; |
1163 if (!dart.notNull(isSpawnUri)) { | 1162 if (!dart.notNull(isSpawnUri)) { |
1164 dart.dcall(topLevel, message); | 1163 dart.dcall(topLevel, message); |
1165 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { | 1164 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { |
1166 dart.dcall(topLevel, args, message); | 1165 dart.dcall(topLevel, args, message); |
1167 } else if (dart.is(topLevel, _MainFunctionArgs)) { | 1166 } else if (dart.is(topLevel, _MainFunctionArgs)) { |
1168 dart.dcall(topLevel, args); | 1167 dart.dcall(topLevel, args); |
1169 } else { | 1168 } else { |
1170 dart.dcall(topLevel); | 1169 dart.dcall(topLevel); |
1171 } | 1170 } |
1172 } | 1171 } |
1173 dart.fn(runStartFunction, dart.void, []); | 1172 dart.fn(runStartFunction, dart.void, []); |
1174 if (dart.notNull(startPaused)) { | 1173 if (dart.notNull(startPaused)) { |
1175 context.addPause(context.pauseCapability, context.pauseCapability); | 1174 dart.dcall(context.addPause, context.pauseCapability, context.pauseCapab
ility); |
1176 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); | 1175 dart.dcall(exports._globalState.topEventLoop.enqueue, context, runStartF
unction, 'start isolate'); |
1177 } else { | 1176 } else { |
1178 runStartFunction(); | 1177 dart.dcall(runStartFunction); |
1179 } | 1178 } |
1180 } | 1179 } |
1181 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 1180 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { |
1182 if (uri == null) | 1181 if (uri == null) |
1183 uri = IsolateNatives.thisScript; | 1182 uri = IsolateNatives.thisScript; |
1184 let worker = new Worker(uri); | 1183 let worker = new Worker(uri); |
1185 let onerrorTrampoline = (function(f, u, c) { | 1184 let onerrorTrampoline = (function(f, u, c) { |
1186 return function(e) { | 1185 return function(e) { |
1187 return f(e, u, c); | 1186 return f(e, u, c); |
1188 }; | 1187 }; |
1189 })(IsolateNatives.workerOnError, uri, onError); | 1188 })(IsolateNatives.workerOnError, uri, onError); |
1190 worker.onerror = onerrorTrampoline; | 1189 worker.onerror = onerrorTrampoline; |
1191 let processWorkerMessageTrampoline = (function(f, a) { | 1190 let processWorkerMessageTrampoline = (function(f, a) { |
1192 return function(e) { | 1191 return function(e) { |
1193 e.onerror = null; | 1192 e.onerror = null; |
1194 return f(a, e); | 1193 return f(a, e); |
1195 }; | 1194 }; |
1196 })(IsolateNatives._processWorkerMessage, worker); | 1195 })(IsolateNatives._processWorkerMessage, worker); |
1197 worker.onmessage = processWorkerMessageTrampoline; | 1196 worker.onmessage = processWorkerMessageTrampoline; |
1198 let o = exports._globalState; | 1197 let o = exports._globalState; |
1199 let workerId = o.nextManagerId; | 1198 let workerId = o.nextManagerId; |
1200 o.nextManagerId = dart.notNull(workerId) + 1; | 1199 o.nextManagerId = dart.notNull(workerId) + 1; |
1201 IsolateNatives.workerIds.set(worker, workerId); | 1200 IsolateNatives.workerIds.set(worker, dart.as(workerId, core.int)); |
1202 exports._globalState.managers.set(workerId, worker); | 1201 exports._globalState.managers.set(dart.as(workerId, core.int), worker); |
1203 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}))); | 1202 worker.postMessage(dart.dcall(_serializeMessage, dart.map({command: 'start
', id: workerId, replyTo: dart.dcall(_serializeMessage, replyPort), args: args,
msg: dart.dcall(_serializeMessage, message), isSpawnUri: isSpawnUri, startPaused
: startPaused, functionName: functionName}))); |
1204 } | 1203 } |
1205 static workerOnError(event, uri, onError) { | 1204 static workerOnError(event, uri, onError) { |
1206 event.preventDefault(); | 1205 event.preventDefault(); |
1207 let message = dart.as(event.message, core.String); | 1206 let message = dart.as(event.message, core.String); |
1208 if (message == null) { | 1207 if (message == null) { |
1209 message = `Error spawning worker for ${uri}`; | 1208 message = `Error spawning worker for ${uri}`; |
1210 } else { | 1209 } else { |
1211 message = `Error spawning worker for ${uri} (${message})`; | 1210 message = `Error spawning worker for ${uri} (${message})`; |
1212 } | 1211 } |
1213 onError(message); | 1212 onError(message); |
(...skipping 21 matching lines...) Expand all Loading... |
1235 _startNonWorker: [dart.void, [core.String, core.String, core.List$(core.St
ring), dart.dynamic, core.bool, core.bool, isolate.SendPort]], | 1234 _startNonWorker: [dart.void, [core.String, core.String, core.List$(core.St
ring), dart.dynamic, core.bool, core.bool, isolate.SendPort]], |
1236 _startIsolate: [dart.void, [core.Function, core.List$(core.String), dart.d
ynamic, core.bool, core.bool, isolate.SendPort]], | 1235 _startIsolate: [dart.void, [core.Function, core.List$(core.String), dart.d
ynamic, core.bool, core.bool, isolate.SendPort]], |
1237 _spawnWorker: [dart.void, [dart.dynamic, core.String, core.List$(core.Stri
ng), dart.dynamic, core.bool, core.bool, isolate.SendPort, dart.functionType(dar
t.void, [core.String])]], | 1236 _spawnWorker: [dart.void, [dart.dynamic, core.String, core.List$(core.Stri
ng), dart.dynamic, core.bool, core.bool, isolate.SendPort, dart.functionType(dar
t.void, [core.String])]], |
1238 workerOnError: [core.bool, [dart.dynamic, core.String, dart.functionType(d
art.void, [core.String])]] | 1237 workerOnError: [core.bool, [dart.dynamic, core.String, dart.functionType(d
art.void, [core.String])]] |
1239 }), | 1238 }), |
1240 names: ['computeThisScript', 'computeThisScriptJsshell', 'computeThisScriptD
8', 'computeThisScriptFromTrace', '_getEventData', '_processWorkerMessage', 'han
dleSpawnWorkerRequest', '_log', '_consoleLog', '_getJSFunctionFromName', '_getJS
FunctionName', '_allocate', 'spawnFunction', 'spawnUri', 'spawn', '_startWorker'
, '_startNonWorker', '_startIsolate', '_spawnWorker', 'workerOnError'] | 1239 names: ['computeThisScript', 'computeThisScriptJsshell', 'computeThisScriptD
8', 'computeThisScriptFromTrace', '_getEventData', '_processWorkerMessage', 'han
dleSpawnWorkerRequest', '_log', '_consoleLog', '_getJSFunctionFromName', '_getJS
FunctionName', '_allocate', 'spawnFunction', 'spawnUri', 'spawn', '_startWorker'
, '_startNonWorker', '_startIsolate', '_spawnWorker', 'workerOnError'] |
1241 }); | 1240 }); |
1242 IsolateNatives.enableSpawnWorker = null; | 1241 IsolateNatives.enableSpawnWorker = null; |
1243 dart.defineLazyProperties(IsolateNatives, { | 1242 dart.defineLazyProperties(IsolateNatives, { |
1244 get thisScript() { | 1243 get thisScript() { |
1245 return IsolateNatives.computeThisScript(); | 1244 return dart.dcall(IsolateNatives.computeThisScript); |
1246 }, | 1245 }, |
1247 set thisScript(_) {}, | 1246 set thisScript(_) {}, |
1248 get workerIds() { | 1247 get workerIds() { |
1249 return new (core.Expando$(core.int))(); | 1248 return new (core.Expando$(core.int))(); |
1250 } | 1249 } |
1251 }); | 1250 }); |
1252 let _checkReplyTo = Symbol('_checkReplyTo'); | 1251 let _checkReplyTo = Symbol('_checkReplyTo'); |
1253 class _BaseSendPort extends core.Object { | 1252 class _BaseSendPort extends core.Object { |
1254 _BaseSendPort(isolateId) { | 1253 _BaseSendPort(isolateId) { |
1255 this[_isolateId] = isolateId; | 1254 this[_isolateId] = isolateId; |
(...skipping 15 matching lines...) Expand all Loading... |
1271 _NativeJsSendPort(receivePort, isolateId) { | 1270 _NativeJsSendPort(receivePort, isolateId) { |
1272 this[_receivePort] = receivePort; | 1271 this[_receivePort] = receivePort; |
1273 super._BaseSendPort(isolateId); | 1272 super._BaseSendPort(isolateId); |
1274 } | 1273 } |
1275 send(message) { | 1274 send(message) { |
1276 let isolate = exports._globalState.isolates.get(this[_isolateId]); | 1275 let isolate = exports._globalState.isolates.get(this[_isolateId]); |
1277 if (isolate == null) | 1276 if (isolate == null) |
1278 return; | 1277 return; |
1279 if (dart.notNull(this[_receivePort][_isClosed])) | 1278 if (dart.notNull(this[_receivePort][_isClosed])) |
1280 return; | 1279 return; |
1281 let msg = _clone(message); | 1280 let msg = dart.dcall(_clone, message); |
1282 if (dart.equals(isolate.controlPort, this[_receivePort])) { | 1281 if (dart.equals(dart.dload(isolate, 'controlPort'), this[_receivePort])) { |
1283 isolate.handleControlMessage(msg); | 1282 dart.dsend(isolate, 'handleControlMessage', msg); |
1284 return; | 1283 return; |
1285 } | 1284 } |
1286 exports._globalState.topEventLoop.enqueue(isolate, dart.fn((() => { | 1285 dart.dcall(exports._globalState.topEventLoop.enqueue, isolate, dart.fn((()
=> { |
1287 if (!dart.notNull(this[_receivePort][_isClosed])) { | 1286 if (!dart.notNull(this[_receivePort][_isClosed])) { |
1288 this[_receivePort][_add](msg); | 1287 dart.dcall(this[_receivePort][_add], msg); |
1289 } | 1288 } |
1290 }).bind(this)), `receive ${message}`); | 1289 }).bind(this)), `receive ${message}`); |
1291 } | 1290 } |
1292 ['=='](other) { | 1291 ['=='](other) { |
1293 return dart.is(other, _NativeJsSendPort) && dart.equals(this[_receivePort]
, dart.dload(other, _receivePort)); | 1292 return dart.is(other, _NativeJsSendPort) && dart.equals(this[_receivePort]
, dart.dload(other, _receivePort)); |
1294 } | 1293 } |
1295 get hashCode() { | 1294 get hashCode() { |
1296 return this[_receivePort][_id]; | 1295 return this[_receivePort][_id]; |
1297 } | 1296 } |
1298 } | 1297 } |
1299 _NativeJsSendPort[dart.implements] = () => [isolate.SendPort]; | 1298 _NativeJsSendPort[dart.implements] = () => [isolate.SendPort]; |
1300 dart.setSignature(_NativeJsSendPort, { | 1299 dart.setSignature(_NativeJsSendPort, { |
1301 constructors: () => ({_NativeJsSendPort: [_NativeJsSendPort, [RawReceivePort
Impl, core.int]]}), | 1300 constructors: () => ({_NativeJsSendPort: [_NativeJsSendPort, [RawReceivePort
Impl, core.int]]}), |
1302 methods: () => ({send: [dart.void, [dart.dynamic]]}) | 1301 methods: () => ({send: [dart.void, [dart.dynamic]]}) |
1303 }); | 1302 }); |
1304 class _WorkerSendPort extends _BaseSendPort { | 1303 class _WorkerSendPort extends _BaseSendPort { |
1305 _WorkerSendPort(workerId, isolateId, receivePortId) { | 1304 _WorkerSendPort(workerId, isolateId, receivePortId) { |
1306 this[_workerId] = workerId; | 1305 this[_workerId] = workerId; |
1307 this[_receivePortId] = receivePortId; | 1306 this[_receivePortId] = receivePortId; |
1308 super._BaseSendPort(isolateId); | 1307 super._BaseSendPort(isolateId); |
1309 } | 1308 } |
1310 send(message) { | 1309 send(message) { |
1311 let workerMessage = _serializeMessage(dart.map({command: 'message', port:
this, msg: message})); | 1310 let workerMessage = dart.dcall(_serializeMessage, dart.map({command: 'mess
age', port: this, msg: message})); |
1312 if (dart.notNull(exports._globalState.isWorker)) { | 1311 if (dart.notNull(exports._globalState.isWorker)) { |
1313 exports._globalState.mainManager.postMessage(workerMessage); | 1312 dart.dcall(exports._globalState.mainManager.postMessage, workerMessage); |
1314 } else { | 1313 } else { |
1315 let manager = exports._globalState.managers.get(this[_workerId]); | 1314 let manager = exports._globalState.managers.get(this[_workerId]); |
1316 if (manager != null) { | 1315 if (manager != null) { |
1317 manager.postMessage(workerMessage); | 1316 manager.postMessage(workerMessage); |
1318 } | 1317 } |
1319 } | 1318 } |
1320 } | 1319 } |
1321 ['=='](other) { | 1320 ['=='](other) { |
1322 return dart.is(other, _WorkerSendPort) && dart.equals(this[_workerId], dar
t.dload(other, _workerId)) && dart.equals(this[_isolateId], dart.dload(other, _i
solateId)) && dart.equals(this[_receivePortId], dart.dload(other, _receivePortId
)); | 1321 return dart.is(other, _WorkerSendPort) && dart.equals(this[_workerId], dar
t.dload(other, _workerId)) && dart.equals(this[_isolateId], dart.dload(other, _i
solateId)) && dart.equals(this[_receivePortId], dart.dload(other, _receivePortId
)); |
1323 } | 1322 } |
1324 get hashCode() { | 1323 get hashCode() { |
1325 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); | 1324 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); |
1326 } | 1325 } |
1327 } | 1326 } |
1328 _WorkerSendPort[dart.implements] = () => [isolate.SendPort]; | 1327 _WorkerSendPort[dart.implements] = () => [isolate.SendPort]; |
1329 dart.setSignature(_WorkerSendPort, { | 1328 dart.setSignature(_WorkerSendPort, { |
1330 constructors: () => ({_WorkerSendPort: [_WorkerSendPort, [core.int, core.int
, core.int]]}), | 1329 constructors: () => ({_WorkerSendPort: [_WorkerSendPort, [core.int, core.int
, core.int]]}), |
1331 methods: () => ({send: [dart.void, [dart.dynamic]]}) | 1330 methods: () => ({send: [dart.void, [dart.dynamic]]}) |
1332 }); | 1331 }); |
1333 let _handler = Symbol('_handler'); | 1332 let _handler = Symbol('_handler'); |
1334 class RawReceivePortImpl extends core.Object { | 1333 class RawReceivePortImpl extends core.Object { |
1335 RawReceivePortImpl(handler) { | 1334 RawReceivePortImpl(handler) { |
1336 this[_handler] = handler; | 1335 this[_handler] = handler; |
1337 this[_id] = (() => { | 1336 this[_id] = (() => { |
1338 let x = RawReceivePortImpl._nextFreeId; | 1337 let x = RawReceivePortImpl._nextFreeId; |
1339 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1; | 1338 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1; |
1340 return x; | 1339 return x; |
1341 })(); | 1340 })(); |
1342 this[_isClosed] = false; | 1341 this[_isClosed] = false; |
1343 exports._globalState.currentContext.register(this[_id], this); | 1342 dart.dcall(exports._globalState.currentContext.register, this[_id], this); |
1344 } | 1343 } |
1345 weak(handler) { | 1344 weak(handler) { |
1346 this[_handler] = handler; | 1345 this[_handler] = handler; |
1347 this[_id] = (() => { | 1346 this[_id] = (() => { |
1348 let x = RawReceivePortImpl._nextFreeId; | 1347 let x = RawReceivePortImpl._nextFreeId; |
1349 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1; | 1348 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1; |
1350 return x; | 1349 return x; |
1351 })(); | 1350 })(); |
1352 this[_isClosed] = false; | 1351 this[_isClosed] = false; |
1353 exports._globalState.currentContext.registerWeak(this[_id], this); | 1352 dart.dcall(exports._globalState.currentContext.registerWeak, this[_id], th
is); |
1354 } | 1353 } |
1355 _controlPort() { | 1354 _controlPort() { |
1356 this[_handler] = null; | 1355 this[_handler] = null; |
1357 this[_id] = 0; | 1356 this[_id] = 0; |
1358 this[_isClosed] = false; | 1357 this[_isClosed] = false; |
1359 } | 1358 } |
1360 set handler(newHandler) { | 1359 set handler(newHandler) { |
1361 this[_handler] = newHandler; | 1360 this[_handler] = newHandler; |
1362 } | 1361 } |
1363 [_close]() { | 1362 [_close]() { |
1364 this[_isClosed] = true; | 1363 this[_isClosed] = true; |
1365 this[_handler] = null; | 1364 this[_handler] = null; |
1366 } | 1365 } |
1367 close() { | 1366 close() { |
1368 if (dart.notNull(this[_isClosed])) | 1367 if (dart.notNull(this[_isClosed])) |
1369 return; | 1368 return; |
1370 this[_isClosed] = true; | 1369 this[_isClosed] = true; |
1371 this[_handler] = null; | 1370 this[_handler] = null; |
1372 exports._globalState.currentContext.unregister(this[_id]); | 1371 dart.dcall(exports._globalState.currentContext.unregister, this[_id]); |
1373 } | 1372 } |
1374 [_add](dataEvent) { | 1373 [_add](dataEvent) { |
1375 if (dart.notNull(this[_isClosed])) | 1374 if (dart.notNull(this[_isClosed])) |
1376 return; | 1375 return; |
1377 dart.dcall(this[_handler], dataEvent); | 1376 dart.dcall(this[_handler], dataEvent); |
1378 } | 1377 } |
1379 get sendPort() { | 1378 get sendPort() { |
1380 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; | 1379 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; |
1381 } | 1380 } |
1382 } | 1381 } |
(...skipping 26 matching lines...) Expand all Loading... |
1409 this[_rawPort] = rawPort; | 1408 this[_rawPort] = rawPort; |
1410 this[_controller] = null; | 1409 this[_controller] = null; |
1411 super.Stream(); | 1410 super.Stream(); |
1412 this[_controller] = async.StreamController.new({onCancel: dart.bind(this,
'close'), sync: true}); | 1411 this[_controller] = async.StreamController.new({onCancel: dart.bind(this,
'close'), sync: true}); |
1413 this[_rawPort].handler = dart.bind(this[_controller], 'add'); | 1412 this[_rawPort].handler = dart.bind(this[_controller], 'add'); |
1414 } | 1413 } |
1415 listen(onData, opts) { | 1414 listen(onData, opts) { |
1416 let onError = opts && 'onError' in opts ? opts.onError : null; | 1415 let onError = opts && 'onError' in opts ? opts.onError : null; |
1417 let onDone = opts && 'onDone' in opts ? opts.onDone : null; | 1416 let onDone = opts && 'onDone' in opts ? opts.onDone : null; |
1418 let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError :
null; | 1417 let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError :
null; |
1419 return this[_controller].stream.listen(onData, {onError: onError, onDone:
onDone, cancelOnError: cancelOnError}); | 1418 return dart.dcall(this[_controller].stream.listen, onData, {onError: onErr
or, onDone: onDone, cancelOnError: cancelOnError}); |
1420 } | 1419 } |
1421 close() { | 1420 close() { |
1422 this[_rawPort].close(); | 1421 dart.dcall(this[_rawPort].close); |
1423 this[_controller].close(); | 1422 dart.dcall(this[_controller].close); |
1424 } | 1423 } |
1425 get sendPort() { | 1424 get sendPort() { |
1426 return this[_rawPort].sendPort; | 1425 return this[_rawPort].sendPort; |
1427 } | 1426 } |
1428 } | 1427 } |
1429 ReceivePortImpl[dart.implements] = () => [isolate.ReceivePort]; | 1428 ReceivePortImpl[dart.implements] = () => [isolate.ReceivePort]; |
1430 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); | 1429 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); |
1431 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); | 1430 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); |
1432 dart.setSignature(ReceivePortImpl, { | 1431 dart.setSignature(ReceivePortImpl, { |
1433 constructors: () => ({ | 1432 constructors: () => ({ |
1434 ReceivePortImpl: [ReceivePortImpl, []], | 1433 ReceivePortImpl: [ReceivePortImpl, []], |
1435 weak: [ReceivePortImpl, []], | 1434 weak: [ReceivePortImpl, []], |
1436 fromRawReceivePort: [ReceivePortImpl, [isolate.RawReceivePort]] | 1435 fromRawReceivePort: [ReceivePortImpl, [isolate.RawReceivePort]] |
1437 }), | 1436 }), |
1438 methods: () => ({ | 1437 methods: () => ({ |
1439 listen: [async.StreamSubscription, [dart.functionType(dart.void, [dart.dyn
amic])], {onError: core.Function, onDone: dart.functionType(dart.void, []), canc
elOnError: core.bool}], | 1438 listen: [async.StreamSubscription, [dart.functionType(dart.void, [dart.dyn
amic])], {onError: core.Function, onDone: dart.functionType(dart.void, []), canc
elOnError: core.bool}], |
1440 close: [dart.void, []] | 1439 close: [dart.void, []] |
1441 }) | 1440 }) |
1442 }); | 1441 }); |
1443 let _once = Symbol('_once'); | 1442 let _once = Symbol('_once'); |
1444 let _inEventLoop = Symbol('_inEventLoop'); | 1443 let _inEventLoop = Symbol('_inEventLoop'); |
1445 let _handle = Symbol('_handle'); | 1444 let _handle = Symbol('_handle'); |
1446 class TimerImpl extends core.Object { | 1445 class TimerImpl extends core.Object { |
1447 TimerImpl(milliseconds, callback) { | 1446 TimerImpl(milliseconds, callback) { |
1448 this[_once] = true; | 1447 this[_once] = true; |
1449 this[_inEventLoop] = false; | 1448 this[_inEventLoop] = false; |
1450 this[_handle] = null; | 1449 this[_handle] = null; |
1451 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export
s._globalState.isWorker))) { | 1450 if (milliseconds == 0 && (!dart.notNull(dart.dcall(hasTimer)) || dart.notN
ull(exports._globalState.isWorker))) { |
1452 let internalCallback = (function() { | 1451 let internalCallback = (function() { |
1453 this[_handle] = null; | 1452 this[_handle] = null; |
1454 callback(); | 1453 callback(); |
1455 }).bind(this); | 1454 }).bind(this); |
1456 dart.fn(internalCallback, dart.void, []); | 1455 dart.fn(internalCallback, dart.void, []); |
1457 this[_handle] = 1; | 1456 this[_handle] = 1; |
1458 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo
ntext, internalCallback, 'timer'); | 1457 dart.dcall(exports._globalState.topEventLoop.enqueue, exports._globalSta
te.currentContext, internalCallback, 'timer'); |
1459 this[_inEventLoop] = true; | 1458 this[_inEventLoop] = true; |
1460 } else if (dart.notNull(hasTimer())) { | 1459 } else if (dart.notNull(dart.dcall(hasTimer))) { |
1461 let internalCallback = (function() { | 1460 let internalCallback = (function() { |
1462 this[_handle] = null; | 1461 this[_handle] = null; |
1463 leaveJsAsync(); | 1462 dart.dcall(leaveJsAsync); |
1464 callback(); | 1463 callback(); |
1465 }).bind(this); | 1464 }).bind(this); |
1466 dart.fn(internalCallback, dart.void, []); | 1465 dart.fn(internalCallback, dart.void, []); |
1467 enterJsAsync(); | 1466 dart.dcall(enterJsAsync); |
1468 this[_handle] = self.setTimeout(internalCallback, milliseconds); | 1467 this[_handle] = dart.as(self.setTimeout(internalCallback, milliseconds),
core.int); |
1469 } else { | 1468 } else { |
1470 dart.assert(dart.notNull(milliseconds) > 0); | 1469 dart.assert(dart.notNull(milliseconds) > 0); |
1471 dart.throw(new core.UnsupportedError("Timer greater than 0.")); | 1470 dart.throw(new core.UnsupportedError("Timer greater than 0.")); |
1472 } | 1471 } |
1473 } | 1472 } |
1474 periodic(milliseconds, callback) { | 1473 periodic(milliseconds, callback) { |
1475 this[_once] = false; | 1474 this[_once] = false; |
1476 this[_inEventLoop] = false; | 1475 this[_inEventLoop] = false; |
1477 this[_handle] = null; | 1476 this[_handle] = null; |
1478 if (dart.notNull(hasTimer())) { | 1477 if (dart.notNull(dart.dcall(hasTimer))) { |
1479 enterJsAsync(); | 1478 dart.dcall(enterJsAsync); |
1480 this[_handle] = self.setInterval(dart.fn((() => { | 1479 this[_handle] = dart.as(self.setInterval(dart.fn((() => { |
1481 callback(this); | 1480 callback(this); |
1482 }).bind(this)), milliseconds); | 1481 }).bind(this)), milliseconds), core.int); |
1483 } else { | 1482 } else { |
1484 dart.throw(new core.UnsupportedError("Periodic timer.")); | 1483 dart.throw(new core.UnsupportedError("Periodic timer.")); |
1485 } | 1484 } |
1486 } | 1485 } |
1487 cancel() { | 1486 cancel() { |
1488 if (dart.notNull(hasTimer())) { | 1487 if (dart.notNull(dart.dcall(hasTimer))) { |
1489 if (dart.notNull(this[_inEventLoop])) { | 1488 if (dart.notNull(this[_inEventLoop])) { |
1490 dart.throw(new core.UnsupportedError("Timer in event loop cannot be ca
nceled.")); | 1489 dart.throw(new core.UnsupportedError("Timer in event loop cannot be ca
nceled.")); |
1491 } | 1490 } |
1492 if (this[_handle] == null) | 1491 if (this[_handle] == null) |
1493 return; | 1492 return; |
1494 leaveJsAsync(); | 1493 dart.dcall(leaveJsAsync); |
1495 if (dart.notNull(this[_once])) { | 1494 if (dart.notNull(this[_once])) { |
1496 self.clearTimeout(this[_handle]); | 1495 self.clearTimeout(this[_handle]); |
1497 } else { | 1496 } else { |
1498 self.clearInterval(this[_handle]); | 1497 self.clearInterval(this[_handle]); |
1499 } | 1498 } |
1500 this[_handle] = null; | 1499 this[_handle] = null; |
1501 } else { | 1500 } else { |
1502 dart.throw(new core.UnsupportedError("Canceling a timer.")); | 1501 dart.throw(new core.UnsupportedError("Canceling a timer.")); |
1503 } | 1502 } |
1504 } | 1503 } |
1505 get isActive() { | 1504 get isActive() { |
1506 return this[_handle] != null; | 1505 return this[_handle] != null; |
1507 } | 1506 } |
1508 } | 1507 } |
1509 TimerImpl[dart.implements] = () => [async.Timer]; | 1508 TimerImpl[dart.implements] = () => [async.Timer]; |
1510 dart.defineNamedConstructor(TimerImpl, 'periodic'); | 1509 dart.defineNamedConstructor(TimerImpl, 'periodic'); |
1511 dart.setSignature(TimerImpl, { | 1510 dart.setSignature(TimerImpl, { |
1512 constructors: () => ({ | 1511 constructors: () => ({ |
1513 TimerImpl: [TimerImpl, [core.int, dart.functionType(dart.void, [])]], | 1512 TimerImpl: [TimerImpl, [core.int, dart.functionType(dart.void, [])]], |
1514 periodic: [TimerImpl, [core.int, dart.functionType(dart.void, [async.Timer
])]] | 1513 periodic: [TimerImpl, [core.int, dart.functionType(dart.void, [async.Timer
])]] |
1515 }), | 1514 }), |
1516 methods: () => ({cancel: [dart.void, []]}) | 1515 methods: () => ({cancel: [dart.void, []]}) |
1517 }); | 1516 }); |
1518 function hasTimer() { | 1517 function hasTimer() { |
1519 return self.setTimeout != null; | 1518 return self.setTimeout != null; |
1520 } | 1519 } |
1521 dart.fn(hasTimer, core.bool, []); | 1520 dart.fn(hasTimer, core.bool, []); |
1522 class CapabilityImpl extends core.Object { | 1521 class CapabilityImpl extends core.Object { |
1523 CapabilityImpl() { | 1522 CapabilityImpl() { |
1524 this._internal(_js_helper.random64()); | 1523 this._internal(dart.dcall(_js_helper.random64)); |
1525 } | 1524 } |
1526 _internal(id) { | 1525 _internal(id) { |
1527 this[_id] = id; | 1526 this[_id] = id; |
1528 } | 1527 } |
1529 get hashCode() { | 1528 get hashCode() { |
1530 let hash = this[_id]; | 1529 let hash = this[_id]; |
1531 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296)[dartx.t
runcate](); | 1530 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296)[dartx.t
runcate](); |
1532 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295; | 1531 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295; |
1533 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 12; | 1532 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 12; |
1534 hash = dart.notNull(hash) * 5 & 4294967295; | 1533 hash = dart.notNull(hash) * 5 & 4294967295; |
1535 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 4; | 1534 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 4; |
1536 hash = dart.notNull(hash) * 2057 & 4294967295; | 1535 hash = dart.notNull(hash) * 2057 & 4294967295; |
1537 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 16; | 1536 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 16; |
1538 return hash; | 1537 return hash; |
1539 } | 1538 } |
1540 ['=='](other) { | 1539 ['=='](other) { |
1541 if (dart.notNull(core.identical(other, this))) | 1540 if (dart.notNull(dart.dcall(core.identical, other, this))) |
1542 return true; | 1541 return true; |
1543 if (dart.is(other, CapabilityImpl)) { | 1542 if (dart.is(other, CapabilityImpl)) { |
1544 return core.identical(this[_id], other[_id]); | 1543 return dart.dcall(core.identical, this[_id], other[_id]); |
1545 } | 1544 } |
1546 return false; | 1545 return false; |
1547 } | 1546 } |
1548 } | 1547 } |
1549 CapabilityImpl[dart.implements] = () => [isolate.Capability]; | 1548 CapabilityImpl[dart.implements] = () => [isolate.Capability]; |
1550 dart.defineNamedConstructor(CapabilityImpl, '_internal'); | 1549 dart.defineNamedConstructor(CapabilityImpl, '_internal'); |
1551 dart.setSignature(CapabilityImpl, { | 1550 dart.setSignature(CapabilityImpl, { |
1552 constructors: () => ({ | 1551 constructors: () => ({ |
1553 CapabilityImpl: [CapabilityImpl, []], | 1552 CapabilityImpl: [CapabilityImpl, []], |
1554 _internal: [CapabilityImpl, [core.int]] | 1553 _internal: [CapabilityImpl, [core.int]] |
1555 }), | 1554 }), |
1556 methods: () => ({'==': [core.bool, [core.Object]]}) | 1555 methods: () => ({'==': [core.bool, [core.Object]]}) |
1557 }); | 1556 }); |
1558 // Exports: | 1557 // Exports: |
1559 exports.enterJsAsync = enterJsAsync; | 1558 exports.enterJsAsync = enterJsAsync; |
1560 exports.leaveJsAsync = leaveJsAsync; | 1559 exports.leaveJsAsync = leaveJsAsync; |
1561 exports.isWorker = isWorker; | 1560 exports.isWorker = isWorker; |
1562 exports.startRootIsolate = startRootIsolate; | 1561 exports.startRootIsolate = startRootIsolate; |
1563 exports.IsolateNatives = IsolateNatives; | 1562 exports.IsolateNatives = IsolateNatives; |
1564 exports.RawReceivePortImpl = RawReceivePortImpl; | 1563 exports.RawReceivePortImpl = RawReceivePortImpl; |
1565 exports.ReceivePortImpl = ReceivePortImpl; | 1564 exports.ReceivePortImpl = ReceivePortImpl; |
1566 exports.TimerImpl = TimerImpl; | 1565 exports.TimerImpl = TimerImpl; |
1567 exports.hasTimer = hasTimer; | 1566 exports.hasTimer = hasTimer; |
1568 exports.CapabilityImpl = CapabilityImpl; | 1567 exports.CapabilityImpl = CapabilityImpl; |
1569 }); | 1568 }); |
OLD | NEW |