File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -934,6 +934,9 @@ class EditSession {
934
934
// load on demand
935
935
this . $modeId = path ;
936
936
config . loadModule ( [ "mode" , path ] , function ( m ) {
937
+ if ( this . destroyed ) {
938
+ return ;
939
+ }
937
940
if ( this . $modeId !== path )
938
941
return cb && cb ( ) ;
939
942
if ( this . $modes [ path ] && ! options ) {
Original file line number Diff line number Diff line change @@ -1125,7 +1125,17 @@ module.exports = {
1125
1125
}
1126
1126
} ) ;
1127
1127
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" ) ;
1129
1139
assert . equal ( session . $modeId , "ace/mode/javascript" ) ;
1130
1140
1131
1141
var modeChangeCallbacks = 0 ;
@@ -1147,12 +1157,15 @@ module.exports = {
1147
1157
assert . equal ( session . $mode . $id , "ace/mode/sh" ) ;
1148
1158
session . setMode ( "ace/mode/css" ) ;
1149
1159
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 ( ) ;
1152
1162
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 ( ) ;
1154
1167
} ) ;
1155
- } , 0 ) ;
1168
+ } ) ;
1156
1169
} ,
1157
1170
1158
1171
"test: sets destroyed flag when destroy called and tokenizer is never null" : function ( ) {
You can’t perform that action at this time.
0 commit comments