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

Fix uncatchable error inside a promise (#810) #811

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laishere
Copy link
Contributor

Fix issue #810

quickjs.c Show resolved Hide resolved
quickjs.c Show resolved Hide resolved
quickjs.c Outdated Show resolved Hide resolved
@saghul
Copy link
Contributor

saghul commented Jan 10, 2025

It would be good to have a test for this.

@laishere
Copy link
Contributor Author

How to run all the tests? @saghul

I just ran

run-test262.exe tests.conf

Result: 0/29 errors, 3 excluded

Cannot run test262.conf.

BTW, I should add my test.js to tests directory right?

@saghul
Copy link
Contributor

saghul commented Jan 10, 2025

This wouldn't be a 262 test, so yeah adding it to the tests/ directory is the way.

@laishere
Copy link
Contributor Author

laishere commented Jan 10, 2025

I just realized that we need an interrupt handler to test it. So I can't do it in pure js. So would need a separate test or modify run-test262.c

@saghul
Copy link
Contributor

saghul commented Jan 10, 2025

Yes it would likely need to be its own C file with the simplified test.

@laishere
Copy link
Contributor Author

Should I add Makefile and CMakeLists.txt target for this test? @saghul

@saghul
Copy link
Contributor

saghul commented Jan 10, 2025

CMake should be the only requirement, since it shouldn't have EXCLUDE_FROM_ALL

@saghul
Copy link
Contributor

saghul commented Jan 17, 2025

Looking good! Can you pl run the test from the CI files? Building it won't make it run.

@laishere
Copy link
Contributor Author

Sure!

@laishere
Copy link
Contributor Author

Updated.

@saghul
Copy link
Contributor

saghul commented Jan 17, 2025

Can you please add it to (some of) the windows targets?

@laishere
Copy link
Contributor Author

No problem, I am working on it now!

@laishere
Copy link
Contributor Author

Updated.

Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM nice work! @bnoordhuis can you have a quick look?

return *time > MAX_TIME;
}

static void sync_call()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void sync_call()
static void sync_call(void)

In C before C23, () means a function taking zero or more arguments.

In C23, () means zero arguments - but quickjs is a C11 project so that doesn't apply.

JS_FreeRuntime(rt);
}

static void async_call()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void async_call()
static void async_call(void)

Comment on lines +18025 to 18026
ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
1, &error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
1, &error);
ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
1, &error);

Although you can also fit it on one line (fits in 80 columns):

Suggested change
ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED,
1, &error);
ret2 = JS_Call(ctx, s->resolving_funcs[1], JS_UNDEFINED, 1, &error);

if (JS_IsUncatchableError(ctx, ctx->rt->current_exception)) {
is_success = false;
} else {
abort(); /* BUG */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't abort here. Resolving functions can fail in (at least but not restricted to) out-of-memory or stack overflow conditions, and those are catchable exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be no catchable exception return here.
If the exception can be caught, then it must be handled by the resolving functions.
Which means JS_GetException must be called first in order to pass it to try-catch or .catch().
If JS_GetException is called, there's no reason for it to still return JS_EXCEPTION as the exception is free.

And I tested the stack overflow inside a promise/async, it's caught as expected, abort() is never triggered.
I prefer to treat it as a bug here. But if abort is not the appropriate way to do this, I will remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, in the specific case of js_async_function_resume it's probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, then I will let it be. Will update the code tomorrow.

Comment on lines +18104 to +18106
if (!js_async_function_resume(ctx, s)) {
return JS_EXCEPTION;
}
Copy link
Contributor

@bnoordhuis bnoordhuis Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH seems to have swallowed my last review comment... I was saying that single-statement if statements (ones without an else clause) usually omit the braces:

Suggested change
if (!js_async_function_resume(ctx, s)) {
return JS_EXCEPTION;
}
if (!js_async_function_resume(ctx, s))
return JS_EXCEPTION;

edit: applies here and below

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

Successfully merging this pull request may close these issues.

3 participants