Update std.js

This commit is contained in:
Namhyeon Go 2023-03-14 13:41:49 +09:00 committed by GitHub
parent 6ab0343834
commit 17bbdadbb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));
@ -98,15 +98,16 @@ function sleep(ms, callback) {
//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__ = [];
@ -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;
} }