Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/__tests__/block-drag-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,23 @@ describe("BlockDragController", () => {

debugSpy.mockRestore();
});
it("guards against a connection pointing at a not-yet-populated slot in blockList", () => {
// blockList is pre-sized for the whole incoming batch (as blocks.js's
// chunked loader does via `_loadCounter = blockObjs.length`), but a
// later chunk hasn't been written into it yet, so index 1 is a genuine
// array hole (undefined) rather than an explicit null placeholder.
// Regression test for the "Cannot read properties of undefined
// (reading 'connections')" crash on rapid next-project + play.
const blockList = [];
blockList[0] = { connections: [null, 1] };
blockList.length = 3;
const blocks = makeBlocks(blockList);
const debugSpy = jest.spyOn(console, "debug").mockImplementation(() => {});

expect(() => blocks.findDragGroup(0)).not.toThrow();

debugSpy.mockRestore();
});

it("_calculateDragGroup stops recursing once the loop counter exceeds the block list length", () => {
const blockList = [
Expand Down
9 changes: 6 additions & 3 deletions js/block-drag-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ class BlockDragController {
}

const myBlock = blocks.blockList[blk];
/** If this happens, something is really broken. */
if (myBlock === null) {
console.debug("null block encountered... this is bad. " + blk);
/** If this happens, something is really broken.
* Covers both an explicit null entry and an undefined one (e.g. an
* index that points past the currently-loaded portion of
* blockList, or a block removed from the array). */
if (!myBlock) {
console.debug("null/missing block encountered... this is bad. " + blk);
return;
}

Expand Down
Loading