[dart2wasm,tfa] Don't infer class of string values in comparisons
In dart2wasm, when a comparison like `x == "hello"` is true, we can't assume that the class of `x` is the same as the class of `"hello"`: - If `x` is received from JS, it will be `JSStringImpl`. - If it's a substring of a `TwoByteString`, it will be `TwoByteString`. - Otherwise it will be `OneByteString`. Update `Target` with the new method ``` bool get canInferStringClassAfterEqualityComparison => true; ``` to allow TFA to *not* infer classes of string values after comparisons. Override the method to return `false` in dart2wasm's `Target` implementation. Fixes #59901. Tested: web/wasm/issue_59901_test Change-Id: I1a6c8deaf27c54240dd4e821dbd8160914502ad7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404562 Reviewed-by: Martin Kustermann <kustermann@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
committed by
Commit Queue
parent
b59c3e22ef
commit
78ce85a7fe
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2025, 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';
|
||||
|
||||
void main() {
|
||||
final List<int> codeUnits = [];
|
||||
final jsString = "hello".toJS.toDart;
|
||||
if (jsString == "hello") {
|
||||
for (int i = 0; i < 5; i += 1) {
|
||||
codeUnits.add(jsString.codeUnitAt(i));
|
||||
}
|
||||
}
|
||||
Expect.listEquals(codeUnits, [104, 101, 108, 108, 111]);
|
||||
}
|
||||
Reference in New Issue
Block a user