-
Notifications
You must be signed in to change notification settings - Fork 683
Introduce jerry_port_track_promise_rejection #4451
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
dbatyai
merged 1 commit into
jerryscript-project:master
from
rerobika:port_promise_rejection_tracker
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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 */ | ||
|
||
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_VLA (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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* 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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also considering suggesting yet another name change, to have the new function named
jerry_port_promise_rejection_tracker
. That would make the new typedef and the new function names aligned, as well as the name used by the spec. However, existing port API function names usually start with a verb (get this, set that, sleep, print, log, etc. -- the only exception being fatal). So, I'm not sure about this. But we should agree upon a good name so that it doesn't need to be changed, at least in the near future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this
jerry_port_track_promise_rejection
for the due to the starting verb convention with the other API functions.jerry_port_promise_rejection_tracker
would be suitable if we would renamejerry_port_log
tojerry_port_logger
and so on. So I'd leave as it for now.