Skip to content

Commit 5531753

Browse files
committed
Update prototype and tests with v0.8
1 parent 908f85d commit 5531753

File tree

6 files changed

+22016
-15140
lines changed

6 files changed

+22016
-15140
lines changed

tests/prototype/libzim-asm.dev.js

Lines changed: 21956 additions & 15110 deletions
Large diffs are not rendered by default.

tests/prototype/libzim-asm.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/prototype/libzim-wasm.dev.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@ var Module = typeof Module != 'undefined' ? Module : {};
1616

1717
// --pre-jses are emitted after the Module integration code, so that they can
1818
// refer to Module (if they choose; they can also define Module)
19+
/**
20+
* Web Worker API for libzim JavaScript bindings
21+
*
22+
* This file provides the pre-JS portion of the web worker that handles ZIM file operations.
23+
* It is concatenated with postjs_file_api.js during the Emscripten build process (see Makefile)
24+
* to create a complete web worker script that can be used with WebAssembly or asm.js builds.
25+
*
26+
* Supported actions: getEntryByPath, search, suggest, getArticleCount, init
27+
*/
28+
1929
self.addEventListener('message', function(e) {
2030
var action = e.data.action;
2131
var path = e.data.path;
2232
var outgoingMessagePort = e.ports[0];
2333
console.debug('WebWorker called with action=' + action);
34+
35+
// Retrieve content from ZIM archive by path
2436
if (action === 'getEntryByPath') {
2537
var follow = e.data.follow;
2638
var entry = Module[action](path);
@@ -43,7 +55,8 @@ self.addEventListener('message', function(e) {
4355
else {
4456
outgoingMessagePort.postMessage({ content: new Uint8Array(), mimetype: 'unknown', isRedirect: false});
4557
}
46-
}
58+
}
59+
// Full-text search across ZIM archive content
4760
else if (action === 'search') {
4861
var text = e.data.text;
4962
var numResults = e.data.numResults || 50;
@@ -55,11 +68,26 @@ self.addEventListener('message', function(e) {
5568
serializedEntries.push({path: entry.getPath()});
5669
}
5770
outgoingMessagePort.postMessage({ entries: serializedEntries });
58-
}
71+
}
72+
// Title-based suggestions for autocomplete (faster than full-text search)
73+
else if (action === 'suggest') {
74+
var text = e.data.text;
75+
var numResults = e.data.numResults || 10;
76+
var suggestions = Module[action](text, numResults);
77+
console.debug('Found nb suggestions = ' + suggestions.size(), suggestions);
78+
var serializedSuggestions = [];
79+
for (var i=0; i<suggestions.size(); i++) {
80+
var entry = suggestions.get(i);
81+
serializedSuggestions.push({path: entry.getPath(), title: entry.getTitle()});
82+
}
83+
outgoingMessagePort.postMessage({ suggestions: serializedSuggestions });
84+
}
85+
// Get total number of articles in the ZIM archive
5986
else if (action === 'getArticleCount') {
6087
var articleCount = Module[action]();
6188
outgoingMessagePort.postMessage(articleCount);
62-
}
89+
}
90+
// Initialize the ZIM archive with file system mounting
6391
else if (action === 'init') {
6492
var files = e.data.files;
6593
var assemblerType = e.data.assemblerType || 'runtime';
@@ -75,6 +103,7 @@ self.addEventListener('message', function(e) {
75103
for (let i = 0; i < files.length; i++) {
76104
Module['arguments'].push('/work/' + files[i].name);
77105
}
106+
// Mount file system for ZIM file access (Electron vs browser environments)
78107
Module['preRun'] = function() {
79108
FS.mkdir('/work');
80109
if (files[0].readMode === 'electron') {
@@ -91,6 +120,9 @@ self.addEventListener('message', function(e) {
91120
console.debug('baseZimFileName = ' + baseZimFileName);
92121
console.debug("Module['arguments'] = " + Module['arguments']);
93122

123+
// File continues in postjs_file_api.js - handles invalid actions and closes the event listener
124+
// Between prejs and postjs: Emscripten injects the compiled WebAssembly/asm.js Module code and bindings
125+
94126

95127
// Sometimes an existing Module object exists with properties
96128
// meant to overwrite the default module functionality. Here
@@ -7445,21 +7477,21 @@ function invoke_viii(index,a1,a2,a3) {
74457477
}
74467478
}
74477479

7448-
function invoke_ii(index,a1) {
7480+
function invoke_v(index) {
74497481
var sp = stackSave();
74507482
try {
7451-
return getWasmTableEntry(index)(a1);
7483+
getWasmTableEntry(index)();
74527484
} catch(e) {
74537485
stackRestore(sp);
74547486
if (!(e instanceof EmscriptenEH)) throw e;
74557487
_setThrew(1, 0);
74567488
}
74577489
}
74587490

7459-
function invoke_v(index) {
7491+
function invoke_ii(index,a1) {
74607492
var sp = stackSave();
74617493
try {
7462-
getWasmTableEntry(index)();
7494+
return getWasmTableEntry(index)(a1);
74637495
} catch(e) {
74647496
stackRestore(sp);
74657497
if (!(e instanceof EmscriptenEH)) throw e;
@@ -8611,12 +8643,10 @@ run();
86118643

86128644
// end include: postamble.js
86138645
// include: /src/postjs_file_api.js
8614-
}
8615-
else {
8646+
} else {
86168647
console.error('Invalid action: ' + action);
86178648
outgoingMessagePort.postMessage('invalid action');
86188649
}
8619-
},false);
8620-
8650+
}, false);
86218651

86228652
// end include: /src/postjs_file_api.js

tests/prototype/libzim-wasm.dev.wasm

132 KB
Binary file not shown.

tests/prototype/libzim-wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/prototype/libzim-wasm.wasm

24.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)