| 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 | }); |
| 140 | if (typeof Reflect === 'object' && Reflect.construct) { |
| 141 | // We construct a different control for this case to include any extra |
| 142 | // frames added by the construct call. |
| 143 | try { |
| 144 | Reflect.construct(Fake, []); |
| 145 | } catch (x) { |
| 146 | control = x; |
| 147 | } |
| 148 | Reflect.construct(fn, [], Fake); |
| 149 | } else { |
| 150 | try { |
| 151 | Fake.call(); |
| 152 | } catch (x) { |
| 153 | control = x; |
| 154 | } |
| 155 | // $FlowFixMe[prop-missing] found when upgrading Flow |
| 156 | fn.call(Fake.prototype); |
| 157 | } |
| 158 | } else { |
| 159 | try { |
| 160 | throw Error(); |
| 161 | } catch (x) { |
| 162 | control = x; |
| 163 | } |
| 164 | // TODO(luna): This will currently only throw if the function component |
| 165 | // tries to access React/ReactDOM/props. We should probably make this throw |
| 166 | // in simple components too |
| 167 | const maybePromise = fn(); |
| 168 | |
| 169 | // If the function component returns a promise, it's likely an async |
| 170 | // component, which we don't yet support. Attach a noop catch handler to |
| 171 | // silence the error. |
| 172 | // TODO: Implement component stacks for async client components? |
| 173 | if (maybePromise && typeof maybePromise.catch === 'function') { |
| 174 | maybePromise.catch(() => {}); |
| 175 | } |
| 176 | } |
| 177 | } catch (sample) { |
| 178 | // This is inlined manually because closure doesn't do it for us. |
| 179 | if (sample && control && typeof sample.stack === 'string') { |
| 180 | return [sample.stack, control.stack]; |