Elemental2 wrapper for DOMParser
jiakuan opened this issue · 8 comments
Can't find DOMParser
from the current elemental2 library.
https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
Shall we support it as well?
@jDramaix This is defined in https://github.com/google/closure-compiler/blob/master/externs/browser/gecko_xml.js though I don't see us using any extern named gecko (though this one doesn't seem Mozilla specific)
When I asked the closure-compiler maintainers some years ago about the different browser-named extern files, they indicated that this was often the original source of that type, and that it wouldn't be beneficial to migrate the externs out of that file and into something common now that the type is standardized.
Yes we do not use any specific browser extern files. If the api has been standardized we need to move the api in another extern file (w3c_xml.js in this case). Contribution is welcome :)
It looks like my memory is faulty or policy has changed: I can't find the specific conversation where gwt community members were asked to not bulk migrate standardized entries, but google/closure-compiler#2478 is one such conversation.
The entire gecko_dom.js is standardized now (with the exception of the serializer method serializeToStream
, which is no longer supported by any browser that I can see), but as it is only a few members, so I'll see about moving it.
The problem is that DOMParser.parseFromString()
is accepting a TrustedHTML
and this is not supported in Elemental2 yet.
@jDramaix elemental also includes w3c_range that uses TrustedHTML, is that also a problem? https://github.com/google/closure-compiler/blob/46131b1844fb070316a98c5b4c047ee3d786553e/externs/browser/w3c_range.js#L250
elemental2/java/elemental2/dom/BUILD
Line 66 in 33cea8e
The definition of the types are there but there is no J2CL/GWT way to instantiate them (I don't even know a standard way to instantiate them on JS). Also, the version of DOMParser.parseFromString()
taking a String
is considered as unsafe and the Elemental2 build will fail internally at Google. So we would end up generating Java code only targeting the signature using TrustedHTML. It' not a working solution as it would not be usable by most users.
I don't even know a standard way to instantiate them on JS)
So is this issue blocked by FireFox+Safari support for trusted types? (mozilla/standards-positions#20, https://webkit.org/standards-positions/ doesn't even mention it).
Elemental already contains the code needed for instantiating trusted HTML in Chromium
TrustedTypePolicyOptions tpo = TrustedTypePolicyOptions.create();
tpo.setCreateHTML((str, ignore) -> str);
DomGlobal.trustedTypes.createPolicy("unsafe", tpo).createHTML("<img>");