servo-default-resources 0.3.0

A component of the servo web-engine.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
if ("dbg" in this) {
    throw new Error("Debugger script must not run more than once!");
}

const dbg = new Debugger;
const debuggeesToPipelineIds = new Map;
const debuggeesToWorkerIds = new Map;
const sourceIdsToScripts = new Map;
const frameActorsToFrames = new Map;
const environmentActorsToEnvironments = new Map;
const environmentsToEnvironmentActors = new Map;
const blackboxing = new Map;
let suspendedFrame = null;
let lastPauseLocation = null;
let debuggerPaused = false;

// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#155>
// Possible values for the `why.type` attribute in "paused" event
const PAUSE_REASONS = {
  INTERRUPTED: "interrupted", // Associated with why.onNext attribute
  RESUME_LIMIT: "resumeLimit",
};

// Find script by scriptId within a script tree
function findScriptById(script, scriptId) {
    if (script.sourceStart === scriptId) {
        return script;
    }
    for (const child of script.getChildScripts()) {
        const found = findScriptById(child, scriptId);
        if (found) return found;
    }
    return null;
}

// Walk script tree and call callback for each script
function walkScriptTree(script, callback) {
    callback(script);
    for (const child of script.getChildScripts()) {
        walkScriptTree(child, callback);
    }
}

// Find a key by a value in a map
function findKeyByValue(map, search) {
    for (const [key, value] of map) {
        if (value === search) return key;
    }
    return undefined;
}

dbg.uncaughtExceptionHook = function(error) {
    console.error(`[debugger] Uncaught exception at ${error.fileName}:${error.lineNumber}:${error.columnNumber}: ${error.name}: ${error.message}`);
};

dbg.onNewScript = function(script) {
    // TODO: handle wasm (`script.source.introductionType == wasm`)
    sourceIdsToScripts.set(script.source.id, script);
    notifyNewSource({
        pipelineId: debuggeesToPipelineIds.get(script.global),
        workerId: debuggeesToWorkerIds.get(script.global),
        spidermonkeyId: script.source.id,
        url: script.source.url,
        urlOverride: script.source.displayURL,
        text: script.source.text,
        introductionType: script.source.introductionType ?? null,
    });
};

// Track a new debuggee global
addEventListener("addDebuggee", event => {
    const {global, pipelineId, workerId} = event;
    const debuggerObject = dbg.addDebuggee(global);
    debuggeesToPipelineIds.set(debuggerObject, pipelineId);
    if (workerId !== undefined) {
        debuggeesToWorkerIds.set(debuggerObject, workerId);
    }
});


// Convert debuggee value to property descriptor value
// <https://searchfox.org/firefox-main/source/devtools/server/actors/object/utils.js#116>
function createValueGrip(value, depth = 0) {
    switch (typeof value) {
        case "undefined":
            return { valueType: "undefined" };
        case "boolean":
            return { valueType: "boolean", booleanValue: value };
        case "number":
            if (value === Infinity) {
                return { valueType: "Infinity" };
            } else if (value === -Infinity) {
                return { valueType: "-Infinity" };
            } else if (Number.isNaN(value)) {
                return { valueType: "NaN" };
            } else if (Object.is(value, -0)) {
                return { valueType: "-0" };
            }
            return { valueType: "number", numberValue: value };
        case "string":
            return { valueType: "string", stringValue: value };
        case "object":
            // <https://searchfox.org/firefox-main/source/devtools/server/actors/object/utils.js#153>
            if (value === null) {
                return { valueType: "null" };
            }
            if (value.optimizedOut || value.uninitialized || value.missingArguments) {
                return { valueType: "null" };
            }
            // TODO: handle typed arrays and storage independently
            const ownPropertyLength = value.getOwnPropertyNamesLength();
            // Debugger.Object - get preview using registered previewers
            // <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html>
            return {
                valueType: "object",
                objectClass: value.class,
                ownPropertyLength: Number.isFinite(ownPropertyLength) ? ownPropertyLength : undefined,
                preview: getPreview(value, depth),
            };
        default:
            return { valueType: "string", stringValue: String(value) };
    }
}

