X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fcore%2F00_builtin.js;h=3f8f67661e6ef718104eca0344d7662706ae7a57;hb=c2184d5500fe31de24e248c9cdf92b31e547fd0c;hp=ebf6e79af18ace5a283893c50195379b5181faaf;hpb=879a00b0da12a642c92bf7679415502099940167;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 ebf6e79..3f8f676 100644 --- a/0.6.x/js/core/00_builtin.js +++ b/0.6.x/js/core/00_builtin.js @@ -9,15 +9,13 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { y = y || []; // apply 内で apply を呼んだ場合に備える - if( x.__apply ){ - if( x === window ){ - x.__apply = void 0; - } else { - delete x.__apply; - }; - }; - if( x.constructor && x.constructor.prototype.__apply ){ - delete x.constructor.prototype.__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; @@ -38,27 +36,26 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) { 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.__apply ){ - if( x === window ){ - x.__apply = void 0; - } else { - delete x.__apply; - }; - }; - if( x.constructor && x.constructor.prototype.__apply ){ - delete x.constructor.prototype.__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; }; return r; }); Function.prototype.call || (Function.prototype.call = function () { var a = arguments, x = a[0], y = [], i = 1, j; for (j = a.length; i < j; ++i) - y[i - 1] = a[i] + y[i - 1] = a[i]; return this.apply(x, y); }); @@ -105,36 +102,165 @@ 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); + }; + })(); */ + +/* + * Safari の JavaScript の不備 + * http://nanto.asablo.jp/blog/2006/01/13/209495 + * + * web.paulownia.jp - JavaScriptとクロージャ + * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html + * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。 + */ +/* +Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){ + var proto = this.constructor && this.constructor.prototype, + __p__ = proto && ( '__proto__' in proto ) && proto.__proto__, + v = this[ p ], + nan = v !== v, // isNaN + r = false, save; + + if( __p__ ) proto.__proto__ = v === null ? undefined : null; + + if( nan ){ + if( proto[ p ] !== proto[ p ] ){ // proto is NaN + proto[ p ] = 0; // different value + r = this[ p ] !== this[ p ]; // isNaN + proto[ p ] = NaN; // proto で定義されていた. + } else { + r = true; + }; + } else + if( p in this ){ + if( !proto || !( p in proto ) || ( proto[ p ] !== v ) ){ + r = true; + } else { + // this と proto に同名で同値が書かれている可能性あり + save = proto[ p ]; + proto[ p ] = v + ' '; // different value + r = v === this[ p ]; + + delete proto[ p ]; + + if( proto[ p ] !== v ){ + // proto で定義されていた. + proto[ p ] = save; + }; + }; + }; + + if( __p__ ) proto.__proto__ = __p__; + + return r; + });*/