Skip to content

Commit 24e65be

Browse files
derekxu16Commit Queue
authored and
Commit Queue
committed
[VM/Service] Add isGetter and isSetter properties to @function and Function
TEST=pkg/vm_service/test/get_object_rpc_test.dart and vm/cc/PrintJSONPrimitives Fixes: #52920 Change-Id: Id3786e48c8827911e7c49af6ab2f0bf0cd97279f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313642 Reviewed-by: Ben Konyi <[email protected]>
1 parent ce5210b commit 24e65be

File tree

10 files changed

+156
-27
lines changed

10 files changed

+156
-27
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=4.10
1+
version=4.11

pkg/vm_service/lib/src/vm_service.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export 'snapshot_graph.dart'
2828
HeapSnapshotObjectNoData,
2929
HeapSnapshotObjectNullData;
3030

31-
const String vmServiceVersion = '4.10.0';
31+
const String vmServiceVersion = '4.11.0';
3232

3333
/// @optional
3434
const String optional = 'optional';
@@ -5087,6 +5087,12 @@ class FuncRef extends ObjRef {
50875087
/// Is this function an abstract method?
50885088
bool? isAbstract;
50895089

5090+
/// Is this function a getter?
5091+
bool? isGetter;
5092+
5093+
/// Is this function a setter?
5094+
bool? isSetter;
5095+
50905096
/// The location of this function in the source code.
50915097
///
50925098
/// Note: this may not agree with the location of `owner` if this is a
@@ -5102,6 +5108,8 @@ class FuncRef extends ObjRef {
51025108
this.isConst,
51035109
this.implicit,
51045110
this.isAbstract,
5111+
this.isGetter,
5112+
this.isSetter,
51055113
required String id,
51065114
this.location,
51075115
}) : super(
@@ -5116,6 +5124,8 @@ class FuncRef extends ObjRef {
51165124
isConst = json['const'] ?? false;
51175125
implicit = json['implicit'] ?? false;
51185126
isAbstract = json['abstract'] ?? false;
5127+
isGetter = json['isGetter'] ?? false;
5128+
isSetter = json['isSetter'] ?? false;
51195129
location = createServiceObject(json['location'], const ['SourceLocation'])
51205130
as SourceLocation?;
51215131
}
@@ -5134,6 +5144,8 @@ class FuncRef extends ObjRef {
51345144
'const': isConst ?? false,
51355145
'implicit': implicit ?? false,
51365146
'abstract': isAbstract ?? false,
5147+
'isGetter': isGetter ?? false,
5148+
'isSetter': isSetter ?? false,
51375149
});
51385150
_setIfNotNull(json, 'location', location?.toJson());
51395151
return json;
@@ -5146,9 +5158,7 @@ class FuncRef extends ObjRef {
51465158
bool operator ==(Object other) => other is FuncRef && id == other.id;
51475159

51485160
@override
5149-
String toString() => '[FuncRef ' //
5150-
'id: $id, name: $name, owner: $owner, isStatic: $isStatic, ' //
5151-
'isConst: $isConst, implicit: $implicit, isAbstract: $isAbstract]';
5161+
String toString() => '[FuncRef]';
51525162
}
51535163

