Update std.js

This commit is contained in:
Namhyeon Go 2022-02-08 18:10:10 +09:00 committed by GitHub
parent cfb434d1c0
commit 3b157000f1
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) {
@ -28,37 +27,16 @@ if (!Function.prototype.GetResource) {
} }
} }
// MS JScript Enumerator to Array
if (!Enumerator.prototype.toArray) { if (!Enumerator.prototype.toArray) {
Enumerator.prototype.toArray = function() { Enumerator.prototype.toArray = function() {
var a = []; var items = [];
for (; !this.atEnd(); this.moveNext()) { for (; !this.atEnd(); this.moveNext()) {
var x = {}; var item = this.item();
var b = new Enumerator(this.item().Properties_); try {
for (; !b.atEnd(); b.moveNext()) { items.push(item);
var c = b.item(); } catch (e) {}
if (typeof c.value !== "unknown") {
try {
x[c.name] = c.value.toString();
} catch (e) {
x[c.name] = c.value;
}
} else {
var i = 0, d = [];
while (true) {
try {
d.push(c.value(i));
i++;
} catch (e) {
break;
}
}
x[c.name] = d;
}
}
a.push(x);
} }
return a; return items;
}; };
} }
@ -72,7 +50,7 @@ global.GetResource = function(ResourceName) {
// [lib/std] the time of `sleep()' function is not accuracy #34 // [lib/std] the time of `sleep()' function is not accuracy #34
global.sleep = function(ms, callback) { global.sleep = function(ms, callback) {
var handler = null; var handler = null;
var cur = Date.now(); var cur = Date.now();
var end = cur + ms; var end = cur + ms;
@ -100,24 +78,24 @@ global.sleep = function(ms, callback) {
}; };
global.repeat = function(ms, callback) { global.repeat = function(ms, callback) {
var handler = null; var handler = null;
var cur = Date.now(); var cur = Date.now();
var end = cur + ms; var end = cur + ms;
if (typeof WScript !== "undefined") { if (typeof WScript !== "undefined") {
while (cur < end) { while (cur < end) {
sleep(callback().ms); sleep(callback().ms);
cur = Date.now(); cur = Date.now();
} }
end = Date.now(); end = Date.now();
} else if (typeof window !== "undefined") { } else if (typeof window !== "undefined") {
if (typeof callback === "function") if (typeof callback === "function")
handler = setInterval(callback, ms) handler = setInterval(callback, ms)
; ;
} }
return { 'ms': end, 'handler': handler }; return { 'ms': end, 'handler': handler };
}; };
global.CHR = function(ord) { global.CHR = function(ord) {