diff --git a/lib/std.js b/lib/std.js index dfecf69..ebb5585 100644 --- a/lib/std.js +++ b/lib/std.js @@ -307,13 +307,30 @@ function StdEventableObject() { }; function AsyncFunction(f) { + this.htmlfile = null; + this.proxyWindow = null; this.f = f; + this.run = function() { - sleep(1, this.f); + if (this.proxyWindow != null) { + this.proxyWindow.setTimeout(1, this.f); + } else { + sleep(1, this.f); + } }; this.runSynchronously = function() { - return this.f(); + return this.f.apply(null, arguments); }; + + // https://qiita.com/abcang/items/80b5733b5a96eeff9945 + if (typeof WScript !== "undefined") { + try { + this.htmlfile = CreateObject("htmlfile"); + this.proxyWindow = this.htmlfile.parentWindow; + } catch (e) { + console.warn("AsyncFunction require HTMLFILE object in WScript"); + } + } }; global.GetResource = GetResource; @@ -326,9 +343,9 @@ global.splitLn = splitLn; global.addslashes = addslashes; global.AsyncFunction = AsyncFunction; -exports.VERSIONINFO = "Standard Lib (std.js) version 0.4"; +exports.VERSIONINFO = "Standard Lib (std.js) version 0.5"; exports.global = global; exports.require = global.require; exports.Event = StdEvent; -exports.EventableObject = StdEventableObject; \ No newline at end of file +exports.EventableObject = StdEventableObject;