OLD | NEW |
1 var _isolate_helper = dart.defineLibrary(_isolate_helper, {}); | 1 var _isolate_helper = dart.defineLibrary(_isolate_helper, {}); |
2 var core = dart.import(core); | 2 var core = dart.import(core); |
3 var _native_typed_data = dart.import(_native_typed_data); | 3 var _native_typed_data = dart.import(_native_typed_data); |
4 var _interceptors = dart.lazyImport(_interceptors); | 4 var _interceptors = dart.lazyImport(_interceptors); |
5 var _js_helper = dart.lazyImport(_js_helper); | 5 var _js_helper = dart.lazyImport(_js_helper); |
6 var isolate = dart.import(isolate); | 6 var isolate = dart.import(isolate); |
7 var _foreign_helper = dart.import(_foreign_helper); | 7 var _foreign_helper = dart.import(_foreign_helper); |
8 var _js_embedded_names = dart.import(_js_embedded_names); | 8 var _js_embedded_names = dart.import(_js_embedded_names); |
9 var collection = dart.import(collection); | 9 var collection = dart.import(collection); |
10 var async = dart.import(async); | 10 var async = dart.import(async); |
(...skipping 15 matching lines...) Expand all Loading... |
26 dart.fn(_clone); | 26 dart.fn(_clone); |
27 let _serializeSendPorts = Symbol('_serializeSendPorts'); | 27 let _serializeSendPorts = Symbol('_serializeSendPorts'); |
28 let _workerId = Symbol('_workerId'); | 28 let _workerId = Symbol('_workerId'); |
29 let _isolateId = Symbol('_isolateId'); | 29 let _isolateId = Symbol('_isolateId'); |
30 let _receivePortId = Symbol('_receivePortId'); | 30 let _receivePortId = Symbol('_receivePortId'); |
31 let _id = Symbol('_id'); | 31 let _id = Symbol('_id'); |
32 let _receivePort = Symbol('_receivePort'); | 32 let _receivePort = Symbol('_receivePort'); |
33 class _Serializer extends core.Object { | 33 class _Serializer extends core.Object { |
34 _Serializer(opts) { | 34 _Serializer(opts) { |
35 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; | 35 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria
lizeSendPorts : true; |
36 this.serializedObjectIds = new (core.Map$(core.Object, core.int)).identity
(); | 36 this.serializedObjectIds = core.Map$(core.Object, core.int).identity(); |
37 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); | 37 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); |
38 } | 38 } |
39 serialize(x) { | 39 serialize(x) { |
40 if (this.isPrimitive(x)) | 40 if (this.isPrimitive(x)) |
41 return this.serializePrimitive(x); | 41 return this.serializePrimitive(x); |
42 let serializationId = this.serializedObjectIds.get(x); | 42 let serializationId = this.serializedObjectIds.get(x); |
43 if (serializationId != null) | 43 if (serializationId != null) |
44 return this.makeRef(serializationId); | 44 return this.makeRef(serializationId); |
45 serializationId = this.serializedObjectIds.length; | 45 serializationId = this.serializedObjectIds.length; |
46 this.serializedObjectIds.set(x, serializationId); | 46 this.serializedObjectIds.set(x, serializationId); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 serializeJsSendPort: [core.Object, [_NativeJsSendPort]], | 183 serializeJsSendPort: [core.Object, [_NativeJsSendPort]], |
184 serializeCapability: [core.Object, [CapabilityImpl]], | 184 serializeCapability: [core.Object, [CapabilityImpl]], |
185 serializeClosure: [core.Object, [_js_helper.Closure]], | 185 serializeClosure: [core.Object, [_js_helper.Closure]], |
186 serializeDartObject: [core.Object, [core.Object]] | 186 serializeDartObject: [core.Object, [core.Object]] |
187 }) | 187 }) |
188 }); | 188 }); |
189 let _adjustSendPorts = Symbol('_adjustSendPorts'); | 189 let _adjustSendPorts = Symbol('_adjustSendPorts'); |
190 class _Deserializer extends core.Object { | 190 class _Deserializer extends core.Object { |
191 _Deserializer(opts) { | 191 _Deserializer(opts) { |
192 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP
orts : true; | 192 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP
orts : true; |
193 this.deserializedObjects = new core.List(); | 193 this.deserializedObjects = core.List.new(); |
194 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); | 194 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); |
195 } | 195 } |
196 deserialize(x) { | 196 deserialize(x) { |
197 if (this.isPrimitive(x)) | 197 if (this.isPrimitive(x)) |
198 return this.deserializePrimitive(x); | 198 return this.deserializePrimitive(x); |
199 if (!dart.is(x, _interceptors.JSArray)) | 199 if (!dart.is(x, _interceptors.JSArray)) |
200 throw new core.ArgumentError(`Bad serialized message: ${x}`); | 200 throw new core.ArgumentError(`Bad serialized message: ${x}`); |
201 switch (dart.dload(x, 'first')) { | 201 switch (dart.dload(x, 'first')) { |
202 case "ref": | 202 case "ref": |
203 { | 203 { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 deserializeArrayInPlace(x) { | 283 deserializeArrayInPlace(x) { |
284 for (let i = 0; dart.notNull(i) < dart.notNull(x[core.$length]); i = dart.
notNull(i) + 1) { | 284 for (let i = 0; dart.notNull(i) < dart.notNull(x[core.$length]); i = dart.
notNull(i) + 1) { |
285 x[core.$set](i, this.deserialize(x[core.$get](i))); | 285 x[core.$set](i, this.deserialize(x[core.$get](i))); |
286 } | 286 } |
287 return x; | 287 return x; |
288 } | 288 } |
289 deserializeFixed(x) { | 289 deserializeFixed(x) { |
290 dart.assert(dart.equals(dart.dindex(x, 0), 'fixed')); | 290 dart.assert(dart.equals(dart.dindex(x, 0), 'fixed')); |
291 let result = dart.as(dart.dindex(x, 1), core.List); | 291 let result = dart.as(dart.dindex(x, 1), core.List); |
292 this.deserializedObjects[core.$add](result); | 292 this.deserializedObjects[core.$add](result); |
293 return new _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(da
rt.as(result, _interceptors.JSArray))); | 293 return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.a
s(result, _interceptors.JSArray))); |
294 } | 294 } |
295 deserializeExtendable(x) { | 295 deserializeExtendable(x) { |
296 dart.assert(dart.equals(dart.dindex(x, 0), 'extendable')); | 296 dart.assert(dart.equals(dart.dindex(x, 0), 'extendable')); |
297 let result = dart.as(dart.dindex(x, 1), core.List); | 297 let result = dart.as(dart.dindex(x, 1), core.List); |
298 this.deserializedObjects[core.$add](result); | 298 this.deserializedObjects[core.$add](result); |
299 return new _interceptors.JSArray.markGrowable(this.deserializeArrayInPlace
(dart.as(result, _interceptors.JSArray))); | 299 return _interceptors.JSArray.markGrowable(this.deserializeArrayInPlace(dar
t.as(result, _interceptors.JSArray))); |
300 } | 300 } |
301 deserializeMutable(x) { | 301 deserializeMutable(x) { |
302 dart.assert(dart.equals(dart.dindex(x, 0), 'mutable')); | 302 dart.assert(dart.equals(dart.dindex(x, 0), 'mutable')); |
303 let result = dart.as(dart.dindex(x, 1), core.List); | 303 let result = dart.as(dart.dindex(x, 1), core.List); |
304 this.deserializedObjects[core.$add](result); | 304 this.deserializedObjects[core.$add](result); |
305 return this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)
); | 305 return this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)
); |
306 } | 306 } |
307 deserializeConst(x) { | 307 deserializeConst(x) { |
308 dart.assert(dart.equals(dart.dindex(x, 0), 'const')); | 308 dart.assert(dart.equals(dart.dindex(x, 0), 'const')); |
309 let result = dart.as(dart.dindex(x, 1), core.List); | 309 let result = dart.as(dart.dindex(x, 1), core.List); |
310 this.deserializedObjects[core.$add](result); | 310 this.deserializedObjects[core.$add](result); |
311 return new _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(da
rt.as(result, _interceptors.JSArray))); | 311 return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.a
s(result, _interceptors.JSArray))); |
312 } | 312 } |
313 deserializeMap(x) { | 313 deserializeMap(x) { |
314 dart.assert(dart.equals(dart.dindex(x, 0), 'map')); | 314 dart.assert(dart.equals(dart.dindex(x, 0), 'map')); |
315 let keys = dart.as(dart.dindex(x, 1), core.List); | 315 let keys = dart.as(dart.dindex(x, 1), core.List); |
316 let values = dart.as(dart.dindex(x, 2), core.List); | 316 let values = dart.as(dart.dindex(x, 2), core.List); |
317 let result = dart.map(); | 317 let result = dart.map(); |
318 this.deserializedObjects[core.$add](result); | 318 this.deserializedObjects[core.$add](result); |
319 keys = keys[core.$map](dart.bind(this, 'deserialize'))[core.$toList](); | 319 keys = keys[core.$map](dart.bind(this, 'deserialize'))[core.$toList](); |
320 for (let i = 0; dart.notNull(i) < dart.notNull(keys[core.$length]); i = da
rt.notNull(i) + 1) { | 320 for (let i = 0; dart.notNull(i) < dart.notNull(keys[core.$length]); i = da
rt.notNull(i) + 1) { |
321 result.set(keys[core.$get](i), this.deserialize(values[core.$get](i))); | 321 result.set(keys[core.$get](i), this.deserialize(values[core.$get](i))); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 this.rootContext = null; | 477 this.rootContext = null; |
478 this.topEventLoop = null; | 478 this.topEventLoop = null; |
479 this.fromCommandLine = null; | 479 this.fromCommandLine = null; |
480 this.isWorker = null; | 480 this.isWorker = null; |
481 this.supportsWorkers = null; | 481 this.supportsWorkers = null; |
482 this.isolates = null; | 482 this.isolates = null; |
483 this.mainManager = null; | 483 this.mainManager = null; |
484 this.managers = null; | 484 this.managers = null; |
485 this[_nativeDetectEnvironment](); | 485 this[_nativeDetectEnvironment](); |
486 this.topEventLoop = new _EventLoop(); | 486 this.topEventLoop = new _EventLoop(); |
487 this.isolates = new (core.Map$(core.int, _IsolateContext))(); | 487 this.isolates = core.Map$(core.int, _IsolateContext).new(); |
488 this.managers = new (core.Map$(core.int, core.Object))(); | 488 this.managers = core.Map$(core.int, core.Object).new(); |
489 if (this.isWorker) { | 489 if (this.isWorker) { |
490 this.mainManager = new _MainManagerStub(); | 490 this.mainManager = new _MainManagerStub(); |
491 this[_nativeInitWorkerMessageHandler](); | 491 this[_nativeInitWorkerMessageHandler](); |
492 } | 492 } |
493 } | 493 } |
494 [_nativeDetectEnvironment]() { | 494 [_nativeDetectEnvironment]() { |
495 let isWindowDefined = exports.globalWindow != null; | 495 let isWindowDefined = exports.globalWindow != null; |
496 let isWorkerDefined = exports.globalWorker != null; | 496 let isWorkerDefined = exports.globalWorker != null; |
497 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); | 497 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); |
498 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && IsolateNatives.thisScript != null; | 498 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && IsolateNatives.thisScript != null; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 let _setGlobals = Symbol('_setGlobals'); | 540 let _setGlobals = Symbol('_setGlobals'); |
541 let _addRegistration = Symbol('_addRegistration'); | 541 let _addRegistration = Symbol('_addRegistration'); |
542 let _close = Symbol('_close'); | 542 let _close = Symbol('_close'); |
543 class _IsolateContext extends core.Object { | 543 class _IsolateContext extends core.Object { |
544 _IsolateContext() { | 544 _IsolateContext() { |
545 this.id = (() => { | 545 this.id = (() => { |
546 let o = exports._globalState, x = o.nextIsolateId; | 546 let o = exports._globalState, x = o.nextIsolateId; |
547 o.nextIsolateId = dart.notNull(x) + 1; | 547 o.nextIsolateId = dart.notNull(x) + 1; |
548 return x; | 548 return x; |
549 })(); | 549 })(); |
550 this.ports = new (core.Map$(core.int, RawReceivePortImpl))(); | 550 this.ports = core.Map$(core.int, RawReceivePortImpl).new(); |
551 this.weakPorts = new (core.Set$(core.int))(); | 551 this.weakPorts = core.Set$(core.int).new(); |
552 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); | 552 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); |
553 this.controlPort = new RawReceivePortImpl._controlPort(); | 553 this.controlPort = new RawReceivePortImpl._controlPort(); |
554 this.pauseCapability = new isolate.Capability(); | 554 this.pauseCapability = isolate.Capability.new(); |
555 this.terminateCapability = new isolate.Capability(); | 555 this.terminateCapability = isolate.Capability.new(); |
556 this.delayedEvents = dart.setType([], core.List$(_IsolateEvent)); | 556 this.delayedEvents = dart.setType([], core.List$(_IsolateEvent)); |
557 this.pauseTokens = new (core.Set$(isolate.Capability))(); | 557 this.pauseTokens = core.Set$(isolate.Capability).new(); |
558 this.errorPorts = new (core.Set$(isolate.SendPort))(); | 558 this.errorPorts = core.Set$(isolate.SendPort).new(); |
559 this.initialized = false; | 559 this.initialized = false; |
560 this.isPaused = false; | 560 this.isPaused = false; |
561 this.doneHandlers = null; | 561 this.doneHandlers = null; |
562 this[_scheduledControlEvents] = null; | 562 this[_scheduledControlEvents] = null; |
563 this[_isExecutingEvent] = false; | 563 this[_isExecutingEvent] = false; |
564 this.errorsAreFatal = true; | 564 this.errorsAreFatal = true; |
565 this.registerWeak(this.controlPort[_id], this.controlPort); | 565 this.registerWeak(this.controlPort[_id], this.controlPort); |
566 } | 566 } |
567 addPause(authentification, resume) { | 567 addPause(authentification, resume) { |
568 if (!dart.equals(this.pauseCapability, authentification)) | 568 if (!dart.equals(this.pauseCapability, authentification)) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 let respond = () => { | 611 let respond = () => { |
612 responsePort.send(null); | 612 responsePort.send(null); |
613 }; | 613 }; |
614 dart.fn(respond, dart.void, []); | 614 dart.fn(respond, dart.void, []); |
615 if (pingType == isolate.Isolate.AS_EVENT) { | 615 if (pingType == isolate.Isolate.AS_EVENT) { |
616 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); | 616 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); |
617 return; | 617 return; |
618 } | 618 } |
619 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); | 619 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); |
620 if (this[_scheduledControlEvents] == null) { | 620 if (this[_scheduledControlEvents] == null) { |
621 this[_scheduledControlEvents] = new collection.Queue(); | 621 this[_scheduledControlEvents] = collection.Queue.new(); |
622 } | 622 } |
623 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); | 623 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); |
624 } | 624 } |
625 handleKill(authentification, priority) { | 625 handleKill(authentification, priority) { |
626 if (!dart.equals(this.terminateCapability, authentification)) | 626 if (!dart.equals(this.terminateCapability, authentification)) |
627 return; | 627 return; |
628 if (priority == isolate.Isolate.IMMEDIATE || priority == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { | 628 if (priority == isolate.Isolate.IMMEDIATE || priority == isolate.Isolate.B
EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { |
629 this.kill(); | 629 this.kill(); |
630 return; | 630 return; |
631 } | 631 } |
632 if (priority == isolate.Isolate.AS_EVENT) { | 632 if (priority == isolate.Isolate.AS_EVENT) { |
633 exports._globalState.topEventLoop.enqueue(this, dart.bind(this, 'kill'),
"kill"); | 633 exports._globalState.topEventLoop.enqueue(this, dart.bind(this, 'kill'),
"kill"); |
634 return; | 634 return; |
635 } | 635 } |
636 dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT); | 636 dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT); |
637 if (this[_scheduledControlEvents] == null) { | 637 if (this[_scheduledControlEvents] == null) { |
638 this[_scheduledControlEvents] = new collection.Queue(); | 638 this[_scheduledControlEvents] = collection.Queue.new(); |
639 } | 639 } |
640 dart.dsend(this[_scheduledControlEvents], 'addLast', dart.bind(this, 'kill
')); | 640 dart.dsend(this[_scheduledControlEvents], 'addLast', dart.bind(this, 'kill
')); |
641 } | 641 } |
642 addErrorListener(port) { | 642 addErrorListener(port) { |
643 this.errorPorts.add(port); | 643 this.errorPorts.add(port); |
644 } | 644 } |
645 removeErrorListener(port) { | 645 removeErrorListener(port) { |
646 this.errorPorts.remove(port); | 646 this.errorPorts.remove(port); |
647 } | 647 } |
648 handleUncaughtError(error, stackTrace) { | 648 handleUncaughtError(error, stackTrace) { |
649 if (this.errorPorts[core.$isEmpty]) { | 649 if (this.errorPorts[core.$isEmpty]) { |
650 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { | 650 if (dart.notNull(this.errorsAreFatal) && dart.notNull(core.identical(thi
s, exports._globalState.rootContext))) { |
651 return; | 651 return; |
652 } | 652 } |
653 if (self.console && self.console.error) { | 653 if (self.console && self.console.error) { |
654 self.console.error(error, stackTrace); | 654 self.console.error(error, stackTrace); |
655 } else { | 655 } else { |
656 core.print(error); | 656 core.print(error); |
657 if (stackTrace != null) | 657 if (stackTrace != null) |
658 core.print(stackTrace); | 658 core.print(stackTrace); |
659 } | 659 } |
660 return; | 660 return; |
661 } | 661 } |
662 let message = new core.List(2); | 662 let message = core.List.new(2); |
663 message[core.$set](0, dart.toString(error)); | 663 message[core.$set](0, dart.toString(error)); |
664 message[core.$set](1, stackTrace == null ? null : dart.toString(stackTrace
)); | 664 message[core.$set](1, stackTrace == null ? null : dart.toString(stackTrace
)); |
665 for (let port of this.errorPorts) | 665 for (let port of this.errorPorts) |
666 port.send(message); | 666 port.send(message); |
667 } | 667 } |
668 eval(code) { | 668 eval(code) { |
669 let old = exports._globalState.currentContext; | 669 let old = exports._globalState.currentContext; |
670 exports._globalState.currentContext = this; | 670 exports._globalState.currentContext = this; |
671 this[_setGlobals](); | 671 this[_setGlobals](); |
672 let result = null; | 672 let result = null; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 break; | 747 break; |
748 } | 748 } |
749 default: | 749 default: |
750 } | 750 } |
751 } | 751 } |
752 lookup(portId) { | 752 lookup(portId) { |
753 return this.ports.get(portId); | 753 return this.ports.get(portId); |
754 } | 754 } |
755 [_addRegistration](portId, port) { | 755 [_addRegistration](portId, port) { |
756 if (this.ports.containsKey(portId)) { | 756 if (this.ports.containsKey(portId)) { |
757 throw new core.Exception("Registry: ports must be registered only once."
); | 757 throw core.Exception.new("Registry: ports must be registered only once."
); |
758 } | 758 } |
759 this.ports.set(portId, port); | 759 this.ports.set(portId, port); |
760 } | 760 } |
761 register(portId, port) { | 761 register(portId, port) { |
762 this[_addRegistration](portId, port); | 762 this[_addRegistration](portId, port); |
763 this[_updateGlobalState](); | 763 this[_updateGlobalState](); |
764 } | 764 } |
765 registerWeak(portId, port) { | 765 registerWeak(portId, port) { |
766 this.weakPorts.add(portId); | 766 this.weakPorts.add(portId); |
767 this[_addRegistration](portId, port); | 767 this[_addRegistration](portId, port); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 register: [dart.void, [core.int, RawReceivePortImpl]], | 819 register: [dart.void, [core.int, RawReceivePortImpl]], |
820 registerWeak: [dart.void, [core.int, RawReceivePortImpl]], | 820 registerWeak: [dart.void, [core.int, RawReceivePortImpl]], |
821 [_updateGlobalState]: [dart.void, []], | 821 [_updateGlobalState]: [dart.void, []], |
822 kill: [dart.void, []], | 822 kill: [dart.void, []], |
823 unregister: [dart.void, [core.int]] | 823 unregister: [dart.void, [core.int]] |
824 }) | 824 }) |
825 }); | 825 }); |
826 let _runHelper = Symbol('_runHelper'); | 826 let _runHelper = Symbol('_runHelper'); |
827 class _EventLoop extends core.Object { | 827 class _EventLoop extends core.Object { |
828 _EventLoop() { | 828 _EventLoop() { |
829 this.events = new (collection.Queue$(_IsolateEvent))(); | 829 this.events = collection.Queue$(_IsolateEvent).new(); |
830 this[_activeJsAsyncCount] = 0; | 830 this[_activeJsAsyncCount] = 0; |
831 } | 831 } |
832 enqueue(isolate, fn, msg) { | 832 enqueue(isolate, fn, msg) { |
833 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d
art.as(fn, core.Function), dart.as(msg, core.String))); | 833 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d
art.as(fn, core.Function), dart.as(msg, core.String))); |
834 } | 834 } |
835 prequeue(event) { | 835 prequeue(event) { |
836 this.events.addFirst(event); | 836 this.events.addFirst(event); |
837 } | 837 } |
838 dequeue() { | 838 dequeue() { |
839 if (this.events[core.$isEmpty]) | 839 if (this.events[core.$isEmpty]) |
840 return null; | 840 return null; |
841 return this.events.removeFirst(); | 841 return this.events.removeFirst(); |
842 } | 842 } |
843 checkOpenReceivePortsFromCommandLine() { | 843 checkOpenReceivePortsFromCommandLine() { |
844 if (dart.notNull(exports._globalState.rootContext != null) && dart.notNull
(exports._globalState.isolates.containsKey(exports._globalState.rootContext.id))
&& dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports._
globalState.rootContext.ports.isEmpty)) { | 844 if (dart.notNull(exports._globalState.rootContext != null) && dart.notNull
(exports._globalState.isolates.containsKey(exports._globalState.rootContext.id))
&& dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports._
globalState.rootContext.ports.isEmpty)) { |
845 throw new core.Exception("Program exited with open ReceivePorts."); | 845 throw core.Exception.new("Program exited with open ReceivePorts."); |
846 } | 846 } |
847 } | 847 } |
848 runIteration() { | 848 runIteration() { |
849 let event = this.dequeue(); | 849 let event = this.dequeue(); |
850 if (event == null) { | 850 if (event == null) { |
851 this.checkOpenReceivePortsFromCommandLine(); | 851 this.checkOpenReceivePortsFromCommandLine(); |
852 exports._globalState.maybeCloseWorker(); | 852 exports._globalState.maybeCloseWorker(); |
853 return false; | 853 return false; |
854 } | 854 } |
855 event.process(); | 855 event.process(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 }, core.Object, [core.String])}); | 1061 }, core.Object, [core.String])}); |
1062 } | 1062 } |
1063 static _log(msg) { | 1063 static _log(msg) { |
1064 if (exports._globalState.isWorker) { | 1064 if (exports._globalState.isWorker) { |
1065 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); | 1065 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); |
1066 } else { | 1066 } else { |
1067 try { | 1067 try { |
1068 IsolateNatives._consoleLog(msg); | 1068 IsolateNatives._consoleLog(msg); |
1069 } catch (e) { | 1069 } catch (e) { |
1070 let trace = dart.stackTrace(e); | 1070 let trace = dart.stackTrace(e); |
1071 throw new core.Exception(trace); | 1071 throw core.Exception.new(trace); |
1072 } | 1072 } |
1073 | 1073 |
1074 } | 1074 } |
1075 } | 1075 } |
1076 static _consoleLog(msg) { | 1076 static _consoleLog(msg) { |
1077 _js_helper.requiresPreamble(); | 1077 _js_helper.requiresPreamble(); |
1078 self.console.log(msg); | 1078 self.console.log(msg); |
1079 } | 1079 } |
1080 static _getJSFunctionFromName(functionName) { | 1080 static _getJSFunctionFromName(functionName) { |
1081 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", _js_
embedded_names.GLOBAL_FUNCTIONS); | 1081 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", _js_
embedded_names.GLOBAL_FUNCTIONS); |
(...skipping 18 matching lines...) Expand all Loading... |
1100 static spawnUri(uri, args, message, startPaused) { | 1100 static spawnUri(uri, args, message, startPaused) { |
1101 IsolateNatives.enableSpawnWorker = true; | 1101 IsolateNatives.enableSpawnWorker = true; |
1102 let isLight = false; | 1102 let isLight = false; |
1103 let isSpawnUri = true; | 1103 let isSpawnUri = true; |
1104 return IsolateNatives.spawn(null, dart.toString(uri), args, message, isLig
ht, isSpawnUri, startPaused); | 1104 return IsolateNatives.spawn(null, dart.toString(uri), args, message, isLig
ht, isSpawnUri, startPaused); |
1105 } | 1105 } |
1106 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { | 1106 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { |
1107 if (uri != null && dart.notNull(uri.endsWith(".dart"))) { | 1107 if (uri != null && dart.notNull(uri.endsWith(".dart"))) { |
1108 uri = dart.notNull(uri) + ".js"; | 1108 uri = dart.notNull(uri) + ".js"; |
1109 } | 1109 } |
1110 let port = new isolate.ReceivePort(); | 1110 let port = isolate.ReceivePort.new(); |
1111 let completer = new (async.Completer$(core.List))(); | 1111 let completer = async.Completer$(core.List).new(); |
1112 port.first.then(dart.fn(msg => { | 1112 port.first.then(dart.fn(msg => { |
1113 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { | 1113 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { |
1114 completer.complete(msg); | 1114 completer.complete(msg); |
1115 } else { | 1115 } else { |
1116 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); | 1116 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); |
1117 completer.completeError(dart.dindex(msg, 1)); | 1117 completer.completeError(dart.dindex(msg, 1)); |
1118 } | 1118 } |
1119 })); | 1119 })); |
1120 let signalReply = port.sendPort; | 1120 let signalReply = port.sendPort; |
1121 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { | 1121 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { |
1122 IsolateNatives._startWorker(functionName, uri, args, message, isSpawnUri
, startPaused, signalReply, dart.fn(message => completer.completeError(message),
dart.void, [core.String])); | 1122 IsolateNatives._startWorker(functionName, uri, args, message, isSpawnUri
, startPaused, signalReply, dart.fn(message => completer.completeError(message),
dart.void, [core.String])); |
1123 } else { | 1123 } else { |
1124 IsolateNatives._startNonWorker(functionName, uri, args, message, isSpawn
Uri, startPaused, signalReply); | 1124 IsolateNatives._startNonWorker(functionName, uri, args, message, isSpawn
Uri, startPaused, signalReply); |
1125 } | 1125 } |
1126 return completer.future; | 1126 return completer.future; |
1127 } | 1127 } |
1128 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { | 1128 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause
d, replyPort, onError) { |
1129 if (args != null) | 1129 if (args != null) |
1130 args = new (core.List$(core.String)).from(args); | 1130 args = core.List$(core.String).from(args); |
1131 if (exports._globalState.isWorker) { | 1131 if (exports._globalState.isWorker) { |
1132 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); | 1132 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); |
1133 } else { | 1133 } else { |
1134 IsolateNatives._spawnWorker(functionName, uri, args, message, isSpawnUri
, startPaused, replyPort, onError); | 1134 IsolateNatives._spawnWorker(functionName, uri, args, message, isSpawnUri
, startPaused, replyPort, onError); |
1135 } | 1135 } |
1136 } | 1136 } |
1137 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { | 1137 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa
used, replyPort) { |
1138 if (uri != null) { | 1138 if (uri != null) { |
1139 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); | 1139 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); |
1140 } | 1140 } |
1141 message = _clone(message); | 1141 message = _clone(message); |
1142 if (args != null) | 1142 if (args != null) |
1143 args = new (core.List$(core.String)).from(args); | 1143 args = core.List$(core.String).from(args); |
1144 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), dart.fn((
) => { | 1144 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), dart.fn((
) => { |
1145 let func = IsolateNatives._getJSFunctionFromName(functionName); | 1145 let func = IsolateNatives._getJSFunctionFromName(functionName); |
1146 IsolateNatives._startIsolate(dart.as(func, core.Function), args, message
, isSpawnUri, startPaused, replyPort); | 1146 IsolateNatives._startIsolate(dart.as(func, core.Function), args, message
, isSpawnUri, startPaused, replyPort); |
1147 }), 'nonworker start'); | 1147 }), 'nonworker start'); |
1148 } | 1148 } |
1149 static get currentIsolate() { | 1149 static get currentIsolate() { |
1150 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 1150 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
1151 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); | 1151 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
1152 } | 1152 } |
1153 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { | 1153 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply
To) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 return new (core.Expando$(core.int))(); | 1245 return new (core.Expando$(core.int))(); |
1246 } | 1246 } |
1247 }); | 1247 }); |
1248 let _checkReplyTo = Symbol('_checkReplyTo'); | 1248 let _checkReplyTo = Symbol('_checkReplyTo'); |
1249 class _BaseSendPort extends core.Object { | 1249 class _BaseSendPort extends core.Object { |
1250 _BaseSendPort(isolateId) { | 1250 _BaseSendPort(isolateId) { |
1251 this[_isolateId] = isolateId; | 1251 this[_isolateId] = isolateId; |
1252 } | 1252 } |
1253 [_checkReplyTo](replyTo) { | 1253 [_checkReplyTo](replyTo) { |
1254 if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort)
&& !dart.is(replyTo, _WorkerSendPort)) { | 1254 if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort)
&& !dart.is(replyTo, _WorkerSendPort)) { |
1255 throw new core.Exception("SendPort.send: Illegal replyTo port type"); | 1255 throw core.Exception.new("SendPort.send: Illegal replyTo port type"); |
1256 } | 1256 } |
1257 } | 1257 } |
1258 } | 1258 } |
1259 _BaseSendPort[dart.implements] = () => [isolate.SendPort]; | 1259 _BaseSendPort[dart.implements] = () => [isolate.SendPort]; |
1260 dart.setSignature(_BaseSendPort, { | 1260 dart.setSignature(_BaseSendPort, { |
1261 constructors: () => ({_BaseSendPort: [_BaseSendPort, [core.int]]}), | 1261 constructors: () => ({_BaseSendPort: [_BaseSendPort, [core.int]]}), |
1262 methods: () => ({[_checkReplyTo]: [dart.void, [isolate.SendPort]]}) | 1262 methods: () => ({[_checkReplyTo]: [dart.void, [isolate.SendPort]]}) |
1263 }); | 1263 }); |
1264 let _isClosed = Symbol('_isClosed'); | 1264 let _isClosed = Symbol('_isClosed'); |
1265 let _add = Symbol('_add'); | 1265 let _add = Symbol('_add'); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 ReceivePortImpl() { | 1398 ReceivePortImpl() { |
1399 this.fromRawReceivePort(new RawReceivePortImpl(null)); | 1399 this.fromRawReceivePort(new RawReceivePortImpl(null)); |
1400 } | 1400 } |
1401 weak() { | 1401 weak() { |
1402 this.fromRawReceivePort(new RawReceivePortImpl.weak(null)); | 1402 this.fromRawReceivePort(new RawReceivePortImpl.weak(null)); |
1403 } | 1403 } |
1404 fromRawReceivePort(rawPort) { | 1404 fromRawReceivePort(rawPort) { |
1405 this[_rawPort] = rawPort; | 1405 this[_rawPort] = rawPort; |
1406 this[_controller] = null; | 1406 this[_controller] = null; |
1407 super.Stream(); | 1407 super.Stream(); |
1408 this[_controller] = new async.StreamController({onCancel: dart.bind(this,
'close'), sync: true}); | 1408 this[_controller] = async.StreamController.new({onCancel: dart.bind(this,
'close'), sync: true}); |
1409 this[_rawPort].handler = dart.bind(this[_controller], 'add'); | 1409 this[_rawPort].handler = dart.bind(this[_controller], 'add'); |
1410 } | 1410 } |
1411 listen(onData, opts) { | 1411 listen(onData, opts) { |
1412 let onError = opts && 'onError' in opts ? opts.onError : null; | 1412 let onError = opts && 'onError' in opts ? opts.onError : null; |
1413 let onDone = opts && 'onDone' in opts ? opts.onDone : null; | 1413 let onDone = opts && 'onDone' in opts ? opts.onDone : null; |
1414 let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError :
null; | 1414 let cancelOnError = opts && 'cancelOnError' in opts ? opts.cancelOnError :
null; |
1415 return this[_controller].stream.listen(onData, {onError: onError, onDone:
onDone, cancelOnError: cancelOnError}); | 1415 return this[_controller].stream.listen(onData, {onError: onError, onDone:
onDone, cancelOnError: cancelOnError}); |
1416 } | 1416 } |
1417 close() { | 1417 close() { |
1418 this[_rawPort].close(); | 1418 this[_rawPort].close(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 exports.leaveJsAsync = leaveJsAsync; | 1557 exports.leaveJsAsync = leaveJsAsync; |
1558 exports.isWorker = isWorker; | 1558 exports.isWorker = isWorker; |
1559 exports.startRootIsolate = startRootIsolate; | 1559 exports.startRootIsolate = startRootIsolate; |
1560 exports.IsolateNatives = IsolateNatives; | 1560 exports.IsolateNatives = IsolateNatives; |
1561 exports.RawReceivePortImpl = RawReceivePortImpl; | 1561 exports.RawReceivePortImpl = RawReceivePortImpl; |
1562 exports.ReceivePortImpl = ReceivePortImpl; | 1562 exports.ReceivePortImpl = ReceivePortImpl; |
1563 exports.TimerImpl = TimerImpl; | 1563 exports.TimerImpl = TimerImpl; |
1564 exports.hasTimer = hasTimer; | 1564 exports.hasTimer = hasTimer; |
1565 exports.CapabilityImpl = CapabilityImpl; | 1565 exports.CapabilityImpl = CapabilityImpl; |
1566 })(_isolate_helper, core, _native_typed_data, _interceptors, _js_helper, isolate
, _foreign_helper, _js_embedded_names, collection, async); | 1566 })(_isolate_helper, core, _native_typed_data, _interceptors, _js_helper, isolate
, _foreign_helper, _js_embedded_names, collection, async); |
OLD | NEW |