@@ -6505,8 +6505,12 @@ main (void)
6505
6505
6506
6506
Generate snapshot from the specified source code.
6507
6507
6508
- *Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6509
- is no longer needed.
6508
+ *Notes*:
6509
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6510
+ is no longer needed.
6511
+ - This API depends on a build option (`JERRY_SNAPSHOT_SAVE`) and can be checked in runtime with
6512
+ the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled).
6513
+ If the feature is not enabled the function will return an error.
6510
6514
6511
6515
**Prototype**
6512
6516
@@ -6560,7 +6564,11 @@ main (void)
6560
6564
global_mode_snapshot_buffer,
6561
6565
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
6562
6566
6563
- size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
6567
+ if (!jerry_value_is_error (generate_result))
6568
+ {
6569
+ size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
6570
+ }
6571
+
6564
6572
jerry_release_value (generate_result);
6565
6573
6566
6574
jerry_cleanup ();
@@ -6586,8 +6594,12 @@ with the given arguments.
6586
6594
The function arguments and function body are
6587
6595
passed as separated arguments.
6588
6596
6589
- *Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6590
- is no longer needed.
6597
+ *Notes*:
6598
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6599
+ is no longer needed.
6600
+ - This API depends on a build option (`JERRY_SNAPSHOT_SAVE`) and can be checked in runtime with
6601
+ the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled).
6602
+ If the feature is not enabled the function will return an error.
6591
6603
6592
6604
**Prototype**
6593
6605
@@ -6648,7 +6660,11 @@ main (void)
6648
6660
func_snapshot_buffer,
6649
6661
sizeof (func_snapshot_buffer) / sizeof (uint32_t));
6650
6662
6651
- size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
6663
+ if (!jerry_value_is_error (generate_result))
6664
+ {
6665
+ size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
6666
+ }
6667
+
6652
6668
jerry_release_value (generate_result);
6653
6669
6654
6670
jerry_cleanup ();
@@ -6670,8 +6686,12 @@ main (void)
6670
6686
6671
6687
Execute snapshot from the specified buffer.
6672
6688
6673
- *Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6674
- is no longer needed.
6689
+ *Notes*:
6690
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6691
+ is no longer needed.
6692
+ - This API depends on a build option (`JERRY_SNAPSHOT_EXEC`) and can be checked in runtime with
6693
+ the `JERRY_FEATURE_SNAPSHOT_EXEC` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled).
6694
+ If the feature is not enabled the function will return an error.
6675
6695
6676
6696
**Prototype**
6677
6697
@@ -6683,13 +6703,13 @@ jerry_exec_snapshot (const uint32_t *snapshot_p,
6683
6703
uint32_t exec_snapshot_opts);
6684
6704
```
6685
6705
6686
- - `snapshot_p` - pointer to snapshot
6687
- - `snapshot_size` - size of snapshot in bytes
6688
- - `func_index` - index of executed function
6706
+ - `snapshot_p` - pointer to snapshot.
6707
+ - `snapshot_size` - size of snapshot in bytes.
6708
+ - `func_index` - index of executed function.
6689
6709
- `exec_snapshot_opts` - any combination of [jerry_exec_snapshot_opts_t](#jerry_exec_snapshot_opts_t) flags.
6690
6710
- return value
6691
- - result of bytecode, if run was successful
6692
- - thrown error, otherwise
6711
+ - result of bytecode, if run was successful.
6712
+ - thrown error, otherwise (an error is reported if the snapshot execution feature is not enabled).
6693
6713
6694
6714
*Changed in version 2.0*: Added `func_index` and `exec_snapshot_opts` arguments. Removed the `copy_bytecode` last argument.
6695
6715
@@ -6716,6 +6736,7 @@ main (void)
6716
6736
0,
6717
6737
global_mode_snapshot_buffer,
6718
6738
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
6739
+ // generate_result should be checked if it is an error or not
6719
6740
6720
6741
size_t global_mode_snapshot_size = (size_t) jerry_get_number_value (generate_result);
6721
6742
jerry_release_value (generate_result);
@@ -6728,6 +6749,9 @@ main (void)
6728
6749
global_mode_snapshot_size,
6729
6750
0,
6730
6751
0);
6752
+
6753
+ // check the `res` value for error and process the result.
6754
+
6731
6755
jerry_release_value (res);
6732
6756
6733
6757
jerry_cleanup ();
@@ -6750,8 +6774,12 @@ Load the selected snapshot function from the specified buffer as a function obje
6750
6774
6751
6775
The lexical environment of the loaded function is always the global lexical environment.
6752
6776
6753
- *Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6754
- is no longer needed.
6777
+ *Notes*:
6778
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
6779
+ is no longer needed.
6780
+ - This API depends on a build option (`JERRY_SNAPSHOT_EXEC`) and can be checked in runtime with
6781
+ the `JERRY_FEATURE_SNAPSHOT_EXEC` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled).
6782
+ If the feature is not enabled the function will return an error.
6755
6783
6756
6784
**Prototype**
6757
6785
@@ -6846,6 +6874,11 @@ main (void)
6846
6874
Collect the used literals from the given snapshot and save them into a buffer in list or C format.
6847
6875
None of these literals are magic strings. In C format only valid identifiers are collected.
6848
6876
6877
+ *Note*:
6878
+ - This API depends on a build option (`JERRY_SNAPSHOT_SAVE`) and can be checked in runtime with
6879
+ the `JERRY_FEATURE_SNAPSHOT_SAVE` feature enum value, see [jerry_is_feature_enabled](#jerry_is_feature_enabled).
6880
+ If the feature is not enabled the function will return zero.
6881
+
6849
6882
**Prototype**
6850
6883
6851
6884
```c
0 commit comments