This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for throws in React (#2502)
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: #2502 Reviewed By: trueadm Differential Revision: D9566580 Pulled By: calebmer fbshipit-source-id: 3716a6afd5fc3ae824182ee50e38e51d72126dc2
- Loading branch information
1 parent
e423a07
commit dfa38c2
Showing
19 changed files
with
666 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
/* @flow */ | ||
|
||
const path = require("path"); | ||
const fs = require("fs"); | ||
const setupReactTests = require("./setupReactTests"); | ||
const { runTest } = setupReactTests(); | ||
|
||
const customConfig = new Map(); | ||
|
||
fs.readdirSync(path.resolve(__dirname, "Throw")).forEach(file => { | ||
test(file, () => { | ||
runTest(path.resolve(__dirname, "Throw", file), customConfig.get(file)); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const React = require("react"); | ||
|
||
function MyComponent(props) { | ||
if (props.b) throw new Error("abrupt"); | ||
return 42; | ||
} | ||
|
||
if (global.__optimizeReactComponentTree) global.__optimizeReactComponentTree(MyComponent); | ||
|
||
MyComponent.getTrials = renderer => { | ||
renderer.update(<MyComponent b={false} />); | ||
return [["simple render", renderer.toJSON()]]; | ||
}; | ||
|
||
module.exports = MyComponent; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const React = require("react"); | ||
|
||
function MyComponent() { | ||
throw new Error("abrupt"); | ||
} | ||
|
||
if (global.__optimizeReactComponentTree) global.__optimizeReactComponentTree(MyComponent); | ||
|
||
MyComponent.getTrials = renderer => { | ||
let error = false; | ||
try { | ||
MyComponent({}); | ||
} catch (error) { | ||
error = true; | ||
} | ||
return [["component errors", error]]; | ||
}; | ||
|
||
module.exports = MyComponent; |
Oops, something went wrong.