Update std.js

This commit is contained in:
Namhyeon Go 2022-02-08 17:49:30 +09:00 committed by GitHub
parent f072522003
commit 8bcbdd5dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,17 +70,28 @@ global.GetResource = function(ResourceName) {
return arguments.callee.caller.GetResource(ResourceName); return arguments.callee.caller.GetResource(ResourceName);
} }
// [lib/std] the time of `sleep()' function is not accuracy #34
global.sleep = function(ms, callback) { global.sleep = function(ms, callback) {
var cur = Date.now();
var end = cur + ms;
if (typeof(WScript) !== "undefined") { if (typeof(WScript) !== "undefined") {
WScript.Sleep(ms); while (cur < end) {
if (typeof(callback) === "function") { WScript.Sleep(1);
callback(); cur = Date.now();
}
} else {
if (typeof(callback) === "function") {
setTimeout(callback, ms);
} }
end = Date.now();
if (typeof(callback) === "function")
callback()
;
} else if (typeof(window) !== "undefined") {
if (typeof(callback) === "function")
setTimeout(callback, ms)
;
} }
return end;
}; };
global.CHR = function(ord) { global.CHR = function(ord) {