From b5064a4bb38e24fdd74e1e4899f33b83e70fe1bc Mon Sep 17 00:00:00 2001 From: Scott Glajch Date: Wed, 25 Feb 2015 13:00:39 -0500 Subject: [PATCH 1/2] Fix for issue #2374, maximum call stack exceeded in 64 bit chrome when pasting large chunks. --- lib/ace/document.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 10a36eb2..0214b38b 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -311,11 +311,12 @@ var Document = function(text) { if (lines.length == 0) return {row: row, column: 0}; - // apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF) - // to circumvent that we have to break huge inserts into smaller chunks here - while (lines.length > 0xF000) { - var end = this._insertLines(row, lines.slice(0, 0xF000)); - lines = lines.slice(0xF000); + // Apply doesn't work for big arrays due to max call stack detection. + // Chrome 64 bit requires threshold smaller than 32k, using a safe value of 1k. + // To circumvent that we have to break huge inserts into smaller chunks here. + while (lines.length > 1000) { + var end = this._insertLines(row, lines.slice(0, 1000)); + lines = lines.slice(1000); row = end.row; } From de9e5226bfa9a101f2c3f6eb76f21722a6e6768b Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 28 Feb 2015 22:16:19 +0400 Subject: [PATCH 2/2] add tests from v1.2 branch and increase split size to improve performance --- lib/ace/document.js | 8 ++++---- lib/ace/document_test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 0214b38b..2e6e5db3 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -312,11 +312,11 @@ var Document = function(text) { return {row: row, column: 0}; // Apply doesn't work for big arrays due to max call stack detection. - // Chrome 64 bit requires threshold smaller than 32k, using a safe value of 1k. + // Chrome 64 bit requires threshold smaller than 32k, using a safe value of 20k. // To circumvent that we have to break huge inserts into smaller chunks here. - while (lines.length > 1000) { - var end = this._insertLines(row, lines.slice(0, 1000)); - lines = lines.slice(1000); + while (lines.length > 20000) { + var end = this._insertLines(row, lines.slice(0, 20000)); + lines = lines.slice(20000); row = end.row; } diff --git a/lib/ace/document_test.js b/lib/ace/document_test.js index 5c324db0..051434b4 100644 --- a/lib/ace/document_test.js +++ b/lib/ace/document_test.js @@ -296,6 +296,35 @@ module.exports = { "test: empty document has to contain one line": function() { var doc = new Document(""); assert.equal(doc.$lines.length, 1); + }, + + "test: ignore empty delta": function() { + var doc = new Document(""); + doc.on("change", function() { + throw "should ignore empty delta"; + }) + doc.insert({row: 0, column: 0}, ""); + doc.insert({row: 1, column: 1}, ""); + doc.remove({start: {row: 1, column: 1}, end: {row: 1, column: 1}}); + }, + + "test: inserting huge delta": function() { + var doc = new Document(""); + var val = ""; + var MAX = 0xF000; + for (var i = 0; i < 10 * MAX; i++) { + val += i + "\n" + } + doc.setValue(val); + assert.equal(doc.getValue(), val); + + for (var i = 3 * MAX + 2; i >= 3 * MAX - 2; i--) { + val = doc.getLines(0, i).join("\n"); + doc.setValue("\nab"); + assert.equal(doc.getValue(), "\nab"); + doc.insert({row: 1, column: 1}, val); + assert.equal(doc.getValue(), "\na" + val + "b"); + } } };