blob: cbc617e36555d165f89806eed510f20479c53694 [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// VMOptions=--enable-isolate-groups
//
// Validates functionality of sendAndExit.
import 'dart:_internal' show sendAndExit;
import 'dart:async';
import 'dart:isolate';
import 'dart:nativewrappers';
import "package:expect/expect.dart";
doNothingWorker(data) {}
spawnWorker(worker, data) async {
Completer completer = Completer();
runZoned(() async {
final isolate = await Isolate.spawn(worker, [data]);
completer.complete(isolate);
}, onError: (e, st) => completer.complete(e));
return await completer.future;
}
verifyCantSendAnonymousClosure() async {
final result = await spawnWorker(doNothingWorker, () {});
Expect.equals(
"Invalid argument(s): Illegal argument in isolate message :"
" (object is a closure - Function '<anonymous closure>': static.)",
result.toString());
}
class NativeWrapperClass extends NativeFieldWrapperClass1 {}
verifyCantSendNative() async {
final result = await spawnWorker(doNothingWorker, NativeWrapperClass());
Expect.isTrue(result.toString().startsWith("Invalid argument(s): "
"Illegal argument in isolate message : "
"(object extends NativeWrapper"));
}
verifyCantSendRegexp() async {
var receivePort = ReceivePort();
final result = await spawnWorker(doNothingWorker, receivePort);
Expect.equals(
"Invalid argument(s): Illegal argument in isolate message : "
"(object is a ReceivePort)",
result.toString());
receivePort.close();
}
class Message {
SendPort sendPort;
Function closure;
Message(this.sendPort, this.closure);
}
add(a, b) => a + b;
worker(Message message) async {
final port = new ReceivePort();
final inbox = new StreamIterator<dynamic>(port);
message.sendPort.send(message.closure(2, 3));
port.close();
}
verifyCanSendStaticMethod() async {
final port = ReceivePort();
final inbox = StreamIterator<dynamic>(port);
final isolate = await Isolate.spawn(worker, Message(port.sendPort, add));
await inbox.moveNext();
Expect.equals(inbox.current, 5);
port.close();
}
main() async {
await verifyCantSendAnonymousClosure();
await verifyCantSendNative();
await verifyCantSendRegexp();
await verifyCanSendStaticMethod();
}