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

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

Issue 1050723002: partially implement instance of checks and some codegen fixes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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; 1 var _isolate_helper;
2 (function(exports) { 2 (function(exports) {
3 'use strict'; 3 'use strict';
4 // Function _serializeMessage: (dynamic) → dynamic 4 // Function _serializeMessage: (dynamic) → dynamic
5 function _serializeMessage(message) { 5 function _serializeMessage(message) {
6 return new _Serializer().serialize(message); 6 return new _Serializer().serialize(message);
7 } 7 }
8 // Function _deserializeMessage: (dynamic) → dynamic 8 // Function _deserializeMessage: (dynamic) → dynamic
9 function _deserializeMessage(message) { 9 function _deserializeMessage(message) {
10 return new _Deserializer().deserialize(message); 10 return new _Deserializer().deserialize(message);
11 } 11 }
12 // Function _clone: (dynamic) → dynamic 12 // Function _clone: (dynamic) → dynamic
13 function _clone(message) { 13 function _clone(message) {
14 let serializer = new _Serializer({serializeSendPorts: false}); 14 let serializer = new _Serializer({serializeSendPorts: false});
15 let deserializer = new _Deserializer(); 15 let deserializer = new _Deserializer();
16 return deserializer.deserialize(serializer.serialize(message)); 16 return deserializer.deserialize(serializer.serialize(message));
17 } 17 }
18 let _serializeSendPorts = Symbol('_serializeSendPorts'); 18 let _serializeSendPorts = Symbol('_serializeSendPorts');
19 let _workerId = Symbol('_workerId'); 19 let _workerId = Symbol('_workerId');
20 let _isolateId = Symbol('_isolateId'); 20 let _isolateId = Symbol('_isolateId');
21 let _receivePortId = Symbol('_receivePortId'); 21 let _receivePortId = Symbol('_receivePortId');
22 let _receivePort = Symbol('_receivePort'); 22 let _receivePort = Symbol('_receivePort');
23 let _id = Symbol('_id'); 23 let _id = Symbol('_id');
24 class _Serializer extends core.Object { 24 class _Serializer extends core.Object {
25 _Serializer(opts) { 25 _Serializer(opts) {
26 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria lizeSendPorts : true; 26 let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.seria lizeSendPorts : true;
27 this.serializedObjectIds = new core.Map.identity(); 27 this.serializedObjectIds = new core.Map$(dynamic, core.int).identity();
28 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool); 28 this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool);
29 } 29 }
30 serialize(x) { 30 serialize(x) {
31 if (this.isPrimitive(x)) 31 if (this.isPrimitive(x))
32 return this.serializePrimitive(x); 32 return this.serializePrimitive(x);
33 let serializationId = this.serializedObjectIds.get(x); 33 let serializationId = this.serializedObjectIds.get(x);
34 if (serializationId != null) 34 if (serializationId != null)
35 return this.makeRef(serializationId); 35 return this.makeRef(serializationId);
36 serializationId = this.serializedObjectIds.length; 36 serializationId = this.serializedObjectIds.length;
37 this.serializedObjectIds.set(x, serializationId); 37 this.serializedObjectIds.set(x, serializationId);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 this.rootContext = null; 423 this.rootContext = null;
424 this.topEventLoop = null; 424 this.topEventLoop = null;
425 this.fromCommandLine = null; 425 this.fromCommandLine = null;
426 this.isWorker = null; 426 this.isWorker = null;
427 this.supportsWorkers = null; 427 this.supportsWorkers = null;
428 this.isolates = null; 428 this.isolates = null;
429 this.mainManager = null; 429 this.mainManager = null;
430 this.managers = null; 430 this.managers = null;
431 this[_nativeDetectEnvironment](); 431 this[_nativeDetectEnvironment]();
432 this.topEventLoop = new _EventLoop(); 432 this.topEventLoop = new _EventLoop();
433 this.isolates = new core.Map(); 433 this.isolates = new (core.Map$(core.int, _IsolateContext))();
434 this.managers = new core.Map(); 434 this.managers = new (core.Map$(core.int, dynamic))();
435 if (this.isWorker) { 435 if (this.isWorker) {
436 this.mainManager = new _MainManagerStub(); 436 this.mainManager = new _MainManagerStub();
437 this[_nativeInitWorkerMessageHandler](); 437 this[_nativeInitWorkerMessageHandler]();
438 } 438 }
439 } 439 }
440 [_nativeDetectEnvironment]() { 440 [_nativeDetectEnvironment]() {
441 let isWindowDefined = exports.globalWindow != null; 441 let isWindowDefined = exports.globalWindow != null;
442 let isWorkerDefined = exports.globalWorker != null; 442 let isWorkerDefined = exports.globalWorker != null;
443 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo balPostMessageDefined); 443 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo balPostMessageDefined);
444 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke rDefined) && dart.notNull(IsolateNatives.thisScript != null); 444 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke rDefined) && dart.notNull(IsolateNatives.thisScript != null);
(...skipping 27 matching lines...) Expand all
472 } 472 }
473 let _controlPort = Symbol('_controlPort'); 473 let _controlPort = Symbol('_controlPort');
474 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); 474 let _scheduledControlEvents = Symbol('_scheduledControlEvents');
475 let _isExecutingEvent = Symbol('_isExecutingEvent'); 475 let _isExecutingEvent = Symbol('_isExecutingEvent');
476 let _updateGlobalState = Symbol('_updateGlobalState'); 476 let _updateGlobalState = Symbol('_updateGlobalState');
477 let _setGlobals = Symbol('_setGlobals'); 477 let _setGlobals = Symbol('_setGlobals');
478 let _addRegistration = Symbol('_addRegistration'); 478 let _addRegistration = Symbol('_addRegistration');
479 class _IsolateContext extends core.Object { 479 class _IsolateContext extends core.Object {
480 _IsolateContext() { 480 _IsolateContext() {
481 this.id = ((x$) => exports._globalState.nextIsolateId = dart.notNull(x$) + 1, x$).bind(this)(exports._globalState.nextIsolateId); 481 this.id = ((x$) => exports._globalState.nextIsolateId = dart.notNull(x$) + 1, x$).bind(this)(exports._globalState.nextIsolateId);
482 this.ports = new core.Map(); 482 this.ports = new (core.Map$(core.int, RawReceivePortImpl))();
483 this.weakPorts = new core.Set(); 483 this.weakPorts = new (core.Set$(core.int))();
484 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE(); 484 this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE();
485 this.controlPort = new RawReceivePortImpl[_controlPort](); 485 this.controlPort = new RawReceivePortImpl[_controlPort]();
486 this.pauseCapability = new isolate.Capability(); 486 this.pauseCapability = new isolate.Capability();
487 this.terminateCapability = new isolate.Capability(); 487 this.terminateCapability = new isolate.Capability();
488 this.delayedEvents = dart.as(new core.List.from([]), core.List$(_IsolateEv ent)); 488 this.delayedEvents = dart.as(new core.List.from([]), core.List$(_IsolateEv ent));
489 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability)); 489 this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability));
490 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort)); 490 this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort));
491 this.initialized = false; 491 this.initialized = false;
492 this.isPaused = false; 492 this.isPaused = false;
493 this.doneHandlers = null; 493 this.doneHandlers = null;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 unregister(portId) { 726 unregister(portId) {
727 this.ports.remove(portId); 727 this.ports.remove(portId);
728 this.weakPorts.remove(portId); 728 this.weakPorts.remove(portId);
729 this[_updateGlobalState](); 729 this[_updateGlobalState]();
730 } 730 }
731 } 731 }
732 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext]; 732 _IsolateContext[dart.implements] = () => [_foreign_helper.IsolateContext];
733 let _runHelper = Symbol('_runHelper'); 733 let _runHelper = Symbol('_runHelper');
734 class _EventLoop extends core.Object { 734 class _EventLoop extends core.Object {
735 _EventLoop() { 735 _EventLoop() {
736 this.events = new collection.Queue(); 736 this.events = new (collection.Queue$(_IsolateEvent))();
737 this[_activeJsAsyncCount] = 0; 737 this[_activeJsAsyncCount] = 0;
738 } 738 }
739 enqueue(isolate, fn, msg) { 739 enqueue(isolate, fn, msg) {
740 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d art.as(fn, core.Function), dart.as(msg, core.String))); 740 this.events.addLast(new _IsolateEvent(dart.as(isolate, _IsolateContext), d art.as(fn, core.Function), dart.as(msg, core.String)));
741 } 741 }
742 prequeue(event) { 742 prequeue(event) {
743 this.events.addFirst(event); 743 this.events.addFirst(event);
744 } 744 }
745 dequeue() { 745 dequeue() {
746 if (this.events.isEmpty) 746 if (this.events.isEmpty)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 let signalReply = port.sendPort; 1016 let signalReply = port.sendPort;
1017 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight )) { 1017 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight )) {
1018 IsolateNatives[_startWorker](functionName, uri, args, message, isSpawnUr i, startPaused, signalReply, ((message) => completer.completeError(message)).bin d(this)); 1018 IsolateNatives[_startWorker](functionName, uri, args, message, isSpawnUr i, startPaused, signalReply, ((message) => completer.completeError(message)).bin d(this));
1019 } else { 1019 } else {
1020 IsolateNatives[_startNonWorker](functionName, uri, args, message, isSpaw nUri, startPaused, signalReply); 1020 IsolateNatives[_startNonWorker](functionName, uri, args, message, isSpaw nUri, startPaused, signalReply);
1021 } 1021 }
1022 return completer.future; 1022 return completer.future;
1023 } 1023 }
1024 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau sed, replyPort, onError) { 1024 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau sed, replyPort, onError) {
1025 if (args != null) 1025 if (args != null)
1026 args = new core.List.from(args); 1026 args = new core.List$(core.String).from(args);
1027 if (exports._globalState.isWorker) { 1027 if (exports._globalState.isWorker) {
1028 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'spawn-worker', functionName: functionName, args: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort }))); 1028 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map( {command: 'spawn-worker', functionName: functionName, args: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort })));
1029 } else { 1029 } else {
1030 IsolateNatives[_spawnWorker](functionName, uri, args, message, isSpawnUr i, startPaused, replyPort, onError); 1030 IsolateNatives[_spawnWorker](functionName, uri, args, message, isSpawnUr i, startPaused, replyPort, onError);
1031 } 1031 }
1032 } 1032 }
1033 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start Paused, replyPort) { 1033 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start Paused, replyPort) {
1034 if (uri != null) { 1034 if (uri != null) {
1035 throw new core.UnsupportedError("Currently spawnUri is not supported wit hout web workers."); 1035 throw new core.UnsupportedError("Currently spawnUri is not supported wit hout web workers.");
1036 } 1036 }
1037 message = _clone(message); 1037 message = _clone(message);
1038 if (args != null) 1038 if (args != null)
1039 args = new core.List.from(args); 1039 args = new core.List$(core.String).from(args);
1040 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { 1040 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => {
1041 let func = IsolateNatives[_getJSFunctionFromName](functionName); 1041 let func = IsolateNatives[_getJSFunctionFromName](functionName);
1042 IsolateNatives[_startIsolate](dart.as(func, core.Function), args, messag e, isSpawnUri, startPaused, replyPort); 1042 IsolateNatives[_startIsolate](dart.as(func, core.Function), args, messag e, isSpawnUri, startPaused, replyPort);
1043 }, 'nonworker start'); 1043 }, 'nonworker start');
1044 } 1044 }
1045 static get currentIsolate() { 1045 static get currentIsolate() {
1046 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext); 1046 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola teContext);
1047 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability}); 1047 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability: context.pauseCapability, terminateCapability: context.terminateCapability});
1048 } 1048 }
1049 static [_startIsolate](topLevel, args, message, isSpawnUri, startPaused, rep lyTo) { 1049 static [_startIsolate](topLevel, args, message, isSpawnUri, startPaused, rep lyTo) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 return true; 1104 return true;
1105 } 1105 }
1106 } 1106 }
1107 IsolateNatives.enableSpawnWorker = null; 1107 IsolateNatives.enableSpawnWorker = null;
1108 dart.defineLazyProperties(IsolateNatives, { 1108 dart.defineLazyProperties(IsolateNatives, {
1109 get thisScript() { 1109 get thisScript() {
1110 return IsolateNatives.computeThisScript(); 1110 return IsolateNatives.computeThisScript();
1111 }, 1111 },
1112 set thisScript(_) {}, 1112 set thisScript(_) {},
1113 get workerIds() { 1113 get workerIds() {
1114 return new core.Expando(); 1114 return new (core.Expando$(core.int))();
1115 } 1115 }
1116 }); 1116 });
1117 let _checkReplyTo = Symbol('_checkReplyTo'); 1117 let _checkReplyTo = Symbol('_checkReplyTo');
1118 class _BaseSendPort extends core.Object { 1118 class _BaseSendPort extends core.Object {
1119 _BaseSendPort(isolateId$) { 1119 _BaseSendPort(isolateId$) {
1120 this[_isolateId] = isolateId$; 1120 this[_isolateId] = isolateId$;
1121 } 1121 }
1122 [_checkReplyTo](replyTo) { 1122 [_checkReplyTo](replyTo) {
1123 if (dart.notNull(replyTo != null) && dart.notNull(!dart.is(replyTo, _Nativ eJsSendPort)) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))) { 1123 if (dart.notNull(replyTo != null) && dart.notNull(!dart.is(replyTo, _Nativ eJsSendPort)) && dart.notNull(!dart.is(replyTo, _WorkerSendPort))) {
1124 throw new core.Exception("SendPort.send: Illegal replyTo port type"); 1124 throw new core.Exception("SendPort.send: Illegal replyTo port type");
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 exports.leaveJsAsync = leaveJsAsync; 1372 exports.leaveJsAsync = leaveJsAsync;
1373 exports.isWorker = isWorker; 1373 exports.isWorker = isWorker;
1374 exports.startRootIsolate = startRootIsolate; 1374 exports.startRootIsolate = startRootIsolate;
1375 exports.IsolateNatives = IsolateNatives; 1375 exports.IsolateNatives = IsolateNatives;
1376 exports.RawReceivePortImpl = RawReceivePortImpl; 1376 exports.RawReceivePortImpl = RawReceivePortImpl;
1377 exports.ReceivePortImpl = ReceivePortImpl; 1377 exports.ReceivePortImpl = ReceivePortImpl;
1378 exports.TimerImpl = TimerImpl; 1378 exports.TimerImpl = TimerImpl;
1379 exports.hasTimer = hasTimer; 1379 exports.hasTimer = hasTimer;
1380 exports.CapabilityImpl = CapabilityImpl; 1380 exports.CapabilityImpl = CapabilityImpl;
1381 })(_isolate_helper || (_isolate_helper = {})); 1381 })(_isolate_helper || (_isolate_helper = {}));
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