20 lines
556 B
TypeScript
20 lines
556 B
TypeScript
import type { Item } from '../fs/Item'
|
|
import type { SimpleStream } from '../utils/SimpleStream'
|
|
import { Program } from './Program'
|
|
|
|
export class Eval extends Program {
|
|
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, _workdir: Item, args: string[]): Promise<number> {
|
|
const javascript = args.slice(1).join(' ')
|
|
|
|
try {
|
|
// todo: pass workdir to the program
|
|
eval(javascript)
|
|
} catch (e) {
|
|
stdout.emit(`${String(e)}\n`)
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
}
|