X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fcore%2F00_builtin.js;h=6d4b1a144bcd2dbc45fe4325e02319368c58d4eb;hb=53149facb2f22305d34b9ac01803a6af433355d0;hp=c491406081c31f2a5d3b9e8ab7e8fa4d6c11f347;hpb=274d0a6291860ae033cd637df296d4327b0fa38c;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/core/00_builtin.js b/0.6.x/js/core/00_builtin.js index c491406..6d4b1a1 100644 --- a/0.6.x/js/core/00_builtin.js +++ b/0.6.x/js/core/00_builtin.js @@ -4,11 +4,23 @@ */ Function.prototype.apply || (Function.prototype.apply = function (x, y) { + var a, i, r, j; x = x || window; - y = y ||[]; + y = y || []; + + // apply 内で apply を呼んだ場合に備える + if( x === window ){ + x.__apply = void 0; + } else { + if( x.constructor && x.constructor.prototype.__apply ){ + delete x.constructor.prototype.__apply; + } else + if( x.__apply ) delete x.__apply; + }; + x.__apply = this; if (!x.__apply) x.constructor.prototype.__apply = this; - var r, j = y.length; + j = y.length; switch (j) { case 0: r = x.__apply(); break; case 1: r = x.__apply(y[0]); break; @@ -21,19 +33,29 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { case 8: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7]); break; case 9: r = x.__apply(y[0], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8]); break; default: - var a = []; - for (var i = 0; i < j; ++i) + a = []; + for (i = 0; i < j; ++i) a[i] = 'y[' + i + ']'; - r = eval('x.__apply(' + a.join(',') + ')'); + //r = eval('x.__apply(' + a.join(',') + ')'); + // closuer compiler 対策 + r = (new Function( 'x,y', 'return x.__apply(' + a.join(',') + ')' ))( x, y ); break; - } - delete x.__apply ? x.__apply : x.constructor.prototype.__apply; + }; + // ie5 + if( x === window ){ + x.__apply = void 0; + } else { + if( x.constructor && x.constructor.prototype.__apply ){ + delete x.constructor.prototype.__apply; + } else + if( x.__apply ) delete x.__apply; + }; return r; }); Function.prototype.call || (Function.prototype.call = function () { - var a = arguments, x = a[0], y = []; - for (var i = 1, j = a.length; i < j; ++i) - y[i - 1] = a[i] + var a = arguments, x = a[0], y = [], i = 1, j; + for (j = a.length; i < j; ++i) + y[i - 1] = a[i]; return this.apply(x, y); }); @@ -43,13 +65,14 @@ Array.prototype.pop || (Array.prototype.pop = function () { return r; }); Array.prototype.push || (Array.prototype.push = function () { - for (var a = arguments, i = 0, j = a.length, l = this.length; i < j; ++i) + var a = arguments, i = 0, j = a.length, l = this.length; + for (; i < j; ++i) this[l + i] = a[i]; return this.length; }); Array.prototype.shift || (Array.prototype.shift = function () { - var r = this[0]; - for(var i = 1, j = this.length; i < j; ++i) + var r = this[0], i = 1, j = this.length; + for( ; i < j; ++i) this[i - 1] = this[i]; --this.length; return r; @@ -79,36 +102,117 @@ Array.prototype.splice || (Array.prototype.splice = function (x, y) { }); /* + * original * JavaScript 1.6, Array.indexOfを下位互換実装する * http://www.inazumatv.com/contents/archives/7965 */ -Array.prototype.indexOf || (Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { - if( this == null ){ - //throw new TypeError(); - }; - var t = Object(this); - var len = t.length >>> 0; - if (len === 0) return -1; +Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, fromIndex ){ + var l = this.length >>> 0, + i = 0; + if( l === 0 ) return -1; - var n = 0; - if (arguments.length > 1) { - n = Number(arguments[1]); - if (n != n) { // shortcut for verifying if it's NaN - n = 0; - } else if (n != 0 && n != Infinity && n != -Infinity) { - n = (n > 0 || -1) * Math.floor(Math.abs(n)); - } - } - if (n >= len) { - return -1; - } - var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); - for (; k < len; k++) { - if (t[k] === searchElement) { - return k; - } - } + if( fromIndex ){ + i = fromIndex || 0; + i = i === -Infinity ? 0 : Math.floor( i < 0 ? -i : i ); + if( l <= i ) return -1; + }; + + for( i = 0 <= i ? i : 0 < l + i ? l + i : 0; i < l; ++i ){ + if( this[ i ] === searchElement ) return i; + }; return -1; }); + +/* + * Window + * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html + */ + +/* 正規表現が使われているため、まだ投入しない itozyun +window.encodeURI || (window.encodeURI = function (x) { + return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) { + var c = s.charCodeAt(0), p = "%"; + return ( + c < 16 ? "%0" + c.toString(16) : + c < 128 ? p + c.toString(16) : + c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) : + p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16) + ).toUpperCase(); + }); +}); + +window.encodeURIComponent || (window.encodeURIComponent = function (x) { + return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) { + var c = s.charCodeAt(0), p = "%"; + return ( + c < 16 ? "%0" + c.toString(16) : + c < 128 ? p + c.toString(16) : + c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) : + p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16) + ).toUpperCase(); + }); +}); + +// 手抜き +window.decodeURI || (window.decodeURI = function (x) { + return ("" + x).replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig, function (s) { + var c = parseInt(s.substring(1), 16); + return String.fromCharCode( + c < 128 ? c : + c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 : + ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63 + ); + }); +}); +*/ + + +//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI); + + +/* + * String + */ + +// replace(RegExp, Function)対応 +/* +if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange)) + (function () { + var g = String.prototype.replace; + String.prototype.replace = function (x, y) { + var s = this, z = y; + // 第二引数が関数 + if (y instanceof Function) { + // 第一引数が正規表現 + if (x instanceof RegExp) { + // その上、グローバルマッチ + if (x.global || /^\/.*g$/.test(x)) { + var r = [], m; + while ((m = x.exec(s)) != null) { + var i = m.index; + r[r.length] = s.slice(0, i); + s = s.slice(i + m[0].length); + r[r.length] = y.apply(null, m.concat(i, this)); + } + r[r.length] = s; + return r.join(""); + } + var m = x.exec(s); + if (!m) + return s; + z = y.apply(null, m.concat(m.index, s)); + } + else { + var i = s.indexOf(x); + if (i < 0) + return s; + z = y(x, i, s); + } + } + return g.call(s, x, z); + }; + })(); */ + +