Update std.js

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

View File

@ -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;
}
}
}
}