Implement new parameters on Isolate.spawn() for dart2js.

R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1294803003 .
This commit is contained in:
Lasse R.H. Nielsen 2015-08-19 13:52:36 +02:00
parent 73a6229d7c
commit f8f06d784a
4 changed files with 53 additions and 10 deletions

View file

@ -1069,6 +1069,7 @@ class IsolateNatives {
} else {
topLevel();
}
context._updateGlobalState();
}
if (startPaused) {

View file

@ -25,11 +25,35 @@ class Isolate {
static Future<Isolate> spawn(void entryPoint(message), var message,
{bool paused: false, bool errorsAreFatal,
SendPort onExit, SendPort onError}) {
bool forcePause = (errorsAreFatal != null) ||
(onExit != null) ||
(onError != null);
try {
return IsolateNatives.spawnFunction(entryPoint, message, paused)
.then((msg) => new Isolate(msg[1],
pauseCapability: msg[2],
terminateCapability: msg[3]));
// TODO: Consider passing the errorsAreFatal/onExit/onError values
// as arguments to the internal spawnUri instead of setting
// them after the isolate has been created.
return IsolateNatives.spawnFunction(entryPoint, message,
paused || forcePause)
.then((msg) {
var isolate = new Isolate(msg[1],
pauseCapability: msg[2],
terminateCapability: msg[3]);
if (forcePause) {
if (errorsAreFatal != null) {
isolate.setErrorsFatal(errorsAreFatal);
}
if (onExit != null) {
isolate.addOnExitListener(onExit);
}
if (onError != null) {
isolate.addErrorListener(onError);
}
if (!paused) {
isolate.resume(isolate.pauseCapability);
}
}
return isolate;
});
} catch (e, st) {
return new Future<Isolate>.error(e, st);
}
@ -70,7 +94,7 @@ class Isolate {
isolate.addOnExitListener(onExit);
}
if (onError != null) {
isolate.addOnErrorListener(onError);
isolate.addErrorListener(onError);
}
if (!paused) {
isolate.resume(isolate.pauseCapability);

View file

@ -9,19 +9,40 @@ import "dart:async";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
// Isolate exiting immediately.
isomain(args) {}
// Isolate exiting after running microtasks.
isomain2(args) {
scheduleMicrotask((){});
}
// Isolate exiting after running timers.
isomain3(args) {
new Timer(Duration.ZERO, (){});
}
main(){
asyncStart();
test(isomain);
test(isomain2);
test(isomain3);
asyncEnd();
}
void test(mainFunction) {
asyncStart();
RawReceivePort exitPort = new RawReceivePort();
exitPort.handler = (message) {
Expect.equals(null, message);
exitPort.close();
asyncEnd();
};
Isolate.spawn(isomain,
Isolate.spawn(mainFunction,
null,
// Setup handler as part of spawn.
errorsAreFatal: false,

View file

@ -55,9 +55,6 @@ message3_test/constMap: RuntimeError # Issue 21817
message3_test/constInstance: RuntimeError # Issue 21817
browser/issue_12474_test: CompileTimeError # Issue 22529
enum_const_test/02: RuntimeError # Issue 21817
error_exit_at_spawn_test: Fail # Issue 23876
error_at_spawn_test: Fail # Issue 23876
exit_at_spawn_test: Fail # Issue 23876
[ $compiler == dart2js && $runtime != d8 ]
error_exit_at_spawn_test: Skip # Issue 23876