////////////////////////////////////////////////////////////////////////////////// // // std.js // // Common routines. Defines LIB object which contains the API, as well as // a global DBG function. // // References // * https://github.com/redskyit/wsh-appjs // * https://github.com/JSman-/JS-Framework // ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // Global APIs ///////////////////////////////////////////////////////////////////////////////// if (!('GetResource' in Function.prototype)) { Function.prototype.GetResource = function(ResourceName) { if (!this.Resources) { var UnNamedResourceIndex = 0, _this = this; this.Resources = {}; function f(match, resType, Content) { _this.Resources[(resType=="[[")?UnNamedResourceIndex++:resType.slice(1,-1)] = Content; } this.toString().replace(/\/\*(\[(?:[^\[]+)?\[)((?:[\r\n]|.)*?)\]\]\*\//gi, f); } return this.Resources[ResourceName]; } } global.GetResource = function(ResourceName) { return arguments.callee.caller.GetResource(ResourceName); } global.sleep = function(ms, callback) { if(typeof(WScript) !== "undefined") { WScript.Sleep(ms); if(typeof(callback) === "function") { callback(); } } else { if(typeof(callback) === "function") { setTimeout(callback, ms); } } } global.exit = function() { if(typeof(WScript) !== "undefined") { WScript.Quit(); } else if(typeof(window) !== "undefined") { window.close(); } } if (!('toArray' in Enumerator.prototype)) { Enumerator.prototype.toArray = function() { var Result = []; for (;!this.atEnd();this.moveNext()) Result.push(this.item()) return Result; } } if (!('forEach' in Enumerator.prototype)) { Enumerator.prototype.forEach = function(action, that /*opt*/) { this.toArray().forEach(action, that); } } // Add ECMA262-5 method binding if not supported natively if (!('bind' in Function.prototype)) { Function.prototype.bind = function(owner) { var that= this; if (arguments.length<=1) { return function() { return that.apply(owner, arguments); }; } else { var args= Array.prototype.slice.call(arguments, 1); return function() { return that.apply(owner, arguments.length===0? args : args.concat(Array.prototype.slice.call(arguments))); }; } }; } // Add ECMA262-5 string trim if not supported natively // if (!('trim' in String.prototype)) { String.prototype.trim = function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); }; } // Add ECMA262-5 Array methods if not supported natively // if (!('indexOf' in Array.prototype)) { Array.prototype.indexOf = function(find, i /*opt*/) { if (i===undefined) i= 0; if (i<0) i+= this.length; if (i<0) i= 0; for (var n= this.length; ithis.length-1) i= this.length-1; for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ // if (i in this && this[i]===find) if (this[i]===find) return i; return -1; }; } if (!('forEach' in Array.prototype)) { Array.prototype.forEach = function(action, that /*opt*/) { for (var i= 0, n= this.length; i