OSDN Git Service

Version 0.6.66, fixed around X.Callback.
[pettanr/clientJs.git] / 0.6.x / js / core / 00_builtin.js
index 989bf76..b9adfeb 100644 (file)
@@ -12,7 +12,10 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) {
        if( x === window ){\r
                x.__apply = void 0;\r
        } else {\r
-               delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
+               if( x.constructor && x.constructor.prototype.__apply ){\r
+                       delete x.constructor.prototype.__apply;\r
+               } else\r
+               if( x.__apply ) delete x.__apply;\r
        };\r
        \r
        x.__apply = this;\r
@@ -33,21 +36,25 @@ Function.prototype.apply || (Function.prototype.apply = function (x, y) {
                        a = [];\r
                        for (i = 0; i < j; ++i)\r
                                a[i] = 'y[' + i + ']';\r
-                       r = eval('x.__apply(' + a.join(',') + ')');\r
+                       //r = eval('x.__apply(' + a.join(',') + ')');\r
+                       // closuer compiler 対策\r
+                       r = (new Function( 'x,y', 'return x.__apply(' + a.join(',') + ')' ))( x, y );\r
                        break;\r
        };\r
-       // delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
        // ie5\r
        if( x === window ){\r
                x.__apply = void 0;\r
        } else {\r
-               delete x.__apply ? x.__apply : x.constructor.prototype.__apply ;\r
+               if( x.constructor && x.constructor.prototype.__apply ){\r
+                       delete x.constructor.prototype.__apply;\r
+               } else\r
+               if( x.__apply ) delete x.__apply;\r
        };\r
        return r;\r
 });\r
 Function.prototype.call || (Function.prototype.call = function () {\r
-       var a = arguments, x = a[0], y = [], i = 1, j;\r
-       for (j = a.length; i < j; ++i)\r
+       var a = arguments, x = a[0], y = [], i = 1, j = a.length;\r
+       for (; i < j; ++i)\r
                y[i - 1] = a[i];\r
        return this.apply(x, y);\r
 });\r
