Remove jerry_port_track_promise_rejection (#4613)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2021-03-11 19:58:44 +01:00 committed by GitHub
parent e739f11ed2
commit edd2f20397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 224 deletions

View File

@ -151,32 +151,6 @@ jerry_port_get_native_module (jerry_value_t name) /**< module specifier */
}
```
## Promise
```c
/**
* HostPromiseRejectionTracker operations
*/
typedef enum
{
JERRY_PROMISE_REJECTION_OPERATION_REJECT, /**< promise is rejected without any handlers */
JERRY_PROMISE_REJECTION_OPERATION_HANDLE, /**< handler is added to a rejected promise for the first time */
} jerry_promise_rejection_operation_t;
/**
* Track unhandled promise rejections.
*
* Note:
* This port function is called by jerry-core when JERRY_BUILTIN_PROMISE
* is enabled.
*
* @param promise rejected promise
* @param operation HostPromiseRejectionTracker operation
*/
void jerry_port_track_promise_rejection (const jerry_value_t promise,
const jerry_promise_rejection_operation_t operation);
```
## Date
```c
@ -418,32 +392,3 @@ void jerry_port_sleep (uint32_t sleep_time)
} /* jerry_port_sleep */
#endif /* defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1) */
```
## Promise
```c
#include "jerryscript-port.h"
/**
* Default implementation of jerry_port_track_promise_rejection.
* Prints the reason of the unhandled rejections.
*/
void
jerry_port_track_promise_rejection (const jerry_value_t promise, /**< rejected promise */
const jerry_promise_rejection_operation_t operation) /**< operation */
{
(void) operation; /* unused */
jerry_value_t reason = jerry_get_promise_result (promise);
jerry_value_t reason_to_string = jerry_value_to_string (reason);
jerry_size_t req_sz = jerry_get_utf8_string_size (reason_to_string);
jerry_char_t str_buf_p[req_sz + 1];
jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, req_sz);
str_buf_p[req_sz] = '\0';
jerry_release_value (reason_to_string);
jerry_release_value (reason);
printf ("Uncaught (in promise) %s\n", str_buf_p);
} /* jerry_port_track_promise_rejection */
```

View File

@ -181,23 +181,6 @@ ecma_is_resolver_already_called (ecma_object_t *promise_obj_p) /**< promise */
return (ecma_promise_get_flags (promise_obj_p) & ECMA_PROMISE_ALREADY_RESOLVED) != 0;
} /* ecma_is_resolver_already_called */
/**
* HostPromiseRejectionTracker
*
* See also: ES11 25.6.1.9
*/
static void
ecma_track_promise_rejection (ecma_object_t *obj_p, /**< rejected promise */
jerry_promise_rejection_operation_t operation) /**< operation */
{
JERRY_ASSERT (ecma_is_promise (obj_p));
if (!(ecma_promise_get_flags (obj_p) & ECMA_PROMISE_HANDLED))
{
jerry_port_track_promise_rejection (ecma_make_object_value (obj_p), operation);
}
} /* ecma_track_promise_rejection */
/**
* Reject a Promise with a reason.
*
@ -252,7 +235,6 @@ ecma_reject_promise (ecma_value_t promise, /**< promise */
promise_p->reactions = ecma_new_collection ();
ecma_collection_destroy (reactions);
ecma_track_promise_rejection (obj_p, JERRY_PROMISE_REJECTION_OPERATION_REJECT);
} /* ecma_reject_promise */
/**
@ -969,7 +951,6 @@ ecma_promise_do_then (ecma_value_t promise, /**< the promise which call 'then' *
{
/* 9. */
ecma_value_t reason = ecma_promise_get_result (promise_obj_p);
ecma_track_promise_rejection (promise_obj_p, JERRY_PROMISE_REJECTION_OPERATION_HANDLE);
ecma_enqueue_promise_reaction_job (ecma_make_object_value (result_capability_obj_p), on_rejected, reason);
ecma_free_value (reason);
@ -990,9 +971,6 @@ ecma_promise_do_then (ecma_value_t promise, /**< the promise which call 'then' *
#endif /* JERRY_PROMISE_CALLBACK */
}
/* ES11: 11. */
promise_p->header.u.class_prop.extra_info |= ECMA_PROMISE_HANDLED;
/* 10. */
return ecma_copy_value (capability_p->header.u.class_prop.u.promise);
} /* ecma_promise_do_then */

View File

@ -34,9 +34,9 @@ typedef enum
ECMA_PROMISE_IS_PENDING = (1 << 0), /**< pending state */
ECMA_PROMISE_IS_FULFILLED = (1 << 1), /**< fulfilled state */
ECMA_PROMISE_ALREADY_RESOLVED = (1 << 2), /**< already resolved */
ECMA_PROMISE_HANDLED = (1 << 3), /**< ES11: 25.6.6 [[PromiseIsHandled]] internal slot */
#if JERRY_PROMISE_CALLBACK
ECMA_PROMISE_UNHANDLED_REJECT = (1 << 4), /**< a Promise is rejected without a catch handler */
ECMA_PROMISE_UNHANDLED_REJECT = (1 << 3), /**< a Promise is rejected without a catch handler,
* related to ES11: 25.6.6 [[PromiseIsHandled]] */
#endif /* JERRY_PROMISE_CALLBACK */
} ecma_promise_flags_t;

View File

@ -252,28 +252,6 @@ size_t jerry_port_normalize_path (const char *in_path_p,
*/
jerry_value_t jerry_port_get_native_module (jerry_value_t name);
/**
* HostPromiseRejectionTracker operations
*/
typedef enum
{
JERRY_PROMISE_REJECTION_OPERATION_REJECT, /**< promise is rejected without any handlers */
JERRY_PROMISE_REJECTION_OPERATION_HANDLE, /**< handler is added to a rejected promise for the first time */
} jerry_promise_rejection_operation_t;
/**
* Track unhandled promise rejections.
*
* Note:
* This port function is called by jerry-core when JERRY_BUILTIN_PROMISE
* is enabled.
*
* @param promise rejected promise
* @param operation HostPromiseRejectionTracker operation
*/
void jerry_port_track_promise_rejection (const jerry_value_t promise,
const jerry_promise_rejection_operation_t operation);
/**
* @}
*/

View File

@ -201,6 +201,48 @@ create_test262 (jerry_value_t global_obj) /**< global object */
return test262_object;
} /* create_test262 */
static void
promise_callback (jerry_promise_event_type_t event_type, /**< event type */
const jerry_value_t object, /**< target object */
const jerry_value_t value, /**< optional argument */
void *user_p) /**< user pointer passed to the callback */
{
(void) value; /* unused */
(void) user_p; /* unused */
const jerry_size_t max_allowed_size = 5 * 1024 - 1;
if (event_type != JERRY_PROMISE_EVENT_REJECT_WITHOUT_HANDLER)
{
return;
}
jerry_value_t reason = jerry_get_promise_result (object);
jerry_value_t reason_to_string = jerry_value_to_string (reason);
if (!jerry_value_is_error (reason_to_string))
{
jerry_size_t buffer_size = jerry_get_utf8_string_size (reason_to_string);
if (buffer_size > max_allowed_size)
{
buffer_size = max_allowed_size;
}
JERRY_VLA (jerry_char_t, str_buf_p, buffer_size + 1);
jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, buffer_size);
str_buf_p[buffer_size] = '\0';
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught Promise rejection: %s\n", str_buf_p);
}
else
{
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught Promise rejection (reason cannot be converted to string)\n");
}
jerry_release_value (reason_to_string);
jerry_release_value (reason);
} /* promise_callback */
/**
* Inits the engine and the debugger
*/
@ -209,6 +251,8 @@ main_init_engine (main_args_t *arguments_p) /**< main arguments */
{
jerry_init (arguments_p->init_flags);
jerry_promise_set_callback (JERRY_PROMISE_EVENT_FILTER_ERROR, promise_callback, NULL);
if (arguments_p->option_flags & OPT_FLAG_DEBUG_SERVER)
{
bool protocol = false;

View File

@ -27,7 +27,6 @@ set(SOURCE_PORT_DEFAULT
default-fatal.c
default-io.c
default-module.c
default-promise.c
)
# Amalgamated JerryScript source/header build.

View File

@ -1,48 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerryscript-port.h"
/**
* Default implementation of jerry_port_track_promise_rejection.
* Prints the reason of the unhandled rejections.
*/
void
jerry_port_track_promise_rejection (const jerry_value_t promise, /**< rejected promise */
const jerry_promise_rejection_operation_t operation) /**< operation */
{
(void) operation; /* unused */
const jerry_size_t max_allowed_size = 5 * 1024 - 1;
jerry_value_t reason = jerry_get_promise_result (promise);
jerry_value_t reason_to_string = jerry_value_to_string (reason);
jerry_release_value (reason);
jerry_length_t end_pos = jerry_get_utf8_string_length (reason_to_string);
jerry_size_t string_size = jerry_get_utf8_string_size (reason_to_string);
jerry_size_t buffer_size = (string_size < max_allowed_size) ? string_size : max_allowed_size;
JERRY_VLA (jerry_char_t, str_buf_p, buffer_size + 1);
jerry_size_t copied = jerry_substring_to_utf8_char_buffer (reason_to_string,
0,
end_pos,
str_buf_p,
buffer_size);
str_buf_p[copied] = '\0';
jerry_release_value (reason_to_string);
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught (in promise) %s\n", str_buf_p);
} /* jerry_port_track_promise_rejection */

View File

@ -1,45 +0,0 @@
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jerryscript-port.h"
/**
* Track unhandled promise rejections.
*
* Note:
* This port function is called by jerry-core when JERRY_BUILTIN_PROMISE
* is enabled.
*
* @param promise rejected promise
* @param operation HostPromiseRejectionTracker operation
*/
void
jerry_port_track_promise_rejection (const jerry_value_t promise,
const jerry_promise_rejection_operation_t operation)
{
(void) operation; /* unused */
jerry_value_t reason = jerry_get_promise_result (promise);
jerry_value_t reason_to_string = jerry_value_to_string (reason);
jerry_size_t req_sz = jerry_get_utf8_string_size (reason_to_string);
jerry_char_t str_buf_p[req_sz + 1];
jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, req_sz);
str_buf_p[req_sz] = '\0';
jerry_release_value (reason_to_string);
jerry_release_value (reason);
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught (in promise) %s\n", str_buf_p);
} /* jerry_port_track_promise_rejection */

View File

@ -227,32 +227,3 @@ jerry_port_get_current_context (void)
{
return current_context_p;
} /* jerry_port_get_current_context */
/**
* Track unhandled promise rejections.
*
* Note:
* This port function is called by jerry-core when JERRY_BUILTIN_PROMISE
* is enabled.
*
* @param promise rejected promise
* @param operation HostPromiseRejectionTracker operation
*/
void
jerry_port_track_promise_rejection (const jerry_value_t promise,
const jerry_promise_rejection_operation_t operation)
{
(void) operation; /* unused */
jerry_value_t reason = jerry_get_promise_result (promise);
jerry_value_t reason_to_string = jerry_value_to_string (reason);
jerry_size_t req_sz = jerry_get_utf8_string_size (reason_to_string);
jerry_char_t str_buf_p[req_sz + 1];
jerry_string_to_utf8_char_buffer (reason_to_string, str_buf_p, req_sz);
str_buf_p[req_sz] = '\0';
jerry_release_value (reason_to_string);
jerry_release_value (reason);
jerry_port_log (JERRY_LOG_LEVEL_WARNING, "Uncaught (in promise) %s\n", str_buf_p);
} /* jerry_port_track_promise_rejection */