File tree 5 files changed +15
-5
lines changed
5 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
20
20
hasOwn ,
21
21
isReserved ,
22
22
handleError ,
23
+ nativeWatch ,
23
24
validateProp ,
24
25
isPlainObject ,
25
26
isReservedAttribute
@@ -53,7 +54,9 @@ export function initState (vm: Component) {
53
54
observe ( vm . _data = { } , true /* asRootData */ )
54
55
}
55
56
if ( opts . computed ) initComputed ( vm , opts . computed )
56
- if ( opts . watch ) initWatch ( vm , opts . watch )
57
+ if ( opts . watch && opts . watch !== nativeWatch ) {
58
+ initWatch ( vm , opts . watch )
59
+ }
57
60
}
58
61
59
62
function checkOptionType ( vm : Component , name : string ) {
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ export const isAndroid = UA && UA.indexOf('android') > 0
17
17
export const isIOS = UA && / i p h o n e | i p a d | i p o d | i o s / . test ( UA )
18
18
export const isChrome = UA && / c h r o m e \/ \d + / . test ( UA ) && ! isEdge
19
19
20
+ // Firefix has a "watch" function on Object.prototype...
21
+ export const nativeWatch = ( { } ) . watch
22
+
20
23
export let supportsPassive = false
21
24
if ( inBrowser ) {
22
25
try {
Original file line number Diff line number Diff line change 2
2
3
3
import config from '../config'
4
4
import { warn } from './debug'
5
+ import { nativeWatch } from './env'
5
6
import { set } from '../observer/index'
6
7
7
8
import {
@@ -172,6 +173,9 @@ ASSET_TYPES.forEach(function (type) {
172
173
* another, so we merge them as arrays.
173
174
*/
174
175
strats . watch = function ( parentVal : ?Object , childVal : ?Object ) : ?Object {
176
+ // work around Firefox's Object.prototype.watch...
177
+ if ( parentVal === nativeWatch ) parentVal = undefined
178
+ if ( childVal === nativeWatch ) childVal = undefined
175
179
/* istanbul ignore if */
176
180
if ( ! childVal ) return Object . create ( parentVal || null )
177
181
if ( ! parentVal ) return childVal
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
2
3
3
export default function testObjectOption ( name ) {
4
- it ( 'should warn non object' , ( ) => {
4
+ it ( 'should warn non object value ' , ( ) => {
5
5
const options = { }
6
6
options [ name ] = ( ) => { }
7
7
new Vue ( options )
8
8
expect ( `component option "${ name } " should be an object` ) . toHaveBeenWarned ( )
9
9
} )
10
10
11
- it ( 'don\'t warn when is an object' , ( ) => {
11
+ it ( 'should not warn valid object value ' , ( ) => {
12
12
const options = { }
13
13
options [ name ] = { }
14
14
new Vue ( options )
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ describe('Options watch', () => {
7
7
spy = jasmine . createSpy ( 'watch' )
8
8
} )
9
9
10
+ testObjectOption ( 'watch' )
11
+
10
12
it ( 'basic usage' , done => {
11
13
const vm = new Vue ( {
12
14
data : {
@@ -24,8 +26,6 @@ describe('Options watch', () => {
24
26
} ) . then ( done )
25
27
} )
26
28
27
- testObjectOption ( 'watch' )
28
-
29
29
it ( 'string method name' , done => {
30
30
const vm = new Vue ( {
31
31
data : {
You can’t perform that action at this time.
0 commit comments