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; StdEventTarget.__counter__ = 0;
function AsyncFunction(f, _filename) { /*
var a = new AsyncFunction(function() {
console.log("calling");
});
*/
function AsyncFunction(f, __filename) {
this.f = f; this.f = f;
this._filename = _filename; this.__filename = __filename;
this.run = function() { this.run = function() {
var args = Array.from(arguments); var args = Array.from(arguments);
@ -415,7 +420,7 @@ function AsyncFunction(f, _filename) {
// CLI or Window? // CLI or Window?
if (typeof WScript !== "undefined") { 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 { } else {
sleep(1, _f); sleep(1, _f);
} }
@ -430,15 +435,19 @@ AsyncFunction.bind = function(exports, args) {
var result = false; var result = false;
if (args.length > 0) { if (args.length > 0) {
var f = '_async_' + args[0]; var targets = [args[0], '_async_' + args[0]];
if (f in exports && typeof exports[f] === "function") { for (var i = 0; (i < targets.length && result == false); i++) {
try { var target = targets[i];
exports[f](args);
result = true; if (target in exports && (typeof exports[target] === "function" || exports[target] instanceof AsyncFunction)) {
} catch (e) { try {
console.error("AsyncFunction.bind exception", e.message); exports[target](args);
result = false; result = true;
} catch (e) {
console.error("Exception of AsyncFunction.bind", e.message);
result = false;
}
} }
} }
} }