From ff25d85758280d4b05d6af640cc2009257da4dc4 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 21 May 2026 01:35:53 -0700 Subject: [PATCH] [dart2wasm, standalone] Rename JSStringImpl to EmbedderStringImpl The standalone target used `JSStringImpl` as the name for its string implementation even though JavaScript isn't involved in that at all. This was to simplify parts of the compiler which can then refer to both classes with the same name. Changing this in the compiler is not that complicated however, so it makes sense to align the string implementation name with the embedder terminology we also use for other host imports. TEST=pkg/dart2wasm/test/ir_tests/standalone.{dart,wat} Change-Id: I1e112c8a72bb43a7edfa73ff7205d353edc7403a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504581 Reviewed-by: Martin Kustermann Commit-Queue: Martin Kustermann Reviewed-by: Slava Egorov --- pkg/dart2wasm/lib/class_info.dart | 4 +- pkg/dart2wasm/lib/code_generator.dart | 14 ++-- pkg/dart2wasm/lib/constants.dart | 4 +- pkg/dart2wasm/lib/kernel_nodes.dart | 32 +++++---- pkg/dart2wasm/lib/target.dart | 14 ++-- pkg/dart2wasm/lib/translator.dart | 5 +- pkg/dart2wasm/lib/wasm_library_checks.dart | 16 ++++- pkg/dart2wasm/test/ir_tests/standalone.wat | 4 +- pkg/kernel/lib/target/targets.dart | 4 -- .../type_flow/summary_collector.dart | 1 - sdk/lib/_internal/wasm/lib/convert_patch.dart | 2 +- .../lib/boxed_double_patch.dart | 19 ++--- .../wasm_standalone/lib/boxed_int_patch.dart | 2 +- .../lib/convert_standalone_patch.dart | 10 +-- .../wasm_standalone/lib/date_patch_patch.dart | 2 +- .../wasm_standalone/lib/embedder_string.dart | 69 +++++++++---------- .../lib/internal_json_encode_patch.dart | 4 +- .../lib/invoke_main_patch.dart | 2 +- .../_internal/wasm_standalone/lib/regexp.dart | 12 ++-- .../wasm_standalone/lib/regexp_patch.dart | 2 +- .../lib/stack_trace_patch.dart | 2 +- .../lib/string_buffer_patch.dart | 4 +- .../wasm_standalone/lib/string_patch.dart | 12 ++-- .../wasm_standalone/lib/uri_patch.dart | 2 +- 24 files changed, 128 insertions(+), 114 deletions(-) diff --git a/pkg/dart2wasm/lib/class_info.dart b/pkg/dart2wasm/lib/class_info.dart index 10952b68b7d..d59a236bbd4 100644 --- a/pkg/dart2wasm/lib/class_info.dart +++ b/pkg/dart2wasm/lib/class_info.dart @@ -366,7 +366,7 @@ class ClassInfoCollector { translator.coreTypes.recordClass, translator.index.getClass("dart:core", "_Type"), translator.index.getClass("dart:_list", "WasmListBase"), - translator.index.getClass("dart:_string", "JSStringImpl"), + translator.stringImplClass, }; for (final name in const [ "ByteBuffer", @@ -911,7 +911,7 @@ class ClassIdNumbering { final fixedOrder = { translator.coreTypes.boolClass: -9, translator.coreTypes.numClass: -8, - translator.jsStringClass: -7, + translator.stringImplClass: -7, translator.typeClass: -6, translator.listBaseClass: -5, translator.hashFieldBaseClass: -4, diff --git a/pkg/dart2wasm/lib/code_generator.dart b/pkg/dart2wasm/lib/code_generator.dart index 581e8406dbe..328c811b67d 100644 --- a/pkg/dart2wasm/lib/code_generator.dart +++ b/pkg/dart2wasm/lib/code_generator.dart @@ -2911,19 +2911,19 @@ abstract class AstCodeGenerator translateExpression(expression, nullableObjectType); } if (expressions.length == 1) { - target = translator.jsStringInterpolate1; + target = translator.stringImplInterpolate1; } else if (expressions.length == 2) { - target = translator.jsStringInterpolate2; + target = translator.stringImplInterpolate2; } else if (expressions.length == 3) { - target = translator.jsStringInterpolate3; + target = translator.stringImplInterpolate3; } else { assert(expressions.length == 4); - target = translator.jsStringInterpolate4; + target = translator.stringImplInterpolate4; } } else { final nullableObjectType = translator.coreTypes.objectNullableRawType; makeArrayFromExpressions(expressions, nullableObjectType); - target = translator.jsStringInterpolate; + target = translator.stringImplInterpolate; } return translator.outputOrVoid(call(target.reference)); } @@ -5271,7 +5271,7 @@ class SwitchInfo { } else if (check()) { equalsMember = translator.boxedIntEquals; } else if (check()) { - equalsMember = translator.jsStringEquals; + equalsMember = translator.stringImplEquals; } else { compare = (switchExprLocal, pushCaseExpr) { // Virtual call to `Object.==`. @@ -5392,7 +5392,7 @@ class SwitchInfo { compare = (switchExprLocal, pushCaseExpr) { codeGen.b.local_get(switchExprLocal); pushCaseExpr(); - codeGen.call(translator.jsStringEquals.reference); + codeGen.call(translator.stringImplEquals.reference); }; } else if (switchExprClass.isEnum) { // If this is an applicable switch over enums, create a jump table. diff --git a/pkg/dart2wasm/lib/constants.dart b/pkg/dart2wasm/lib/constants.dart index 88498892919..4d8b7e7711b 100644 --- a/pkg/dart2wasm/lib/constants.dart +++ b/pkg/dart2wasm/lib/constants.dart @@ -772,7 +772,7 @@ class ConstantCreator extends ConstantVisitor @override ConstantInfo? visitStringConstant(StringConstant constant) { - ClassInfo info = translator.classInfo[translator.jsStringClass]!; + ClassInfo info = translator.classInfo[translator.stringImplClass]!; final standalone = translator.options.standalone; return createConstant( @@ -1598,7 +1598,7 @@ class TypeOfConstantVisitor extends ConstantVisitor @override w.RefType visitStringConstant(StringConstant constant) { - return _typeOfClass(translator.jsStringClass); + return _typeOfClass(translator.stringImplClass); } @override diff --git a/pkg/dart2wasm/lib/kernel_nodes.dart b/pkg/dart2wasm/lib/kernel_nodes.dart index b4e37982a32..d72abd0fd9b 100644 --- a/pkg/dart2wasm/lib/kernel_nodes.dart +++ b/pkg/dart2wasm/lib/kernel_nodes.dart @@ -10,16 +10,20 @@ import 'package:kernel/library_index.dart'; /// compiler. mixin KernelNodes { LibraryIndex get index; + bool get isStandalone; CoreTypes get coreTypes; // dart:_internal classes late final Class symbolClass = index.getClass("dart:_internal", "Symbol"); + String get _stringImplClassName => + isStandalone ? "EmbedderStringImpl" : "JSStringImpl"; + // dart:_js_types classes - late final Class jsStringClass = index.getClass( + late final Class stringImplClass = index.getClass( "dart:_string", - "JSStringImpl", + _stringImplClassName, ); // dart:collection classes @@ -374,34 +378,34 @@ mixin KernelNodes { ); // dart:_js_types procedures - late final Procedure jsStringEquals = index.getProcedure( + late final Procedure stringImplEquals = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "==", ); - late final Procedure jsStringInterpolate = index.getProcedure( + late final Procedure stringImplInterpolate = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "_interpolate", ); - late final Procedure jsStringInterpolate1 = index.getProcedure( + late final Procedure stringImplInterpolate1 = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "_interpolate1", ); - late final Procedure jsStringInterpolate2 = index.getProcedure( + late final Procedure stringImplInterpolate2 = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "_interpolate2", ); - late final Procedure jsStringInterpolate3 = index.getProcedure( + late final Procedure stringImplInterpolate3 = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "_interpolate3", ); - late final Procedure jsStringInterpolate4 = index.getProcedure( + late final Procedure stringImplInterpolate4 = index.getProcedure( "dart:_string", - "JSStringImpl", + _stringImplClassName, "_interpolate4", ); diff --git a/pkg/dart2wasm/lib/target.dart b/pkg/dart2wasm/lib/target.dart index edaefb1403f..c7be3f7a613 100644 --- a/pkg/dart2wasm/lib/target.dart +++ b/pkg/dart2wasm/lib/target.dart @@ -116,7 +116,7 @@ class WasmTarget extends Target { Class? _wasmDefaultSet; Class? _wasmImmutableMap; Class? _wasmImmutableSet; - Class? _jsString; + Class? _stringImpl; Class? _closure; Class? _boxedInt; Class? _boxedDouble; @@ -452,6 +452,7 @@ class WasmTarget extends Target { libraries, coreTypes, diagnosticReporter, + mode == .standalone, ); awaitTrans.transformLibraries(libraries, hierarchy, coreTypes); @@ -613,19 +614,12 @@ class WasmTarget extends Target { @override Class concreteStringLiteralClass(CoreTypes coreTypes, String value) { - return _jsString ??= coreTypes.index.getClass( + return _stringImpl ??= coreTypes.index.getClass( "dart:_string", - "JSStringImpl", + mode == .standalone ? "EmbedderStringImpl" : "JSStringImpl", ); } - // In dart2wasm we can't assume that `x == "hello"` means `x`'s class is - // `concreteStringLiteralClass("hello")`, it may also be `JSStringImpl` when - // it's obtained from a JS call, or `TwoByteString` when it's a substring of a - // `TwoByteString`. - @override - bool get canInferStringClassAfterEqualityComparison => false; - @override Class concreteClosureClass(CoreTypes coreTypes) { return _closure ??= coreTypes.index.getClass('dart:core', '_Closure'); diff --git a/pkg/dart2wasm/lib/translator.dart b/pkg/dart2wasm/lib/translator.dart index fde0fb174fe..cab2a4ef39d 100644 --- a/pkg/dart2wasm/lib/translator.dart +++ b/pkg/dart2wasm/lib/translator.dart @@ -104,6 +104,9 @@ class Translator with KernelNodes { final ClosedWorldClassHierarchy hierarchy; late final ClassHierarchySubtypes subtypes; + @override + bool get isStandalone => options.standalone; + // TFA-inferred metadata. late final Map directCallMetadata = (component.metadata[DirectCallMetadataRepository.repositoryTag] @@ -371,7 +374,7 @@ class Translator with KernelNodes { boxedIntClass: boxedIntClass, boxedDoubleClass: boxedDoubleClass, boxedBoolClass: coreTypes.boolClass, - jsStringClass: jsStringClass, + stringImplClass: stringImplClass, }; /// Type for vtable entries for dynamic calls. These entries are used in diff --git a/pkg/dart2wasm/lib/wasm_library_checks.dart b/pkg/dart2wasm/lib/wasm_library_checks.dart index be433df55e3..0bd485c1349 100644 --- a/pkg/dart2wasm/lib/wasm_library_checks.dart +++ b/pkg/dart2wasm/lib/wasm_library_checks.dart @@ -20,8 +20,13 @@ void checkDartWasmApiUseIfImported( Iterable libraries, CoreTypes coreTypes, DiagnosticReporter diagnosticReporter, + bool isStandalone, ) { - final checks = _DartWasmLibraryChecks(coreTypes, diagnosticReporter); + final checks = _DartWasmLibraryChecks( + coreTypes, + isStandalone, + diagnosticReporter, + ); for (final library in libraries) { // Skip the check if the library doesn't import dart:_wasm. // TODO: This misses libraries importing dart:_wasm through an export. @@ -43,10 +48,17 @@ class _DartWasmLibraryChecks extends RecursiveVisitor with KernelNodes { @override final CoreTypes coreTypes; + @override + final bool isStandalone; + @override LibraryIndex get index => coreTypes.index; - _DartWasmLibraryChecks(this.coreTypes, this._diagnosticReporter); + _DartWasmLibraryChecks( + this.coreTypes, + this.isStandalone, + this._diagnosticReporter, + ); @override void visitLibrary(Library library) { diff --git a/pkg/dart2wasm/test/ir_tests/standalone.wat b/pkg/dart2wasm/test/ir_tests/standalone.wat index 0336e0fed2a..2af39fa38cb 100644 --- a/pkg/dart2wasm/test/ir_tests/standalone.wat +++ b/pkg/dart2wasm/test/ir_tests/standalone.wat @@ -1,9 +1,9 @@ (module $module0 (type $#Top (struct (field $field0 i32))) - (type $JSStringImpl (sub final $#Top (struct + (type $EmbedderStringImpl (sub final $#Top (struct (field $field0 i32) (field $_ref (ref extern))))) - (global $"\"Hello world\"" (mut (ref null $JSStringImpl)) + (global $"\"Hello world\"" (mut (ref null $EmbedderStringImpl)) (ref.null none)) ) \ No newline at end of file diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart index ea452ac49fe..128c46d40b6 100644 --- a/pkg/kernel/lib/target/targets.dart +++ b/pkg/kernel/lib/target/targets.dart @@ -588,10 +588,6 @@ abstract class Target { Class? concreteDoubleLiteralClass(CoreTypes coreTypes, double value) => null; Class? concreteStringLiteralClass(CoreTypes coreTypes, String value) => null; - /// When a comparison `x == ` is true, whether we can assume the - /// class of `x` to be `concreteStringLiteralClass()`. - bool get canInferStringClassAfterEqualityComparison => true; - Class? concreteAsyncResultClass(CoreTypes coreTypes) => null; Class? concreteSyncStarResultClass(CoreTypes coreTypes) => null; diff --git a/pkg/vm/lib/transformations/type_flow/summary_collector.dart b/pkg/vm/lib/transformations/type_flow/summary_collector.dart index 41845317172..d6207c94e90 100644 --- a/pkg/vm/lib/transformations/type_flow/summary_collector.dart +++ b/pkg/vm/lib/transformations/type_flow/summary_collector.dart @@ -1742,7 +1742,6 @@ class SummaryCollector extends RecursiveResultVisitor { _environment.coreTypes.doubleNullableRawType, )) || (isStringConstant(rhs) && - target.canInferStringClassAfterEqualityComparison && _isSubtype( lhs.variable.type, _environment.coreTypes.stringNullableRawType, diff --git a/sdk/lib/_internal/wasm/lib/convert_patch.dart b/sdk/lib/_internal/wasm/lib/convert_patch.dart index 07fb1293f20..5681afa6c20 100644 --- a/sdk/lib/_internal/wasm/lib/convert_patch.dart +++ b/sdk/lib/_internal/wasm/lib/convert_patch.dart @@ -23,7 +23,7 @@ dynamic _parseJson( ) { final listener = _JsonListener(reviver); final parser = _StringParser(listener); - parser.setNewChunk(unsafeCast(source), source.length); + parser.setNewChunk(source, source.length); parser.parse(0); parser.close(); return listener.result; diff --git a/sdk/lib/_internal/wasm_standalone/lib/boxed_double_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/boxed_double_patch.dart index 940aee73390..cd8628fc5f3 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/boxed_double_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/boxed_double_patch.dart @@ -11,7 +11,7 @@ import 'dart:_wasm'; class BoxedDouble { @patch String toString() { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.f64ToString(WasmF64.fromDouble(value)), ); } @@ -48,12 +48,13 @@ class BoxedDouble { return result; } - String _toStringAsFixed(int fractionDigits) => JSStringImpl.fromRefUnchecked( - embedder.f64ToFixed( - WasmF64.fromDouble(this), - WasmI32.fromInt(fractionDigits), - ), - ); + String _toStringAsFixed(int fractionDigits) => + EmbedderStringImpl.fromRefUnchecked( + embedder.f64ToFixed( + WasmF64.fromDouble(this), + WasmI32.fromInt(fractionDigits), + ), + ); @patch String toStringAsExponential([int? fractionDigits]) { @@ -83,7 +84,7 @@ class BoxedDouble { } String _toStringAsExponential(int? fractionDigits) => - JSStringImpl.fromRefUnchecked( + EmbedderStringImpl.fromRefUnchecked( fractionDigits == null ? embedder.f64ToExponential(WasmF64.fromDouble(this)) : embedder.f64ToExponentialWithFractionDigits( @@ -113,7 +114,7 @@ class BoxedDouble { } String _toStringAsPrecision(int fractionDigits) => - JSStringImpl.fromRefUnchecked( + EmbedderStringImpl.fromRefUnchecked( embedder.f64ToPrecision( WasmF64.fromDouble(this), WasmI32.fromInt(fractionDigits), diff --git a/sdk/lib/_internal/wasm_standalone/lib/boxed_int_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/boxed_int_patch.dart index c41b841d5ea..0a3c795a3f7 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/boxed_int_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/boxed_int_patch.dart @@ -21,7 +21,7 @@ class BoxedInt { } String _intToString(int value, int radix) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( i64ToString(WasmI64.fromInt(value), WasmI32.fromInt(radix)), ); } diff --git a/sdk/lib/_internal/wasm_standalone/lib/convert_standalone_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/convert_standalone_patch.dart index 2853da35d45..02705fc9a02 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/convert_standalone_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/convert_standalone_patch.dart @@ -23,7 +23,7 @@ class _StringParser { static WasmArray stringToCharCodeArray(String string, int end) { final array = WasmArray(end); if (string.length == end) { - final externRef = unsafeCast(string).wrappedExternRef; + final externRef = unsafeCast(string).wrappedExternRef; embedder.stringToCodeUnits(externRef, array, 0.toWasmI32()); } else { for (int i = 0; i < end; ++i) @@ -37,16 +37,18 @@ class _StringParser { @patch double _parseValidFloat(String string) { return embedder - .doubleParseInfallible(unsafeCast(string).wrappedExternRef) + .doubleParseInfallible( + unsafeCast(string).wrappedExternRef, + ) .toDouble(); } @patch String _stringFromCharCodeArray(WasmArray array, int start, int end) { - return JSStringImpl.fromCharCodeArray(array, start, end); + return EmbedderStringImpl.fromCharCodeArray(array, start, end); } @patch String _stringFromAsciiBytes(WasmArray source, int start, int end) { - return JSStringImpl.fromAsciiBytes(source, start, end); + return EmbedderStringImpl.fromAsciiBytes(source, start, end); } diff --git a/sdk/lib/_internal/wasm_standalone/lib/date_patch_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/date_patch_patch.dart index 0612bed52bc..fa18d6f9ccf 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/date_patch_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/date_patch_patch.dart @@ -14,7 +14,7 @@ class DateTime { @patch static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) => - JSStringImpl.fromRefUnchecked( + EmbedderStringImpl.fromRefUnchecked( timeZoneNameForClampedSeconds(WasmI64.fromInt(secondsSinceEpoch)), ); diff --git a/sdk/lib/_internal/wasm_standalone/lib/embedder_string.dart b/sdk/lib/_internal/wasm_standalone/lib/embedder_string.dart index 484157b61a6..c4db6386a2a 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/embedder_string.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/embedder_string.dart @@ -31,15 +31,11 @@ extension StringUncheckedOperations on String { } /// A string managed by the WebAssembly embedder. -/// -/// This is not necessarily a JavaScript string, but the `JSStringImpl` name is -/// referenced a lot in the compiler and since this class and it's counterpart -/// in the JS target have the same structure (wrapping an externref), adopting -/// the same name avoids conditional names in the compiler. -final class JSStringImpl implements String, StringUncheckedOperationsBase { +final class EmbedderStringImpl + implements String, StringUncheckedOperationsBase { WasmExternRef? _ref; - JSStringImpl.fromRefUnchecked(this._ref); + EmbedderStringImpl.fromRefUnchecked(this._ref); WasmExternRef? get wrappedExternRef => _ref; @@ -99,23 +95,23 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { .toString(); } - static JSStringImpl fromAsciiBytes( + static EmbedderStringImpl fromAsciiBytes( WasmArray source, int start, int end, ) { final length = WasmI32.fromInt(end - start); - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringFromAsciiBytes(source, WasmI32.fromInt(start), length), ); } - static JSStringImpl fromCharCodeArray( + static EmbedderStringImpl fromCharCodeArray( WasmArray source, int start, int end, ) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringFromCharCodeArray( source, WasmI32.fromInt(start), @@ -127,23 +123,23 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { @pragma("wasm:initialize-at-startup") static final _stringFromCodePointBuffer = WasmArray(2); - static JSStringImpl fromCharCode(int charCode) { + static EmbedderStringImpl fromCharCode(int charCode) { final array = _stringFromCodePointBuffer; array.write(0, charCode); - return JSStringImpl.fromCharCodeArray(array, 0, 1); + return EmbedderStringImpl.fromCharCodeArray(array, 0, 1); } - static JSStringImpl fromCodePoint(int codePoint) { + static EmbedderStringImpl fromCodePoint(int codePoint) { final array = _stringFromCodePointBuffer; if (codePoint <= 0xffff) { array.write(0, codePoint); - return JSStringImpl.fromCharCodeArray(array, 0, 1); + return EmbedderStringImpl.fromCharCodeArray(array, 0, 1); } final low = 0xDC00 | (codePoint & 0x3ff); final high = 0xD7C0 + (codePoint >> 10); array.write(0, high); array.write(1, low); - return JSStringImpl.fromCharCodeArray(array, 0, 2); + return EmbedderStringImpl.fromCharCodeArray(array, 0, 2); } @override @@ -187,10 +183,10 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { @override @pragma('wasm:pure-function') String operator +(String other) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringConcat( wrappedExternRef, - unsafeCast(other).wrappedExternRef, + unsafeCast(other).wrappedExternRef, ), ); } @@ -217,19 +213,19 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { } return result.toString(); } - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringReplaceAllString( wrappedExternRef, - unsafeCast(from).wrappedExternRef, - unsafeCast(to).wrappedExternRef, + unsafeCast(from).wrappedExternRef, + unsafeCast(to).wrappedExternRef, ), ); } else if (from is EmbedderRegExp) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringReplaceAllRegExp( wrappedExternRef, from._regexp, - unsafeCast(to).wrappedExternRef, + unsafeCast(to).wrappedExternRef, ), ); } else { @@ -260,12 +256,12 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { } String _replaceRange(int start, int end, String replacement) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringReplaceRange( wrappedExternRef, WasmI32.fromInt(start), WasmI32.fromInt(end), - unsafeCast(replacement).wrappedExternRef, + unsafeCast(replacement).wrappedExternRef, ), ); } @@ -326,7 +322,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { @override @pragma('wasm:prefer-inline') String _substringUnchecked(int start, int end) => - JSStringImpl.fromRefUnchecked( + EmbedderStringImpl.fromRefUnchecked( embedder.stringSubstring( wrappedExternRef, WasmI32.fromInt(start), @@ -340,7 +336,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { if (embedder.stringEquals(toLower, wrappedExternRef).toBool()) { return this; } else { - return JSStringImpl.fromRefUnchecked(toLower); + return EmbedderStringImpl.fromRefUnchecked(toLower); } } @@ -350,7 +346,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { if (embedder.stringEquals(toUpper, wrappedExternRef).toBool()) { return this; } else { - return JSStringImpl.fromRefUnchecked(toUpper); + return EmbedderStringImpl.fromRefUnchecked(toUpper); } } @@ -391,7 +387,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { ); } - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.stringRepeat(wrappedExternRef, WasmI32.fromInt(times)), ); } @@ -420,7 +416,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { int indexOf(Pattern pattern, [int start = 0]) { final length = this.length; RangeErrorUtils.checkValueBetweenZeroAndPositiveMax(start, length); - if (pattern is JSStringImpl) { + if (pattern is EmbedderStringImpl) { return embedder .stringIndexOfString( wrappedExternRef, @@ -447,7 +443,7 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { } else { RangeErrorUtils.checkValueBetweenZeroAndPositiveMax(start, length); } - if (pattern is JSStringImpl) { + if (pattern is EmbedderStringImpl) { if (start + pattern.length > length) { start = length - pattern.length; } @@ -500,20 +496,21 @@ final class JSStringImpl implements String, StringUncheckedOperationsBase { @pragma("wasm:prefer-inline") String operator [](int index) { IndexErrorUtils.checkIndex(index, length); - return JSStringImpl.fromCharCode(_codeUnitAtUnchecked(index)); + return EmbedderStringImpl.fromCharCode(_codeUnitAtUnchecked(index)); } @override @pragma('wasm:prefer-inline') bool operator ==(Object other) => - other is JSStringImpl && embedder.stringEquals(_ref, other._ref).toBool(); + other is EmbedderStringImpl && + embedder.stringEquals(_ref, other._ref).toBool(); @override @pragma('wasm:prefer-inline') int compareTo(String other) => embedder .stringCompare( wrappedExternRef, - unsafeCast(other).wrappedExternRef, + unsafeCast(other).wrappedExternRef, ) .toIntSigned(); @@ -527,6 +524,6 @@ String _stringIdentity(String string) => string; @patch @pragma('wasm:prefer-inline') -JSStringImpl embedderStringFromDartString(String s) { - return unsafeCast(s); +EmbedderStringImpl embedderStringFromDartString(String s) { + return unsafeCast(s); } diff --git a/sdk/lib/_internal/wasm_standalone/lib/internal_json_encode_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/internal_json_encode_patch.dart index 4ff8d471728..016f8aa9d71 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/internal_json_encode_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/internal_json_encode_patch.dart @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:_embedder' as embedder; -import 'dart:_string' show embedderStringFromDartString, JSStringImpl; +import 'dart:_string' show embedderStringFromDartString, EmbedderStringImpl; import 'dart:_wasm'; -String jsonEncode(String object) => JSStringImpl.fromRefUnchecked( +String jsonEncode(String object) => EmbedderStringImpl.fromRefUnchecked( embedder.jsonEncodeString( embedderStringFromDartString(object).wrappedExternRef, ), diff --git a/sdk/lib/_internal/wasm_standalone/lib/invoke_main_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/invoke_main_patch.dart index cefb7d43df9..b8c9a5d6a1a 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/invoke_main_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/invoke_main_patch.dart @@ -36,7 +36,7 @@ WasmVoid _invokeMain(WasmArray args) { try { final dartArgs = []; for (var i = 0; i < args.length; i++) { - dartArgs.add(JSStringImpl.fromRefUnchecked(args[i])); + dartArgs.add(EmbedderStringImpl.fromRefUnchecked(args[i])); } _invokeMainInternal(dartArgs); diff --git a/sdk/lib/_internal/wasm_standalone/lib/regexp.dart b/sdk/lib/_internal/wasm_standalone/lib/regexp.dart index c7e4a3ee8dc..dc557bfca88 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/regexp.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/regexp.dart @@ -35,7 +35,7 @@ final class EmbedderRegExp implements RegExp { if (!embedder.regexpIsRegexp(compiled).toBool()) { // The returned value is the stringified JavaScript exception. Turn it // into a Dart exception. - final errorMessage = JSStringImpl.fromRefUnchecked(compiled); + final errorMessage = EmbedderStringImpl.fromRefUnchecked(compiled); throw FormatException('Illegal RegExp pattern ($errorMessage)', pattern); } @@ -133,7 +133,9 @@ final class _EmbedderMatch implements RegExpMatch { _match, WasmI32.fromInt(group), ); - return contents.isNull ? null : JSStringImpl.fromRefUnchecked(contents); + return contents.isNull + ? null + : EmbedderStringImpl.fromRefUnchecked(contents); } @override @@ -145,7 +147,7 @@ final class _EmbedderMatch implements RegExpMatch { late final List groupNames = List.generate( embedder.regexpMatchGetNamedGroups(_match).toIntUnsigned(), (i) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( embedder.regexpMatchGetGroupName(_match, WasmI32.fromInt(i)), ); }, @@ -162,7 +164,9 @@ final class _EmbedderMatch implements RegExpMatch { _match, WasmI32.fromInt(groupIndex), ); - return contents.isNull ? null : JSStringImpl.fromRefUnchecked(contents); + return contents.isNull + ? null + : EmbedderStringImpl.fromRefUnchecked(contents); } } diff --git a/sdk/lib/_internal/wasm_standalone/lib/regexp_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/regexp_patch.dart index d62a1892ad6..95241311226 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/regexp_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/regexp_patch.dart @@ -23,7 +23,7 @@ class RegExp { @patch static String escape(String text) { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( regexpEscape(embedderStringFromDartString(text).wrappedExternRef), ); } diff --git a/sdk/lib/_internal/wasm_standalone/lib/stack_trace_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/stack_trace_patch.dart index dd36b7cf2fa..efb67749734 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/stack_trace_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/stack_trace_patch.dart @@ -27,7 +27,7 @@ final class _EmbedderStackTrace implements StackTrace { @override String toString() { - return JSStringImpl.fromRefUnchecked( + return EmbedderStringImpl.fromRefUnchecked( stackTraceToString(_embedderStackTrace), ); } diff --git a/sdk/lib/_internal/wasm_standalone/lib/string_buffer_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/string_buffer_patch.dart index 0a6f42a50cd..66bacaeecba 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/string_buffer_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/string_buffer_patch.dart @@ -70,7 +70,9 @@ class StringBuffer { @patch String toString() { - return JSStringImpl.fromRefUnchecked(stringBufferToString(_hostBuffer)); + return EmbedderStringImpl.fromRefUnchecked( + stringBufferToString(_hostBuffer), + ); } void _writeString(String str) { diff --git a/sdk/lib/_internal/wasm_standalone/lib/string_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/string_patch.dart index e613b56d6ae..51873b5e355 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/string_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/string_patch.dart @@ -56,7 +56,7 @@ class String { : length; if (end <= start) return ''; - return JSStringImpl.fromAsciiBytes( + return EmbedderStringImpl.fromAsciiBytes( charCodes.data, charCodes.offsetInElements + start, charCodes.offsetInElements + end, @@ -80,7 +80,7 @@ class String { end += offset; final data = charCodes.data; - return JSStringImpl.fromCharCodeArray(data, start, end); + return EmbedderStringImpl.fromCharCodeArray(data, start, end); } static String? _fromWasmListBaseCharCodes( @@ -106,7 +106,7 @@ class String { } dst.write(i, charCode); } - return JSStringImpl.fromCharCodeArray(dst, 0, count); + return EmbedderStringImpl.fromCharCodeArray(dst, 0, count); } static String _fromIterableCharCodes( @@ -130,7 +130,7 @@ class String { it.moveNext(); } - // Convert to WasmArray for JSStringImpl.fromCharCodeArray. + // Convert to WasmArray for EmbedderStringImpl.fromCharCodeArray. final charCodesLength = (end ?? length) - start; if (charCodesLength <= 0) return ""; final typedArrayLength = charCodesLength * 2; @@ -152,13 +152,13 @@ class String { } } - return JSStringImpl.fromCharCodeArray(list, 0, index); + return EmbedderStringImpl.fromCharCodeArray(list, 0, index); } @patch @pragma("wasm:prefer-inline") factory String.fromCharCode(int charCode) { RangeErrorUtils.checkValueBetweenZeroAndPositiveMax(charCode, 0x10ffff); - return JSStringImpl.fromCodePoint(charCode); + return EmbedderStringImpl.fromCodePoint(charCode); } } diff --git a/sdk/lib/_internal/wasm_standalone/lib/uri_patch.dart b/sdk/lib/_internal/wasm_standalone/lib/uri_patch.dart index 5d753f2fe89..9735eea8d7a 100644 --- a/sdk/lib/_internal/wasm_standalone/lib/uri_patch.dart +++ b/sdk/lib/_internal/wasm_standalone/lib/uri_patch.dart @@ -11,7 +11,7 @@ import 'dart:_wasm'; class Uri { @patch static Uri get base { - final currentUri = JSStringImpl.fromRefUnchecked(baseUri()); + final currentUri = EmbedderStringImpl.fromRefUnchecked(baseUri()); if (currentUri != null) { return Uri.parse(currentUri); }