-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlibrary.js
26 lines (24 loc) · 1.05 KB
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mergeInto(LibraryManager.library, {
js_output_result: function (symbol, data, polygon, polygon_size) {
// function provided by Emscripten to convert WASM heap string pointers to JS strings.
const Pointer_stringify = Module["UTF8ToString"];
// Note: new TypedArray(someBuffer) will create a new view onto the same memory chunk,
// while new TypedArray(someTypedArray) will copy the data so the original can be freed.
const resultView = new Int32Array(
Module.HEAP32.buffer,
polygon,
polygon_size * 2
);
const coordinates = new Int32Array(resultView);
// call the downstream processing function that should have been set by the client code
const downstreamProcessor = Module["processResult"];
if (downstreamProcessor == null) {
throw new Error("No downstream processing function set");
}
downstreamProcessor(
Pointer_stringify(symbol),
Pointer_stringify(data),
coordinates
);
}
});