Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit dc20e31

Browse files
author
Dart CI
committed
Version 2.19.0-342.0.dev
Merge 7e87efd into dev
2 parents bda27e5 + 7e87efd commit dc20e31

File tree

6 files changed

+65
-54
lines changed

6 files changed

+65
-54
lines changed

pkg/dart2wasm/lib/dynamic_dispatch.dart

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ class DynamicDispatcher {
164164
w.Instructions b = function.body;
165165
w.Local addLocal(w.ValueType type) => function.addLocal(type);
166166

167-
Iterable<SelectorInfo>? selectors =
168-
translator.dispatchTable.selectorsForDynamicNode(node);
167+
// We make a copy of the list of selectors to avoid concurrent
168+
// modification.
169+
List<SelectorInfo> selectors =
170+
translator.dispatchTable.selectorsForDynamicNode(node)?.toList() ?? [];
169171

170172
// Test the receiver's class ID against every class that implements a given
171173
// selector. If there is a match then invoke the selector, otherwise calls
@@ -179,47 +181,43 @@ class DynamicDispatcher {
179181
b.local_get(receiverVar);
180182
b.struct_get(translator.topInfo.struct, FieldIndex.classId);
181183
b.local_set(cidLocal);
182-
if (selectors != null) {
183-
// We make a copy of the list of selectors to avoid concurrent
184-
// modification.
185-
for (SelectorInfo selector in selectors.toList()) {
186-
if (!preSelector(selector)) {
187-
continue;
188-
}
189-
translator.functions.activateSelector(selector);
190-
for (int classID in selector.classIds) {
191-
b.local_get(cidLocal);
192-
b.i32_const(classID);
193-
b.i32_eq();
194-
b.if_();
195-
196-
// TODO(joshualitt): We should be able to make this a direct
197-
// invocation. However, there appear to be corner cases today where we
198-
// still need to do the actual invocation as an indirect call, for
199-
// example if the procedure we are invoking is abstract.
200-
b.comment("Dynamic invocation of '${selector.name}'");
201-
b.local_get(receiverVar);
202-
translator.convertType(function, translator.topInfo.nullableType,
203-
selector.signature.inputs[0]);
204-
205-
pushArguments(selector);
206-
b.local_get(cidLocal);
207-
int offset = selector.offset!;
208-
if (offset != 0) {
209-
b.i32_const(offset);
210-
b.i32_add();
211-
}
212-
b.call_indirect(selector.signature);
213-
214-
w.ValueType result =
215-
translator.outputOrVoid(selector.signature.outputs);
216-
translator.convertType(
217-
function, result, translator.topInfo.nullableType);
218-
onCallSuccess();
219-
b.end(); // end if
184+
for (SelectorInfo selector in selectors) {
185+
if (!preSelector(selector)) {
186+
continue;
187+
}
188+
translator.functions.activateSelector(selector);
189+
for (int classID in selector.classIds) {
190+
b.local_get(cidLocal);
191+
b.i32_const(classID);
192+
b.i32_eq();
193+
b.if_();
194+
195+
// TODO(joshualitt): We should be able to make this a direct
196+
// invocation. However, there appear to be corner cases today where we
197+
// still need to do the actual invocation as an indirect call, for
198+
// example if the procedure we are invoking is abstract.
199+
b.comment("Dynamic invocation of '${selector.name}'");
200+
b.local_get(receiverVar);
201+
translator.convertType(function, translator.topInfo.nullableType,
202+
selector.signature.inputs[0]);
203+
204+
pushArguments(selector);
205+
b.local_get(cidLocal);
206+
int offset = selector.offset!;
207+
if (offset != 0) {
208+
b.i32_const(offset);
209+
b.i32_add();
220210
}
221-
postSelector();
211+
b.call_indirect(selector.signature);
212+
213+
w.ValueType result =
214+
translator.outputOrVoid(selector.signature.outputs);
215+
translator.convertType(
216+
function, result, translator.topInfo.nullableType);
217+
onCallSuccess();
218+
b.end(); // end if
222219
}
220+
postSelector();
223221
}
224222

225223
// Handle the case where no test succeeded.

sdk/lib/_internal/wasm/lib/class_id.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class ClassID {
2222
external static int get cidFunction;
2323
@pragma("wasm:class-id", "dart.core#_Function")
2424
external static int get cid_Function;
25+
@pragma("wasm:class-id", "dart.core#_List")
26+
external static int get cidFixedLengthList;
27+
@pragma("wasm:class-id", "dart.core#_ListBase")
28+
external static int get cidListBase;
29+
@pragma("wasm:class-id", "dart.core#_GrowableList")
30+
external static int get cidGrowableList;
31+
@pragma("wasm:class-id", "dart.core#_ImmutableList")
32+
external static int get cidImmutableList;
2533

2634
// Class IDs for RTI Types.
2735
@pragma("wasm:class-id", "dart.core#_NeverType")

sdk/lib/_internal/wasm/lib/errors_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ external Never _throwObjectWithStackTrace(Object error, StackTrace stacktrace);
1010
class Error {
1111
@patch
1212
static String _objectToString(Object object) {
13-
return 'Instance of ${object._runtimeType}';
13+
return "Instance of '${object._runtimeType}'";
1414
}
1515

1616
@patch

sdk/lib/_internal/wasm/lib/list.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ abstract class _ListBase<E> extends ListBase<E> {
1818
_ListBase._withData(this._length, this._data);
1919

2020
E operator [](int index) {
21+
RangeError.checkValidIndex(index, this, "[]", _length);
2122
return unsafeCast(_data.read(index));
2223
}
2324

@@ -51,6 +52,7 @@ abstract class _ModifiableList<E> extends _ListBase<E> {
5152
: super._withData(length, data);
5253

5354
void operator []=(int index, E value) {
55+
RangeError.checkValidIndex(index, this, "[]=", _length);
5456
_data.write(index, value);
5557
}
5658

sdk/lib/_internal/wasm/lib/string_patch.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,18 @@ abstract class _StringBase implements String {
125125
static String createFromCharCodes(
126126
Iterable<int> charCodes, int start, int? end, int? limit) {
127127
// TODO(srdjan): Also skip copying of wide typed arrays.
128-
if (charCodes is Uint8List) {
129-
final actualEnd =
130-
RangeError.checkValidRange(start, end, charCodes.length);
131-
return _createOneByteString(charCodes, start, actualEnd - start);
132-
} else if (charCodes is! Uint16List) {
133-
return _createStringFromIterable(charCodes, start, end);
128+
final ccid = ClassID.getID(charCodes);
129+
if (ccid != ClassID.cidFixedLengthList &&
130+
ccid != ClassID.cidListBase &&
131+
ccid != ClassID.cidGrowableList &&
132+
ccid != ClassID.cidImmutableList) {
133+
if (charCodes is Uint8List) {
134+
final actualEnd =
135+
RangeError.checkValidRange(start, end, charCodes.length);
136+
return _createOneByteString(charCodes, start, actualEnd - start);
137+
} else if (charCodes is! Uint16List) {
138+
return _createStringFromIterable(charCodes, start, end);
139+
}
134140
}
135141
final int codeCount = charCodes.length;
136142
final actualEnd = RangeError.checkValidRange(start, end, codeCount);
@@ -172,11 +178,8 @@ abstract class _StringBase implements String {
172178
if (charCodes is EfficientLengthIterable) {
173179
int length = charCodes.length;
174180
final endVal = RangeError.checkValidRange(start, end, length);
175-
final Uint16List charCodeList = Uint16List(endVal - start);
176-
int i = 0;
177-
for (final char in charCodes.take(endVal).skip(start)) {
178-
charCodeList[i++] = char;
179-
}
181+
final charCodeList =
182+
List<int>.from(charCodes.take(endVal).skip(start), growable: false);
180183
return createFromCharCodes(charCodeList, 0, charCodeList.length, null);
181184
}
182185
// Don't know length of iterable, so iterate and see if all the values

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 19
2929
PATCH 0
30-
PRERELEASE 341
30+
PRERELEASE 342
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)