diff --git a/src/util.js b/src/util.js index 79a1c89cd..de84853b6 100644 --- a/src/util.js +++ b/src/util.js @@ -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) { diff --git a/test/unit/util_spec.js b/test/unit/util_spec.js index d1f5a7387..621736c12 100644 --- a/test/unit/util_spec.js +++ b/test/unit/util_spec.js @@ -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); + }); + }); + });