Skip to content

Commit

Permalink
fix: calling setMode just before destroy causes error reading getLeng…
Browse files Browse the repository at this point in the history
…th (#5727)
  • Loading branch information
nlujjawal authored Jan 28, 2025
1 parent 73f9f17 commit 62b973e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/edit_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ class EditSession {
// load on demand
this.$modeId = path;
config.loadModule(["mode", path], function(m) {
if (this.destroyed) {
return;
}
if (this.$modeId !== path)
return cb && cb();
if (this.$modes[path] && !options) {
Expand Down
23 changes: 18 additions & 5 deletions src/edit_session_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,17 @@ module.exports = {
}
});
var session = new EditSession([]);
session.setMode("ace/mode/javascript");

var onChangeModeCallCount = 0;
var originalOnChangeMode = session.$onChangeMode;

// Create spy
session.$onChangeMode = function(...arguments) {
onChangeModeCallCount++;
originalOnChangeMode.apply(this, arguments);
};

session.setMode("ace/mode/javascript");
assert.equal(session.$modeId, "ace/mode/javascript");

var modeChangeCallbacks = 0;
Expand All @@ -1147,12 +1157,15 @@ module.exports = {
assert.equal(session.$mode.$id, "ace/mode/sh");
session.setMode("ace/mode/css");
assert.equal(session.$mode.$id, "ace/mode/sh");
// TODO this should not error
// session.destroy();
// destory session to check if the last mode which is being loaded is aborted or not
session.destroy();
setTimeout(function() {
next();
// check if last setmode is aborted due to destroy
assert.equal(onChangeModeCallCount, 4);
session.$onChangeMode = originalOnChangeMode;
next();
});
}, 0);
});
},

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

0 comments on commit 62b973e

Please sign in to comment.