You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a test to ensure that the modularization works correctly.
Since we are doing our own modularization rather than relying upon emcc, we have to do a workaround to undo its attempts at exporting the SqlJs Module.
// This module exports a promise that loads and resolves to the actual sql.js module.
4
+
// In addition, When you use emcc's modularization, it still expects to export a global object called `Module`,
5
+
// which is able to be used/called before the WASM is loaded.
6
+
// The modularization below exports a promise that loads and resolves to the actual sql.js module.
5
7
// That way, this module can't be used before the WASM is finished loading.
6
8
7
-
8
-
// So the first thing that this module does is define a place for the loadedModule to reside
9
-
10
9
// We are going to define a function that a user will call to start loading initializing our Sql.js library
11
-
// However, that function might be called multiple times, and on subsequent calls, we want it to return the same module that it's already loaded once before.
10
+
// However, that function might be called multiple times, and on subsequent calls, we don't actually want it to instantiate a new instance of the Module
11
+
// Instead, we want to return the previously loaded module
12
12
13
+
// TODO: Make this not declare a global if used in the browser
13
14
varinitSqlJsPromise=undefined;
14
15
15
16
varinitSqlJs=function(moduleConfig){
@@ -18,7 +19,7 @@ var initSqlJs = function (moduleConfig) {
18
19
returninitSqlJsPromise;
19
20
}
20
21
// If we're here, we've never called this function before
assert.equal(SQL,sqlModule1,"Initializing the module multiple times only creates it once");
15
+
assert.equal(sqlModule1,sqlModule2,"Initializing the module multiple times only creates it once");
16
+
vardb1=newsqlModule1.Database();
17
+
assert.equal(Object.getPrototypeOf(db1),SQL.Database.prototype,"sqlModule1 has a Database object that has the same prototype as the originally loaded SQL module");
18
+
assert.equal(Object.getPrototypeOf(db1),sqlModule2.Database.prototype,"sqlModule1 has a Database object that has the same prototype as the sqlModule2");
19
+
20
+
21
+
vardb2=newsqlModule2.Database();
22
+
assert.equal(Object.getPrototypeOf(db2),sqlModule1.Database.prototype,"sqlModule2 has a Database object that has the same prototype as the sqlModule1");
23
+
24
+
done();
25
+
});
26
+
});
27
+
};
28
+
29
+
if(module==require.main){
30
+
consttargetFile=process.argv[2];
31
+
constloadSqlLib=require('./load_sql_lib');
32
+
loadSqlLib(targetFile).then((sql)=>{
33
+
require('test').run({
34
+
'test modularization': function(assert,done){
35
+
// TODO: Dry this up so that this code isn't duped between here and load_sql_lib.js
0 commit comments