mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 09:24:58 +00:00
Update app.js, lib/std.js
This commit is contained in:
parent
04c2325ade
commit
cfc9501554
27
app.js
27
app.js
|
@ -33,15 +33,17 @@
|
|||
// must define main = function(args) {}, which is called once the module is
|
||||
// loaded.
|
||||
//
|
||||
// Report abuse or security issue: abuse@catswords.net
|
||||
// app.js
|
||||
// Namhyeon Go <abuse@catswords.net>
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
// If you find an abuse case or a security issue, please feel free to contact me.
|
||||
//
|
||||
|
||||
var exit = function(status) {
|
||||
console.error("Exit", status, "caused");
|
||||
|
||||
if (typeof WScript !== "undefined") {
|
||||
WScript.quit(status);
|
||||
WScript.Quit(status);
|
||||
} else if (typeof window !== "undefined") {
|
||||
window.close();
|
||||
}
|
||||
|
@ -63,7 +65,7 @@ var console = {
|
|||
_echoCallback: null,
|
||||
_wshEcho: function(message) {
|
||||
if (typeof WScript !== "undefined") {
|
||||
WScript.echo("[*] " + message)
|
||||
WScript.Echo("[*] " + message)
|
||||
}
|
||||
},
|
||||
_echo: function(args, type) {
|
||||
|
@ -187,7 +189,12 @@ if (typeof CreateObject === "undefined") {
|
|||
};
|
||||
CreateObject.make = function(p, s) {
|
||||
if (typeof WScript !== "undefined") {
|
||||
return WScript.CreateObject(p, s);
|
||||
if ("CreateObject" in WScript) {
|
||||
return WScript.CreateObject(p, s);
|
||||
} else {
|
||||
console.warn("(Chakra) The standalone engine does not supported. Please use the built-in engine.");
|
||||
console.warn("(Chakra) hint:", "cscript //NoLogo //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} app.js <filename> <...arguments>");
|
||||
}
|
||||
} else if (typeof ActiveXObject !== "undefined") {
|
||||
return new ActiveXObject(p);
|
||||
}
|
||||
|
@ -324,10 +331,16 @@ require.__getDirName__ = function(path) {
|
|||
};
|
||||
require.__getCurrentScriptDirectory__ = function() {
|
||||
if (typeof WScript !== "undefined") {
|
||||
return require.__getDirName__(WScript.ScriptFullName);
|
||||
if ("ScriptFullName" in WScript) {
|
||||
return require.__getDirName__(WScript.ScriptFullName);
|
||||
} else {
|
||||
console.warn("Could not resolve an absolute path. Use the relative path.");
|
||||
return ".";
|
||||
}
|
||||
} else if (typeof document !== "undefined") {
|
||||
return require.__getDirName__(document.location.pathname);
|
||||
} else {
|
||||
console.warn("Could not resolve an absolute path. Use the relative path.");
|
||||
return ".";
|
||||
}
|
||||
};
|
||||
|
@ -493,7 +506,9 @@ function initializeWindow(name, args, w, h) {
|
|||
}
|
||||
|
||||
// JSON 2
|
||||
__include__("app/assets/js/json2");
|
||||
if (typeof JSON === "undefined") {
|
||||
__include__("app/assets/js/json2");
|
||||
}
|
||||
|
||||
// core-js (aka. babel-polyfill)
|
||||
require("app/assets/js/core-js-3.26.1.minified");
|
||||
|
|
62
lib/std.js
62
lib/std.js
|
@ -30,38 +30,40 @@ if (!Function.prototype.GetResource) {
|
|||
// The provided code snippet has been corrected by ChatGPT.
|
||||
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
|
||||
// Related issues: #75 #42 #30
|
||||
Enumerator.prototype.toArray = function() {
|
||||
var result = [];
|
||||
while (!this.atEnd()) {
|
||||
var currentItem = this.item();
|
||||
var currentItemProperties = currentItem.Properties_;
|
||||
var itemObject = {};
|
||||
if (typeof Enumerator !== "undefined") {
|
||||
Enumerator.prototype.toArray = function() {
|
||||
var result = [];
|
||||
while (!this.atEnd()) {
|
||||
var currentItem = this.item();
|
||||
var currentItemProperties = currentItem.Properties_;
|
||||
var itemObject = {};
|
||||
|
||||
var propertiesEnumerator = new Enumerator(currentItemProperties);
|
||||
while (!propertiesEnumerator.atEnd()) {
|
||||
var property = propertiesEnumerator.item();
|
||||
if (typeof property.value !== "unknown") { // The type "Unknown" is Array
|
||||
itemObject[property.name] = property.value;
|
||||
} else {
|
||||
var arrayValues = [];
|
||||
var index = 0;
|
||||
while (true) {
|
||||
try {
|
||||
arrayValues.push(property.value(index));
|
||||
index++;
|
||||
} catch (e) {
|
||||
break;
|
||||
var propertiesEnumerator = new Enumerator(currentItemProperties);
|
||||
while (!propertiesEnumerator.atEnd()) {
|
||||
var property = propertiesEnumerator.item();
|
||||
if (typeof property.value !== "unknown") { // The type "Unknown" is Array
|
||||
itemObject[property.name] = property.value;
|
||||
} else {
|
||||
var arrayValues = [];
|
||||
var index = 0;
|
||||
while (true) {
|
||||
try {
|
||||
arrayValues.push(property.value(index));
|
||||
index++;
|
||||
} catch (e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
itemObject[property.name] = arrayValues;
|
||||
}
|
||||
itemObject[property.name] = arrayValues;
|
||||
propertiesEnumerator.moveNext();
|
||||
}
|
||||
propertiesEnumerator.moveNext();
|
||||
result.push(itemObject);
|
||||
this.moveNext();
|
||||
}
|
||||
result.push(itemObject);
|
||||
this.moveNext();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Global APIs
|
||||
|
@ -88,11 +90,11 @@ function sleep(ms, callback) {
|
|||
|
||||
if (typeof callback === "function") {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
} else if (typeof window !== "undefined") {
|
||||
if (typeof callback === "function") {
|
||||
handler = setTimeout(callback, ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -583,7 +585,7 @@ exports.Storage = StdStorage;
|
|||
exports.alert = alert;
|
||||
exports.confirm = confirm;
|
||||
|
||||
exports.VERSIONINFO = "Standard Library (std.js) version 0.8.3";
|
||||
exports.VERSIONINFO = "Standard Library (std.js) version 0.8.4";
|
||||
exports.AUTHOR = "abuse@catswords.net";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
Loading…
Reference in New Issue
Block a user