Fix duplicate logs from scripts when ext is used

This commit is contained in:
Zaid Abdulla committed 2017-03-07 15:08:23 -08:00
1 parent 38e83d8544
commit 21816ed8ef
1 file changed
+11 -4
+11 -4
View File
@@ -193,6 +193,7 @@ function commit() {
function ext() { function ext() {
++ state.extCounter;
let extCall = Array.from(arguments).map(String); let extCall = Array.from(arguments).map(String);
let key = `${state.revision}: ${JSON.stringify(extCall)}`; let key = `${state.revision}: ${JSON.stringify(extCall)}`;
@@ -205,7 +206,7 @@ function ext() {
function log(msg, meta) { function log(msg, meta) {
if (state.revision === state.maxRevision) { if (state.revision === state.maxRevision && state.extCounter >= 0) {
const details = Object.assign({}, meta, { const details = Object.assign({}, meta, {
sessionContext: state.sessionContext, sessionContext: state.sessionContext,
message: `Script: ${msg}` 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 = { state = {
sessionContext: sessionContext, sessionContext: sessionContext,
revision: startRevision, revision: startRevision,
@@ -264,7 +265,8 @@ function run(script, globals, sessionContext, startRevision, maxRevision, callba
declarations: [], declarations: [],
extensions: {}, extensions: {},
clear: [], clear: [],
rng: null rng: null,
extCounter: extCounter
}; };
for (let n of Object.keys(context)) for (let n of Object.keys(context))
@@ -288,7 +290,12 @@ function run(script, globals, sessionContext, startRevision, maxRevision, callba
} }
let _state = state; 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; let counter = 3;
for (let key of Object.keys(_state.extensions)) { for (let key of Object.keys(_state.extensions)) {