MWSE/console/official/native/js.js

51 lines
1.2 KiB
JavaScript

class CommandJS{
stdin = null;
stdout = null;
stderr = null;
constructor(pipe){
this.stdin = pipe.stdin;
this.stdout = pipe.stdout;
this.stderr = pipe.stderr;
}
async main(args)
{
let commandline = args.find(e => e.type == "arguments");
if(commandline)
{
try{
let t = eval(commandline.data);
if(typeof t != "undefined")
{
this.stdout.writeln(JSON.stringify(t,null, ' ').replace(/\n/g,'\r\n'));
}
}catch(e){
this.stderr.writeln(e.message);
}
}
this.exit();
}
};
class CommandJSRaw{
stdin = null;
stdout = null;
stderr = null;
constructor(pipe){
this.stdin = pipe.stdin;
this.stdout = pipe.stdout;
this.stderr = pipe.stderr;
}
async main(args)
{
let commandline = args.find(e => e.type == "arguments");
if(commandline)
{
let t = eval(commandline.data);
this.stdout.writeln(t);
}
this.exit();
}
};
CommandNamespace.namespaces.set('js', CommandJS);
CommandNamespace.namespaces.set('jsecho', CommandJSRaw);