Skip to content

Commit 61f5965

Browse files
committed
pass parameters explicitly to avoid using .apply
which is not supported for console methods in ie9
1 parent b18be9e commit 61f5965

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

packages/shared/warningWithoutStack.js

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
let warningWithoutStack = () => {};
1616

1717
if (__DEV__) {
18-
const consoleError = Function.prototype.bind.call(console.error, console);
19-
2018
warningWithoutStack = function(condition, format, ...args) {
2119
if (format === undefined) {
2220
throw new Error(
@@ -28,15 +26,62 @@ if (__DEV__) {
2826
return;
2927
}
3028
if (typeof console !== 'undefined') {
31-
const stringArgs = args.map(item => '' + item);
32-
const originalConsoleError = console.error;
29+
const arr = args.map(item => '' + item);
30+
const arrLength = arr.length;
3331

34-
if (typeof console.error.apply === 'undefined') {
35-
console.error = consoleError;
32+
if (arrLength === 0) {
33+
console.error('Warning: ' + format);
34+
} else if (arrLength === 1) {
35+
console.error('Warning: ' + format, arr[0]);
36+
} else if (arrLength === 2) {
37+
console.error('Warning: ' + format, arr[0], arr[1]);
38+
} else if (arrLength === 3) {
39+
console.error('Warning: ' + format, arr[0], arr[1], arr[2]);
40+
} else if (arrLength === 4) {
41+
console.error('Warning: ' + format, arr[0], arr[1], arr[2], arr[3]);
42+
} else if (arrLength === 5) {
43+
console.error(
44+
'Warning: ' + format,
45+
arr[0],
46+
arr[1],
47+
arr[2],
48+
arr[3],
49+
arr[4],
50+
);
51+
} else if (arrLength === 6) {
52+
console.error(
53+
'Warning: ' + format,
54+
arr[0],
55+
arr[1],
56+
arr[2],
57+
arr[3],
58+
arr[4],
59+
arr[5],
60+
);
61+
} else if (arrLength === 7) {
62+
console.error(
63+
'Warning: ' + format,
64+
arr[0],
65+
arr[1],
66+
arr[2],
67+
arr[3],
68+
arr[4],
69+
arr[5],
70+
arr[6],
71+
);
72+
} else if (arrLength === 8) {
73+
console.error(
74+
'Warning: ' + format,
75+
arr[0],
76+
arr[1],
77+
arr[2],
78+
arr[3],
79+
arr[4],
80+
arr[5],
81+
arr[6],
82+
arr[7],
83+
);
3684
}
37-
38-
console.error('Warning: ' + format, ...stringArgs);
39-
console.error = originalConsoleError;
4085
}
4186
try {
4287
// --- Welcome to debugging React ---

0 commit comments

Comments
 (0)