Blame view

lib/jsdom/living/nodes/ShadowRoot-impl.js 1.26 KB
858f2bdf5   Boyan Georgiev   fixes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  "use strict";
  
  const { parseFragment } = require("../../browser/parser");
  const { fragmentSerialization } = require("../domparsing/serialization.js");
  const { nodeRoot } = require("../helpers/node");
  const { mixin } = require("../../utils");
  
  const DocumentFragment = require("./DocumentFragment-impl").implementation;
  const DocumentOrShadowRootImpl = require("./DocumentOrShadowRoot-impl").implementation;
  
  class ShadowRootImpl extends DocumentFragment {
    constructor(globalObject, args, privateData) {
      super(globalObject, args, privateData);
  
      const { mode } = privateData;
      this._mode = mode;
    }
  
    _getTheParent(event) {
      if (!event.composed && this === nodeRoot(event._path[0].item)) {
        return null;
      }
  
      return this._host;
    }
  
    get mode() {
      return this._mode;
    }
  
    get host() {
      return this._host;
    }
  
    // https://w3c.github.io/DOM-Parsing/#dfn-innerhtml
    get innerHTML() {
      return fragmentSerialization(this, {
        requireWellFormed: true,
        globalObject: this._globalObject
      });
    }
    set innerHTML(markup) {
      const fragment = parseFragment(markup, this._host);
      this._replaceAll(fragment);
    }
  }
  
  mixin(ShadowRootImpl.prototype, DocumentOrShadowRootImpl.prototype);
  
  module.exports = {
    implementation: ShadowRootImpl
  };