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 fcfa49be512b7399e1bd8afaa727a0e4f859b52e..2cefb18a649daabe20d8285a5d7846031b0ec841 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 _kind; |
| + 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) { |
|
Johnni Winther
2012/10/29 12:05:55
Do we need to do this at all when [_namedIndices]
Lasse Reichstein Nielsen
2012/10/30 10:03:31
Hmm, we could probably do it at that point instead
|
| + _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 = []; |
| + 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 (isAccessor) 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; |
| @@ -647,7 +719,7 @@ class Primitives { |
| String selectorName = 'call\$$argumentCount$buffer'; |
| var jsFunction = JS('var', '#[#]', function, selectorName); |
| if (jsFunction == null) { |
| - throw new NoSuchMethodError(function, selectorName, arguments); |
| + throw new NoSuchMethodError(function, selectorName, arguments, {}); |
| } |
| // We bound 'this' to [function] because of how we compile |
| // closures: escaped local variables are stored and accessed through |
| @@ -888,7 +960,7 @@ unwrapException(ex) { |
| type == 'non_object_property_load') { |
| return new NullPointerException(); |
| } else if (type == 'undefined_method') { |
| - return new NoSuchMethodError('', name, []); |
| + return new NoSuchMethodError('', name, [], {}); |
| } |
| var ieErrorCode = JS('int', '#.number & 0xffff', ex); |
| @@ -909,7 +981,7 @@ unwrapException(ex) { |
| // Object doesn't support property or method 'foo' which sets the error |
| // code 438 in IE. |
| // TODO(kasperl): Compute the right name if possible. |
| - return new NoSuchMethodError('', '<unknown>', []); |
| + return new NoSuchMethodError('', '<unknown>', [], {}); |
| } |
| } |
| @@ -1376,7 +1448,7 @@ void assertHelper(condition) { |
| * resolved cannot be found. |
| */ |
| void throwNoSuchMethod(obj, name, arguments) { |
| - throw new NoSuchMethodError(obj, name, arguments); |
| + throw new NoSuchMethodError(obj, name, arguments, {}); |
| } |
| /** |