Skip to content

Object.defineProperty not working with older Safari Versions #50

@moehlone

Description

@moehlone

Hi,

I had a problem with Safari on iOS 6.1.3.

The if check

if (!("classList" in document.createElement("_")) || document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")))

resolves correctly in true and the script comes later to

try { objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);

This is a problem in old Safari Versions, because it is not working on DOM Objects. So there is no error but toggle or add will not work with the additional parameters.

I found a working solution for myself by adding

if ("document" in self) {
var setPropOnDOM = true;

// Detect if we can define properties on DOM Objects
try {
    Object.defineProperty(document.createElement("_"), "classList", {
        "get": function() {}
    });
} catch (e) { //Old Safari versions will break at this point
    setPropOnDOM = false;
}

// Full polyfill for browsers with no classList support
// Including IE < Edge missing SVGElement.classList
if (setPropOnDOM && (!("classList" in document.createElement("_")) || document.createElementNS && !("classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")))) {

Old Safaris will resolve in the catch block and then go on with partial support which is then working like expected. I will finish it next week and come back with a clean and fully response when my unit tests are green in all browsers (including old IE, Safari and so on).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions