Index: sdk/lib/_internal/compiler/js_lib/isolate_helper.dart |
diff --git a/sdk/lib/_internal/compiler/js_lib/isolate_helper.dart b/sdk/lib/_internal/compiler/js_lib/isolate_helper.dart |
index 9d36be556b0a7ccc5a975e2c32ba2908ade7862a..6f3e3611ded95104da05c24ec0659f54c6b6021f 100644 |
--- a/sdk/lib/_internal/compiler/js_lib/isolate_helper.dart |
+++ b/sdk/lib/_internal/compiler/js_lib/isolate_helper.dart |
@@ -311,7 +311,7 @@ class _IsolateContext implements IsolateContext { |
List<_IsolateEvent> delayedEvents = []; |
Set<Capability> pauseTokens = new Set(); |
- // Container with the "on exit" handler send-ports. |
+ // Container with the "on exit" handler send-ports and responses. |
var doneHandlers; |
/** |
@@ -355,14 +355,12 @@ class _IsolateContext implements IsolateContext { |
_updateGlobalState(); |
} |
- void addDoneListener(SendPort responsePort) { |
+ void addDoneListener(SendPort responsePort, Object response) { |
if (doneHandlers == null) { |
- doneHandlers = []; |
+ // TODO(lrn): Use map optimized for few keys. |
+ doneHandlers = new HashMap(); |
} |
- // If necessary, we can switch doneHandlers to a Set if it gets larger. |
- // That is not expected to happen in practice. |
- if (doneHandlers.contains(responsePort)) return; |
- doneHandlers.add(responsePort); |
+ doneHandlers[responsePort] = response; |
} |
void removeDoneListener(SendPort responsePort) { |
@@ -375,18 +373,14 @@ class _IsolateContext implements IsolateContext { |
this.errorsAreFatal = errorsAreFatal; |
} |
- void handlePing(SendPort responsePort, int pingType) { |
+ void handlePing(SendPort responsePort, int pingType, Object response) { |
if (pingType == Isolate.IMMEDIATE || |
(pingType == Isolate.BEFORE_NEXT_EVENT && |
!_isExecutingEvent)) { |
- responsePort.send(null); |
- return; |
- } |
- void respond() { responsePort.send(null); } |
- if (pingType == Isolate.AS_EVENT) { |
- _globalState.topEventLoop.enqueue(this, respond, "ping"); |
+ responsePort.send(response); |
return; |
} |
+ void respond() { responsePort.send(response); } |
assert(pingType == Isolate.BEFORE_NEXT_EVENT); |
if (_scheduledControlEvents == null) { |
_scheduledControlEvents = new Queue(); |
@@ -402,10 +396,6 @@ class _IsolateContext implements IsolateContext { |
kill(); |
return; |
} |
- if (priority == Isolate.AS_EVENT) { |
- _globalState.topEventLoop.enqueue(this, kill, "kill"); |
- return; |
- } |
assert(priority == Isolate.BEFORE_NEXT_EVENT); |
if (_scheduledControlEvents == null) { |
_scheduledControlEvents = new Queue(); |
@@ -499,7 +489,7 @@ class _IsolateContext implements IsolateContext { |
removePause(message[1]); |
break; |
case 'add-ondone': |
- addDoneListener(message[1]); |
+ addDoneListener(message[1], message[2]); |
break; |
case 'remove-ondone': |
removeDoneListener(message[1]); |
@@ -508,7 +498,7 @@ class _IsolateContext implements IsolateContext { |
setErrorsFatal(message[1], message[2]); |
break; |
case "ping": |
- handlePing(message[1], message[2]); |
+ handlePing(message[1], message[2], message[3]); |
break; |
case "kill": |
handleKill(message[1], message[2]); |
@@ -574,9 +564,7 @@ class _IsolateContext implements IsolateContext { |
_globalState.isolates.remove(id); // indicate this isolate is not active |
errorPorts.clear(); |
if (doneHandlers != null) { |
- for (SendPort port in doneHandlers) { |
- port.send(null); |
- } |
+ doneHandlers.forEach((port, response) { port.send(response); }); |
doneHandlers = null; |
} |
} |