| Index: sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
|
| diff --git a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
|
| index 18da81df1d6d1ad555502b35ec69f4bb68442f7b..d66b967b44efd8cbb4fb464c58d3fd7d11686d83 100644
|
| --- a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
|
| +++ b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
|
| @@ -4,45 +4,50 @@
|
|
|
| library _isolate_helper;
|
|
|
| -import 'dart:_js_embedded_names' show
|
| - CLASS_ID_EXTRACTOR,
|
| - CLASS_FIELDS_EXTRACTOR,
|
| - CREATE_NEW_ISOLATE,
|
| - CURRENT_SCRIPT,
|
| - INITIALIZE_EMPTY_INSTANCE,
|
| - INSTANCE_FROM_CLASS_ID,
|
| - STATIC_FUNCTION_NAME_PROPERTY_NAME;
|
| +import 'dart:_js_embedded_names'
|
| + show
|
| + CLASS_ID_EXTRACTOR,
|
| + CLASS_FIELDS_EXTRACTOR,
|
| + CREATE_NEW_ISOLATE,
|
| + CURRENT_SCRIPT,
|
| + INITIALIZE_EMPTY_INSTANCE,
|
| + INSTANCE_FROM_CLASS_ID,
|
| + STATIC_FUNCTION_NAME_PROPERTY_NAME;
|
|
|
| import 'dart:async';
|
| import 'dart:collection' show Queue;
|
| import 'dart:isolate';
|
| import 'dart:_native_typed_data' show NativeByteBuffer, NativeTypedData;
|
|
|
| -import 'dart:_js_helper' show
|
| - Closure,
|
| - InternalMap,
|
| - Primitives,
|
| - convertDartClosureToJS,
|
| - createDartClosureFromNameOfStaticFunction,
|
| - isDartObject,
|
| - random64,
|
| - requiresPreamble;
|
| -
|
| -import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS,
|
| - JS,
|
| - JS_CURRENT_ISOLATE_CONTEXT,
|
| - JS_EMBEDDED_GLOBAL,
|
| - JS_SET_STATIC_STATE,
|
| - IsolateContext;
|
| -
|
| -import 'dart:_interceptors' show Interceptor,
|
| - JSArray,
|
| - JSExtendableArray,
|
| - JSFixedArray,
|
| - JSIndexable,
|
| - JSMutableArray,
|
| - JSObject;
|
| -
|
| +import 'dart:_js_helper'
|
| + show
|
| + Closure,
|
| + InternalMap,
|
| + Primitives,
|
| + convertDartClosureToJS,
|
| + createDartClosureFromNameOfStaticFunction,
|
| + isDartObject,
|
| + random64,
|
| + requiresPreamble;
|
| +
|
| +import 'dart:_foreign_helper'
|
| + show
|
| + DART_CLOSURE_TO_JS,
|
| + JS,
|
| + JS_CURRENT_ISOLATE_CONTEXT,
|
| + JS_EMBEDDED_GLOBAL,
|
| + JS_SET_STATIC_STATE,
|
| + IsolateContext;
|
| +
|
| +import 'dart:_interceptors'
|
| + show
|
| + Interceptor,
|
| + JSArray,
|
| + JSExtendableArray,
|
| + JSFixedArray,
|
| + JSIndexable,
|
| + JSMutableArray,
|
| + JSObject;
|
|
|
| part 'isolate_serialization.dart';
|
|
|
| @@ -113,9 +118,13 @@ void startRootIsolate(entry, args) {
|
| // by having a "default" isolate (the first one created).
|
| _globalState.currentContext = rootContext;
|
| if (entry is _MainFunctionArgs) {
|
| - rootContext.eval(() { entry(args); });
|
| + rootContext.eval(() {
|
| + entry(args);
|
| + });
|
| } else if (entry is _MainFunctionArgsMessage) {
|
| - rootContext.eval(() { entry(args, null); });
|
| + rootContext.eval(() {
|
| + entry(args, null);
|
| + });
|
| } else {
|
| rootContext.eval(entry);
|
| }
|
| @@ -165,7 +174,6 @@ set _globalState(_Manager val) {
|
| /** State associated with the current manager. See [globalState]. */
|
| // TODO(sigmund): split in multiple classes: global, thread, main-worker states?
|
| class _Manager {
|
| -
|
| /** Next available isolate id within this [_Manager]. */
|
| int nextIsolateId = 0;
|
|
|
| @@ -213,7 +221,7 @@ class _Manager {
|
| _MainManagerStub mainManager;
|
|
|
| /// Registry of active Web Workers. Only used in the main [_Manager].
|
| - Map<int, dynamic /* Worker */> managers;
|
| + Map<int, dynamic /* Worker */ > managers;
|
|
|
| /** The entry point given by [startRootIsolate]. */
|
| final Function entry;
|
| @@ -225,7 +233,8 @@ class _Manager {
|
| topEventLoop = new _EventLoop();
|
| isolates = new Map<int, _IsolateContext>();
|
| managers = new Map<int, dynamic>();
|
| - if (isWorker) { // "if we are not the main manager ourself" is the intent.
|
| + if (isWorker) {
|
| + // "if we are not the main manager ourself" is the intent.
|
| mainManager = new _MainManagerStub();
|
| _nativeInitWorkerMessageHandler();
|
| }
|
| @@ -238,20 +247,23 @@ class _Manager {
|
| // `isWorker` must be initialized now, since `IsolateNatives.thisScript`
|
| // may access it.
|
| isWorker = !isWindowDefined && globalPostMessageDefined;
|
| - supportsWorkers = isWorker
|
| - || (isWorkerDefined && IsolateNatives.thisScript != null);
|
| + supportsWorkers =
|
| + isWorker || (isWorkerDefined && IsolateNatives.thisScript != null);
|
| fromCommandLine = !isWindowDefined && !isWorker;
|
| }
|
|
|
| void _nativeInitWorkerMessageHandler() {
|
| - var function = JS('',
|
| + var function = JS(
|
| + '',
|
| "(function (f, a) { return function (e) { f(a, e); }})(#, #)",
|
| DART_CLOSURE_TO_JS(IsolateNatives._processWorkerMessage),
|
| mainManager);
|
| JS("void", r"self.onmessage = #", function);
|
| // We ensure dartPrint is defined so that the implementation of the Dart
|
| // print method knows what to call.
|
| - JS('', '''self.dartPrint = self.dartPrint || (function(serialize) {
|
| + JS(
|
| + '',
|
| + '''self.dartPrint = self.dartPrint || (function(serialize) {
|
| return function (object) {
|
| if (self.console && self.console.log) {
|
| self.console.log(object)
|
| @@ -259,7 +271,8 @@ class _Manager {
|
| self.postMessage(serialize(object));
|
| }
|
| }
|
| -})(#)''', DART_CLOSURE_TO_JS(_serializePrintMessage));
|
| +})(#)''',
|
| + DART_CLOSURE_TO_JS(_serializePrintMessage));
|
| }
|
|
|
| static _serializePrintMessage(object) {
|
| @@ -271,9 +284,7 @@ class _Manager {
|
| * there are no active async JavaScript tasks still running.
|
| */
|
| void maybeCloseWorker() {
|
| - if (isWorker
|
| - && isolates.isEmpty
|
| - && topEventLoop._activeJsAsyncCount == 0) {
|
| + if (isWorker && isolates.isEmpty && topEventLoop._activeJsAsyncCount == 0) {
|
| mainManager.postMessage(_serializeMessage({'command': 'close'}));
|
| }
|
| }
|
| @@ -298,7 +309,7 @@ class _IsolateContext implements IsolateContext {
|
| final RawReceivePortImpl controlPort = new RawReceivePortImpl._controlPort();
|
|
|
| final Capability pauseCapability = new Capability();
|
| - final Capability terminateCapability = new Capability(); // License to kill.
|
| + final Capability terminateCapability = new Capability(); // License to kill.
|
|
|
| /// Boolean flag set when the initial method of the isolate has been executed.
|
| ///
|
| @@ -348,7 +359,7 @@ class _IsolateContext implements IsolateContext {
|
| if (!isPaused) return;
|
| pauseTokens.remove(resume);
|
| if (pauseTokens.isEmpty) {
|
| - while(delayedEvents.isNotEmpty) {
|
| + while (delayedEvents.isNotEmpty) {
|
| _IsolateEvent event = delayedEvents.removeLast();
|
| _globalState.topEventLoop.prequeue(event);
|
| }
|
| @@ -388,12 +399,14 @@ class _IsolateContext implements IsolateContext {
|
|
|
| void handlePing(SendPort responsePort, int pingType, Object response) {
|
| if (pingType == Isolate.IMMEDIATE ||
|
| - (pingType == Isolate.BEFORE_NEXT_EVENT &&
|
| - !_isExecutingEvent)) {
|
| + (pingType == Isolate.BEFORE_NEXT_EVENT && !_isExecutingEvent)) {
|
| responsePort.send(response);
|
| return;
|
| }
|
| - void respond() { responsePort.send(response); }
|
| + void respond() {
|
| + responsePort.send(response);
|
| + }
|
| +
|
| assert(pingType == Isolate.BEFORE_NEXT_EVENT);
|
| if (_scheduledControlEvents == null) {
|
| _scheduledControlEvents = new Queue();
|
| @@ -404,8 +417,7 @@ class _IsolateContext implements IsolateContext {
|
| void handleKill(Capability authentification, int priority) {
|
| if (this.terminateCapability != authentification) return;
|
| if (priority == Isolate.IMMEDIATE ||
|
| - (priority == Isolate.BEFORE_NEXT_EVENT &&
|
| - !_isExecutingEvent)) {
|
| + (priority == Isolate.BEFORE_NEXT_EVENT && !_isExecutingEvent)) {
|
| kill();
|
| return;
|
| }
|
| @@ -443,8 +455,8 @@ class _IsolateContext implements IsolateContext {
|
| return;
|
| }
|
| List message = new List(2)
|
| - ..[0] = error.toString()
|
| - ..[1] = (stackTrace == null) ? null : stackTrace.toString();
|
| + ..[0] = error.toString()
|
| + ..[1] = (stackTrace == null) ? null : stackTrace.toString();
|
| for (SendPort port in errorPorts) port.send(message);
|
| }
|
|
|
| @@ -537,7 +549,7 @@ class _IsolateContext implements IsolateContext {
|
| }
|
|
|
| /** Registers a port on this isolate. */
|
| - void register(int portId, RawReceivePortImpl port) {
|
| + void register(int portId, RawReceivePortImpl port) {
|
| _addRegistration(portId, port);
|
| _updateGlobalState();
|
| }
|
| @@ -547,7 +559,7 @@ class _IsolateContext implements IsolateContext {
|
| *
|
| * The port does not keep the isolate active.
|
| */
|
| - void registerWeak(int portId, RawReceivePortImpl port) {
|
| + void registerWeak(int portId, RawReceivePortImpl port) {
|
| weakPorts.add(portId);
|
| _addRegistration(portId, port);
|
| }
|
| @@ -622,10 +634,10 @@ class _EventLoop {
|
| }
|
|
|
| void checkOpenReceivePortsFromCommandLine() {
|
| - if (_globalState.rootContext != null
|
| - && _globalState.isolates.containsKey(_globalState.rootContext.id)
|
| - && _globalState.fromCommandLine
|
| - && _globalState.rootContext.ports.isEmpty) {
|
| + if (_globalState.rootContext != null &&
|
| + _globalState.isolates.containsKey(_globalState.rootContext.id) &&
|
| + _globalState.fromCommandLine &&
|
| + _globalState.rootContext.ports.isEmpty) {
|
| // We want to reach here only on the main [_Manager] and only
|
| // on the command-line. In the browser the isolate might
|
| // still be alive due to DOM callbacks, but the presumption is
|
| @@ -660,6 +672,7 @@ class _EventLoop {
|
| if (!runIteration()) return;
|
| Timer.run(next);
|
| }
|
| +
|
| next();
|
| } else {
|
| // Run synchronously until no more iterations are available.
|
| @@ -677,8 +690,8 @@ class _EventLoop {
|
| try {
|
| _runHelper();
|
| } catch (e, trace) {
|
| - _globalState.mainManager.postMessage(_serializeMessage(
|
| - {'command': 'error', 'msg': '$e\n$trace' }));
|
| + _globalState.mainManager.postMessage(
|
| + _serializeMessage({'command': 'error', 'msg': '$e\n$trace'}));
|
| }
|
| }
|
| }
|
| @@ -727,6 +740,7 @@ get globalWorker {
|
| requiresPreamble();
|
| return JS('', "self.Worker");
|
| }
|
| +
|
| bool get globalPostMessageDefined {
|
| requiresPreamble();
|
| return JS('bool', "!!self.postMessage");
|
| @@ -739,7 +753,6 @@ typedef _MainFunctionArgsMessage(args, message);
|
| /// Note: IsolateNatives depends on _globalState which is only set up correctly
|
| /// when 'dart:isolate' has been imported.
|
| class IsolateNatives {
|
| -
|
| // We set [enableSpawnWorker] to true (not null) when calling isolate
|
| // primitives that require support for spawning workers. The field starts out
|
| // by being null, and dart2js' type inference will track if it can have a
|
| @@ -785,10 +798,11 @@ class IsolateNatives {
|
| // According to Internet Explorer documentation, the stack
|
| // property is not set until the exception is thrown. The stack
|
| // property was not provided until IE10.
|
| - stack = JS('String|Null',
|
| - '(function() {'
|
| - 'try { throw new Error() } catch(e) { return e.stack }'
|
| - '})()');
|
| + stack = JS(
|
| + 'String|Null',
|
| + '(function() {'
|
| + 'try { throw new Error() } catch(e) { return e.stack }'
|
| + '})()');
|
| if (stack == null) throw new UnsupportedError('No stack trace');
|
| }
|
| var pattern, matches;
|
| @@ -797,9 +811,8 @@ class IsolateNatives {
|
| // traces that look like this:
|
| // Error
|
| // at methodName (URI:LINE:COLUMN)
|
| - pattern = JS('',
|
| - r'new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m")');
|
| -
|
| + pattern =
|
| + JS('', r'new RegExp("^ *at [^(]*\\((.*):[0-9]*:[0-9]*\\)$", "m")');
|
|
|
| matches = JS('JSExtendableArray|Null', '#.match(#)', stack, pattern);
|
| if (matches != null) return JS('String', '#[1]', matches);
|
| @@ -841,8 +854,8 @@ class IsolateNatives {
|
| var replyTo = _deserializeMessage(msg['replyTo']);
|
| var context = new _IsolateContext();
|
| _globalState.topEventLoop.enqueue(context, () {
|
| - _startIsolate(entryPoint, args, message,
|
| - isSpawnUri, startPaused, replyTo);
|
| + _startIsolate(
|
| + entryPoint, args, message, isSpawnUri, startPaused, replyTo);
|
| }, 'worker-start');
|
| // Make sure we always have a current context in this worker.
|
| // TODO(7907): This is currently needed because we're using
|
| @@ -874,8 +887,8 @@ class IsolateNatives {
|
| break;
|
| case 'print':
|
| if (_globalState.isWorker) {
|
| - _globalState.mainManager.postMessage(
|
| - _serializeMessage({'command': 'print', 'msg': msg}));
|
| + _globalState.mainManager
|
| + .postMessage(_serializeMessage({'command': 'print', 'msg': msg}));
|
| } else {
|
| print(msg['msg']);
|
| }
|
| @@ -887,9 +900,8 @@ class IsolateNatives {
|
|
|
| static handleSpawnWorkerRequest(msg) {
|
| var replyPort = msg['replyPort'];
|
| - spawn(msg['functionName'], msg['uri'],
|
| - msg['args'], msg['msg'],
|
| - false, msg['isSpawnUri'], msg['startPaused']).then((msg) {
|
| + spawn(msg['functionName'], msg['uri'], msg['args'], msg['msg'], false,
|
| + msg['isSpawnUri'], msg['startPaused']).then((msg) {
|
| replyPort.send(msg);
|
| }, onError: (String errorMessage) {
|
| replyPort.send([_SPAWN_FAILED_SIGNAL, errorMessage]);
|
| @@ -899,8 +911,8 @@ class IsolateNatives {
|
| /** Log a message, forwarding to the main [_Manager] if appropriate. */
|
| static _log(msg) {
|
| if (_globalState.isWorker) {
|
| - _globalState.mainManager.postMessage(
|
| - _serializeMessage({'command': 'log', 'msg': msg }));
|
| + _globalState.mainManager
|
| + .postMessage(_serializeMessage({'command': 'log', 'msg': msg}));
|
| } else {
|
| try {
|
| _consoleLog(msg);
|
| @@ -935,35 +947,32 @@ class IsolateNatives {
|
| return JS("", "new #()", ctor);
|
| }
|
|
|
| - static Future<List> spawnFunction(void topLevelFunction(message),
|
| - var message,
|
| - bool startPaused) {
|
| + static Future<List> spawnFunction(
|
| + void topLevelFunction(message), var message, bool startPaused) {
|
| IsolateNatives.enableSpawnWorker = true;
|
| final name = _getJSFunctionName(topLevelFunction);
|
| if (name == null) {
|
| - throw new UnsupportedError(
|
| - "only top-level functions can be spawned.");
|
| + throw new UnsupportedError("only top-level functions can be spawned.");
|
| }
|
| bool isLight = false;
|
| bool isSpawnUri = false;
|
| return spawn(name, null, null, message, isLight, isSpawnUri, startPaused);
|
| }
|
|
|
| - static Future<List> spawnUri(Uri uri, List<String> args, var message,
|
| - bool startPaused) {
|
| + static Future<List> spawnUri(
|
| + Uri uri, List<String> args, var message, bool startPaused) {
|
| IsolateNatives.enableSpawnWorker = true;
|
| bool isLight = false;
|
| bool isSpawnUri = true;
|
| - return spawn(null, uri.toString(), args, message,
|
| - isLight, isSpawnUri, startPaused);
|
| + return spawn(
|
| + null, uri.toString(), args, message, isLight, isSpawnUri, startPaused);
|
| }
|
|
|
| // TODO(sigmund): clean up above, after we make the new API the default:
|
|
|
| /// If [uri] is `null` it is replaced with the current script.
|
| - static Future<List> spawn(String functionName, String uri,
|
| - List<String> args, message,
|
| - bool isLight, bool isSpawnUri, bool startPaused) {
|
| + static Future<List> spawn(String functionName, String uri, List<String> args,
|
| + message, bool isLight, bool isSpawnUri, bool startPaused) {
|
| // Assume that the compiled version of the Dart file lives just next to the
|
| // dart file.
|
| // TODO(floitsch): support precompiled version of dart2js output.
|
| @@ -983,20 +992,20 @@ class IsolateNatives {
|
| SendPort signalReply = port.sendPort;
|
|
|
| if (_globalState.useWorkers && !isLight) {
|
| - _startWorker(
|
| - functionName, uri, args, message, isSpawnUri, startPaused,
|
| + _startWorker(functionName, uri, args, message, isSpawnUri, startPaused,
|
| signalReply, (String message) => completer.completeError(message));
|
| } else {
|
| - _startNonWorker(
|
| - functionName, uri, args, message, isSpawnUri, startPaused,
|
| + _startNonWorker(functionName, uri, args, message, isSpawnUri, startPaused,
|
| signalReply);
|
| }
|
| return completer.future;
|
| }
|
|
|
| static void _startWorker(
|
| - String functionName, String uri,
|
| - List<String> args, message,
|
| + String functionName,
|
| + String uri,
|
| + List<String> args,
|
| + message,
|
| bool isSpawnUri,
|
| bool startPaused,
|
| SendPort replyPort,
|
| @@ -1007,23 +1016,26 @@ class IsolateNatives {
|
| if (args != null) args = new List<String>.from(args);
|
| if (_globalState.isWorker) {
|
| _globalState.mainManager.postMessage(_serializeMessage({
|
| - 'command': 'spawn-worker',
|
| - 'functionName': functionName,
|
| - 'args': args,
|
| - 'msg': message,
|
| - 'uri': uri,
|
| - 'isSpawnUri': isSpawnUri,
|
| - 'startPaused': startPaused,
|
| - 'replyPort': replyPort}));
|
| + 'command': 'spawn-worker',
|
| + 'functionName': functionName,
|
| + 'args': args,
|
| + 'msg': message,
|
| + 'uri': uri,
|
| + 'isSpawnUri': isSpawnUri,
|
| + 'startPaused': startPaused,
|
| + 'replyPort': replyPort
|
| + }));
|
| } else {
|
| - _spawnWorker(functionName, uri, args, message,
|
| - isSpawnUri, startPaused, replyPort, onError);
|
| + _spawnWorker(functionName, uri, args, message, isSpawnUri, startPaused,
|
| + replyPort, onError);
|
| }
|
| }
|
|
|
| static void _startNonWorker(
|
| - String functionName, String uri,
|
| - List<String> args, var message,
|
| + String functionName,
|
| + String uri,
|
| + List<String> args,
|
| + var message,
|
| bool isSpawnUri,
|
| bool startPaused,
|
| SendPort replyPort) {
|
| @@ -1048,22 +1060,21 @@ class IsolateNatives {
|
| static Isolate get currentIsolate {
|
| _IsolateContext context = JS_CURRENT_ISOLATE_CONTEXT();
|
| return new Isolate(context.controlPort.sendPort,
|
| - pauseCapability: context.pauseCapability,
|
| - terminateCapability: context.terminateCapability);
|
| + pauseCapability: context.pauseCapability,
|
| + terminateCapability: context.terminateCapability);
|
| }
|
|
|
| - static void _startIsolate(Function topLevel,
|
| - List<String> args, message,
|
| - bool isSpawnUri,
|
| - bool startPaused,
|
| - SendPort replyTo) {
|
| + static void _startIsolate(Function topLevel, List<String> args, message,
|
| + bool isSpawnUri, bool startPaused, SendPort replyTo) {
|
| _IsolateContext context = JS_CURRENT_ISOLATE_CONTEXT();
|
| Primitives.initializeStatics(context.id);
|
| // The isolate's port does not keep the isolate open.
|
| - replyTo.send([_SPAWNED_SIGNAL,
|
| - context.controlPort.sendPort,
|
| - context.pauseCapability,
|
| - context.terminateCapability]);
|
| + replyTo.send([
|
| + _SPAWNED_SIGNAL,
|
| + context.controlPort.sendPort,
|
| + context.pauseCapability,
|
| + context.terminateCapability
|
| + ]);
|
|
|
| void runStartFunction() {
|
| context.initialized = true;
|
| @@ -1081,8 +1092,8 @@ class IsolateNatives {
|
|
|
| if (startPaused) {
|
| context.addPause(context.pauseCapability, context.pauseCapability);
|
| - _globalState.topEventLoop.enqueue(context, runStartFunction,
|
| - 'start isolate');
|
| + _globalState.topEventLoop
|
| + .enqueue(context, runStartFunction, 'start isolate');
|
| } else {
|
| runStartFunction();
|
| }
|
| @@ -1092,12 +1103,15 @@ class IsolateNatives {
|
| * Spawns an isolate in a worker. [factoryName] is the Javascript constructor
|
| * name for the isolate entry point class.
|
| */
|
| - static void _spawnWorker(functionName, String uri,
|
| - List<String> args, message,
|
| - bool isSpawnUri,
|
| - bool startPaused,
|
| - SendPort replyPort,
|
| - void onError(String message)) {
|
| + static void _spawnWorker(
|
| + functionName,
|
| + String uri,
|
| + List<String> args,
|
| + message,
|
| + bool isSpawnUri,
|
| + bool startPaused,
|
| + SendPort replyPort,
|
| + void onError(String message)) {
|
| if (uri == null) uri = thisScript;
|
| final worker = JS('var', 'new Worker(#)', uri);
|
| // Trampolines are used when wanting to call a Dart closure from
|
| @@ -1112,7 +1126,9 @@ class IsolateNatives {
|
| return f(e, u, c)
|
| }
|
| })(#, #, #)''',
|
| - DART_CLOSURE_TO_JS(workerOnError), uri, onError);
|
| + DART_CLOSURE_TO_JS(workerOnError),
|
| + uri,
|
| + onError);
|
| JS('void', '#.onerror = #', worker, onerrorTrampoline);
|
|
|
| var processWorkerMessageTrampoline = JS(
|
| @@ -1133,19 +1149,24 @@ class IsolateNatives {
|
| // We also store the id on the worker itself so that we can unregister it.
|
| workerIds[worker] = workerId;
|
| _globalState.managers[workerId] = worker;
|
| - JS('void', '#.postMessage(#)', worker, _serializeMessage({
|
| - 'command': 'start',
|
| - 'id': workerId,
|
| - // Note: we serialize replyPort twice because the child worker needs to
|
| - // first deserialize the worker id, before it can correctly deserialize
|
| - // the port (port deserialization is sensitive to what is the current
|
| - // workerId).
|
| - 'replyTo': _serializeMessage(replyPort),
|
| - 'args': args,
|
| - 'msg': _serializeMessage(message),
|
| - 'isSpawnUri': isSpawnUri,
|
| - 'startPaused': startPaused,
|
| - 'functionName': functionName }));
|
| + JS(
|
| + 'void',
|
| + '#.postMessage(#)',
|
| + worker,
|
| + _serializeMessage({
|
| + 'command': 'start',
|
| + 'id': workerId,
|
| + // Note: we serialize replyPort twice because the child worker needs to
|
| + // first deserialize the worker id, before it can correctly deserialize
|
| + // the port (port deserialization is sensitive to what is the current
|
| + // workerId).
|
| + 'replyTo': _serializeMessage(replyPort),
|
| + 'args': args,
|
| + 'msg': _serializeMessage(message),
|
| + 'isSpawnUri': isSpawnUri,
|
| + 'startPaused': startPaused,
|
| + 'functionName': functionName
|
| + }));
|
| }
|
|
|
| static bool workerOnError(
|
| @@ -1180,9 +1201,9 @@ abstract class _BaseSendPort implements SendPort {
|
| const _BaseSendPort(this._isolateId);
|
|
|
| void _checkReplyTo(SendPort replyTo) {
|
| - if (replyTo != null
|
| - && replyTo is! _NativeJsSendPort
|
| - && replyTo is! _WorkerSendPort) {
|
| + if (replyTo != null &&
|
| + replyTo is! _NativeJsSendPort &&
|
| + replyTo is! _WorkerSendPort) {
|
| throw new Exception("SendPort.send: Illegal replyTo port type");
|
| }
|
| }
|
| @@ -1217,8 +1238,8 @@ class _NativeJsSendPort extends _BaseSendPort implements SendPort {
|
| }, 'receive');
|
| }
|
|
|
| - bool operator ==(var other) => (other is _NativeJsSendPort) &&
|
| - (_receivePort == other._receivePort);
|
| + bool operator ==(var other) =>
|
| + (other is _NativeJsSendPort) && (_receivePort == other._receivePort);
|
|
|
| int get hashCode => _receivePort._id;
|
| }
|
| @@ -1233,10 +1254,8 @@ class _WorkerSendPort extends _BaseSendPort implements SendPort {
|
| : super(isolateId);
|
|
|
| void send(var message) {
|
| - final workerMessage = _serializeMessage({
|
| - 'command': 'message',
|
| - 'port': this,
|
| - 'msg': message});
|
| + final workerMessage =
|
| + _serializeMessage({'command': 'message', 'port': this, 'msg': message});
|
|
|
| if (_globalState.isWorker) {
|
| // Communication from one worker to another go through the
|
| @@ -1282,7 +1301,9 @@ class RawReceivePortImpl implements RawReceivePort {
|
| // Creates the control port of an isolate.
|
| // This is created before the isolate context object itself,
|
| // so it cannot access the static _nextFreeId field.
|
| - RawReceivePortImpl._controlPort() : _handler = null, _id = 0;
|
| + RawReceivePortImpl._controlPort()
|
| + : _handler = null,
|
| + _id = 0;
|
|
|
| void set handler(Function newHandler) {
|
| _handler = newHandler;
|
| @@ -1327,11 +1348,9 @@ class ReceivePortImpl extends Stream implements ReceivePort {
|
| }
|
|
|
| StreamSubscription listen(void onData(var event),
|
| - {Function onError,
|
| - void onDone(),
|
| - bool cancelOnError}) {
|
| - return _controller.stream.listen(onData, onError: onError, onDone: onDone,
|
| - cancelOnError: cancelOnError);
|
| + {Function onError, void onDone(), bool cancelOnError}) {
|
| + return _controller.stream.listen(onData,
|
| + onError: onError, onDone: onDone, cancelOnError: cancelOnError);
|
| }
|
|
|
| void close() {
|
| @@ -1347,10 +1366,8 @@ class TimerImpl implements Timer {
|
| bool _inEventLoop = false;
|
| int _handle;
|
|
|
| - TimerImpl(int milliseconds, void callback())
|
| - : _once = true {
|
| + TimerImpl(int milliseconds, void callback()) : _once = true {
|
| if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) {
|
| -
|
| void internalCallback() {
|
| _handle = null;
|
| callback();
|
| @@ -1366,11 +1383,10 @@ class TimerImpl implements Timer {
|
| // TODO(7907): In case of web workers, we need to use the event
|
| // loop instead of setTimeout, to make sure the futures get executed in
|
| // order.
|
| - _globalState.topEventLoop.enqueue(
|
| - _globalState.currentContext, internalCallback, 'timer');
|
| + _globalState.topEventLoop
|
| + .enqueue(_globalState.currentContext, internalCallback, 'timer');
|
| _inEventLoop = true;
|
| } else if (hasTimer()) {
|
| -
|
| void internalCallback() {
|
| _handle = null;
|
| leaveJsAsync();
|
| @@ -1380,8 +1396,7 @@ class TimerImpl implements Timer {
|
| enterJsAsync();
|
|
|
| _handle = JS('int', 'self.setTimeout(#, #)',
|
| - convertDartClosureToJS(internalCallback, 0),
|
| - milliseconds);
|
| + convertDartClosureToJS(internalCallback, 0), milliseconds);
|
| } else {
|
| assert(milliseconds > 0);
|
| throw new UnsupportedError("Timer greater than 0.");
|
| @@ -1392,9 +1407,13 @@ class TimerImpl implements Timer {
|
| : _once = false {
|
| if (hasTimer()) {
|
| enterJsAsync();
|
| - _handle = JS('int', 'self.setInterval(#, #)',
|
| - convertDartClosureToJS(() { callback(this); }, 0),
|
| - milliseconds);
|
| + _handle = JS(
|
| + 'int',
|
| + 'self.setInterval(#, #)',
|
| + convertDartClosureToJS(() {
|
| + callback(this);
|
| + }, 0),
|
| + milliseconds);
|
| } else {
|
| throw new UnsupportedError("Periodic timer.");
|
| }
|
| @@ -1426,7 +1445,6 @@ bool hasTimer() {
|
| return JS('', 'self.setTimeout') != null;
|
| }
|
|
|
| -
|
| /**
|
| * Implementation class for [Capability].
|
| *
|
| @@ -1445,7 +1463,7 @@ class CapabilityImpl implements Capability {
|
| // http://www.concentric.net/~Ttwang/tech/inthash.htm
|
| // (via https://gist.github.com/badboy/6267743)
|
| int hash = _id;
|
| - hash = (hash >> 0) ^ (hash ~/ 0x100000000); // To 32 bit from ~64.
|
| + hash = (hash >> 0) ^ (hash ~/ 0x100000000); // To 32 bit from ~64.
|
| hash = (~hash + (hash << 15)) & 0xFFFFFFFF;
|
| hash ^= hash >> 12;
|
| hash = (hash * 5) & 0xFFFFFFFF;
|
| @@ -1455,7 +1473,7 @@ class CapabilityImpl implements Capability {
|
| return hash;
|
| }
|
|
|
| - bool operator==(Object other) {
|
| + bool operator ==(Object other) {
|
| if (identical(other, this)) return true;
|
| if (other is CapabilityImpl) {
|
| return identical(_id, other._id);
|
|
|