This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28109 - Inconsistent argument naming in createElementNS and createAttributeNS
Summary: Inconsistent argument naming in createElementNS and createAttributeNS
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-26 16:58 UTC by Philip Jägenstedt
Modified: 2015-11-30 14:44 UTC (History)
3 users (show)

See Also:


Attachments

Description Philip Jägenstedt 2015-02-26 16:58:49 UTC
https://dom.spec.whatwg.org/#document

Element createElementNS(DOMString? namespace, DOMString qualifiedName)

vs

Attr createAttributeNS(DOMString? namespace, DOMString name);

The algorithms look very similar, it seems like createAttributeNS should call its argument qualifiedName too. Maybe. Blink's IDL files do anyway.
Comment 1 Anne 2015-02-27 08:18:20 UTC
Well there's a difference. Attributes actually have a slot called "name". For elements "qualifiedName" is a combination of the internal prefix and local name slot.

It might be that attributes should follow that though...
Comment 2 Philip Jägenstedt 2015-02-27 10:48:31 UTC
OK, right, Attr.name is a thing. I guess it's a difference between naming the input for what it is, or how it is used.

Anything is OK by me, it just looked like an accidental difference to me.
Comment 3 Anne 2015-02-27 15:04:00 UTC
Well, tagName is a thing too... I guess I should check if we actually need an internal slot for name... If we don't I should probably define it in a way similar to elements.
Comment 4 Philip Jägenstedt 2015-03-01 00:34:55 UTC
Do you mean removing Attr.name entirely?
Comment 5 Philip Jägenstedt 2015-03-01 00:50:41 UTC
I see that setAttributeNS(DOMString? namespace, DOMString name, DOMString value) also doesn't match getAttributeNS(DOMString? namespace, DOMString localName), but in that case it doesn't seem odd to me.

(See https://crbug.com/460722 for why I'm noticing these things.)
Comment 6 Philip Jägenstedt 2015-03-01 00:55:31 UTC
No wait that is odd, why wouldn't setAttributeNS and getAttributeNS have the same first two arguments?
Comment 7 Anne 2015-03-01 08:27:34 UTC
> Do you mean removing Attr.name entirely?

No, I meant to drop the internal slot and instead compute it based on prefix and local name.

> No wait that is odd, why wouldn't setAttributeNS and getAttributeNS have the
> same first two arguments?

I'm not sure, is that not what implementations do?
Comment 8 Philip Jägenstedt 2015-03-02 03:41:18 UTC
(In reply to Anne from comment #7)
> > Do you mean removing Attr.name entirely?
> 
> No, I meant to drop the internal slot and instead compute it based on prefix
> and local name.

Oh. FWIW, as implemented in Blink, there's just a QualifiedName (which is a prefix+localName+namespace) used to compute name, localName and namespaceURI. name is prefix + ":" + localName (or just localName if not prefix) so it sounds like the name slot isn't needed.

> > No wait that is odd, why wouldn't setAttributeNS and getAttributeNS have the
> > same first two arguments?
> 
> I'm not sure, is that not what implementations do?

OK, actually setAttributeNS takes a qualifiedName while getAttributeNS takes a localName. That's because when setting you can give a prefix but when getting the prefix doesn't matter. There's always more subtlety to namespaces than I realize.

I found an incompatibility here:

var elem = document.createElement('b');
elem.setAttributeNS('https://example.com', 'a:name', 'value');
elem.setAttributeNS('https://example.com', 'b:name', 'value');
alert(elem.attributes[0].prefix);

Blink/WebKit say a, IE and Gecko say b. I think the spec says b?

In any event, I'm wrong, getAttributeNS and setAttributeNS don't have the same two first arguments. Whether or not just "name" is a good name for setAttributeNS's second argument I'll leave to you.
Comment 9 Anne 2015-03-02 13:27:28 UTC
The specification says "a" for that case as far as I can tell. Since an attribute is found only the value is changed. Prefix is not mutable in the specification I think.

I think I will rename name to qualifiedName when I remove the name internal slot.
Comment 10 Arkadiusz Michalski (Spirit) 2015-11-29 01:30:21 UTC
So this was done by https://github.com/whatwg/dom/issues/110 and can be close here?
Comment 11 Anne 2015-11-29 10:53:04 UTC
No, we still name one argument qualifiedName and the other name. This bug is about changing the argument to getAttribute() et al from name to qualifiedName for editorial consistency and to make things easier to read and understand.