( fn: Function, construct: boolean, )
| 80 | * which represents our component. |
| 81 | */ |
| 82 | export function describeNativeComponentFrame( |
| 83 | fn: Function, |
| 84 | construct: boolean, |
| 85 | ): string { |
| 86 | // If something asked for a stack inside a fake render, it should get ignored. |
| 87 | if (!fn || reentry) { |
| 88 | return ''; |
| 89 | } |
| 90 | |
| 91 | if (__DEV__) { |
| 92 | const frame = componentFrameCache.get(fn); |
| 93 | if (frame !== undefined) { |
| 94 | return frame; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | reentry = true; |
| 99 | const previousPrepareStackTrace = Error.prepareStackTrace; |
| 100 | Error.prepareStackTrace = DefaultPrepareStackTrace; |
| 101 | let previousDispatcher = null; |
| 102 | |
| 103 | if (__DEV__) { |
| 104 | previousDispatcher = ReactSharedInternals.H; |
| 105 | // Set the dispatcher in DEV because this might be call in the render function |
| 106 | // for warnings. |
| 107 | ReactSharedInternals.H = null; |
| 108 | disableLogs(); |
| 109 | } |
| 110 | try { |
| 111 | /** |
| 112 | * Finding a common stack frame between sample and control errors can be |
| 113 | * tricky given the different types and levels of stack trace truncation from |
| 114 | * different JS VMs. So instead we'll attempt to control what that common |
| 115 | * frame should be through this object method: |
| 116 | * Having both the sample and control errors be in the function under the |
| 117 | * `DescribeNativeComponentFrameRoot` property, + setting the `name` and |
| 118 | * `displayName` properties of the function ensures that a stack |
| 119 | * frame exists that has the method name `DescribeNativeComponentFrameRoot` in |
| 120 | * it for both control and sample stacks. |
| 121 | */ |
| 122 | const RunInRootFrame = { |
| 123 | DetermineComponentFrameRoot(): [?string, ?string] { |
| 124 | let control; |
| 125 | try { |
| 126 | // This should throw. |
| 127 | if (construct) { |
| 128 | // Something should be setting the props in the constructor. |
| 129 | const Fake = function () { |
| 130 | throw Error(); |
| 131 | }; |
| 132 | // $FlowFixMe[prop-missing] |
| 133 | Object.defineProperty(Fake.prototype, 'props', { |
| 134 | set: function () { |
| 135 | // We use a throwing setter instead of frozen or non-writable props |
| 136 | // because that won't throw in a non-strict mode function. |
| 137 | throw Error(); |
| 138 | }, |
| 139 | }); |
no test coverage detected