panzerdp/voca

explorer support

Kreider186 opened this issue · 8 comments

Hi! I tried the voca.js on explorer v11 and it crashed.

I'm not an expert in javascript but I managed to make it work by adding a few lines. Maybe it could be useful to others?

Modifies:

At the very beginning of the file:

//object.keys support
if (!Object.keys) {
  Object.keys = function(obj) {
    var keys = [];
    for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
      keys.push(i);
    }
  }
 return keys;
  };
}

//object.values support
if (!Object.values) {

Object.values = function(obj) {

var res = [];
    for (var i in obj) {
        if (obj.hasOwnProperty(i)) {
            res.push(obj[i]);
        }
    }
    return res;
  };
}

//Array.foreach support
if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(fn, scope) {
        for(var i = 0, len = this.length; i < len; ++i) {
            fn.call(scope, this[i], i, this);
        }
    }
}

//Array.isArray support
if (!Array.isArray) {
    Array.isArray = function(item) {
      if(item instanceof Array){return true;}
      return false;
    }
}

//bind support
if (!Function.prototype.bind) {
  Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
      // closest thing possible to the ECMAScript 5
      // internal IsCallable function
      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
    }

    var aArgs   = Array.prototype.slice.call(arguments, 1),
        fToBind = this,
        fNOP    = function() {},
        fBound  = function() {
          return fToBind.apply(this instanceof fNOP && oThis
                 ? this
                 : oThis,
                 aArgs.concat(Array.prototype.slice.call(arguments)));
        };

    fNOP.prototype = this.prototype;
    fBound.prototype = new fNOP();

    return fBound;
  };
}

(function (global, factory) { 
[...]

And then the function isNil

function isNil(value) {
    return value === undefined || value === null || value === '';
}

Now it works.

@Kreider186,
Please show the code you're running and what was the error message.
Thanks.

@panzerdp
I was running the voca.js build (directly into browser's web page) and there wasn't any error messages, simply it didn't work at all (with internet explorer, it works perfecly with chrome).

Inspecting the code with explorer's debugger I found that many functions were not supported.
So I add the functions above in order to overwrite non-supported functions.

Once overwritten the unsupported functions, the code was still not working and again no exceptions/errors were thrown.

Then, I figured out that here:

ReplacementIndex.prototype.getIndexByPosition = function (position) {
  return isNil(position) ? this.index : position - 1;
};

the function was returning -1 because in explorer the value of position wasn't undefined nor null but simply nothing ('').

So I edited the isNil function this way:

function isNil(value) {
return value === undefined || value === null || value === '';
}

And now it works.

@panzerdp
I've made a pdf with some screenshot and the description of what happened step by step.
Hope it helps.

p.s.: the 3rd error was triggered by my my script because I was already replacing some unsupported function (objext.keys and object.values) but I removed the hack for the screenshot report.
screenshots.pdf

@Kreider186,
The problem is in meta tag <meta http-equiv="X-UA-Compatible" content="IE=8"> that makes the browser work in IE 8 mode (which does not support Object.keys(), func.bind(), etc).

Voca however supports IE 9 and above.

Try to remove this meta tag and see if it works.

@panzerdp
Nhope, that doesn't solve the issue. But I tried to replace the meta tag with:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

And at least the last error disappeard (the one on isNil function).
Ill'do some other research.

@panzerdp
Mmm... what the heck.
I've no idea of what happened but today it works.
Putting the right meta did the trick and now everything works.
Thank you!

You're welcome.