Skip to content

Commit b2c0075

Browse files
committed
simplify loggers and tests without IE9 & 10
1 parent 3b1fe09 commit b2c0075

File tree

2 files changed

+12
-90
lines changed

2 files changed

+12
-90
lines changed

src/lib/loggers.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,10 @@ loggers.error = function() {
8282
}
8383
};
8484

85-
/*
86-
* Robust apply, for IE9 where console.log doesn't support
87-
* apply like other functions do
88-
*/
8985
function apply(f, args) {
9086
if(f && f.apply) {
91-
try {
92-
// `this` should always be console, since here we're always
93-
// applying a method of the console object.
94-
f.apply(console, args);
95-
return;
96-
} catch(e) { /* in case apply failed, fall back on the code below */ }
97-
}
98-
99-
// no apply - just try calling the function on each arg independently
100-
for(var i = 0; i < args.length; i++) {
101-
try {
102-
f(args[i]);
103-
} catch(e) {
104-
// still fails - last resort simple console.log
105-
console.log(args[i]);
106-
}
87+
// `this` should always be console, since here we're always
88+
// applying a method of the console object.
89+
f.apply(console, args);
10790
}
10891
}

test/jasmine/tests/lib_test.js

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,28 +1675,25 @@ describe('Test lib.js:', function() {
16751675
var stashLogLevel;
16761676
var stashOnGraphLogLevel;
16771677

1678-
function consoleFn(name, hasApply, messages) {
1678+
function consoleFn(name, messages) {
16791679
var out = function() {
1680-
if(hasApply) expect(this).toBe(window.console);
16811680
var args = [];
16821681
for(var i = 0; i < arguments.length; i++) args.push(arguments[i]);
16831682
messages.push([name, args]);
16841683
};
16851684

1686-
if(!hasApply) out.apply = undefined;
1687-
16881685
return out;
16891686
}
16901687

1691-
function mockConsole(hasApply, hasTrace, hasError) {
1688+
function mockConsole() {
16921689
var out = {
16931690
MESSAGES: []
16941691
};
1695-
out.log = consoleFn('log', hasApply, out.MESSAGES);
1692+
out.log = consoleFn('log', out.MESSAGES);
16961693

1697-
if(hasError) out.error = consoleFn('error', hasApply, out.MESSAGES);
1694+
out.error = consoleFn('error', out.MESSAGES);
16981695

1699-
if(hasTrace) out.trace = consoleFn('trace', hasApply, out.MESSAGES);
1696+
out.trace = consoleFn('trace', out.MESSAGES);
17001697

17011698
return out;
17021699
}
@@ -1713,8 +1710,8 @@ describe('Test lib.js:', function() {
17131710
config.notifyOnLogging = stashOnGraphLogLevel;
17141711
});
17151712

1716-
it('emits one console message if apply is available', function() {
1717-
var c = window.console = mockConsole(true, true, true);
1713+
it('emits one console message', function() {
1714+
var c = window.console = mockConsole();
17181715
config.logging = 2;
17191716

17201717
Lib.log('tick', 'tock', 'tick', 'tock', 1);
@@ -1728,50 +1725,8 @@ describe('Test lib.js:', function() {
17281725
]);
17291726
});
17301727

1731-
it('falls back on console.log if no trace', function() {
1732-
var c = window.console = mockConsole(true, false, true);
1733-
config.logging = 2;
1734-
1735-
Lib.log('Hi');
1736-
Lib.warn(42);
1737-
1738-
expect(c.MESSAGES).toEqual([
1739-
['log', ['LOG:', 'Hi']],
1740-
['log', ['WARN:', 42]]
1741-
]);
1742-
});
1743-
1744-
it('falls back on separate calls if no apply', function() {
1745-
var c = window.console = mockConsole(false, false, true);
1746-
config.logging = 2;
1747-
1748-
Lib.log('tick', 'tock', 'tick', 'tock', 1);
1749-
Lib.warn('I\'m', 'a', 'little', 'cuckoo', 'clock', [1, 2]);
1750-
Lib.error('cuckoo!', 'cuckoo!!!', {a: 1, b: 2});
1751-
1752-
expect(c.MESSAGES).toEqual([
1753-
['log', ['LOG:']],
1754-
['log', ['tick']],
1755-
['log', ['tock']],
1756-
['log', ['tick']],
1757-
['log', ['tock']],
1758-
['log', [1]],
1759-
['log', ['WARN:']],
1760-
['log', ['I\'m']],
1761-
['log', ['a']],
1762-
['log', ['little']],
1763-
['log', ['cuckoo']],
1764-
['log', ['clock']],
1765-
['log', [[1, 2]]],
1766-
['error', ['ERROR:']],
1767-
['error', ['cuckoo!']],
1768-
['error', ['cuckoo!!!']],
1769-
['error', [{a: 1, b: 2}]]
1770-
]);
1771-
});
1772-
17731728
it('omits .log at log level 1', function() {
1774-
var c = window.console = mockConsole(true, true, true);
1729+
var c = window.console = mockConsole();
17751730
config.logging = 1;
17761731

17771732
Lib.log(1);
@@ -1785,7 +1740,7 @@ describe('Test lib.js:', function() {
17851740
});
17861741

17871742
it('logs nothing at log level 0', function() {
1788-
var c = window.console = mockConsole(true, true, true);
1743+
var c = window.console = mockConsole();
17891744
config.logging = 0;
17901745

17911746
Lib.log(1);
@@ -1795,22 +1750,6 @@ describe('Test lib.js:', function() {
17951750
expect(c.MESSAGES).toEqual([]);
17961751
});
17971752

1798-
it('falls back on simple log if there is no console.error', function() {
1799-
// TODO
1800-
1801-
var c = window.console = mockConsole(true, true, false);
1802-
config.logging = 2;
1803-
1804-
Lib.error('who are you', 'who who... are you', {a: 1, b: 2});
1805-
1806-
expect(c.MESSAGES).toEqual([
1807-
['log', ['ERROR:']],
1808-
['log', ['who are you']],
1809-
['log', ['who who... are you']],
1810-
['log', [{a: 1, b: 2}]]
1811-
]);
1812-
});
1813-
18141753
describe('should log message in notifier div in accordance notifyOnLogging config option', function() {
18151754
var query = '.notifier-note';
18161755

0 commit comments

Comments
 (0)