Skip to content

Commit

Permalink
Extract try/catch into a separate function to prevent deopt (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and zpao committed Aug 19, 2016
1 parent e3017e6 commit a1dca09
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/__forks__/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ var emptyFunction = require('emptyFunction');
var warning = emptyFunction;

if (__DEV__) {
function printWarning(format, ...args) {
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
}

warning = function(condition, format, ...args) {
if (format === undefined) {
throw new Error(
Expand All @@ -36,17 +50,7 @@ if (__DEV__) {
}

if (!condition) {
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
printWarning(format, ...args);
}
};
}
Expand Down

0 comments on commit a1dca09

Please sign in to comment.