Chromium Code Reviews| Index: runtime/lib/isolate_patch.dart |
| diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart |
| index 46e4f4039fb0280e74acec775d4b2dd9a71c2e31..eede93c6a1e1edabdac9d1c7895bff7e2055b008 100644 |
| --- a/runtime/lib/isolate_patch.dart |
| +++ b/runtime/lib/isolate_patch.dart |
| @@ -57,6 +57,28 @@ class _ReceivePortImpl extends Stream implements ReceivePort { |
| StreamController _controller; |
| } |
| +typedef void ImmediateCallback(); |
| + |
| +/// The callback that has been registered through `scheduleImmediate`. |
| +ImmediateCallback _pendingImmediateCallback; |
| + |
| +/// The closure that should be used as scheduleImmediateClosure, when the VM |
| +/// is responsible for the event loop. |
| +void _isolateScheduleImmediate(void callback()) { |
| + assert(_pendingImmediateCallback == null); |
| + _pendingImmediateCallback = callback; |
| +} |
| + |
| +/// Provide closurized access to _isolateScheduleImmediate. |
| +/// This makes it easier for embedders to set the scheduleImmediate closure. |
| +Function get _isolateScheduleImmediateClosure => _isolateScheduleImmediate; |
| + |
| +/// The embedder can execute this function to get hold of |
| +/// [_isolateScheduleImmediate] above. |
| +Function _getIsolateScheduleImmediateClosure() { |
| + return _isolateScheduleImmediate; |
| +} |
| + |
| class _RawReceivePortImpl implements RawReceivePort { |
| factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; |
| @@ -92,7 +114,15 @@ class _RawReceivePortImpl implements RawReceivePort { |
| static void _handleMessage( |
| _RawReceivePortImpl port, int replyId, var message) { |
| assert(port != null); |
| + // TODO(floitsch): this relies on the fact that any exception aborts the |
|
Lasse Reichstein Nielsen
2013/11/27 11:41:28
Bugnumber for catching uncaught exceptions?
floitsch
2013/11/27 13:57:06
I have added 8875.
|
| + // VM. Once we have non-fatal global exceptions we need to catch errors |
| + // so that we can run the immediate callbacks. |
| port._handler(message); |
| + if (_pendingImmediateCallback != null) { |
| + var callback = _pendingImmediateCallback; |
| + _pendingImmediateCallback = null; |
| + callback(); |
| + } |
| } |
| // Call into the VM to close the VM maintained mappings. |
| @@ -215,8 +245,11 @@ patch class Isolate { |
| completer.complete(new Isolate._fromControlPort(controlPort)); |
| }; |
| } catch(e, st) { |
| - // TODO(14718): we want errors to go into the returned future. |
| - rethrow; |
| + // Don't complete immediately with an error, since the caller didn't |
| + // yet have the time to install an error handler. |
| + scheduleMicrotask(() { |
| + completer.completeError(e, st); |
|
Lasse Reichstein Nielsen
2013/11/27 11:41:28
Could we add this to the head of the queue instead
floitsch
2013/11/27 13:57:06
The current implementation is consistent with a no
|
| + }); |
| }; |
| return completer.future; |
| } |
| @@ -235,8 +268,11 @@ patch class Isolate { |
| completer.complete(new Isolate._fromControlPort(controlPort)); |
| }; |
| } catch(e, st) { |
| - // TODO(14718): we want errors to go into the returned future. |
| - rethrow; |
| + // Don't complete immediately with an error, since the caller didn't |
| + // yet have the time to install an error handler. |
| + scheduleMicrotask(() { |
| + completer.completeError(e, st); |
| + }); |
| }; |
| return completer.future; |
| } |