Skip to content

Commit e8a13ae

Browse files
authored
Use empty object as initial JS library. NFC (#16957)
This minor refactoring mans that library.js and library_bootstrap.js are less special and allows libraries other than `library.js` to be processed first (something I wanted to try in another PR).
1 parent dd59daa commit e8a13ae

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/library.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// object. For convenience, the short name appears here. Note that if you add a
2121
// new function with an '_', it will not be found.
2222

23-
LibraryManager.library = {
23+
mergeInto(LibraryManager.library, {
2424
// ==========================================================================
2525
// getTempRet0/setTempRet0: scratch space handling i64 return
2626
//
@@ -3587,7 +3587,7 @@ LibraryManager.library = {
35873587
__c_longjmp_import: true,
35883588
#endif
35893589
#endif
3590-
};
3590+
});
35913591

35923592
function autoAddDeps(object, name) {
35933593
for (var item in object) {

src/library_bootstrap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
assert(false, "library_bootstrap.js only designed for use with BOOTSTRAPPING_STRUCT_INFO")
1212
#endif
1313

14-
assert(!LibraryManager.library);
15-
LibraryManager.library = {
14+
assert(Object.keys(LibraryManager.library).length === 0);
15+
mergeInto(LibraryManager.library, {
1616
$callRuntimeCallbacks: function() {},
1717
$handleException: function(e) { if (!e instanceof ExitStatus && !e == 'unwind') throw e; },
18-
};
18+
});

src/modules.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function genArgSequence(n) {
2121
global.libraryFunctions = [];
2222

2323
global.LibraryManager = {
24-
library: null,
24+
library: {},
2525
structs: {},
2626
loaded: false,
2727
libraries: [],
@@ -31,7 +31,8 @@ global.LibraryManager = {
3131
},
3232

3333
load: function() {
34-
if (this.library) return;
34+
assert(!this.loaded);
35+
this.loaded = true;
3536

3637
// Core system libraries (always linked against)
3738
let libraries = [
@@ -302,8 +303,6 @@ global.LibraryManager = {
302303
}
303304
}
304305
}
305-
306-
this.loaded = true;
307306
},
308307
};
309308

0 commit comments

Comments
 (0)