polyfill-service
Version:
A polyfill combinator
1 lines • 4.79 kB
JSON
{"aliases":["es5","modernizr:es5object","default","blissfuljs"],"browsers":{"firefox":"3.6","safari":"4 - 4.1","ios_saf":"4.3","firefox_mob":"3.6","ie":"6 - 8"},"notes":["In browsers that have no hooks to define getter functions (notably IE <= 8), attempting to defineProperty with a getter or setter function will fail. Since failing silently would likely break your application, we throw an exception. In IE8, this can be hard to diagnose because the console will just say 'Exception thrown and not caught'"],"docs":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty","baseDir":"Object/defineProperty","hasTests":true,"rawSource":"\n// Object.defineProperty\n(function (nativeDefineProperty) {\n\n\tvar supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');\n\tvar ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';\n\tvar ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';\n\n\tObject.defineProperty = function defineProperty(object, property, descriptor) {\n\n\t\t// Where native support exists, assume it\n\t\tif (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {\n\t\t\treturn nativeDefineProperty(object, property, descriptor);\n\t\t}\n\n\t\tvar propertyString = String(property);\n\t\tvar hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;\n\t\tvar getterType = 'get' in descriptor && typeof descriptor.get;\n\t\tvar setterType = 'set' in descriptor && typeof descriptor.set;\n\n\t\tif (object === null || !(object instanceof Object || typeof object === 'object')) {\n\t\t\tthrow new TypeError('Object must be an object (Object.defineProperty polyfill)');\n\t\t}\n\n\t\tif (!(descriptor instanceof Object)) {\n\t\t\tthrow new TypeError('Descriptor must be an object (Object.defineProperty polyfill)');\n\t\t}\n\n\t\t// handle descriptor.get\n\t\tif (getterType) {\n\t\t\tif (getterType !== 'function') {\n\t\t\t\tthrow new TypeError('Getter expected a function (Object.defineProperty polyfill)');\n\t\t\t}\n\t\t\tif (!supportsAccessors) {\n\t\t\t\tthrow new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);\n\t\t\t}\n\t\t\tif (hasValueOrWritable) {\n\t\t\t\tthrow new TypeError(ERR_VALUE_ACCESSORS);\n\t\t\t}\n\t\t\tobject.__defineGetter__(propertyString, descriptor.get);\n\t\t} else {\n\t\t\tobject[propertyString] = descriptor.value;\n\t\t}\n\n\t\t// handle descriptor.set\n\t\tif (setterType) {\n\t\t\tif (setterType !== 'function') {\n\t\t\t\tthrow new TypeError('Setter expected a function (Object.defineProperty polyfill)');\n\t\t\t}\n\t\t\tif (!supportsAccessors) {\n\t\t\t\tthrow new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);\n\t\t\t}\n\t\t\tif (hasValueOrWritable) {\n\t\t\t\tthrow new TypeError(ERR_VALUE_ACCESSORS);\n\t\t\t}\n\t\t\tobject.__defineSetter__(propertyString, descriptor.set);\n\t\t}\n\n\t\t// OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above\n\t\tif ('value' in descriptor) {\n\t\t\tobject[propertyString] = descriptor.value;\n\t\t}\n\n\t\treturn object;\n\t};\n}(Object.defineProperty));\n","minSource":"!function(e){var t=Object.prototype.hasOwnProperty(\"__defineGetter__\"),r=\"Getters & setters cannot be defined on this javascript engine\",n=\"A property cannot both have accessors and be writable or have a value\";Object.defineProperty=function(o,i,f){if(e&&(o===window||o===document||o===Element.prototype||o instanceof Element))return e(o,i,f);var p=String(i),c=\"value\"in f||\"writable\"in f,a=\"get\"in f&&typeof f.get,y=\"set\"in f&&typeof f.set;if(null===o||!(o instanceof Object||\"object\"==typeof o))throw new TypeError(\"Object must be an object (Object.defineProperty polyfill)\");if(!(f instanceof Object))throw new TypeError(\"Descriptor must be an object (Object.defineProperty polyfill)\");if(a){if(\"function\"!==a)throw new TypeError(\"Getter expected a function (Object.defineProperty polyfill)\");if(!t)throw new TypeError(r);if(c)throw new TypeError(n);o.__defineGetter__(p,f.get)}else o[p]=f.value;if(y){if(\"function\"!==y)throw new TypeError(\"Setter expected a function (Object.defineProperty polyfill)\");if(!t)throw new TypeError(r);if(c)throw new TypeError(n);o.__defineSetter__(p,f.set)}return\"value\"in f&&(o[p]=f.value),o}}(Object.defineProperty);","detectSource":"// In IE8, defineProperty could only act on DOM elements, so full support\n// for the feature requires the ability to set a property on an arbitrary object\n'defineProperty' in Object && (function() {\n\ttry {\n\t\tvar a = {};\n\t\tObject.defineProperty(a, 'test', {value:42});\n\t\treturn true;\n\t} catch(e) {\n\t\treturn false\n\t}\n}())"}