[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 <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
ea3fb4d69a
commit
ff25d85758
@@ -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 <String>[
|
||||
"ByteBuffer",
|
||||
@@ -911,7 +911,7 @@ class ClassIdNumbering {
|
||||
final fixedOrder = <Class, int>{
|
||||
translator.coreTypes.boolClass: -9,
|
||||
translator.coreTypes.numClass: -8,
|
||||
translator.jsStringClass: -7,
|
||||
translator.stringImplClass: -7,
|
||||
translator.typeClass: -6,
|
||||
translator.listBaseClass: -5,
|
||||
translator.hashFieldBaseClass: -4,
|
||||
|
||||
@@ -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<IntLiteral, IntConstant>()) {
|
||||
equalsMember = translator.boxedIntEquals;
|
||||
} else if (check<StringLiteral, StringConstant>()) {
|
||||
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.
|
||||
|
||||
@@ -772,7 +772,7 @@ class ConstantCreator extends ConstantVisitor<ConstantInfo?>
|
||||
|
||||
@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<w.RefType>
|
||||
|
||||
@override
|
||||
w.RefType visitStringConstant(StringConstant constant) {
|
||||
return _typeOfClass(translator.jsStringClass);
|
||||
return _typeOfClass(translator.stringImplClass);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -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",
|
||||
);
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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<TreeNode, DirectCallMetadata> 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
|
||||
|
||||
@@ -20,8 +20,13 @@ void checkDartWasmApiUseIfImported(
|
||||
Iterable<Library> 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) {
|
||||
|
||||
@@ -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))
|
||||
)
|
||||
@@ -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 == <literal>` is true, whether we can assume the
|
||||
/// class of `x` to be `concreteStringLiteralClass(<literal>)`.
|
||||
bool get canInferStringClassAfterEqualityComparison => true;
|
||||
|
||||
Class? concreteAsyncResultClass(CoreTypes coreTypes) => null;
|
||||
Class? concreteSyncStarResultClass(CoreTypes coreTypes) => null;
|
||||
|
||||
|
||||
@@ -1742,7 +1742,6 @@ class SummaryCollector extends RecursiveResultVisitor<TypeExpr?> {
|
||||
_environment.coreTypes.doubleNullableRawType,
|
||||
)) ||
|
||||
(isStringConstant(rhs) &&
|
||||
target.canInferStringClassAfterEqualityComparison &&
|
||||
_isSubtype(
|
||||
lhs.variable.type,
|
||||
_environment.coreTypes.stringNullableRawType,
|
||||
|
||||
@@ -23,7 +23,7 @@ dynamic _parseJson(
|
||||
) {
|
||||
final listener = _JsonListener(reviver);
|
||||
final parser = _StringParser(listener);
|
||||
parser.setNewChunk(unsafeCast<JSStringImpl>(source), source.length);
|
||||
parser.setNewChunk(source, source.length);
|
||||
parser.parse(0);
|
||||
parser.close();
|
||||
return listener.result;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class _StringParser {
|
||||
static WasmArray<WasmI16> stringToCharCodeArray(String string, int end) {
|
||||
final array = WasmArray<WasmI16>(end);
|
||||
if (string.length == end) {
|
||||
final externRef = unsafeCast<JSStringImpl>(string).wrappedExternRef;
|
||||
final externRef = unsafeCast<EmbedderStringImpl>(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<JSStringImpl>(string).wrappedExternRef)
|
||||
.doubleParseInfallible(
|
||||
unsafeCast<EmbedderStringImpl>(string).wrappedExternRef,
|
||||
)
|
||||
.toDouble();
|
||||
}
|
||||
|
||||
@patch
|
||||
String _stringFromCharCodeArray(WasmArray<WasmI16> array, int start, int end) {
|
||||
return JSStringImpl.fromCharCodeArray(array, start, end);
|
||||
return EmbedderStringImpl.fromCharCodeArray(array, start, end);
|
||||
}
|
||||
|
||||
@patch
|
||||
String _stringFromAsciiBytes(WasmArray<WasmI8> source, int start, int end) {
|
||||
return JSStringImpl.fromAsciiBytes(source, start, end);
|
||||
return EmbedderStringImpl.fromAsciiBytes(source, start, end);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class DateTime {
|
||||
|
||||
@patch
|
||||
static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) =>
|
||||
JSStringImpl.fromRefUnchecked(
|
||||
EmbedderStringImpl.fromRefUnchecked(
|
||||
timeZoneNameForClampedSeconds(WasmI64.fromInt(secondsSinceEpoch)),
|
||||
);
|
||||
|
||||
|
||||
@@ -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<WasmI8> 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<WasmI16> 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<WasmI16>(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<JSStringImpl>(other).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(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<JSStringImpl>(from).wrappedExternRef,
|
||||
unsafeCast<JSStringImpl>(to).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(from).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(to).wrappedExternRef,
|
||||
),
|
||||
);
|
||||
} else if (from is EmbedderRegExp) {
|
||||
return JSStringImpl.fromRefUnchecked(
|
||||
return EmbedderStringImpl.fromRefUnchecked(
|
||||
embedder.stringReplaceAllRegExp(
|
||||
wrappedExternRef,
|
||||
from._regexp,
|
||||
unsafeCast<JSStringImpl>(to).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(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<JSStringImpl>(replacement).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(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<JSStringImpl>(other).wrappedExternRef,
|
||||
unsafeCast<EmbedderStringImpl>(other).wrappedExternRef,
|
||||
)
|
||||
.toIntSigned();
|
||||
|
||||
@@ -527,6 +524,6 @@ String _stringIdentity(String string) => string;
|
||||
|
||||
@patch
|
||||
@pragma('wasm:prefer-inline')
|
||||
JSStringImpl embedderStringFromDartString(String s) {
|
||||
return unsafeCast<JSStringImpl>(s);
|
||||
EmbedderStringImpl embedderStringFromDartString(String s) {
|
||||
return unsafeCast<EmbedderStringImpl>(s);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
|
||||
@@ -36,7 +36,7 @@ WasmVoid _invokeMain(WasmArray<WasmExternRef?> args) {
|
||||
try {
|
||||
final dartArgs = <String>[];
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
dartArgs.add(JSStringImpl.fromRefUnchecked(args[i]));
|
||||
dartArgs.add(EmbedderStringImpl.fromRefUnchecked(args[i]));
|
||||
}
|
||||
|
||||
_invokeMainInternal(dartArgs);
|
||||
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class RegExp {
|
||||
|
||||
@patch
|
||||
static String escape(String text) {
|
||||
return JSStringImpl.fromRefUnchecked(
|
||||
return EmbedderStringImpl.fromRefUnchecked(
|
||||
regexpEscape(embedderStringFromDartString(text).wrappedExternRef),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ final class _EmbedderStackTrace implements StackTrace {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return JSStringImpl.fromRefUnchecked(
|
||||
return EmbedderStringImpl.fromRefUnchecked(
|
||||
stackTraceToString(_embedderStackTrace),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,9 @@ class StringBuffer {
|
||||
|
||||
@patch
|
||||
String toString() {
|
||||
return JSStringImpl.fromRefUnchecked(stringBufferToString(_hostBuffer));
|
||||
return EmbedderStringImpl.fromRefUnchecked(
|
||||
stringBufferToString(_hostBuffer),
|
||||
);
|
||||
}
|
||||
|
||||
void _writeString(String str) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user