Fix isDict when type is missing in dictionary.

This commit is contained in:
Brendan Dahl 2013-01-10 16:32:26 -08:00
parent 2ccad4ca45
commit a79f005527
2 changed files with 21 additions and 1 deletions

View File

@ -441,7 +441,14 @@ function isCmd(v, cmd) {
}
function isDict(v, type) {
return v instanceof Dict && (!type || v.get('Type').name == type);
if (!(v instanceof Dict)) {
return false;
}
if (!type) {
return true;
}
var dictType = v.get('Type');
return isName(dictType) && dictType.name == type;
}
function isArray(v) {

View File

@ -63,5 +63,18 @@ describe('util', function() {
});
});
describe('isDict', function() {
it('handles empty dictionaries with type check', function() {
var dict = new Dict();
expect(isDict(dict, 'Page')).toEqual(false);
});
it('handles dictionaries with type check', function() {
var dict = new Dict();
dict.set('Type', new Name('Page'));
expect(isDict(dict, 'Page')).toEqual(true);
});
});
});