You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 -->
// when resuming a generator and not needed when yielding from a generator, as is occurring
1382
1382
// here.
1383
1383
AssertMsg(args.Info.Count == 2, "Generator ScriptFunctions should only be invoked by generator APIs with the pair of arguments they pass in -- the generator object and a ResumeYieldData pointer");
0 commit comments