MCPcopy
hub / github.com/jsdom/jsdom / replaceData

Method replaceData

lib/jsdom/living/nodes/CharacterData-impl.js:67–110  ·  view source on GitHub ↗
(offset, count, data)

Source from the content-addressed store, hash-verified

65 // https://dom.spec.whatwg.org/#dom-characterdata-replacedata
66 // https://dom.spec.whatwg.org/#concept-cd-replace
67 replaceData(offset, count, data) {
68 const { length } = this;
69
70 if (offset > length) {
71 throw DOMException.create(this._globalObject, [
72 "The index is not in the allowed range.",
73 "IndexSizeError"
74 ]);
75 }
76
77 if (offset + count > length) {
78 count = length - offset;
79 }
80
81 queueMutationRecord(MUTATION_TYPE.CHARACTER_DATA, this, null, null, this._data, [], [], null, null);
82
83 const start = this._data.slice(0, offset);
84 const end = this._data.slice(offset + count);
85 this._data = start + data + end;
86
87 for (const range of this._liveRanges()) {
88 const { _start, _end } = range;
89
90 if (_start.node === this && _start.offset > offset && _start.offset <= offset + count) {
91 range._setLiveRangeStart(this, offset);
92 }
93
94 if (_end.node === this && _end.offset > offset && _end.offset <= offset + count) {
95 range._setLiveRangeEnd(this, offset);
96 }
97
98 if (_start.node === this && _start.offset > offset + count) {
99 range._setLiveRangeStart(this, _start.offset + data.length - count);
100 }
101
102 if (_end.node === this && _end.offset > offset + count) {
103 range._setLiveRangeEnd(this, _end.offset + data.length - count);
104 }
105 }
106
107 if (this.nodeType === TEXT_NODE && this.parentNode) {
108 this.parentNode._childTextContentChangeSteps();
109 }
110 }
111}
112
113mixin(CharacterDataImpl.prototype, NonDocumentTypeChildNodeImpl.prototype);

Callers 12

dataMethod · 0.95
appendDataMethod · 0.95
insertDataMethod · 0.95
deleteDataMethod · 0.95
splitTextMethod · 0.80
normalizeMethod · 0.80
nodeValueMethod · 0.80
textContentMethod · 0.80
deleteContentsMethod · 0.80
extractRangeFunction · 0.80
core.jsFile · 0.80
html.jsFile · 0.80

Calls 6

queueMutationRecordFunction · 0.85
sliceMethod · 0.80
_liveRangesMethod · 0.80
_setLiveRangeStartMethod · 0.80
_setLiveRangeEndMethod · 0.80

Tested by

no test coverage detected