From 8e6a02d899ef62ef5b8405518b36340e609198e2 Mon Sep 17 00:00:00 2001 From: asiva Date: Wed, 11 Oct 2023 21:51:02 +0000 Subject: [PATCH] [vm/lib] Fix for https://github.com/dart-lang/sdk/issues/45347 TEST=new tests added Change-Id: Ic604cc9576f092c1bf96f411ae1abdea6c78c384 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329784 Reviewed-by: Ben Konyi Commit-Queue: Siva Annamalai --- pkg/dartdev/test/commands/compile_test.dart | 37 +++++++++++++++++++++ sdk/lib/_internal/vm/lib/developer.dart | 2 +- sdk/lib/_internal/vm/lib/isolate_patch.dart | 2 +- tests/standalone/regress_45347.dart | 29 ++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/standalone/regress_45347.dart diff --git a/pkg/dartdev/test/commands/compile_test.dart b/pkg/dartdev/test/commands/compile_test.dart index 0a0cb93e710..92c8eea1b82 100644 --- a/pkg/dartdev/test/commands/compile_test.dart +++ b/pkg/dartdev/test/commands/compile_test.dart @@ -374,6 +374,43 @@ void defineCompileTests() { expect(result.stdout, contains('42')); }, skip: isRunningOnIA32); + test('Regression test for https://github.com/dart-lang/sdk/issues/45347', + () async { + final p = project(mainSrc: ''' + import "dart:developer"; + import "dart:isolate"; + void main() { + final id = Service.getIsolateId(Isolate.current)?? "NA"; + } + '''); + final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath)); + final outFile = path.canonicalize(path.join(p.dirPath, 'myexe')); + + var result = await p.run( + [ + 'compile', + 'exe', + '-v', + '-o', + outFile, + inFile, + ], + ); + + expect(result.stderr, isEmpty); + expect(result.exitCode, 0); + expect(File(outFile).existsSync(), true, + reason: 'File not found: $outFile'); + + result = Process.runSync( + outFile, + [], + ); + + expect(result.stderr, isEmpty); + expect(result.exitCode, 0); + }, skip: isRunningOnIA32); + test('Compile executable cannot compile cross-OS', () async { final p = project( mainSrc: 'void main() {print(const String.fromEnvironment("cross"));}'); diff --git a/sdk/lib/_internal/vm/lib/developer.dart b/sdk/lib/_internal/vm/lib/developer.dart index 5e373ad0785..89104a9ff14 100644 --- a/sdk/lib/_internal/vm/lib/developer.dart +++ b/sdk/lib/_internal/vm/lib/developer.dart @@ -178,7 +178,7 @@ external void _webServerControl( @patch @pragma("vm:external-name", "Developer_getIsolateIdFromSendPort") -external String _getIsolateIdFromSendPort(SendPort sendPort); +external String? _getIsolateIdFromSendPort(SendPort sendPort); @patch @pragma("vm:external-name", "Developer_getObjectId") diff --git a/sdk/lib/_internal/vm/lib/isolate_patch.dart b/sdk/lib/_internal/vm/lib/isolate_patch.dart index 40a5ea86e37..c2f522bc629 100644 --- a/sdk/lib/_internal/vm/lib/isolate_patch.dart +++ b/sdk/lib/_internal/vm/lib/isolate_patch.dart @@ -535,7 +535,7 @@ final class Isolate { external static void _sendOOB(port, msg); @pragma("vm:external-name", "Isolate_getDebugName") - external static String _getDebugName(SendPort controlPort); + external static String? _getDebugName(SendPort controlPort); @patch void _pause(Capability resumeCapability) { diff --git a/tests/standalone/regress_45347.dart b/tests/standalone/regress_45347.dart new file mode 100644 index 00000000000..7bb0cffd38b --- /dev/null +++ b/tests/standalone/regress_45347.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Regression test for https://github.com/dart-lang/sdk/issues/45347 + +import 'dart:developer'; +import 'dart:isolate'; +import "package:expect/expect.dart"; + +void sendSetOfEnums(SendPort port) { + Isolate childIsolate = Isolate.current; + port.send(childIsolate); +} + +void main() async { + try { + final id = Service.getIsolateId(Isolate.current) ?? "NA"; + print(id); + + final port = ReceivePort(); + await Isolate.spawn(sendSetOfEnums, port.sendPort); + Isolate childIsolate = await port.first; + final did = childIsolate.debugName ?? "NA"; + print(did); + } catch (e, s) { + Expect.isTrue(false); + } +}