Skip to content

Commit 1d10a65

Browse files
authored
fix: check if DOM prototypes are extensible (#15569)
1 parent 1a5fb8f commit 1d10a65

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

.changeset/dry-ducks-roll.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: check if DOM prototypes are extensible

packages/svelte/src/internal/client/dom/operations.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
33
import { DEV } from 'esm-env';
44
import { init_array_prototype_warnings } from '../dev/equality.js';
5-
import { get_descriptor } from '../../shared/utils.js';
5+
import { get_descriptor, is_extensible } from '../../shared/utils.js';
66

77
// export these for reference in the compiled code, making global name deduplication unnecessary
88
/** @type {Window} */
@@ -34,26 +34,31 @@ export function init_operations() {
3434

3535
var element_prototype = Element.prototype;
3636
var node_prototype = Node.prototype;
37+
var text_prototype = Text.prototype;
3738

3839
// @ts-ignore
3940
first_child_getter = get_descriptor(node_prototype, 'firstChild').get;
4041
// @ts-ignore
4142
next_sibling_getter = get_descriptor(node_prototype, 'nextSibling').get;
4243

43-
// the following assignments improve perf of lookups on DOM nodes
44-
// @ts-expect-error
45-
element_prototype.__click = undefined;
46-
// @ts-expect-error
47-
element_prototype.__className = undefined;
48-
// @ts-expect-error
49-
element_prototype.__attributes = null;
50-
// @ts-expect-error
51-
element_prototype.__style = undefined;
52-
// @ts-expect-error
53-
element_prototype.__e = undefined;
54-
55-
// @ts-expect-error
56-
Text.prototype.__t = undefined;
44+
if (is_extensible(element_prototype)) {
45+
// the following assignments improve perf of lookups on DOM nodes
46+
// @ts-expect-error
47+
element_prototype.__click = undefined;
48+
// @ts-expect-error
49+
element_prototype.__className = undefined;
50+
// @ts-expect-error
51+
element_prototype.__attributes = null;
52+
// @ts-expect-error
53+
element_prototype.__style = undefined;
54+
// @ts-expect-error
55+
element_prototype.__e = undefined;
56+
}
57+
58+
if (is_extensible(text_prototype)) {
59+
// @ts-expect-error
60+
text_prototype.__t = undefined;
61+
}
5762

5863
if (DEV) {
5964
// @ts-expect-error

packages/svelte/src/internal/shared/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export var get_descriptors = Object.getOwnPropertyDescriptors;
1010
export var object_prototype = Object.prototype;
1111
export var array_prototype = Array.prototype;
1212
export var get_prototype_of = Object.getPrototypeOf;
13+
export var is_extensible = Object.isExtensible;
1314

1415
/**
1516
* @param {any} thing

0 commit comments

Comments
 (0)