From 16d06dac06b9ec70896d7ead6df69e05758cdc6a Mon Sep 17 00:00:00 2001 From: Joshua Litt Date: Wed, 5 Oct 2022 16:37:59 +0000 Subject: [PATCH] [dart2wasm] Restore caller's zone when returning from await. Change-Id: Ifd0013eb130ff98bf2127991b685258ced115824 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262480 Commit-Queue: Joshua Litt Reviewed-by: Aske Simon Christensen --- sdk/lib/_internal/wasm/lib/async_patch.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/lib/_internal/wasm/lib/async_patch.dart b/sdk/lib/_internal/wasm/lib/async_patch.dart index 68d64d1af1b..7c6c4b0c5f6 100644 --- a/sdk/lib/_internal/wasm/lib/async_patch.dart +++ b/sdk/lib/_internal/wasm/lib/async_patch.dart @@ -86,8 +86,13 @@ class _FutureError { @pragma("wasm:entry-point") Object? _awaitHelper(Object? operand, WasmExternRef? stack) { + // Save the existing zone in a local, and restore('_leave') upon returning. We + // ensure that the zone will be restored in the event of an exception by + // restoring the original zone before we throw the exception. + _Zone current = Zone._current; if (operand is! Future) return operand; Object? result = _futurePromise(stack, operand); + Zone._leave(current); if (result is _FutureError) { // TODO(askesc): Combine stack traces throw result.exception;