Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(parser): Getter should call member classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Jul 2, 2013
1 parent f73def3 commit f92381e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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) {
Expand Down Expand Up @@ -161,8 +168,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) {
Expand Down
11 changes: 11 additions & 0 deletions test/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand Down Expand Up @@ -354,6 +359,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!');
Expand Down

0 comments on commit f92381e

Please sign in to comment.