From 0fbe4df00471415e33ba580c56d6e24afcb0c519 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Fri, 1 Apr 2011 16:43:43 -0400 Subject: [PATCH] [#463] Popcorn.isArray() to support FF3.6; +18 Unit tests --- popcorn.js | 4 ++++ test/popcorn.unit.js | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/popcorn.js b/popcorn.js index 8b064aa..c68ce35 100644 --- a/popcorn.js +++ b/popcorn.js @@ -13,6 +13,7 @@ forEach = Array.prototype.forEach, hasOwn = Object.prototype.hasOwnProperty, slice = Array.prototype.slice, + toString = Object.prototype.toString, // ID string matching rIdExp = /^(#([\w\-\_\.]+))$/, @@ -330,6 +331,9 @@ return size; }, + isArray: Array.isArray || function( array ) { + return toString.call( array ) === "[object Array]"; + }, nop: function () {} }); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 0f63263..12e877f 100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -164,6 +164,39 @@ test("guid", function () { } }); +test("isArray", function() { + + expect(18); + + var empty = [], + fastSmall = [1], + slow = [], + slowSmall = [], + all = null; + + slowSmall[999999] = 0; + slowSmall.length = 0; + slow.slow = 0; + + all = [ [], [1], new Array, Array(0),'abc'.match(/(a)/g), slow, slowSmall ]; + + all.forEach(function( a ) { + ok( Popcorn.isArray(a), "Popcorn.isArray("+JSON.stringify(a)+")" ); + }); + + equal( Popcorn.isArray.length, 1, "Popcorn.isArray.length, 1" ); + + ok( !Popcorn.isArray(), "!Popcorn.isArray(), false"); + ok( !Popcorn.isArray({}), "!Popcorn.isArray({}), false"); + ok( !Popcorn.isArray(null), "!Popcorn.isArray(null), false"); + ok( !Popcorn.isArray(undefined), "!Popcorn.isArray(undefined)"); + ok( !Popcorn.isArray(17), "!Popcorn.isArray(17), false"); + ok( !Popcorn.isArray("Array"), "!Popcorn.isArray('Array'), false"); + ok( !Popcorn.isArray(Math.PI), "!Popcorn.isArray(Math.PI), false"); + ok( !Popcorn.isArray(true), "!Popcorn.isArray(true), false"); + ok( !Popcorn.isArray(false), "!Popcorn.isArray(false), false"); + ok( !Popcorn.isArray( {__proto__: Array.prototype, length:1, 0:1, 1:2} ), "{__proto__: Array.prototype, length:1, 0:1, 1:2}"); +}); test("Protected", function () { @@ -1920,11 +1953,11 @@ test("Parser Support", function () { } }); - Popcorn.parser( "parseAudio", function( data ){ - ok( typeof data.json === "object", "data.json exists"); - plus(); - return data.json; - }); + Popcorn.parser( "parseAudio", function( data ){ + ok( typeof data.json === "object", "data.json exists"); + plus(); + return data.json; + }); audiocorn.parseAudio("data/parserAudio.json", function() { -- 2.43.0