Update app.js, lib/std.js

This commit is contained in:
Namhyeon Go 2024-01-08 15:42:54 +09:00
parent 04c2325ade
commit cfc9501554
2 changed files with 53 additions and 36 deletions

27
app.js
View File

@ -33,15 +33,17 @@
// must define main = function(args) {}, which is called once the module is // must define main = function(args) {}, which is called once the module is
// loaded. // loaded.
// //
// Report abuse or security issue: abuse@catswords.net // app.js
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs // 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) { var exit = function(status) {
console.error("Exit", status, "caused"); console.error("Exit", status, "caused");
if (typeof WScript !== "undefined") { if (typeof WScript !== "undefined") {
WScript.quit(status); WScript.Quit(status);
} else if (typeof window !== "undefined") { } else if (typeof window !== "undefined") {
window.close(); window.close();
} }
@ -63,7 +65,7 @@ var console = {
_echoCallback: null, _echoCallback: null,
_wshEcho: function(message) { _wshEcho: function(message) {
if (typeof WScript !== "undefined") { if (typeof WScript !== "undefined") {
WScript.echo("[*] " + message) WScript.Echo("[*] " + message)
} }
}, },
_echo: function(args, type) { _echo: function(args, type) {
@ -187,7 +189,12 @@ if (typeof CreateObject === "undefined") {
}; };
CreateObject.make = function(p, s) { CreateObject.make = function(p, s) {
if (typeof WScript !== "undefined") { 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") { } else if (typeof ActiveXObject !== "undefined") {
return new ActiveXObject(p); return new ActiveXObject(p);
} }
@ -324,10 +331,16 @@ require.__getDirName__ = function(path) {
}; };
require.__getCurrentScriptDirectory__ = function() { require.__getCurrentScriptDirectory__ = function() {
if (typeof WScript !== "undefined") { 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") { } else if (typeof document !== "undefined") {
return require.__getDirName__(document.location.pathname); return require.__getDirName__(document.location.pathname);
} else { } else {
console.warn("Could not resolve an absolute path. Use the relative path.");
return "."; return ".";
} }
}; };
@ -493,7 +506,9 @@ function initializeWindow(name, args, w, h) {
} }
// JSON 2 // JSON 2
__include__("app/assets/js/json2"); if (typeof JSON === "undefined") {
__include__("app/assets/js/json2");
}
// core-js (aka. babel-polyfill) // core-js (aka. babel-polyfill)
require("app/assets/js/core-js-3.26.1.minified"); require("app/assets/js/core-js-3.26.1.minified");

View File

@ -30,38 +30,40 @@ if (!Function.prototype.GetResource) {
// The provided code snippet has been corrected by ChatGPT. // The provided code snippet has been corrected by ChatGPT.
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa // https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
// Related issues: #75 #42 #30 // Related issues: #75 #42 #30
Enumerator.prototype.toArray = function() { if (typeof Enumerator !== "undefined") {
var result = []; Enumerator.prototype.toArray = function() {
while (!this.atEnd()) { var result = [];
var currentItem = this.item(); while (!this.atEnd()) {
var currentItemProperties = currentItem.Properties_; var currentItem = this.item();
var itemObject = {}; var currentItemProperties = currentItem.Properties_;
var itemObject = {};
var propertiesEnumerator = new Enumerator(currentItemProperties); var propertiesEnumerator = new Enumerator(currentItemProperties);
while (!propertiesEnumerator.atEnd()) { while (!propertiesEnumerator.atEnd()) {
var property = propertiesEnumerator.item(); var property = propertiesEnumerator.item();
if (typeof property.value !== "unknown") { // The type "Unknown" is Array if (typeof property.value !== "unknown") { // The type "Unknown" is Array
itemObject[property.name] = property.value; itemObject[property.name] = property.value;
} else { } else {
var arrayValues = []; var arrayValues = [];
var index = 0; var index = 0;
while (true) { while (true) {
try { try {
arrayValues.push(property.value(index)); arrayValues.push(property.value(index));
index++; index++;
} catch (e) { } catch (e) {
break; break;
}
} }
itemObject[property.name] = arrayValues;
} }
itemObject[property.name] = arrayValues; propertiesEnumerator.moveNext();
} }
propertiesEnumerator.moveNext(); result.push(itemObject);
this.moveNext();
} }
result.push(itemObject); return result;
this.moveNext(); };
} }
return result;
};
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Global APIs // Global APIs
@ -88,11 +90,11 @@ function sleep(ms, callback) {
if (typeof callback === "function") { if (typeof callback === "function") {
callback(); callback();
} }
} else if (typeof window !== "undefined") { } else if (typeof window !== "undefined") {
if (typeof callback === "function") { if (typeof callback === "function") {
handler = setTimeout(callback, ms); handler = setTimeout(callback, ms);
} }
} }
return { return {
@ -583,7 +585,7 @@ exports.Storage = StdStorage;
exports.alert = alert; exports.alert = alert;
exports.confirm = confirm; 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.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;