-
Notifications
You must be signed in to change notification settings - Fork 120
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
Implement DOMParser interface #137
base: master
Are you sure you want to change the base?
Conversation
This implements the DOMParser interface. As of now, only the "text/html" type is supported, the unsupported types will throw.
c585f01
to
737b617
Compare
@@ -4,6 +4,7 @@ var EventTarget = require('./EventTarget'); | |||
var Location = require('./Location'); | |||
var sloppy = require('./sloppy'); | |||
var utils = require('./utils'); | |||
var DOMParserWrapper = require("./DOMParser"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this DOMParserWrapper
and not just DOMParser
? None of the other classes have ...Wrapper
suffixes.
@@ -3036,6 +3035,9 @@ | |||
"dom/nodes/Element-siblingElement-null-xhtml.xhtml": [ | |||
"Uncaught: Unexpected token <" | |||
], | |||
"dom/nodes/Element-tagName.html": [ | |||
"tagName should be updated when changing ownerDocument" | |||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new test failure. Why?
"Location value", | ||
"DOMParser parses HTML tag soup with no problems", | ||
"DOMParser throws on an invalid enum value" | ||
"baseURI value" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that we pass these tests now!
@@ -12,6 +13,7 @@ function Window(document) { | |||
this.document._scripting_enabled = true; | |||
this.document.defaultView = this; | |||
this.location = new Location(this, this.document._address || 'about:blank'); | |||
this.DOMParser = DOMParserWrapper(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this isn't the right way to export it. You should instead add this to lib/impl.js, which then gets merged into Window in via utils.expose
in the last line of this file.
This implementation seems to work correctly when the content type is set
to
text/html
, however the XML types fall through the HTMLParser sincethere's no XMLSerializer interface.
The tests for the
text/html
type are passing, except thebaseURI
one, since its getter is not yet implemented in thelib/Node.js
file.If, in the future, the XMLSerializer interface is implemented I think it should be easy to add the missing logic.
Lastly: I'm not sure if the DOMParser interface should be exposed the way I did.
It needs to access the active document address and I didn't find any other way to make it work.
Maybe, by logic, it should go into the
lib/impl.js
file?Edit:
At the end I decided to definitely throw on the not-yet-implemented XML types to avoid misleading behavior with the HTMLParser fallback (case sensitivity to name one).
Still, I'm not really sure I exposed the DOMParser interface the proper way.