[dart2wasm] Use the same Dart object when to{Upper,Lower}Case returns the argument

This fixes `identical` checks when the input doesn't need case mapping.

This change was originally made in [1], but I'm trying to split it into
smaller CLs as it currently has a lot of conflicts with the main branch.

[1]: https://dart-review.googlesource.com/c/sdk/+/316628

Change-Id: I88da52a3a73c9d587acefe2b14fd39edaf01c966
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332200
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Ömer Sinan Ağacan 2023-11-02 12:21:24 +00:00 committed by Commit Queue
parent 12c4e22a4d
commit d0a2656611

View file

@ -319,14 +319,20 @@ final class JSStringImpl implements String {
@override
String toLowerCase() {
return JSStringImpl(
js.JS<WasmExternRef?>('s => s.toLowerCase()', toExternRef));
final thisRef = toExternRef;
final lowerCaseRef = js.JS<WasmExternRef?>('s => s.toLowerCase()', thisRef);
return _jsIdentical(thisRef, lowerCaseRef)
? this
: JSStringImpl(lowerCaseRef);
}
@override
String toUpperCase() {
return JSStringImpl(
js.JS<WasmExternRef?>('s => s.toUpperCase()', toExternRef));
final thisRef = toExternRef;
final upperCaseRef = js.JS<WasmExternRef?>('s => s.toUpperCase()', thisRef);
return _jsIdentical(thisRef, upperCaseRef)
? this
: JSStringImpl(upperCaseRef);
}
// Characters with Whitespace property (Unicode 6.3).
@ -679,3 +685,6 @@ JSStringImpl _jsStringToJSStringImpl(WasmExternRef? string) =>
@pragma("wasm:export", "\$jsStringFromJSStringImpl")
WasmExternRef? _jsStringFromJSStringImpl(JSStringImpl string) =>
string.toExternRef;
bool _jsIdentical(WasmExternRef? ref1, WasmExternRef? ref2) =>
js.JS<bool>('Object.is', ref1, ref2);