Skip to content

Commit

Permalink
Fix IE8 problems
Browse files Browse the repository at this point in the history
- Refactor out Object.create
- Wrap non-function con methods as functions and check for .apply method
  • Loading branch information
jgable committed Jan 22, 2014
1 parent 07f16a8 commit b894cb0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/cross-console.js
Expand Up @@ -14,7 +14,14 @@

// inherit the console prototype
if(con) {
CC = Object.create(con);
CC = function () { };
for(var prop in con.prototype) {
if (!con.hasOwnProperty(prop)) {
continue;
}

CC.prototype[prop] = con.prototype[prop];
}
}

if (typeof module !== 'undefined') {
Expand Down Expand Up @@ -135,6 +142,7 @@
'profiles'
],
idx = pass_methods.length,
method,
handleCircularReferences = function() {
var circularKeys = [], depthRestriction = 15; // resetting the brains

Expand Down Expand Up @@ -303,12 +311,19 @@
idx = trace_methods.length;

while(--idx >= 0){
method = con[trace_methods[idx]];
// Make dummy methods for console methods that don't exist (IE9 has no console.error)
con[trace_methods[idx]] = con[trace_methods[idx]] || function () { };
if (typeof method !== 'function') {
method = function () {
if (con[trace_methods[idx]].apply) {
con[trace_methods[idx]].apply(con, arguments);
}
};
}

// Make the method an actual function
// (IE's console.log is not actually a Function and therefore has no apply())
con[trace_methods[idx]] = Function.prototype.bind.call(con[trace_methods[idx]], con);
method = Function.prototype.bind.call(method, con);

loadTraceMethods(idx,trace_methods[idx]);
}
Expand Down

0 comments on commit b894cb0

Please sign in to comment.