Skip to content

Commit 62b973e

Browse files
authored
fix: calling setMode just before destroy causes error reading getLength (#5727)
1 parent 73f9f17 commit 62b973e

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/edit_session.js

+3
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ class EditSession {
934934
// load on demand
935935
this.$modeId = path;
936936
config.loadModule(["mode", path], function(m) {
937+
if (this.destroyed) {
938+
return;
939+
}
937940
if (this.$modeId !== path)
938941
return cb && cb();
939942
if (this.$modes[path] && !options) {

src/edit_session_test.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,17 @@ module.exports = {
11251125
}
11261126
});
11271127
var session = new EditSession([]);
1128-
session.setMode("ace/mode/javascript");
1128+
1129+
var onChangeModeCallCount = 0;
1130+
var originalOnChangeMode = session.$onChangeMode;
1131+
1132+
// Create spy
1133+
session.$onChangeMode = function(...arguments) {
1134+
onChangeModeCallCount++;
1135+
originalOnChangeMode.apply(this, arguments);
1136+
};
1137+
1138+
session.setMode("ace/mode/javascript");
11291139
assert.equal(session.$modeId, "ace/mode/javascript");
11301140

11311141
var modeChangeCallbacks = 0;
@@ -1147,12 +1157,15 @@ module.exports = {
11471157
assert.equal(session.$mode.$id, "ace/mode/sh");
11481158
session.setMode("ace/mode/css");
11491159
assert.equal(session.$mode.$id, "ace/mode/sh");
1150-
// TODO this should not error
1151-
// session.destroy();
1160+
// destory session to check if the last mode which is being loaded is aborted or not
1161+
session.destroy();
11521162
setTimeout(function() {
1153-
next();
1163+
// check if last setmode is aborted due to destroy
1164+
assert.equal(onChangeModeCallCount, 4);
1165+
session.$onChangeMode = originalOnChangeMode;
1166+
next();
11541167
});
1155-
}, 0);
1168+
});
11561169
},
11571170

11581171
"test: sets destroyed flag when destroy called and tokenizer is never null": function() {

0 commit comments

Comments
 (0)