| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | let hasConfirmedEval = false; |
| 11 | export function checkEvalAvailabilityOnceDev(): void { |
| 12 | if (__DEV__) { |
| 13 | if (!hasConfirmedEval) { |
| 14 | hasConfirmedEval = true; |
| 15 | try { |
| 16 | // eslint-disable-next-line no-eval |
| 17 | (0, eval)('null'); |
| 18 | } catch { |
| 19 | console.error( |
| 20 | 'eval() is not supported in this environment. ' + |
| 21 | 'If this page was served with a `Content-Security-Policy` header, ' + |
| 22 | 'make sure that `unsafe-eval` is included. ' + |
| 23 | 'React requires eval() in development mode for various debugging features ' + |
| 24 | 'like reconstructing callstacks from a different environment.\n' + |
| 25 | 'React will never use eval() in production mode', |
| 26 | ); |
| 27 | } |
| 28 | } |
| 29 | } else { |
| 30 | // These errors should never make it into a build so we don't need to encode them in codes.json |
| 31 | // eslint-disable-next-line react-internal/prod-error-codes |
| 32 | throw new Error( |
| 33 | 'checkEvalAvailabilityOnceDev should never be called in production mode. This is a bug in React.', |
| 34 | ); |
| 35 | } |
| 36 | } |