Skip to content

Commit 606666d

Browse files
committed
test: fix Object.prototype.watch related warnings
1 parent 1f9e924 commit 606666d

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

Diff for: src/core/instance/state.js

+4-1
Original file line numberDiff line numberDiff 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

5962
function checkOptionType (vm: Component, name: string) {

Diff for: src/core/util/env.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const isAndroid = UA && UA.indexOf('android') > 0
1717
export const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
1818
export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
1919

20+
// Firefix has a "watch" function on Object.prototype...
21+
export const nativeWatch = ({}).watch
22+
2023
export let supportsPassive = false
2124
if (inBrowser) {
2225
try {

Diff for: src/core/util/options.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import config from '../config'
44
import { warn } from './debug'
5+
import { nativeWatch } from './env'
56
import { set } from '../observer/index'
67

78
import {
@@ -172,6 +173,9 @@ ASSET_TYPES.forEach(function (type) {
172173
* another, so we merge them as arrays.
173174
*/
174175
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
175179
/* istanbul ignore if */
176180
if (!childVal) return Object.create(parentVal || null)
177181
if (!parentVal) return childVal

Diff for: test/helpers/test-object-option.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Vue from 'vue'
22

33
export 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)

Diff for: test/unit/features/options/watch.spec.js

+2-2
Original file line numberDiff line numberDiff 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: {

0 commit comments

Comments
 (0)