Files
sdk/tests/web/wasm/masquerade_test.dart
Martin Kustermann 76548a7ab9 [tests] Rewrite various tests to not depend on <obj>.runtimeType.toString()
In dart2wasm applications are by default deployed in `-O2` mode which
implies `--minify`.

Given this is the default configuration for customers, we want good
testing of this configuration and not large numbers of approved failures.

=> Rewrite various tests to not depend on `<obj>.runtimeType.toString()`

Change-Id: I1108b28c63b8bec6ad94df0d7b878b3339776df9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436281
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-06-24 01:16:24 -07:00

38 lines
1.1 KiB
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:typed_data';
import 'dart:js_interop';
import 'package:expect/expect.dart';
const bool isJsCompatibility = bool.fromEnvironment(
'dart.wasm.js_compatibility',
);
void main() {
final uint8List = Uint8List(10);
final uint8ListView = uint8List.buffer.asUint8List(1, 2);
final uint16ListView = uint8List.buffer.asUint16List(2, 4);
Expect.equals(Uint8List, uint8List.runtimeType);
Expect.equals(Uint8List, uint8ListView.runtimeType);
Expect.equals(Uint16List, uint16ListView.runtimeType);
final jsString = eval('"foobar"').dartify();
final jsTypedData = eval('new Uint8Array(10)').dartify();
Expect.equals(String, jsString.runtimeType);
if (isJsCompatibility) {
Expect.equals(Uint8List, jsTypedData.runtimeType);
} else {
// JSUint8ArrayImpl
Expect.notEquals(Uint8List, jsTypedData.runtimeType);
}
}
@JS()
external JSObject eval(String code);