(window: WindowLike = getGlobal())
| 117 | }; |
| 118 | |
| 119 | function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify { |
| 120 | const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root); |
| 121 | |
| 122 | DOMPurify.version = VERSION; |
| 123 | |
| 124 | DOMPurify.removed = []; |
| 125 | |
| 126 | if ( |
| 127 | !window || |
| 128 | !window.document || |
| 129 | window.document.nodeType !== NODE_TYPE.document || |
| 130 | !window.Element |
| 131 | ) { |
| 132 | // Not running in a browser, provide a factory function |
| 133 | // so that you can pass your own Window |
| 134 | DOMPurify.isSupported = false; |
| 135 | |
| 136 | return DOMPurify; |
| 137 | } |
| 138 | |
| 139 | let { document } = window; |
| 140 | |
| 141 | const originalDocument = document; |
| 142 | const currentScript: HTMLScriptElement = |
| 143 | originalDocument.currentScript as HTMLScriptElement; |
| 144 | const { |
| 145 | DocumentFragment, |
| 146 | HTMLTemplateElement, |
| 147 | Node, |
| 148 | Element, |
| 149 | NodeFilter, |
| 150 | NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap, |
| 151 | HTMLFormElement, |
| 152 | DOMParser, |
| 153 | trustedTypes, |
| 154 | } = window; |
| 155 | |
| 156 | const ElementPrototype = Element.prototype; |
| 157 | |
| 158 | const cloneNode = lookupGetter(ElementPrototype, 'cloneNode'); |
| 159 | const remove = lookupGetter(ElementPrototype, 'remove'); |
| 160 | const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling'); |
| 161 | const getChildNodes = lookupGetter(ElementPrototype, 'childNodes'); |
| 162 | const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); |
| 163 | |
| 164 | // As per issue #47, the web-components registry is inherited by a |
| 165 | // new document created via createHTMLDocument. As per the spec |
| 166 | // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries) |
| 167 | // a new empty registry is used when creating a template contents owner |
| 168 | // document, so we use that as our parent document to ensure nothing |
| 169 | // is inherited. |
| 170 | if (typeof HTMLTemplateElement === 'function') { |
| 171 | const template = document.createElement('template'); |
| 172 | if (template.content && template.content.ownerDocument) { |
| 173 | document = template.content.ownerDocument; |
| 174 | } |
| 175 | } |
| 176 |
no test coverage detected