Open nv08 opened 1 month ago
What's the contents of the "a.js" file?
What's the contents of the "a.js" file?
Simple add function which add two numbers and return output
static int eval_buf(JSContext ctx, const void buf, int buf_len, const char *filename, int eval_flags) { JSValue val; int ret;
if ((eval_flags & JS_EVAL_TYPE_MASK) == JS_EVAL_TYPE_MODULE) {
/* for the modules, we compile then run to be able to set
import.meta */
val = JS_Eval(ctx, buf, buf_len, filename,
eval_flags | JS_EVAL_FLAG_COMPILE_ONLY);
if (!JS_IsException(val)) {
js_module_set_import_meta(ctx, val, TRUE, TRUE);
val = JS_EvalFunction(ctx, val);
}
val = js_std_await(ctx, val);
} else {
val = JS_Eval(ctx, buf, buf_len, filename, eval_flags);
}
if (JS_IsException(val)) {
js_std_dump_error(ctx);
ret = -1;
} else {
ret = 0;
}
JS_FreeValue(ctx, val);
return ret;
}
using this eval_buf, for non_module it works and returns as expected but for module (.js using import statements) it doesn't returns anything @johnjg75dev @ctn-malone
function main() { return 10; }
main();
Where does the return exactly goes?
i was trying to get the result of return for this program
using jS_EVAL -> JS_EVAL_FUNCTION -> JS_STD_AWAIT after these i get "undefined" in value. Am i missing anything or its the default behaviour?