Skip to content

Conversation

HerringtonDarkholme
Copy link
Member

If the prototype of a function is also a function, we treat it as Function constructor.

This check is context independent, so server side can safely extract vue as an external library. And it is not expensive.

Of course it is not silver bullet. Users can pass a value of which the prototype is set to a function. But naughty users can also rewrite Function global, so I think this change is at most as bad as current check.

Other counter examples are welcome!

// 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' && (!prop.type || typeof prop.type.prototype !== 'function')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we already have the proper check implemented here: https://github.com/vuejs/vue/blob/dev/src/core/util/props.js#L166-L169

So we can just do getType(prop.type) === 'Function'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Didn't notice that!

@yyx990803 yyx990803 merged commit 01151ce into vuejs:dev Feb 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants