shawnbot / aight

JavaScript shims and shams for making IE8-9 behave reasonably

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Additional work on CSSStyleDeclaration

brettz9 opened this issue · comments

Regarding css-properties.js, would you take a look at https://github.com/brettz9/jml/blob/master/shims/CSSStyleDeclaration.js and let me know if that content interests you in some manner? I added some more methods to CSSStyleDeclaration such as getPropertyPriority() and adding more type checking and conversions.

Note there are a few dependencies:

  1. One is a shim for DOMException (e.g., my fork of @inexorabletash 's copy is at https://github.com/brettz9/jml/blob/master/shims/DOMException.js which indicates it also depends on shims for Object.keys and Array.prototype.forEach as also found in https://github.com/brettz9/jml/tree/master/shims ) which adds a convenience method DOMException.create() since the real DOMException does not allow itself to be instantiation through "new DOMException". Although I'm normally not a fan of adding non-standard properties (even if on a namespace), I think this one is unobtrusive enough and more convenient than packing all the code into each file that uses it.
  2. Object.defineProperty as shimmed by https://github.com/eligrey/Xccessors/blob/master/xccessors-standard.js

Hi there, and thanks for this. Your implementation of CSSStyleDeclaration looks great, and at first glance it doesn't depend on the non-standard DOMException.create() method. My preference would be to reference this as a submodule (as I've done with other libraries in the new v2 branch). Would you be ok with that?

Hello and thanks...

Correct, my implementation doesn't depend on the non-standard exception method, but it produces a more complete standard-emulating exception if the shim is present (though the error would only occur in an obscure case anyways). A submodule would be just fine.

While imperfect, you may also be interested in https://github.com/brettz9/jml/blob/master/shims/Element.prototype.getAttribute.js or https://github.com/brettz9/jml/blob/master/shims/XMLSerializer.js which may provide more than existing polyfill implementations in that they attempt to streamline behavior with IE, even where the behavior is not part of a standard.

Just a quick note re: DOMException - browsers new apply a name attribute since code is deprecated. So if you're mimicking them just using objects, don't forget to include that.

(As an aside, I wouldn't bother trying to generate a real DOMException. There's very little code in the wild that actually does identity tests on DOM objects rather than just inspecting properties, and exceptions even less-so.)

Are you sure about there being a name attribute? I don't see this mentioned at either https://dom.spec.whatwg.org/#exception-domexception or http://www.w3.org/TR/dom/#exception-domexception . Do you know where this has been established?

https://dom.spec.whatwg.org/#exception-domexception

Throw a new DOMException exception, whose message is a user agent-defined value, name is name, and whose code exception field is code.

Where "Throw" references:

http://heycam.github.io/webidl/#dfn-throw

and http://heycam.github.io/webidl/#es-exceptions for the ES binding of IDL exceptions.

... but it's weird that the IDL definition of DOMException in https://dom.spec.whatwg.org/#exception-domexception doesn't have name called out. I'll bug @annevk

... although the DOM spec's comment: at https://dom.spec.whatwg.org/#errors really covers it:

This entire section will move out of DOM into IDL. Use this standard as reference for DOMException until that has happened. Replace instances of DOMError with DOMException as DOMError will be nuked from orbit soon.

Errors are being moved out of the DOM spec entirely into Web IDL, and they are defined (in convoluted text) at: https://dom.spec.whatwg.org/#errors

Anyway... all in flux, but all new exception types are defined with name and code is 0. All browsers (well, IE10 and more modern) adhere to this.

http://heycam.github.io/webidl/#dfn-exception-name

(DOMException has a name (and message) field because it is an exception and not an interface. Subtle, but important difference. But yes, if anyone wants to start maintaining IDL we can have a chat about how the specifications need to be updated.)

I've updated the CSSOM shim in #49 and am going to stick with this much simpler implementation for now.