File tree Expand file tree Collapse file tree 2 files changed +43
-7
lines changed Expand file tree Collapse file tree 2 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -162,14 +162,14 @@ class Await implements EvcOp {
162162
163163 void _suspend (Runtime runtime, Continuation continuation, $Future future,
164164 Completer completer) async {
165- final result = await future.$value;
166- runtime.returnValue = result;
167- runtime.frameOffset = continuation.frameOffset;
168- runtime.frame = continuation.frame;
169- runtime.stack.add (continuation.frame);
170- runtime.scopeNameStack.add ('<asynchronous gap>' );
171-
172165 try {
166+ final result = await future.$value;
167+ runtime.returnValue = result;
168+ runtime.frameOffset = continuation.frameOffset;
169+ runtime.frame = continuation.frame;
170+ runtime.stack.add (continuation.frame);
171+ runtime.scopeNameStack.add ('<asynchronous gap>' );
172+
173173 runtime.bridgeCall (continuation.programOffset);
174174 } catch (e) {
175175 // temporary fix: this isn't correct, we need to reenter the eval loop
Original file line number Diff line number Diff line change @@ -259,5 +259,41 @@ void main() {
259259 .executeLib ('package:example/main.dart' , 'main' , [callback])),
260260 prints ('a\n b\n ' ));
261261 });
262+
263+ test ('Should catch bridge future error' , () async {
264+ final runtime = compiler.compileWriteAndLoad ({
265+ 'example' : {
266+ 'main.dart' : '''
267+ import 'dart:async';
268+
269+ void main(Function callback) async {
270+ await callback();
271+ }
272+ '''
273+ }
274+ });
275+
276+ bool callbackExecuted = false ;
277+ final callback = $Closure ((runtime, target, args) {
278+ callbackExecuted = true ;
279+ return $Future .wrap (Future .error (Exception ('Bridge error' )));
280+ });
281+
282+ Exception ? caughtException;
283+ try {
284+ await runtime
285+ .executeLib ('package:example/main.dart' , 'main' , [callback]);
286+ fail ('Expected exception was not thrown' );
287+ } catch (e) {
288+ caughtException = e as Exception ;
289+ }
290+
291+ // Verify callback was executed
292+ expect (callbackExecuted, isTrue);
293+
294+ // Verify correct exception type and message
295+ expect (caughtException, isA <Exception >());
296+ expect (caughtException.toString (), contains ('Bridge error' ));
297+ });
262298 });
263299}
You can’t perform that action at this time.
0 commit comments