From 25d892ff4370a9c18fbf228394d09fb11529d868 Mon Sep 17 00:00:00 2001 From: Ron Waldon Date: Tue, 7 May 2013 08:05:31 +1000 Subject: [PATCH] split ES5 shim/sham tests into separate tests boolean results also now consistent with other tests --- feature-detects/es5/es5array.js | 39 +++++++++++++ feature-detects/es5/es5date.js | 40 +++++++++++++ feature-detects/es5/es5function.js | 29 ++++++++++ .../es5/{es5sham.js => es5object.js} | 17 +++--- feature-detects/es5/es5shim.js | 56 ------------------- feature-detects/es5/es5string.js | 29 ++++++++++ 6 files changed, 146 insertions(+), 64 deletions(-) create mode 100644 feature-detects/es5/es5array.js create mode 100644 feature-detects/es5/es5date.js create mode 100644 feature-detects/es5/es5function.js rename feature-detects/es5/{es5sham.js => es5object.js} (68%) delete mode 100644 feature-detects/es5/es5shim.js create mode 100644 feature-detects/es5/es5string.js diff --git a/feature-detects/es5/es5array.js b/feature-detects/es5/es5array.js new file mode 100644 index 0000000000..03708f614b --- /dev/null +++ b/feature-detects/es5/es5array.js @@ -0,0 +1,39 @@ +/*! +{ + "name": "ES5 Array", + "property": "es5array", + "notes": [{ + "name": "ES5 Shim documentation", + "href": "https://github.com/kriskowal/es5-shim" + }, { + "name": "ECMAScript 5.1 Language Specification", + "href": "http://www.ecma-international.org/ecma-262/5.1/" + }], + "async": false, + "authors": ["Ron Waldon (@jokeyrhyme)"], + "knownBugs": [], + "tags": [] +} +!*/ +/* DOC + +Check if browser implements ECMAScript 5 Array per specification. + +*/ +define(['Modernizr'], function (Modernizr) { + // es5array + // test by @jokeyrhyme + Modernizr.addTest('es5array', function () { + return Array.prototype && + Array.prototype.every && + Array.prototype.filter && + Array.prototype.forEach && + Array.prototype.indexOf && + Array.prototype.lastIndexOf && + Array.prototype.map && + Array.prototype.some && + Array.prototype.reduce && + Array.prototype.reduceRight && + Array.isArray; + }); +}); diff --git a/feature-detects/es5/es5date.js b/feature-detects/es5/es5date.js new file mode 100644 index 0000000000..cf8be36ac6 --- /dev/null +++ b/feature-detects/es5/es5date.js @@ -0,0 +1,40 @@ +/*! +{ + "name": "ES5 Date", + "property": "es5date", + "notes": [{ + "name": "ES5 Shim documentation", + "href": "https://github.com/kriskowal/es5-shim" + }, { + "name": "ECMAScript 5.1 Language Specification", + "href": "http://www.ecma-international.org/ecma-262/5.1/" + }], + "async": false, + "authors": ["Ron Waldon (@jokeyrhyme)"], + "knownBugs": [], + "tags": [] +} +!*/ +/* DOC + +Check if browser implements ECMAScript 5 Date per specification. + +*/ +define(['Modernizr'], function (Modernizr) { + // es5date + // test by @jokeyrhyme + Modernizr.addTest('es5date', function () { + var isoDate = '2013-04-12T06:06:37.307Z', + canParseISODate = false; + try { + canParseISODate = !!Date.parse(isoDate); + } catch (e) { + // no ISO date parsing yet + } + return Date.now && + Date.prototype && + Date.prototype.toISOString && + Date.prototype.toJSON && + canParseISODate; + }); +}); diff --git a/feature-detects/es5/es5function.js b/feature-detects/es5/es5function.js new file mode 100644 index 0000000000..e0200a60d7 --- /dev/null +++ b/feature-detects/es5/es5function.js @@ -0,0 +1,29 @@ +/*! +{ + "name": "ES5 Function", + "property": "es5function", + "notes": [{ + "name": "ES5 Shim documentation", + "href": "https://github.com/kriskowal/es5-shim" + }, { + "name": "ECMAScript 5.1 Language Specification", + "href": "http://www.ecma-international.org/ecma-262/5.1/" + }], + "async": false, + "authors": ["Ron Waldon (@jokeyrhyme)"], + "knownBugs": [], + "tags": [] +} +!*/ +/* DOC + +Check if browser implements ECMAScript 5 Function per specification. + +*/ +define(['Modernizr'], function (Modernizr) { + // es5function + // test by @jokeyrhyme + Modernizr.addTest('es5function', function () { + return Function.prototype && Function.prototype.bind; + }); +}); diff --git a/feature-detects/es5/es5sham.js b/feature-detects/es5/es5object.js similarity index 68% rename from feature-detects/es5/es5sham.js rename to feature-detects/es5/es5object.js index b4c57cf859..232c7e291d 100644 --- a/feature-detects/es5/es5sham.js +++ b/feature-detects/es5/es5object.js @@ -1,7 +1,7 @@ /*! { - "name": "ES5 Sham", - "property": "es5sham", + "name": "ES5 Object", + "property": "es5object", "notes": [{ "name": "ES5 Shim documentation", "href": "https://github.com/kriskowal/es5-shim" @@ -17,14 +17,15 @@ !*/ /* DOC -Check if browser needs ES5 Sham (true) or if it already implements ES5 (false). +Check if browser implements ECMAScript 5 Object per specification. */ -define(['Modernizr'], function(Modernizr) { - // es5sham +define(['Modernizr'], function (Modernizr) { + // es5object // test by @jokeyrhyme - Modernizr.addTest('es5sham', function() { - return !(Object.create && + Modernizr.addTest('es5object', function () { + return Object.keys && + Object.create && Object.getPrototypeOf && Object.getOwnPropertyNames && Object.isSealed && @@ -35,6 +36,6 @@ define(['Modernizr'], function(Modernizr) { Object.defineProperties && Object.seal && Object.freeze && - Object.preventExtensions); + Object.preventExtensions; }); }); diff --git a/feature-detects/es5/es5shim.js b/feature-detects/es5/es5shim.js deleted file mode 100644 index f1e42cb54e..0000000000 --- a/feature-detects/es5/es5shim.js +++ /dev/null @@ -1,56 +0,0 @@ -/*! -{ - "name": "ES5 Shim", - "property": "es5shim", - "notes": [{ - "name": "ES5 Shim documentation", - "href": "https://github.com/kriskowal/es5-shim" - }, { - "name": "ECMAScript 5.1 Language Specification", - "href": "http://www.ecma-international.org/ecma-262/5.1/" - }], - "async": false, - "authors": ["Ron Waldon (@jokeyrhyme)"], - "knownBugs": [], - "tags": [] -} -!*/ -/* DOC - -Check if browser needs ES5 Shim (true) or if it already implements ES5 (false). - -*/ -define(['Modernizr'], function(Modernizr) { - // es5shim - // test by @jokeyrhyme - Modernizr.addTest('es5shim', function() { - var isoDate = '2013-04-12T06:06:37.307Z', - canParseISODate = false; - try { - canParseISODate = !!Date.parse(isoDate); - } catch (e) { - // no ISO date parsing yet - } - return !(Array.prototype && - Array.prototype.every && - Array.prototype.filter && - Array.prototype.forEach && - Array.prototype.indexOf && - Array.prototype.lastIndexOf && - Array.prototype.map && - Array.prototype.some && - Array.prototype.reduce && - Array.prototype.reduceRight && - Array.isArray && - Date.now && - Date.prototype && - Date.prototype.toISOString && - Date.prototype.toJSON && - canParseISODate && - Function.prototype && - Function.prototype.bind && - Object.keys && - String.prototype && - String.prototype.trim); - }); -}); diff --git a/feature-detects/es5/es5string.js b/feature-detects/es5/es5string.js new file mode 100644 index 0000000000..59daa34c71 --- /dev/null +++ b/feature-detects/es5/es5string.js @@ -0,0 +1,29 @@ +/*! +{ + "name": "ES5 String", + "property": "es5string", + "notes": [{ + "name": "ES5 Shim documentation", + "href": "https://github.com/kriskowal/es5-shim" + }, { + "name": "ECMAScript 5.1 Language Specification", + "href": "http://www.ecma-international.org/ecma-262/5.1/" + }], + "async": false, + "authors": ["Ron Waldon (@jokeyrhyme)"], + "knownBugs": [], + "tags": [] +} +!*/ +/* DOC + +Check if browser implements ECMAScript 5 String per specification. + +*/ +define(['Modernizr'], function (Modernizr) { + // es5string + // test by @jokeyrhyme + Modernizr.addTest('es5string', function () { + return String.prototype && String.prototype.trim; + }); +});