mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: use WeakMap and null for DepthCalculator (#9892)
This commit is contained in:
parent
1f76cdda12
commit
323db305f0
@ -172,10 +172,10 @@ class PQueryEngine {
|
||||
}
|
||||
|
||||
class DepthCalculator {
|
||||
#cache = new Map<Node, number[]>();
|
||||
#cache = new WeakMap<Node, number[]>();
|
||||
|
||||
calculate(node: Node, depth: number[] = []): number[] {
|
||||
if (node instanceof Document) {
|
||||
calculate(node: Node | null, depth: number[] = []): number[] {
|
||||
if (node === null) {
|
||||
return depth;
|
||||
}
|
||||
if (node instanceof ShadowRoot) {
|
||||
@ -196,7 +196,7 @@ class DepthCalculator {
|
||||
++index;
|
||||
}
|
||||
|
||||
const value = this.calculate(node.parentNode as Node, [index]);
|
||||
const value = this.calculate(node.parentNode, [index]);
|
||||
this.#cache.set(node, value);
|
||||
return [...value, ...depth];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user