diff --git a/lib/parser.dart b/lib/parser.dart index 6117b8c9f..2a7c58620 100644 --- a/lib/parser.dart +++ b/lib/parser.dart @@ -134,6 +134,13 @@ abstract class Getter { operator[](name); } +stripTrailingNulls(List l) { + while (l.length > 0 && l.last == null) { + l.removeLast(); + } + return l; +} + // Returns a tuple [found, value] getterChild(value, childKey) { if (value is List && childKey is num) { @@ -163,8 +170,8 @@ getterChild(value, childKey) { // maybe it is a member method? if (instanceMirror.type.members.containsKey(curSym)) { MethodMirror methodMirror = instanceMirror.type.members[curSym]; - return [true, _relaxFnArgs((args) { - if (args == null) args = []; + return [true, _relaxFnArgs(([a0, a1, a2, a3, a4, a5]) { + var args = stripTrailingNulls([a0, a1, a2, a3, a4, a5]); try { return instanceMirror.invoke(curSym, args).reflectee; } catch (e) { diff --git a/test/parser_spec.dart b/test/parser_spec.dart index 7b122249f..897c93a49 100644 --- a/test/parser_spec.dart +++ b/test/parser_spec.dart @@ -9,6 +9,11 @@ class TestData { method() => "testMethod"; } +class Ident { + id(x) => x; + doubleId(x,y) => [x,y]; +} + class Mixin {} class MixedTestData extends TestData with Mixin { } @@ -355,6 +360,12 @@ main() { expect(eval("x.y.z")).toEqual(null); }); + it('should access classes on scope', () { + scope['ident'] = new Ident(); + expect(eval('ident.id(6)')).toEqual(6); + expect(eval('ident.doubleId(4,5)')).toEqual([4, 5]); + }); + it('should resolve deeply nested paths (important for CSP mode)', () { scope['a'] = {'b': {'c': {'d': {'e': {'f': {'g': {'h': {'i': {'j': {'k': {'l': {'m': {'n': 'nooo!'}}}}}}}}}}}}}; expect(eval("a.b.c.d.e.f.g.h.i.j.k.l.m.n")).toBe('nooo!');