In my WebAssembly code, compiled using the WebIDL approach, I have defined an int type function in the main module and exported it to JavaScript. Inside this int type function, I have implemented conditional logic using 'if else' statements as follows:
int MainModule::testDebug(int n) {
if (n == 8 || n == 16) {
return n;
}
else if ((emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true) &&
n == 2 &&
(emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true)
) {
(emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true)
return n;
}
}
After compiling this code to WebAssembly, I noticed that when I pass the value 4 as an argument, it appears to be assigned the value 2 within the 'else if' block, causing the program to execute the logic within that block. This behavior seems unexpected and might be indicative of a potential bug.
The resulting output of the given sample code is '4 2 2,' whereas the expected output should have been '4.' This discrepancy occurs because the conditional statement terminates when 'n == 2,' as intended.
In my WebAssembly code, compiled using the WebIDL approach, I have defined an int type function in the main module and exported it to JavaScript. Inside this int type function, I have implemented conditional logic using 'if else' statements as follows:
int MainModule::testDebug(int n) { if (n == 8 || n == 16) { return n; } else if ((emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true) && n == 2 && (emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true) ) { (emscripten_log(EM_LOG_CONSOLE, "number: %d", n), true) return n; } }
After compiling this code to WebAssembly, I noticed that when I pass the value 4 as an argument, it appears to be assigned the value 2 within the 'else if' block, causing the program to execute the logic within that block. This behavior seems unexpected and might be indicative of a potential bug.
The resulting output of the given sample code is '4 2 2,' whereas the expected output should have been '4.' This discrepancy occurs because the conditional statement terminates when 'n == 2,' as intended.