Skip to content

Commit

Permalink
Add test for segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
verhovsky committed Jul 17, 2023
1 parent 30b26fd commit 6611553
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion test/node_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,62 @@ describe("Node", () => {
assert.equal('/', slash.text, '"/" text');
})
)
})
});

describe("VSCode", () => {
it("shouldn't segfault when accessing properties on the prototype", () => {
const tree = parser.parse('2 + 2');
const nodePrototype = Object.getPrototypeOf(tree.rootNode);
// const nodePrototype = tree.rootNode.__proto__;

const properties = [
"type",
"typeId",
"isNamed",
"text",
"startPosition",
"endPosition",
"startIndex",
"endIndex",
"parent",
"children",
"namedChildren",
"childCount",
"namedChildCount",
"firstChild",
"firstNamedChild",
"lastChild",
"lastNamedChild",
"nextSibling",
"nextNamedSibling",
"previousSibling",
"previousNamedSibling",
];
for (const property of properties) {
assert.throws(() => { nodePrototype[property]; }, TypeError)
}

const methods = [
"hasChanges",
"hasError",
"isMissing",
"toString",
"walk",
// these take arguments but the "this" check happens first
"child",
"namedChild",
"firstChildForIndex",
"firstNamedChildForIndex",
"namedDescendantForIndex",
"descendantForIndex",
"descendantsOfType",
"namedDescendantForPosition",
"descendantForPosition",
"closest",
];
for (const method of methods) {
assert.throws(nodePrototype[method], TypeError)
}
});
});
});

0 comments on commit 6611553

Please sign in to comment.