File tree 2 files changed +20
-8
lines changed
2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -878,6 +878,22 @@ describe('api: watch', () => {
878
878
expect ( source ) . toHaveBeenCalledWith ( instance )
879
879
} )
880
880
881
+ test ( 'should not leak `this.proxy` to setup()' , ( ) => {
882
+ const source = jest . fn ( )
883
+
884
+ const Comp = defineComponent ( {
885
+ render ( ) { } ,
886
+ setup ( ) {
887
+ watch ( source , ( ) => { } )
888
+ }
889
+ } )
890
+
891
+ const root = nodeOps . createElement ( 'div' )
892
+ createApp ( Comp ) . mount ( root )
893
+ // should not have any arguments
894
+ expect ( source . mock . calls [ 0 ] ) . toMatchObject ( [ ] )
895
+ } )
896
+
881
897
// #2728
882
898
test ( 'pre watcher callbacks should not track dependencies' , async ( ) => {
883
899
const a = ref ( 0 )
@@ -944,7 +960,7 @@ describe('api: watch', () => {
944
960
await nextTick ( )
945
961
expect ( spy ) . toHaveBeenCalledTimes ( 2 )
946
962
} )
947
-
963
+
948
964
it ( 'watching sources: ref<any[]>' , async ( ) => {
949
965
const foo = ref ( [ 1 ] )
950
966
const spy = jest . fn ( )
Original file line number Diff line number Diff line change @@ -189,9 +189,7 @@ function doWatch(
189
189
} else if ( isReactive ( s ) ) {
190
190
return traverse ( s )
191
191
} else if ( isFunction ( s ) ) {
192
- return callWithErrorHandling ( s , instance , ErrorCodes . WATCH_GETTER , [
193
- instance && ( instance . proxy as any )
194
- ] )
192
+ return callWithErrorHandling ( s , instance , ErrorCodes . WATCH_GETTER )
195
193
} else {
196
194
__DEV__ && warnInvalidSource ( s )
197
195
}
@@ -200,9 +198,7 @@ function doWatch(
200
198
if ( cb ) {
201
199
// getter with cb
202
200
getter = ( ) =>
203
- callWithErrorHandling ( source , instance , ErrorCodes . WATCH_GETTER , [
204
- instance && ( instance . proxy as any )
205
- ] )
201
+ callWithErrorHandling ( source , instance , ErrorCodes . WATCH_GETTER )
206
202
} else {
207
203
// no cb -> simple effect
208
204
getter = ( ) => {
@@ -371,7 +367,7 @@ export function instanceWatch(
371
367
? source . includes ( '.' )
372
368
? createPathGetter ( publicThis , source )
373
369
: ( ) => publicThis [ source ]
374
- : source . bind ( publicThis )
370
+ : source . bind ( publicThis , publicThis )
375
371
let cb
376
372
if ( isFunction ( value ) ) {
377
373
cb = value
You can’t perform that action at this time.
0 commit comments