Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
contentDoc.contentType = contentType.essence;
}
}
const encoding = sniffHTMLEncoding(data, sniffOptions);
contentDoc._encoding = encoding;
const html = whatwgEncoding.decode(data, contentDoc._encoding);
try {
parseIntoDocument(html, contentDoc);
} catch (error) {
if (
error.constructor.name === "DOMException" &&
error.code === DOMException.SYNTAX_ERR &&
contentDoc._parsingMode === "xml"
) {
// As defined (https://html.spec.whatwg.org/#read-xml) parsing error in XML document may be reported inline by
// mutating the document.
const element = contentDoc.createElementNS("http://www.mozilla.org/newlayout/xml/parsererror.xml", "parsererror");
element.textContent = error.message;
while (contentDoc.childNodes.length > 0) {
contentDoc.removeChild(contentDoc.lastChild);
}
contentDoc.appendChild(element);
} else {
throw error;
}
}
export function toAbortablePromise(
observable: Observable,
signal?: ?AbortSignal,
): Promise {
if (signal == null) {
return observable.toPromise();
}
if (signal.aborted) {
return Promise.reject(DOMException('Aborted', 'AbortError'));
}
return observable
.race(
Observable.fromEvent(signal, 'abort').map(() => {
throw new DOMException('Aborted', 'AbortError');
}),
)
.toPromise();
}
Observable.fromEvent(signal, 'abort').map(() => {
throw new DOMException('Aborted', 'AbortError');
}),
)