-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MERGE #5456 @sethbrenith] nicer dynamic casts
Merge pull request #5456 from sethbrenith:user/sethb/is I recently came across the following code: ```C++ // JsParseSerialized only accepts ArrayBuffer (incl. ExternalArrayBuffer) if (!Js::ExternalArrayBuffer::Is(bufferVal)) { return JsErrorInvalidArgument; } ``` I thought the comment was out of date, and was about to update it, when I realized that `ExternalArrayBuffer::Is` actually invokes `ArrayBuffer::Is`, because static methods are inherited and `ExternalArrayBuffer` doesn't provide an `Is` method. I don't want to live in a world where `ExternalArrayBuffer::Is(bufferVal)` can return something other than whether `bufferVal` is an `ExternalArrayBuffer`, so this change is my proposed solution. It introduces a new template method `VarIs` (in RecyclableObject.h) and uses it consistently for all type-checks and conversions of `RecyclableObject` subclasses. Benefits are: * Avoid the confusing case above (it would be a linker error) * Less boilerplate code (this is a net removal of about 1500 lines) * Every type gets by default an optimization for when the compiler knows the input is `RecyclableObject*` (previously only a few types implemented this) Most of the change is purely mechanical, and anybody who's willing to review it is a hero. However, a few cases are interesting: * `DynamicObject`, `JavascriptArray`, and `JavascriptGeneratorFunction` had asymmetrical behavior between `Is` and `(Unsafe)?FromVar`. I have attempted to avoid any behavior changes in this review by updating callers to `Is` to use a new uniquely-named method, and making `VarIs` respect the behavior from `(Unsafe)?FromVar`. * A few calls have been updated to refer to the thing they were actually calling, not some subclass: * `JavascriptObject` -> `DynamicObject` * `ExternalArrayBuffer` -> `ArrayBuffer` * `JavascriptArrayBuffer` -> `ArrayBuffer` * `RuntimeFunction` -> `JavascriptFunction` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/microsoft/chakracore/5456) <!-- Reviewable:end -->
- Loading branch information
Showing
226 changed files
with
3,200 additions
and
4,654 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.