// Diagnostic-only, bounded task queue; real callbacks are executed at checkpoints.
// No callback is discarded or synchronously run in place of an asynchronous task.
globalThis.__xfeTaskQueue = [];
globalThis.__xfeTimerId = 0;
globalThis.queueMicrotask = function(callback) {
if (typeof callback !== 'function') throw new TypeError('queueMicrotask requires a callback');
if (__xfeTaskQueue.length >= 256) throw new RangeError('Probe task budget exceeded');
__xfeTaskQueue.push({kind:'microtask',callback:callback,id:++__xfeTimerId});
};
globalThis.setTimeout = function(callback, delay, ...args) {
if (typeof callback !== 'function') throw new TypeError('Probe does not compile timer strings');
if (__xfeTaskQueue.length >= 256) throw new RangeError('Probe task budget exceeded');
const id = ++__xfeTimerId;
__xfeTaskQueue.push({kind:'timer',callback:()=>callback(...args),id:id,due:Date.now()+Math.max(0,+delay||0)});
return id;
};
globalThis.clearTimeout = function(id) { __xfeTaskQueue = __xfeTaskQueue.filter(t=>t.id!==id); };
globalThis.requestAnimationFrame = function(callback) { return setTimeout(()=>callback(performance.now()),17); };
globalThis.cancelAnimationFrame = clearTimeout;
globalThis.__xfeProbeStart = Date.now();
globalThis.__xfePerformanceEntries = [];
globalThis.performance = {
now:function(){return Date.now()-__xfeProbeStart;},
mark:function(name){const entry={name:String(name),entryType:'mark',startTime:this.now(),duration:0};if(__xfePerformanceEntries.length>=256)throw new RangeError('Probe performance budget exceeded');__xfePerformanceEntries.push(entry);return entry;},
measure:function(name,start,end){const find=n=>{const e=__xfePerformanceEntries.filter(e=>e.entryType==='mark'&&e.name===n).pop();if(!e)throw new Error('Unknown performance mark: '+n);return e.startTime;};const begin=start===undefined?0:find(start),finish=end===undefined?this.now():find(end);const entry={name:String(name),entryType:'measure',startTime:begin,duration:finish-begin};if(__xfePerformanceEntries.length>=256)throw new RangeError('Probe performance budget exceeded');__xfePerformanceEntries.push(entry);return entry;},
getEntriesByType:function(type){return __xfePerformanceEntries.filter(e=>e.entryType===type).slice();},
clearMarks:function(name){__xfePerformanceEntries=__xfePerformanceEntries.filter(e=>e.entryType!=='mark'||name!==undefined&&e.name!==name);},
clearMeasures:function(name){__xfePerformanceEntries=__xfePerformanceEntries.filter(e=>e.entryType!=='measure'||name!==undefined&&e.name!==name);}
};
globalThis.__xfeCheckpoint = function() {
let executed = 0;
for (;;) {
const index = __xfeTaskQueue.findIndex(t=>t.kind==='microtask'||t.due<=Date.now());
if (index<0) return executed;
if (++executed>256) throw new RangeError('Probe checkpoint task budget exceeded');
const task = __xfeTaskQueue.splice(index,1)[0];
task.callback();
}
};
// Diagnostic-only, bounded task queue; real callbacks are executed at checkpoints.
// No callback is discarded or synchronously run in place of an asynchronous task.
globalThis.__xfeTaskQueue = [];
globalThis.__xfeTimerId = 0;
globalThis.queueMicrotask = function(callback) {
if (typeof callback !== 'function') throw new TypeError('queueMicrotask requires a callback');
if (__xfeTaskQueue.length >= 256) throw new RangeError('Probe task budget exceeded');
__xfeTaskQueue.push({kind:'microtask',callback:callback,id:++__xfeTimerId});
};
globalThis.setTimeout = function(callback, delay, ...args) {
if (typeof callback !== 'function') throw new TypeError('Probe does not compile timer strings');
if (__xfeTaskQueue.length >= 256) throw new RangeError('Probe task budget exceeded');
const id = ++__xfeTimerId;
__xfeTaskQueue.push({kind:'timer',callback:()=>callback(...args),id:id,due:Date.now()+Math.max(0,+delay||0)});
return id;
};
globalThis.clearTimeout = function(id) { __xfeTaskQueue = __xfeTaskQueue.filter(t=>t.id!==id); };
globalThis.requestAnimationFrame = function(callback) { return setTimeout(()=>callback(performance.now()),17); };
globalThis.cancelAnimationFrame = clearTimeout;
globalThis.__xfeProbeStart = Date.now();
globalThis.__xfePerformanceEntries = [];
globalThis.performance = {
now:function(){return Date.now()-__xfeProbeStart;},
mark:function(name){const entry={name:String(name),entryType:'mark',startTime:this.now(),duration:0};if(__xfePerformanceEntries.length>=256)throw new RangeError('Probe performance budget exceeded');__xfePerformanceEntries.push(entry);return entry;},
measure:function(name,start,end){const find=n=>{const e=__xfePerformanceEntries.filter(e=>e.entryType==='mark'&&e.name===n).pop();if(!e)throw new Error('Unknown performance mark: '+n);return e.startTime;};const begin=start===undefined?0:find(start),finish=end===undefined?this.now():find(end);const entry={name:String(name),entryType:'measure',startTime:begin,duration:finish-begin};if(__xfePerformanceEntries.length>=256)throw new RangeError('Probe performance budget exceeded');__xfePerformanceEntries.push(entry);return entry;},
getEntriesByType:function(type){return __xfePerformanceEntries.filter(e=>e.entryType===type).slice();},
clearMarks:function(name){__xfePerformanceEntries=__xfePerformanceEntries.filter(e=>e.entryType!=='mark'||name!==undefined&&e.name!==name);},
clearMeasures:function(name){__xfePerformanceEntries=__xfePerformanceEntries.filter(e=>e.entryType!=='measure'||name!==undefined&&e.name!==name);}
};
globalThis.__xfeCheckpoint = function() {
let executed = 0;
for (;;) {
const index = __xfeTaskQueue.findIndex(t=>t.kind==='microtask'||t.due<=Date.now());
if (index<0) return executed;
if (++executed>256) throw new RangeError('Probe checkpoint task budget exceeded');
const task = __xfeTaskQueue.splice(index,1)[0];
task.callback();
}
};