Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return missing in module #357

Open
nv08 opened this issue Oct 1, 2024 · 3 comments
Open

Return missing in module #357

nv08 opened this issue Oct 1, 2024 · 3 comments

Comments

@nv08
Copy link

nv08 commented Oct 1, 2024

function main() {
return 10;
}

main();

Where does the return exactly goes?

i was trying to get the result of return for this program

import add from "a.js";

function main() {
  const a = add(1, 2);
  console.log(a);
  return a;
}

main();

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?

@johnjg75dev
Copy link

What's the contents of the "a.js" file?

@nv08
Copy link
Author

nv08 commented Oct 5, 2024

What's the contents of the "a.js" file?

Simple add function which add two numbers and return output

@nv08
Copy link
Author

nv08 commented Nov 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants