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

Unified Diff: lib/compiler/implementation/lib/js_helper.dart

Issue 11264005: InvocationMirror implemented in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Optimization + updated cf comments. Created 8 years, 2 months 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
Index: lib/compiler/implementation/lib/js_helper.dart
diff --git a/lib/compiler/implementation/lib/js_helper.dart b/lib/compiler/implementation/lib/js_helper.dart
index e5476d45799af63c012c1651b46f318d88efaabe..89e6cabd277a38033850c45ed4e6b84443cfa7f9 100644
--- a/lib/compiler/implementation/lib/js_helper.dart
+++ b/lib/compiler/implementation/lib/js_helper.dart
@@ -352,6 +352,78 @@ class ListIterator<T> implements Iterator<T> {
}
}
+createInvocationMirror(name, internalName, type, arguments, argumentNames) =>
+ new JSInvocationMirror(name, internalName, type, arguments, argumentNames);
+
+class JSInvocationMirror implements InvocationMirror {
+ static const METHOD = 0;
+ static const GETTER = 1;
+ static const SETTER = 2;
+
+ final String memberName;
+ final String _internalName;
+ final int _type;
ngeoffray 2012/10/26 08:34:55 Call it kind? Type is overloaded.
Johnni Winther 2012/10/26 10:18:01 Done.
+ final List _arguments;
+ final List _namedArgumentNames;
+ /** Map from argument name to index in _arguments. */
+ Map<String,Dynamic> _namedIndices = null;
ngeoffray 2012/10/26 08:34:55 space after comma (same in other places in this fi
Johnni Winther 2012/10/26 10:18:01 Done.
+
+ JSInvocationMirror(this.memberName,
+ this._internalName,
+ this._type,
+ this._arguments,
+ this._namedArgumentNames) {
+ if (_type == METHOD) {
+ if (_namedArgumentNames != null && _namedArgumentNames.length > 0) {
+ _namedIndices = <String,int>{};
+ int namedArgumentCount = _namedArgumentNames.length;
+ int namedArgumentsStartIndex =
+ _arguments.length - _namedArgumentNames.length;
+ for (int i = 0; i < namedArgumentCount; i++) {
+ _namedIndices[_namedArgumentNames[i]] = i + namedArgumentsStartIndex;
+ }
+ } else {
+ _namedIndices = const <String,int>{};
+ }
+ }
+ }
+
+ bool get isMethod => _type == METHOD;
+ bool get isGetter => _type == GETTER;
+ bool get isSetter => _type == SETTER;
+ bool get isAccessor => _type != METHOD;
+
+ List get positionalArguments {
+ if (_type == GETTER) return null;
ngeoffray 2012/10/26 08:34:55 check isAccessor instead?
Johnni Winther 2012/10/26 10:18:01 Done.
+ var list = [];
+ var argumentCount =
+ _arguments.length - _namedArgumentNames.length;
+ for (var index = 0 ; index < argumentCount ; index++) {
+ list.add(_arguments[index]);
+ }
+ return list;
+ }
+
+ Map<String,Dynamic> get namedArguments {
+ if (_type != METHOD) return null;
+ var map = <String,Dynamic>{};
+ _namedIndices.forEach((String name, int index) {
+ map[name] = _arguments[index];
+ });
+ return map;
+ }
+
+ // TODO(lrn): Hide subtype when class literals are implemented.
+ // Type get runtimeType => InvocationMirror;
+
+ invokeOn(Object object) {
+ List arguments = _arguments;
+ if (!isJsArray(arguments)) arguments = new List.from(arguments);
+ return JS("var", "#[#].apply(#, #)",
+ object, _internalName, object, arguments);
+ }
+}
+
class Primitives {
static int hashCodeSeed = 0;

Powered by Google App Engine
This is Rietveld 408576698