Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: runtime/lib/invocation_mirror_patch.dart

Issue 11570042: Implement InvocationMirror.invokeOn method in the vm (issue 7227). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/invocation_mirror.cc ('k') | runtime/lib/lib_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/invocation_mirror_patch.dart
===================================================================
--- runtime/lib/invocation_mirror_patch.dart (revision 16186)
+++ runtime/lib/invocation_mirror_patch.dart (working copy)
@@ -3,64 +3,112 @@
// BSD-style license that can be found in the LICENSE file.
class _InvocationMirror implements InvocationMirror {
- static final int METHOD = 0;
- static final int GETTER = 1;
- static final int SETTER = 2;
+ // Constants describing the invocation type.
+ static final int _METHOD = 0;
+ static final int _GETTER = 1;
+ static final int _SETTER = 2;
- // TODO(regis): Compute lazily the value of these fields, and save the
- // arguments passed into _allocateInvocationMirror.
+ // Internal representation of the invocation mirror.
+ final String _functionName;
+ final List _argumentsDescriptor;
+ final List _arguments;
- final String memberName;
- final List positionalArguments;
- final Map<String, dynamic> namedArguments;
+ // External representation of the invocation mirror; populated on demand.
+ String _memberName;
+ int _type;
+ List _positionalArguments;
+ Map<String, dynamic> _namedArguments;
- final int _type;
+ void _setMemberNameAndType() {
+ if (_functionName.startsWith("get:")) {
+ _type = _GETTER;
+ _memberName = _functionName.substring(4);
+ } else if (_functionName.startsWith("set:")) {
+ _type = _SETTER;
+ _memberName = _functionName.substring(4).concat("=");
+ } else {
+ _type = _METHOD;
+ _memberName = _functionName;
+ }
+ }
- _InvocationMirror(this.memberName,
- this._type,
- this.positionalArguments,
- this.namedArguments);
+ String get memberName {
+ if (_memberName == null) {
+ _setMemberNameAndType();
+ }
+ return _memberName;
+ }
- static _allocateInvocationMirror(String name,
- List argumentsDescriptor,
- List arguments) {
- var memberName;
- var type;
- if (name.startsWith("get:")) {
- type = GETTER;
- memberName = name.substring(4);
- } else if (name.startsWith("set:")) {
- type = SETTER;
- memberName = name.substring(4).concat("=");
- } else {
- type = METHOD;
- memberName = name;
+ List get positionalArguments {
+ if (_positionalArguments == null) {
+ // Exclude receiver.
+ int numPositionalArguments = _argumentsDescriptor[1] - 1;
+ _positionalArguments = _arguments.getRange(1, numPositionalArguments);
}
- // Exclude receiver.
- int numArguments = argumentsDescriptor[0] - 1;
- int numPositionalArguments = argumentsDescriptor[1] - 1;
- int numNamedArguments = numArguments - numPositionalArguments;
- List positionalArguments = arguments.getRange(1, numPositionalArguments);
- Map<String, dynamic> namedArguments;
- if (numNamedArguments > 0) {
- namedArguments = new Map<String, dynamic>();
+ return _positionalArguments;
+ }
+
+ Map<String, dynamic> get namedArguments {
+ if (_namedArguments == null) {
+ _namedArguments = new Map<String, dynamic>();
+ int numArguments = _argumentsDescriptor[0] - 1; // Exclude receiver.
+ int numPositionalArguments = _argumentsDescriptor[1] - 1;
+ int numNamedArguments = numArguments - numPositionalArguments;
for (int i = 0; i < numNamedArguments; i++) {
- String arg_name = argumentsDescriptor[2 + 2*i];
- var arg_value = arguments[argumentsDescriptor[3 + 2*i]];
- namedArguments[arg_name] = arg_value;
+ String arg_name = _argumentsDescriptor[2 + 2*i];
+ var arg_value = _arguments[_argumentsDescriptor[3 + 2*i]];
+ _namedArguments[arg_name] = arg_value;
}
}
- return new _InvocationMirror(memberName, type,
- positionalArguments, namedArguments);
+ return _namedArguments;
}
- bool get isMethod => _type == METHOD;
- bool get isAccessor => _type != METHOD;
- bool get isGetter => _type == GETTER;
- bool get isSetter => _type == SETTER;
+ bool get isMethod {
+ if (_memberName == null) {
+ _setMemberNameAndType();
+ }
+ return _type == _METHOD;
+ }
+ bool get isAccessor {
+ if (_memberName == null) {
+ _setMemberNameAndType();
+ }
+ return _type != _METHOD;
+ }
+
+ bool get isGetter {
+ if (_memberName == null) {
+ _setMemberNameAndType();
+ }
+ return _type == _GETTER;
+ }
+
+ bool get isSetter {
+ if (_memberName == null) {
+ _setMemberNameAndType();
+ }
+ return _type == _SETTER;
+ }
+
+ _InvocationMirror(this._functionName,
+ this._argumentsDescriptor,
+ this._arguments);
+
+ static _allocateInvocationMirror(String functionName,
+ List argumentsDescriptor,
+ List arguments) {
+ return new _InvocationMirror(functionName, argumentsDescriptor, arguments);
+ }
+
+ static _invoke(Object receiver,
+ String functionName,
+ List argumentsDescriptor,
+ List arguments)
+ native "InvocationMirror_invoke";
+
invokeOn(Object receiver) {
- throw new UnsupportedError("invokeOn not implemented yet");
+ _invoke(receiver, _functionName, _argumentsDescriptor, _arguments);
}
}
« no previous file with comments | « runtime/lib/invocation_mirror.cc ('k') | runtime/lib/lib_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698