MCPcopy Create free account
hub / github.com/cure53/DOMPurify / createDOMPurify

Function createDOMPurify

src/purify.ts:230–3277  ·  view source on GitHub ↗
(window: WindowLike = getGlobal())

Source from the content-addressed store, hash-verified

228};
229
230function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
231 const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root);
232
233 DOMPurify.version = VERSION;
234
235 DOMPurify.removed = [];
236
237 if (
238 !window ||
239 !window.document ||
240 window.document.nodeType !== NODE_TYPE.document ||
241 !window.Element
242 ) {
243 // Not running in a browser, provide a factory function
244 // so that you can pass your own Window
245 DOMPurify.isSupported = false;
246
247 return DOMPurify;
248 }
249
250 let { document } = window;
251
252 const originalDocument = document;
253 const currentScript: HTMLScriptElement =
254 originalDocument.currentScript as HTMLScriptElement;
255 const {
256 DocumentFragment,
257 HTMLTemplateElement,
258 Node,
259 Element,
260 NodeFilter,
261 NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap,
262 HTMLFormElement,
263 DOMParser,
264 trustedTypes,
265 } = window;
266
267 const ElementPrototype = Element.prototype;
268
269 const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
270 const remove = lookupGetter(ElementPrototype, 'remove');
271 // Clobber-safe Attr-node removal. On an HTMLFormElement a descendant named
272 // "removeAttributeNode" shadows the prototype method via
273 // [LegacyOverrideBuiltIns], so element.removeAttributeNode(attr) throws.
274 // Calling the cached Element.prototype method with the element as the
275 // receiver removes the exact live Attr node regardless of the shadowing.
276 const removeAttributeNode = lookupGetter(
277 ElementPrototype,
278 'removeAttributeNode'
279 );
280 const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
281 const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
282 const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
283 const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
284 const getAttributes = lookupGetter(ElementPrototype, 'attributes');
285 const getNodeType =
286 Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
287 const getNodeName =

Callers 6

startQUnitFunction · 0.85
startQUnitFunction · 0.85
withDOMPurifyFunction · 0.85
DOMPurifyFunction · 0.85
purify.tsFile · 0.85
runFunction · 0.85

Calls 15

getGlobalFunction · 0.85
lookupGetterFunction · 0.85
_createHooksMapFunction · 0.85
addToSetFunction · 0.85
_isNodeFunction · 0.85
stringifyValueFunction · 0.85
_parseConfigFunction · 0.85
cloneFunction · 0.85
_neutralizePatchLinkageFunction · 0.85
_readNodeNameFunction · 0.85
_neutralizeRootFunction · 0.85
_isClobberedFunction · 0.85

Tested by

no test coverage detected