File tree Expand file tree Collapse file tree 5 files changed +15
-5
lines changed Expand file tree Collapse file tree 5 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
2020 hasOwn ,
2121 isReserved ,
2222 handleError ,
23+ nativeWatch ,
2324 validateProp ,
2425 isPlainObject ,
2526 isReservedAttribute
@@ -53,7 +54,9 @@ export function initState (vm: Component) {
5354 observe ( vm . _data = { } , true /* asRootData */ )
5455 }
5556 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+ }
5760}
5861
5962function 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
1717export const isIOS = UA && / i p h o n e | i p a d | i p o d | i o s / . test ( UA )
1818export const isChrome = UA && / c h r o m e \/ \d + / . test ( UA ) && ! isEdge
1919
20+ // Firefix has a "watch" function on Object.prototype...
21+ export const nativeWatch = ( { } ) . watch
22+
2023export let supportsPassive = false
2124if ( inBrowser ) {
2225 try {
Original file line number Diff line number Diff line change 22
33import config from '../config'
44import { warn } from './debug'
5+ import { nativeWatch } from './env'
56import { set } from '../observer/index'
67
78import {
@@ -172,6 +173,9 @@ ASSET_TYPES.forEach(function (type) {
172173 * another, so we merge them as arrays.
173174 */
174175strats . 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
175179 /* istanbul ignore if */
176180 if ( ! childVal ) return Object . create ( parentVal || null )
177181 if ( ! parentVal ) return childVal
Original file line number Diff line number Diff line change 11import Vue from 'vue'
22
33export default function testObjectOption ( name ) {
4- it ( 'should warn non object' , ( ) => {
4+ it ( 'should warn non object value ' , ( ) => {
55 const options = { }
66 options [ name ] = ( ) => { }
77 new Vue ( options )
88 expect ( `component option "${ name } " should be an object` ) . toHaveBeenWarned ( )
99 } )
1010
11- it ( 'don\'t warn when is an object' , ( ) => {
11+ it ( 'should not warn valid object value ' , ( ) => {
1212 const options = { }
1313 options [ name ] = { }
1414 new Vue ( options )
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ describe('Options watch', () => {
77 spy = jasmine . createSpy ( 'watch' )
88 } )
99
10+ testObjectOption ( 'watch' )
11+
1012 it ( 'basic usage' , done => {
1113 const vm = new Vue ( {
1214 data : {
@@ -24,8 +26,6 @@ describe('Options watch', () => {
2426 } ) . then ( done )
2527 } )
2628
27- testObjectOption ( 'watch' )
28-
2929 it ( 'string method name' , done => {
3030 const vm = new Vue ( {
3131 data : {
You can’t perform that action at this time.
0 commit comments