[dart2wasm] Remove jsStringToDartString
`jsStringToDartString` doesn't do anything since we removed pure Wasm
string classes and started using JS strings for all strings.
Change-Id: I939fc75ab24531b8d98235d23b80f7960f799bca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417260
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
diff --git a/sdk/lib/_internal/wasm/lib/boxed_double.dart b/sdk/lib/_internal/wasm/lib/boxed_double.dart
index a163e1d..45ca84a 100644
--- a/sdk/lib/_internal/wasm/lib/boxed_double.dart
+++ b/sdk/lib/_internal/wasm/lib/boxed_double.dart
@@ -5,7 +5,7 @@
import "dart:_error_utils";
import 'dart:_boxed_int' show intHashCode;
import 'dart:_internal' show doubleToIntBits, intBitsToDouble;
-import 'dart:_js_helper' show JS, jsStringToDartString;
+import 'dart:_js_helper' show JS;
import 'dart:_string';
import 'dart:_wasm';
@@ -353,12 +353,10 @@
return "Infinity";
}
- String result = jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef?>(
- 'Function.prototype.call.bind(Number.prototype.toString)',
- WasmF64.fromDouble(value),
- ),
+ String result = JSStringImpl(
+ JS<WasmExternRef?>(
+ 'Function.prototype.call.bind(Number.prototype.toString)',
+ WasmF64.fromDouble(value),
),
);
if (this % 1.0 == 0.0 && result.indexOf('e') == -1) {
@@ -402,13 +400,11 @@
return result;
}
- String _toStringAsFixed(int fractionDigits) => jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(
- "(d, digits) => d.toFixed(digits)",
- value,
- fractionDigits.toDouble(),
- ),
+ String _toStringAsFixed(int fractionDigits) => JSStringImpl(
+ JS<WasmExternRef>(
+ "(d, digits) => d.toFixed(digits)",
+ value,
+ fractionDigits.toDouble(),
),
);
@@ -438,18 +434,15 @@
return result;
}
- String _toStringAsExponential(int? fractionDigits) {
- final jsString = JSStringImpl(
- fractionDigits == null
- ? JS<WasmExternRef>("d => d.toExponential()", value)
- : JS<WasmExternRef>(
- "(d, f) => d.toExponential(f)",
- value,
- fractionDigits.toDouble(),
- ),
- );
- return jsStringToDartString(jsString);
- }
+ String _toStringAsExponential(int? fractionDigits) => JSStringImpl(
+ fractionDigits == null
+ ? JS<WasmExternRef>("d => d.toExponential()", value)
+ : JS<WasmExternRef>(
+ "(d, f) => d.toExponential(f)",
+ value,
+ fractionDigits.toDouble(),
+ ),
+ );
String toStringAsPrecision(int precision) {
// See ECMAScript-262, 15.7.4.7 for details.
@@ -470,13 +463,11 @@
return result;
}
- String _toStringAsPrecision(int fractionDigits) => jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(
- "(d, precision) => d.toPrecision(precision)",
- value,
- fractionDigits.toDouble(),
- ),
+ String _toStringAsPrecision(int fractionDigits) => JSStringImpl(
+ JS<WasmExternRef>(
+ "(d, precision) => d.toPrecision(precision)",
+ value,
+ fractionDigits.toDouble(),
),
);
diff --git a/sdk/lib/_internal/wasm/lib/convert_patch.dart b/sdk/lib/_internal/wasm/lib/convert_patch.dart
index 5a277b2..cfec2cf 100644
--- a/sdk/lib/_internal/wasm/lib/convert_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/convert_patch.dart
@@ -9,7 +9,7 @@
show patch, POWERS_OF_TEN, unsafeCast, pushWasmArray, popWasmArray;
import "dart:_js_string_convert";
import "dart:_js_types";
-import "dart:_js_helper" show JS, jsStringToDartString, jsStringFromDartString;
+import "dart:_js_helper" show JS, jsStringFromDartString;
import "dart:_list"
show GrowableList, WasmListBaseUnsafeExtensions, WasmListBase;
import "dart:_string";
diff --git a/sdk/lib/_internal/wasm/lib/core_patch.dart b/sdk/lib/_internal/wasm/lib/core_patch.dart
index 09514ca..dd29a4a 100644
--- a/sdk/lib/_internal/wasm/lib/core_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/core_patch.dart
@@ -32,12 +32,7 @@
import "dart:_internal" as _internal;
import 'dart:_js_helper'
- show
- JS,
- JSSyntaxRegExp,
- quoteStringForRegExp,
- jsStringFromDartString,
- jsStringToDartString;
+ show JS, JSSyntaxRegExp, quoteStringForRegExp, jsStringFromDartString;
import 'dart:_list';
diff --git a/sdk/lib/_internal/wasm/lib/date_patch_patch.dart b/sdk/lib/_internal/wasm/lib/date_patch_patch.dart
index b9ccc8f..ebf58ee 100644
--- a/sdk/lib/_internal/wasm/lib/date_patch_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/date_patch_patch.dart
@@ -4,7 +4,7 @@
import "dart:_internal" show patch;
-import 'dart:_js_helper' show JS, jsStringToDartString;
+import 'dart:_js_helper' show JS;
import 'dart:_string';
import 'dart:_wasm';
@@ -16,9 +16,8 @@
@patch
static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) =>
- jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(r"""secondsSinceEpoch => {
+ JSStringImpl(
+ JS<WasmExternRef>(r"""secondsSinceEpoch => {
const date = new Date(secondsSinceEpoch * 1000);
const match = /\((.*)\)/.exec(date.toString());
if (match == null) {
@@ -27,7 +26,6 @@
}
return match[1];
}""", secondsSinceEpoch.toDouble()),
- ),
);
// In Dart, the offset is the difference between local time and UTC,
diff --git a/sdk/lib/_internal/wasm/lib/internal_patch.dart b/sdk/lib/_internal/wasm/lib/internal_patch.dart
index 5ee0f2c..4a162a4 100644
--- a/sdk/lib/_internal/wasm/lib/internal_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/internal_patch.dart
@@ -8,7 +8,6 @@
JS,
JSAnyToExternRef,
jsStringFromDartString,
- jsStringToDartString,
jsUint8ArrayFromDartUint8List;
import "dart:_js_types" show JSStringImpl;
import 'dart:_string';
@@ -156,12 +155,10 @@
}
}
-String jsonEncode(String object) => jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(
- "s => JSON.stringify(s)",
- jsStringFromDartString(object).toExternRef,
- ),
+String jsonEncode(String object) => JSStringImpl(
+ JS<WasmExternRef>(
+ "s => JSON.stringify(s)",
+ jsStringFromDartString(object).toExternRef,
),
);
diff --git a/sdk/lib/_internal/wasm/lib/js_helper.dart b/sdk/lib/_internal/wasm/lib/js_helper.dart
index 4e4286f..2dc82e2 100644
--- a/sdk/lib/_internal/wasm/lib/js_helper.dart
+++ b/sdk/lib/_internal/wasm/lib/js_helper.dart
@@ -266,7 +266,6 @@
}
external JSStringImpl jsStringFromDartString(String s);
-external String jsStringToDartString(JSStringImpl s);
WasmExternRef? newObjectRaw() => JS<WasmExternRef?>('() => ({})');
diff --git a/sdk/lib/_internal/wasm/lib/js_helper_patch.dart b/sdk/lib/_internal/wasm/lib/js_helper_patch.dart
index bfd124e..6e19b97 100644
--- a/sdk/lib/_internal/wasm/lib/js_helper_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/js_helper_patch.dart
@@ -14,15 +14,7 @@
@patch
@pragma('wasm:prefer-inline')
-JSStringImpl jsStringFromDartString(String s) {
- return unsafeCast<JSStringImpl>(s);
-}
-
-@patch
-@pragma('wasm:prefer-inline')
-String jsStringToDartString(JSStringImpl s) {
- return s;
-}
+JSStringImpl jsStringFromDartString(String s) => unsafeCast<JSStringImpl>(s);
@pragma('wasm:prefer-inline')
void _copyFromWasmI8Array(
diff --git a/sdk/lib/_internal/wasm/lib/regexp_helper.dart b/sdk/lib/_internal/wasm/lib/regexp_helper.dart
index 29364fc..c712522 100644
--- a/sdk/lib/_internal/wasm/lib/regexp_helper.dart
+++ b/sdk/lib/_internal/wasm/lib/regexp_helper.dart
@@ -13,15 +13,13 @@
// This method is optimized to test before replacement, which should be
// much faster. This might be worth measuring in real world use cases
// though.
-jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(r"""s => {
+JSStringImpl(
+ JS<WasmExternRef>(r"""s => {
if (/[[\]{}()*+?.\\^$|]/.test(s)) {
s = s.replace(/[[\]{}()*+?.\\^$|]/g, '\\$&');
}
return s;
}""", jsStringFromDartString(string).toExternRef),
- ),
);
// TODO(srujzs): Add this to `JSObject`.
@@ -134,8 +132,8 @@
if (isJSRegExp(result)) return JSValue(result!) as JSNativeRegExp;
// The returned value is the stringified JavaScript exception. Turn it into
// a Dart exception.
- String errorMessage = jsStringToDartString(JSStringImpl(result!));
- throw new FormatException('Illegal RegExp pattern ($errorMessage)', source);
+ String errorMessage = JSStringImpl(result!);
+ throw FormatException('Illegal RegExp pattern ($errorMessage)', source);
}
RegExpMatch? firstMatch(String string) {
diff --git a/sdk/lib/_internal/wasm/lib/string.dart b/sdk/lib/_internal/wasm/lib/string.dart
index 7ae23d5..8652e7c 100644
--- a/sdk/lib/_internal/wasm/lib/string.dart
+++ b/sdk/lib/_internal/wasm/lib/string.dart
@@ -11,7 +11,7 @@
WasmStringBase;
import 'dart:_error_utils';
-import 'dart:_js_helper' show JS, jsStringFromDartString, jsStringToDartString;
+import 'dart:_js_helper' show JS, jsStringFromDartString;
import 'dart:_string';
import 'dart:_list';
import 'dart:_object_helper';
@@ -130,21 +130,17 @@
const int _maxLatin1 = 0xff;
const int _maxUtf16 = 0xffff;
-String _toUpperCase(String string) => jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(
- "s => s.toUpperCase()",
- jsStringFromDartString(string).toExternRef,
- ),
+String _toUpperCase(String string) => JSStringImpl(
+ JS<WasmExternRef>(
+ "s => s.toUpperCase()",
+ jsStringFromDartString(string).toExternRef,
),
);
-String _toLowerCase(String string) => jsStringToDartString(
- JSStringImpl(
- JS<WasmExternRef>(
- "s => s.toLowerCase()",
- jsStringFromDartString(string).toExternRef,
- ),
+String _toLowerCase(String string) => JSStringImpl(
+ JS<WasmExternRef>(
+ "s => s.toLowerCase()",
+ jsStringFromDartString(string).toExternRef,
),
);
@@ -1040,9 +1036,6 @@
for (int i = 0; i < numValues; ++i) {
final value = values[i];
var stringValue = value is String ? value : value.toString();
- if (stringValue is JSStringImpl) {
- stringValue = jsStringToDartString(stringValue);
- }
values[i] = stringValue;
isOneByteString = isOneByteString && stringValue is OneByteString;
totalLength += stringValue.length;
@@ -1218,10 +1211,6 @@
bool isOneByteString = true;
for (int i = start; i < end; i++) {
String stringValue = strings[i];
- if (stringValue is JSStringImpl) {
- stringValue = jsStringToDartString(stringValue);
- strings[i] = stringValue;
- }
isOneByteString = isOneByteString && stringValue is OneByteString;
totalLength += stringValue.length;
}
diff --git a/sdk/lib/_internal/wasm/lib/uri_patch.dart b/sdk/lib/_internal/wasm/lib/uri_patch.dart
index b777c6a..dcdd60f 100644
--- a/sdk/lib/_internal/wasm/lib/uri_patch.dart
+++ b/sdk/lib/_internal/wasm/lib/uri_patch.dart
@@ -18,7 +18,7 @@
}"""),
);
if (currentUri != null) {
- return Uri.parse(jsStringToDartString(currentUri));
+ return Uri.parse(currentUri);
}
throw UnsupportedError("'Uri.base' is not supported");
}
diff --git a/sdk/lib/_internal/wasm_js_compatibility/lib/js_helper_patch.dart b/sdk/lib/_internal/wasm_js_compatibility/lib/js_helper_patch.dart
index 4f0c629..ea0994e 100644
--- a/sdk/lib/_internal/wasm_js_compatibility/lib/js_helper_patch.dart
+++ b/sdk/lib/_internal/wasm_js_compatibility/lib/js_helper_patch.dart
@@ -13,10 +13,6 @@
@patch
@pragma('wasm:prefer-inline')
-String jsStringToDartString(JSStringImpl s) => s;
-
-@patch
-@pragma('wasm:prefer-inline')
WasmExternRef jsUint8ArrayFromDartUint8List(Uint8List l) =>
throw UnsupportedError(
'In JS compatibility mode we only support JS typed data implementations.',