Merge branch 'master' into global-bindings

This commit is contained in:
deanhannigan 2024-01-10 11:10:51 +00:00 committed by GitHub
commit c787d21c94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 38 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "2.14.4", "version": "2.14.5",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*", "packages/*",

View File

@ -12,51 +12,49 @@ export function init() {
const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS
let track: TrackerFn = f => f() let track: TrackerFn = f => f()
if (perRequestLimit) { if (perRequestLimit) {
tracer.trace<any>("runJS.setupTracker", {}, span => { const bbCtx = tracer.trace("runJS.getCurrentContext", {}, span =>
const bbCtx = context.getCurrentContext() context.getCurrentContext()
if (bbCtx) { )
if (!bbCtx.jsExecutionTracker) { if (bbCtx) {
span?.addTags({ if (!bbCtx.jsExecutionTracker) {
createdExecutionTracker: true,
})
bbCtx.jsExecutionTracker =
timers.ExecutionTimeTracker.withLimit(perRequestLimit)
}
span?.addTags({ span?.addTags({
js: { createdExecutionTracker: true,
limitMS: bbCtx.jsExecutionTracker.limitMs,
elapsedMS: bbCtx.jsExecutionTracker.elapsedMS,
},
}) })
// We call checkLimit() here to prevent paying the cost of creating bbCtx.jsExecutionTracker = tracer.trace(
// a new VM context below when we don't need to. "runJS.createExecutionTimeTracker",
bbCtx.jsExecutionTracker.checkLimit() {},
track = bbCtx.jsExecutionTracker.track.bind( span => timers.ExecutionTimeTracker.withLimit(perRequestLimit)
bbCtx.jsExecutionTracker
) )
} }
}) span?.addTags({
js: {
limitMS: bbCtx.jsExecutionTracker.limitMs,
elapsedMS: bbCtx.jsExecutionTracker.elapsedMS,
},
})
// We call checkLimit() here to prevent paying the cost of creating
// a new VM context below when we don't need to.
tracer.trace("runJS.checkLimitAndBind", {}, span => {
bbCtx.jsExecutionTracker!.checkLimit()
track = bbCtx.jsExecutionTracker!.track.bind(
bbCtx.jsExecutionTracker
)
})
}
} }
ctx = tracer.trace("runJS.ctxClone", {}, span => { ctx = {
return { ...ctx,
...ctx, alert: undefined,
alert: undefined, setInterval: undefined,
setInterval: undefined, setTimeout: undefined,
setTimeout: undefined, }
}
})
tracer.trace("runJS.vm.createContext", {}, span => {
vm.createContext(ctx)
})
vm.createContext(ctx)
return track(() => return track(() =>
tracer.trace("runJS.vm.runInNewContext", {}, span => vm.runInNewContext(js, ctx, {
vm.runInNewContext(js, ctx, { timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS,
timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS, })
})
)
) )
}) })
}) })