Skip to content

Commit 48dd4dd

Browse files
committed
Audit try/finally around console patching (facebook#31286)
Otherwise if something errors they can be left patched. [Review without whitespace](https://github.com/facebook/react/pull/31286/files?w=1) DiffTrain build for [b8ae38f](facebook@b8ae38f)
1 parent 7b4965f commit 48dd4dd

38 files changed

+2770
-2336
lines changed

compiled/facebook-www/JSXDEVRuntime-dev.classic.js

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -201,64 +201,64 @@ __DEV__ &&
201201
previousDispatcher = ReactSharedInternals.H;
202202
ReactSharedInternals.H = null;
203203
disableLogs();
204-
var RunInRootFrame = {
205-
DetermineComponentFrameRoot: function () {
206-
try {
207-
if (construct) {
208-
var Fake = function () {
209-
throw Error();
210-
};
211-
Object.defineProperty(Fake.prototype, "props", {
212-
set: function () {
204+
try {
205+
var RunInRootFrame = {
206+
DetermineComponentFrameRoot: function () {
207+
try {
208+
if (construct) {
209+
var Fake = function () {
213210
throw Error();
211+
};
212+
Object.defineProperty(Fake.prototype, "props", {
213+
set: function () {
214+
throw Error();
215+
}
216+
});
217+
if ("object" === typeof Reflect && Reflect.construct) {
218+
try {
219+
Reflect.construct(Fake, []);
220+
} catch (x) {
221+
var control = x;
222+
}
223+
Reflect.construct(fn, [], Fake);
224+
} else {
225+
try {
226+
Fake.call();
227+
} catch (x$0) {
228+
control = x$0;
229+
}
230+
fn.call(Fake.prototype);
214231
}
215-
});
216-
if ("object" === typeof Reflect && Reflect.construct) {
217-
try {
218-
Reflect.construct(Fake, []);
219-
} catch (x) {
220-
var control = x;
221-
}
222-
Reflect.construct(fn, [], Fake);
223232
} else {
224233
try {
225-
Fake.call();
226-
} catch (x$0) {
227-
control = x$0;
234+
throw Error();
235+
} catch (x$1) {
236+
control = x$1;
228237
}
229-
fn.call(Fake.prototype);
238+
(Fake = fn()) &&
239+
"function" === typeof Fake.catch &&
240+
Fake.catch(function () {});
230241
}
231-
} else {
232-
try {
233-
throw Error();
234-
} catch (x$1) {
235-
control = x$1;
236-
}
237-
(Fake = fn()) &&
238-
"function" === typeof Fake.catch &&
239-
Fake.catch(function () {});
242+
} catch (sample) {
243+
if (sample && control && "string" === typeof sample.stack)
244+
return [sample.stack, control.stack];
240245
}
241-
} catch (sample) {
242-
if (sample && control && "string" === typeof sample.stack)
243-
return [sample.stack, control.stack];
246+
return [null, null];
244247
}
245-
return [null, null];
246-
}
247-
};
248-
RunInRootFrame.DetermineComponentFrameRoot.displayName =
249-
"DetermineComponentFrameRoot";
250-
var namePropDescriptor = Object.getOwnPropertyDescriptor(
251-
RunInRootFrame.DetermineComponentFrameRoot,
252-
"name"
253-
);
254-
namePropDescriptor &&
255-
namePropDescriptor.configurable &&
256-
Object.defineProperty(
248+
};
249+
RunInRootFrame.DetermineComponentFrameRoot.displayName =
250+
"DetermineComponentFrameRoot";
251+
var namePropDescriptor = Object.getOwnPropertyDescriptor(
257252
RunInRootFrame.DetermineComponentFrameRoot,
258-
"name",
259-
{ value: "DetermineComponentFrameRoot" }
253+
"name"
260254
);
261-
try {
255+
namePropDescriptor &&
256+
namePropDescriptor.configurable &&
257+
Object.defineProperty(
258+
RunInRootFrame.DetermineComponentFrameRoot,
259+
"name",
260+
{ value: "DetermineComponentFrameRoot" }
261+
);
262262
var _RunInRootFrame$Deter =
263263
RunInRootFrame.DetermineComponentFrameRoot(),
264264
sampleStack = _RunInRootFrame$Deter[0],
@@ -267,54 +267,58 @@ __DEV__ &&
267267
var sampleLines = sampleStack.split("\n"),
268268
controlLines = controlStack.split("\n");
269269
for (
270-
sampleStack = _RunInRootFrame$Deter = 0;
271-
_RunInRootFrame$Deter < sampleLines.length &&
272-
!sampleLines[_RunInRootFrame$Deter].includes(
270+
_RunInRootFrame$Deter = namePropDescriptor = 0;
271+
namePropDescriptor < sampleLines.length &&
272+
!sampleLines[namePropDescriptor].includes(
273273
"DetermineComponentFrameRoot"
274274
);
275275

276276
)
277-
_RunInRootFrame$Deter++;
277+
namePropDescriptor++;
278278
for (
279279
;
280-
sampleStack < controlLines.length &&
281-
!controlLines[sampleStack].includes("DetermineComponentFrameRoot");
280+
_RunInRootFrame$Deter < controlLines.length &&
281+
!controlLines[_RunInRootFrame$Deter].includes(
282+
"DetermineComponentFrameRoot"
283+
);
282284

283285
)
284-
sampleStack++;
286+
_RunInRootFrame$Deter++;
285287
if (
286-
_RunInRootFrame$Deter === sampleLines.length ||
287-
sampleStack === controlLines.length
288+
namePropDescriptor === sampleLines.length ||
289+
_RunInRootFrame$Deter === controlLines.length
288290
)
289291
for (
290-
_RunInRootFrame$Deter = sampleLines.length - 1,
291-
sampleStack = controlLines.length - 1;
292-
1 <= _RunInRootFrame$Deter &&
293-
0 <= sampleStack &&
294-
sampleLines[_RunInRootFrame$Deter] !== controlLines[sampleStack];
292+
namePropDescriptor = sampleLines.length - 1,
293+
_RunInRootFrame$Deter = controlLines.length - 1;
294+
1 <= namePropDescriptor &&
295+
0 <= _RunInRootFrame$Deter &&
296+
sampleLines[namePropDescriptor] !==
297+
controlLines[_RunInRootFrame$Deter];
295298

296299
)
297-
sampleStack--;
300+
_RunInRootFrame$Deter--;
298301
for (
299302
;
300-
1 <= _RunInRootFrame$Deter && 0 <= sampleStack;
301-
_RunInRootFrame$Deter--, sampleStack--
303+
1 <= namePropDescriptor && 0 <= _RunInRootFrame$Deter;
304+
namePropDescriptor--, _RunInRootFrame$Deter--
302305
)
303306
if (
304-
sampleLines[_RunInRootFrame$Deter] !== controlLines[sampleStack]
307+
sampleLines[namePropDescriptor] !==
308+
controlLines[_RunInRootFrame$Deter]
305309
) {
306-
if (1 !== _RunInRootFrame$Deter || 1 !== sampleStack) {
310+
if (1 !== namePropDescriptor || 1 !== _RunInRootFrame$Deter) {
307311
do
308312
if (
309-
(_RunInRootFrame$Deter--,
310-
sampleStack--,
311-
0 > sampleStack ||
312-
sampleLines[_RunInRootFrame$Deter] !==
313-
controlLines[sampleStack])
313+
(namePropDescriptor--,
314+
_RunInRootFrame$Deter--,
315+
0 > _RunInRootFrame$Deter ||
316+
sampleLines[namePropDescriptor] !==
317+
controlLines[_RunInRootFrame$Deter])
314318
) {
315319
var _frame =
316320
"\n" +
317-
sampleLines[_RunInRootFrame$Deter].replace(
321+
sampleLines[namePropDescriptor].replace(
318322
" at new ",
319323
" at "
320324
);
@@ -325,7 +329,7 @@ __DEV__ &&
325329
componentFrameCache.set(fn, _frame);
326330
return _frame;
327331
}
328-
while (1 <= _RunInRootFrame$Deter && 0 <= sampleStack);
332+
while (1 <= namePropDescriptor && 0 <= _RunInRootFrame$Deter);
329333
}
330334
break;
331335
}

0 commit comments

Comments
 (0)