[ Service ] Test constructor tearoffs through VM service

Fixes #46240

TEST=runtime/observatory/tests/service/constructor_tear_off_test.dart

Change-Id: I335b16106db89dfede10d2ba3b73676465b306bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212627
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Ben Konyi 2021-09-14 17:14:31 +00:00 committed by commit-bot@chromium.org
parent b113bd154b
commit b1491fc43e
3 changed files with 74 additions and 2 deletions

View file

@ -41,5 +41,5 @@ abstract class LibraryDependency {
LibraryRef get target;
/// [optional]
String get prefix;
String? get prefix;
}

View file

@ -2479,7 +2479,7 @@ class Breakpoint extends ServiceObject implements M.Breakpoint {
class LibraryDependency implements M.LibraryDependency {
final bool isImport;
final bool isDeferred;
final String prefix;
final String? prefix;
final Library target;
bool get isExport => !isImport;

View file

@ -0,0 +1,72 @@
// Copyright (c) 2021, 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.
// @dart=2.15
// SharedOptions=--enable-experiment=constructor-tearoffs
import 'package:observatory/service_common.dart';
import 'package:test/test.dart';
import 'test_helper.dart';
class Foo {
Foo();
Foo.named();
}
class Generic<T> {
Generic();
}
@pragma('vm:entry-point')
Function getNamedConstructorTearoff() => Foo.named;
@pragma('vm:entry-point')
Function getDefaultConstructorTearoff() => Foo.new;
@pragma('vm:entry-point')
Function getGenericConstructorTearoff() => Generic<int>.new;
Future<void> invokeConstructorTearoff(
Isolate isolate,
String name,
String expectedType,
) async {
final lib = await isolate.rootLibrary.load() as Library;
final tearoff = await isolate.invokeRpc('invoke', {
'targetId': lib.id,
'selector': name,
'argumentIds': [],
});
final result = await isolate.invokeRpc('invoke', {
'targetId': tearoff.id,
'selector': 'call',
'argumentIds': [],
}) as Instance;
expect(result.clazz!.name, expectedType);
}
final tests = <IsolateTest>[
(Isolate isolate) => invokeConstructorTearoff(
isolate,
'getNamedConstructorTearoff',
'Foo',
),
(Isolate isolate) => invokeConstructorTearoff(
isolate,
'getDefaultConstructorTearoff',
'Foo',
),
(Isolate isolate) => invokeConstructorTearoff(
isolate,
'getGenericConstructorTearoff',
'Generic',
),
];
void main(List<String> args) => runIsolateTests(
args,
tests,
);