-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobject-defineproperty-ie.js
8 lines (8 loc) · 4.19 KB
/
object-defineproperty-ie.js
1
2
3
4
5
6
7
8
/**
* Object.defineProperty Sham For IE
* @version 3.1.0
* @author Ambit Tsai <ambit_tsai@qq.com>
* @license Apache-2.0
* @see {@link https://github.com/ambit-tsai/object-defineproperty-ie}
*/
!function(f,s){var i,r="defineProperty",o="defineProperties",u="getOwnPropertyDescriptor",p=u+"s",l="Property description must be an object: ",y="__INTERNAL__",a="enumerable",c="configurable",h="value",v="writable",b="get",d="set",g=s.getOwnPropertyNames||function(t){var n=[];return m(t,function(t){n.push(t)}),n};if(s[r])try{s[r]({},"",{})}catch(n){var E=s[r];s[o]=function(e,t){return e instanceof Element||e===document||e===f?(P(t)||w(l+t),m(t,function(t,n){E(e,t,n)}),e):S(e,t)},s[r]=function(t,n,e){var r={};return r[n]=e,s[o](t,r)}}else s[r]=function(t,n,e){var r={};return r[n]=e,S(t,r)};if(s[o]||(/\[native code\]/.test(s[r].toString())?s[o]=function(e,t){return P(t)||w(l+t),m(t,function(t,n){s[r](e,t,n)}),e}:s[o]=S),s[u]){if(s[u](f,c+c)){var e=s[u];s[u]=function(t,n){return t instanceof Element||t===document||t===f?M(t,n)?e(t,n):i:G(t,n)}}}else s[u]=G;function P(t){return!!t&&("object"==typeof t||"function"==typeof t)}function w(t){throw new TypeError(t)}function m(t,n){for(var e in t)M(t,e)&&n(e,t[e])}function M(t,n){return s.prototype.hasOwnProperty.call(t,n)}function S(t,n){P(t)||w("Method called on non-object"),P(n)||w(l+n);for(var e,r=g(n),i={},o=r.length-1;0<=o;--o){var u=r[o],a=V(n[u]);i[u]=a,M(t,u)||(e=!0)}return r.length||g(t).length?j(t)&&!e?(C(R(t).props,i),t):(C(n=s[p](t),i),function c(t){var n=f.setTimeout(s),r="["+y+"]",i=["Class VbClass"+n," Private "+r],o=0,u=new k(t);m(t,function(t){t===y&&w('Property "'+t+'" is the reserved word of "object-defineproperty-ie"');var n="["+t+"]",e="val"===t?"v":"val";i.push(" Public Property Get "+n," If "+r+".getter("+o+", ME) Then"," Set "+n+" = "+r+".getterReturn"," Else"," "+n+" = "+r+".getterReturn"," End If"," End Property"," Public Property Let "+n+"("+e+")"," "+r+".setter "+o+", ME, "+e," End Property"," Public Property Set "+n+"("+e+")"),o?i.push(" "+r+".setter "+o+", ME, "+e):i.push(" If isEmpty("+r+") Then"," Set "+r+" = "+e," Else"," "+r+".setter "+o+", ME, "+e," End If"),i.push(" End Property"),u.keyMap[o++]=t}),i.push("End Class","Function VbFactory"+n+"()"," Set VbFactory"+n+" = New VbClass"+n,"End Function"),f.execScript(i.join("\r\n"),"VBS");var e=f["VbFactory"+n]();return e[u.keyMap[0]]=u,e}(n)):t}function V(t){P(t)||w(l+t);var n={};return a in t&&(n[a]=!!t[a]),c in t&&(n[c]=!!t[c]),h in t&&(n[h]=t[h]),v in t&&(n[v]=!!t[v]),b in t&&("function"!=typeof t[b]&&t[b]!==i?w("Getter must be a function: "+t[b]):n[b]=t[b]),d in t&&("function"!=typeof t[d]&&t[d]!==i?w("Setter must be a function: "+t[d]):n[d]=t[d]),(b in n||d in n)&&(h in n||v in n)&&w("Cannot both specify accessors and a value or writable attribute"),n}function j(t){if(!(y in t))try{t[y]=0,delete t[y]}catch(n){return!0}return!1}function R(t){for(var n in t)return t[n]=k,t[n]}function k(t){this.props=t,this.keyMap={},this.canGetData=i,this.getterReturn=i}function C(r,t){m(t,function(t,n){var e=r[t];e?!1===e[c]&&(h in e&&(n[c]||b in n||d in n||!e[v]&&h in n&&n[h]!==e[h]||!e[v]&&n[v]||a in n&&n[a]!==e[a])||b in e&&(n[c]||h in n||v in n||a in n&&n[a]!==e[a]))&&w("Cannot redefine property: "+t):((e={})[h]=i,e[v]=!1,e[a]=!1,e[c]=!1),r[t]=n,h in n||v in n?(h in n||(n[h]=e[h]),v in n||(n[v]=e[v])):b in n||d in n?(b in n||(n[b]=e[b]),d in n||(n[d]=e[d])):h in e?(n[h]=e[h],n[v]=e[v]):(n[b]=e[b],n[d]=e[d]),a in n||(n[a]=e[a]),c in n||(n[c]=e[c])})}function G(t,n){if(M(t,n)){if(j(t))return function i(e,t){return m(t,function(t,n){e[t]=n}),e}({},R(t).props[n]);var e={};for(var r in e[h]=t[n],e[v]=!0,e[c]=!0,e[a]=!1,t)if(r===n){e[a]=!0;break}return e}}s[p]||(s[p]=function(t){for(var n=g(t),e={},r=n.length-1;0<=r;--r){var i=n[r],o=s[u](t,i);o&&(e[i]=o)}return e}),f._isVbObject=j,f._getVbInternalOf=R,k.prototype.getter=function(t,n){if(this.canGetData===t)return(this.getterReturn=this).canGetData=i,!0;var e=this.keyMap[t],r=this.props[e];return this.getterReturn=r[b]?r[b].call(n):r[h],P(this.getterReturn)},k.prototype.setter=function(t,n,e){if(e!==k){var r=this.keyMap[t],i=this.props[r];i[v]?i[h]=e:i[d]&&i[d].call(n,e)}else this.canGetData=t}}(window,Object);