Skip to content

Commit f068340

Browse files
authored
Revert "fix: ensure deep mutation ownership widening (#11094)"
This reverts commit 8578857.
1 parent be84242 commit f068340

File tree

5 files changed

+13
-148
lines changed

5 files changed

+13
-148
lines changed

.changeset/mighty-frogs-obey.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/svelte/src/internal/client/dev/ownership.js

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { STATE_SYMBOL } from '../constants.js';
44
import { untrack } from '../runtime.js';
5-
import { get_descriptors } from '../utils.js';
65

76
/** @type {Record<string, Array<{ start: Location, end: Location, component: Function }>>} */
87
const boundaries = {};
@@ -92,107 +91,49 @@ export function mark_module_end() {
9291
}
9392
}
9493

95-
let add_owner_visited = new Set();
96-
9794
/**
9895
*
9996
* @param {any} object
10097
* @param {any} owner
10198
*/
10299
export function add_owner(object, owner) {
103-
// Needed because ownership addition can invoke getters on a proxy,
104-
// calling add_owner anew, so just keeping the set as part of
105-
// add_owner_to_object would not be enough.
106-
const prev = add_owner_visited;
107-
try {
108-
add_owner_visited = new Set(add_owner_visited);
109-
untrack(() => {
110-
add_owner_to_object(object, owner, add_owner_visited);
111-
});
112-
} finally {
113-
add_owner_visited = prev;
114-
}
100+
untrack(() => {
101+
add_owner_to_object(object, owner);
102+
});
115103
}
116104

117105
/**
118106
* @param {any} object
119107
* @param {Function} owner
120-
* @param {Set<any>} visited
121108
*/
122-
function add_owner_to_object(object, owner, visited) {
123-
if (visited.has(object)) return;
124-
visited.add(object);
125-
109+
function add_owner_to_object(object, owner) {
126110
if (object?.[STATE_SYMBOL]?.o && !object[STATE_SYMBOL].o.has(owner)) {
127111
object[STATE_SYMBOL].o.add(owner);
112+
113+
for (const key in object) {
114+
add_owner_to_object(object[key], owner);
115+
}
128116
}
129-
// Not inside previous if-block; there could be normal objects in-between
130-
traverse_for_owners(object, (nested) => add_owner_to_object(nested, owner, visited));
131117
}
132118

133-
let strip_owner_visited = new Set();
134-
135119
/**
136120
* @param {any} object
137121
*/
138122
export function strip_owner(object) {
139-
// Needed because ownership stripping can invoke getters on a proxy,
140-
// calling strip_owner anew, so just keeping the set as part of
141-
// strip_owner_from_object would not be enough.
142-
const prev = strip_owner_visited;
143-
try {
144-
untrack(() => {
145-
strip_owner_from_object(object, strip_owner_visited);
146-
});
147-
} finally {
148-
strip_owner_visited = prev;
149-
}
123+
untrack(() => {
124+
strip_owner_from_object(object);
125+
});
150126
}
151127

152128
/**
153129
* @param {any} object
154-
* @param {Set<any>} visited
155130
*/
156-
function strip_owner_from_object(object, visited) {
157-
if (visited.has(object)) return;
158-
visited.add(object);
159-
131+
function strip_owner_from_object(object) {
160132
if (object?.[STATE_SYMBOL]?.o) {
161133
object[STATE_SYMBOL].o = null;
162-
}
163-
// Not inside previous if-block; there could be normal objects in-between
164-
traverse_for_owners(object, (nested) => strip_owner_from_object(nested, visited));
165-
}
166134

167-
/**
168-
* @param {any} object
169-
* @param {(obj: any) => void} cb
170-
*/
171-
function traverse_for_owners(object, cb) {
172-
if (typeof object === 'object' && object !== null && !(object instanceof EventTarget)) {
173135
for (const key in object) {
174-
cb(object[key]);
175-
}
176-
// deal with state on classes
177-
const proto = Object.getPrototypeOf(object);
178-
if (
179-
proto !== Object.prototype &&
180-
proto !== Array.prototype &&
181-
proto !== Map.prototype &&
182-
proto !== Set.prototype &&
183-
proto !== Date.prototype
184-
) {
185-
const descriptors = get_descriptors(proto);
186-
for (let key in descriptors) {
187-
const get = descriptors[key].get;
188-
if (get) {
189-
try {
190-
cb(object[key]);
191-
} catch (e) {
192-
// continue
193-
}
194-
}
195-
}
136+
strip_owner(object[key]);
196137
}
197138
}
198139
}

packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-6/_config.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-6/main.svelte

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-6/sub.svelte

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)