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

Commit f3df0b1

Browse files
committed
fix(parser): Handle exceptions with grace
1 parent a574104 commit f3df0b1

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

lib/parser.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,11 @@ getterChild(value, childKey) {
161161

162162
InstanceMirror instanceMirror = reflect(value);
163163
Symbol curSym = new Symbol(childKey);
164+
164165
try {
165166
// maybe it is a member field?
166167
return [true, instanceMirror.getField(curSym).reflectee];
167-
} catch (e) {
168+
} on NoSuchMethodError catch (e) {
168169
// maybe it is a member method?
169170
if (instanceMirror.type.members.containsKey(curSym)) {
170171
MethodMirror methodMirror = instanceMirror.type.members[curSym];
@@ -178,10 +179,16 @@ getterChild(value, childKey) {
178179
})];
179180
}
180181
return [false, null];
182+
} catch (e) {
183+
throw;
181184
}
182185
}
183186

184187
getter(scope, locals, path) {
188+
if (scope == null) {
189+
return null;
190+
}
191+
185192
List<String> pathKeys = path.split('.');
186193
var pathKeysLength = pathKeys.length;
187194

test/compiler_spec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ main() {
315315
expect(() {
316316
var element = $('<tab local><pane></pane><pane local></pane></tab>');
317317
$compile(element)(injector, element);
318-
}, throwsA(contains('No provider found for LocalAttrDirective! (resolving LocalAttrDirective)')));
318+
}).toThrow('No provider found for LocalAttrDirective! (resolving LocalAttrDirective)');
319319
}));
320320

321321
it('should publish component controller into the scope', async(inject((Scope $rootScope) {

test/parser_spec.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,32 @@ main() {
690690
Parser.parse('{}()')({});
691691
}).toThrow('{} is not a function');
692692
});
693+
694+
it('should let null be null', () {
695+
scope['map'] = {};
696+
697+
expect(eval('null')).toBe(null);
698+
expect(eval('map.null')).toBe(null);
699+
});
700+
701+
702+
it('should behave gracefully with a null scope', () {
703+
expect(Parser.parse('null')(null)).toBe(null);
704+
});
705+
706+
707+
it('should pass exceptions through getters', () {
708+
expect(() {
709+
Parser.parse('boo')(new ScopeWithErrors());
710+
}).toThrow('boo to you');
711+
});
712+
713+
714+
it('should pass exceptions through methods', () {
715+
expect(() {
716+
Parser.parse('foo()')(new ScopeWithErrors());
717+
}).toThrow('foo to you');
718+
});
693719
});
694720

695721
describe('assignable', () {
@@ -714,5 +740,9 @@ main() {
714740
expect(Parser.parse('a.b')({'a': {'b': 5}}, {'a': null})).toEqual(null);
715741
});
716742
});
743+
}
717744

745+
class ScopeWithErrors {
746+
String get boo { dump("got a boo"); throw "boo to you"; }
747+
String foo() { dump("got a foo"); throw "foo to you"; }
718748
}

0 commit comments

Comments
 (0)