Sha256: 740042adfd6513de3fe13db21f4bf4b5d3a8b8b89b44396fc302fdc8e5ea0c59

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

"use strict";

const { parseIntoDocument } = require("../../browser/parser");

const Document = require("../generated/Document");

exports.implementation = class DOMParserImpl {
  constructor(globalObject) {
    this._globalObject = globalObject;
  }

  parseFromString(string, contentType) {
    switch (String(contentType)) {
      case "text/html": {
        return this.createScriptingDisabledDocument("html", contentType, string);
      }

      case "text/xml":
      case "application/xml":
      case "application/xhtml+xml":
      case "image/svg+xml": {
        try {
          return this.createScriptingDisabledDocument("xml", contentType, string);
        } catch (error) {
          const document = this.createScriptingDisabledDocument("xml", contentType);
          const element = document.createElementNS("http://www.mozilla.org/newlayout/xml/parsererror.xml", "parsererror");

          element.textContent = error.message;

          document.appendChild(element);
          return document;
        }
      }

      default:
        throw new TypeError("Invalid contentType");
    }
  }

  createScriptingDisabledDocument(parsingMode, contentType, string) {
    const document = Document.createImpl(this._globalObject, [], {
      options: {
        parsingMode,
        encoding: "UTF-8",
        contentType,
        readyState: "complete",
        scriptingDisabled: true
        // TODO: somehow set URL to active document's URL
      }
    });

    if (string !== undefined) {
      parseIntoDocument(string, document);
    }

    return document;
  }
};

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.72.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.72.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.71.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.70.2 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.70.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.70.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.69.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.68.2 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.68.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.68.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.67.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.67.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.66.2 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.66.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.66.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.65.1 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.65.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.64.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js
appmap-0.63.0 ./node_modules/jsdom/lib/jsdom/living/domparsing/DOMParser-impl.js