@@ -159,22 +159,6 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
159
159
}
160
160
} ,
161
161
162
- has (
163
- {
164
- _ : { data, accessCache, renderContext, type, sink }
165
- } : ComponentPublicProxyTarget ,
166
- key : string
167
- ) {
168
- return (
169
- accessCache ! [ key ] !== undefined ||
170
- ( data !== EMPTY_OBJ && hasOwn ( data , key ) ) ||
171
- hasOwn ( renderContext , key ) ||
172
- ( type . props && hasOwn ( normalizePropsOptions ( type . props ) [ 0 ] , key ) ) ||
173
- hasOwn ( publicPropertiesMap , key ) ||
174
- hasOwn ( sink , key )
175
- )
176
- } ,
177
-
178
162
set (
179
163
{ _ : instance } : ComponentPublicProxyTarget ,
180
164
key : string ,
@@ -207,6 +191,35 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
207
191
}
208
192
}
209
193
return true
194
+ } ,
195
+
196
+ has (
197
+ {
198
+ _ : { data, accessCache, renderContext, type, sink, appContext }
199
+ } : ComponentPublicProxyTarget ,
200
+ key : string
201
+ ) {
202
+ return (
203
+ accessCache ! [ key ] !== undefined ||
204
+ ( data !== EMPTY_OBJ && hasOwn ( data , key ) ) ||
205
+ hasOwn ( renderContext , key ) ||
206
+ ( type . props && hasOwn ( normalizePropsOptions ( type . props ) [ 0 ] , key ) ) ||
207
+ hasOwn ( publicPropertiesMap , key ) ||
208
+ hasOwn ( sink , key ) ||
209
+ hasOwn ( appContext . config . globalProperties , key )
210
+ )
211
+ }
212
+ }
213
+
214
+ if ( __DEV__ && ! __TEST__ ) {
215
+ PublicInstanceProxyHandlers . ownKeys = (
216
+ target : ComponentPublicProxyTarget
217
+ ) => {
218
+ warn (
219
+ `Avoid app logic that relies on enumerating keys on a component instance. ` +
220
+ `The keys will be empty in production mode to avoid performance overhead.`
221
+ )
222
+ return Reflect . ownKeys ( target )
210
223
}
211
224
}
212
225
@@ -232,21 +245,31 @@ export function createDevProxyTarget(instance: ComponentInternalInstance) {
232
245
233
246
// expose internal instance for proxy handlers
234
247
Object . defineProperty ( target , `_` , {
248
+ configurable : true ,
249
+ enumerable : false ,
235
250
get : ( ) => instance
236
251
} )
237
252
238
253
// expose public properties
239
254
Object . keys ( publicPropertiesMap ) . forEach ( key => {
240
255
Object . defineProperty ( target , key , {
241
- get : ( ) => publicPropertiesMap [ key ] ( instance )
256
+ configurable : true ,
257
+ enumerable : false ,
258
+ get : ( ) => publicPropertiesMap [ key ] ( instance ) ,
259
+ // intercepted by the proxy so no need for implementation,
260
+ // but needed to prevent set errors
261
+ set : NOOP
242
262
} )
243
263
} )
244
264
245
265
// expose global properties
246
266
const { globalProperties } = instance . appContext . config
247
267
Object . keys ( globalProperties ) . forEach ( key => {
248
268
Object . defineProperty ( target , key , {
249
- get : ( ) => globalProperties [ key ]
269
+ configurable : true ,
270
+ enumerable : false ,
271
+ get : ( ) => globalProperties [ key ] ,
272
+ set : NOOP
250
273
} )
251
274
} )
252
275
@@ -264,9 +287,8 @@ export function exposePropsOnDevProxyTarget(
264
287
Object . keys ( normalizePropsOptions ( propsOptions ) [ 0 ] ) . forEach ( key => {
265
288
Object . defineProperty ( proxyTarget , key , {
266
289
enumerable : true ,
290
+ configurable : true ,
267
291
get : ( ) => instance . props [ key ] ,
268
- // intercepted by the proxy so no need for implementation,
269
- // but needed to prevent set errors
270
292
set : NOOP
271
293
} )
272
294
} )
@@ -280,9 +302,8 @@ export function exposeRenderContextOnDevProxyTarget(
280
302
Object . keys ( toRaw ( renderContext ) ) . forEach ( key => {
281
303
Object . defineProperty ( proxyTarget , key , {
282
304
enumerable : true ,
305
+ configurable : true ,
283
306
get : ( ) => renderContext [ key ] ,
284
- // intercepted by the proxy so no need for implementation,
285
- // but needed to prevent set errors
286
307
set : NOOP
287
308
} )
288
309
} )
0 commit comments