File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -883,6 +883,10 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() {
883883 * memory consumption will grow forever
884884 */
885885 Database . prototype [ "close" ] = function close ( ) {
886+ // do nothing if db is null or already closed
887+ if ( this . db === null ) {
888+ return ;
889+ }
886890 Object . values ( this . statements ) . forEach ( function each ( stmt ) {
887891 stmt [ "free" ] ( ) ;
888892 } ) ;
Original file line number Diff line number Diff line change @@ -63,7 +63,12 @@ function onModuleReady(SQL) {
6363 return postMessage ( result ) ;
6464 }
6565 case "close" :
66- return db && db . close ( ) ;
66+ if ( db ) {
67+ db . close ( ) ;
68+ }
69+ return postMessage ( {
70+ id : data [ "id" ]
71+ } ) ;
6772 default :
6873 throw new Error ( "Invalid action : " + ( data && data [ "action" ] ) ) ;
6974 }
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ exports.test = async function test(SQL, assert) {
9191 var actual = "" ;
9292 for ( let i = 0 ; i < header . length ; i ++ ) actual += String . fromCharCode ( data . buffer [ i ] ) ;
9393 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 ] ] } ] ) ;
94100}
95101
96102function obj2array ( obj ) {
You can’t perform that action at this time.
0 commit comments