From da1c187b3c86d2b906280c35de7ff9f744d1c000 Mon Sep 17 00:00:00 2001
From: Klaus Weidner <klausw@google.com>
Date: Tue, 10 Apr 2012 15:49:46 -0700
Subject: [PATCH] Avoid calling length on undefined if no event handlers are
 registered.

---
 dygraph.js | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/dygraph.js b/dygraph.js
index e1cdd4e..1ebe261 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -483,11 +483,13 @@ Dygraph.prototype.cascadeEvents_ = function(name, extra_props) {
   Dygraph.update(e, extra_props);
 
   var callback_plugin_pairs = this.eventListeners_[name];
-  for (var i = callback_plugin_pairs.length - 1; i >= 0; i--) {
-    var plugin = callback_plugin_pairs[i][0];
-    var callback = callback_plugin_pairs[i][1];
-    callback.call(plugin, e);
-    if (e.propagationStopped) break;
+  if (callback_plugin_pairs) {
+    for (var i = callback_plugin_pairs.length - 1; i >= 0; i--) {
+      var plugin = callback_plugin_pairs[i][0];
+      var callback = callback_plugin_pairs[i][1];
+      callback.call(plugin, e);
+      if (e.propagationStopped) break;
+    }
   }
   return e.defaultPrevented;
 };
-- 
2.7.4