@@ -71,43 +78,43 @@ Array.prototype.shift || (Array.prototype.shift = function () {
        return r;\r
 });\r
 Array.prototype.unshift || (Array.prototype.unshift = function () {\r
-       var a = arguments, l = a.length, j = this.length += l - 1;\r
-       for (var i = j; i >= l; --i)\r
+       var a = arguments, l = a.length, j = this.length += l - 1, i = j;\r
+       for (; i >= l; --i)\r
                this[i] = this[i - l];\r
-       for (var i = 0; i < l; ++i)\r
+       for (i = 0; i < l; ++i)\r
                this[i] = a[i];\r
        return j;\r
 });\r
 Array.prototype.splice || (Array.prototype.splice = function (x, y) {\r
-       var a = arguments, s = a.length - 2 - y, r = this.slice(x, x + y);\r
+       var a = arguments, s = a.length - 2 - y, r = this.slice(x, x + y),i,j;\r
        if (s > 0) {\r
-               for (var i = this.length - 1, j = x + y; i >= j; --i)\r
+               for (i = this.length - 1, j = x + y; i >= j; --i)\r
                        this[i + s] = this[i];\r
        }\r
        else if (s < 0) {\r
-               for (var i = x + y, j = this.length; i < j; ++i)\r
+               for (i = x + y, j = this.length; i < j; ++i)\r
                        this[i + s] = this[i];\r
                this.length += s;\r
        }\r
-       for (var i = 2, j = a.length; i < j; ++i)\r
+       for (i = 2, j = a.length; i < j; ++i)\r
                this[i - 2 + x] = a[i];\r
        return r;\r
 });\r
 \r
 /*\r
- * JavaScript 1.6, Array.indexOfを下位互換実装する\r
  * original\r
+ * JavaScript 1.6, Array.indexOfを下位互換実装する\r
  * http://www.inazumatv.com/contents/archives/7965\r
  */\r
 \r
 Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, fromIndex ){\r
-        var l = this.length >>> 0,\r
-               i = 0;\r
+        var l = this.length >>> 0, i;\r
+        \r
         if( l === 0 ) return -1;\r
         \r
         if( fromIndex ){\r
             i = fromIndex || 0;\r
-            i = i === -Infinity ? 0 : Math.floor( i < 0 ? -i : i );\r
+            i = i === -Infinity ? 0 : ( i < 0 ? -i : i ) | 0; // Math.floor\r
             if( l <= i ) return -1;\r
         };\r
 \r
@@ -117,3 +124,160 @@ Array.prototype.indexOf || (Array.prototype.indexOf = function( searchElement, f
         return -1;\r
        });\r
 \r
+\r
+/*\r
+ * Window\r
+ * by http://nurucom-archives.hp.infoseek.co.jp/digital/trans-uri.html\r
+ */\r
+\r
+/* 正規表現が使われているため、まだ投入しない itozyun\r
+window.encodeURI || (window.encodeURI = function (x) {\r
+       return ("" + x).replace(/[^!#$&-;=?-Z_a-z~]/g, function (s) {\r
+               var c = s.charCodeAt(0), p = "%";\r
+               return (\r
+                       c < 16 ? "%0" + c.toString(16) :\r
+                       c < 128 ? p + c.toString(16) :\r
+                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+               ).toUpperCase();\r
+       });\r
+});\r
+\r
+window.encodeURIComponent || (window.encodeURIComponent = function (x) {\r
+       return ("" + x).replace(/[^!'-*.0-9A-Z_a-z~-]/g, function (s) {\r
+               var c = s.charCodeAt(0), p = "%";\r
+               return (\r
+                       c < 16 ? "%0" + c.toString(16) :\r
+                       c < 128 ? p + c.toString(16) :\r
+                       c < 2048 ? p + (c >> 6 | 192).toString(16) + p + (c & 63 | 128).toString(16) :\r
+                       p + (c >> 12 | 224).toString(16) + p + (c >> 6 & 63 | 128).toString(16) + p + (c & 63 | 128).toString(16)\r
+               ).toUpperCase();\r
+       });\r
+});\r
+\r
+// 手抜き\r
+window.decodeURI || (window.decodeURI = function (x) {\r
+       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) {\r
+               var c = parseInt(s.substring(1), 16);\r
+               return String.fromCharCode(\r
+                       c < 128 ? c :\r
+                       c < 224 ? (c & 31) << 6 | parseInt(s.substring(4), 16) & 63 :\r
+                       ((c & 15) << 6 | parseInt(s.substring(4), 16) & 63) << 6 | parseInt(s.substring(7), 16) & 63\r
+               );\r
+       });\r
+});\r
+*/\r
+\r
+\r
+//window.decodeURIComponent || (window.decodeURIComponent = window.decodeURI);\r
+\r
+\r
+/*\r
+ * String\r
+ */\r
+\r
+// replace(RegExp, Function)対応\r
+/*\r
+if (window.ActiveXObject ? !Number.prototype.toFixed : (!navigator.taintEnabled && !document.createElement("input").setSelectionRange))\r
+       (function () {\r
+               var g = String.prototype.replace;\r
+               String.prototype.replace = function (x, y) {\r
+                       var s = this, z = y;\r
+                       // 第二引数が関数\r
+                       if (y instanceof Function) {\r
+                               // 第一引数が正規表現\r
+                               if (x instanceof RegExp) {\r
+                                       // その上、グローバルマッチ\r
+                                       if (x.global || /^\/.*g$/.test(x)) {\r
+                                               var r = [], m;\r
+                                               while ((m = x.exec(s)) != null) {\r
+                                                       var i = m.index;\r
+                                                       r[r.length] = s.slice(0, i);\r
+                                                       s = s.slice(i + m[0].length);\r
+                                                       r[r.length] = y.apply(null, m.concat(i, this));\r
+                                               }\r
+                                               r[r.length] = s;\r
+                                               return r.join("");\r
+                                       }\r
+                                       var m = x.exec(s);\r
+                                       if (!m)\r
+                                               return s;\r
+                                       z = y.apply(null, m.concat(m.index, s));\r
+                               }\r
+                               else {\r
+                                       var i = s.indexOf(x);\r
+                                       if (i < 0)\r
+                                               return s;\r
+                                       z = y(x, i, s);\r
+                               }\r
+                       }\r
+                       return g.call(s, x, z);\r
+               };\r
+       })(); */\r
+       \r
+/*\r
+ * Safari の JavaScript の不備 \r
+ * http://nanto.asablo.jp/blog/2006/01/13/209495\r
+ * \r
+ * web.paulownia.jp - JavaScriptとクロージャ\r
+ * https://web.archive.org/web/20070526063400/http://web.paulownia.jp/script/oop/closure.html\r
+ * MacOSX 10.3のsafariにはhasOwnPropertyが実装されていないので、独自に追加する必要があります。\r
+ */\r
+/*\r
+Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){\r
+               var proto = this.constructor && this.constructor.prototype,\r
+                       __p__ = proto && proto.__proto__,\r
+                       v     = this[ p ],\r
+                       r     = false;\r
+               \r
+               if( __p__ ) proto.__proto__ = null;\r
+               \r
+               if( p in this ){\r
+                       if( v !== v ){\r
+                               if( proto && ( p in proto ) && proto[ p ] !== proto[ p ] ){ // proto[ p ] is NaN\r
+                                       proto[ p ] = 0; // different value\r
+                                       r = this[ p ] !== this[ p ]; // isNaN?\r
+                                       proto[ p ] = v; // set NaN\r
+                               } else {\r
+                                       r = true;\r
+                               };\r
+                       } else\r
+                       if( proto && p in proto && proto[ p ] === v ){\r
+                               // this と proto に同名で同値が書かれている可能性あり\r
+                               proto[ p ] = v + ' '; // different value\r
+                               r = v === this[ p ];\r
+                               proto[ p ] = v;\r
+                       } else {\r
+                               r = true;\r
+                       };\r
+               };\r
+               \r
+               if( __p__ ) proto.__proto__ = __p__;\r
+               \r
+               return r;\r
+  }); */\r
+/*\r
+Object.prototype.hasOwnProperty || (Object.prototype.hasOwnProperty = function( p ){\r
+               var proto = this.constructor && this.constructor.prototype,\r
+                       __p__ = proto && proto.__proto__,\r
+                       v     = this[ p ],\r
+                       isNaN = v !== v;\r
+                       r     = false;\r
+               \r
+               if( __p__ ) proto.__proto__ = null;\r
+               \r
+               if( p in this ){\r
+                       if( proto && p in proto && ( proto[ p ] === v ) ^ isNaN ){ //true + false, false + true\r
+                               // this と proto に同名で同値が書かれている可能性あり\r
+                               proto[ p ] = v + ' '; // different value\r
+                               r = ( v === this[ p ] ) ^ isNaN; // true + false, false + true\r
+                               proto[ p ] = v;\r
+                       } else {\r
+                               r = true;\r
+                       };\r
+               };\r
+               \r
+               if( __p__ ) proto.__proto__ = __p__;\r
+               \r
+               return r;\r
+  }); */
\ No newline at end of file