Skip to content

Commit

Permalink
Fix warning without stack for ie9 (#13620)
Browse files Browse the repository at this point in the history
* Fix warning without stack for ie9

Where console methods like log, error etc. don't have 'apply' method.
Because of the lot of tests already expect that exactly console['method']
will be called - had to reapply references for console.error method

#13610

* pass parameters explicitly to avoid using .apply
which is not supported for console methods in ie9

* Minor tweaks
  • Loading branch information
link-alex authored and gaearon committed Sep 12, 2018
1 parent dde0645 commit 1b2646a
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions packages/shared/warningWithoutStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,54 @@ if (__DEV__) {
'message argument',
);
}
if (args.length > 8) {
// Check before the condition to catch violations early.
throw new Error(
'warningWithoutStack() currently supports at most 8 arguments.',
);
}
if (condition) {
return;
}
if (typeof console !== 'undefined') {
const stringArgs = args.map(item => '' + item);
console.error('Warning: ' + format, ...stringArgs);
const [a, b, c, d, e, f, g, h] = args.map(item => '' + item);
const message = 'Warning: ' + format;

// We intentionally don't use spread (or .apply) because it breaks IE11:
// https://github.com/facebook/react/issues/13610
switch (args.length) {
case 0:
console.error(message);
break;
case 1:
console.error(message, a);
break;
case 2:
console.error(message, a, b);
break;
case 3:
console.error(message, a, b, c);
break;
case 4:
console.error(message, a, b, c, d);
break;
case 5:
console.error(message, a, b, c, d, e);
break;
case 6:
console.error(message, a, b, c, d, e, f);
break;
case 7:
console.error(message, a, b, c, d, e, f, g);
break;
case 8:
console.error(message, a, b, c, d, e, f, g, h);
break;
default:
throw new Error(
'warningWithoutStack() currently supports at most 8 arguments.',
);
}
}
try {
// --- Welcome to debugging React ---
Expand Down

0 comments on commit 1b2646a

Please sign in to comment.