Chromium Code Reviews| 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 5a180261b0950696b593ad5977f178849fb3a358..d2218327ea079906d215be09315fb473dc1a6d39 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 { |
|
ahe
2012/10/29 12:14:05
Please move this to its own file, like string_help
|
| + static const METHOD = 0; |
|
ahe
2012/10/29 12:14:05
FYI: It is possible to read these constants from t
|
| + static const GETTER = 1; |
| + static const SETTER = 2; |
| + |
| + final String memberName; |
| + final String _internalName; |
| + final int _kind; |
|
ahe
2012/10/29 12:14:05
This field could use some documentation.
|
| + final List _arguments; |
| + final List _namedArgumentNames; |
| + /** Map from argument name to index in _arguments. */ |
| + Map<String,dynamic> _namedIndices = null; |
| + |
| + JSInvocationMirror(this.memberName, |
| + this._internalName, |
| + this._kind, |
| + this._arguments, |
| + this._namedArgumentNames) { |
| + if (_kind == METHOD) { |
| + if (_namedArgumentNames != null && _namedArgumentNames.length > 0) { |
|
ahe
2012/10/29 12:14:05
I think you need to compute this lazily.
|
| + _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 => _kind == METHOD; |
| + bool get isGetter => _kind == GETTER; |
| + bool get isSetter => _kind == SETTER; |
| + bool get isAccessor => _kind != METHOD; |
| + |
| + List get positionalArguments { |
| + if (isAccessor) return null; |
| + var list = []; |
|
ahe
2012/10/29 12:14:05
You should be able to preallocate the correct size
|
| + var argumentCount = |
| + _arguments.length - _namedArgumentNames.length; |
|
ahe
2012/10/29 12:14:05
I think this fits on one line.
|
| + for (var index = 0 ; index < argumentCount ; index++) { |
|
ahe
2012/10/29 12:14:05
Please use the common pattern:
for (int i = 0;
|
| + list.add(_arguments[index]); |
| + } |
| + return list; |
| + } |
| + |
| + Map<String,dynamic> get namedArguments { |
| + if (isAccessor) return null; |
| + var map = <String,dynamic>{}; |
| + _namedIndices.forEach((String name, int index) { |
|
ahe
2012/10/29 12:14:05
I'm having a really hard time seeing why you would
|
| + 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; |