From a79f0055276a04671711686e137a8739543a21bc Mon Sep 17 00:00:00 2001
From: Brendan Dahl <brendan.dahl@gmail.com>
Date: Thu, 10 Jan 2013 16:32:26 -0800
Subject: [PATCH] Fix isDict when type is missing in dictionary.

---
 src/util.js            |  9 ++++++++-
 test/unit/util_spec.js | 13 +++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

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);
+    });
+  });
+
 });