W3C home > Mailing lists > Public > www-style@w3.org > August 2013

RE: [cssom] Methods instead of attributes for usedStyle et al

From: François REMY <francois.remy.dev@outlook.com>
Date: Wed, 14 Aug 2013 02:22:31 +0200
Message-ID: <DUB120-W48361E406465995D6DF7FAA5450@phx.gbl>
To: Simon Pieters <simonp@opera.com>, "www-style@w3.org" <www-style@w3.org>
> getComputedStyle returns a new object each time even if it gets invoked
> with the same arguments in WebKit/Blink/Gecko, but not in IE10:
>
> http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2449
>
> Does anyone have an opinion about which is better, or should I just go
> with the majority? Is getComputedStyle often invoked with the same
> arguments in a tight loop in the wild?

Ooops. Since the object was live, I assumed it would be the same object every time. I happen to call getComputedStyle inside loops from time to time (because I use recursive functions and do not/cannot pass all the style objects as arguments, or because of copy-paste).

I didn't notice any slow down due to it, but I'll try to optimize that anyway. I wonder if replacing the gCS implementation with one with weak maps isn't a good idea, then.



I suppose the advantage of returning a fresh object is that people cannot leak info on the computed style of an element (put expando on it and leak the object forever) or corrupt it. On the other side, it seems like a strange edge case to me which may not be worth the cost.

Another solution would be to "freeze" the object so that it simply cannot accept expandos or custom things (outside its prototype chain). Is IE's object frozen? Or is it like TextNodes (ie: the returned object is the same as long as it's not GCed, but all expandos are lost after the GC because a new object is created then)? 		 	   		  
Received on Wednesday, 14 August 2013 00:22:59 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 14 August 2013 00:23:04 UTC