@@ -40,6 +40,18 @@ window.qBittorrent.Cache = (() => {
40
40
} ;
41
41
} ;
42
42
43
+ const deepFreeze = ( obj ) => {
44
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#examples
45
+
46
+ const keys = Reflect . ownKeys ( obj ) ;
47
+ for ( const key of keys ) {
48
+ const value = obj [ key ] ;
49
+ if ( ( value && ( typeof value === 'object' ) ) || ( typeof value === 'function' ) )
50
+ deepFreeze ( value ) ;
51
+ }
52
+ Object . freeze ( obj ) ;
53
+ } ;
54
+
43
55
class BuildInfoCache {
44
56
#m_store = { } ;
45
57
@@ -51,13 +63,15 @@ window.qBittorrent.Cache = (() => {
51
63
onSuccess : ( responseJSON ) => {
52
64
if ( ! responseJSON )
53
65
return ;
66
+
67
+ deepFreeze ( responseJSON ) ;
54
68
this . #m_store = responseJSON ;
55
69
}
56
70
} ) . send ( ) ;
57
71
}
58
72
59
73
get ( ) {
60
- return structuredClone ( this . #m_store) ;
74
+ return this . #m_store;
61
75
}
62
76
}
63
77
@@ -80,7 +94,9 @@ window.qBittorrent.Cache = (() => {
80
94
onSuccess : ( responseJSON , responseText ) => {
81
95
if ( ! responseJSON )
82
96
return ;
83
- this . #m_store = structuredClone ( responseJSON ) ;
97
+
98
+ deepFreeze ( responseJSON ) ;
99
+ this . #m_store = responseJSON ;
84
100
85
101
if ( typeof obj . onSuccess === 'function' )
86
102
obj . onSuccess ( responseJSON , responseText ) ;
@@ -89,7 +105,7 @@ window.qBittorrent.Cache = (() => {
89
105
}
90
106
91
107
get ( ) {
92
- return structuredClone ( this . #m_store) ;
108
+ return this . #m_store;
93
109
}
94
110
95
111
// obj: {
@@ -114,13 +130,15 @@ window.qBittorrent.Cache = (() => {
114
130
obj . onFailure ( xhr ) ;
115
131
} ,
116
132
onSuccess : ( responseText , responseXML ) => {
133
+ this . #m_store = structuredClone ( this . #m_store) ;
117
134
for ( const key in obj . data ) {
118
135
if ( ! Object . hasOwn ( obj . data , key ) )
119
136
continue ;
120
137
121
138
const value = obj . data [ key ] ;
122
139
this . #m_store[ key ] = value ;
123
140
}
141
+ deepFreeze ( this . #m_store) ;
124
142
125
143
if ( typeof obj . onSuccess === 'function' )
126
144
obj . onSuccess ( responseText , responseXML ) ;
0 commit comments