TypeError vs HierarchyRequestError
speich opened this issue · 2 comments
How should I/we go about specific error messages when setting a property ? For example when setting the HTMLTableCaption property, the spec says to throw a HierarchyRequestError error. But since the method protected function __prop_set_caption(?HTMLTableCaptionElement $value): void {}
does a type check, a TypeError is thrown by php before I can even test for the type and throw the custom HierarchyRequestError
Originally posted by @speich in #268 (comment)
This was only a simple case where the argument type HTMLTableCaptionElement matches the required property, e.g. the tag directly. But what about: protected function _prop_set_tFoot(?HTMLTableSectionElement $value): void {}
where I have to test that the tag is actually a <tfoot> ?
We should allow PHP to perform type checking as far as possible, so the caption
property will not be able to receive anything other than an HTMLTableCaptionElement
. This is true to the spec, but in JavaScript they don't have the luxury of having type checking built into the language.
There are areas of the code that will still require manual checks. As you've found, the tFoot
property can take an HTMLTableSectionElement
, which might not necessarily be a <tfoot>
, but will not violate the type sensitivity as defined by the spec.
In this case, it makes complete sense to perform manual specific type checks, and throwing a HierarcheRequestError
where necessary. Checking the tagName is as much as is necessary, as far as I can see.