Skip to content

Split main promise event filter into multiple filters #4792

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

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/02.API-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,11 @@ described in [jerry_promise_event_type_t](#jerry_promise_event_type_t).
Possible values:

- JERRY_PROMISE_EVENT_FILTER_DISABLE - Disable reporting of all events.
- JERRY_PROMISE_EVENT_FILTER_MAIN - Enables the following events:
- JERRY_PROMISE_EVENT_FILTER_CREATE - Enables the following event:
- JERRY_PROMISE_EVENT_CREATE
- JERRY_PROMISE_EVENT_FILTER_RESOLVE - Enables the following event:
- JERRY_PROMISE_EVENT_RESOLVE
- JERRY_PROMISE_EVENT_FILTER_REJECT - Enables the following event:
- JERRY_PROMISE_EVENT_REJECT
- JERRY_PROMISE_EVENT_FILTER_ERROR - Enables the following events:
- JERRY_PROMISE_EVENT_RESOLVE_FULFILLED
Expand Down Expand Up @@ -6152,7 +6154,7 @@ main (void)
{
jerry_init (JERRY_INIT_EMPTY);

jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_MAIN, promise_callback, NULL);
jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_CREATE, promise_callback, NULL);

const char *source_p = "var p = Promise.resolve(0)\n"
"p.then(function (v) { return v; })";
Expand Down
6 changes: 3 additions & 3 deletions jerry-core/ecma/operations/ecma-promise-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ecma_reject_promise (ecma_value_t promise, /**< promise */
JERRY_ASSERT (ecma_promise_get_flags (obj_p) & ECMA_PROMISE_IS_PENDING);

#if JERRY_PROMISE_CALLBACK
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_MAIN))
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_REJECT))
{
JERRY_ASSERT (JERRY_CONTEXT (promise_callback) != NULL);
JERRY_CONTEXT (promise_callback) (JERRY_PROMISE_EVENT_REJECT,
Expand Down Expand Up @@ -282,7 +282,7 @@ ecma_fulfill_promise (ecma_value_t promise, /**< promise */
}

#if JERRY_PROMISE_CALLBACK
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_MAIN))
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_RESOLVE))
{
JERRY_ASSERT (JERRY_CONTEXT (promise_callback) != NULL);
JERRY_CONTEXT (promise_callback) (JERRY_PROMISE_EVENT_RESOLVE,
Expand Down Expand Up @@ -514,7 +514,7 @@ ecma_op_create_promise_object (ecma_value_t executor, /**< the executor function
promise_object_p->reactions = reactions;

#if JERRY_PROMISE_CALLBACK
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_MAIN))
if (JERRY_UNLIKELY (JERRY_CONTEXT (promise_callback_filters) & JERRY_PROMISE_EVENT_FILTER_CREATE))
{
JERRY_ASSERT (JERRY_CONTEXT (promise_callback) != NULL);
JERRY_CONTEXT (promise_callback) (JERRY_PROMISE_EVENT_CREATE,
Expand Down
18 changes: 10 additions & 8 deletions jerry-core/include/jerryscript-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,23 @@ typedef enum
typedef enum
{
JERRY_PROMISE_EVENT_FILTER_DISABLE = 0, /**< disable reporting of all events */
JERRY_PROMISE_EVENT_FILTER_MAIN = (1 << 0), /**< enables the following events:
* JERRY_PROMISE_EVENT_CREATE
* JERRY_PROMISE_EVENT_RESOLVE
* JERRY_PROMISE_EVENT_REJECT */
JERRY_PROMISE_EVENT_FILTER_ERROR = (1 << 1), /**< enables the following events:
JERRY_PROMISE_EVENT_FILTER_CREATE = (1 << 0), /**< enables the following event:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to keep the JERRY_PROMISE_EVENT_FILTER_MAIN and specify it's value as: JERRY_PROMISE_EVENT_FILTER_CREATE | JERRY_PROMISE_EVENT_FILTER_RESOLVE | JERRY_PROMISE_EVENT_FILTER_REJECT ? That way we keep the old way (which will catch the "main" cases) and will have the new more fine tuned option.

Copy link
Member Author

Choose a reason for hiding this comment

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

This has never been released, so there is no need to worry about compatiblity.

* JERRY_PROMISE_EVENT_CREATE */
JERRY_PROMISE_EVENT_FILTER_RESOLVE = (1 << 1), /**< enables the following event:
* JERRY_PROMISE_EVENT_RESOLVE */
JERRY_PROMISE_EVENT_FILTER_REJECT = (1 << 2), /**< enables the following event:
* JERRY_PROMISE_EVENT_REJECT */
JERRY_PROMISE_EVENT_FILTER_ERROR = (1 << 3), /**< enables the following events:
* JERRY_PROMISE_EVENT_RESOLVE_FULFILLED
* JERRY_PROMISE_EVENT_REJECT_FULFILLED
* JERRY_PROMISE_EVENT_REJECT_WITHOUT_HANDLER
* JERRY_PROMISE_EVENT_CATCH_HANDLER_ADDED */
JERRY_PROMISE_EVENT_FILTER_REACTION_JOB = (1 << 2), /**< enables the following events:
JERRY_PROMISE_EVENT_FILTER_REACTION_JOB = (1 << 4), /**< enables the following events:
* JERRY_PROMISE_EVENT_BEFORE_REACTION_JOB
* JERRY_PROMISE_EVENT_AFTER_REACTION_JOB */
JERRY_PROMISE_EVENT_FILTER_ASYNC_MAIN = (1 << 3), /**< enables the following events:
JERRY_PROMISE_EVENT_FILTER_ASYNC_MAIN = (1 << 5), /**< enables the following event:
* JERRY_PROMISE_EVENT_ASYNC_AWAIT */
JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB = (1 << 4), /**< enables the following events:
JERRY_PROMISE_EVENT_FILTER_ASYNC_REACTION_JOB = (1 << 6), /**< enables the following events:
* JERRY_PROMISE_EVENT_ASYNC_BEFORE_RESOLVE
* JERRY_PROMISE_EVENT_ASYNC_BEFORE_REJECT
* JERRY_PROMISE_EVENT_ASYNC_AFTER_RESOLVE
Expand Down
4 changes: 3 additions & 1 deletion tests/unit-core/test-promise-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ main (void)

jerry_init (JERRY_INIT_EMPTY);

jerry_promise_event_filter_t filters = (JERRY_PROMISE_EVENT_FILTER_MAIN
jerry_promise_event_filter_t filters = (JERRY_PROMISE_EVENT_FILTER_CREATE
| JERRY_PROMISE_EVENT_FILTER_RESOLVE
| JERRY_PROMISE_EVENT_FILTER_REJECT
Comment on lines +137 to +139
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing tests where only one of these are captured.

Copy link
Member Author

@zherczeg zherczeg Oct 11, 2021

Choose a reason for hiding this comment

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

I know, but there are currently no tests for splitting filters. We plan to add more tests in the future.

| JERRY_PROMISE_EVENT_FILTER_ERROR
| JERRY_PROMISE_EVENT_FILTER_REACTION_JOB
| JERRY_PROMISE_EVENT_FILTER_ASYNC_MAIN
Expand Down