Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(js): Use WASM to fix unresolved memBuffer file #359

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ js-test:
build/js/infomap.worker.js: $(SOURCES) $(PRE_WORKER_MODULE)
@echo "Compiling Infomap to run in a worker in the browser..."
@mkdir -p $(dir $@)
em++ -std=c++14 -O3 -s WASM=0 -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ENVIRONMENT=worker --pre-js $(PRE_WORKER_MODULE) -o build/js/$(WORKER_FILENAME) $(SOURCES)
em++ -std=c++14 -O3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ENVIRONMENT=worker --pre-js $(PRE_WORKER_MODULE) -o build/js/$(WORKER_FILENAME) $(SOURCES)

js-clean:
$(RM) -r build/js interfaces/js/src/worker index.js *.d.ts README.md
Expand Down
14 changes: 0 additions & 14 deletions interfaces/js/pre-worker-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ function readFile(filename) {

let outName = "Untitled";

let memoryHackRequest = {
status: 200,
useRequest: null,
addEventListener: function (event, callback) {
if (event === "load") {
this.useRequest = callback;
}
},
};

var Module = {
arguments: [],
preRun: function () {
Expand Down Expand Up @@ -72,14 +62,10 @@ var Module = {
};
postMessage({ type: "finished", content });
},
memoryInitializerRequest: memoryHackRequest,
};

onmessage = function onmessage(message) {
const data = message.data;

memoryHackRequest.response = data.memBuffer;
memoryHackRequest.useRequest();
outName = data.outName;
Module.arguments.push(...[data.filename, ".", ...data.arguments]);
FS.writeFile(data.filename, data.network);
Expand Down
3 changes: 0 additions & 3 deletions interfaces/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import fileToString, {
import networkToString, { NetworkTypes } from "./network";
// @ts-ignore
import InfomapWorker from "./worker/infomap.worker.js";
// @ts-ignore
import MemFile from "./worker/infomap.worker.js.mem";

export interface Changelog {
body: string | null;
Expand Down Expand Up @@ -194,7 +192,6 @@ class Infomap {
this.workers[id] = worker;

worker.postMessage({
memBuffer: new Uint8Array(MemFile),
arguments: args.split(" "),
filename,
network,
Expand Down
Loading