// Extract own properties from a debuggee object
// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html#function-properties-of-the-debugger-object-prototype>
function extractOwnProperties(obj, depth) {
    const ownProperties = [];
    let totalLength = 0;

    let names;
    try {
        names = obj.getOwnPropertyNames();
        totalLength = names.length;
    } catch (e) {
        return { ownProperties, ownPropertiesLength: 0 };
    }

    for (const name of names) {
        try {
            const desc = obj.getOwnPropertyDescriptor(name);
            if (desc) {
                const prop = {
                    name: name,
                    configurable: desc.configurable ?? false,
                    enumerable: desc.enumerable ?? false,
                    writable: desc.writable ?? false,
                    isAccessor: desc.get !== undefined || desc.set !== undefined,
                    value: createValueGrip(undefined, depth + 1),
                };

                if (desc.value !== undefined) {
                    prop.value = createValueGrip(desc.value, depth + 1);
                } else if (desc.get) {
                    try {
                        const result = desc.get.call(obj);
                        if (result && "return" in result) {
                            prop.value = createValueGrip(result.return, depth + 1);
                        }
                    } catch (e) { }
                }

                ownProperties.push(prop);
            }
        } catch (e) {
            // For now skip properties that throw on access
        }
    }

    return { ownProperties, ownPropertiesLength: totalLength };
}

// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#80>
const previewers = {};

// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#125>
previewers.Function = [ function FunctionPreviewer(obj, depth) {
    let function_details = {
        name: obj.name,
        displayName: obj.displayName,
        parameterNames: obj.parameterNames ? obj.parameterNames: [],
        isAsync: obj.isAsyncFunction,
        isGenerator: obj.isGeneratorFunction,
    }

    let preview = { kind: "Object", function: function_details };
    if (depth > 1) {
        return undefined;
    }

    const { ownProperties, ownPropertiesLength } = extractOwnProperties(obj, depth);
    preview.ownProperties = ownProperties;
    preview.ownPropertiesLength = ownPropertiesLength;

    return preview;
} ];

// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#172>
previewers.Array = [ function ArrayPreviewer(obj, depth) {
    const lengthDescriptor = obj.getOwnPropertyDescriptor("length");
    const arrayLength = lengthDescriptor ? lengthDescriptor.value : 0;

    let preview = { kind: "ArrayLike", arrayLength };
    if (depth > 1) {
        return undefined;
    }

    let items = (preview.items = []);
    for (let i = 0; i < arrayLength; i++) {
        try {
            const desc = obj.getOwnPropertyDescriptor(i);
            if (desc && desc.value !== undefined) {
                const grip = createValueGrip(desc.value, depth + 1);
                delete grip.preview;
                items.push(grip);
            }
        } catch (e) {
            // For now skip properties that throw on access
        }
    }

    return preview;
} ];

// Generic fallback for object previewer
// <https://searchfox.org/mozilla-central/source/devtools/server/actors/object/previewers.js#856>
previewers.Object = [ function ObjectPreviewer(obj, depth) {
    let preview = { kind: "Object" };
    if (depth > 1) {
       return undefined;
    }

    const { ownProperties, ownPropertiesLength } = extractOwnProperties(obj, depth);
    preview.ownProperties = ownProperties;
    preview.ownPropertiesLength = ownPropertiesLength;

    return preview;
} ];

function getPreview(obj, depth) {
    const className = obj.class;

    // <https://searchfox.org/mozilla-central/source/devtools/server/actors/object.js#295>
    const typePreviewers = previewers[className] || previewers.Object;
    for (const previewer of typePreviewers) {
        const result = previewer(obj, depth);
        if (result) return result;
    }

    return undefined;
}

