Skip to content

Commit 5fe8d1a

Browse files
authored
Merge pull request #27 from ansbbrooks/fix/wasm-config-print-printerr-1
Ensure `config.print()` and `config.printErr()` are properly applied to to `emscriptenConfig`
2 parents a7f40e9 + 01c25b3 commit 5fe8d1a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/core/configManager.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,33 @@ export function createEmscriptenConfig(config, wasmFile) {
8282
},
8383
...userPreRun];
8484
}
85+
{
86+
const print = config?.print;
87+
if (print != null) {
88+
if (typeof print !== 'function') {
89+
throw new Error(`config.print must be a function, if provided`);
90+
}
91+
// Wrap the user-provided config.print() function in another
92+
// function to ensure that we control the function signature
93+
// that is provided to the final emscriptenConfig object.
94+
emscriptenConfig.print = (text) => {
95+
print(text);
96+
};
97+
}
98+
}
99+
{
100+
const printErr = config?.printErr;
101+
if (printErr != null) {
102+
if (typeof printErr !== 'function') {
103+
throw new Error(`config.printErr must be a function, if provided`);
104+
}
105+
// Wrap the user-provided config.printErr() function in another
106+
// function to ensure that we control the function signature
107+
// that is provided to the final emscriptenConfig object.
108+
emscriptenConfig.printErr = (text) => {
109+
printErr(text);
110+
};
111+
}
112+
}
85113
return emscriptenConfig;
86114
}

0 commit comments

Comments
 (0)