quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Revert "Add `JS_HasException()` (#265)"

Open bellard opened this issue 1 year ago • 7 comments

This reverts commit db9dbd0a2b6d115c9ef3c0dc37e0c669ef4844e4.

bellard avatar May 30 '24 12:05 bellard

This patch is not correct because "null" is a valid exception. Currently, the only way to test an exception is to test if JS_EXCEPTION is returned. The content of "current_exception" is undefined otherwise.

bellard avatar May 30 '24 12:05 bellard

Would it be reasonable to make the contents of current_exception defined at all times so one can actually test for pending exceptions?

kasperisager avatar May 30 '24 13:05 kasperisager

null is a valid exception, so testing for JS_NULL is not correct even if current_exception is defined all the time (try throw null). We may initialize it to JS_UNINITIALIZED instead.

bellard avatar May 30 '24 13:05 bellard

That's an awfully good point! Initialising it to JS_UNINITIALIZED instead and letting that mean "no pending exception" sounds like a plan, I can put together a PR.

kasperisager avatar May 30 '24 14:05 kasperisager

That's an awfully good point! Initialising it to JS_UNINITIALIZED instead and letting that mean "no pending exception" sounds like a plan, I can put together a PR.

Using JS_UNINITIALIZED is indeed a clever way to allow for any valid value to be thrown.

chqrlie avatar May 30 '24 14:05 chqrlie

@chqrlie Isn't JS_UNDEFINED it's own thing?

kasperisager avatar May 30 '24 14:05 kasperisager

@chqrlie Isn't JS_UNDEFINED it's own thing?

Yes, I was confused in my earlier comment. JS_UNDEFINED and JS_UNINITIALIZED are different types, JS_UNINITALIZED is used for special let semantics and is a perfect solution for the issue at stake here.

chqrlie avatar May 31 '24 15:05 chqrlie