Skip to content

Commit 1551faa

Browse files
authored
docs: Add documentation to safeRegexTest (#10227)
1 parent eba2656 commit 1551faa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/LiveQuery/QueryTools.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ var vm = require('vm');
55
var logger = require('../logger').default;
66

77
var regexTimeout = 0;
8+
// IMPORTANT: vmContext is shared across all calls for performance (vm.createContext() is expensive).
9+
// This is safe because safeRegexTest is synchronous — setting the context properties and calling
10+
// runInContext happen in the same event loop tick with no interruption possible. Do NOT add any
11+
// asynchronous operations (await, callbacks, promises) between setting vmContext properties and
12+
// calling script.runInContext, as this would allow other calls to overwrite the context values
13+
// and cause cross-contamination between regex evaluations.
814
var vmContext = vm.createContext(Object.create(null));
915
var scriptCache = new Map();
1016
var SCRIPT_CACHE_MAX = 1000;
@@ -13,6 +19,7 @@ function setRegexTimeout(ms) {
1319
regexTimeout = ms;
1420
}
1521

22+
// IMPORTANT: This function must remain synchronous. See vmContext comment above.
1623
function safeRegexTest(pattern, flags, input) {
1724
try {
1825
if (!regexTimeout) {

0 commit comments

Comments
 (0)