Files
sdk/tests/web/wasm/location_href_test.dart
Martin Kustermann 149db7eced [dart2wasm] Make commandline JS runner (run_wasm.js) initialize location.href
By initializing `location.href` in the commandline JS runners we allow
programs running in D8 to use `Uri.base` (which depends on
`location.href`).

That in return will allow running some Dart programs in D8 that would
otherwise not run (e.g. code using `package:test/test.dart` - which uses
`Uri.base`)

TEST=tests/web/wasm/location_href_test.dart

Change-Id: Ie219f8d9ece3b92f2442200539557f116d2c84ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363700
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-04-19 12:40:23 +00:00

28 lines
786 B
Dart

// Copyright (c) 2024, 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';
import 'package:expect/expect.dart';
import 'package:expect/config.dart';
@JS('location.href')
external JSString? get locationHref;
void main() {
final String? nullableHref = locationHref?.toDart;
Expect.isNotNull(nullableHref);
final String href = nullableHref!;
print('location.href = $href');
if (isBrowserConfiguration) {
Expect.isTrue(href.startsWith('http://'));
Expect.isTrue(href.contains('/test.html'));
} else {
Expect.isTrue(href.startsWith('file://'));
Expect.isTrue(href.endsWith('.wasm'));
}
}