mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 21:17:55 +08:00
* fix #4872, use context agnostic Function constructor check * use getType to check Function Constructor * fix negation
This commit is contained in:
parent
dfaf1265a2
commit
01151ce3fa
@ -70,7 +70,8 @@ function getPropDefaultValue (vm: ?Component, prop: PropOptions, key: string): a
|
||||
return vm._props[key]
|
||||
}
|
||||
// call factory function for non-Function types
|
||||
return typeof def === 'function' && prop.type !== Function
|
||||
// a value is Function if its prototype is function even across different execution context
|
||||
return typeof def === 'function' && getType(prop.type) !== 'Function'
|
||||
? def.call(vm)
|
||||
: def
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Vue from '../../dist/vue.runtime.common.js'
|
||||
import VM from 'vm'
|
||||
import { createRenderer } from '../../packages/vue-server-renderer'
|
||||
const { renderToString } = createRenderer()
|
||||
|
||||
@ -699,6 +700,23 @@ describe('SSR: renderToString', () => {
|
||||
done()
|
||||
}, context)
|
||||
})
|
||||
|
||||
it('default value Foreign Function', () => {
|
||||
const FunctionConstructor = VM.runInNewContext('Function')
|
||||
const func = () => 123
|
||||
const vm = new Vue({
|
||||
props: {
|
||||
a: {
|
||||
type: FunctionConstructor,
|
||||
default: func
|
||||
}
|
||||
},
|
||||
propsData: {
|
||||
a: undefined
|
||||
}
|
||||
})
|
||||
expect(vm.a).toBe(func)
|
||||
})
|
||||
})
|
||||
|
||||
function renderVmWithOptions (options, cb) {
|
||||
|
@ -98,6 +98,22 @@ describe('Options props', () => {
|
||||
}).then(done)
|
||||
})
|
||||
|
||||
it('default value Function', () => {
|
||||
const func = () => 132
|
||||
const vm = new Vue({
|
||||
props: {
|
||||
a: {
|
||||
type: Function,
|
||||
default: func
|
||||
}
|
||||
},
|
||||
propsData: {
|
||||
a: undefined
|
||||
}
|
||||
})
|
||||
expect(vm.a).toBe(func)
|
||||
})
|
||||
|
||||
it('warn object/array default values', () => {
|
||||
new Vue({
|
||||
props: {
|
||||
|
Loading…
Reference in New Issue
Block a user