Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4872, use context agnostic Function constructor check #4928

Merged
merged 3 commits into from
Feb 14, 2017

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!

@@ -70,7 +70,8 @@ function getPropDefaultValue (vm: ?Component, prop: PropOptions, key: string): a
return vm[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' && (!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