Remove helpers.deepFreeze and call Object.freeze only on things that need it for ~11% time reduction measured via profile-fixture.mjs on Apple Silicon M1.

This commit is contained in:
David Anson 2022-06-09 23:56:44 -07:00
parent b6471fba31
commit 936c876810
5 changed files with 110 additions and 97 deletions

View file

@ -1200,6 +1200,39 @@ test("customRulesAsyncThrowsInSyncContext", (t) => {
);
});
test("customRulesParamsAreFrozen", (t) => {
const options = {
"customRules": [
{
"names": [ "name" ],
"description": "description",
"tags": [ "tag" ],
"function":
(params) => {
const pending = [ params ];
let current = null;
while ((current = pending.shift())) {
t.true(Object.isFrozen(current) || (current === params));
for (const name of Object.getOwnPropertyNames(current)) {
const value = current[name];
if (value && (typeof value === "object")) {
pending.push(value);
}
}
}
}
}
],
"files": [
"CONTRIBUTING.md",
"README.md",
"doc/CustomRules.md",
"doc/Rules.md"
]
};
return markdownlint.promises.markdownlint(options).then(() => null);
});
test("customRulesParamsAreStable", (t) => {
t.plan(4);
const config1 = { "value1": 10 };

View file

@ -953,40 +953,6 @@ test("applyFixes", (t) => {
}
});
test("deepFreeze", (t) => {
t.plan(6);
const obj = {
"prop": true,
"func": () => true,
"sub": {
"prop": [ 1 ],
"sub": {
"prop": "one"
}
}
};
t.is(helpers.deepFreeze(obj), obj, "Did not return object.");
for (const scenario of [
() => {
obj.prop = false;
},
() => {
obj.func = () => false;
},
() => {
obj.sub.prop = [];
},
() => {
obj.sub.prop[0] = 0;
},
() => {
obj.sub.sub.prop = "zero";
}
]) {
t.throws(scenario, null, "Assigned to frozen object.");
}
});
test("forEachLink", (t) => {
t.plan(291);
const testCases = [