Skip to content
Open
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
Switch to a WeakMap to avoid memory leak
  • Loading branch information
developit authored Dec 4, 2019
commit 3c7521cd43d2514931cacd72bd3e3cdce7a8e169
6 changes: 3 additions & 3 deletions src/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let DOMAttributeNames = {
htmlFor: 'for'
};

let sanitized = {};
let sanitized = new WeakMap();

/** Hyperscript reviver that constructs a sanitized HTML string. */
export default function h(name, attrs) {
Expand Down Expand Up @@ -47,14 +47,14 @@ export default function h(name, attrs) {
for (let i=child.length; i--; ) stack.push(child[i]);
}
else {
s += sanitized[child]===true ? child : esc(child);
s += sanitized.has(child) ? child : esc(child);
}
}
}

s += name ? `</${name}>` : '';
}

sanitized[s] = true;
sanitized.set(s, true);
return s;
}