[whatwg/url] Give optional argument to constructor a sane default (#108)

https://url.spec.whatwg.org/#constructors

The current spec does not provide a sane default for an optional constructor argument, which is a POLA violation. It now puts the burdon on the caller to provide a location object when the URL is relative, requiring the caller to inspect the URL. In practice this will result in an object being passed at all times, since we want the URL object to do the parsing and not do half the work in our code. This makes the whole "optional" part of the argument  a non-feature.

The sane default is the ownerDocument of the calling script. This makes for a much cleaner API which works for the proverbial 80%, leaving only corner cases (the URL of an embedded frame's resource) to provide the baseParam. This change should have no effect on existing code.

If the group wishes to stick to the current specification, then a TypeError is not the correct exception to throw here, but instead _should_ choose MissingArgument. The URLs passed to the constructor are of the correct type (string) and valid URLs. There is not enough information to resolve the URL, because of the missing argument. Yet, when a type error is thrown, the first thought of the programmer will be to search how something else then a string can be passed to the constructor.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/108

Received on Thursday, 31 March 2016 05:55:08 UTC