From 2da2375bcfb3da976402801c8d09fe48d3d249c6 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Fri, 5 Jan 2024 23:58:56 +0000 Subject: [PATCH] [js_runtime/js_dev_runtime] Don't consider running on Windows when compiled for web This bool is used to check if certain Uri functions should default to Windows behavior on Node. If running on the web, these checks will always be false though, so add a check to enable tree shaking to remove unused Windows functionality. Fixes https://github.com/dart-lang/sdk/issues/54474 Change-Id: I1ef830f7b14af928a16a875d50cf6ab0db727dfc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345100 Reviewed-by: Sigmund Cherem Reviewed-by: Nate Bosch Reviewed-by: Mayank Patke Commit-Queue: Mayank Patke Auto-Submit: Parker Lougheed --- .../js_dev_runtime/patch/core_patch.dart | 9 ++------- sdk/lib/_internal/js_runtime/lib/core_patch.dart | 15 ++++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart index 66676eea45d..38d0b205ff9 100644 --- a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart +++ b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart @@ -884,14 +884,9 @@ class Uri { @patch class _Uri { + // DDC is only used when targeting the browser, so this is always false. @patch - static bool get _isWindows => _isWindowsCached; - - static final bool _isWindowsCached = JS( - 'bool', - 'typeof process != "undefined" && ' - 'Object.prototype.toString.call(process) == "[object process]" && ' - 'process.platform == "win32"'); + static bool get _isWindows => false; // Matches a String that _uriEncodes to itself regardless of the kind of // component. This corresponds to [_unreservedTable], i.e. characters that diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart index 7bd9fff3224..8ca49428ed4 100644 --- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart +++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart @@ -822,11 +822,16 @@ class _Uri { @patch static bool get _isWindows => _isWindowsCached; - static final bool _isWindowsCached = JS( - 'bool', - 'typeof process != "undefined" && ' - 'Object.prototype.toString.call(process) == "[object process]" && ' - 'process.platform == "win32"'); + // Consider the possibility of using Windows behavior if app is + // compiled with `--server-mode` and running on Node or a similar platform. + static final bool _isWindowsCached = + !const bool.fromEnvironment('dart.library.html') && + JS( + 'bool', + 'typeof process != "undefined" && ' + 'Object.prototype.toString.call(process) == "[object process]" && ' + 'process.platform == "win32"', + ); // Matches a String that _uriEncodes to itself regardless of the kind of // component. This corresponds to [_unreservedTable], i.e. characters that