diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/pipeline/expression_js_emit.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/pipeline/expression_js_emit.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/expression_js_emit.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/expression_js_emit.cpp b/src/mongo/db/pipeline/expression_js_emit.cpp index d19a9c53191..ca6ba238c6e 100644 --- a/src/mongo/db/pipeline/expression_js_emit.cpp +++ b/src/mongo/db/pipeline/expression_js_emit.cpp @@ -145,11 +145,14 @@ Value ExpressionInternalJsEmit::evaluate(const Document& root, Variables* variab ExpressionContext* expCtx = getExpressionContext(); auto jsExec = expCtx->getJsExecWithScope(); - // Inject the native "emit" function to be called from the user-defined map function. This - // particular Expression/ExpressionContext may be reattached to a new OperationContext (and thus - // a new JS Scope) when used across getMore operations, so this method will handle that case for - // us by only injecting if we haven't already. - jsExec->injectEmitIfNecessary(emitFromJS, &_emitState); + + // Inject the native "emit" function to be called from the user-defined map function. + // + // We reinject this function on every invocation of evaluate(), because there is a single + // JsExecution instance for the OperationContext, which may be shared by multiple aggregation + // pipelines and we need to ensure that the injected function still points to the valid + // contextual data ('_emitState'). + jsExec->injectEmit(emitFromJS, &_emitState); // Although inefficient to "create" a new function every time we evaluate, this will usually end // up being a simple cache lookup. This is needed because the JS Scope may have been recreated |
