mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-20 16:41:04 +00:00
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/*!
|
|
{
|
|
"name": "ES5 Syntax",
|
|
"property": "es5syntax",
|
|
"notes": [{
|
|
"name": "ECMAScript 5.1 Language Specification",
|
|
"href": "https://www.ecma-international.org/ecma-262/5.1/"
|
|
}, {
|
|
"name": "original implementation of detect code",
|
|
"href": "https://kangax.github.io/compat-table/es5/"
|
|
}],
|
|
"authors": ["Ron Waldon (@jokeyrhyme)"],
|
|
"warnings": ["This detect uses `eval()`, so CSP may be a problem."],
|
|
"tags": ["es5"]
|
|
}
|
|
!*/
|
|
/* DOC
|
|
Check if browser accepts ECMAScript 5 syntax.
|
|
*/
|
|
define(['Modernizr'], function(Modernizr) {
|
|
Modernizr.addTest('es5syntax', function() {
|
|
var value, obj, stringAccess, getter, setter, reservedWords, zeroWidthChars;
|
|
try {
|
|
/* eslint no-eval: "off" */
|
|
// Property access on strings
|
|
stringAccess = eval('"foobar"[3] === "b"');
|
|
// Getter in property initializer
|
|
getter = eval('({ get x(){ return 1 } }).x === 1');
|
|
eval('({ set x(v){ value = v; } }).x = 1');
|
|
// Setter in property initializer
|
|
setter = value === 1;
|
|
// Reserved words as property names
|
|
eval('obj = ({ if: 1 })');
|
|
reservedWords = obj['if'] === 1;
|
|
// Zero-width characters in identifiers
|
|
zeroWidthChars = eval('_\u200c\u200d = true');
|
|
|
|
return stringAccess && getter && setter && reservedWords && zeroWidthChars;
|
|
} catch (ignore) {
|
|
return false;
|
|
}
|
|
});
|
|
});
|