fix: cleanup array prototype monkeypatching (#11634)

* fix: cleanup array prototype monkeypatching

* Update packages/svelte/src/internal/client/dev/equality.js

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/11617/head
Dominic Gannaway 2 months ago committed by GitHub
parent e5e7ec2404
commit 4f8bba2f80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,6 +3,14 @@ import { get_proxied_value } from '../proxy.js';
export function init_array_prototype_warnings() {
const array_prototype = Array.prototype;
// The REPL ends up here over and over, and this prevents it from adding more and more patches
// of the same kind to the prototype, which would slow down everything over time.
// @ts-expect-error
const cleanup = Array.__svelte_cleanup;
if (cleanup) {
cleanup();
}
const { indexOf, lastIndexOf, includes } = array_prototype;
array_prototype.indexOf = function (item, from_index) {
@ -55,6 +63,13 @@ export function init_array_prototype_warnings() {
return has;
};
// @ts-expect-error
Array.__svelte_cleanup = () => {
array_prototype.indexOf = indexOf;
array_prototype.lastIndexOf = lastIndexOf;
array_prototype.includes = includes;
};
}
/**

Loading…
Cancel
Save