Sha256: 2fb8cdeb2891322700888ee7c891ac8462bc32399ea6c3c9996d79bb084b235b

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

"use strict";

const idlUtils = require("../generated/utils");
const NodeImpl = require("./Node-impl").implementation;
const ChildNodeImpl = require("./ChildNode-impl").implementation;
const NonDocumentTypeChildNodeImpl = require("./NonDocumentTypeChildNode-impl").implementation;
const DOMException = require("../../web-idl/DOMException");

class CharacterDataImpl extends NodeImpl {
  constructor(args, privateData) {
    super(args, privateData);

    this._data = privateData.data;
  }

  get data() {
    return this._data;
  }
  set data(data) {
    this._data = data;
  }

  get length() {
    return this._data.length;
  }

  substringData(offset, count) {
    const length = this.length;

    if (offset > length) {
      throw new DOMException(DOMException.INDEX_SIZE_ERR);
    }

    if (offset + count > length) {
      return this._data.substring(offset);
    }

    return this._data.substring(offset, offset + count);
  }

  appendData(data) {
    this.replaceData(this.length, 0, data);
  }

  insertData(offset, data) {
    this.replaceData(offset, 0, data);
  }

  deleteData(offset, count) {
    this.replaceData(offset, count, "");
  }

  replaceData(offset, count, data) {
    const length = this.length;

    if (offset > length) {
      throw new DOMException(DOMException.INDEX_SIZE_ERR);
    }

    if (offset + count > length) {
      count = length - offset;
    }

    const start = this._data.substring(0, offset);
    const end = this._data.substring(offset + count);

    this._data = start + data + end;

    // TODO: range stuff
  }
}

idlUtils.mixin(CharacterDataImpl.prototype, NonDocumentTypeChildNodeImpl.prototype);
idlUtils.mixin(CharacterDataImpl.prototype, ChildNodeImpl.prototype);

module.exports = {
  implementation: CharacterDataImpl
};

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/jsdom/lib/jsdom/living/nodes/CharacterData-impl.js
lanes-0.8.0 node_modules/jsdom/lib/jsdom/living/nodes/CharacterData-impl.js
select_all-rails-0.3.1 node_modules/jsdom/lib/jsdom/living/nodes/CharacterData-impl.js