Check for the type of the the spawned function.

In general we avoid explicit type-checks, but in this case the error would be only detected in the new isolate making error handling much harder.

Fixes #27185
BUG= http://dartbug.com/27185.
R=lrn@google.com

Review URL: https://codereview.chromium.org/2414173003 .
This commit is contained in:
Florian Loitsch 2016-10-14 13:27:11 +02:00
parent 523da59d56
commit 136e476c87
4 changed files with 17 additions and 11 deletions

View file

@ -193,9 +193,9 @@ class _SendPortImpl implements SendPort {
void _sendInternal(var message) native "SendPortImpl_sendInternal_";
}
typedef _MainFunction();
typedef _MainFunctionArgs(args);
typedef _MainFunctionArgsMessage(args, message);
typedef _NullaryFunction();
typedef _UnaryFunction(args);
typedef _BinaryFunction(args, message);
/**
* Takes the real entry point as argument and invokes it with the
@ -253,9 +253,9 @@ void _startIsolate(SendPort parentPort,
port.close();
if (isSpawnUri) {
if (entryPoint is _MainFunctionArgsMessage) {
if (entryPoint is _BinaryFunction) {
entryPoint(args, message);
} else if (entryPoint is _MainFunctionArgs) {
} else if (entryPoint is _UnaryFunction) {
entryPoint(args);
} else {
entryPoint();
@ -310,6 +310,11 @@ void _startIsolate(SendPort parentPort,
// `paused` isn't handled yet.
RawReceivePort readyPort;
try {
// Check for the type of `entryPoint` on the spawning isolate to make
// error-handling easier.
if (entryPoint is! _UnaryFunction) {
throw new ArgumentError(entryPoint);
}
// The VM will invoke [_startIsolate] with entryPoint as argument.
readyPort = new RawReceivePort();

View file

@ -10,6 +10,8 @@ import 'dart:_isolate_helper' show CapabilityImpl,
ReceivePortImpl,
RawReceivePortImpl;
typedef _UnaryFunction(arg);
@patch
class Isolate {
static final _currentIsolateCache = IsolateNatives.currentIsolate;
@ -42,6 +44,11 @@ class Isolate {
(onExit != null) ||
(onError != null);
try {
// Check for the type of `entryPoint` on the spawning isolate to make
// error-handling easier.
if (entryPoint is! _UnaryFunction) {
throw new ArgumentError(entryPoint);
}
// TODO: Consider passing the errorsAreFatal/onExit/onError values
// as arguments to the internal spawnUri instead of setting
// them after the isolate has been created.

View file

@ -676,8 +676,6 @@ WebPlatformTest/shadow-dom/shadow-trees/upper-boundary-encapsulation/test-007_t0
[ $compiler == dart2js && $checked != true ]
Language/Expressions/Property_Extraction/General_Super_Property_Extraction/getter_lookup_t02: Timeout, Skip # Please triage this failure
Language/Expressions/Property_Extraction/Super_Closurization/setter_closurization_t09: CompileTimeError # Please triage this failure
LibTest/isolate/Isolate/spawn_A02_t04: RuntimeError # Issue 27185
LibTest/isolate/Isolate/spawn_A02_t05: RuntimeError # Issue 27185
[ $compiler == dart2js && $minified ]
LibTest/typed_data/Float32List/runtimeType_A01_t01: fail # co19-roll r559: Please triage this failure

View file

@ -59,10 +59,6 @@ Language/Libraries_and_Scripts/Imports/deferred_import_t02: Crash # Issue 27201
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) && $system == windows ]
Language/Expressions/Function_Invocation/async_invokation_t04: Pass, RuntimeError # co19 issue 54
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) && $checked == false ]
LibTest/isolate/Isolate/spawn_A02_t04: RuntimeError # Issue 27185
LibTest/isolate/Isolate/spawn_A02_t05: RuntimeError, Crash # Issue 27185
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) && ($arch != x64 && $arch != simarm64 && $arch != arm64 && $arch != simdbc64) ]
LibTest/core/int/operator_left_shift_A01_t02: Fail # co19 issue 129