array.insert throws length-exceeded event - fixes #314
This commit is contained in:
parent
89c5541ee6
commit
311dd50f1b
@ -679,6 +679,8 @@ export const typeListInsertGenericsAfter = (transaction, parent, referenceItem,
|
||||
packJsonContent()
|
||||
}
|
||||
|
||||
const lengthExceeded = error.create('Length exceeded!')
|
||||
|
||||
/**
|
||||
* @param {Transaction} transaction
|
||||
* @param {AbstractType<any>} parent
|
||||
@ -689,6 +691,9 @@ export const typeListInsertGenericsAfter = (transaction, parent, referenceItem,
|
||||
* @function
|
||||
*/
|
||||
export const typeListInsertGenerics = (transaction, parent, index, content) => {
|
||||
if (index > parent._length) {
|
||||
throw lengthExceeded
|
||||
}
|
||||
if (index === 0) {
|
||||
if (parent._searchMarker) {
|
||||
updateMarkerChanges(parent._searchMarker, index, content.length)
|
||||
@ -766,7 +771,7 @@ export const typeListDelete = (transaction, parent, index, length) => {
|
||||
n = n.right
|
||||
}
|
||||
if (length > 0) {
|
||||
throw error.create('array length exceeded')
|
||||
throw lengthExceeded
|
||||
}
|
||||
if (parent._searchMarker) {
|
||||
updateMarkerChanges(parent._searchMarker, startIndex, -startLength + length /* in case we remove the above exception */)
|
||||
|
@ -169,7 +169,7 @@ export class YXmlElement extends YXmlFragment {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
hasAttribute (attributeName) {
|
||||
hasAttribute (attributeName) {
|
||||
return /** @type {any} */ (typeMapHas(this, attributeName))
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,49 @@ export const testLengthIssue = tc => {
|
||||
t.assert(arr.length === arr.toArray().length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging yjs#314
|
||||
*
|
||||
* @param {t.TestCase} tc
|
||||
*/
|
||||
export const testLengthIssue2 = tc => {
|
||||
const doc = new Y.Doc()
|
||||
const next = doc.getArray()
|
||||
doc.transact(() => {
|
||||
next.insert(0, ['group2'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
next.insert(1, ['rectangle3'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
next.delete(0)
|
||||
next.insert(0, ['rectangle3'])
|
||||
})
|
||||
next.delete(1)
|
||||
doc.transact(() => {
|
||||
next.insert(1, ['ellipse4'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
next.insert(2, ['ellipse3'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
next.insert(3, ['ellipse2'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
doc.transact(() => {
|
||||
t.fails(() => {
|
||||
next.insert(5, ['rectangle2'])
|
||||
})
|
||||
next.insert(4, ['rectangle2'])
|
||||
})
|
||||
doc.transact(() => {
|
||||
// this should not throw an error message
|
||||
next.delete(4)
|
||||
})
|
||||
})
|
||||
console.log(next.toArray())
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {t.TestCase} tc
|
||||
*/
|
||||
|
@ -18,7 +18,7 @@ export const testSetProperty = tc => {
|
||||
/**
|
||||
* @param {t.TestCase} tc
|
||||
*/
|
||||
export const testHasProperty = tc => {
|
||||
export const testHasProperty = tc => {
|
||||
const { testConnector, users, xml0, xml1 } = init(tc, { users: 2 })
|
||||
xml0.setAttribute('height', '10')
|
||||
t.assert(xml0.hasAttribute('height'), 'Simple set+has works')
|
||||
|
Loading…
x
Reference in New Issue
Block a user