File tree 1 file changed +21
-10
lines changed
packages/svelte/src/internal/client
1 file changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -16,20 +16,29 @@ import * as w from './warnings.js';
16
16
import { get_stack } from './dev/tracing.js' ;
17
17
import { tracing_mode_flag } from '../flags/index.js' ;
18
18
19
+ /**
20
+ * @param {unknown } value
21
+ * @returns {boolean }
22
+ */
23
+ function should_proxy ( value ) {
24
+ if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
25
+ return false ;
26
+ }
27
+ const prototype = get_prototype_of ( value ) ;
28
+ if ( prototype !== object_prototype && prototype !== array_prototype ) {
29
+ return false ;
30
+ }
31
+ return true ;
32
+ }
33
+
19
34
/**
20
35
* @template T
21
36
* @param {T } value
22
37
* @returns {T }
23
38
*/
24
39
export function proxy ( value ) {
25
40
// if non-proxyable, or is already a proxy, return `value`
26
- if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
27
- return value ;
28
- }
29
-
30
- const prototype = get_prototype_of ( value ) ;
31
-
32
- if ( prototype !== object_prototype && prototype !== array_prototype ) {
41
+ if ( ! should_proxy ( value ) ) {
33
42
return value ;
34
43
}
35
44
@@ -289,10 +298,12 @@ export function proxy(value) {
289
298
* @returns {T | void }
290
299
*/
291
300
export function return_proxy ( value ) {
292
- const res = proxy ( value ) ;
293
- if ( res !== value || ( typeof value === 'object' && value !== null && STATE_SYMBOL in value ) ) {
301
+ if (
302
+ ! should_proxy ( value ) &&
303
+ ! ( typeof value === 'object' && value !== null && STATE_SYMBOL in value )
304
+ ) {
294
305
// if the argument passed was already a proxy, we don't warn
295
- return res ;
306
+ return proxy ( value ) ;
296
307
}
297
308
w . state_return_not_proxyable ( ) ;
298
309
}
You can’t perform that action at this time.
0 commit comments