This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
Support constructors that return an object but also throw #2501
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.
The following example currently fails with a
FatalError
.This is where the
FatalError
is thrown:https://github.com/facebook/prepack/blob/f59798b19678b52fe11ae77def2dfe551e374c1e/src/methods/function.js#L264-L267
The majority of this PR is refactoring the type of construction functions to return a
Value
(which includesAbstractValue
) instead of a concreteObjectValue
. I updated call sites to include athrowIfNotConcreteObject()
instead of handling abstract values in many cases.Would it be useful to add some general
Value.prototype.map
utility function? Which would provideConcreteValue
s to a mapper function and abstract over conditional values,__bottomValue
, and more.Motivation
Babel return an object from constructors for classes that call
super()
to follow the spec. This means we hit an invariant on all React class components which might throw. Which happens to be quite a few given the prevalent use ofnullthrows()
orinvariant()
in Facebook codebases.