// Evaluate some javascript code in the global context of the debuggee
// See executeInGlobal() at <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.object/index.html#function-properties-of-the-debugger-object-prototype>
addEventListener("eval", event => {
    const {code, pipelineId, workerId, frameActorId} = event;

    let completionValue;
    if (frameActorId) {
        const frame = frameActorsToFrames.get(frameActorId);
        // <https://searchfox.org/firefox-main/source/js/src/doc/Debugger/Debugger.Frame.md#223>
        if (frame?.onStack) {
            completionValue = frame.eval(code);
        } else {
            completionValue = { throw: "Frame not available" };
        }
    } else {
        const object = workerId !== undefined ?
            findKeyByValue(debuggeesToWorkerIds, workerId) :
            findKeyByValue(debuggeesToPipelineIds, pipelineId);
        completionValue = object.executeInGlobal(code);
    }

    // Completion values: <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#completion-values>
    let resultValue;
    if (completionValue === null) {
        resultValue = { completionType: "terminated", value: createValueGrip(undefined), hasException: false };
    } else if ("throw" in completionValue) {
        // See adoptDebuggeeValue() in <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger/index.html>
        // <https://searchfox.org/firefox-main/source/devtools/server/actors/webconsole/eval-with-debugger.js#312>
        // we probably don't need adoptDebuggeeValue, as we only have one debugger instance for now
        // let value = dbg.adoptDebuggeeValue(completionValue.throw);
        resultValue = { completionType: "throw", value: createValueGrip(completionValue.throw), hasException: true };
    } else if ("return" in completionValue) {
        resultValue = { completionType: "return", value: createValueGrip(completionValue.return), hasException: false };
    }

    // To avoid recursion errors in the WebIDL, preview needs to live outside of the property descriptor
    if (resultValue.value.preview) {
        resultValue.preview = resultValue.value.preview;
        delete resultValue.value.preview;
    }

    evalResult(event, resultValue);
});

addEventListener("getPossibleBreakpoints", event => {
    const {spidermonkeyId} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const result = [];
    walkScriptTree(script, (currentScript) => {
        for (const location of currentScript.getPossibleBreakpoints()) {
            location["scriptId"] = currentScript.sourceStart;
            result.push(location);
        }
    });
    getPossibleBreakpointsResult(event, result);
});

function createFrameActor(frame, pipelineId) {
    let frameActorId = findKeyByValue(frameActorsToFrames, frame);
    if (!frameActorId) {
        // TODO: Check if we already have an actor for this frame
        frameActorId = registerFrameActor(pipelineId, {
            // TODO: Some properties throw if terminated is true
            // TODO: arguments: frame.arguments,
            displayName: frame.script.displayName,
            onStack: frame.onStack,
            oldest: frame.older == null,
            terminated: frame.terminated,
            type_: frame.type,
            url: frame.script.url,
        });

        if (!frameActorId) {
            console.error("[debugger] Couldn't create frame");
            return undefined;
        }
        frameActorsToFrames.set(frameActorId, frame);
    }

    return frameActorId;
}

function handlePauseAndRespond(frame, pauseReason) {
    // https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1706
    // We don't handle nested pauses correctly.  Don't try - if we're
    // paused, just continue running whatever code triggered the pause.
    if (debuggerPaused) {
        return undefined;
    }

    dbg.onEnterFrame = undefined;
    clearSteppingHooks(frame);

    // Get the pipeline ID for this debuggee
    const pipelineId = debuggeesToPipelineIds.get(frame.script.global);
    if (!pipelineId) {
        console.error("[debugger] No pipeline ID for frame's global");
        return undefined;
    }

    let frameActorId = createFrameActor(frame, pipelineId);

    // <https://github.com/mozilla-firefox/firefox/blob/63719d122f9214f37fd1d285a91897b8345b88b0/js/src/doc/Debugger/Debugger.Script.md?plain=1#L293-L303>
    const offset = frame.offset;
    const offsetMetadata = frame.script.getOffsetMetadata(offset);
    const frameOffset = {
        frameActorId,
        column: offsetMetadata.columnNumber - 1,
        line: offsetMetadata.lineNumber
    };
    lastPauseLocation = { line: offsetMetadata.lineNumber, column: offsetMetadata.columnNumber };

    const source = frame.script.source;
    if (source != null && isBlackBoxed(source.id, frameOffset.line, frameOffset.column)) {
        return undefined;
    }

    // Notify devtools and enter pause loop. This blocks until Resume.
    debuggerPaused = true;
    try {
        pauseAndRespond(
            pipelineId,
            frameOffset,
            pauseReason
        );
    } finally {
        debuggerPaused = false;
    }

    // <https://web.archive.org/web/20251212212538/https://firefox-source-docs.mozilla.org/js/Debugger/Conventions.html#resumption-values>
    // Return undefined to continue execution normally after resume.
    return undefined;
}

addEventListener("frames", event => {
    const {pipelineId, start, count} = event;
    let frameList = handleListFrames(pipelineId, start, count);

    listFramesResult(frameList);
})

// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1425>
function handleListFrames(pipelineId, start, count) {
    let frame = dbg.getNewestFrame()

    const walkToParentFrame = () => {
        if (!frame) {
            return;
        }

        const currentFrame = frame;
        frame = null;

        if (currentFrame.older) {
            frame = currentFrame.older;
        }
    }

    let i = 0;
    while (frame && i < start) {
      walkToParentFrame();
      i++;
    }

    // Return count frames, or all remaining frames if count is not defined.
    const frames = [];
    for (; frame && (!count || i < start + count); i++, walkToParentFrame()) {
      const frameActorId = createFrameActor(frame, pipelineId);
      frames.push(frameActorId);
    }

    return frames;
}

addEventListener("setBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const target = findScriptById(script, scriptId);
    if (target) {
        target.setBreakpoint(offset, {
            // setBreakpoint(offset, handler) in <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.script/index.html#function-properties-of-the-debugger-script-prototype-object>
            // The hit handler receives a Debugger.Frame instance representing the currently executing stack frame.
            hit: (frame) => handlePauseAndRespond(frame, {type_: "breakpoint"})
        });
    }
});

// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.frame/index.html>
addEventListener("interrupt", event => {
    dbg.onEnterFrame = (frame) => handlePauseAndRespond(
        frame,
        { type_: PAUSE_REASONS.INTERRUPTED, onNext: true }
    );
});

// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1088>
function hasMoved(frame) {
    if (!lastPauseLocation) {
        return true;
    }
    const meta = frame.script.getOffsetMetadata(frame.offset);
    return meta.lineNumber !== lastPauseLocation.line ||
           meta.columnNumber !== lastPauseLocation.column;
}

function makeSteppingHooks(steppingType, startFrame) {
    return {
        onEnterFrame: function (frame) {
            const { onStep, onPop } = makeSteppingHooks("next", frame);
            frame.onStep = onStep;
            frame.onPop = onPop;
        },
        onStep: function () {
            const meta = this.script.getOffsetMetadata(this.offset);
            if (!meta.isBreakpoint || !hasMoved(this)) {
                return undefined;
            }
            if (this !== startFrame || meta.isStepStart) {
                return handlePauseAndRespond(this, { type_: PAUSE_REASONS.RESUME_LIMIT });
            }
        },
        onPop: function (completion) {
            this.reportedPop = true;
            suspendedFrame = this;
            attachSteppingHooks(steppingType, this);
            return undefined;
        },
    }
}

function getNextStepFrame(frame) {
    const endOfFrame = frame.reportedPop;
    const stepFrame = endOfFrame ? frame.older : frame;
    if (!stepFrame || !stepFrame.script) {
      return null;
    }
    return stepFrame;
}

// <https://searchfox.org/firefox-main/source/devtools/server/actors/thread.js#1235>
function attachSteppingHooks(steppingType, frame) {
    if (steppingType === "finish" && frame.reportedPop) {
        steppingType = "next";
    }

    const stepFrame = getNextStepFrame(frame);
    if (!stepFrame) {
        steppingType = "step";
    }

    const { onEnterFrame, onStep, onPop } = makeSteppingHooks(
        steppingType,
        frame,
    );

    if (steppingType === "step") {
        dbg.onEnterFrame = onEnterFrame;
    }

    if (stepFrame) {
        switch (steppingType) {
            case "step":
            case "next":
                if (stepFrame.script) {
                    stepFrame.onStep = onStep;
                }
            case "finish":
                stepFrame.onPop = onPop;
                break;
        }
    }
}

function clearSteppingHooks(suspendedFrame) {
    if (suspendedFrame) {
        suspendedFrame.onStep = undefined;
        suspendedFrame.onPop = undefined;
    }
    let frame = dbg.getNewestFrame();
    if (frame?.onStack) {
        while (frame) {
            frame.onStep = undefined;
            frame.onPop = undefined;
            frame = frame.older;
        }
    }
}

// <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#resuming-a-thread>
addEventListener("resume", event => {
    const {resumeLimitType: steppingType, frameActorID} = event;
    let frame = dbg.getNewestFrame();
    if (frameActorID) {
        frame = frameActorsToFrames.get(frameActorID);
        if (!frame) {
            console.error("[debugger] Couldn't find frame");
        }
    }
    if (steppingType) {
        // This is a temporary fix until we support async contexts.
        if (steppingType === "finish") {
            lastPauseLocation = null;
        }
        attachSteppingHooks(steppingType, frame);
    } else {
        clearSteppingHooks(frame);
    }
});

