mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-12 14:00:01 -04:00
suppress syscall errors in a better way
This commit is contained in:
parent
6fc1751ddb
commit
961ce1c37f
2 changed files with 7 additions and 23 deletions
|
@ -10,7 +10,7 @@ OUT_FILE="out/libcurl.js"
|
|||
EXPORTED_FUNCS="_main,_perform_request"
|
||||
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
|
||||
COMPILER_OPTIONS="-o $OUT_FILE -lcurl -lssl -lcrypto -lcjson -I $INCLUDE_DIR -L $LIB_DIR"
|
||||
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sWEBSOCKET_URL=wss://debug.ading.dev/ws -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS --preload-file $CACERT_FILE"
|
||||
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sWEBSOCKET_URL=wss://debug.ading.dev/ws -sSINGLE_FILE -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS --preload-file $CACERT_FILE"
|
||||
|
||||
if [ ! -f $CACERT_FILE ]; then
|
||||
wget "https://curl.se/ca/cacert.pem" -O $CACERT_FILE
|
||||
|
@ -18,8 +18,14 @@ fi
|
|||
|
||||
tools/all_deps.sh
|
||||
|
||||
rm -rf out
|
||||
mkdir -p out
|
||||
|
||||
COMPILE_CMD="emcc main.c $COMPILER_OPTIONS $EMSCRIPTEN_OPTIONS"
|
||||
echo $COMPILE_CMD
|
||||
$COMPILE_CMD
|
||||
|
||||
#patch the output to work around some emscripten bugs
|
||||
sed -i 's/err("__syscall_getsockname " \?+ \?fd);//' $OUT_FILE
|
||||
sed -i 's/function _emscripten_console_error(str) {/& if(UTF8ToString(str).endsWith("__syscall_setsockopt\\n")) return;/' $OUT_FILE
|
||||
mv out/libcurl.data ./
|
|
@ -79,27 +79,6 @@ function allocate_array(array) {
|
|||
return allocate(array, ALLOC_NORMAL);
|
||||
}
|
||||
|
||||
//make emscripten shut up about unsupported syscalls
|
||||
function silence_errs() {
|
||||
window._err = window.err;
|
||||
window.err = function() {
|
||||
let arg = arguments[0];
|
||||
if (is_str(arg) && arg.startsWith("__syscall_getsockname")) {
|
||||
return;
|
||||
}
|
||||
window._err(...arguments);
|
||||
}
|
||||
|
||||
window._console_error = window.console.error;
|
||||
window.console.error = function() {
|
||||
let arg = arguments[0];
|
||||
if (is_str(arg) && arg === "warning: unsupported syscall: __syscall_setsockopt\n") {
|
||||
return;
|
||||
}
|
||||
window._console_error(...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
//low level interface with c code
|
||||
function perform_request(url, params, js_data_callback, js_end_callback, body=null) {
|
||||
let params_str = JSON.stringify(params);
|
||||
|
@ -201,7 +180,6 @@ function libcurl_fetch(url, params={}) {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
silence_errs();
|
||||
console.log(await libcurl_fetch("https://httpbin.org/anything"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue