Fix duplicate logs from scripts when ext is used
This commit is contained in:
1 parent
38e83d8544
commit
21816ed8ef
1 file changed
+11
-4
+11
-4
@@ -193,6 +193,7 @@ function commit() {
|
||||
|
||||
|
||||
function ext() {
|
||||
++ state.extCounter;
|
||||
let extCall = Array.from(arguments).map(String);
|
||||
let key = `${state.revision}: ${JSON.stringify(extCall)}`;
|
||||
|
||||
@@ -205,7 +206,7 @@ function ext() {
|
||||
|
||||
|
||||
function log(msg, meta) {
|
||||
if (state.revision === state.maxRevision) {
|
||||
if (state.revision === state.maxRevision && state.extCounter >= 0) {
|
||||
const details = Object.assign({}, meta, {
|
||||
sessionContext: state.sessionContext,
|
||||
message: `Script: ${msg}`
|
||||
@@ -255,7 +256,7 @@ function errorToFault(err) {
|
||||
}
|
||||
|
||||
|
||||
function run(script, globals, sessionContext, startRevision, maxRevision, callback) {
|
||||
function run(script, globals, sessionContext, startRevision, maxRevision, callback, extCounter = 0) {
|
||||
state = {
|
||||
sessionContext: sessionContext,
|
||||
revision: startRevision,
|
||||
@@ -264,7 +265,8 @@ function run(script, globals, sessionContext, startRevision, maxRevision, callba
|
||||
declarations: [],
|
||||
extensions: {},
|
||||
clear: [],
|
||||
rng: null
|
||||
rng: null,
|
||||
extCounter: extCounter
|
||||
};
|
||||
|
||||
for (let n of Object.keys(context))
|
||||
@@ -288,7 +290,12 @@ function run(script, globals, sessionContext, startRevision, maxRevision, callba
|
||||
}
|
||||
|
||||
let _state = state;
|
||||
let args = arguments;
|
||||
let args = Array.from(arguments);
|
||||
|
||||
// Need to maintain a counter of ext() calls to avoid calling certain
|
||||
// functions (e.g. log()) multiple times as calling ext() results in
|
||||
// re-execution of script without revision being incremented.
|
||||
args[6] = 0 - (state.extCounter - extCounter);
|
||||
|
||||
let counter = 3;
|
||||
for (let key of Object.keys(_state.extensions)) {
|
||||
|
||||
Reference in new issue
Block a user