Ensure functions that have prototype properties assigned by Object.defineProperty get marked as classes#34577
Merged
andrewbranch merged 2 commits intomicrosoft:masterfrom Oct 18, 2019
Conversation
…fineProperty get marked as classes
sandersn
approved these changes
Oct 18, 2019
weswigham
approved these changes
Oct 18, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34481
Various JS constructs indicate to the binder that a function is actually a constructor:
thisinside the body/** @constructor */JSDoc tagA missing one was defining a prototype property via
Object.defineProperty. So if you have the codeThe
Object.definePropertyto the prototype is the sole indicator thatGraphicis a constructor, but it was being missed, so the symbolGraphicwas not marked as a class. However, when the checker tries to get the type ofthis, it rightly assumes thatGraphicmust be a class, and hence the crash.It’s also notable that the provided repro had something like this:
which we don’t recognize as a bindable declaration onto Graphic at all—if we did, this bug would have remained undiscovered. Similarly, if the original code had any assignment to
this, or any property assignment toGraphic.prototype, or used the JSDoc/** @constructor */tag, the crash wouldn‘t have occurred because a different declaration would have markedGraphicas class-like.