Chromium Code Reviews| Index: sdk/lib/_internal/lib/isolate_helper.dart |
| diff --git a/sdk/lib/_internal/lib/isolate_helper.dart b/sdk/lib/_internal/lib/isolate_helper.dart |
| index cd3ee4ad56d5108a7bea28b98c0d61e420773756..90b929931eb018f11b8a58569a92f12eb747d0fe 100644 |
| --- a/sdk/lib/_internal/lib/isolate_helper.dart |
| +++ b/sdk/lib/_internal/lib/isolate_helper.dart |
| @@ -554,10 +554,12 @@ class IsolateNatives { |
| var args = msg['args']; |
| var message = _deserializeMessage(msg['msg']); |
| var isSpawnUri = msg['isSpawnUri']; |
| + var startPaused = msg['startPaused']; |
| var replyTo = _deserializeMessage(msg['replyTo']); |
| var context = new _IsolateContext(); |
| _globalState.topEventLoop.enqueue(context, () { |
| - _startIsolate(entryPoint, args, message, isSpawnUri, 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 |
| @@ -571,7 +573,8 @@ class IsolateNatives { |
| case 'spawn-worker': |
| _spawnWorker(msg['functionName'], msg['uri'], |
| msg['args'], msg['msg'], |
| - msg['isSpawnUri'], msg['replyPort']); |
| + msg['isSpawnUri'], msg['startPaused'], |
| + msg['replyPort']); |
| break; |
| case 'message': |
| SendPort port = msg['port']; |
| @@ -639,17 +642,24 @@ class IsolateNatives { |
| } |
| static Future<List> spawnFunction(void topLevelFunction(message), |
| - message) { |
| + var message, |
| + bool startPaused) { |
| final name = _getJSFunctionName(topLevelFunction); |
| if (name == null) { |
| throw new UnsupportedError( |
| "only top-level functions can be spawned."); |
| } |
| - return spawn(name, null, null, message, false, false); |
| + bool isLight = false; |
| + bool isSpawnUri = false; |
| + return spawn(name, null, null, message, isLight, isSpawnUri, startPaused); |
| } |
| - static Future<List> spawnUri(Uri uri, List<String> args, message) { |
| - return spawn(null, uri.toString(), args, message, false, true); |
| + static Future<List> spawnUri(Uri uri, List<String> args, var message, |
| + bool startPaused) { |
| + bool isLight = false; |
| + bool isSpawnUri = true; |
| + return spawn(null, uri.toString(), args, message, |
| + isLight, isSpawnUri, startPaused); |
| } |
| // TODO(sigmund): clean up above, after we make the new API the default: |
| @@ -657,7 +667,7 @@ class IsolateNatives { |
| /// 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 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. |
| @@ -672,10 +682,12 @@ class IsolateNatives { |
| SendPort signalReply = port.sendPort; |
| if (_globalState.useWorkers && !isLight) { |
| - _startWorker(functionName, uri, args, message, isSpawnUri, signalReply); |
| + _startWorker(functionName, uri, args, message, isSpawnUri, startPaused, |
| + signalReply); |
| } else { |
| _startNonWorker( |
| - functionName, uri, args, message, isSpawnUri, signalReply); |
| + functionName, uri, args, message, isSpawnUri, startPaused, |
| + signalReply); |
| } |
| return result; |
| } |
| @@ -684,6 +696,7 @@ class IsolateNatives { |
| String functionName, String uri, |
| List<String> args, message, |
| bool isSpawnUri, |
| + bool startPaused, |
| SendPort replyPort) { |
| if (_globalState.isWorker) { |
| _globalState.mainManager.postMessage(_serializeMessage({ |
| @@ -693,16 +706,19 @@ class IsolateNatives { |
| 'msg': message, |
| 'uri': uri, |
| 'isSpawnUri': isSpawnUri, |
| + 'startPaused': startPaused, |
| 'replyPort': replyPort})); |
| } else { |
| - _spawnWorker(functionName, uri, args, message, isSpawnUri, replyPort); |
| + _spawnWorker(functionName, uri, args, message, |
| + isSpawnUri, startPaused, replyPort); |
| } |
| } |
| static void _startNonWorker( |
| String functionName, String uri, |
| - List<String> args, message, |
| + List<String> args, var message, |
| bool isSpawnUri, |
| + bool startPaused, |
| SendPort replyPort) { |
| // TODO(eub): support IE9 using an iframe -- Dart issue 1702. |
| if (uri != null) { |
| @@ -711,13 +727,14 @@ class IsolateNatives { |
| } |
| _globalState.topEventLoop.enqueue(new _IsolateContext(), () { |
| final func = _getJSFunctionFromName(functionName); |
| - _startIsolate(func, args, message, isSpawnUri, replyPort); |
| + _startIsolate(func, args, message, isSpawnUri, startPaused, replyPort); |
| }, 'nonworker start'); |
| } |
| 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); |
| @@ -725,14 +742,23 @@ class IsolateNatives { |
| replyTo.send([_SPAWNED_SIGNAL, |
| context.controlPort.sendPort, |
| context.pauseCapability]); |
| - if (!isSpawnUri) { |
| - topLevel(message); |
| - } else if (topLevel is _MainFunctionArgsMessage) { |
| - topLevel(args, message); |
| - } else if (topLevel is _MainFunctionArgs) { |
| - topLevel(args); |
| + void runStartFunction() { |
|
floitsch
2014/02/14 14:21:38
new line before and after nested function.
Lasse Reichstein Nielsen
2014/02/18 08:13:36
Done.
|
| + if (!isSpawnUri) { |
| + topLevel(message); |
| + } else if (topLevel is _MainFunctionArgsMessage) { |
| + topLevel(args, message); |
| + } else if (topLevel is _MainFunctionArgs) { |
| + topLevel(args); |
| + } else { |
| + topLevel(); |
| + } |
| + } |
| + if (startPaused) { |
| + context.addPause(context.pauseCapability, context.pauseCapability); |
| + _globalState.topEventLoop.enqueue(context, runStartFunction, |
| + 'start isolate'); |
| } else { |
| - topLevel(); |
| + runStartFunction(); |
| } |
| } |
| @@ -743,6 +769,7 @@ class IsolateNatives { |
| static void _spawnWorker(functionName, String uri, |
| List<String> args, message, |
| bool isSpawnUri, |
| + bool startPaused, |
| SendPort replyPort) { |
| if (uri == null) uri = thisScript; |
| final worker = JS('var', 'new Worker(#)', uri); |
| @@ -767,6 +794,7 @@ class IsolateNatives { |
| 'args': args, |
| 'msg': _serializeMessage(message), |
| 'isSpawnUri': isSpawnUri, |
| + 'startPaused': startPaused, |
| 'functionName': functionName })); |
| } |
| } |