]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#583] Fixes Popcorn.forEach() NodeList enumeration bug
authorrwldrn <waldron.rick@gmail.com>
Thu, 16 Jun 2011 21:52:38 +0000 (17:52 -0400)
committerrwldrn <waldron.rick@gmail.com>
Thu, 16 Jun 2011 21:52:38 +0000 (17:52 -0400)
popcorn.js
test/popcorn.unit.js

index efa17bf8d5bd634104f5e168c6b14cf2a4766b17..0032156df00c7412cda28c86b5dbb58999f1de6c 100644 (file)
       return obj.forEach( fn, context );
     }
 
+    if ( toString.call( obj ) === "[object NodeList]" ) {
+      for ( var key = 0, len = obj.length; key < len; key++ ) {
+        fn.call( context, obj[ key ], key, obj );
+      }
+      return obj;
+    }
+
     for ( var key in obj ) {
       if ( hasOwn.call( obj, key ) ) {
         fn.call( context, obj[ key ], key, obj );
       }
     }
-
     return obj;
   };
 
index 7c4a603bb4fd2c446ae3428db8271073a5029660..6eb473f0727ebd0bb01066459b18436909a9bc2a 100644 (file)
@@ -70,6 +70,36 @@ test("Popcorn.* Static Methods", function () {
   });
 });
 
+test("Popcorn.forEach", function() {
+
+  expect(3);
+
+  var count = 0, 
+    nodelist = document.querySelectorAll("div[id^='qunit-']"), 
+    array = [ 1, 2 ], 
+    object = { a: "1", b: "2" };
+
+  Popcorn.forEach( nodelist, function() {
+    count++;
+  });
+
+  equal(count, nodelist.length, nodelist.length + " elements in NodeList");
+  count = 0;
+
+  Popcorn.forEach( array, function() {
+    count++;
+  });
+
+  equal(count, array.length, array.length + " items in Array");
+  count = 0;
+
+  Popcorn.forEach( object, function() {
+    count++;
+  });
+
+  equal(count, Popcorn.sizeOf(object), Popcorn.sizeOf(object) + " properties in object");
+});
+
 test("Popcorn.util.toSeconds" , function () {
   var framerate = 24,
       storedStartTime,
@@ -433,8 +463,8 @@ test("Popcorn.[addTrackEvent | removeTrackEvent].ref()", function() {
   
   var popped = Popcorn("#video");
 
-       // Calling exec() will create tracks and added them to the
-       // trackreference internally
+  // Calling exec() will create tracks and added them to the
+  // trackreference internally
   popped.exec( 1, function() { /* ... */ });
   popped.exec( 3, function() { /* ... */ });
   popped.exec( 5, function() { /* ... */ });