Support this binding retrieval for backtrace frames (#4669)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-05-17 11:41:29 +02:00
committed by GitHub
parent a67f198134
commit 67a61bc211
5 changed files with 97 additions and 8 deletions
+58
View File
@@ -10606,6 +10606,7 @@ main (void)
- [jerry_backtrace_get_frame_type](#jerry_backtrace_get_frame_type)
- [jerry_backtrace_get_location](#jerry_backtrace_get_location)
- [jerry_backtrace_get_function](#jerry_backtrace_get_function)
- [jerry_backtrace_get_this](#jerry_backtrace_get_this)
- [jerry_backtrace_is_strict](#jerry_backtrace_is_strict)
@@ -10785,6 +10786,63 @@ backtrace_callback (jerry_backtrace_frame_t *frame_p,
- [jerry_backtrace_capture](#jerry_backtrace_capture)
## jerry_backtrace_get_this
**Summary**
Initialize and return with the 'this' binding private field of a backtrace frame.
The 'this' binding is a hidden value passed to the called function. As for arrow
functions, the 'this' binding is assigned at function creation. This getter
function can only be called from the callback function of
[jerry_backtrace_capture](#jerry_backtrace_capture), and the value becomes invalid
after the callback returns.
*Notes*:
- The returned data must not be modified, and does not need to be freed.
Any cleanup is done automatically after the callback is returned.
**Prototype**
```c
const jerry_value_t *
jerry_backtrace_get_this (jerry_backtrace_frame_t *frame_p);
```
- `frame_p` - a frame passed to the [jerry_backtrace_callback_t](#jerry_backtrace_callback_t) callback
- return value
- pointer to the 'this' binding if the binding is available,
- NULL otherwise
*New in version [[NEXT_RELEASE]]*.
**Example**
See the example of [jerry_backtrace_capture](#jerry_backtrace_capture)
with the following callback function:
```c
static bool
backtrace_callback (jerry_backtrace_frame_t *frame_p,
void *user_p)
{
jerry_value_t *this_p = jerry_backtrace_get_this (frame_p);
if (this_p != NULL)
{
printf ("The 'this' binding is available");
return true;
}
printf ("The 'this' binding is NOT available");
return true;
}
```
**See also**
- [jerry_backtrace_capture](#jerry_backtrace_capture)
## jerry_backtrace_is_strict
**Summary**