mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +00:00
Update std.js
This commit is contained in:
parent
17bbdadbb4
commit
388c0ae3d0
31
lib/std.js
31
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user