From 226667e7645ec5b7f23500e3447e6eded868b325 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Wed, 31 Jan 2024 14:38:43 +0000 Subject: [PATCH] [gardening] Fix recent change to language/stack_trace/* tests in CSP mode In CSP mode we cannot use `eval()`, so use static interop mechanism to set stack trace limit. It seems `window` is available in Chrome and others have higher limit anyway. Change-Id: Id57dc86936d0568338a8ee4436e69e39be8eb32c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349483 Reviewed-by: Slava Egorov Commit-Queue: Martin Kustermann --- tests/language/stack_trace/web_helper.dart | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/language/stack_trace/web_helper.dart b/tests/language/stack_trace/web_helper.dart index ecdf245266e..d102897a931 100644 --- a/tests/language/stack_trace/web_helper.dart +++ b/tests/language/stack_trace/web_helper.dart @@ -9,17 +9,26 @@ void configureStackFrameLimit() { // are captured in stack traces (e.g. Chrome's limit is 10). // We can configure that here manually, to ensure the tests pass // on all compiler+browser combinations. - eval(''' - var globalState = (typeof window != "undefined") ? window - : (typeof global != "undefined") ? global - : (typeof self != "undefined") ? self : null; + jsWindow?.error.stackTraceLimit = 100; +} - // By default, stack traces cutoff at 10 in Chrome. - if (globalState.Error) { - globalState.Error.stackTraceLimit = Infinity; - } -'''); +@JS('window') +external JSWindow? get jsWindow; + +@JS() +@staticInterop +class JSWindow {} + +extension on JSWindow { + @JS('Error') + external JSError get error; } @JS() -external void eval(String code); +@staticInterop +class JSError {} + +extension on JSError { + @JS('stackTraceLimit') + external void set stackTraceLimit(int value); +}