Merge pull request #2548 from brendandahl/isdict-fix

Fix isDict when type is missing in dictionary.
This commit is contained in:
Yury Delendik 2013-01-11 15:02:06 -08:00
commit d111003cdb
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);
});
});
});