Fix something wrong

This commit is contained in:
Namhyeon Go 2022-02-10 15:25:19 +09:00
parent 255f9dab32
commit 403095c5cb
5 changed files with 219 additions and 77 deletions

View File

@ -10,7 +10,6 @@ var FILE = require("lib/file");
var HTTP = require("lib/http"); var HTTP = require("lib/http");
var Websocket = require("lib/websocket"); var Websocket = require("lib/websocket");
var AutoIt = require("lib/autoit"); var AutoIt = require("lib/autoit");
var ToolKit = require("lib/toolkit");
// for remote debugging // for remote debugging
var pageEventId = 0; var pageEventId = 0;
@ -42,7 +41,6 @@ var ChromeObject = function(interfaces) {
// dependencies // dependencies
this.oAutoIt = null; this.oAutoIt = null;
this.oToolkit = null;
// for remote debugging // for remote debugging
this.debuggingPort = 0; this.debuggingPort = 0;
@ -57,7 +55,6 @@ var ChromeObject = function(interfaces) {
this.create = function() { this.create = function() {
this.oAutoIt = AutoIt.create(); this.oAutoIt = AutoIt.create();
this.oToolkit = ToolKit.create();
return this; return this;
}; };
@ -1174,10 +1171,6 @@ var ChromeObject = function(interfaces) {
this.oAutoIt.callFunction("MouseClick", ["left"]); this.oAutoIt.callFunction("MouseClick", ["left"]);
}; };
this.vMouseClick = function(x, y) {
this.oToolkit.sendClick(this.pageId.substring(0, 6), x, y, 1);
};
this.mouseWheelUp = function() { this.mouseWheelUp = function() {
this.oAutoIt.callFunction("MouseWheel", ["up"]); this.oAutoIt.callFunction("MouseWheel", ["up"]);
}; };

View File

@ -39,5 +39,5 @@ exports.execCommand = function(cmd) {
}; };
exports.runAs = function(cmd) { exports.runAs = function(cmd) {
return exports.execCommand("Start-Process cmd \"/q /c " + addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs"); return exports.execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
}; };

View File

@ -3,17 +3,6 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var FILE = require("lib/file"); var FILE = require("lib/file");
var addslashes = function(s) {
return s.toString().replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"');
};
var ShellObject = function() { var ShellObject = function() {
this.interface = null; this.interface = null;
this.currentDirectory = null; this.currentDirectory = null;
@ -36,7 +25,7 @@ var ShellObject = function() {
if (typeof(dirname) === "string") { if (typeof(dirname) === "string") {
this.workingDirectory = dirname; this.workingDirectory = dirname;
this.interface.CurrentDirectory = this.workingDirectory; this.interface.CurrentDirectory = this.workingDirectory;
console.info("ShellObject.workingDirectory ->", this.workingDirectory); console.log("ShellObject.workingDirectory ->", this.workingDirectory);
} }
return this; return this;
}; };
@ -53,7 +42,7 @@ var ShellObject = function() {
return cmd.map(function(s) { return cmd.map(function(s) {
if (s == '') { if (s == '') {
return "''"; return "''";
} else if (!/[ "=]/g.test(s)) { } else if (!/[ "]/g.test(s)) {
return s; return s;
} else { } else {
return "\"" + addslashes(s) + "\""; return "\"" + addslashes(s) + "\"";
@ -67,7 +56,7 @@ var ShellObject = function() {
this.createProcess = function(cmd) { this.createProcess = function(cmd) {
try { try {
var c = this.build(cmd); var c = this.build(cmd);
console.info("ShellObject.createProcess() ->", c); console.log("ShellObject.createProcess() ->", c);
return this.interface.Exec(c); return this.interface.Exec(c);
} catch (e) { } catch (e) {
console.error("ShellObject.createProcess() ->", e.message); console.error("ShellObject.createProcess() ->", e.message);
@ -84,7 +73,7 @@ var ShellObject = function() {
//c += " 2>&1"; //c += " 2>&1";
c += " 2> " + stdErrPath; c += " 2> " + stdErrPath;
this.interface.Run(c, 0, true); this.interface.Run(c, 0, true);
console.info("ShellObject.exec() ->", c); console.log("ShellObject.exec() ->", c);
sleep(1); sleep(1);
if (FILE.fileExists(stdOutPath)) { if (FILE.fileExists(stdOutPath)) {
@ -97,6 +86,7 @@ var ShellObject = function() {
FILE.deleteFile(stdErrPath); FILE.deleteFile(stdErrPath);
} }
console.log(c);
//console.log("[stdout] " + stdout); //console.log("[stdout] " + stdout);
//console.log("[stderr] " + stderr); //console.log("[stderr] " + stderr);
@ -106,14 +96,14 @@ var ShellObject = function() {
this.run = function(cmd, fork) { this.run = function(cmd, fork) {
var fork = (typeof(fork) !== "undefined") ? fork : true; var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c (" + this.build(cmd) + ")"; var c = "%comspec% /q /c (" + this.build(cmd) + ")";
console.info("ShellObject.run() ->", c); console.log("ShellObject.run() ->", c);
this.interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork); this.interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork);
}; };
this.runAs = function(FN, args) { this.runAs = function(FN, args) {
var oShell = CreateObject("Shell.Application"); var oShell = CreateObject("Shell.Application");
var _args = null; var _args = null;
console.info("ShellObject.runAs() ->", FN); console.log("ShellObject.runAs() ->", FN);
if (typeof(args) !== "undefined") { if (typeof(args) !== "undefined") {
_args = args.join(' '); _args = args.join(' ');
} }
@ -145,7 +135,7 @@ var ShellObject = function() {
}; };
this.release = function() { this.release = function() {
console.info("ShellObject.release() ->", this.currentDirectory); console.log("ShellObject.release() ->", this.currentDirectory);
this.interface.CurrentDirectory = this.currentDirectory; this.interface.CurrentDirectory = this.currentDirectory;
this.interface = null; this.interface = null;
}; };
@ -175,7 +165,7 @@ exports.runVisibleWindow = function(cmd, fork) {
exports.createProcess = function(cmd, workingDirectory) { exports.createProcess = function(cmd, workingDirectory) {
if (typeof(workingDirectory) !== "undefined") { if (typeof(workingDirectory) !== "undefined") {
console.info("Working directory: " + workingDirectory); console.log("Working directory: " + workingDirectory);
} }
return (new ShellObject()).setWorkingDirectory(workingDirectory).createProcess(cmd); return (new ShellObject()).setWorkingDirectory(workingDirectory).createProcess(cmd);
}; };

View File

@ -10,6 +10,7 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Polyfills // Polyfills
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
if (!Function.prototype.GetResource) { if (!Function.prototype.GetResource) {
Function.prototype.GetResource = function(ResourceName) { Function.prototype.GetResource = function(ResourceName) {
if (!this.Resources) { if (!this.Resources) {
@ -27,16 +28,37 @@ if (!Function.prototype.GetResource) {
} }
} }
// MS JScript Enumerator to Array
if (!Enumerator.prototype.toArray) { if (!Enumerator.prototype.toArray) {
Enumerator.prototype.toArray = function() { Enumerator.prototype.toArray = function() {
var items = []; var a = [];
for (; !this.atEnd(); this.moveNext()) { for (; !this.atEnd(); this.moveNext()) {
var item = this.item(); var x = {};
var b = new Enumerator(this.item().Properties_);
for (; !b.atEnd(); b.moveNext()) {
var c = b.item();
if (typeof c.value !== "unknown") {
try { try {
items.push(item); x[c.name] = c.value.toString();
} catch (e) {} } catch (e) {
x[c.name] = c.value;
} }
return items; } else {
var i = 0, d = [];
while (true) {
try {
d.push(c.value(i));
i++;
} catch (e) {
break;
}
}
x[c.name] = d;
}
}
a.push(x);
}
return a;
}; };
} }
@ -44,27 +66,175 @@ if (!Enumerator.prototype.toArray) {
// Global APIs // Global APIs
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
global.GetResource = function(ResourceName) { function GetResource(ResourceName) {
return arguments.callee.caller.GetResource(ResourceName); return arguments.callee.caller.GetResource(ResourceName);
} }
global.sleep = function(ms, callback) { // [lib/std] the time of `sleep()' function is not accuracy #34
if (typeof(WScript) !== "undefined") { function sleep(ms, callback) {
var handler = null;
var cur = Date.now();
var end = cur + ms;
if (typeof WScript !== "undefined") {
/*
while (cur < end) {
//WScript.Sleep(1);
cur = Date.now();
}
end = Date.now();
*/
WScript.Sleep(ms); WScript.Sleep(ms);
if (typeof(callback) === "function") { if (typeof callback === "function")
callback(); callback()
;
} else if (typeof window !== "undefined") {
if (typeof callback === "function")
handler = setTimeout(callback, ms);
;
} }
} else {
if (typeof(callback) === "function") { return { 'ms': end, 'handler': handler };
setTimeout(callback, ms); };
function repeat(target, callback, onError) {
switch (typeof target) {
case "number":
case "boolean":
var ms = target;
var i = 0;
var result = null;
var handler = null;
var cur = Date.now();
var end = cur + ms;
if (typeof WScript !== "undefined") {
while (ms === true ? true : (cur < end)) {
try {
if (typeof callback === "function")
var result = callback(i);
if (typeof result === "number") {
i += result;
} else if (result === false) {
break;
} }
;
} catch (e) {
if (typeof onError === "function")
if (onError(e) === false)
break
;
;
}
cur = Date.now();
}
end = Date.now();
} else if (typeof window !== "undefined") {
if (typeof callback === "function")
handler = setInterval(callback, ms);
;
}
return { 'ms': end, 'handler': handler };
case "object":
var arr = target;
for (var i = 0; i < arr.length; i++) {
try {
if (typeof callback === "function")
if (callback(i, arr[i]) === false)
break
;
;
} catch (e) {
if (typeof onError === "function")
if (onError(e) === false)
break
;
;
}
}
break;
} }
}; };
global.CHR = function(ord) { function rotate(target, callback, onError) {
var arr = target;
var i = 0;
var stop = false;
while (!stop) {
try {
if (typeof callback === "function") {
stop = callback(i, arr[i]);
} else {
stop = true;
}
} catch (e) {
if (typeof onError === "function")
stop = onError(e);
;
}
i++;
i = i % keywords.length;
}
};
function range() {
var args = arguments;
var N = [], start, end, step;
switch(args.length) {
case 3:
start = args[0];
end = args[1];
step = args[2];
break;
case 2:
start = args[0];
end = args[1];
step = 1;
break;
case 1:
start = 0;
end = args[0];
step = 1;
break;
}
for (var i = start; i < end; i = i + step)
N.push(i)
;
return N;
};
function CHR(ord) {
return String.fromCharCode(ord); return String.fromCharCode(ord);
}; };
function splitLn(s) {
return s.split(/\r?\n/);
};
function addslashes(s) {
return s.toString().replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"')
;
};
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Private APIs / Utility functions // Private APIs / Utility functions
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -73,7 +243,7 @@ global.CHR = function(ord) {
// Emulate Server.CreateObject // Emulate Server.CreateObject
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
exports.CreateObject = function(progId, serverName, callback) { function CreateObject(progId, serverName, callback) {
var progIds = []; var progIds = [];
var _CreateObject = function(p, s) { var _CreateObject = function(p, s) {
if (typeof(WScript) !== "undefined") { if (typeof(WScript) !== "undefined") {
@ -102,42 +272,22 @@ exports.CreateObject = function(progId, serverName, callback) {
} }
}; };
/////////////////////////////////////////////////////////////////////////////////
// Standard Event Object
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var StdEvent = function(eventName) { function StdEvent(eventName) {
this.bubbles = false; // Not supported
this.cancelable = false; // Not supported
this.composed = false; // Not supported
this.currentTarget = null; // Not supported
this.defaultPrevented = false; this.defaultPrevented = false;
this.eventPhase = null; // TODO
this.isTrusted = true; // Not supported
this.timeStamp = new Date(); this.timeStamp = new Date();
this.eventName = eventName; this.eventName = eventName;
this.target = null; this.target = null;
// Not supported
this.composedPath = function() {
return null;
};
this.preventDefault = function() { this.preventDefault = function() {
this.defaultPrevented = true; this.defaultPrevented = true;
}; };
// Not supported
this.stopImmediatePropagation = function() {
return null;
}; };
// Not supported function StdEventableObject() {
this.setPropagation = function() {
return null;
};
};
var StdEventableObject = function() {
this.dispatchEvent = function(event) { this.dispatchEvent = function(event) {
event.target = this; event.target = this;
if(('on' + event.eventName) in this) this['on' + event.eventName](event); if(('on' + event.eventName) in this) this['on' + event.eventName](event);
@ -152,7 +302,16 @@ var StdEventableObject = function() {
}; };
}; };
exports.VERSIONINFO = "Standard Lib (std.js) version 0.3"; global.GetResource = GetResource;
global.sleep = sleep;
global.repeat = repeat;
global.rotate = rotate;
global.range = range;
global.CHR = CHR;
global.splitLn = splitLn;
global.addslashes = addslashes;
exports.VERSIONINFO = "Standard Lib (std.js) version 0.4";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -10,7 +10,7 @@ var ToolkitObject = function() {
this.interface = CreateObject("WelsonJS.Toolkit"); this.interface = CreateObject("WelsonJS.Toolkit");
return this; return this;
} catch (e) { } catch (e) {
console.warn("WelsonJS.Toolkit is disabled"); console.error("ToolkitObject.create() ->", e.message);
} }
}; };