// <https://firefox-source-docs.mozilla.org/devtools-user/debugger-api/debugger.script/index.html#function-properties-of-the-debugger-script-prototype-object>
// There may be more than one breakpoint at the same offset with different handlers, but we don’t handle that case for now.
addEventListener("clearBreakpoint", event => {
    const {spidermonkeyId, scriptId, offset} = event;
    const script = sourceIdsToScripts.get(spidermonkeyId);
    const target = findScriptById(script, scriptId);
    if (target) {
        // If the instance refers to a JSScript, remove all breakpoints set in this script at that offset.
        target.clearAllBreakpoints(offset);
    }
});

// TODO: Get variables (scopes don't show if they don't have a variable)
function createEnvironmentActor(environment) {
    let info = {};
    if (environment.type == "declarative") {
        info.type_ = environment.calleeScript ? "function" : "block";
    } else {
        info.type_ = environment.type;
    }

    info.scopeKind = environment.scopeKind;

    if (environment.calleeScript) {
        info.functionDisplayName = environment.calleeScript.displayName;
    }

    let parent = null;
    if (environment.parent) {
        parent = createEnvironmentActor(environment.parent);
    }

    if (environment.type == "declarative") {
        info.bindingVariables = buildBindings(environment);
    }

    let actor = environmentsToEnvironmentActors.get(environment);
    actor = registerEnvironmentActor(info, parent, actor);
    environmentsToEnvironmentActors.set(environment, actor);
    return actor;
}

function buildBindings(environment) {
    let bindingVars = [];
    for (const name of environment.names()) {
        const value = environment.getVariable(name);
        const property = {
            name: name,
            configurable: false,
            enumerable: true,
            writable: !(
                value &&
                (value.optimizedOut || value.uninitialized || value.missingArguments)
            ),
            isAccessor: false,
            value: createValueGrip(value),
        };

        // To avoid recursion errors in the WebIDL, preview needs to live outside of the property descriptor
        let preview = undefined;
        if (property.value.preview) {
            preview = property.value.preview;
            delete property.value.preview;
        }

        bindingVars.push({ property, preview });
    }
    return bindingVars;
}

// Get a `Debugger.Environment` instance within which evaluation is taking place.
// <https://searchfox.org/firefox-main/source/devtools/server/actors/frame.js#109>
addEventListener("getEnvironment", event => {
    const {frameActorId} = event;
    frame = frameActorsToFrames.get(frameActorId);

    const actor = createEnvironmentActor(frame.environment);
    getEnvironmentResult(actor);
});

addEventListener("blackbox", event => {
    if (event.coversFullSource) {
        // Blackbox the entire source
        blackboxing.set(event.spidermonkeyId, []);
    } else {
        // Blackbox only a part of the source
        let blackbox = blackboxing.get(event.spidermonkeyId);
        if (blackbox == undefined) {
            blackbox = [];
        }

        blackbox.push({
            start: event.start(),
            end: event.end()
        });

        blackboxing.set(event.spidermonkeyId, blackbox);
    }
});

addEventListener("unblackbox", event => {
    if (event.coversFullSource) {
        // Unblackbox the entire source
        blackboxing.delete(event.spidermonkeyId);
    } else {
        // Unblackbox an earlier range of the source
        const array = blackboxing.get(event.spidermonkeyId);

        const start = event.start();
        const end = event.end();
        const index = array.findIndex(range => range.start.line === start.line
                && range.start.column === start.column
                && range.end.line === end.line
                && range.end.column === end.column
        );
        if (index !== -1) {
            array.splice(index, 1);

            // Empty arrays represent a fully blackboxed file
            // Therefore, if we just made the array empty we will need to remove it from the map
            if (array.length === 0) {
                blackboxing.delete(event.spidermonkeyId);
            }
        }
    }
});

function isBlackBoxed(spidermonkeyId, line, column) {
    const sourceBlackboxing = blackboxing.get(spidermonkeyId);

    if (sourceBlackboxing == undefined) {
        return false;
    } else if (sourceBlackboxing.length === 0) {
        // An empty array represents a fully ignored source
        return true;
    }

    for (const range of sourceBlackboxing) {
        return (range.start.line < line || (range.start.line === line && range.start.column <= column))
                && (range.end.line > line || (range.end.line === line && range.end.column >= column))
    }

    return false;
}