Skip to content

Commit b07b710

Browse files
[lib] Be explicit about the type parameter for positional argument lists.
Widen `reflect` and `setField` to accept dynamic. `Object` will soon no longer be a top type, and dynamic is more consistent with other reflective inputs and `reflectee`. Bug: #40045 Change-Id: Ic1e3a26aaea5de078cc616846cb52417c7975d11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132720 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent 5581307 commit b07b710

File tree

12 files changed

+35
-52
lines changed

12 files changed

+35
-52
lines changed

sdk/lib/_internal/js_dev_runtime/patch/mirrors_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MirrorSystem {
3131
MirrorSystem currentMirrorSystem() => js.currentJsMirrorSystem;
3232

3333
@patch
34-
InstanceMirror reflect(Object reflectee) => js.reflect(reflectee);
34+
InstanceMirror reflect(dynamic reflectee) => js.reflect(reflectee);
3535

3636
@patch
3737
ClassMirror reflectClass(Type key) {

sdk/lib/_internal/js_dev_runtime/private/js_mirrors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class JsInstanceMirror extends JsObjectMirror implements InstanceMirror {
193193
return reflect(field);
194194
}
195195

196-
InstanceMirror setField(Symbol symbol, Object value) {
196+
InstanceMirror setField(Symbol symbol, dynamic value) {
197197
var name = _getMember(symbol);
198198
dart.dputMirror(reflectee, name, value);
199199
return reflect(value);
@@ -392,7 +392,7 @@ class JsClassMirror extends JsMirror implements ClassMirror {
392392
return reflect(JS('', '#[#]', dart.unwrapType(_cls), name));
393393
}
394394

395-
InstanceMirror setField(Symbol symbol, Object value) {
395+
InstanceMirror setField(Symbol symbol, dynamic value) {
396396
var name = getName(symbol);
397397
JS('', '#[#] = #', dart.unwrapType(_cls), name, value);
398398
return reflect(value);

sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const String _message = 'dart:mirrors is no longer supported for web apps';
1515
MirrorSystem currentMirrorSystem() => throw new UnsupportedError(_message);
1616

1717
@patch
18-
InstanceMirror reflect(Object reflectee) =>
18+
InstanceMirror reflect(dynamic reflectee) =>
1919
throw new UnsupportedError(_message);
2020

2121
@patch

sdk/lib/_internal/vm/lib/mirrors_impl.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ abstract class _ObjectMirror extends Mirror implements ObjectMirror {
223223

224224
_ObjectMirror._(this._reflectee);
225225

226-
InstanceMirror invoke(Symbol memberName, List positionalArguments,
226+
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
227227
[Map<Symbol, dynamic> namedArguments]) {
228228
int numPositionalArguments = positionalArguments.length;
229229
int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
@@ -247,7 +247,7 @@ abstract class _ObjectMirror extends Mirror implements ObjectMirror {
247247
return reflect(this._invokeGetter(_reflectee, _n(memberName)));
248248
}
249249

250-
InstanceMirror setField(Symbol memberName, Object value) {
250+
InstanceMirror setField(Symbol memberName, dynamic value) {
251251
this._invokeSetter(_reflectee, _n(memberName), value);
252252
return reflect(value);
253253
}
@@ -307,13 +307,13 @@ class _InstanceMirror extends _ObjectMirror implements InstanceMirror {
307307
return reflect(_invokeGetter(_reflectee, _n(memberName)));
308308
}
309309

310-
InstanceMirror setField(Symbol memberName, arg) {
310+
InstanceMirror setField(Symbol memberName, dynamic arg) {
311311
_invokeSetter(_reflectee, _n(memberName), arg);
312312
return reflect(arg);
313313
}
314314

315315
// Override to include the receiver in the arguments.
316-
InstanceMirror invoke(Symbol memberName, List positionalArguments,
316+
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
317317
[Map<Symbol, dynamic> namedArguments]) {
318318
int numPositionalArguments = positionalArguments.length + 1; // Receiver.
319319
int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
@@ -355,7 +355,7 @@ class _ClosureMirror extends _InstanceMirror implements ClosureMirror {
355355
return _function = _computeFunction(reflectee);
356356
}
357357

358-
InstanceMirror apply(List positionalArguments,
358+
InstanceMirror apply(List<dynamic> positionalArguments,
359359
[Map<Symbol, dynamic> namedArguments]) {
360360
return this.invoke(#call, positionalArguments, namedArguments);
361361
}
@@ -646,7 +646,8 @@ class _ClassMirror extends _ObjectMirror implements ClassMirror, _TypeMirror {
646646

647647
String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
648648

649-
InstanceMirror newInstance(Symbol constructorName, List positionalArguments,
649+
InstanceMirror newInstance(
650+
Symbol constructorName, List<dynamic> positionalArguments,
650651
[Map<Symbol, dynamic> namedArguments]) {
651652
// Native code will add the 1 or 2 implicit arguments depending on whether
652653
// we end up invoking a factory or constructor respectively.
@@ -1442,7 +1443,7 @@ class _Mirrors {
14421443
}
14431444

14441445
// Creates a new local mirror for some Object.
1445-
static InstanceMirror reflect(Object reflectee) {
1446+
static InstanceMirror reflect(dynamic reflectee) {
14461447
return reflectee is Function
14471448
? new _ClosureMirror._(reflectee)
14481449
: new _InstanceMirror._(reflectee);

sdk/lib/_internal/vm/lib/mirrors_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MirrorSystem currentMirrorSystem() {
3636
* current running isolate.
3737
*/
3838
@patch
39-
InstanceMirror reflect(Object reflectee) {
39+
InstanceMirror reflect(dynamic reflectee) {
4040
return _Mirrors.reflect(reflectee);
4141
}
4242

sdk/lib/mirrors/mirrors.dart

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ external MirrorSystem currentMirrorSystem();
151151
* function can only be used to obtain mirrors on objects of the current
152152
* isolate.
153153
*/
154-
external InstanceMirror reflect(Object reflectee);
154+
external InstanceMirror reflect(dynamic reflectee);
155155

156156
/**
157157
* Reflects a class declaration.
@@ -401,11 +401,7 @@ abstract class ObjectMirror implements Mirror {
401401
* If the invocation throws an exception *e* (that it does not catch), this
402402
* method throws *e*.
403403
*/
404-
/*
405-
* TODO(turnidge): Handle ambiguous names.
406-
* TODO(turnidge): Handle optional & named arguments.
407-
*/
408-
InstanceMirror invoke(Symbol memberName, List positionalArguments,
404+
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
409405
[Map<Symbol, dynamic> namedArguments]);
410406

411407
/**
@@ -469,8 +465,7 @@ abstract class ObjectMirror implements Mirror {
469465
* If the invocation throws an exception *e* (that it does not catch) this
470466
* method throws *e*.
471467
*/
472-
/* TODO(turnidge): Handle ambiguous names.*/
473-
InstanceMirror setField(Symbol fieldName, Object value);
468+
InstanceMirror setField(Symbol fieldName, dynamic value);
474469

475470
/**
476471
* Performs [invocation] on the reflectee of this [ObjectMirror].
@@ -529,7 +524,7 @@ abstract class InstanceMirror implements ObjectMirror {
529524
* If you access [reflectee] when [hasReflectee] is false, an
530525
* exception is thrown.
531526
*/
532-
get reflectee;
527+
dynamic get reflectee;
533528

534529
/**
535530
* Whether this mirror is equal to [other].
@@ -597,7 +592,7 @@ abstract class ClosureMirror implements InstanceMirror {
597592
* If the invocation throws an exception *e* (that it does not catch), this
598593
* method throws *e*.
599594
*/
600-
InstanceMirror apply(List positionalArguments,
595+
InstanceMirror apply(List<dynamic> positionalArguments,
601596
[Map<Symbol, dynamic> namedArguments]);
602597
}
603598

@@ -845,11 +840,6 @@ abstract class ClassMirror implements TypeMirror, ObjectMirror {
845840
*/
846841
ClassMirror get mixin;
847842

848-
// TODO(ahe): What about:
849-
// /// Finds the instance member named [name] declared or inherited in the
850-
// /// reflected class.
851-
// DeclarationMirror instanceLookup(Symbol name);
852-
853843
/**
854844
* Invokes the named constructor and returns a mirror on the result.
855845
*
@@ -878,7 +868,8 @@ abstract class ClassMirror implements TypeMirror, ObjectMirror {
878868
* * If evaluating the expression throws an exception *e* (that it does not
879869
* catch), this method throws *e*.
880870
*/
881-
InstanceMirror newInstance(Symbol constructorName, List positionalArguments,
871+
InstanceMirror newInstance(
872+
Symbol constructorName, List<dynamic> positionalArguments,
882873
[Map<Symbol, dynamic> namedArguments]);
883874

884875
/**

sdk_nnbd/lib/_internal/js_dev_runtime/patch/mirrors_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MirrorSystem {
2929
MirrorSystem currentMirrorSystem() => js.currentJsMirrorSystem;
3030

3131
@patch
32-
InstanceMirror reflect(Object reflectee) => js.reflect(reflectee);
32+
InstanceMirror reflect(dynamic reflectee) => js.reflect(reflectee);
3333

3434
@patch
3535
ClassMirror reflectClass(Type key) {

sdk_nnbd/lib/_internal/js_dev_runtime/private/js_mirrors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class JsInstanceMirror extends JsObjectMirror implements InstanceMirror {
191191
return reflect(field);
192192
}
193193

194-
InstanceMirror setField(Symbol symbol, Object value) {
194+
InstanceMirror setField(Symbol symbol, dynamic value) {
195195
var name = _getMember(symbol);
196196
dart.dputMirror(reflectee, name, value);
197197
return reflect(value);
@@ -390,7 +390,7 @@ class JsClassMirror extends JsMirror implements ClassMirror {
390390
return reflect(JS('', '#[#]', dart.unwrapType(_cls), name));
391391
}
392392

393-
InstanceMirror setField(Symbol symbol, Object value) {
393+
InstanceMirror setField(Symbol symbol, dynamic value) {
394394
var name = getName(symbol);
395395
JS('', '#[#] = #', dart.unwrapType(_cls), name, value);
396396
return reflect(value);

sdk_nnbd/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const String _message = 'dart:mirrors is no longer supported for web apps';
1313
MirrorSystem currentMirrorSystem() => throw new UnsupportedError(_message);
1414

1515
@patch
16-
InstanceMirror reflect(Object reflectee) =>
16+
InstanceMirror reflect(dynamic reflectee) =>
1717
throw new UnsupportedError(_message);
1818

1919
@patch

sdk_nnbd/lib/_internal/vm/lib/mirrors_impl.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ abstract class _ObjectMirror extends Mirror implements ObjectMirror {
245245
return reflect(this._invokeGetter(_reflectee, _n(memberName)));
246246
}
247247

248-
InstanceMirror setField(Symbol memberName, Object value) {
248+
InstanceMirror setField(Symbol memberName, dynamic value) {
249249
this._invokeSetter(_reflectee, _n(memberName), value);
250250
return reflect(value);
251251
}
@@ -305,7 +305,7 @@ class _InstanceMirror extends _ObjectMirror implements InstanceMirror {
305305
return reflect(_invokeGetter(_reflectee, _n(memberName)));
306306
}
307307

308-
InstanceMirror setField(Symbol memberName, arg) {
308+
InstanceMirror setField(Symbol memberName, dynamic arg) {
309309
_invokeSetter(_reflectee, _n(memberName), arg);
310310
return reflect(arg);
311311
}
@@ -1441,7 +1441,7 @@ class _Mirrors {
14411441
}
14421442

14431443
// Creates a new local mirror for some Object.
1444-
static InstanceMirror reflect(Object reflectee) {
1444+
static InstanceMirror reflect(dynamic reflectee) {
14451445
return reflectee is Function
14461446
? new _ClosureMirror._(reflectee)
14471447
: new _InstanceMirror._(reflectee);

sdk_nnbd/lib/_internal/vm/lib/mirrors_patch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ MirrorSystem currentMirrorSystem() {
3434
* current running isolate.
3535
*/
3636
@patch
37-
InstanceMirror reflect(Object reflectee) {
37+
InstanceMirror reflect(dynamic reflectee) {
3838
return _Mirrors.reflect(reflectee);
3939
}
4040

sdk_nnbd/lib/mirrors/mirrors.dart

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ external MirrorSystem currentMirrorSystem();
149149
* function can only be used to obtain mirrors on objects of the current
150150
* isolate.
151151
*/
152-
external InstanceMirror reflect(Object reflectee);
152+
external InstanceMirror reflect(dynamic reflectee);
153153

154154
/**
155155
* Reflects a class declaration.
@@ -400,11 +400,7 @@ abstract class ObjectMirror implements Mirror {
400400
* If the invocation throws an exception *e* (that it does not catch), this
401401
* method throws *e*.
402402
*/
403-
/*
404-
* TODO(turnidge): Handle ambiguous names.
405-
* TODO(turnidge): Handle optional & named arguments.
406-
*/
407-
InstanceMirror invoke(Symbol memberName, List positionalArguments,
403+
InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments,
408404
[Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{}]);
409405

410406
/**
@@ -468,8 +464,7 @@ abstract class ObjectMirror implements Mirror {
468464
* If the invocation throws an exception *e* (that it does not catch) this
469465
* method throws *e*.
470466
*/
471-
/* TODO(turnidge): Handle ambiguous names.*/
472-
InstanceMirror setField(Symbol fieldName, Object value);
467+
InstanceMirror setField(Symbol fieldName, dynamic value);
473468

474469
/**
475470
* Performs [invocation] on the reflectee of this [ObjectMirror].
@@ -528,7 +523,7 @@ abstract class InstanceMirror implements ObjectMirror {
528523
* If you access [reflectee] when [hasReflectee] is false, an
529524
* exception is thrown.
530525
*/
531-
get reflectee;
526+
dynamic get reflectee;
532527

533528
/**
534529
* Whether this mirror is equal to [other].
@@ -596,7 +591,7 @@ abstract class ClosureMirror implements InstanceMirror {
596591
* If the invocation throws an exception *e* (that it does not catch), this
597592
* method throws *e*.
598593
*/
599-
InstanceMirror apply(List positionalArguments,
594+
InstanceMirror apply(List<dynamic> positionalArguments,
600595
[Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{}]);
601596
}
602597

@@ -844,11 +839,6 @@ abstract class ClassMirror implements TypeMirror, ObjectMirror {
844839
*/
845840
ClassMirror get mixin;
846841

847-
// TODO(ahe): What about:
848-
// /// Finds the instance member named [name] declared or inherited in the
849-
// /// reflected class.
850-
// DeclarationMirror instanceLookup(Symbol name);
851-
852842
/**
853843
* Invokes the named constructor and returns a mirror on the result.
854844
*
@@ -877,7 +867,8 @@ abstract class ClassMirror implements TypeMirror, ObjectMirror {
877867
* * If evaluating the expression throws an exception *e* (that it does not
878868
* catch), this method throws *e*.
879869
*/
880-
InstanceMirror newInstance(Symbol constructorName, List positionalArguments,
870+
InstanceMirror newInstance(
871+
Symbol constructorName, List<dynamic> positionalArguments,
881872
[Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{}]);
882873

883874
/**

0 commit comments

Comments
 (0)