51545164
/// A `Func` represents a Dart language function.
@@ -5186,6 +5196,14 @@ class Func extends Obj implements FuncRef {
51865196
@override
51875197
bool? isAbstract;
51885198

5199+
/// Is this function a getter?
5200+
@override
5201+
bool? isGetter;
5202+
5203+
/// Is this function a setter?
5204+
@override
5205+
bool? isSetter;
5206+
51895207
/// The location of this function in the source code.
51905208
///
51915209
/// Note: this may not agree with the location of `owner` if this is a
@@ -5209,6 +5227,8 @@ class Func extends Obj implements FuncRef {
52095227
this.isConst,
52105228
this.implicit,
52115229
this.isAbstract,
5230+
this.isGetter,
5231+
this.isSetter,
52125232
this.signature,
52135233
required String id,
52145234
this.location,
@@ -5225,6 +5245,8 @@ class Func extends Obj implements FuncRef {
52255245
isConst = json['const'] ?? false;
52265246
implicit = json['implicit'] ?? false;
52275247
isAbstract = json['abstract'] ?? false;
5248+
isGetter = json['isGetter'] ?? false;
5249+
isSetter = json['isSetter'] ?? false;
52285250
location = createServiceObject(json['location'], const ['SourceLocation'])
52295251
as SourceLocation?;
52305252
signature = createServiceObject(json['signature'], const ['InstanceRef'])
@@ -5246,6 +5268,8 @@ class Func extends Obj implements FuncRef {
52465268
'const': isConst ?? false,
52475269
'implicit': implicit ?? false,
52485270
'abstract': isAbstract ?? false,
5271+
'isGetter': isGetter ?? false,
5272+
'isSetter': isSetter ?? false,
52495273
'signature': signature?.toJson(),
52505274
});
52515275
_setIfNotNull(json, 'location', location?.toJson());
@@ -5260,9 +5284,7 @@ class Func extends Obj implements FuncRef {
52605284
bool operator ==(Object other) => other is Func && id == other.id;
52615285

52625286
@override
5263-
String toString() => '[Func ' //
5264-
'id: $id, name: $name, owner: $owner, isStatic: $isStatic, ' //
5265-
'isConst: $isConst, implicit: $implicit, isAbstract: $isAbstract, signature: $signature]';
5287+
String toString() => '[Func]';
52665288
}
52675289

52685290
/// `InstanceRef` is a reference to an `Instance`.

pkg/vm_service/test/get_object_rpc_test.dart

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ base class _DummyClass extends _DummyAbstractBaseClass {
2727
static var dummyVarWithInit = foo();
2828
late String dummyLateVarWithInit = 'bar';
2929
late String dummyLateVar;
30+
int get dummyVarGetter => dummyVar;
31+
set dummyVarSetter(int value) => dummyVar = value;
3032
@override
3133
void dummyFunction(int a, [bool b = false]) {}
3234
void dummyGenericFunction<K, V>(K a, {required V param}) {}
@@ -904,7 +906,7 @@ var tests = <IsolateTest>[
904906
expect(result.interfaces!.length, 0);
905907
expect(result.mixin, isNull);
906908
expect(result.fields!.length, 5);
907-
expect(result.functions!.length, 10);
909+
expect(result.functions!.length, 12);
908910
expect(result.subclasses!.length, 2);
909911
final json = result.json!;
910912
expect(json['_vmName'], startsWith('_DummyClass@'));
@@ -1262,7 +1264,8 @@ var tests = <IsolateTest>[
12621264
(VmService service, IsolateRef isolateRef) async {
12631265
final isolateId = isolateRef.id!;
12641266
final isolate = await service.getIsolate(isolateId);
1265-
// Call eval to get a class id.
1267+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1268+
// [classRef] field to build a function ID.
12661269
final evalResult = await service.invoke(
12671270
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
12681271
final objectId = "${evalResult.classRef!.id!}/functions/dummyFunction";
@@ -1273,6 +1276,8 @@ var tests = <IsolateTest>[
12731276
expect(result.isConst, equals(false));
12741277
expect(result.implicit, equals(false));
12751278
expect(result.isAbstract, equals(false));
1279+
expect(result.isGetter, false);
1280+
expect(result.isSetter, false);
12761281
final signature = result.signature!;
12771282
expect(signature.typeParameters, isNull);
12781283
expect(signature.returnType, isNotNull);
@@ -1297,7 +1302,8 @@ var tests = <IsolateTest>[
12971302
(VmService service, IsolateRef isolateRef) async {
12981303
final isolateId = isolateRef.id!;
12991304
final isolate = await service.getIsolate(isolateId);
1300-
// Call eval to get a class id.
1305+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1306+
// [classRef] field to build a function ID.
13011307
final evalResult = await service.invoke(
13021308
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
13031309
final objectId =
@@ -1309,6 +1315,8 @@ var tests = <IsolateTest>[
13091315
expect(result.isConst, equals(false));
13101316
expect(result.implicit, equals(false));
13111317
expect(result.isAbstract, equals(false));
1318+
expect(result.isGetter, false);
1319+
expect(result.isSetter, false);
13121320
final signature = result.signature!;
13131321
expect(signature.typeParameters!.length, 2);
13141322
expect(signature.returnType, isNotNull);
@@ -1362,6 +1370,8 @@ var tests = <IsolateTest>[
13621370
expect(funcResult.isConst, equals(false));
13631371
expect(funcResult.implicit, equals(false));
13641372
expect(funcResult.isAbstract, equals(true));
1373+
expect(funcResult.isGetter, false);
1374+
expect(funcResult.isSetter, false);
13651375
final signature = funcResult.signature!;
13661376
expect(signature.typeParameters, isNull);
13671377
expect(signature.returnType, isNotNull);
@@ -1421,11 +1431,84 @@ var tests = <IsolateTest>[
14211431
expect(json['_guardLength'], isNotNull);
14221432
},
14231433

1434+
// getter
1435+
(VmService service, IsolateRef isolateRef) async {
1436+
final isolateId = isolateRef.id!;
1437+
final isolate = await service.getIsolate(isolateId);
1438+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1439+
// [classRef] field to build a function ID.
1440+
final evalResult = await service.invoke(
1441+
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
1442+
final objectId =
1443+
"${evalResult.classRef!.id!}/functions/get${Uri.encodeComponent(':')}dummyVarGetter";
1444+
final result = await service.getObject(isolateId, objectId) as Func;
1445+
expect(result.id, objectId);
1446+
expect(result.name, 'dummyVarGetter');
1447+
expect(result.isStatic, false);
1448+
expect(result.isConst, false);
1449+
expect(result.implicit, false);
1450+
expect(result.isAbstract, false);
1451+
expect(result.isGetter, true);
1452+
expect(result.isSetter, false);
1453+
final signature = result.signature!;
1454+
expect(signature.typeParameters, isNull);
1455+
expect(signature.returnType, isNotNull);
1456+
final parameters = signature.parameters!;
1457+
expect(parameters.length, 1);
1458+
expect(result.location, isNotNull);
1459+
expect(result.code, isNotNull);
1460+
final json = result.json!;
1461+
expect(json['_kind'], 'GetterFunction');
1462+
expect(json['_optimizable'], true);
1463+
expect(json['_inlinable'], true);
1464+
expect(json['_usageCounter'], 0);
1465+
expect(json['_optimizedCallSiteCount'], 0);
1466+
expect(json['_deoptimizations'], 0);
1467+
},
1468+
1469+
// setter
1470+
(VmService service, IsolateRef isolateRef) async {
1471+
final isolateId = isolateRef.id!;
1472+
final isolate = await service.getIsolate(isolateId);
1473+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1474+
// [classRef] field to build a function ID.
1475+
final evalResult = await service.invoke(
1476+
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
1477+
final objectId =
1478+
"${evalResult.classRef!.id!}/functions/set${Uri.encodeComponent(':')}dummyVarSetter";
1479+
final result = await service.getObject(isolateId, objectId) as Func;
1480+
expect(result.id, objectId);
1481+
expect(result.name, 'dummyVarSetter=');
1482+
expect(result.isStatic, false);
1483+
expect(result.isConst, false);
1484+
expect(result.implicit, false);
1485+
expect(result.isAbstract, false);
1486+
expect(result.isGetter, false);
1487+
expect(result.isSetter, true);
1488+
final signature = result.signature!;
1489+
expect(signature.typeParameters, isNull);
1490+
expect(signature.returnType, isNotNull);
1491+
final parameters = signature.parameters!;
1492+
expect(parameters.length, 2);
1493+
expect(parameters[1].parameterType!.name, equals('int'));
1494+
expect(parameters[1].fixed, isTrue);
1495+
expect(result.location, isNotNull);
1496+
expect(result.code, isNotNull);
1497+
final json = result.json!;
1498+
expect(json['_kind'], 'SetterFunction');
1499+
expect(json['_optimizable'], true);
1500+
expect(json['_inlinable'], true);
1501+
expect(json['_usageCounter'], 0);
1502+
expect(json['_optimizedCallSiteCount'], 0);
1503+
expect(json['_deoptimizations'], 0);
1504+
},
1505+
14241506
// static field initializer
14251507
(VmService service, IsolateRef isolateRef) async {
14261508
final isolateId = isolateRef.id!;
14271509
final isolate = await service.getIsolate(isolateId);
1428-
// Call eval to get a class id.
1510+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1511+
// [classRef] field to build a function ID.
14291512
final evalResult = await service.invoke(
14301513
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
14311514
final objectId = "${evalResult.classRef!.id!}/field_inits/dummyVarWithInit";
@@ -1436,6 +1519,8 @@ var tests = <IsolateTest>[
14361519
expect(result.isConst, equals(false));
14371520
expect(result.implicit, equals(false));
14381521
expect(result.isAbstract, equals(false));
1522+
expect(result.isGetter, false);
1523+
expect(result.isSetter, false);
14391524
final signature = result.signature!;
14401525
expect(signature.typeParameters, isNull);
14411526
expect(signature.returnType, isNotNull);
@@ -1455,7 +1540,8 @@ var tests = <IsolateTest>[
14551540
(VmService service, IsolateRef isolateRef) async {
14561541
final isolateId = isolateRef.id!;
14571542
final isolate = await service.getIsolate(isolateId);
1458-
// Call eval to get a class id.
1543+
// Call [invoke] to get an [InstanceRef], and then use the ID of its
1544+
// [classRef] field to build a function ID.
14591545
final evalResult = await service.invoke(
14601546
isolateId, isolate.rootLib!.id!, 'getDummyClass', []) as InstanceRef;
14611547
final objectId =
@@ -1467,6 +1553,8 @@ var tests = <IsolateTest>[
14671553
expect(result.isConst, equals(false));
14681554
expect(result.implicit, equals(false));
14691555
expect(result.isAbstract, equals(false));
1556+
expect(result.isGetter, false);
1557+
expect(result.isSetter, false);
14701558
final signature = result.signature!;
14711559
expect(signature.typeParameters, isNull);
14721560
expect(signature.returnType, isNotNull);
@@ -1547,9 +1635,11 @@ var tests = <IsolateTest>[
15471635
final isolateId = isolateRef.id!;
15481636
final isolate = await service.getIsolate(isolateId);
15491637
// Call eval to get a UserTag id.
1550-
final evalResult = await service.invoke(
1551-
isolateId, isolate.rootLib!.id!, 'getUserTag', []) as InstanceRef;
1552-
final result = await service.getObject(isolateId, evalResult.id!) as Instance;
1638+
final evalResult =
1639+
await service.invoke(isolateId, isolate.rootLib!.id!, 'getUserTag', [])
1640+
as InstanceRef;
1641+
final result =
1642+
await service.getObject(isolateId, evalResult.id!) as Instance;
15531643
expect(result.label, equals('Test Tag'));
15541644
},
15551645

runtime/observatory/tests/service/get_version_rpc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var tests = <VMTest>[
1212
final result = await vm.invokeRpcNoUpgrade('getVersion', {});
1313
expect(result['type'], 'Version');
1414
expect(result['major'], 4);
15-
expect(result['minor'], 10);
15+
expect(result['minor'], 11);
1616
expect(result['_privateMajor'], 0);
1717
expect(result['_privateMinor'], 0);
1818
},

runtime/observatory_2/tests/service_2/get_version_rpc_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var tests = <VMTest>[
1212
final result = await vm.invokeRpcNoUpgrade('getVersion', {});
1313
expect(result['type'], equals('Version'));
1414
expect(result['major'], equals(4));
15-
expect(result['minor'], equals(10));
15+
expect(result['minor'], equals(11));
1616
expect(result['_privateMajor'], equals(0));
1717
expect(result['_privateMinor'], equals(0));
1818
},

runtime/vm/object_service.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ void Function::PrintJSONImpl(JSONStream* stream, bool ref) const {
371371
jsobj.AddProperty("abstract", is_abstract());
372372
jsobj.AddProperty("_intrinsic", is_intrinsic());
373373
jsobj.AddProperty("_native", is_native());
374+
jsobj.AddProperty("isGetter", kind() == UntaggedFunction::kGetterFunction);
375+
jsobj.AddProperty("isSetter", kind() == UntaggedFunction::kSetterFunction);
374376

375377
const Script& script = Script::Handle(this->script());
376378
if (!script.IsNull()) {

runtime/vm/object_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6085,8 +6085,8 @@ ISOLATE_UNIT_TEST_CASE(PrintJSONPrimitives) {
60856085
"\"name\":\"dart.core\",\"uri\":\"dart:core\"}},"
60866086
"\"_kind\":\"RegularFunction\",\"static\":false,\"const\":false,"
60876087
"\"implicit\":false,\"abstract\":false,"
6088-
"\"_intrinsic\":false,\"_native\":false,"
6089-
"\"location\":{\"type\":\"SourceLocation\","
6088+
"\"_intrinsic\":false,\"_native\":false,\"isGetter\":false,"
6089+
"\"isSetter\":false,\"location\":{\"type\":\"SourceLocation\","
60906090
"\"script\":{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
60916091
"\"uri\":\"dart:core\\/bool.dart\",\"_kind\":\"kernel\"}}}",
60926092
buffer);

runtime/vm/service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace dart {
1818

1919
#define SERVICE_PROTOCOL_MAJOR_VERSION 4
20-
#define SERVICE_PROTOCOL_MINOR_VERSION 10
20+
#define SERVICE_PROTOCOL_MINOR_VERSION 11
2121

2222
class Array;
2323
class EmbedderServiceHandler;

0 commit comments

Comments
 (0)