Files
sdk/pkg/dwds/web/web_utils.dart
Jessy Yameogo e1d687cb9e [dwds][dwds_test_common] Base copy of DWDS and DWDS_TEST_COMMON from webdev@e43744b235531f409ab5e2f1271178943569697a
This CL migrates the `dwds` and `dwds_test_common` packages into the Dart SDK
repository.

Key Changes:
- Migration: Moved source code and tests into `pkg/dwds` & `pkg/dwds_test_common`.
- Linting and path resolution were updated in https://github.com/dart-lang/webdev/pull/2797, https://github.com/dart-lang/webdev/pull/2798 & https://github.com/dart-lang/webdev/pull/2799 to support both environments (webdev and sdk).


Testing:
- All tests passing locally.
- CI try bots are green.

Design Doc: http://goto.google.com/migrating-webdev and http://goto.google.com/migrating-dwds

Fixes https://github.com/dart-lang/sdk/issues/62100
Fixes https://github.com/dart-lang/sdk/issues/62101
Fixes https://github.com/dart-lang/sdk/issues/62102
Fixes https://github.com/dart-lang/sdk/issues/62103

Cq-Include-Trybots: luci.dart.try:pkg-win-release-try,pkg-win-release-arm64-try,pkg-mac-release-try,pkg-mac-release-arm64-try,pkg-linux-release-try,pkg-linux-release-arm64-try,pkg-linux-debug-try
Change-Id: Icc2bf9a86efb79d04a67053962a4548fe6e894f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494640
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2026-04-23 13:18:18 -07:00

60 lines
1.5 KiB
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:js_interop';
@JS('window')
external WindowContext get windowContext;
@JS('Error')
@staticInterop
abstract class WindowContext {}
extension WindowContextExtension on WindowContext {
external bool? get $isInternalBuild;
external bool? get $isFlutterApp;
external String? get $dartAppId;
external String? get $dartExtensionUri;
}
@JS('Array.from')
external JSArray _jsArrayFrom(JSAny any);
@JS('Object.values')
external JSArray _jsObjectValues(JSAny any);
@JS('Error')
@staticInterop
abstract class JsError {}
extension JsErrorExtension on JsError {
external String get message;
external String get stack;
}
@JS('Map')
@staticInterop
abstract class JsMap<K extends JSAny, V extends JSAny> {}
extension JsMapExtension<K extends JSAny, V extends JSAny> on JsMap<K, V> {
external V? get(K key);
external JSObject keys();
}
extension JSObjectExtension on JSObject {
Iterable<Object?> get values => _jsObjectValues(this).toDartIterable();
}
extension JSArrayExtension on JSArray {
Iterable<T> toDartIterable<T>() => toDart.map((e) => e.dartify() as T);
List<T> toDartList<T>() => toDartIterable<T>().toList();
}
extension ModuleDependencyGraph on JsMap<JSString, JSArray> {
Iterable<String> get modules => _jsArrayFrom(keys()).toDartIterable();
List<String> parents(String key) => get(key.toJS)?.toDartList() ?? [];
}