From 388c0ae3d07afbb0beeaa254ee571d12b0b8e62e Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Tue, 14 Mar 2023 13:50:26 +0900 Subject: [PATCH] Update std.js --- lib/std.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/std.js b/lib/std.js index b1bf963..3c72633 100644 --- a/lib/std.js +++ b/lib/std.js @@ -396,9 +396,14 @@ function StdEventTarget() { }; StdEventTarget.__counter__ = 0; -function AsyncFunction(f, _filename) { +/* +var a = new AsyncFunction(function() { + console.log("calling"); +}); +*/ +function AsyncFunction(f, __filename) { this.f = f; - this._filename = _filename; + this.__filename = __filename; this.run = function() { var args = Array.from(arguments); @@ -415,7 +420,7 @@ function AsyncFunction(f, _filename) { // CLI or Window? if (typeof WScript !== "undefined") { - require("lib/shell").show(["cscript", "app.js", this._filename, f].concat(args)); + require("lib/shell").show(["cscript", "app.js", this.__filename, f].concat(args)); } else { sleep(1, _f); } @@ -430,15 +435,19 @@ AsyncFunction.bind = function(exports, args) { var result = false; if (args.length > 0) { - var f = '_async_' + args[0]; + var targets = [args[0], '_async_' + args[0]]; - if (f in exports && typeof exports[f] === "function") { - try { - exports[f](args); - result = true; - } catch (e) { - console.error("AsyncFunction.bind exception", e.message); - result = false; + for (var i = 0; (i < targets.length && result == false); i++) { + var target = targets[i]; + + if (target in exports && (typeof exports[target] === "function" || exports[target] instanceof AsyncFunction)) { + try { + exports[target](args); + result = true; + } catch (e) { + console.error("Exception of AsyncFunction.bind", e.message); + result = false; + } } } }