mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-12 04:31:04 +00:00
Update std.js
This commit is contained in:
parent
6ab0343834
commit
17bbdadbb4
69
lib/std.js
69
lib/std.js
|
@ -10,7 +10,6 @@
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// Polyfills
|
// Polyfills
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (!Function.prototype.GetResource) {
|
if (!Function.prototype.GetResource) {
|
||||||
Function.prototype.GetResource = function(ResourceName) {
|
Function.prototype.GetResource = function(ResourceName) {
|
||||||
if (!this.Resources) {
|
if (!this.Resources) {
|
||||||
|
@ -56,7 +55,8 @@ if (!Enumerator.prototype.toArray2) {
|
||||||
x[c.name] = c.value;
|
x[c.name] = c.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var i = 0, d = [];
|
var i = 0,
|
||||||
|
d = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
d.push(c.value(i));
|
d.push(c.value(i));
|
||||||
|
@ -95,18 +95,19 @@ function sleep(ms, callback) {
|
||||||
cur = Date.now();
|
cur = Date.now();
|
||||||
}
|
}
|
||||||
end = Date.now();
|
end = Date.now();
|
||||||
|
|
||||||
//WScript.Sleep(ms);
|
//WScript.Sleep(ms);
|
||||||
if (typeof callback === "function")
|
if (typeof callback === "function")
|
||||||
callback()
|
callback();
|
||||||
;
|
|
||||||
} else if (typeof window !== "undefined") {
|
} else if (typeof window !== "undefined") {
|
||||||
if (typeof callback === "function")
|
if (typeof callback === "function")
|
||||||
handler = setTimeout(callback, ms);
|
handler = setTimeout(callback, ms);;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { 'ms': end, 'handler': handler };
|
return {
|
||||||
|
'ms': end,
|
||||||
|
'handler': handler
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function repeat(target, callback, onError, onNextInterval, onNext) {
|
function repeat(target, callback, onError, onNextInterval, onNext) {
|
||||||
|
@ -171,7 +172,9 @@ function repeat(target, callback, onError, onNextInterval, onNext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { 'ms': end, 'handler': handler };
|
return {
|
||||||
|
'ms': end, 'handler': handler
|
||||||
|
};
|
||||||
|
|
||||||
case "object":
|
case "object":
|
||||||
var arr = target;
|
var arr = target;
|
||||||
|
@ -180,15 +183,11 @@ function repeat(target, callback, onError, onNextInterval, onNext) {
|
||||||
try {
|
try {
|
||||||
if (typeof callback === "function")
|
if (typeof callback === "function")
|
||||||
if (callback(i, arr[i]) === false)
|
if (callback(i, arr[i]) === false)
|
||||||
break
|
break;;
|
||||||
;
|
|
||||||
;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof onError === "function")
|
if (typeof onError === "function")
|
||||||
if (onError(e, i, arr[i]) === false)
|
if (onError(e, i, arr[i]) === false)
|
||||||
break
|
break;;
|
||||||
;
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,8 +209,7 @@ function rotate(target, callback, onError) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof onError === "function")
|
if (typeof onError === "function")
|
||||||
stop = onError(e, i, arr[i]);
|
stop = onError(e, i, arr[i]);;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@ -221,9 +219,10 @@ function rotate(target, callback, onError) {
|
||||||
|
|
||||||
function range() {
|
function range() {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
var N = [], start, end, step;
|
var N = [],
|
||||||
|
start, end, step;
|
||||||
|
|
||||||
switch(args.length) {
|
switch (args.length) {
|
||||||
case 3:
|
case 3:
|
||||||
start = args[0];
|
start = args[0];
|
||||||
end = args[1];
|
end = args[1];
|
||||||
|
@ -244,8 +243,7 @@ function range() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = start; i < end; i = i + step)
|
for (var i = start; i < end; i = i + step)
|
||||||
N.push(i)
|
N.push(i);
|
||||||
;
|
|
||||||
|
|
||||||
return N;
|
return N;
|
||||||
};
|
};
|
||||||
|
@ -260,14 +258,13 @@ function splitLn(s) {
|
||||||
|
|
||||||
function addslashes(s) {
|
function addslashes(s) {
|
||||||
return s.toString().replace(/\\/g, '\\\\').
|
return s.toString().replace(/\\/g, '\\\\').
|
||||||
replace(/\u0008/g, '\\b').
|
replace(/\u0008/g, '\\b').
|
||||||
replace(/\t/g, '\\t').
|
replace(/\t/g, '\\t').
|
||||||
replace(/\n/g, '\\n').
|
replace(/\n/g, '\\n').
|
||||||
replace(/\f/g, '\\f').
|
replace(/\f/g, '\\f').
|
||||||
replace(/\r/g, '\\r').
|
replace(/\r/g, '\\r').
|
||||||
replace(/'/g, '\\\'').
|
replace(/'/g, '\\\'').
|
||||||
replace(/"/g, '\\"')
|
replace(/"/g, '\\"');
|
||||||
;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -326,8 +323,8 @@ function StdEvent(type) {
|
||||||
this.target = null;
|
this.target = null;
|
||||||
this.currentTarget = null;
|
this.currentTarget = null;
|
||||||
this.eventPhase = StdEvent.NONE;
|
this.eventPhase = StdEvent.NONE;
|
||||||
this.bubbles = false; // Not used but to be compatible
|
this.bubbles = false; // Not used but to be compatible
|
||||||
this.composed = false; // Not used but to be compatible
|
this.composed = false; // Not used but to be compatible
|
||||||
|
|
||||||
this.preventDefault = function() {
|
this.preventDefault = function() {
|
||||||
this.defaultPrevented = true;
|
this.defaultPrevented = true;
|
||||||
|
@ -347,9 +344,9 @@ function StdEvent(type) {
|
||||||
this.stopPropagation = function() {};
|
this.stopPropagation = function() {};
|
||||||
};
|
};
|
||||||
StdEvent.NONE = 0;
|
StdEvent.NONE = 0;
|
||||||
StdEvent.CAPTURING_PHASE = 1; // Not used but to be compatible
|
StdEvent.CAPTURING_PHASE = 1; // Not used but to be compatible
|
||||||
StdEvent.AT_TARGET = 2;
|
StdEvent.AT_TARGET = 2;
|
||||||
StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible
|
StdEvent.BUBBLING_PHASE = 3; // Not used but to be compatible
|
||||||
|
|
||||||
function StdEventTarget() {
|
function StdEventTarget() {
|
||||||
this.__events__ = [];
|
this.__events__ = [];
|
||||||
|
@ -408,7 +405,7 @@ function AsyncFunction(f, _filename) {
|
||||||
|
|
||||||
// increase number of async functions
|
// increase number of async functions
|
||||||
AsyncFunction.counter++;
|
AsyncFunction.counter++;
|
||||||
|
|
||||||
// decrease number of async functions
|
// decrease number of async functions
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var _f = function() {
|
var _f = function() {
|
||||||
|
@ -439,7 +436,7 @@ AsyncFunction.bind = function(exports, args) {
|
||||||
try {
|
try {
|
||||||
exports[f](args);
|
exports[f](args);
|
||||||
result = true;
|
result = true;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error("AsyncFunction.bind exception", e.message);
|
console.error("AsyncFunction.bind exception", e.message);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +476,7 @@ function GeneratorFunction(f, callback) {
|
||||||
this._nextState++;
|
this._nextState++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._done = (typeof this._callback !== "undefined" ? this._callback(this) : false);
|
this._done = (typeof this._callback !== "undefined" ? this._callback(this) : false);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user