@@ -35,6 +35,8 @@ Possible compile time enabled feature types:
3535 - JERRY_FEATURE_REGEXP_DUMP - regexp byte-code dumps
3636 - JERRY_FEATURE_SNAPSHOT_SAVE - saving snapshot files
3737 - JERRY_FEATURE_SNAPSHOT_EXEC - executing snapshot files
38+ - JERRY_FEATURE_DEBUGGER - debugger is available
39+ - JERRY_FEATURE_VM_EXEC_STOP - stopping ECMAScript execution
3840
3941## jerry_char_t
4042
@@ -3877,3 +3879,76 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p,
38773879- [jerry_init](#jerry_init)
38783880- [jerry_cleanup](#jerry_cleanup)
38793881- [jerry_register_magic_strings](#jerry_register_magic_strings)
3882+
3883+
3884+ ## jerry_set_vm_exec_stop_callback
3885+
3886+ **Summary**
3887+
3888+ When JERRY_FEATURE_VM_EXEC_STOP is enabled a callback function can be
3889+ specified by this function. This callback is periodically called when
3890+ JerryScript executes an ECMASCript program.
3891+
3892+ If the callback returns with undefined value the ECMAScript execution
3893+ continues. Otherwise the result is thrown by the engine (if the error
3894+ flag is not set for the returned value the engine automatically sets
3895+ it). The callback function might be called again even if it thrown
3896+ an error. In this case the function must throw the same error again.
3897+
3898+ Frequently calling a callback in the main executor loop reduces
3899+ its performance. The `frequency` argument allows decreasing
3900+ this overhead. If its value is `N`, the callback is called only
3901+ every `N` times. The minimum value of `N` is `1` (`0` is converted
3902+ to `1` automatically).
3903+
3904+ **Prototype**
3905+
3906+ ```c
3907+ void
3908+ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb,
3909+ void *user_p,
3910+ uint32_t frequency);
3911+ ```
3912+
3913+ - `stop_cb` - periodically called callback (passing NULL disables this feature)
3914+ - `user_p` - user pointer passed to the `stop_cb` function
3915+ - `frequency` - frequency of calling the `stop_cb` function
3916+
3917+ **Example**
3918+
3919+ ```c
3920+ static jerry_value_t
3921+ vm_exec_stop_callback (void *user_p)
3922+ {
3923+ static int countdown = 10;
3924+
3925+ while (countdown > 0)
3926+ {
3927+ countdown--;
3928+ return jerry_create_undefined();
3929+ }
3930+
3931+ // The error flag is added automatically.
3932+ return jerry_create_string((const jerry_char_t *) "Abort script");
3933+ }
3934+
3935+ {
3936+ jerry_init (JERRY_INIT_EMPTY);
3937+
3938+ jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
3939+
3940+ // Inifinte loop.
3941+ const char *src_p = "while(true) {}";
3942+
3943+ jerry_value_t src = jerry_parse ((jerry_char_t *) src_p, strlen (src_p), false);
3944+ jerry_release_value (jerry_run (src));
3945+ jerry_release_value (src);
3946+ }
3947+ ```
3948+
3949+ **See also**
3950+
3951+ - [jerry_init](#jerry_init)
3952+ - [jerry_cleanup](#jerry_cleanup)
3953+ - [jerry_parse](#jerry_parse)
3954+ - [jerry_run](#jerry_run)
0 commit comments