Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for Object.prototype.__proto__ in unsupported browsers …

…using Object.defineProperty and Object.getPrototypeOf
  • Loading branch information...
commit 428a7bb729cbff2464a10fc99bb4b13750a1f226 1 parent b0c9611
@constantology authored
View
11 README.md
@@ -938,6 +938,13 @@ Returns the `values` of the passed Object based on it's enumerable keys.
```
+### GET: Object.prototype.\_\_proto\_\_:String
+Some browsers — like MSIE 9 & 10 which `m8` supports — do not support the non-standard property `__proto__`.
+
+Luckily however, they do support `Object.getPrototypeOf`, which will return the same value as `__proto__`.
+
+`m8` conveniently wraps this call up inside the `__proto__` getter for those browsers, so you can (more) easily work with `Object` prototypes.
+
### GET: Object.prototype.\_\_type\_\_:String
Attempts to resolve a normalised type for any type that inherits from JavaScript's `Object.prototype`. See `m8.type` for more information.
@@ -945,8 +952,8 @@ Attempts to resolve a normalised type for any type that inherits from JavaScript
## File size
-- m8.js ≅ 6.2kb (gzipped)
-- m8.min.js ≅ 3.5kb (minzipped)
+- m8.js ≅ 6.4kb (gzipped)
+- m8.min.js ≅ 3.6kb (minzipped)
## License
View
135 m8.js
@@ -387,141 +387,6 @@
Type[__xid__] = extenders.length; // assigned every time __lib__.x() is called, and
} // potentilly throwing overwrite errors.
-/*~ src/nativex.js ~*/
- x.cache( 'Array', function( Type ) {
- var PROTO = Type.prototype;
-
- def( Type, 'coerce', function( a, i, j ) {
- if ( !got( a, 'length' ) ) return [a];
- i = type( i ) == 'number' ? i > 0 ? i : 0 : 0;
- j = type( j ) == 'number' ? j > i ? j : j <= 0 ? a.length + j : i + j : a.length;
- return slice.call( a, i, j );
- }, 'w' );
-
- defs( PROTO, {
- find : function( fn, ctx ) {
- var i = -1, l = this.length >>> 0;
- ctx || ( ctx = this );
- while ( ++i < l ) if ( !!fn.call( ctx, this[i], i, this ) ) return this[i];
- return null;
- },
- invoke : function( fn ) {
- var args = Type.coerce( arguments, 1 );
- return PROTO.map.call( this, function( item ) {
- return item && typeof item[fn] == 'function' ? item[fn].apply( item, args ) : UNDEF;
- } );
- },
- pluck : function( key, existing_only ) {
- existing_only = existing_only === true;
- return PROTO.reduce.call( this, function( val, item ) {
- var v = Object.value( item, key );
-
- ( existing_only && !exists( v ) ) || val.push( v );
-
- return val;
- }, [] );
- }
- }, 'w' );
- } );
-
- x.cache( 'Boolean', function( Type ) {
- def( Type, 'coerce', function( item ) {
- switch( type( item ) ) {
- case 'boolean' : return item;
- case 'nan' : case false : return false;
- case 'number' : case 'string' : return !( item in force ? !force[item] : Number( item ) === 0 );
- }
- return true;
- }, 'w' );
- } );
-
- x.cache( 'Function', function( Type ) {
- function anon( name ) { return !name || name in anon_list; }
- function toString() { return this.toString(); }
- function valueOf() { return this; }
-
- var __xname__ = '__xname__',
- anon_list = { Anonymous : true, anonymous : true },
- desc = { mimic : function( fn, name ) {
- var fn_val = fn.valueOf(); // in case fn is a mimicked Function, we'll want to mimic the original
- defs( this, {
- displayName : ( name || fname( fn_val ) ),
- toString : toString.bind( fn_val ),
- valueOf : valueOf.bind( fn_val )
- }, 'c', true );
- return this;
- } };
- desc[__name__] = { get : function() {
- if ( !this[__xname__] ) {
- var fn = this.valueOf(), // if this function is mimicking another, get the mimicked function
-// handles anonymous functions which are mimicking (see mimic below) named functions
- name_m = fn !== this ? !anon( fn[__name__] ) ? fn[__name__] : null : null,
- name = name_m || fname( this );
- !anon( name ) || anon( this.displayName ) || ( name = this.displayName );
- def( this, __xname__, ( name || 'anonymous' ), 'w' );
- }
- return this[__xname__];
- } };
-
- defs( Type.prototype, desc, 'w' );
-// allows us to better try and get a functions name, you can add to this list if you like
- def( Type, 'anon_list', { value : anon_list }, 'w' );
-
- } );
-
- x.cache( 'Object', function( Type ) {
-// this is a special case which does not use __lib__.describe
-// since it internally uses __type__ which is about to be set up here.
- def( Type.prototype, __type__, copy( { get : function() {
- var _type_, item = this, ctor = item.constructor, ntype = nativeType( item ),
- dtype = domType( ntype ) || ( re_global.test( ntype ) ? 'global' : false );
-
- if ( dtype ) return dtype;
- if ( ntype == 'number' ) return isNaN( item ) ? 'nan' : 'number';
-
- if ( ntype == 'object' && typeof ctor == 'function' ) {
- if ( ctor[__type__] != 'function' ) {
- _type_ = String( ctor[__name__] ).toLowerCase();
- return !_type_ || _type_ == 'anonymous' ? ctor[__type__] || ntype : _type_;
- }
- }
-
- return ntype;
- } }, modes.r ) );
-
- defs( Type, {
- key : function( item, val ) {
- return Type.keys( Type( item ) ).find( function( key ) {
- return item[key] === val;
- } );
- },
- reduce : function( item, fn, val ) {
- return Type.keys( Type( item ) ).reduce( function( res, key, i ) {
- res = fn.call( item, res, item[key], key, item, i );
- return res;
- }, val );
- },
- value : function( item, key ) {
- if ( isNaN( key ) ) {
- if ( got( item, key ) ) return item[key];
- if ( !!~key.indexOf( '.' ) ) {
- var val; key = key.split( '.' );
- while ( val = key.shift() )
- if ( ( item = Type.value( item, val ) ) === UNDEF )
- break;
- return item;
- }
- }
- return empty( item )
- ? UNDEF : exists( item[key] )
- ? item[key] : typeof item.get == 'function'
- ? item.get( key ) : typeof item.getAttribute == 'function'
- ? item.getAttribute( key ) : UNDEF;
- },
- values : function( item ) { return Type.keys( Object( item ) ).map( function( key ) { return item[key]; } ); }
- }, 'w' );
- } );
-
/*~ src/expose.js ~*/
iter( PACKAGE ) || ( PACKAGE = ENV == 'commonjs' ? module : root );
View
2  m8.min.js
@@ -1 +1 @@
-!function(e,t,n){"use strict";function r(e){return e}function u(e,t){switch(I(e)){case"array":break;case"string":e=e.split(".");break;default:return c(t)}if(bt.test(e[0])&&(t=r,e.shift()),!e.length)return c(t);e[0].indexOf("^")||(t||"^"==e[0]?e.shift():e[0]=e[0].substring(1)),t=c(t);for(var n;n=e.shift();)t=t[n]||(t[n]=C());return t}function c(t){return"commonjs"==Z?t?k(t)?t.exports:t:module.exports:t||e}function i(e){var t,n=Number(e);return isNaN(n)?(t=e+"")in nt?nt[t]:e:n}function o(e,t,n){n=n===!0,t||(t=e,e=C());for(var r in t)!j(t,r)||n&&j(e,r)||(e[r]=t[r]);return e}function a(e,t,n){return n=n===!0,t||(t=e,e=C()),Object.getOwnPropertyNames(t).reduce(function(e,r){return n&&j(e,r)||f(e,r,h(t,r)),e},e)}function f(e,n,u){var c,i,o,a,f=gt.call(arguments,3),s=y(e,n);switch(I(f[0])){case"string":i=ot[f.shift()];break;case"object":i=f.shift();break;default:o=I(u),i="object"!=o&&s?h(e,n):null,!i||(i="function"==o?ot.cw:ot.cew)}return a=f.shift()===!0,c=f.shift()===!0,s&&!a?c&&Error(t+".def cannot overwrite existing property: "+n+", in item type: "+K(e)+"."):("object"!=o&&i&&(u=l(u,i)),(u.get||u.set)&&delete u.writable,Object.defineProperty(e,n,u)),r}function s(e,t,n,u,c){n||(n="cw");for(var i in t)!j(t,i)||f(e,i,t[i],n,u,c);return r}function l(e,t){return o("object"==I(e)?e:{value:e},"object"==I(t)?t:ot[(t+"").toLowerCase()]||ot.cew,!0)}function h(e,t){return Object.getOwnPropertyDescriptor(e,t)}function b(e){return!p(e)||!A(e)&&_(e)||!1}function p(e){return!(null===e||e===J||"number"==typeof e&&isNaN(e))}function d(t,n,r){"string"!=typeof n&&t[Q]&&(r=n,n=t[Q]);var u,c=C();return c[Q]=n,c[X]="library","commonjs"==Z&&k(r)?r.exports=t:(r||(r=e),(u=r[n])&&_(u)?(u[n]=t,t=a(u,t)):f(r,n,l({value:t},"ew")),"browser"==Z&&r===e&&("function"!=typeof define||!define.amd||define(n,[],function(){return t}))),s(t,c,"w",!0),t}function g(e){return e.name||e.displayName||((e+"").match(pt)||["",""])[1].trim()}function m(e){return w(e,Array.coerce(arguments,1))}function y(e,t){return t+""in Object(e)}function w(e,t,n){return(e+"").replace(n||lt,function(e,n){return t[n]||""})}function x(){return mt.replace(ht,v)}function v(e){var t=0|16*ft();return("x"==e?t:8|3&t).toString(16)}function j(e,t){return et.hasOwnProperty.call(Object(e),t+"")}function O(e,t){return e?y(e,"id")&&!b(e.id)?e.id:e.id=N(t):N(t)}function N(e){return(e||it)+"-"+ ++ct}function k(e){if(null===tt)return!1;try{return e instanceof tt}catch(t){return!1}}function _(e){return y(e,"length")||"object"==I(e)}function A(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function E(e,t){var n;if(t)n=I(t);else switch(n=I(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}switch(n){case"object":return Object.keys(t).reduce(S,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(P,e);default:return t}}function P(e,t,n){return e[n]=I(e[n])===I(t)?E(e[n],t):E(t),e}function S(e,t){return e.target[t]=I(e.target[t])===I(e.source[t])?E(e.target[t],e.source[t]):E(e.source[t]),e}function B(){}function C(e){var t=Object.create(null);return"object"==typeof e?o(t,e):t}function F(e,t,n){var r;if(n+="",arguments.length>3){for(n=gt.call(arguments,2);r=n.shift();)if(F(e,t,r))return!0;return!1}if(e(t,n))return!0;if("string"!=typeof t&&~n.indexOf(".")){for(n=n.split(".");r=n.shift();){if(!F(e,t,r))return!1;t=t[r]}return!0}return!1}function L(e,t){for(var n=[e];t>=++e;)n.push(e);return n}function D(e,t){t=Array.isArray(t)?t:gt.call(arguments,1);var n=Array.isArray(e)?M:R;return t.forEach(n,e),e}function M(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,0>t||this.splice(t,1)}function R(e){delete this[e]}function $(e){return et.toString.call(e)}function q(e){return et.valueOf.call(e)}function z(e){return e==ut?ut:e==rt||"nodelist"==e?rt:e.indexOf("htm")||e.lastIndexOf("element")+7!==e.length?!1:"htmlelement"}function I(e){var t=$(e);return t in at?at[t]:at[t]=t.split(" ")[1].split("]")[0].replace(dt,"$1").toLowerCase()}function K(e){if(null===e||e===J)return!1;var t=y(e,X)?e[X]:null===Object.getPrototypeOf(e)?"nullobject":J;return"object"!==t?t:F(j,e,"configurable","enumerable","writable")&&j(e,"value")||F(j,e,"get","set")?"descriptor":t}function T(e,t){if(!t)return E(e);switch(I(t)){case"object":return Object.keys(t).reduce(V,{source:t,target:e}).target;case"array":return t.reduce(U,e);default:return e}}function U(e,t,n){return e[n]=y(e,n)?I(e[n])==I(t)?T(e[n],t):e[n]:E(t),e}function V(e,t){return e.target[t]=y(e.target,t)?I(e.target[t])==I(e.source[t])?T(e.target[t],e.source[t]):e.target[t]:E(e.source[t]),e}function W(){return gt.call(arguments).forEach(H),r}function G(e){e(this,r)}function H(e){y(e,Y)||f(e,Y,0,"w");var t=yt[e[Q]||g(e)];t&&(t.slice(e[Y]).forEach(G,e),e[Y]=t.length)}"undefined"==typeof global?e:e=global;var J,Q="__name__",X="__type__",Y="__xid__",Z="undefined"!=typeof module&&"exports"in module&&"function"==typeof require?"commonjs":"undefined"!=typeof navigator?"browser":"other",et=Object.prototype,tt="commonjs"!=Z?null:require("module"),nt=[!1,0/0,null,!0,J].reduce(function(e,t){return e[t+""]=t,e},C()),rt="htmlcollection",ut="htmldocument",ct=999,it="anon",ot=function(){var e={ce:"ec",cw:"wc",ew:"we",cew:"cwe ecw ewc wce wec".split(" ")},t="configurable enumerable writable".split(" "),n={c:[!0,!1,!1],ce:[!0,!0,!1],cew:[!0,!0,!0],cw:[!0,!1,!0],e:[!1,!0,!1],ew:[!1,!0,!0],r:[!1,!1,!1],w:[!1,!1,!0]},r=Object.keys(n).reduce(function(r,u){function c(e){r[e]=r[u]}var i=e[u];return r[u]=t.reduce(function(e,t,r){return e[t]=n[u][r],e},C()),!i||(Array.isArray(i)?i.forEach(c):c(i)),r},C());return delete r[J],r}(),at="Array Boolean Date Function Null Number Object RegExp String Undefined".split(" ").reduce(function(e,t){return e["[object "+t+"]"]=t.toLowerCase(),e},C()),ft=Math.random,st=/global|window/i,lt=/\$?\{([^\}]+)\}/g,ht=/[xy]/g,bt=RegExp("^\\u005E?"+t),pt=/[\s\(]*function([^\(]+).*/,dt=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,gt=Array.prototype.slice,mt="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",yt={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};f(W,"cache",function(e,t){return"string"==typeof e||(e=e[Q]||g(e)),yt[e]||(yt[e]=[]),yt[e].push(t),r},"w"),W.cache("Array",function(e){var t=e.prototype;f(e,"coerce",function(e,t,n){return y(e,"length")?(t="number"==K(t)?t>0?t:0:0,n="number"==K(n)?n>t?n:0>=n?e.length+n:t+n:e.length,gt.call(e,t,n)):[e]},"w"),s(t,{find:function(e,t){var n=-1,r=this.length>>>0;for(t||(t=this);r>++n;)if(e.call(t,this[n],n,this))return this[n];return null},invoke:function(n){var r=e.coerce(arguments,1);return t.map.call(this,function(e){return e&&"function"==typeof e[n]?e[n].apply(e,r):J})},pluck:function(e,n){return n=n===!0,t.reduce.call(this,function(t,r){var u=Object.value(r,e);return n&&!p(u)||t.push(u),t},[])}},"w")}),W.cache("Boolean",function(e){f(e,"coerce",function(e){switch(K(e)){case"boolean":return e;case"nan":case!1:return!1;case"number":case"string":return!(e in nt?!nt[e]:0===Number(e))}return!0},"w")}),W.cache("Function",function(e){function t(e){return!e||e in c}function n(){return""+this}function r(){return this}var u="__xname__",c={Anonymous:!0,anonymous:!0},i={mimic:function(e,t){var u=e.valueOf();return s(this,{displayName:t||g(u),toString:n.bind(u),valueOf:r.bind(u)},"c",!0),this}};i[Q]={get:function(){if(!this[u]){var e=this.valueOf(),n=e!==this?t(e[Q])?null:e[Q]:null,r=n||g(this);!t(r)||t(this.displayName)||(r=this.displayName),f(this,u,r||"anonymous","w")}return this[u]}},s(e.prototype,i,"w"),f(e,"anon_list",{value:c},"w")}),W.cache("Object",function(e){f(e.prototype,X,o({get:function(){var e,t=this,n=t.constructor,r=I(t),u=z(r)||(st.test(r)?"global":!1);return u?u:"number"==r?isNaN(t)?"nan":"number":"object"==r&&"function"==typeof n&&"function"!=n[X]?(e=(n[Q]+"").toLowerCase(),e&&"anonymous"!=e?e:n[X]||r):r}},ot.r)),s(e,{key:function(t,n){return e.keys(e(t)).find(function(e){return t[e]===n})},reduce:function(t,n,r){return e.keys(e(t)).reduce(function(e,r,u){return e=n.call(t,e,t[r],r,t,u)},r)},value:function(t,n){if(isNaN(n)){if(y(t,n))return t[n];if(~n.indexOf(".")){var r;for(n=n.split(".");(r=n.shift())&&(t=e.value(t,r))!==J;);return t}}return b(t)?J:p(t[n])?t[n]:"function"==typeof t.get?t.get(n):"function"==typeof t.getAttribute?t.getAttribute(n):J},values:function(t){return e.keys(Object(t)).map(function(e){return t[e]})}},"w")}),_(n)||(n="commonjs"==Z?module:e),s(r=d(r,t,n),{ENV:Z,global:{value:e},modes:{value:ot},bless:u,coerce:i,copy:o,cpdef:a,def:f,defs:s,describe:l,description:h,empty:b,exists:p,expose:d,format:m,got:F.bind(null,y),gsub:w,guid:x,has:F.bind(null,j),id:O,iter:_,len:A,merge:E,nativeType:I,noop:B,ntype:I,obj:C,range:L,remove:D,tostr:$,type:K,update:T,valof:q,x:W},"w"),W(Object,Array,Boolean,Function)}(this,"m8");
+!function(e,t,n){"use strict";function r(e){return e}function u(e,t){switch(z(e)){case"array":break;case"string":e=e.split(".");break;default:return c(t)}if(ft.test(e[0])&&(t=r,e.shift()),!e.length)return c(t);e[0].indexOf("^")||(t||"^"==e[0]?e.shift():e[0]=e[0].substring(1)),t=c(t);for(var n;n=e.shift();)t=t[n]||(t[n]=C());return t}function c(t){return"commonjs"==Y?t?_(t)?t.exports:t:module.exports:t||e}function o(e){var t,n=Number(e);return isNaN(n)?(t=e+"")in tt?tt[t]:e:n}function i(e,t,n){n=n===!0,t||(t=e,e=C());for(var r in t)!j(t,r)||n&&j(e,r)||(e[r]=t[r]);return e}function a(e,t,n){return n=n===!0,t||(t=e,e=C()),Object.getOwnPropertyNames(t).reduce(function(e,r){return n&&j(e,r)||f(e,r,p(t,r)),e},e)}function f(e,n,u){var c,o,i,a,f=pt.call(arguments,3),s=m(e,n);switch(z(f[0])){case"string":o=ut[f.shift()];break;case"object":o=f.shift();break;default:i=z(u),o="object"!=i&&s?p(e,n):null,!o||(o="function"==i?ut.cw:ut.cew)}return a=f.shift()===!0,c=f.shift()===!0,s&&!a?c&&Error(t+".def cannot overwrite existing property: "+n+", in item type: "+K(e)+"."):("object"!=i&&o&&(u=l(u,o)),(u.get||u.set)&&delete u.writable,Object.defineProperty(e,n,u)),r}function s(e,t,n,u,c){n||(n="cw");for(var o in t)!j(t,o)||f(e,o,t[o],n,u,c);return r}function l(e,t){return i("object"==z(e)?e:{value:e},"object"==z(t)?t:ut[(t+"").toLowerCase()]||ut.cew,!0)}function p(e,t){return Object.getOwnPropertyDescriptor(e,t)}function b(e){return!g(e)||!A(e)&&k(e)||!1}function g(e){return!(null===e||e===H||"number"==typeof e&&isNaN(e))}function d(t,n,r){"string"!=typeof n&&t[J]&&(r=n,n=t[J]);var u,c=C();return c[J]=n,c[Q]="library","commonjs"==Y&&_(r)?r.exports=t:(r||(r=e),(u=r[n])&&k(u)?(u[n]=t,t=a(u,t)):f(r,n,l({value:t},"ew")),"browser"==Y&&r===e&&("function"!=typeof define||!define.amd||define(n,[],function(){return t}))),s(t,c,"w",!0),t}function h(e){return e.name||e.displayName||((e+"").match(st)||["",""])[1].trim()}function y(e){return x(e,Array.coerce(arguments,1))}function m(e,t){return t+""in Object(e)}function x(e,t,n){return(e+"").replace(n||it,function(e,n){return t[n]||""})}function w(){return bt.replace(at,v)}function v(e){var t=0|16*ot();return("x"==e?t:8|3&t).toString(16)}function j(e,t){return Z.hasOwnProperty.call(Object(e),t+"")}function O(e,t){return e?m(e,"id")&&!b(e.id)?e.id:e.id=N(t):N(t)}function N(e){return(e||rt)+"-"+ ++nt}function _(e){if(null===et)return!1;try{return e instanceof et}catch(t){return!1}}function k(e){return m(e,"length")||"object"==z(e)}function A(e){return("length"in(e=Object(e))?e:Object.keys(e)).length}function E(e,t){var n;if(t)n=z(t);else switch(n=z(e)){case"array":case"object":t=e,e=new(t.constructor||Object);break;default:return e}switch(n){case"object":return Object.keys(t).reduce(S,{source:t,target:e}).target;case"array":return e.length=t.length,t.reduce(P,e);default:return t}}function P(e,t,n){return e[n]=z(e[n])===z(t)?E(e[n],t):E(t),e}function S(e,t){return e.target[t]=z(e.target[t])===z(e.source[t])?E(e.target[t],e.source[t]):E(e.source[t]),e}function B(){}function C(e){var t=Object.create(null);return"object"==typeof e?i(t,e):t}function F(e,t,n){var r;if(n+="",arguments.length>3){for(n=pt.call(arguments,2);r=n.shift();)if(F(e,t,r))return!0;return!1}if(e(t,n))return!0;if("string"!=typeof t&&~n.indexOf(".")){for(n=n.split(".");r=n.shift();){if(!F(e,t,r))return!1;t=t[r]}return!0}return!1}function L(e,t){for(var n=[e];t>=++e;)n.push(e);return n}function D(e,t){t=Array.isArray(t)?t:pt.call(arguments,1);var n=Array.isArray(e)?M:R;return t.forEach(n,e),e}function M(e){var t=this.indexOf(e);t=~t?t:!isNaN(e)&&e in this?e:t,0>t||this.splice(t,1)}function R(e){delete this[e]}function $(e){return Z.toString.call(e)}function q(e){return Z.valueOf.call(e)}function z(e){var t=$(e);return t in ct?ct[t]:ct[t]=t.split(" ")[1].split("]")[0].replace(lt,"$1").toLowerCase()}function K(e){if(null===e||e===H)return!1;var t=m(e,Q)?e[Q]:null===Object.getPrototypeOf(e)?"nullobject":H;return"object"!==t?t:F(j,e,"configurable","enumerable","writable")&&j(e,"value")||F(j,e,"get","set")?"descriptor":t}function T(e,t){if(!t)return E(e);switch(z(t)){case"object":return Object.keys(t).reduce(V,{source:t,target:e}).target;case"array":return t.reduce(U,e);default:return e}}function U(e,t,n){return e[n]=m(e,n)?z(e[n])==z(t)?T(e[n],t):e[n]:E(t),e}function V(e,t){return e.target[t]=m(e.target,t)?z(e.target[t])==z(e.source[t])?T(e.target[t],e.source[t]):e.target[t]:E(e.source[t]),e}function W(){return pt.call(arguments).forEach(G),r}function I(e){e(this,r)}function G(e){m(e,X)||f(e,X,0,"w");var t=gt[e[J]||h(e)];t&&(t.slice(e[X]).forEach(I,e),e[X]=t.length)}"undefined"==typeof global?e:e=global;var H,J="__name__",Q="__type__",X="__xid__",Y="undefined"!=typeof module&&"exports"in module&&"function"==typeof require?"commonjs":"undefined"!=typeof navigator?"browser":"other",Z=Object.prototype,et="commonjs"!=Y?null:require("module"),tt=[!1,0/0,null,!0,H].reduce(function(e,t){return e[t+""]=t,e},C()),nt=999,rt="anon",ut=function(){var e={ce:"ec",cw:"wc",ew:"we",cew:"cwe ecw ewc wce wec".split(" ")},t="configurable enumerable writable".split(" "),n={c:[!0,!1,!1],ce:[!0,!0,!1],cew:[!0,!0,!0],cw:[!0,!1,!0],e:[!1,!0,!1],ew:[!1,!0,!0],r:[!1,!1,!1],w:[!1,!1,!0]},r=Object.keys(n).reduce(function(r,u){function c(e){r[e]=r[u]}var o=e[u];return r[u]=t.reduce(function(e,t,r){return e[t]=n[u][r],e},C()),!o||(Array.isArray(o)?o.forEach(c):c(o)),r},C());return delete r[H],r}(),ct="Array Boolean Date Function Null Number Object RegExp String Undefined".split(" ").reduce(function(e,t){return e["[object "+t+"]"]=t.toLowerCase(),e},C()),ot=Math.random,it=/\$?\{([^\}]+)\}/g,at=/[xy]/g,ft=RegExp("^\\u005E?"+t),st=/[\s\(]*function([^\(]+).*/,lt=/^[Ww]ebkit|[Mm]oz|O|[Mm]s|[Kk]html(.*)$/,pt=Array.prototype.slice,bt="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",gt={Array:[],Boolean:[],Date:[],Function:[],Number:[],Object:[],RegExp:[],String:[]};f(W,"cache",function(e,t){return"string"==typeof e||(e=e[J]||h(e)),gt[e]||(gt[e]=[]),gt[e].push(t),r},"w"),k(n)||(n="commonjs"==Y?module:e),s(r=d(r,t,n),{ENV:Y,global:{value:e},modes:{value:ut},bless:u,coerce:o,copy:i,cpdef:a,def:f,defs:s,describe:l,description:p,empty:b,exists:g,expose:d,format:y,got:F.bind(null,m),gsub:x,guid:w,has:F.bind(null,j),id:O,iter:k,len:A,merge:E,nativeType:z,noop:B,ntype:z,obj:C,range:L,remove:D,tostr:$,type:K,update:T,valof:q,x:W},"w"),W(Object,Array,Boolean,Function)}(this,"m8");
View
2  package.json
@@ -27,5 +27,5 @@
"scripts" : {
"test" : "mocha -c --ignore-leaks -R spec -u tdd ./test/*.test.js"
},
- "version" : "0.3.5"
+ "version" : "0.3.6"
}
View
6 src/nativex.js
@@ -99,6 +99,12 @@
return ntype;
} }, modes.r ) );
+ def( Type.prototype, '__proto__', {
+ get : function() {
+ return Type.getPrototypeOf( this );
+ } // todo: set???
+ }, 'c' );
+
defs( Type, {
key : function( item, val ) {
return Type.keys( Type( item ) ).find( function( key ) {
View
25 test/m8.test.js
@@ -377,6 +377,31 @@ suite( 'm8', function() {
done();
} );
+ test( 'Object.prototype.__proto__', function( done ) {
+ function Collection() {
+ this.push.apply( this, arguments );
+ return this;
+ }
+ m8.defs( Collection.prototype = [], {
+ __type__ : 'collection',
+ slice : function() {
+ var val = this.__proto__.__proto__.slice.apply( this, arguments );
+ return Array.isArray( val ) ? Collection.apply( Object.create( Collection.prototype ), val ) : val;
+ },
+ splice : function() {
+ var val = this.__proto__.__proto__.splice.apply( this, arguments );
+ return Array.isArray( val ) ? Collection.apply( Object.create( Collection.prototype ), val ) : val;
+ }
+ }, 'cw', true );
+
+ var col = new Collection( 1, 2, 3, 4, 5 );
+ expect( m8.type( col.slice( 0 ) ) ).to.equal( 'collection' );
+ expect( col.slice( 1, 3 ).length ).to.equal( 2 );
+ expect( col.length ).to.equal( 5 );
+
+ done();
+ } );
+
test( '<static> Array.coerce returns an Array based on the passed item', function( done ) {
expect( Array.coerce( [1, 2, 3] ) ).to.eql( [1, 2, 3] );
expect( Array.coerce( { foo : 'bar' } ) ).to.eql( [{ foo : 'bar' }] );
Please sign in to comment.
Something went wrong with that request. Please try again.