Is defineProperty for elements broken in iOS6?

186 Views Asked by At

JavaScript's defineProperty and __defineSetter do not work on elements in iOS6. It works properly on all other browsers and on previous versions of iOS. Anybody know more about this?

<input id='Button1' type="button" value="test" onclick="test()">
<script>
Object.defineProperty(Button1,'width',{set: function(x){
    Button1.style.width=x},
    enumerable: true,
    configurable: true});

function test(){
  Button1.width="100px";
  alert(Button1.style.width);
  }
</script>

Here's the fiddle:

http://jsfiddle.net/ghenne/pnL7p/

1

There are 1 best solutions below

0
On

Actually, iOS 6 appears to be the first version of Safari that doesn't suffer from a bug that allows certain native DOM properties (like width) to be overwritten even when they are non-configurable.

In all versions of Safari (mobile or otherwise) I've been able to test with, the width property (and several others) are not configurable (i.e. configurable: false). Despite this, the current version of Safari on the desktop, and versions of mobile safari on iOS 5.1 and lower will happily allow the width property to be given a new descriptor. In iOS 6, the descriptor is respected.

One thing worth mentioning is that configurable is respected for user set properties, it's just these preset properties that have the problem.

As for other browsers, Chrome sets these properties to configurable, and Firefox appears to not associate descriptors with the properties, which is why you don't have problems on these browsers. I did not test IE.

The real issue, it seems to me, is that Safari sets these properties to be not configurable, and in iOS 6 has finally started paying attention to that.