| OLD | NEW |
| 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); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 dart.copyProperties(exports, { | 373 dart.copyProperties(exports, { |
| 374 get _globalState() { | 374 get _globalState() { |
| 375 return dart.as(init.globalState, _Manager); | 375 return dart.as(init.globalState, _Manager); |
| 376 }, | 376 }, |
| 377 set _globalState(val) { | 377 set _globalState(val) { |
| 378 init.globalState = val; | 378 init.globalState = val; |
| 379 } | 379 } |
| 380 }); | 380 }); |
| 381 let _nativeDetectEnvironment = Symbol('_nativeDetectEnvironment'); | 381 let _nativeDetectEnvironment = Symbol('_nativeDetectEnvironment'); |
| 382 let _nativeInitWorkerMessageHandler = Symbol('_nativeInitWorkerMessageHandler'
); | 382 let _nativeInitWorkerMessageHandler = Symbol('_nativeInitWorkerMessageHandler'
); |
| 383 let _processWorkerMessage$ = Symbol('_processWorkerMessage'); | 383 let _processWorkerMessage = Symbol('_processWorkerMessage'); |
| 384 let _serializePrintMessage$ = Symbol('_serializePrintMessage'); | 384 let _serializePrintMessage = Symbol('_serializePrintMessage'); |
| 385 class _Manager extends core.Object { | 385 class _Manager extends core.Object { |
| 386 get useWorkers() { | 386 get useWorkers() { |
| 387 return this.supportsWorkers; | 387 return this.supportsWorkers; |
| 388 } | 388 } |
| 389 _Manager(entry) { | 389 _Manager(entry) { |
| 390 this.entry = entry; | 390 this.entry = entry; |
| 391 this.nextIsolateId = 0; | 391 this.nextIsolateId = 0; |
| 392 this.currentManagerId = 0; | 392 this.currentManagerId = 0; |
| 393 this.nextManagerId = 1; | 393 this.nextManagerId = 1; |
| 394 this.currentContext = null; | 394 this.currentContext = null; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 414 let isWorkerDefined = exports.globalWorker !== null; | 414 let isWorkerDefined = exports.globalWorker !== null; |
| 415 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); | 415 this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.glo
balPostMessageDefined); |
| 416 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && dart.notNull(IsolateNatives.thisScript !== null); | 416 this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorke
rDefined) && dart.notNull(IsolateNatives.thisScript !== null); |
| 417 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); | 417 this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(thi
s.isWorker); |
| 418 } | 418 } |
| 419 [_nativeInitWorkerMessageHandler]() { | 419 [_nativeInitWorkerMessageHandler]() { |
| 420 let function$0 = function(f, a) { | 420 let function$0 = function(f, a) { |
| 421 return function(e) { | 421 return function(e) { |
| 422 f(a, e); | 422 f(a, e); |
| 423 }; | 423 }; |
| 424 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage$
]), this.mainManager); | 424 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), this.mainManager); |
| 425 self.onmessage = function$0; | 425 self.onmessage = function$0; |
| 426 self.dartPrint = self.dartPrint || function(serialize) { | 426 self.dartPrint = self.dartPrint || function(serialize) { |
| 427 return function(object) { | 427 return function(object) { |
| 428 if (self.console && self.console.log) { | 428 if (self.console && self.console.log) { |
| 429 self.console.log(object); | 429 self.console.log(object); |
| 430 } else { | 430 } else { |
| 431 self.postMessage(serialize(object)); | 431 self.postMessage(serialize(object)); |
| 432 } | 432 } |
| 433 }; | 433 }; |
| 434 }(_foreign_helper.DART_CLOSURE_TO_JS(_serializePrintMessage)); | 434 }(_foreign_helper.DART_CLOSURE_TO_JS(_Manager[_serializePrintMessage])); |
| 435 } | 435 } |
| 436 static [_serializePrintMessage$](object) { | 436 static [_serializePrintMessage](object) { |
| 437 return _serializeMessage(dart.map({command: "print", msg: object})); | 437 return _serializeMessage(dart.map({command: "print", msg: object})); |
| 438 } | 438 } |
| 439 maybeCloseWorker() { | 439 maybeCloseWorker() { |
| 440 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] === 0) { | 440 if (dart.notNull(this.isWorker) && dart.notNull(this.isolates.isEmpty) &&
this.topEventLoop[_activeJsAsyncCount] === 0) { |
| 441 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); | 441 this.mainManager.postMessage(_serializeMessage(dart.map({command: 'close
'}))); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); | 445 let _scheduledControlEvents = Symbol('_scheduledControlEvents'); |
| 446 let _isExecutingEvent = Symbol('_isExecutingEvent'); | 446 let _isExecutingEvent = Symbol('_isExecutingEvent'); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 }, | 771 }, |
| 772 get globalWorker() { | 772 get globalWorker() { |
| 773 _js_helper.requiresPreamble(); | 773 _js_helper.requiresPreamble(); |
| 774 return self.Worker; | 774 return self.Worker; |
| 775 }, | 775 }, |
| 776 get globalPostMessageDefined() { | 776 get globalPostMessageDefined() { |
| 777 _js_helper.requiresPreamble(); | 777 _js_helper.requiresPreamble(); |
| 778 return !!self.postMessage; | 778 return !!self.postMessage; |
| 779 } | 779 } |
| 780 }); | 780 }); |
| 781 let _getEventData$ = Symbol('_getEventData'); | 781 let _getEventData = Symbol('_getEventData'); |
| 782 let _log$ = Symbol('_log'); | 782 let _getJSFunctionFromName = Symbol('_getJSFunctionFromName'); |
| 783 let _consoleLog$ = Symbol('_consoleLog'); | 783 let _startIsolate = Symbol('_startIsolate'); |
| 784 let _getJSFunctionFromName$ = Symbol('_getJSFunctionFromName'); | 784 let _log = Symbol('_log'); |
| 785 let _getJSFunctionName$ = Symbol('_getJSFunctionName'); | 785 let _consoleLog = Symbol('_consoleLog'); |
| 786 let _getJSFunctionName = Symbol('_getJSFunctionName'); |
| 786 let _allocate = Symbol('_allocate'); | 787 let _allocate = Symbol('_allocate'); |
| 787 let _startWorker$ = Symbol('_startWorker'); | 788 let _startWorker = Symbol('_startWorker'); |
| 788 let _startNonWorker$ = Symbol('_startNonWorker'); | 789 let _startNonWorker = Symbol('_startNonWorker'); |
| 789 let _startIsolate$ = Symbol('_startIsolate'); | 790 let _spawnWorker = Symbol('_spawnWorker'); |
| 790 let _spawnWorker$ = Symbol('_spawnWorker'); | |
| 791 class IsolateNatives extends core.Object { | 791 class IsolateNatives extends core.Object { |
| 792 static computeThisScript() { | 792 static computeThisScript() { |
| 793 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na
mes.CURRENT_SCRIPT); | 793 let currentScript = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_na
mes.CURRENT_SCRIPT); |
| 794 if (currentScript !== null) { | 794 if (currentScript !== null) { |
| 795 return String(currentScript.src); | 795 return String(currentScript.src); |
| 796 } | 796 } |
| 797 if (_js_helper.Primitives.isD8) | 797 if (_js_helper.Primitives.isD8) |
| 798 return computeThisScriptD8(); | 798 return IsolateNatives.computeThisScriptD8(); |
| 799 if (_js_helper.Primitives.isJsshell) | 799 if (_js_helper.Primitives.isJsshell) |
| 800 return computeThisScriptJsshell(); | 800 return IsolateNatives.computeThisScriptJsshell(); |
| 801 if (exports._globalState.isWorker) | 801 if (exports._globalState.isWorker) |
| 802 return computeThisScriptFromTrace(); | 802 return IsolateNatives.computeThisScriptFromTrace(); |
| 803 return null; | 803 return null; |
| 804 } | 804 } |
| 805 static computeThisScriptJsshell() { | 805 static computeThisScriptJsshell() { |
| 806 return dart.as(thisFilename(), core.String); | 806 return dart.as(thisFilename(), core.String); |
| 807 } | 807 } |
| 808 static computeThisScriptD8() { | 808 static computeThisScriptD8() { |
| 809 return computeThisScriptFromTrace(); | 809 return IsolateNatives.computeThisScriptFromTrace(); |
| 810 } | 810 } |
| 811 static computeThisScriptFromTrace() { | 811 static computeThisScriptFromTrace() { |
| 812 let stack = new Error().stack; | 812 let stack = new Error().stack; |
| 813 if (stack === null) { | 813 if (stack === null) { |
| 814 stack = function() { | 814 stack = function() { |
| 815 try { | 815 try { |
| 816 throw new Error(); | 816 throw new Error(); |
| 817 } catch (e) { | 817 } catch (e) { |
| 818 return e.stack; | 818 return e.stack; |
| 819 } | 819 } |
| 820 | 820 |
| 821 }(); | 821 }(); |
| 822 if (stack === null) | 822 if (stack === null) |
| 823 throw new core.UnsupportedError('No stack trace'); | 823 throw new core.UnsupportedError('No stack trace'); |
| 824 } | 824 } |
| 825 let pattern = null, matches = null; | 825 let pattern = null, matches = null; |
| 826 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); | 826 pattern = new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m"); |
| 827 matches = stack.match(pattern); | 827 matches = stack.match(pattern); |
| 828 if (matches !== null) | 828 if (matches !== null) |
| 829 return matches[1]; | 829 return matches[1]; |
| 830 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); | 830 pattern = new RegExp("^[^@]*@(.*):[0-9]*$", "m"); |
| 831 matches = stack.match(pattern); | 831 matches = stack.match(pattern); |
| 832 if (matches !== null) | 832 if (matches !== null) |
| 833 return matches[1]; | 833 return matches[1]; |
| 834 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); | 834 throw new core.UnsupportedError(`Cannot extract URI from "${stack}"`); |
| 835 } | 835 } |
| 836 static [_getEventData$](e) { | 836 static [_getEventData](e) { |
| 837 return e.data; | 837 return e.data; |
| 838 } | 838 } |
| 839 static [_processWorkerMessage$](sender, e) { | 839 static [_processWorkerMessage](sender, e) { |
| 840 let msg = _deserializeMessage(_getEventData(e)); | 840 let msg = _deserializeMessage(IsolateNatives[_getEventData](e)); |
| 841 switch (dart.dindex(msg, 'command')) { | 841 switch (dart.dindex(msg, 'command')) { |
| 842 case 'start': | 842 case 'start': |
| 843 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); | 843 exports._globalState.currentManagerId = dart.as(dart.dindex(msg, 'id')
, core.int); |
| 844 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); | 844 let functionName = dart.as(dart.dindex(msg, 'functionName'), core.Stri
ng); |
| 845 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : _getJSFunctionFromName(functionName), core.Function); | 845 let entryPoint = dart.as(functionName === null ? exports._globalState.
entry : IsolateNatives[_getJSFunctionFromName](functionName), core.Function); |
| 846 let args = dart.dindex(msg, 'args'); | 846 let args = dart.dindex(msg, 'args'); |
| 847 let message = _deserializeMessage(dart.dindex(msg, 'msg')); | 847 let message = _deserializeMessage(dart.dindex(msg, 'msg')); |
| 848 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); | 848 let isSpawnUri = dart.dindex(msg, 'isSpawnUri'); |
| 849 let startPaused = dart.dindex(msg, 'startPaused'); | 849 let startPaused = dart.dindex(msg, 'startPaused'); |
| 850 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); | 850 let replyTo = _deserializeMessage(dart.dindex(msg, 'replyTo')); |
| 851 let context = new _IsolateContext(); | 851 let context = new _IsolateContext(); |
| 852 exports._globalState.topEventLoop.enqueue(context, () => { | 852 exports._globalState.topEventLoop.enqueue(context, () => { |
| 853 _startIsolate(entryPoint, dart.as(args, core.List$(core.String)), me
ssage, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core.bool), dart.as(
replyTo, isolate.SendPort)); | 853 IsolateNatives[_startIsolate](entryPoint, dart.as(args, core.List$(c
ore.String)), message, dart.as(isSpawnUri, core.bool), dart.as(startPaused, core
.bool), dart.as(replyTo, isolate.SendPort)); |
| 854 }, 'worker-start'); | 854 }, 'worker-start'); |
| 855 exports._globalState.currentContext = context; | 855 exports._globalState.currentContext = context; |
| 856 exports._globalState.topEventLoop.run(); | 856 exports._globalState.topEventLoop.run(); |
| 857 break; | 857 break; |
| 858 case 'spawn-worker': | 858 case 'spawn-worker': |
| 859 if (enableSpawnWorker !== null) | 859 if (IsolateNatives.enableSpawnWorker !== null) |
| 860 handleSpawnWorkerRequest(msg); | 860 IsolateNatives.handleSpawnWorkerRequest(msg); |
| 861 break; | 861 break; |
| 862 case 'message': | 862 case 'message': |
| 863 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); | 863 let port = dart.as(dart.dindex(msg, 'port'), isolate.SendPort); |
| 864 if (port !== null) { | 864 if (port !== null) { |
| 865 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); | 865 dart.dinvoke(dart.dindex(msg, 'port'), 'send', dart.dindex(msg, 'msg
')); |
| 866 } | 866 } |
| 867 exports._globalState.topEventLoop.run(); | 867 exports._globalState.topEventLoop.run(); |
| 868 break; | 868 break; |
| 869 case 'close': | 869 case 'close': |
| 870 exports._globalState.managers.remove(workerIds.get(sender)); | 870 exports._globalState.managers.remove(IsolateNatives.workerIds.get(send
er)); |
| 871 sender.terminate(); | 871 sender.terminate(); |
| 872 exports._globalState.topEventLoop.run(); | 872 exports._globalState.topEventLoop.run(); |
| 873 break; | 873 break; |
| 874 case 'log': | 874 case 'log': |
| 875 _log(dart.dindex(msg, 'msg')); | 875 IsolateNatives[_log](dart.dindex(msg, 'msg')); |
| 876 break; | 876 break; |
| 877 case 'print': | 877 case 'print': |
| 878 if (exports._globalState.isWorker) { | 878 if (exports._globalState.isWorker) { |
| 879 exports._globalState.mainManager.postMessage(_serializeMessage(dart.
map({command: 'print', msg: msg}))); | 879 exports._globalState.mainManager.postMessage(_serializeMessage(dart.
map({command: 'print', msg: msg}))); |
| 880 } else { | 880 } else { |
| 881 core.print(dart.dindex(msg, 'msg')); | 881 core.print(dart.dindex(msg, 'msg')); |
| 882 } | 882 } |
| 883 break; | 883 break; |
| 884 case 'error': | 884 case 'error': |
| 885 throw dart.dindex(msg, 'msg'); | 885 throw dart.dindex(msg, 'msg'); |
| 886 } | 886 } |
| 887 } | 887 } |
| 888 static handleSpawnWorkerRequest(msg) { | 888 static handleSpawnWorkerRequest(msg) { |
| 889 let replyPort = dart.dindex(msg, 'replyPort'); | 889 let replyPort = dart.dindex(msg, 'replyPort'); |
| 890 spawn(dart.as(dart.dindex(msg, 'functionName'), core.String), dart.as(dart
.dindex(msg, 'uri'), core.String), dart.as(dart.dindex(msg, 'args'), core.List$(
core.String)), dart.dindex(msg, 'msg'), false, dart.as(dart.dindex(msg, 'isSpawn
Uri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.bool)).then(dar
t.closureWrap((msg) => { | 890 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.closureWrap((msg) => { |
| 891 dart.dinvoke(replyPort, 'send', msg); | 891 dart.dinvoke(replyPort, 'send', msg); |
| 892 }, "(List<dynamic>) → dynamic"), { | 892 }, "(List<dynamic>) → dynamic"), { |
| 893 onError: (errorMessage) => { | 893 onError: (errorMessage) => { |
| 894 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); | 894 dart.dinvoke(replyPort, 'send', new List.from([_SPAWN_FAILED_SIGNAL, e
rrorMessage])); |
| 895 } | 895 } |
| 896 }); | 896 }); |
| 897 } | 897 } |
| 898 static [_log$](msg) { | 898 static [_log](msg) { |
| 899 if (exports._globalState.isWorker) { | 899 if (exports._globalState.isWorker) { |
| 900 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); | 900 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'log', msg: msg}))); |
| 901 } else { | 901 } else { |
| 902 try { | 902 try { |
| 903 _consoleLog(msg); | 903 IsolateNatives[_consoleLog](msg); |
| 904 } catch (e) { | 904 } catch (e) { |
| 905 let trace = dart.stackTrace(e); | 905 let trace = dart.stackTrace(e); |
| 906 throw new core.Exception(trace); | 906 throw new core.Exception(trace); |
| 907 } | 907 } |
| 908 | 908 |
| 909 } | 909 } |
| 910 } | 910 } |
| 911 static [_consoleLog$](msg) { | 911 static [_consoleLog](msg) { |
| 912 _js_helper.requiresPreamble(); | 912 _js_helper.requiresPreamble(); |
| 913 self.console.log(msg); | 913 self.console.log(msg); |
| 914 } | 914 } |
| 915 static [_getJSFunctionFromName$](functionName) { | 915 static [_getJSFunctionFromName](functionName) { |
| 916 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", _js_
embedded_names.GLOBAL_FUNCTIONS); | 916 let globalFunctionsContainer = _foreign_helper.JS_EMBEDDED_GLOBAL("", _js_
embedded_names.GLOBAL_FUNCTIONS); |
| 917 return globalFunctionsContainer[functionName](); | 917 return globalFunctionsContainer[functionName](); |
| 918 } | 918 } |
| 919 static [_getJSFunctionName$](f) { | 919 static [_getJSFunctionName](f) { |
| 920 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); | 920 return dart.as(dart.is(f, _js_helper.Closure) ? f.$name : null, core.Strin
g); |
| 921 } | 921 } |
| 922 static [_allocate](ctor) { | 922 static [_allocate](ctor) { |
| 923 return new ctor(); | 923 return new ctor(); |
| 924 } | 924 } |
| 925 static spawnFunction(topLevelFunction, message, startPaused) { | 925 static spawnFunction(topLevelFunction, message, startPaused) { |
| 926 IsolateNatives.enableSpawnWorker = true; | 926 IsolateNatives.enableSpawnWorker = true; |
| 927 let name = _getJSFunctionName(topLevelFunction); | 927 let name = IsolateNatives[_getJSFunctionName](topLevelFunction); |
| 928 if (name === null) { | 928 if (name === null) { |
| 929 throw new core.UnsupportedError("only top-level functions can be spawned
."); | 929 throw new core.UnsupportedError("only top-level functions can be spawned
."); |
| 930 } | 930 } |
| 931 let isLight = false; | 931 let isLight = false; |
| 932 let isSpawnUri = false; | 932 let isSpawnUri = false; |
| 933 return spawn(name, null, null, message, isLight, isSpawnUri, startPaused); | 933 return IsolateNatives.spawn(name, null, null, message, isLight, isSpawnUri
, startPaused); |
| 934 } | 934 } |
| 935 static spawnUri(uri, args, message, startPaused) { | 935 static spawnUri(uri, args, message, startPaused) { |
| 936 IsolateNatives.enableSpawnWorker = true; | 936 IsolateNatives.enableSpawnWorker = true; |
| 937 let isLight = false; | 937 let isLight = false; |
| 938 let isSpawnUri = true; | 938 let isSpawnUri = true; |
| 939 return spawn(null, uri.toString(), args, message, isLight, isSpawnUri, sta
rtPaused); | 939 return IsolateNatives.spawn(null, uri.toString(), args, message, isLight,
isSpawnUri, startPaused); |
| 940 } | 940 } |
| 941 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { | 941 static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPau
sed) { |
| 942 if (dart.notNull(uri !== null) && dart.notNull(uri.endsWith(".dart"))) | 942 if (dart.notNull(uri !== null) && dart.notNull(uri.endsWith(".dart"))) |
| 943 uri = ".js"; | 943 uri = ".js"; |
| 944 let port = new isolate.ReceivePort(); | 944 let port = new isolate.ReceivePort(); |
| 945 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); | 945 let completer = dart.as(new async.Completer(), async.Completer$(core.List)
); |
| 946 port.first.then(((msg) => { | 946 port.first.then(((msg) => { |
| 947 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { | 947 if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) { |
| 948 completer.complete(msg); | 948 completer.complete(msg); |
| 949 } else { | 949 } else { |
| 950 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); | 950 dart.assert(dart.equals(dart.dindex(msg, 0), _SPAWN_FAILED_SIGNAL)); |
| 951 completer.completeError(dart.dindex(msg, 1)); | 951 completer.completeError(dart.dindex(msg, 1)); |
| 952 } | 952 } |
| 953 }).bind(this)); | 953 }).bind(this)); |
| 954 let signalReply = port.sendPort; | 954 let signalReply = port.sendPort; |
| 955 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { | 955 if (dart.notNull(exports._globalState.useWorkers) && !dart.notNull(isLight
)) { |
| 956 _startWorker(functionName, uri, args, message, isSpawnUri, startPaused,
signalReply, ((message) => completer.completeError(message)).bind(this)); | 956 IsolateNatives[_startWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, signalReply, ((message) => completer.completeError(message)).bin
d(this)); |
| 957 } else { | 957 } else { |
| 958 _startNonWorker(functionName, uri, args, message, isSpawnUri, startPause
d, signalReply); | 958 IsolateNatives[_startNonWorker](functionName, uri, args, message, isSpaw
nUri, startPaused, signalReply); |
| 959 } | 959 } |
| 960 return completer.future; | 960 return completer.future; |
| 961 } | 961 } |
| 962 static [_startWorker$](functionName, uri, args, message, isSpawnUri, startPa
used, replyPort, onError) { | 962 static [_startWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
| 963 if (args !== null) | 963 if (args !== null) |
| 964 args = new core.List.from(args); | 964 args = new core.List.from(args); |
| 965 if (exports._globalState.isWorker) { | 965 if (exports._globalState.isWorker) { |
| 966 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); | 966 exports._globalState.mainManager.postMessage(_serializeMessage(dart.map(
{command: 'spawn-worker', functionName: functionName, args: args, msg: message,
uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort
}))); |
| 967 } else { | 967 } else { |
| 968 _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
replyPort, onError); | 968 IsolateNatives[_spawnWorker](functionName, uri, args, message, isSpawnUr
i, startPaused, replyPort, onError); |
| 969 } | 969 } |
| 970 } | 970 } |
| 971 static [_startNonWorker$](functionName, uri, args, message, isSpawnUri, star
tPaused, replyPort) { | 971 static [_startNonWorker](functionName, uri, args, message, isSpawnUri, start
Paused, replyPort) { |
| 972 if (uri !== null) { | 972 if (uri !== null) { |
| 973 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); | 973 throw new core.UnsupportedError("Currently spawnUri is not supported wit
hout web workers."); |
| 974 } | 974 } |
| 975 message = _clone(message); | 975 message = _clone(message); |
| 976 if (args !== null) | 976 if (args !== null) |
| 977 args = new core.List.from(args); | 977 args = new core.List.from(args); |
| 978 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { | 978 exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => { |
| 979 let func = _getJSFunctionFromName(functionName); | 979 let func = IsolateNatives[_getJSFunctionFromName](functionName); |
| 980 _startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, s
tartPaused, replyPort); | 980 IsolateNatives[_startIsolate](dart.as(func, core.Function), args, messag
e, isSpawnUri, startPaused, replyPort); |
| 981 }, 'nonworker start'); | 981 }, 'nonworker start'); |
| 982 } | 982 } |
| 983 static get currentIsolate() { | 983 static get currentIsolate() { |
| 984 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 984 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
| 985 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); | 985 return new isolate.Isolate(context.controlPort.sendPort, {pauseCapability:
context.pauseCapability, terminateCapability: context.terminateCapability}); |
| 986 } | 986 } |
| 987 static [_startIsolate$](topLevel, args, message, isSpawnUri, startPaused, re
plyTo) { | 987 static [_startIsolate](topLevel, args, message, isSpawnUri, startPaused, rep
lyTo) { |
| 988 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); | 988 let context = dart.as(_foreign_helper.JS_CURRENT_ISOLATE_CONTEXT(), _Isola
teContext); |
| 989 _js_helper.Primitives.initializeStatics(context.id); | 989 _js_helper.Primitives.initializeStatics(context.id); |
| 990 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); | 990 replyTo.send(new List.from([_SPAWNED_SIGNAL, context.controlPort.sendPort,
context.pauseCapability, context.terminateCapability])); |
| 991 // Function runStartFunction: () → void | 991 // Function runStartFunction: () → void |
| 992 function runStartFunction() { | 992 function runStartFunction() { |
| 993 context.initialized = true; | 993 context.initialized = true; |
| 994 if (!dart.notNull(isSpawnUri)) { | 994 if (!dart.notNull(isSpawnUri)) { |
| 995 dart.dinvokef(topLevel, message); | 995 dart.dinvokef(topLevel, message); |
| 996 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { | 996 } else if (dart.is(topLevel, _MainFunctionArgsMessage)) { |
| 997 dart.dinvokef(topLevel, args, message); | 997 dart.dinvokef(topLevel, args, message); |
| 998 } else if (dart.is(topLevel, _MainFunctionArgs)) { | 998 } else if (dart.is(topLevel, _MainFunctionArgs)) { |
| 999 dart.dinvokef(topLevel, args); | 999 dart.dinvokef(topLevel, args); |
| 1000 } else { | 1000 } else { |
| 1001 dart.dinvokef(topLevel); | 1001 dart.dinvokef(topLevel); |
| 1002 } | 1002 } |
| 1003 } | 1003 } |
| 1004 if (startPaused) { | 1004 if (startPaused) { |
| 1005 context.addPause(context.pauseCapability, context.pauseCapability); | 1005 context.addPause(context.pauseCapability, context.pauseCapability); |
| 1006 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); | 1006 exports._globalState.topEventLoop.enqueue(context, runStartFunction, 'st
art isolate'); |
| 1007 } else { | 1007 } else { |
| 1008 runStartFunction(); | 1008 runStartFunction(); |
| 1009 } | 1009 } |
| 1010 } | 1010 } |
| 1011 static [_spawnWorker$](functionName, uri, args, message, isSpawnUri, startPa
used, replyPort, onError) { | 1011 static [_spawnWorker](functionName, uri, args, message, isSpawnUri, startPau
sed, replyPort, onError) { |
| 1012 if (uri === null) | 1012 if (uri === null) |
| 1013 uri = thisScript; | 1013 uri = IsolateNatives.thisScript; |
| 1014 let worker = new Worker(uri); | 1014 let worker = new Worker(uri); |
| 1015 let onerrorTrampoline = function(f, u, c) { | 1015 let onerrorTrampoline = function(f, u, c) { |
| 1016 return function(e) { | 1016 return function(e) { |
| 1017 return f(e, u, c); | 1017 return f(e, u, c); |
| 1018 }; | 1018 }; |
| 1019 }(_foreign_helper.DART_CLOSURE_TO_JS(workerOnError), uri, onError); | 1019 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives.workerOnError), uri, o
nError); |
| 1020 worker.onerror = onerrorTrampoline; | 1020 worker.onerror = onerrorTrampoline; |
| 1021 let processWorkerMessageTrampoline = function(f, a) { | 1021 let processWorkerMessageTrampoline = function(f, a) { |
| 1022 return function(e) { | 1022 return function(e) { |
| 1023 e.onerror = null; | 1023 e.onerror = null; |
| 1024 return f(a, e); | 1024 return f(a, e); |
| 1025 }; | 1025 }; |
| 1026 }(_foreign_helper.DART_CLOSURE_TO_JS(_processWorkerMessage), worker); | 1026 }(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]
), worker); |
| 1027 worker.onmessage = processWorkerMessageTrampoline; | 1027 worker.onmessage = processWorkerMessageTrampoline; |
| 1028 let workerId = ((x$) => exports._globalState.nextManagerId = dart.notNull(
x$) + 1, x$).bind(this)(exports._globalState.nextManagerId); | 1028 let workerId = ((x$) => exports._globalState.nextManagerId = dart.notNull(
x$) + 1, x$).bind(this)(exports._globalState.nextManagerId); |
| 1029 workerIds.set(worker, workerId); | 1029 IsolateNatives.workerIds.set(worker, workerId); |
| 1030 exports._globalState.managers.set(workerId, worker); | 1030 exports._globalState.managers.set(workerId, worker); |
| 1031 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); | 1031 worker.postMessage(_serializeMessage(dart.map({command: 'start', id: worke
rId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(m
essage), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functio
nName}))); |
| 1032 } | 1032 } |
| 1033 static workerOnError(event, uri, onError) { | 1033 static workerOnError(event, uri, onError) { |
| 1034 event.preventDefault(); | 1034 event.preventDefault(); |
| 1035 let message = dart.as(event.message, core.String); | 1035 let message = dart.as(event.message, core.String); |
| 1036 if (message === null) { | 1036 if (message === null) { |
| 1037 message = `Error spawning worker for ${uri}`; | 1037 message = `Error spawning worker for ${uri}`; |
| 1038 } else { | 1038 } else { |
| 1039 message = `Error spawning worker for ${uri} (${message})`; | 1039 message = `Error spawning worker for ${uri} (${message})`; |
| 1040 } | 1040 } |
| 1041 onError(message); | 1041 onError(message); |
| 1042 return true; | 1042 return true; |
| 1043 } | 1043 } |
| 1044 } | 1044 } |
| 1045 IsolateNatives.enableSpawnWorker = null; | 1045 IsolateNatives.enableSpawnWorker = null; |
| 1046 dart.defineLazyProperties(IsolateNatives, { | 1046 dart.defineLazyProperties(IsolateNatives, { |
| 1047 get thisScript() { | 1047 get thisScript() { |
| 1048 return computeThisScript(); | 1048 return IsolateNatives.computeThisScript(); |
| 1049 }, | 1049 }, |
| 1050 set thisScript(_) {}, | 1050 set thisScript(_) {}, |
| 1051 get workerIds() { | 1051 get workerIds() { |
| 1052 return new core.Expando(); | 1052 return new core.Expando(); |
| 1053 } | 1053 } |
| 1054 }); | 1054 }); |
| 1055 let _checkReplyTo = Symbol('_checkReplyTo'); | 1055 let _checkReplyTo = Symbol('_checkReplyTo'); |
| 1056 class _BaseSendPort extends core.Object { | 1056 class _BaseSendPort extends core.Object { |
| 1057 _BaseSendPort(isolateId$) { | 1057 _BaseSendPort(isolateId$) { |
| 1058 this[_isolateId] = isolateId$; | 1058 this[_isolateId] = isolateId$; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 } | 1111 } |
| 1112 } | 1112 } |
| 1113 ['=='](other) { | 1113 ['=='](other) { |
| 1114 return dart.notNull(dart.is(other, _WorkerSendPort)) && this[_workerId] ==
= dart.dload(other, '_workerId') && this[_isolateId] === dart.dload(other, '_iso
lateId') && this[_receivePortId] === dart.dload(other, '_receivePortId'); | 1114 return dart.notNull(dart.is(other, _WorkerSendPort)) && this[_workerId] ==
= dart.dload(other, '_workerId') && this[_isolateId] === dart.dload(other, '_iso
lateId') && this[_receivePortId] === dart.dload(other, '_receivePortId'); |
| 1115 } | 1115 } |
| 1116 get hashCode() { | 1116 get hashCode() { |
| 1117 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); | 1117 return dart.notNull(this[_workerId]) << 16 ^ dart.notNull(this[_isolateId]
) << 8 ^ dart.notNull(this[_receivePortId]); |
| 1118 } | 1118 } |
| 1119 } | 1119 } |
| 1120 let _handler = Symbol('_handler'); | 1120 let _handler = Symbol('_handler'); |
| 1121 let _nextFreeId = Symbol('_nextFreeId'); |
| 1121 let _close = Symbol('_close'); | 1122 let _close = Symbol('_close'); |
| 1122 let _add = Symbol('_add'); | 1123 let _add = Symbol('_add'); |
| 1124 let _controlPort = Symbol('_controlPort'); |
| 1123 class RawReceivePortImpl extends core.Object { | 1125 class RawReceivePortImpl extends core.Object { |
| 1124 RawReceivePortImpl(handler) { | 1126 RawReceivePortImpl(handler) { |
| 1125 this[_handler] = handler; | 1127 this[_handler] = handler; |
| 1126 this[_id] = ((x$) => _nextFreeId = dart.notNull(x$) + 1, x$)(_nextFreeId); | 1128 this[_id] = ((x$) => RawReceivePortImpl[_nextFreeId] = dart.notNull(x$) +
1, x$)(RawReceivePortImpl[_nextFreeId]); |
| 1127 this[_isClosed] = false; | 1129 this[_isClosed] = false; |
| 1128 exports._globalState.currentContext.register(this[_id], this); | 1130 exports._globalState.currentContext.register(this[_id], this); |
| 1129 } | 1131 } |
| 1130 RawReceivePortImpl$weak(handler) { | 1132 RawReceivePortImpl$weak(handler) { |
| 1131 this[_handler] = handler; | 1133 this[_handler] = handler; |
| 1132 this[_id] = ((x$) => _nextFreeId = dart.notNull(x$) + 1, x$)(_nextFreeId); | 1134 this[_id] = ((x$) => RawReceivePortImpl[_nextFreeId] = dart.notNull(x$) +
1, x$)(RawReceivePortImpl[_nextFreeId]); |
| 1133 this[_isClosed] = false; | 1135 this[_isClosed] = false; |
| 1134 exports._globalState.currentContext.registerWeak(this[_id], this); | 1136 exports._globalState.currentContext.registerWeak(this[_id], this); |
| 1135 } | 1137 } |
| 1136 RawReceivePortImpl$_controlPort() { | 1138 RawReceivePortImpl$_controlPort() { |
| 1137 this[_handler] = null; | 1139 this[_handler] = null; |
| 1138 this[_id] = 0; | 1140 this[_id] = 0; |
| 1139 this[_isClosed] = false; | 1141 this[_isClosed] = false; |
| 1140 } | 1142 } |
| 1141 set handler(newHandler) { | 1143 set handler(newHandler) { |
| 1142 this[_handler] = newHandler; | 1144 this[_handler] = newHandler; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1155 [_add](dataEvent) { | 1157 [_add](dataEvent) { |
| 1156 if (this[_isClosed]) | 1158 if (this[_isClosed]) |
| 1157 return; | 1159 return; |
| 1158 dart.dinvokef(this[_handler], dataEvent); | 1160 dart.dinvokef(this[_handler], dataEvent); |
| 1159 } | 1161 } |
| 1160 get sendPort() { | 1162 get sendPort() { |
| 1161 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; | 1163 return new _NativeJsSendPort(this, exports._globalState.currentContext.id)
; |
| 1162 } | 1164 } |
| 1163 } | 1165 } |
| 1164 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); | 1166 dart.defineNamedConstructor(RawReceivePortImpl, 'weak'); |
| 1165 dart.defineNamedConstructor(RawReceivePortImpl, '_controlPort'); | 1167 dart.defineNamedConstructor(RawReceivePortImpl, _controlPort); |
| 1166 RawReceivePortImpl._nextFreeId = 1; | 1168 RawReceivePortImpl._nextFreeId = 1; |
| 1167 let _rawPort = Symbol('_rawPort'); | 1169 let _rawPort = Symbol('_rawPort'); |
| 1168 let _controller = Symbol('_controller'); | 1170 let _controller = Symbol('_controller'); |
| 1169 class ReceivePortImpl extends async.Stream { | 1171 class ReceivePortImpl extends async.Stream { |
| 1170 ReceivePortImpl() { | 1172 ReceivePortImpl() { |
| 1171 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); | 1173 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl(null)); |
| 1172 } | 1174 } |
| 1173 ReceivePortImpl$weak() { | 1175 ReceivePortImpl$weak() { |
| 1174 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl.weak(null))
; | 1176 this.ReceivePortImpl$fromRawReceivePort(new RawReceivePortImpl.weak(null))
; |
| 1175 } | 1177 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 get isActive() { | 1263 get isActive() { |
| 1262 return this[_handle] !== null; | 1264 return this[_handle] !== null; |
| 1263 } | 1265 } |
| 1264 } | 1266 } |
| 1265 dart.defineNamedConstructor(TimerImpl, 'periodic'); | 1267 dart.defineNamedConstructor(TimerImpl, 'periodic'); |
| 1266 // Function hasTimer: () → bool | 1268 // Function hasTimer: () → bool |
| 1267 function hasTimer() { | 1269 function hasTimer() { |
| 1268 _js_helper.requiresPreamble(); | 1270 _js_helper.requiresPreamble(); |
| 1269 return self.setTimeout !== null; | 1271 return self.setTimeout !== null; |
| 1270 } | 1272 } |
| 1273 let _internal = Symbol('_internal'); |
| 1271 class CapabilityImpl extends core.Object { | 1274 class CapabilityImpl extends core.Object { |
| 1272 CapabilityImpl() { | 1275 CapabilityImpl() { |
| 1273 this.CapabilityImpl$_internal(_js_helper.random64()); | 1276 this.CapabilityImpl$_internal(_js_helper.random64()); |
| 1274 } | 1277 } |
| 1275 CapabilityImpl$_internal(id) { | 1278 CapabilityImpl$_internal(id) { |
| 1276 this[_id] = id; | 1279 this[_id] = id; |
| 1277 } | 1280 } |
| 1278 get hashCode() { | 1281 get hashCode() { |
| 1279 let hash = this[_id]; | 1282 let hash = this[_id]; |
| 1280 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296).truncat
e(); | 1283 hash = dart.notNull(hash) >> 0 ^ (dart.notNull(hash) / 4294967296).truncat
e(); |
| 1281 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295; | 1284 hash = ~dart.notNull(hash) + (dart.notNull(hash) << 15) & 4294967295; |
| 1282 hash = dart.notNull(hash) >> 12; | 1285 hash = dart.notNull(hash) >> 12; |
| 1283 hash = dart.notNull(hash) * 5 & 4294967295; | 1286 hash = dart.notNull(hash) * 5 & 4294967295; |
| 1284 hash = dart.notNull(hash) >> 4; | 1287 hash = dart.notNull(hash) >> 4; |
| 1285 hash = dart.notNull(hash) * 2057 & 4294967295; | 1288 hash = dart.notNull(hash) * 2057 & 4294967295; |
| 1286 hash = dart.notNull(hash) >> 16; | 1289 hash = dart.notNull(hash) >> 16; |
| 1287 return hash; | 1290 return hash; |
| 1288 } | 1291 } |
| 1289 ['=='](other) { | 1292 ['=='](other) { |
| 1290 if (core.identical(other, this)) | 1293 if (core.identical(other, this)) |
| 1291 return true; | 1294 return true; |
| 1292 if (dart.is(other, CapabilityImpl)) { | 1295 if (dart.is(other, CapabilityImpl)) { |
| 1293 return core.identical(this[_id], other[_id]); | 1296 return core.identical(this[_id], other[_id]); |
| 1294 } | 1297 } |
| 1295 return false; | 1298 return false; |
| 1296 } | 1299 } |
| 1297 } | 1300 } |
| 1298 dart.defineNamedConstructor(CapabilityImpl, '_internal'); | 1301 dart.defineNamedConstructor(CapabilityImpl, _internal); |
| 1299 // Exports: | 1302 // Exports: |
| 1300 exports.enterJsAsync = enterJsAsync; | 1303 exports.enterJsAsync = enterJsAsync; |
| 1301 exports.leaveJsAsync = leaveJsAsync; | 1304 exports.leaveJsAsync = leaveJsAsync; |
| 1302 exports.isWorker = isWorker; | 1305 exports.isWorker = isWorker; |
| 1303 exports.startRootIsolate = startRootIsolate; | 1306 exports.startRootIsolate = startRootIsolate; |
| 1304 exports.IsolateNatives = IsolateNatives; | 1307 exports.IsolateNatives = IsolateNatives; |
| 1305 exports.RawReceivePortImpl = RawReceivePortImpl; | 1308 exports.RawReceivePortImpl = RawReceivePortImpl; |
| 1306 exports.ReceivePortImpl = ReceivePortImpl; | 1309 exports.ReceivePortImpl = ReceivePortImpl; |
| 1307 exports.TimerImpl = TimerImpl; | 1310 exports.TimerImpl = TimerImpl; |
| 1308 exports.hasTimer = hasTimer; | 1311 exports.hasTimer = hasTimer; |
| 1309 exports.CapabilityImpl = CapabilityImpl; | 1312 exports.CapabilityImpl = CapabilityImpl; |
| 1310 })(_isolate_helper || (_isolate_helper = {})); | 1313 })(_isolate_helper || (_isolate_helper = {})); |
| OLD | NEW |