File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -883,6 +883,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
883
883
* memory consumption will grow forever
884
884
*/
885
885
Database . prototype [ "close" ] = function close ( ) {
886
+ // do nothing if db is null or already closed
887
+ if ( this . db === null ) {
888
+ return ;
889
+ }
886
890
Object . values ( this . statements ) . forEach ( function each ( stmt ) {
887
891
stmt [ "free" ] ( ) ;
888
892
} ) ;
Original file line number Diff line number Diff line change @@ -63,7 +63,12 @@ function onModuleReady(SQL) {
63
63
return postMessage ( result ) ;
64
64
}
65
65
case "close" :
66
- return db && db . close ( ) ;
66
+ if ( db ) {
67
+ db . close ( ) ;
68
+ }
69
+ return postMessage ( {
70
+ id : data [ "id" ]
71
+ } ) ;
67
72
default :
68
73
throw new Error ( "Invalid action : " + ( data && data [ "action" ] ) ) ;
69
74
}
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ exports.test = async function test(SQL, assert) {
91
91
var actual = "" ;
92
92
for ( let i = 0 ; i < header . length ; i ++ ) actual += String . fromCharCode ( data . buffer [ i ] ) ;
93
93
assert . equal ( actual , header , 'Data returned is an SQLite database file' ) ;
94
+
95
+ // test worker properly opens db after closing
96
+ await worker . postMessage ( { action : "close" } ) ;
97
+ await worker . postMessage ( { action : "open" } ) ;
98
+ data = await worker . postMessage ( { action : "exec" , sql : "SELECT 1" } ) ;
99
+ assert . deepEqual ( data . results , [ { "columns" :[ "1" ] , "values" :[ [ 1 ] ] } ] ) ;
94
100
}
95
101
96
102
function obj2array ( obj ) {
You can’t perform that action at this time.
0 commit comments