aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/Scripting.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-22 17:16:18 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-22 17:16:18 -0400
commitf82458be8bc8beaab387cc2813b7b18c9b3caac2 (patch)
tree4d547ad7f2623257cc585e16df17c05c8979e06a /src/client/util/Scripting.ts
parentf529d7d22162689c08830418da67a89778111e16 (diff)
initial commit post master merge
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 };