mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 21:51:04 +00:00
Update polyfills (std.js, app.js, es5-shim, es5-sham, es6-shim, es6-sham)
This commit is contained in:
parent
29a0b6bc7c
commit
ea2aed0df0
33
app.js
33
app.js
|
@ -73,6 +73,8 @@ function require(FN) {
|
||||||
var cache = require.__cache = require.__cache || {};
|
var cache = require.__cache = require.__cache || {};
|
||||||
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
||||||
if (cache[FN]) return cache[FN];
|
if (cache[FN]) return cache[FN];
|
||||||
|
|
||||||
|
// load script file
|
||||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||||
var T = null;
|
var T = null;
|
||||||
try {
|
try {
|
||||||
|
@ -85,6 +87,8 @@ function require(FN) {
|
||||||
console.error("LOAD ERROR! " + e.number + ", " + e.description + ", FN=" + FN, 1);
|
console.error("LOAD ERROR! " + e.number + ", " + e.description + ", FN=" + FN, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make global function
|
||||||
FSO = null;
|
FSO = null;
|
||||||
T = "(function(global){\n" + '"use strict";' + "\n" + T + "})(this);\n\n////@ sourceURL=" + FN;
|
T = "(function(global){\n" + '"use strict";' + "\n" + T + "})(this);\n\n////@ sourceURL=" + FN;
|
||||||
try {
|
try {
|
||||||
|
@ -92,24 +96,13 @@ function require(FN) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("PARSE ERROR! " + e.number + ", " + e.description + ", FN=" + FN, 1);
|
console.error("PARSE ERROR! " + e.number + ", " + e.description + ", FN=" + FN, 1);
|
||||||
}
|
}
|
||||||
if ("VERSIONINFO" in cache[FN]) console.log(cache[FN].VERSIONINFO);
|
|
||||||
return cache[FN];
|
|
||||||
}
|
|
||||||
|
|
||||||
function include(FN) {
|
// check type of callback return
|
||||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
if(typeof(cache[FN]) === "object") {
|
||||||
var T = null;
|
if ("VERSIONINFO" in cache[FN]) console.log(cache[FN].VERSIONINFO);
|
||||||
try {
|
|
||||||
var TS = FSO.OpenTextFile(FN, 1);
|
|
||||||
if (TS.AtEndOfStream) return "";
|
|
||||||
T = TS.ReadAll();
|
|
||||||
TS.Close();
|
|
||||||
TS = null;
|
|
||||||
eval(T);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("LOAD ERROR! " + e.number + ", " + e.description + ", FN=" + FN, 1);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cache[FN];
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -117,6 +110,10 @@ function include(FN) {
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function init_console() {
|
function init_console() {
|
||||||
|
if(typeof(WScript) === "undefined") {
|
||||||
|
console.error("Error, WScript is not defined", 1);
|
||||||
|
}
|
||||||
|
|
||||||
var n = WScript.arguments.length;
|
var n = WScript.arguments.length;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
var args = [];
|
var args = [];
|
||||||
|
@ -141,6 +138,10 @@ function init_console() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_window(name, args, w, h) {
|
function init_window(name, args, w, h) {
|
||||||
|
if(typeof(window) === "undefined") {
|
||||||
|
console.error("Error, window is not defined", 1);
|
||||||
|
}
|
||||||
|
|
||||||
var app = require(name);
|
var app = require(name);
|
||||||
|
|
||||||
// "set default size of window";
|
// "set default size of window";
|
||||||
|
|
137
lib/std.js
137
lib/std.js
|
@ -5,16 +5,17 @@
|
||||||
// Common routines. Defines LIB object which contains the API, as well as
|
// Common routines. Defines LIB object which contains the API, as well as
|
||||||
// a global DBG function.
|
// a global DBG function.
|
||||||
//
|
//
|
||||||
// References
|
// References:
|
||||||
// * https://github.com/redskyit/wsh-appjs
|
// * https://github.com/redskyit/wsh-appjs
|
||||||
// * https://github.com/JSman-/JS-Framework
|
// * https://github.com/JSman-/JS-Framework
|
||||||
//
|
//
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// Global APIs
|
// Polyfills
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
if (!('GetResource' in Function.prototype)) {
|
|
||||||
|
if (!Function.prototype.GetResource) {
|
||||||
Function.prototype.GetResource = function(ResourceName) {
|
Function.prototype.GetResource = function(ResourceName) {
|
||||||
if (!this.Resources) {
|
if (!this.Resources) {
|
||||||
var UnNamedResourceIndex = 0,
|
var UnNamedResourceIndex = 0,
|
||||||
|
@ -31,6 +32,18 @@ if (!('GetResource' in Function.prototype)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ECMAScript 5 compatibility shims for legacy (and modern) JavaScript engines
|
||||||
|
require("app/assets/js/es5-shim-4.5.14.min");
|
||||||
|
require("app/assets/js/es5-sham-4.5.14.min");
|
||||||
|
|
||||||
|
// ECMAScript 6 compatibility shims for legacy JS engines
|
||||||
|
require("app/assets/js/es6-shim-0.35.5.min");
|
||||||
|
require("app/assets/js/es6-shim-0.35.5.min");
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Global APIs
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
global.GetResource = function(ResourceName) {
|
global.GetResource = function(ResourceName) {
|
||||||
return arguments.callee.caller.GetResource(ResourceName);
|
return arguments.callee.caller.GetResource(ResourceName);
|
||||||
}
|
}
|
||||||
|
@ -56,122 +69,6 @@ global.exit = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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; i < n; i++)
|
|
||||||
if (this[i] === find) return i;
|
|
||||||
//if (i in this && this[i]===find) return i;
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!('lastIndexOf' in Array.prototype)) {
|
|
||||||
Array.prototype.lastIndexOf = function(find, i /*opt*/ ) {
|
|
||||||
if (i === undefined) i = this.length - 1;
|
|
||||||
if (i < 0) i += this.length;
|
|
||||||
if (i > this.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 < n; i++)
|
|
||||||
//if (i in this)
|
|
||||||
action.call(that, this[i], i, this);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!('map' in Array.prototype)) {
|
|
||||||
Array.prototype.map = function(mapper, that /*opt*/ ) {
|
|
||||||
var other = new Array(this.length);
|
|
||||||
for (var i = 0, n = this.length; i < n; i++)
|
|
||||||
//if (i in this)
|
|
||||||
other[i] = mapper.call(that, this[i], i, this);
|
|
||||||
return other;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!('filter' in Array.prototype)) {
|
|
||||||
Array.prototype.filter = function(filter, that /*opt*/ ) {
|
|
||||||
var other = [],
|
|
||||||
v;
|
|
||||||
for (var i = 0, n = this.length; i < n; i++)
|
|
||||||
//if (i in this && filter.call(that, v= this[i], i, this))
|
|
||||||
if (filter.call(that, v = this[i], i, this))
|
|
||||||
other.push(v);
|
|
||||||
return other;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!('every' in Array.prototype)) {
|
|
||||||
Array.prototype.every = function(tester, that /*opt*/ ) {
|
|
||||||
for (var i = 0, n = this.length; i < n; i++)
|
|
||||||
//if (i in this && !tester.call(that, this[i], i, this))
|
|
||||||
if (!tester.call(that, this[i], i, this))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!('some' in Array.prototype)) {
|
|
||||||
Array.prototype.some = function(tester, that /*opt*/ ) {
|
|
||||||
for (var i = 0, n = this.length; i < n; i++)
|
|
||||||
//if (i in this && tester.call(that, this[i], i, this))
|
|
||||||
if (tester.call(that, this[i], i, this))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private APIs / Utility functions
|
// Private APIs / Utility functions
|
||||||
|
@ -193,4 +90,4 @@ scope.CreateObject = function(n) {
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
return scope;
|
return scope;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user