Skip to content

Commit

Permalink
Version 3.5.0-66.0.dev
Browse files Browse the repository at this point in the history
Merge 7328c46 into dev
  • Loading branch information
Dart CI committed Apr 16, 2024
2 parents 99928bb + 7328c46 commit f2464b2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ vars = {
# self-service update these by following the go/dart-engprod/browsers.md
# instructions. d8, the V8 shell, is always checked out.
"checkout_javascript_engines": False,
"d8_tag": "version:12.3.150",
"d8_tag": "version:12.5.216",
"jsshell_tag": "version:122.0",
"jsc_tag": "version:274355",

Expand Down
25 changes: 25 additions & 0 deletions pkg/front_end/test/vm_service_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class VMServiceHelper {

Future<bool> waitUntilPaused(String isolateId) async {
int nulls = 0;
int tries = 0;
while (true) {
tries++;
bool? result = await isPaused(isolateId);
if (result == null) {
nulls++;
Expand All @@ -69,11 +71,34 @@ class VMServiceHelper {
} else if (result) {
return true;
} else {
if (tries > 50) {
// Waited 5+ seconds --- check if some isolate is paused at start
// and resume if it is. This is for instance the case with macros.
await _resumeAllPausedAtStartIsolates();
tries = 0;
}
await Future.delayed(const Duration(milliseconds: 100));
}
}
}

Future<void> _resumeAllPausedAtStartIsolates() async {
vmService.VM vm = await serviceClient.getVM();
for (vmService.IsolateRef isolateRef in vm.isolates!) {
try {
String? id = isolateRef.id;
if (id == null) continue;
vmService.Isolate isolate = await _serviceClient.getIsolate(id);
if (isolate.pauseEvent?.kind == "PauseStart") {
print("Found isolate paused at start - resuming it.");
await serviceClient.resume(id);
}
} catch (e) {
// It might exit at some point so we can't expect to get a good result.
}
}
}

Future<bool?> isPaused(String isolateId) async {
vmService.Isolate isolate = await _serviceClient.getIsolate(isolateId);
String? kind = isolate.pauseEvent!.kind;
Expand Down
102 changes: 55 additions & 47 deletions sdk/lib/_internal/wasm/lib/js_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,66 +441,74 @@ final class JSStringImpl implements String {
return index;
}

// We can't use JS `trim` as we need to return the argument if it doesn't
// have any whitespace to trim. JS `trim` also doesn't handle NEL.
// dart2wasm can't use JavaScript trim directly,
// because JavaScript does not trim
// the NEXT LINE (NEL) character (0x85).
@override
String trim() {
final len = this.length;
final first = firstNonWhitespace();
if (len == first) {
// String contains only whitespaces.
return "";
// Start by doing JS trim. Then check if it leaves a NEL at
// either end of the string.
final result =
JSStringImpl(js.JS<WasmExternRef?>('s => s.trim()', toExternRef));
final resultLength = result.length;
if (resultLength == 0) return result;
int firstCode = result._codeUnitAtUnchecked(0);
int startIndex = 0;
if (firstCode == nelCodeUnit) {
startIndex = _skipLeadingWhitespace(result, 1);
if (startIndex == resultLength) return "";
}
final last = lastNonWhitespace() + 1;
if (first == 0 && last == len) {
// Returns this string since it does not have leading or trailing
// whitespaces.
return this;

int endIndex = resultLength;
// We know that there is at least one character that is non-whitespace.
// Therefore we don't need to verify that endIndex > startIndex.
int lastCode = result.codeUnitAt(endIndex - 1);
if (lastCode == nelCodeUnit) {
endIndex = _skipTrailingWhitespace(result, endIndex - 1);
}
return JSStringImpl(_jsSubstring(toExternRef, first, last));
if (startIndex == 0 && endIndex == resultLength) return result;
return substring(startIndex, endIndex);
}

// Same as `trim`, we can't use JS `trimLeft`.
// dart2wasm can't use JavaScript trimLeft directly because it does not trim
// the NEXT LINE character (0x85).
@override
String trimLeft() {
final len = length;
int first = 0;
for (; first < len; first++) {
if (!_isWhitespace(codeUnitAt(first))) {
break;
}
}
if (len == first) {
// String contains only whitespaces.
return "";
}
if (first == 0) {
// Returns this string since it does not have leading or trailing
// whitespaces.
return this;
// Start by doing JS trim. Then check if it leaves a NEL at
// the beginning of the string.
int startIndex = 0;
final result =
JSStringImpl(js.JS<WasmExternRef?>('s => s.trimLeft()', toExternRef));
final resultLength = result.length;
if (resultLength == 0) return result;
int firstCode = result._codeUnitAtUnchecked(0);
if (firstCode == nelCodeUnit) {
startIndex = _skipLeadingWhitespace(result, 1);
}
return JSStringImpl(_jsSubstring(toExternRef, first, len));
if (startIndex == 0) return result;
if (startIndex == resultLength) return "";
return result.substring(startIndex);
}

// Same as `trim`, we can't use JS `trimRight`.
// dart2wasm can't use JavaScript trimRight directly because it does not trim
// the NEXT LINE character (0x85).
@override
String trimRight() {
final len = length;
int last = len - 1;
for (; last >= 0; last--) {
if (!_isWhitespace(codeUnitAt(last))) {
break;
}
}
if (last == -1) {
// String contains only whitespaces.
return "";
}
if (last == (len - 1)) {
// Returns this string since it does not have trailing whitespaces.
return this;
}
return JSStringImpl(_jsSubstring(toExternRef, 0, last + 1));
// Start by doing JS trim. Then check if it leaves a NEL at the end of the
// string.
final result =
JSStringImpl(js.JS<WasmExternRef?>('s => s.trimRight()', toExternRef));
final resultLength = result.length;
int endIndex = resultLength;
if (endIndex == 0) return result;
int lastCode = result.codeUnitAt(endIndex - 1);
if (lastCode == nelCodeUnit) {
endIndex = _skipTrailingWhitespace(result, endIndex - 1);
}

if (endIndex == resultLength) return result;
if (endIndex == 0) return "";
return result.substring(0, endIndex);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 5
PATCH 0
PRERELEASE 65
PRERELEASE 66
PRERELEASE_PATCH 0

0 comments on commit f2464b2

Please sign in to comment.