Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give optional argument to constructor a sane default #108

Closed
melvyn-sopacua opened this issue Mar 31, 2016 · 2 comments
Closed

Give optional argument to constructor a sane default #108

melvyn-sopacua opened this issue Mar 31, 2016 · 2 comments

Comments

@melvyn-sopacua
Copy link

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.

@annevk
Copy link
Member

annevk commented Mar 31, 2016

JavaScript doesn't have a MissingArgument exception. Anyway, this is a duplicate of #71. new URL() shouldn't have any defaulting since the default varies widely depending on context, but there should maybe be a utility method on specific contexts.

@annevk annevk closed this as completed Mar 31, 2016
@annevk
Copy link
Member

annevk commented Mar 31, 2016

(Note also that a calling script doesn't have an ownerDocument.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants