Support throwing null (#10213)

* Support throwing null

In JavaScript, you can throw values of any type, not just errors. That
includes null. We currently rely on null checks to determine if a user-
provided function has thrown. This refactors our error handling code to
keep track of an explicit boolean flag instead.

* Add DOM fixture test case for break on exception behavior

* preventDefault error events during feature test

We call invokeGuardedCallbackDev at startup as part of a feature test.
But we don't want those errors to log to the console.

* Add throwing null test case

* Use ReactFeatureFlags instead of ReactDOMFeatureFlags

React ART uses this, too.

* Non-errors in error logger

If a non-error is thrown, we'll coerce the value to a string and use
that as the message.
This commit is contained in:
Andrew Clark
2017-07-21 15:34:41 -07:00
committed by GitHub
parent 6208fcc585
commit dec5233db3
11 changed files with 390 additions and 141 deletions
+7 -6
View File
@@ -2328,21 +2328,22 @@ src/renderers/shared/stack/reconciler/__tests__/Transaction-test.js
* should allow nesting of transactions
src/renderers/shared/utils/__tests__/ReactErrorUtils-test.js
* it should rethrow errors caught by invokeGuardedCallbackAndCatchFirstError (development)
* it should rethrow caught errors (development)
* should call the callback the passed arguments (development)
* should call the callback with the provided context (development)
* should return a caught error (development)
* should return null if no error is thrown (development)
* should catch errors (development)
* should return false from clearCaughtError if no error was thrown (development)
* can nest with same debug name (development)
* does not return nested errors (development)
* can be shimmed (development)
* it should rethrow errors caught by invokeGuardedCallbackAndCatchFirstError (production)
* it should rethrow caught errors (production)
* should call the callback the passed arguments (production)
* should call the callback with the provided context (production)
* should return a caught error (production)
* should return null if no error is thrown (production)
* should catch errors (production)
* should return false from clearCaughtError if no error was thrown (production)
* can nest with same debug name (production)
* does not return nested errors (production)
* catches null values
* can be shimmed (production)
src/renderers/shared/utils/__tests__/accumulateInto-test.js
+1
View File
@@ -12,6 +12,7 @@ jest.mock('ReactFeatureFlags', () => {
const flags = require.requireActual('ReactFeatureFlags');
return Object.assign({}, flags, {
disableNewFiberFeatures: true,
forceInvokeGuardedCallbackDev: true,
});
});
jest.mock('ReactNativeFeatureFlags', () => {