Index: runtime/lib/invocation_mirror_patch.dart |
diff --git a/runtime/lib/invocation_mirror_patch.dart b/runtime/lib/invocation_mirror_patch.dart |
index ef325e35b8e917467629d3da7d4560e3f58b3be1..7fd57bde529c57f6df11ac2c32b68292ca0283de 100644 |
--- a/runtime/lib/invocation_mirror_patch.dart |
+++ b/runtime/lib/invocation_mirror_patch.dart |
@@ -5,6 +5,7 @@ |
// NOTE: When making changes to this class, please also update |
// `VmTarget.instantiateInvocation` and `VmTarget._invocationType` in |
// `pkg/kernel/lib/target/vm.dart`. |
+// TODO(regis): See above NOTE. |
class _InvocationMirror implements Invocation { |
// Constants describing the invocation type. |
// _FIELD cannot be generated by regular invocation mirrors. |
@@ -43,6 +44,7 @@ class _InvocationMirror implements Invocation { |
// External representation of the invocation mirror; populated on demand. |
Symbol _memberName; |
int _type; |
+ List _typeArguments; |
List _positionalArguments; |
Map<Symbol, dynamic> _namedArguments; |
@@ -67,16 +69,36 @@ class _InvocationMirror implements Invocation { |
return _memberName; |
} |
+ List get typeArguments { |
+ if (_typeArguments == null) { |
+ int typeArgsLen = _argumentsDescriptor[_TYPE_ARGS_LEN]; |
+ if (typeArgsLen == 0) { |
+ return _typeArguments = const []; |
+ } |
+ // A TypeArguments object does not have a corresponding Dart class and |
+ // cannot be accessed as an array in Dart. Therefore, we need a native |
+ // call to unpack the individual types into a list. |
+ _typeArguments = _unpackTypeArguments(_arguments[0]); |
+ } |
+ return _typeArguments; |
+ } |
+ |
+ // Unpack the given TypeArguments object into a new list of individual types. |
+ static List _unpackTypeArguments(typeArguments) |
+ native "InvocationMirror_unpackTypeArguments"; |
+ |
List get positionalArguments { |
if (_positionalArguments == null) { |
- int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT]; |
- // Don't count receiver. |
- if (numPositionalArguments == 1) { |
+ // The argument descriptor counts the receiver, but not the type arguments |
+ // as positional arguments. |
+ int numPositionalArguments = _argumentsDescriptor[_POSITIONAL_COUNT] - 1; |
+ if (numPositionalArguments == 0) { |
return _positionalArguments = const []; |
} |
- // Exclude receiver. |
- _positionalArguments = |
- new _ImmutableList._from(_arguments, 1, numPositionalArguments - 1); |
+ // Exclude receiver and type args in the returned list. |
+ int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0; |
+ _positionalArguments = new _ImmutableList._from( |
+ _arguments, receiverIndex + 1, numPositionalArguments); |
} |
return _positionalArguments; |
} |
@@ -89,11 +111,13 @@ class _InvocationMirror implements Invocation { |
if (numNamedArguments == 0) { |
return _namedArguments = const {}; |
} |
+ int receiverIndex = _argumentsDescriptor[_TYPE_ARGS_LEN] > 0 ? 1 : 0; |
_namedArguments = new Map<Symbol, dynamic>(); |
for (int i = 0; i < numNamedArguments; i++) { |
int namedEntryIndex = _FIRST_NAMED_ENTRY + 2 * i; |
String arg_name = _argumentsDescriptor[namedEntryIndex]; |
- var arg_value = _arguments[_argumentsDescriptor[namedEntryIndex + 1]]; |
+ var arg_value = _arguments[ |
+ receiverIndex + _argumentsDescriptor[namedEntryIndex + 1]]; |
_namedArguments[new internal.Symbol.unvalidated(arg_name)] = arg_value; |
} |
_namedArguments = new Map.unmodifiable(_namedArguments); |