graphicore / specimenTools

Apache License 2.0
29 stars 5 forks source link

iOS 8.1 Javascript error in OTFeatureInfo.js #21

Open kontur opened 7 years ago

kontur commented 7 years ago

The call to Object.freeze(https://github.com/graphicore/specimenTools/blob/master/lib/services/OTFeatureInfo.js#L775) is causing an Javascript error in iOS 8.1.

The code checks if obj is indeed of type 'object', but for this case it seems to be 'undefined' when it reaches this line.

I'm not entirely sure what is going on in this part of the code, so I thought I run this by you first.

graphicore commented 7 years ago

The code checks if obj is indeed of type 'object', but for this case it seems to be 'undefined' when it reaches this line.

This looks like a strange bug in the iOS JS. The objcan't change within this function. Have you tried to searching for a bug in wherever iOS 8.1 Javascript is managed. iOS 8.1 JavaScript, what is this Mobile Safari?

We could try ... catch the call and just go without freezing there. It's more like an API measure to make it explicit that the data in the module shouldn't be changed, maybe even a bit paranoid. If we don't freeze on systems we develop on, it's not changing anything.

graphicore commented 7 years ago

The code checks if obj is indeed of type 'object', but for this case it seems to be 'undefined' when it reaches this line.

Thinking about this, it could well be that Object.freeze is not defined in old browsers.

The error would be something like "undefined is not a function" or "TypeError: Object.freeze is not a function." the message depends on the js interpreter.

If so:

function deepFreeze(obj) {
        var k;
        if(!Object.freeze) return;
        if(typeof obj !== 'object') return;
        for(k in obj)
            deepFreeze(obj[k]);
        Object.freeze(obj);
}

this should do the trick. Could you try this out?

kontur commented 7 years ago

Funnily enough this fails not because Object.freeze is not defined (it seems to be) nor because the obj passed in would not be a an object (at least according to typeof). Very odd.

With a try-catch it can be made to not break, as per: https://github.com/kontur/specimenTools/commit/753d5b2d01dafb67b9c8a82168aa7660607cce52

However, I get another javascript error that seems to also appear only on that outdated iOS version. Here the error is undefined is not a function

graphicore commented 7 years ago

However, I get another javascript error that seems to also appear only on that outdated iOS version. Here the error is undefined is not a function

In this case codePointAt is probably not defined. It's a newer replacement for charCodeAt

There's a Polyfill though.

kontur commented 7 years ago

That seems to do the trick, no more iOS 8 errors at least on the test pages. I couldn't find any other places that have included a polyfill, so in this instance I included at inside the FontsData.js. I have my changes in this branch