[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 <sigmund@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
This commit is contained in:
Parker Lougheed
2024-01-05 23:58:56 +00:00
committed by Commit Queue
parent aa6b6470e3
commit 2da2375bcf
2 changed files with 12 additions and 12 deletions
@@ -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
@@ -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>(
'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