Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Add basic support for throws in React #2502

Closed
wants to merge 4 commits into from

Conversation

calebmer
Copy link
Contributor

Starts adding basic support for throws in React. Concretely there are three things this PR does outside of adding tests:

  1. Allowing throw side-effects.
  2. Removing an invalid invariant. createdObjects changes after calling realm.captureEffects() and this is expected. Later code which joins/incorporates effects will merge in the captured createdObjects.
  3. Don’t catch AbruptCompletions and handle them as errors. Instead let them propagate up to the nearest realm.evaluateForEffects(). (Or similar function.)

I have not run this against the internal web bundle yet. Against the internal React Native bundle we get pretty far without removing throws with these changes.

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than intercept EXCEPTION_THROWN, it would be better to instead not throw it in cases where the case was an explicit error rather than that of a JS error. I'll push some changes to help push this along as I'm interested in getting throws supported in both internal bundles if possible.

@@ -814,8 +813,6 @@ export function getValueFromFunctionCall(
} else {
throw error;
}
} finally {
invariant(createdObjects === realm.createdObjects, "realm.createdObjects was not correctly restored");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this invariant, it's been very useful in finding early evaluation errors. Rather, we should capture the effects of the function call (using evaluateForEffects) and apply them if the createdObjects has been correctly restored. We ran into countless issues in the past that this guarded against, so I don't think we should regress on this if possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, to make this PR easier I'm happy to remove the invariant for now. I can revisit with some changes later this week that I had planned.

@trueadm
Copy link
Contributor

trueadm commented Aug 29, 2018

@calebmer I pushed some changes that I proposed above and also fixed up the React tests. I added an invariant that we run into on the internal React bundle that we'll need to fix in a follow up PR too. If you could review and let me know if you like the changes?

@calebmer
Copy link
Contributor Author

I like your changes @trueadm 👍

Fixed the serializer tests now that __optimize does not log a diagnostic for throws.

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@calebmer calebmer deleted the react-throw branch August 30, 2018 16:37
calebmer added a commit to calebmer/prepack that referenced this pull request Aug 30, 2018
Summary:
Starts adding basic support for throws in React. Concretely there are three things this PR does outside of adding tests:

1. Allowing throw side-effects.
2. Removing an invalid invariant. `createdObjects` changes after calling `realm.captureEffects()` and this is expected. Later code which joins/incorporates effects will merge in the captured `createdObjects`.
3. Don’t catch `AbruptCompletion`s and handle them as errors. Instead let them propagate up to the nearest `realm.evaluateForEffects()`. (Or similar function.)

I have not run this against the internal web bundle yet. Against the internal React Native bundle we get pretty far without removing throws with these changes.
Pull Request resolved: facebookarchive#2502

Reviewed By: trueadm

Differential Revision: D9566580

Pulled By: calebmer

fbshipit-source-id: 3716a6afd5fc3ae824182ee50e38e51d72126dc2
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants