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

Element.attributes should be a NamedNodeMap #853

Closed
paton opened this issue Aug 11, 2014 · 6 comments
Closed

Element.attributes should be a NamedNodeMap #853

paton opened this issue Aug 11, 2014 · 6 comments

Comments

@paton
Copy link
Contributor

paton commented Aug 11, 2014

document.createElement('div').attributes.toString();

Chrome: "[object NamedNodeMap]"
jsdom: "[object Object]"

Also...

var div = _window.document.createElement('div');
var attrs = [];

for (var prop in div.attributes) {
  if (div.hasOwnProperty(prop)) attrs.push(prop);
}
console.log(attrs)

Chrome: []
jsdom: [ '_ownerDocument', '_parentNode', '_readonly' ]


This is breaking a script that copies attributes from one element onto another.

Is this something that's fixable?

@domenic
Copy link
Member

domenic commented Aug 11, 2014

The toString problem: yes, definitely fixable; pull request welcome.

The own-properties problem: kind of. We could fix your particular example by making the underscored-properties non-enumerable, which is not very hard. But if we wanted to protect against Object.getOwnPropertyNames, it'd be much harder; ideas over in #835.

@paton
Copy link
Contributor Author

paton commented Aug 11, 2014

Awesome.. will take a deeper look.

@skrat
Copy link

skrat commented Sep 1, 2014

Regardless of the example, why not making it a NamedNodeMap?

@Joris-van-der-Wel
Copy link
Member

It is a NamedNodeMap now, however toString() will still return "[object Object]".
The toString behaviour is defined in Web IDL. The toString is incorrect for a lot of objects in jsdom #1136 .

@domenic
Copy link
Member

domenic commented Jun 26, 2015

Oh hey, fixed this in 5.4.0.

@domenic domenic closed this as completed Jun 26, 2015
@Frankusky
Copy link

Frankusky commented Apr 25, 2017

I wasn't able to get NamedNodeMap, even using Object.prototype.toString.call(domElement.attributes) neither using domElement.attributes.toString(), both returns [object Object]

Im using the following code:

let dom = new JSDOM("<!DOCTYPE html><div class="test"><script src="http://test.com/file.js" my-attribute="testing"></script>"); global.window = dom.window; global.document = dom.window.document; console.log(document.getElementsByTagName('script')[0].attributes.toString()); console.log(Object.prototype.toString.call(document.getElementsByTagName('script')[0].attributes));

I will create a new issue since this is issue is too old

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

No branches or pull requests

5 participants