Skip to content

Commit

Permalink
[js_runtime/js_dev_runtime] Don't consider running on Windows when co…
Browse files Browse the repository at this point in the history
…mpiled 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 #54474

Change-Id: I1ef830f7b14af928a16a875d50cf6ab0db727dfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345100
Reviewed-by: Sigmund Cherem <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
Reviewed-by: Mayank Patke <[email protected]>
Commit-Queue: Mayank Patke <[email protected]>
Auto-Submit: Parker Lougheed <[email protected]>
  • Loading branch information
parlough authored and Commit Queue committed Jan 5, 2024
1 parent aa6b647 commit 2da2375
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 2 additions & 7 deletions sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions sdk/lib/_internal/js_runtime/lib/core_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2da2375

Please sign in to comment.