aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/Scripting.ts
diff options
context:
space:
mode:
authorandrewdkim <adkim414@gmail.com>2019-10-01 18:55:50 -0400
committerandrewdkim <adkim414@gmail.com>2019-10-01 18:55:50 -0400
commit23619154f8688ffcb25a988158d75934c0cacbf7 (patch)
treed7462da0f0e8b9de091263af166959872e8af0f6 /src/client/util/Scripting.ts
parent45b9f489033cd323614463ca9c36f41900bf1965 (diff)
parent69e4a936c4eb0cc2e35e4e7f3258aed1f72b8da7 (diff)
still unfinished
Diffstat (limited to 'src/client/util/Scripting.ts')
-rw-r--r--src/client/util/Scripting.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 1d0916ac0..ff4451824 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -19,6 +19,7 @@ export interface ScriptSucccess {
export interface ScriptError {
success: false;
error: any;
+ result: any;
}
export type ScriptResult = ScriptSucccess | ScriptError;
@@ -27,7 +28,7 @@ export interface CompiledScript {
readonly compiled: true;
readonly originalScript: string;
readonly options: Readonly<ScriptOptions>;
- run(args?: { [name: string]: any }): ScriptResult;
+ run(args?: { [name: string]: any }, onError?: (res: any) => void, errorVal?: any): ScriptResult;
}
export interface CompileError {
@@ -100,7 +101,7 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
// let params: any[] = [Docs, ...fieldTypes];
let compiledFunction = new Function(...paramNames, `return ${script}`);
let { capturedVariables = {} } = options;
- let run = (args: { [name: string]: any } = {}): ScriptResult => {
+ let run = (args: { [name: string]: any } = {}, onError?: (e: any) => void, errorVal?: any): ScriptResult => {
let argsArray: any[] = [];
for (let name of customParams) {
if (name === "this") {
@@ -127,7 +128,8 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
if (batch) {
batch.end();
}
- return { success: false, error };
+ onError && onError(error);
+ return { success: false, error, result: errorVal };
}
};
return { compiled: true, run, originalScript, options };