specimenTools icon indicating copy to clipboard operation
specimenTools copied to clipboard

iOS 8.1 Javascript error in OTFeatureInfo.js

Open kontur opened this issue 8 years ago • 5 comments

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.

kontur avatar Mar 02 '17 08:03 kontur

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 avatar Mar 02 '17 14:03 graphicore

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?

graphicore avatar Mar 06 '17 05:03 graphicore

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

kontur avatar Apr 02 '17 15:04 kontur

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.

graphicore avatar Apr 02 '17 15:04 graphicore

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

kontur avatar Apr 08 '17 20:04 kontur