Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: lib/runtime/dart/_isolate_helper.js

Issue 1138793002: Tag closures with their types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: More comment fixes Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/runtime/dart/_internal.js ('k') | lib/runtime/dart/_js_helper.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
11 (function(exports, core, _native_typed_data, _interceptors, _js_helper, isolate, _foreign_helper, _js_embedded_names, collection, async) { 11 (function(exports, core, _native_typed_data, _interceptors, _js_helper, isolate, _foreign_helper, _js_embedded_names, collection, async) {
12 'use strict'; 12 'use strict';
13 // Function _serializeMessage: (dynamic) → dynamic
14 function _serializeMessage(message) { 13 function _serializeMessage(message) {
15 return new _Serializer().serialize(message); 14 return new _Serializer().serialize(message);
16 } 15 }
17 // Function _deserializeMessage: (dynamic) → dynamic 16 dart.fn(_serializeMessage);
18 function _deserializeMessage(message) { 17 function _deserializeMessage(message) {
19 return new _Deserializer().deserialize(message); 18 return new _Deserializer().deserialize(message);
20 } 19 }
21 // Function _clone: (dynamic) → dynamic 20 dart.fn(_deserializeMessage);
22 function _clone(message) { 21 function _clone(message) {
23 let serializer = new _Serializer({serializeSendPorts: false}); 22 let serializer = new _Serializer({serializeSendPorts: false});
24 let deserializer = new _Deserializer(); 23 let deserializer = new _Deserializer();
25 return deserializer.deserialize(serializer.serialize(message)); 24 return deserializer.deserialize(serializer.serialize(message));
26 } 25 }
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$(dart.dynamic, core.int)).identit y(); 36 this.serializedObjectIds = new (core.Map$(dart.dynamic, core.int)).identit y();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return ['function', name]; 157 return ['function', name];
158 } 158 }
159 serializeDartObject(x) { 159 serializeDartObject(x) {
160 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n ames.CLASS_ID_EXTRACTOR); 160 let classExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_n ames.CLASS_ID_EXTRACTOR);
161 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_ names.CLASS_FIELDS_EXTRACTOR); 161 let fieldsExtractor = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_ names.CLASS_FIELDS_EXTRACTOR);
162 let classId = classExtractor(x); 162 let classId = classExtractor(x);
163 let fields = dart.as(fieldsExtractor(x), core.List); 163 let fields = dart.as(fieldsExtractor(x), core.List);
164 return ['dart', classId, this.serializeArrayInPlace(dart.as(fields, _inter ceptors.JSArray))]; 164 return ['dart', classId, this.serializeArrayInPlace(dart.as(fields, _inter ceptors.JSArray))];
165 } 165 }
166 } 166 }
167 dart.setSignature(_Serializer, {
168 methods: () => ({
169 serialize: dart.functionType(dart.dynamic, [dart.dynamic]),
170 unsupported: dart.functionType(dart.void, [dart.dynamic], [core.String]),
171 makeRef: dart.functionType(dart.dynamic, [core.int]),
172 isPrimitive: dart.functionType(core.bool, [dart.dynamic]),
173 serializePrimitive: dart.functionType(dart.dynamic, [dart.dynamic]),
174 serializeByteBuffer: dart.functionType(dart.dynamic, [_native_typed_data.N ativeByteBuffer]),
175 serializeTypedData: dart.functionType(dart.dynamic, [_native_typed_data.Na tiveTypedData]),
176 serializeJSIndexable: dart.functionType(dart.dynamic, [_interceptors.JSInd exable]),
177 serializeArray: dart.functionType(dart.dynamic, [_interceptors.JSArray]),
178 serializeArrayInPlace: dart.functionType(dart.dynamic, [_interceptors.JSAr ray]),
179 serializeMap: dart.functionType(dart.dynamic, [core.Map]),
180 serializeJSObject: dart.functionType(dart.dynamic, [_interceptors.JSObject ]),
181 serializeWorkerSendPort: dart.functionType(dart.dynamic, [_WorkerSendPort] ),
182 serializeJsSendPort: dart.functionType(dart.dynamic, [_NativeJsSendPort]),
183 serializeCapability: dart.functionType(dart.dynamic, [CapabilityImpl]),
184 serializeClosure: dart.functionType(dart.dynamic, [_js_helper.Closure]),
185 serializeDartObject: dart.functionType(dart.dynamic, [dart.dynamic])
186 })
187 });
167 let _adjustSendPorts = Symbol('_adjustSendPorts'); 188 let _adjustSendPorts = Symbol('_adjustSendPorts');
168 class _Deserializer extends core.Object { 189 class _Deserializer extends core.Object {
169 _Deserializer(opts) { 190 _Deserializer(opts) {
170 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP orts : true; 191 let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendP orts : true;
171 this.deserializedObjects = new core.List(); 192 this.deserializedObjects = new core.List();
172 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool); 193 this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool);
173 } 194 }
174 deserialize(x) { 195 deserialize(x) {
175 if (this.isPrimitive(x)) 196 if (this.isPrimitive(x))
176 return this.deserializePrimitive(x); 197 return this.deserializePrimitive(x);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 let classId = dart.as(dart.dindex(x, 1), core.String); 370 let classId = dart.as(dart.dindex(x, 1), core.String);
350 let fields = dart.as(dart.dindex(x, 2), core.List); 371 let fields = dart.as(dart.dindex(x, 2), core.List);
351 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embed ded_names.INSTANCE_FROM_CLASS_ID); 372 let instanceFromClassId = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embed ded_names.INSTANCE_FROM_CLASS_ID);
352 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded _names.INITIALIZE_EMPTY_INSTANCE); 373 let initializeObject = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded _names.INITIALIZE_EMPTY_INSTANCE);
353 let emptyInstance = instanceFromClassId(classId); 374 let emptyInstance = instanceFromClassId(classId);
354 this.deserializedObjects[core.$add](emptyInstance); 375 this.deserializedObjects[core.$add](emptyInstance);
355 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray)); 376 this.deserializeArrayInPlace(dart.as(fields, _interceptors.JSArray));
356 return initializeObject(classId, emptyInstance, fields); 377 return initializeObject(classId, emptyInstance, fields);
357 } 378 }
358 } 379 }
380 dart.setSignature(_Deserializer, {
381 methods: () => ({
382 deserialize: dart.functionType(dart.dynamic, [dart.dynamic]),
383 isPrimitive: dart.functionType(core.bool, [dart.dynamic]),
384 deserializePrimitive: dart.functionType(dart.dynamic, [dart.dynamic]),
385 deserializeRef: dart.functionType(dart.dynamic, [dart.dynamic]),
386 deserializeByteBuffer: dart.functionType(_native_typed_data.NativeByteBuff er, [dart.dynamic]),
387 deserializeTypedData: dart.functionType(_native_typed_data.NativeTypedData , [dart.dynamic]),
388 deserializeArrayInPlace: dart.functionType(core.List, [_interceptors.JSArr ay]),
389 deserializeFixed: dart.functionType(core.List, [dart.dynamic]),
390 deserializeExtendable: dart.functionType(core.List, [dart.dynamic]),
391 deserializeMutable: dart.functionType(core.List, [dart.dynamic]),
392 deserializeConst: dart.functionType(core.List, [dart.dynamic]),
393 deserializeMap: dart.functionType(core.Map, [dart.dynamic]),
394 deserializeSendPort: dart.functionType(isolate.SendPort, [dart.dynamic]),
395 deserializeRawSendPort: dart.functionType(isolate.SendPort, [dart.dynamic] ),
396 deserializeJSObject: dart.functionType(dart.dynamic, [dart.dynamic]),
397 deserializeClosure: dart.functionType(core.Function, [dart.dynamic]),
398 deserializeDartObject: dart.functionType(dart.dynamic, [dart.dynamic])
399 })
400 });
359 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.dyn amic, [dart.dynamic])); 401 let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.dyn amic, [dart.dynamic]));
360 // Function _callInIsolate: (_IsolateContext, Function) → dynamic
361 function _callInIsolate(isolate, func) { 402 function _callInIsolate(isolate, func) {
362 let result = isolate.eval(func); 403 let result = isolate.eval(func);
363 exports._globalState.topEventLoop.run(); 404 exports._globalState.topEventLoop.run();
364 return result; 405 return result;
365 } 406 }
407 dart.fn(_callInIsolate, () => dart.functionType(dart.dynamic, [_IsolateContext , core.Function]));
366 let _activeJsAsyncCount = Symbol('_activeJsAsyncCount'); 408 let _activeJsAsyncCount = Symbol('_activeJsAsyncCount');
367 // Function enterJsAsync: () → dynamic
368 function enterJsAsync() { 409 function enterJsAsync() {
369 let o = exports._globalState.topEventLoop; 410 let o = exports._globalState.topEventLoop;
370 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) + 1; 411 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) + 1;
371 } 412 }
372 // Function leaveJsAsync: () → dynamic 413 dart.fn(enterJsAsync);
373 function leaveJsAsync() { 414 function leaveJsAsync() {
374 let o = exports._globalState.topEventLoop; 415 let o = exports._globalState.topEventLoop;
375 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) - 1; 416 o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) - 1;
376 dart.assert(dart.notNull(exports._globalState.topEventLoop[_activeJsAsyncCou nt]) >= 0); 417 dart.assert(dart.notNull(exports._globalState.topEventLoop[_activeJsAsyncCou nt]) >= 0);
377 } 418 }
378 // Function isWorker: () → bool 419 dart.fn(leaveJsAsync);
379 function isWorker() { 420 function isWorker() {
380 return exports._globalState.isWorker; 421 return exports._globalState.isWorker;
381 } 422 }
382 // Function _currentIsolate: () → _IsolateContext 423 dart.fn(isWorker, core.bool, []);
383 function _currentIsolate() { 424 function _currentIsolate() {
384 return exports._globalState.currentContext; 425 return exports._globalState.currentContext;
385 } 426 }
386 // Function startRootIsolate: (dynamic, dynamic) → void 427 dart.fn(_currentIsolate, () => dart.functionType(_IsolateContext, []));
387 function startRootIsolate(entry, args) { 428 function startRootIsolate(entry, args) {
388 args = args; 429 args = args;
389 if (args == null) 430 if (args == null)
390 args = []; 431 args = [];
391 if (!dart.is(args, core.List)) { 432 if (!dart.is(args, core.List)) {
392 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`); 433 throw new core.ArgumentError(`Arguments to main must be a List: ${args}`);
393 } 434 }
394 exports._globalState = new _Manager(dart.as(entry, core.Function)); 435 exports._globalState = new _Manager(dart.as(entry, core.Function));
395 if (exports._globalState.isWorker) 436 if (exports._globalState.isWorker)
396 return; 437 return;
397 let rootContext = new _IsolateContext(); 438 let rootContext = new _IsolateContext();
398 exports._globalState.rootContext = rootContext; 439 exports._globalState.rootContext = rootContext;
399 exports._globalState.currentContext = rootContext; 440 exports._globalState.currentContext = rootContext;
400 if (dart.is(entry, _MainFunctionArgs)) { 441 if (dart.is(entry, _MainFunctionArgs)) {
401 rootContext.eval(() => { 442 rootContext.eval(dart.fn(() => {
402 dart.dcall(entry, args); 443 dart.dcall(entry, args);
403 }); 444 }));
404 } else if (dart.is(entry, _MainFunctionArgsMessage)) { 445 } else if (dart.is(entry, _MainFunctionArgsMessage)) {
405 rootContext.eval(() => { 446 rootContext.eval(dart.fn(() => {
406 dart.dcall(entry, args, null); 447 dart.dcall(entry, args, null);
407 }); 448 }));
408 } else { 449 } else {
409 rootContext.eval(dart.as(entry, core.Function)); 450 rootContext.eval(dart.as(entry, core.Function));
410 } 451 }
411 exports._globalState.topEventLoop.run(); 452 exports._globalState.topEventLoop.run();
412 } 453 }
454 dart.fn(startRootIsolate, dart.void, [dart.dynamic, dart.dynamic]);
413 dart.copyProperties(exports, { 455 dart.copyProperties(exports, {
414 get _globalState() { 456 get _globalState() {
415 return dart.as(dart.globalState, _Manager); 457 return dart.as(dart.globalState, _Manager);
416 }, 458 },
417 set _globalState(val) { 459 set _globalState(val) {
418 dart.globalState = val; 460 dart.globalState = val;
419 } 461 }
420 }); 462 });
421 let _nativeDetectEnvironment = Symbol('_nativeDetectEnvironment'); 463 let _nativeDetectEnvironment = Symbol('_nativeDetectEnvironment');
422 let _nativeInitWorkerMessageHandler = Symbol('_nativeInitWorkerMessageHandler' ); 464 let _nativeInitWorkerMessageHandler = Symbol('_nativeInitWorkerMessageHandler' );
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 } 515 }
474 static _serializePrintMessage(object) { 516 static _serializePrintMessage(object) {
475 return _serializeMessage(dart.map({command: "print", msg: object})); 517 return _serializeMessage(dart.map({command: "print", msg: object}));
476 } 518 }
477 maybeCloseWorker() { 519 maybeCloseWorker() {
478 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) && this.topEventLoop[_activeJsAsyncCount] == 0) { 520 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) && this.topEventLoop[_activeJsAsyncCount] == 0) {
479 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '}))); 521 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close '})));
480 } 522 }
481 } 523 }
482 } 524 }
525 dart.setSignature(_Manager, {
526 methods: () => ({
527 [_nativeDetectEnvironment]: dart.functionType(dart.void, []),
528 [_nativeInitWorkerMessageHandler]: dart.functionType(dart.void, []),
529 maybeCloseWorker: dart.functionType(dart.void, [])
530 }),
531 statics: () => ({_serializePrintMessage: dart.functionType(dart.dynamic, [da rt.dynamic])}),
532 names: ['_serializePrintMessage']
533 });
483 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); 534 let _scheduledControlEvents = Symbol('_scheduledControlEvents');
484 let _isExecutingEvent = Symbol('_isExecutingEvent'); 535 let _isExecutingEvent = Symbol('_isExecutingEvent');
485 let _updateGlobalState = Symbol('_updateGlobalState'); 536 let _updateGlobalState = Symbol('_updateGlobalState');
486 let _setGlobals = Symbol('_setGlobals'); 537 let _setGlobals = Symbol('_setGlobals');
487 let _addRegistration = Symbol('_addRegistration'); 538 let _addRegistration = Symbol('_addRegistration');
488 let _close = Symbol('_close'); 539 let _close = Symbol('_close');
489 class _IsolateContext extends core.Object { 540 class _IsolateContext extends core.Object {
490 _IsolateContext() { 541 _IsolateContext() {
491 this.id = (() => { 542 this.id = (() => {
492 let o = exports._globalState, x = o.nextIsolateId; 543 let o = exports._globalState, x = o.nextIsolateId;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 setErrorsFatal(authentification, errorsAreFatal) { 598 setErrorsFatal(authentification, errorsAreFatal) {
548 if (!dart.equals(this.terminateCapability, authentification)) 599 if (!dart.equals(this.terminateCapability, authentification))
549 return; 600 return;
550 this.errorsAreFatal = errorsAreFatal; 601 this.errorsAreFatal = errorsAreFatal;
551 } 602 }
552 handlePing(responsePort, pingType) { 603 handlePing(responsePort, pingType) {
553 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) { 604 if (pingType == isolate.Isolate.IMMEDIATE || pingType == isolate.Isolate.B EFORE_NEXT_EVENT && !dart.notNull(this[_isExecutingEvent])) {
554 responsePort.send(null); 605 responsePort.send(null);
555 return; 606 return;
556 } 607 }
557 // Function respond: () → void
558 let respond = () => { 608 let respond = () => {
559 responsePort.send(null); 609 responsePort.send(null);
560 }; 610 };
611 dart.fn(respond, dart.void, []);
561 if (pingType == isolate.Isolate.AS_EVENT) { 612 if (pingType == isolate.Isolate.AS_EVENT) {
562 exports._globalState.topEventLoop.enqueue(this, respond, "ping"); 613 exports._globalState.topEventLoop.enqueue(this, respond, "ping");
563 return; 614 return;
564 } 615 }
565 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT); 616 dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT);
566 if (this[_scheduledControlEvents] == null) { 617 if (this[_scheduledControlEvents] == null) {
567 this[_scheduledControlEvents] = new collection.Queue(); 618 this[_scheduledControlEvents] = new collection.Queue();
568 } 619 }
569 dart.dsend(this[_scheduledControlEvents], 'addLast', respond); 620 dart.dsend(this[_scheduledControlEvents], 'addLast', respond);
570 } 621 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 this.doneHandlers = null; 788 this.doneHandlers = null;
738 } 789 }
739 } 790 }
740 unregister(portId) { 791 unregister(portId) {
741 this.ports.remove(portId); 792 this.ports.remove(portId);
742 this.weakPorts.remove(portId); 793 this.weakPorts.remove(portId);
743 this[_updateGlobalState](); 794 this[_updateGlobalState]();
744 } 795 }
745 } 796 }
746 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext]; 797 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext];
798 dart.setSignature(_IsolateContext, {
799 methods: () => ({
800 addPause: dart.functionType(dart.void, [isolate.Capability, isolate.Capabi lity]),
801 removePause: dart.functionType(dart.void, [isolate.Capability]),
802 addDoneListener: dart.functionType(dart.void, [isolate.SendPort]),
803 removeDoneListener: dart.functionType(dart.void, [isolate.SendPort]),
804 setErrorsFatal: dart.functionType(dart.void, [isolate.Capability, core.boo l]),
805 handlePing: dart.functionType(dart.void, [isolate.SendPort, core.int]),
806 handleKill: dart.functionType(dart.void, [isolate.Capability, core.int]),
807 addErrorListener: dart.functionType(dart.void, [isolate.SendPort]),
808 removeErrorListener: dart.functionType(dart.void, [isolate.SendPort]),
809 handleUncaughtError: dart.functionType(dart.void, [dart.dynamic, core.Stac kTrace]),
810 eval: dart.functionType(dart.dynamic, [core.Function]),
811 [_setGlobals]: dart.functionType(dart.void, []),
812 handleControlMessage: dart.functionType(dart.void, [dart.dynamic]),
813 lookup: dart.functionType(RawReceivePortImpl, [core.int]),
814 [_addRegistration]: dart.functionType(dart.void, [core.int, RawReceivePort Impl]),
815 register: dart.functionType(dart.void, [core.int, RawReceivePortImpl]),
816 registerWeak: dart.functionType(dart.void, [core.int, RawReceivePortImpl]) ,
817 [_updateGlobalState]: dart.functionType(dart.void, []),
818 kill: dart.functionType(dart.void, []),
819 unregister: dart.functionType(dart.void, [core.int])
820 })
821 });
747 let _runHelper = Symbol('_runHelper'); 822 let _runHelper = Symbol('_runHelper');
748 class _EventLoop extends core.Object { 823 class _EventLoop extends core.Object {
749 _EventLoop() { 824 _EventLoop() {
750 this.events = new (collection.Queue$(_IsolateEvent))(); 825 this.events = new (collection.Queue$(_IsolateEvent))();
751 this[_activeJsAsyncCount] = 0; 826 this[_activeJsAsyncCount] = 0;
752 } 827 }
753 enqueue(isolate, fn, msg) { 828 enqueue(isolate, fn, msg) {
754 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d art.as(fn, core.Function), dart.as(msg, core.String))); 829 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d art.as(fn, core.Function), dart.as(msg, core.String)));
755 } 830 }
756 prequeue(event) { 831 prequeue(event) {
(...skipping 14 matching lines...) Expand all
771 if (event == null) { 846 if (event == null) {
772 this.checkOpenReceivePortsFromCommandLine(); 847 this.checkOpenReceivePortsFromCommandLine();
773 exports._globalState.maybeCloseWorker(); 848 exports._globalState.maybeCloseWorker();
774 return false; 849 return false;
775 } 850 }
776 event.process(); 851 event.process();
777 return true; 852 return true;
778 } 853 }
779 [_runHelper]() { 854 [_runHelper]() {
780 if (exports.globalWindow != null) { 855 if (exports.globalWindow != null) {
781 // Function next: () → dynamic
782 let next = (() => { 856 let next = (() => {
783 if (!dart.notNull(this.runIteration())) 857 if (!dart.notNull(this.runIteration()))
784 return; 858 return;
785 async.Timer.run(next); 859 async.Timer.run(next);
786 }).bind(this); 860 }).bind(this);
861 dart.fn(next);
787 next(); 862 next();
788 } else { 863 } else {
789 while (this.runIteration()) { 864 while (this.runIteration()) {
790 } 865 }
791 } 866 }
792 } 867 }
793 run() { 868 run() {
794 if (!dart.notNull(exports._globalState.isWorker)) { 869 if (!dart.notNull(exports._globalState.isWorker)) {
795 this[_runHelper](); 870 this[_runHelper]();
796 } else { 871 } else {
797 try { 872 try {
798 this[_runHelper](); 873 this[_runHelper]();
799 } catch (e) { 874 } catch (e) {
800 let trace = dart.stackTrace(e); 875 let trace = dart.stackTrace(e);
801 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma p({command: 'error', msg: `${e}\n${trace}`}))); 876 exports._globalState.mainManager.postMessage(_serializeMessage(dart.ma p({command: 'error', msg: `${e}\n${trace}`})));
802 } 877 }
803 878
804 } 879 }
805 } 880 }
806 } 881 }
882 dart.setSignature(_EventLoop, {
883 methods: () => ({
884 enqueue: dart.functionType(dart.void, [dart.dynamic, dart.dynamic, dart.dy namic]),
885 prequeue: dart.functionType(dart.void, [_IsolateEvent]),
886 dequeue: dart.functionType(_IsolateEvent, []),
887 checkOpenReceivePortsFromCommandLine: dart.functionType(dart.void, []),
888 runIteration: dart.functionType(core.bool, []),
889 [_runHelper]: dart.functionType(dart.void, []),
890 run: dart.functionType(dart.void, [])
891 })
892 });
807 class _IsolateEvent extends core.Object { 893 class _IsolateEvent extends core.Object {
808 _IsolateEvent(isolate, fn, message) { 894 _IsolateEvent(isolate, fn, message) {
809 this.isolate = isolate; 895 this.isolate = isolate;
810 this.fn = fn; 896 this.fn = fn;
811 this.message = message; 897 this.message = message;
812 } 898 }
813 process() { 899 process() {
814 if (this.isolate.isPaused) { 900 if (this.isolate.isPaused) {
815 this.isolate.delayedEvents[core.$add](this); 901 this.isolate.delayedEvents[core.$add](this);
816 return; 902 return;
817 } 903 }
818 this.isolate.eval(this.fn); 904 this.isolate.eval(this.fn);
819 } 905 }
820 } 906 }
907 dart.setSignature(_IsolateEvent, {
908 methods: () => ({process: dart.functionType(dart.void, [])})
909 });
821 class _MainManagerStub extends core.Object { 910 class _MainManagerStub extends core.Object {
822 postMessage(msg) { 911 postMessage(msg) {
823 _js_helper.requiresPreamble(); 912 _js_helper.requiresPreamble();
824 self.postMessage(msg); 913 self.postMessage(msg);
825 } 914 }
826 } 915 }
916 dart.setSignature(_MainManagerStub, {
917 methods: () => ({postMessage: dart.functionType(dart.void, [dart.dynamic])})
918 });
827 let _SPAWNED_SIGNAL = "spawned"; 919 let _SPAWNED_SIGNAL = "spawned";
828 let _SPAWN_FAILED_SIGNAL = "spawn failed"; 920 let _SPAWN_FAILED_SIGNAL = "spawn failed";
829 dart.copyProperties(exports, { 921 dart.copyProperties(exports, {
830 get globalWindow() { 922 get globalWindow() {
831 _js_helper.requiresPreamble(); 923 _js_helper.requiresPreamble();
832 return self.window; 924 return self.window;
833 }, 925 },
834 get globalWorker() { 926 get globalWorker() {
835 _js_helper.requiresPreamble(); 927 _js_helper.requiresPreamble();
836 return self.Worker; 928 return self.Worker;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 { 990 {
899 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id') , core.int); 991 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id') , core.int);
900 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri ng); 992 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri ng);
901 let entryPoint = functionName == null ? exports._globalState.entry : d art.as(IsolateNatives._getJSFunctionFromName(functionName), core.Function); 993 let entryPoint = functionName == null ? exports._globalState.entry : d art.as(IsolateNatives._getJSFunctionFromName(functionName), core.Function);
902 let args = dart.dindex(msg, 'args'); 994 let args = dart.dindex(msg, 'args');
903 let message = _deserializeMessage(dart.dindex(msg, 'msg')); 995 let message = _deserializeMessage(dart.dindex(msg, 'msg'));
904 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); 996 let isSpawnUri = dart.dindex(msg, 'isSpawnUri');
905 let startPaused = dart.dindex(msg, 'startPaused'); 997 let startPaused = dart.dindex(msg, 'startPaused');
906 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); 998 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo'));
907 let context = new _IsolateContext(); 999 let context = new _IsolateContext();
908 exports._globalState.topEventLoop.enqueue(context, () => { 1000 exports._globalState.topEventLoop.enqueue(context, dart.fn(() => {
909 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)); 1001 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));
910 }, 'worker-start'); 1002 }), 'worker-start');
911 exports._globalState.currentContext = context; 1003 exports._globalState.currentContext = context;
912 exports._globalState.topEventLoop.run(); 1004 exports._globalState.topEventLoop.run();
913 break; 1005 break;
914 } 1006 }
915 case 'spawn-worker': 1007 case 'spawn-worker':
916 { 1008 {
917 if (IsolateNatives.enableSpawnWorker != null) 1009 if (IsolateNatives.enableSpawnWorker != null)
918 IsolateNatives.handleSpawnWorkerRequest(msg); 1010 IsolateNatives.handleSpawnWorkerRequest(msg);
919 break; 1011 break;
920 } 1012 }
(...skipping 28 matching lines...) Expand all
949 break; 1041 break;
950 } 1042 }
951 case 'error': 1043 case 'error':
952 { 1044 {
953 throw dart.dindex(msg, 'msg'); 1045 throw dart.dindex(msg, 'msg');
954 } 1046 }
955 } 1047 }
956 } 1048 }
957 static handleSpawnWorkerRequest(msg) { 1049 static handleSpawnWorkerRequest(msg) {
958 let replyPort = dart.dindex(msg, 'replyPort'); 1050 let replyPort = dart.dindex(msg, 'replyPort');
959 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(msg => { 1051 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 => {
960 dart.dsend(replyPort, 'send', msg); 1052 dart.dsend(replyPort, 'send', msg);
961 }, { 1053 }), {onError: dart.fn(errorMessage => {
962 onError: errorMessage => {
963 dart.dsend(replyPort, 'send', [_SPAWN_FAILED_SIGNAL, errorMessage]); 1054 dart.dsend(replyPort, 'send', [_SPAWN_FAILED_SIGNAL, errorMessage]);
964 } 1055 }, dart.dynamic, [core.String])});
965 });
966 } 1056 }
967 static _log(msg) { 1057 static _log(msg) {
968 if (exports._globalState.isWorker) { 1058 if (exports._globalState.isWorker) {
969 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'log', msg: msg}))); 1059 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'log', msg: msg})));
970 } else { 1060 } else {
971 try { 1061 try {
972 IsolateNatives._consoleLog(msg); 1062 IsolateNatives._consoleLog(msg);
973 } catch (e) { 1063 } catch (e) {
974 let trace = dart.stackTrace(e); 1064 let trace = dart.stackTrace(e);
975 throw new core.Exception(trace); 1065 throw new core.Exception(trace);
(...skipping 30 matching lines...) Expand all
1006 let isLight = false; 1096 let isLight = false;
1007 let isSpawnUri = true; 1097 let isSpawnUri = true;
1008 return IsolateNatives.spawn(null, dart.toString(uri), args, message, isLig ht, isSpawnUri, startPaused); 1098 return IsolateNatives.spawn(null, dart.toString(uri), args, message, isLig ht, isSpawnUri, startPaused);
1009 } 1099 }
1010 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau sed) { 1100 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau sed) {
1011 if (uri != null && dart.notNull(uri.endsWith(".dart"))) { 1101 if (uri != null && dart.notNull(uri.endsWith(".dart"))) {
1012 uri = dart.notNull(uri) + ".js"; 1102 uri = dart.notNull(uri) + ".js";
1013 } 1103 }
1014 let port = new isolate.ReceivePort(); 1104 let port = new isolate.ReceivePort();
1015 let completer = new (async.Completer$(core.List))(); 1105 let completer = new (async.Completer$(core.List))();
1016 port.first.then(msg => { 1106 port.first.then(dart.fn(msg => {
1017 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { 1107 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) {
1018 completer.complete(msg); 1108 completer.complete(msg);
1019 } else { 1109 } else {
1020 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); 1110 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL));
1021 completer.completeError(dart.dindex(msg, 1)); 1111 completer.completeError(dart.dindex(msg, 1));
1022 } 1112 }
1023 }); 1113 }));
1024 let signalReply = port.sendPort; 1114 let signalReply = port.sendPort;
1025 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight )) { 1115 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight )) {
1026 IsolateNatives._startWorker(functionName, uri, args, message, isSpawnUri , startPaused, signalReply, message => completer.completeError(message)); 1116 IsolateNatives._startWorker(functionName, uri, args, message, isSpawnUri , startPaused, signalReply, dart.fn(message => completer.completeError(message), dart.void, [core.String]));
1027 } else { 1117 } else {
1028 IsolateNatives._startNonWorker(functionName, uri, args, message, isSpawn Uri, startPaused, signalReply); 1118 IsolateNatives._startNonWorker(functionName, uri, args, message, isSpawn Uri, startPaused, signalReply);
1029 } 1119 }
1030 return completer.future; 1120 return completer.future;
1031 } 1121 }
1032 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) { 1122 static _startWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) {
1033 if (args != null) 1123 if (args != null)
1034 args = new (core.List$(core.String)).from(args); 1124 args = new (core.List$(core.String)).from(args);
1035 if (exports._globalState.isWorker) { 1125 if (exports._globalState.isWorker) {
1036 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'spawn-worker', functionName: functionName, args: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort }))); 1126 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'spawn-worker', functionName: functionName, args: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort })));
1037 } else { 1127 } else {
1038 IsolateNatives._spawnWorker(functionName, uri, args, message, isSpawnUri , startPaused, replyPort, onError); 1128 IsolateNatives._spawnWorker(functionName, uri, args, message, isSpawnUri , startPaused, replyPort, onError);
1039 } 1129 }
1040 } 1130 }
1041 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa used, replyPort) { 1131 static _startNonWorker(functionName, uri, args, message, isSpawnUri, startPa used, replyPort) {
1042 if (uri != null) { 1132 if (uri != null) {
1043 throw new core.UnsupportedError("Currently spawnUri is not supported wit hout web workers."); 1133 throw new core.UnsupportedError("Currently spawnUri is not supported wit hout web workers.");
1044 } 1134 }
1045 message = _clone(message); 1135 message = _clone(message);
1046 if (args != null) 1136 if (args != null)
1047 args = new (core.List$(core.String)).from(args); 1137 args = new (core.List$(core.String)).from(args);
1048 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { 1138 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), dart.fn(( ) => {
1049 let func = IsolateNatives._getJSFunctionFromName(functionName); 1139 let func = IsolateNatives._getJSFunctionFromName(functionName);
1050 IsolateNatives._startIsolate(dart.as(func, core.Function), args, message , isSpawnUri, startPaused, replyPort); 1140 IsolateNatives._startIsolate(dart.as(func, core.Function), args, message , isSpawnUri, startPaused, replyPort);
1051 }, 'nonworker start'); 1141 }), 'nonworker start');
1052 } 1142 }
1053 static get currentIsolate() { 1143 static get currentIsolate() {
1054 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext); 1144 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext);
1055 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability}); 1145 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability});
1056 } 1146 }
1057 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply To) { 1147 static _startIsolate(topLevel, args, message, isSpawnUri, startPaused, reply To) {
1058 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext); 1148 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext);
1059 _js_helper.Primitives.initializeStatics(context.id); 1149 _js_helper.Primitives.initializeStatics(context.id);
1060 replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pause Capability, context.terminateCapability]); 1150 replyTo.send([_SPAWNED_SIGNAL, context.controlPort.sendPort, context.pause Capability, context.terminateCapability]);
1061 // Function runStartFunction: () → void
1062 let runStartFunction = () => { 1151 let runStartFunction = () => {
1063 context.initialized = true; 1152 context.initialized = true;
1064 if (!dart.notNull(isSpawnUri)) { 1153 if (!dart.notNull(isSpawnUri)) {
1065 dart.dcall(topLevel, message); 1154 dart.dcall(topLevel, message);
1066 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { 1155 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) {
1067 dart.dcall(topLevel, args, message); 1156 dart.dcall(topLevel, args, message);
1068 } else if (dart.is(topLevel, _MainFunctionArgs)) { 1157 } else if (dart.is(topLevel, _MainFunctionArgs)) {
1069 dart.dcall(topLevel, args); 1158 dart.dcall(topLevel, args);
1070 } else { 1159 } else {
1071 dart.dcall(topLevel); 1160 dart.dcall(topLevel);
1072 } 1161 }
1073 }; 1162 };
1163 dart.fn(runStartFunction, dart.void, []);
1074 if (startPaused) { 1164 if (startPaused) {
1075 context.addPause(context.pauseCapability, context.pauseCapability); 1165 context.addPause(context.pauseCapability, context.pauseCapability);
1076 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st art isolate'); 1166 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st art isolate');
1077 } else { 1167 } else {
1078 runStartFunction(); 1168 runStartFunction();
1079 } 1169 }
1080 } 1170 }
1081 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) { 1171 static _spawnWorker(functionName, uri, args, message, isSpawnUri, startPause d, replyPort, onError) {
1082 if (uri == null) 1172 if (uri == null)
1083 uri = IsolateNatives.thisScript; 1173 uri = IsolateNatives.thisScript;
(...skipping 23 matching lines...) Expand all
1107 let message = dart.as(event.message, core.String); 1197 let message = dart.as(event.message, core.String);
1108 if (message == null) { 1198 if (message == null) {
1109 message = `Error spawning worker for ${uri}`; 1199 message = `Error spawning worker for ${uri}`;
1110 } else { 1200 } else {
1111 message = `Error spawning worker for ${uri} (${message})`; 1201 message = `Error spawning worker for ${uri} (${message})`;
1112 } 1202 }
1113 onError(message); 1203 onError(message);
1114 return true; 1204 return true;
1115 } 1205 }
1116 } 1206 }
1207 dart.setSignature(IsolateNatives, {
1208 statics: () => ({
1209 computeThisScript: dart.functionType(core.String, []),
1210 computeThisScriptJsshell: dart.functionType(core.String, []),
1211 computeThisScriptD8: dart.functionType(core.String, []),
1212 computeThisScriptFromTrace: dart.functionType(core.String, []),
1213 _getEventData: dart.functionType(dart.dynamic, [dart.dynamic]),
1214 _processWorkerMessage: dart.functionType(dart.void, [dart.dynamic, dart.dy namic]),
1215 handleSpawnWorkerRequest: dart.functionType(dart.dynamic, [dart.dynamic]),
1216 _log: dart.functionType(dart.dynamic, [dart.dynamic]),
1217 _consoleLog: dart.functionType(dart.void, [dart.dynamic]),
1218 _getJSFunctionFromName: dart.functionType(dart.dynamic, [core.String]),
1219 _getJSFunctionName: dart.functionType(core.String, [core.Function]),
1220 _allocate: dart.functionType(dart.dynamic, [dart.dynamic]),
1221 spawnFunction: dart.functionType(async.Future$(core.List), [dart.functionT ype(dart.void, [dart.dynamic]), dart.dynamic, core.bool]),
1222 spawnUri: dart.functionType(async.Future$(core.List), [core.Uri, core.List $(core.String), dart.dynamic, core.bool]),
1223 spawn: dart.functionType(async.Future$(core.List), [core.String, core.Stri ng, core.List$(core.String), dart.dynamic, core.bool, core.bool, core.bool]),
1224 _startWorker: dart.functionType(dart.void, [core.String, core.String, core .List$(core.String), dart.dynamic, core.bool, core.bool, isolate.SendPort, dart. functionType(dart.void, [core.String])]),
1225 _startNonWorker: dart.functionType(dart.void, [core.String, core.String, c ore.List$(core.String), dart.dynamic, core.bool, core.bool, isolate.SendPort]),
1226 _startIsolate: dart.functionType(dart.void, [core.Function, core.List$(cor e.String), dart.dynamic, core.bool, core.bool, isolate.SendPort]),
1227 _spawnWorker: dart.functionType(dart.void, [dart.dynamic, core.String, cor e.List$(core.String), dart.dynamic, core.bool, core.bool, isolate.SendPort, dart .functionType(dart.void, [core.String])]),
1228 workerOnError: dart.functionType(core.bool, [dart.dynamic, core.String, da rt.functionType(dart.void, [core.String])])
1229 }),
1230 names: ['computeThisScript', 'computeThisScriptJsshell', 'computeThisScriptD 8', 'computeThisScriptFromTrace', '_getEventData', '_processWorkerMessage', 'han dleSpawnWorkerRequest', '_log', '_consoleLog', '_getJSFunctionFromName', '_getJS FunctionName', '_allocate', 'spawnFunction', 'spawnUri', 'spawn', '_startWorker' , '_startNonWorker', '_startIsolate', '_spawnWorker', 'workerOnError']
1231 });
1117 IsolateNatives.enableSpawnWorker = null; 1232 IsolateNatives.enableSpawnWorker = null;
1118 dart.defineLazyProperties(IsolateNatives, { 1233 dart.defineLazyProperties(IsolateNatives, {
1119 get thisScript() { 1234 get thisScript() {
1120 return IsolateNatives.computeThisScript(); 1235 return IsolateNatives.computeThisScript();
1121 }, 1236 },
1122 set thisScript(_) {}, 1237 set thisScript(_) {},
1123 get workerIds() { 1238 get workerIds() {
1124 return new (core.Expando$(core.int))(); 1239 return new (core.Expando$(core.int))();
1125 } 1240 }
1126 }); 1241 });
1127 let _checkReplyTo = Symbol('_checkReplyTo'); 1242 let _checkReplyTo = Symbol('_checkReplyTo');
1128 class _BaseSendPort extends core.Object { 1243 class _BaseSendPort extends core.Object {
1129 _BaseSendPort(isolateId) { 1244 _BaseSendPort(isolateId) {
1130 this[_isolateId] = isolateId; 1245 this[_isolateId] = isolateId;
1131 } 1246 }
1132 [_checkReplyTo](replyTo) { 1247 [_checkReplyTo](replyTo) {
1133 if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort) && !dart.is(replyTo, _WorkerSendPort)) { 1248 if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort) && !dart.is(replyTo, _WorkerSendPort)) {
1134 throw new core.Exception("SendPort.send: Illegal replyTo port type"); 1249 throw new core.Exception("SendPort.send: Illegal replyTo port type");
1135 } 1250 }
1136 } 1251 }
1137 } 1252 }
1138 _BaseSendPort[dart.implements] = () => [isolate.SendPort]; 1253 _BaseSendPort[dart.implements] = () => [isolate.SendPort];
1254 dart.setSignature(_BaseSendPort, {
1255 methods: () => ({[_checkReplyTo]: dart.functionType(dart.void, [isolate.Send Port])})
1256 });
1139 let _isClosed = Symbol('_isClosed'); 1257 let _isClosed = Symbol('_isClosed');
1140 let _add = Symbol('_add'); 1258 let _add = Symbol('_add');
1141 class _NativeJsSendPort extends _BaseSendPort { 1259 class _NativeJsSendPort extends _BaseSendPort {
1142 _NativeJsSendPort(receivePort, isolateId) { 1260 _NativeJsSendPort(receivePort, isolateId) {
1143 this[_receivePort] = receivePort; 1261 this[_receivePort] = receivePort;
1144 super._BaseSendPort(isolateId); 1262 super._BaseSendPort(isolateId);
1145 } 1263 }
1146 send(message) { 1264 send(message) {
1147 let isolate = exports._globalState.isolates.get(this[_isolateId]); 1265 let isolate = exports._globalState.isolates.get(this[_isolateId]);
1148 if (isolate == null) 1266 if (isolate == null)
1149 return; 1267 return;
1150 if (this[_receivePort][_isClosed]) 1268 if (this[_receivePort][_isClosed])
1151 return; 1269 return;
1152 let msg = _clone(message); 1270 let msg = _clone(message);
1153 if (dart.equals(isolate.controlPort, this[_receivePort])) { 1271 if (dart.equals(isolate.controlPort, this[_receivePort])) {
1154 isolate.handleControlMessage(msg); 1272 isolate.handleControlMessage(msg);
1155 return; 1273 return;
1156 } 1274 }
1157 exports._globalState.topEventLoop.enqueue(isolate, (() => { 1275 exports._globalState.topEventLoop.enqueue(isolate, dart.fn((() => {
1158 if (!dart.notNull(this[_receivePort][_isClosed])) { 1276 if (!dart.notNull(this[_receivePort][_isClosed])) {
1159 this[_receivePort][_add](msg); 1277 this[_receivePort][_add](msg);
1160 } 1278 }
1161 }).bind(this), `receive ${message}`); 1279 }).bind(this)), `receive ${message}`);
1162 } 1280 }
1163 ['=='](other) { 1281 ['=='](other) {
1164 return dart.is(other, _NativeJsSendPort) && dart.notNull(dart.equals(this[ _receivePort], dart.dload(other, _receivePort))); 1282 return dart.is(other, _NativeJsSendPort) && dart.notNull(dart.equals(this[ _receivePort], dart.dload(other, _receivePort)));
1165 } 1283 }
1166 get hashCode() { 1284 get hashCode() {
1167 return this[_receivePort][_id]; 1285 return this[_receivePort][_id];
1168 } 1286 }
1169 } 1287 }
1170 _NativeJsSendPort[dart.implements] = () => [isolate.SendPort]; 1288 _NativeJsSendPort[dart.implements] = () => [isolate.SendPort];
1289 dart.setSignature(_NativeJsSendPort, {
1290 methods: () => ({
1291 send: dart.functionType(dart.void, [dart.dynamic]),
1292 '==': dart.functionType(core.bool, [dart.dynamic])
1293 })
1294 });
1171 class _WorkerSendPort extends _BaseSendPort { 1295 class _WorkerSendPort extends _BaseSendPort {
1172 _WorkerSendPort(workerId, isolateId, receivePortId) { 1296 _WorkerSendPort(workerId, isolateId, receivePortId) {
1173 this[_workerId] = workerId; 1297 this[_workerId] = workerId;
1174 this[_receivePortId] = receivePortId; 1298 this[_receivePortId] = receivePortId;
1175 super._BaseSendPort(isolateId); 1299 super._BaseSendPort(isolateId);
1176 } 1300 }
1177 send(message) { 1301 send(message) {
1178 let workerMessage = _serializeMessage(dart.map({command: 'message', port: this, msg: message})); 1302 let workerMessage = _serializeMessage(dart.map({command: 'message', port: this, msg: message}));
1179 if (exports._globalState.isWorker) { 1303 if (exports._globalState.isWorker) {
1180 exports._globalState.mainManager.postMessage(workerMessage); 1304 exports._globalState.mainManager.postMessage(workerMessage);
1181 } else { 1305 } else {
1182 let manager = exports._globalState.managers.get(this[_workerId]); 1306 let manager = exports._globalState.managers.get(this[_workerId]);
1183 if (manager != null) { 1307 if (manager != null) {
1184 manager.postMessage(workerMessage); 1308 manager.postMessage(workerMessage);
1185 } 1309 }
1186 } 1310 }
1187 } 1311 }
1188 ['=='](other) { 1312 ['=='](other) {
1189 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 )); 1313 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 ));
1190 } 1314 }
1191 get hashCode() { 1315 get hashCode() {
1192 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId] ) << 8 ^ dart.notNull(this[_receivePortId]); 1316 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId] ) << 8 ^ dart.notNull(this[_receivePortId]);
1193 } 1317 }
1194 } 1318 }
1195 _WorkerSendPort[dart.implements] = () => [isolate.SendPort]; 1319 _WorkerSendPort[dart.implements] = () => [isolate.SendPort];
1320 dart.setSignature(_WorkerSendPort, {
1321 methods: () => ({
1322 send: dart.functionType(dart.void, [dart.dynamic]),
1323 '==': dart.functionType(core.bool, [dart.dynamic])
1324 })
1325 });
1196 let _handler = Symbol('_handler'); 1326 let _handler = Symbol('_handler');
1197 class RawReceivePortImpl extends core.Object { 1327 class RawReceivePortImpl extends core.Object {
1198 RawReceivePortImpl(handler) { 1328 RawReceivePortImpl(handler) {
1199 this[_handler] = handler; 1329 this[_handler] = handler;
1200 this[_id] = (() => { 1330 this[_id] = (() => {
1201 let x = RawReceivePortImpl._nextFreeId; 1331 let x = RawReceivePortImpl._nextFreeId;
1202 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1; 1332 RawReceivePortImpl._nextFreeId = dart.notNull(x) + 1;
1203 return x; 1333 return x;
1204 })(); 1334 })();
1205 this[_isClosed] = false; 1335 this[_isClosed] = false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 return; 1369 return;
1240 dart.dcall(this[_handler], dataEvent); 1370 dart.dcall(this[_handler], dataEvent);
1241 } 1371 }
1242 get sendPort() { 1372 get sendPort() {
1243 return new _NativeJsSendPort(this, exports._globalState.currentContext.id) ; 1373 return new _NativeJsSendPort(this, exports._globalState.currentContext.id) ;
1244 } 1374 }
1245 } 1375 }
1246 RawReceivePortImpl[dart.implements] = () => [isolate.RawReceivePort]; 1376 RawReceivePortImpl[dart.implements] = () => [isolate.RawReceivePort];
1247 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); 1377 dart.defineNamedConstructor(RawReceivePortImpl, 'weak');
1248 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); 1378 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort');
1379 dart.setSignature(RawReceivePortImpl, {
1380 methods: () => ({
1381 [_close]: dart.functionType(dart.void, []),
1382 close: dart.functionType(dart.void, []),
1383 [_add]: dart.functionType(dart.void, [dart.dynamic])
1384 })
1385 });
1249 RawReceivePortImpl._nextFreeId = 1; 1386 RawReceivePortImpl._nextFreeId = 1;
1250 let _rawPort = Symbol('_rawPort'); 1387 let _rawPort = Symbol('_rawPort');
1251 let _controller = Symbol('_controller'); 1388 let _controller = Symbol('_controller');
1252 class ReceivePortImpl extends async.Stream { 1389 class ReceivePortImpl extends async.Stream {
1253 ReceivePortImpl() { 1390 ReceivePortImpl() {
1254 this.fromRawReceivePort(new RawReceivePortImpl(null)); 1391 this.fromRawReceivePort(new RawReceivePortImpl(null));
1255 } 1392 }
1256 weak() { 1393 weak() {
1257 this.fromRawReceivePort(new RawReceivePortImpl.weak(null)); 1394 this.fromRawReceivePort(new RawReceivePortImpl.weak(null));
1258 } 1395 }
(...skipping 14 matching lines...) Expand all
1273 this[_rawPort].close(); 1410 this[_rawPort].close();
1274 this[_controller].close(); 1411 this[_controller].close();
1275 } 1412 }
1276 get sendPort() { 1413 get sendPort() {
1277 return this[_rawPort].sendPort; 1414 return this[_rawPort].sendPort;
1278 } 1415 }
1279 } 1416 }
1280 ReceivePortImpl[dart.implements] = () => [isolate.ReceivePort]; 1417 ReceivePortImpl[dart.implements] = () => [isolate.ReceivePort];
1281 dart.defineNamedConstructor(ReceivePortImpl, 'weak'); 1418 dart.defineNamedConstructor(ReceivePortImpl, 'weak');
1282 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort'); 1419 dart.defineNamedConstructor(ReceivePortImpl, 'fromRawReceivePort');
1420 dart.setSignature(ReceivePortImpl, {
1421 methods: () => ({
1422 listen: dart.functionType(async.StreamSubscription, [dart.functionType(dar t.void, [dart.dynamic])], {nErro: core.Function, nDon: dart.functionType(dart.vo id, []), ancelOnErro: core.bool}),
1423 close: dart.functionType(dart.void, [])
1424 })
1425 });
1283 let _once = Symbol('_once'); 1426 let _once = Symbol('_once');
1284 let _inEventLoop = Symbol('_inEventLoop'); 1427 let _inEventLoop = Symbol('_inEventLoop');
1285 let _handle = Symbol('_handle'); 1428 let _handle = Symbol('_handle');
1286 class TimerImpl extends core.Object { 1429 class TimerImpl extends core.Object {
1287 TimerImpl(milliseconds, callback) { 1430 TimerImpl(milliseconds, callback) {
1288 this[_once] = true; 1431 this[_once] = true;
1289 this[_inEventLoop] = false; 1432 this[_inEventLoop] = false;
1290 this[_handle] = null; 1433 this[_handle] = null;
1291 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export s._globalState.isWorker))) { 1434 if (milliseconds == 0 && (!dart.notNull(hasTimer()) || dart.notNull(export s._globalState.isWorker))) {
1292 // Function internalCallback: () → void
1293 let internalCallback = (() => { 1435 let internalCallback = (() => {
1294 this[_handle] = null; 1436 this[_handle] = null;
1295 callback(); 1437 callback();
1296 }).bind(this); 1438 }).bind(this);
1439 dart.fn(internalCallback, dart.void, []);
1297 this[_handle] = 1; 1440 this[_handle] = 1;
1298 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo ntext, internalCallback, 'timer'); 1441 exports._globalState.topEventLoop.enqueue(exports._globalState.currentCo ntext, internalCallback, 'timer');
1299 this[_inEventLoop] = true; 1442 this[_inEventLoop] = true;
1300 } else if (hasTimer()) { 1443 } else if (hasTimer()) {
1301 // Function internalCallback: () → void
1302 let internalCallback = (() => { 1444 let internalCallback = (() => {
1303 this[_handle] = null; 1445 this[_handle] = null;
1304 leaveJsAsync(); 1446 leaveJsAsync();
1305 callback(); 1447 callback();
1306 }).bind(this); 1448 }).bind(this);
1449 dart.fn(internalCallback, dart.void, []);
1307 enterJsAsync(); 1450 enterJsAsync();
1308 this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(intern alCallback, 0), milliseconds); 1451 this[_handle] = self.setTimeout(_js_helper.convertDartClosureToJS(intern alCallback, 0), milliseconds);
1309 } else { 1452 } else {
1310 dart.assert(dart.notNull(milliseconds) > 0); 1453 dart.assert(dart.notNull(milliseconds) > 0);
1311 throw new core.UnsupportedError("Timer greater than 0."); 1454 throw new core.UnsupportedError("Timer greater than 0.");
1312 } 1455 }
1313 } 1456 }
1314 periodic(milliseconds, callback) { 1457 periodic(milliseconds, callback) {
1315 this[_once] = false; 1458 this[_once] = false;
1316 this[_inEventLoop] = false; 1459 this[_inEventLoop] = false;
1317 this[_handle] = null; 1460 this[_handle] = null;
1318 if (hasTimer()) { 1461 if (hasTimer()) {
1319 enterJsAsync(); 1462 enterJsAsync();
1320 this[_handle] = self.setInterval(_js_helper.convertDartClosureToJS((() = > { 1463 this[_handle] = self.setInterval(_js_helper.convertDartClosureToJS(dart. fn((() => {
1321 callback(this); 1464 callback(this);
1322 }).bind(this), 0), milliseconds); 1465 }).bind(this)), 0), milliseconds);
1323 } else { 1466 } else {
1324 throw new core.UnsupportedError("Periodic timer."); 1467 throw new core.UnsupportedError("Periodic timer.");
1325 } 1468 }
1326 } 1469 }
1327 cancel() { 1470 cancel() {
1328 if (hasTimer()) { 1471 if (hasTimer()) {
1329 if (this[_inEventLoop]) { 1472 if (this[_inEventLoop]) {
1330 throw new core.UnsupportedError("Timer in event loop cannot be cancele d."); 1473 throw new core.UnsupportedError("Timer in event loop cannot be cancele d.");
1331 } 1474 }
1332 if (this[_handle] == null) 1475 if (this[_handle] == null)
1333 return; 1476 return;
1334 leaveJsAsync(); 1477 leaveJsAsync();
1335 if (this[_once]) { 1478 if (this[_once]) {
1336 self.clearTimeout(this[_handle]); 1479 self.clearTimeout(this[_handle]);
1337 } else { 1480 } else {
1338 self.clearInterval(this[_handle]); 1481 self.clearInterval(this[_handle]);
1339 } 1482 }
1340 this[_handle] = null; 1483 this[_handle] = null;
1341 } else { 1484 } else {
1342 throw new core.UnsupportedError("Canceling a timer."); 1485 throw new core.UnsupportedError("Canceling a timer.");
1343 } 1486 }
1344 } 1487 }
1345 get isActive() { 1488 get isActive() {
1346 return this[_handle] != null; 1489 return this[_handle] != null;
1347 } 1490 }
1348 } 1491 }
1349 TimerImpl[dart.implements] = () => [async.Timer]; 1492 TimerImpl[dart.implements] = () => [async.Timer];
1350 dart.defineNamedConstructor(TimerImpl, 'periodic'); 1493 dart.defineNamedConstructor(TimerImpl, 'periodic');
1351 // Function hasTimer: () → bool 1494 dart.setSignature(TimerImpl, {
1495 methods: () => ({cancel: dart.functionType(dart.void, [])})
1496 });
1352 function hasTimer() { 1497 function hasTimer() {
1353 _js_helper.requiresPreamble(); 1498 _js_helper.requiresPreamble();
1354 return self.setTimeout != null; 1499 return self.setTimeout != null;
1355 } 1500 }
1501 dart.fn(hasTimer, core.bool, []);
1356 class CapabilityImpl extends core.Object { 1502 class CapabilityImpl extends core.Object {
1357 CapabilityImpl() { 1503 CapabilityImpl() {
1358 this._internal(_js_helper.random64()); 1504 this._internal(_js_helper.random64());
1359 } 1505 }
1360 _internal(id) { 1506 _internal(id) {
1361 this[_id] = id; 1507 this[_id] = id;
1362 } 1508 }
1363 get hashCode() { 1509 get hashCode() {
1364 let hash = this[_id]; 1510 let hash = this[_id];
1365 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296).truncat e(); 1511 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296).truncat e();
1366 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295; 1512 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295;
1367 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 12; 1513 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 12;
1368 hash = dart.notNull(hash) * 5 & 4294967295; 1514 hash = dart.notNull(hash) * 5 & 4294967295;
1369 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 4; 1515 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 4;
1370 hash = dart.notNull(hash) * 2057 & 4294967295; 1516 hash = dart.notNull(hash) * 2057 & 4294967295;
1371 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 16; 1517 hash = dart.notNull(hash) ^ dart.notNull(hash) >> 16;
1372 return hash; 1518 return hash;
1373 } 1519 }
1374 ['=='](other) { 1520 ['=='](other) {
1375 if (core.identical(other, this)) 1521 if (core.identical(other, this))
1376 return true; 1522 return true;
1377 if (dart.is(other, CapabilityImpl)) { 1523 if (dart.is(other, CapabilityImpl)) {
1378 return core.identical(this[_id], other[_id]); 1524 return core.identical(this[_id], other[_id]);
1379 } 1525 }
1380 return false; 1526 return false;
1381 } 1527 }
1382 } 1528 }
1383 CapabilityImpl[dart.implements] = () => [isolate.Capability]; 1529 CapabilityImpl[dart.implements] = () => [isolate.Capability];
1384 dart.defineNamedConstructor(CapabilityImpl, '_internal'); 1530 dart.defineNamedConstructor(CapabilityImpl, '_internal');
1531 dart.setSignature(CapabilityImpl, {
1532 methods: () => ({'==': dart.functionType(core.bool, [core.Object])})
1533 });
1385 // Exports: 1534 // Exports:
1386 exports.enterJsAsync = enterJsAsync; 1535 exports.enterJsAsync = enterJsAsync;
1387 exports.leaveJsAsync = leaveJsAsync; 1536 exports.leaveJsAsync = leaveJsAsync;
1388 exports.isWorker = isWorker; 1537 exports.isWorker = isWorker;
1389 exports.startRootIsolate = startRootIsolate; 1538 exports.startRootIsolate = startRootIsolate;
1390 exports.IsolateNatives = IsolateNatives; 1539 exports.IsolateNatives = IsolateNatives;
1391 exports.RawReceivePortImpl = RawReceivePortImpl; 1540 exports.RawReceivePortImpl = RawReceivePortImpl;
1392 exports.ReceivePortImpl = ReceivePortImpl; 1541 exports.ReceivePortImpl = ReceivePortImpl;
1393 exports.TimerImpl = TimerImpl; 1542 exports.TimerImpl = TimerImpl;
1394 exports.hasTimer = hasTimer; 1543 exports.hasTimer = hasTimer;
1395 exports.CapabilityImpl = CapabilityImpl; 1544 exports.CapabilityImpl = CapabilityImpl;
1396 })(_isolate_helper, core, _native_typed_data, _interceptors, _js_helper, isolate , _foreign_helper, _js_embedded_names, collection, async); 1545 })(_isolate_helper, core, _native_typed_data, _interceptors, _js_helper, isolate , _foreign_helper, _js_embedded_names, collection, async);
OLDNEW
« no previous file with comments | « lib/runtime/dart/_internal.js ('k') | lib/runtime/dart/_js_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698