@@ -3750,7 +3750,7 @@ jerry_error_type (const jerry_value_t value);
3750
3750
3751
3751
```c
3752
3752
{
3753
- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, "error msg");
3753
+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, jerry_string_sz ( "error msg") );
3754
3754
jerry_error_t error_type = jerry_error_type (error_obj);
3755
3755
3756
3756
// error_type is now JERRY_ERROR_RANGE.
@@ -3868,7 +3868,7 @@ void main(void)
3868
3868
3869
3869
jerry_error_on_created (error_object_created_callback, NULL);
3870
3870
3871
- jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message"));
3871
+ jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Message") ));
3872
3872
3873
3873
jerry_cleanup ();
3874
3874
} /* main */
@@ -4062,7 +4062,7 @@ throw_exception (const jerry_call_info_t *call_info_p, /**< call info */
4062
4062
(void) argv;
4063
4063
(void) argc;
4064
4064
4065
- jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, "Error!");
4065
+ jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Error!") );
4066
4066
4067
4067
/* Ignore calling the vm_throw_callback function. */
4068
4068
jerry_exception_allow_capture (result_value, false);
@@ -4353,7 +4353,7 @@ main (void)
4353
4353
4354
4354
jerry_string_external_on_free (external_string_free_callback);
4355
4355
4356
- const char * string_p = "This is a long external string, should not be duplicated!";
4356
+ #define string_p "This is a long external string, should not be duplicated!"
4357
4357
jerry_value_t external_string = jerry_string_external_sz (string_p, NULL);
4358
4358
/* The external_string_free_callback is called. */
4359
4359
jerry_value_free (external_string);
@@ -4414,7 +4414,7 @@ main (void)
4414
4414
{
4415
4415
jerry_init (JERRY_INIT_EMPTY);
4416
4416
4417
- const char * string_p = "This is a long external string, should not be duplicated!";
4417
+ #define string_p "This is a long external string, should not be duplicated!"
4418
4418
4419
4419
jerry_value_t external_string = jerry_string_external_sz (string_p, (void *) &user_value);
4420
4420
@@ -6903,13 +6903,13 @@ jerry_boolean (bool value);
6903
6903
6904
6904
**Summary**
6905
6905
6906
- Create new JavaScript Error object with the specified error message.
6906
+ Create an Error object with the provided `message` string value as the error `message` property.
6907
+ If the `message` value is not a string, the created error will not have a `message` property.
6907
6908
6908
- Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
6909
- Creating an Error object with no error type is not valid.
6910
-
6911
- *Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
6912
- is no longer needed.
6909
+ *Note*:
6910
+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
6911
+ Creating an Error object with no error type is not valid.
6912
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
6913
6913
6914
6914
**Prototype**
6915
6915
@@ -6948,27 +6948,31 @@ jerry_error (jerry_error_t error_type, jerry_value_t message);
6948
6948
6949
6949
**Summary**
6950
6950
6951
- Create new JavaScript Error object, using the a zero-terminated string as the error message.
6951
+ Create an Error object with the provided `message_sz` string value as the error `message` property.
6952
+ If the `message_sz` value is not a string, the created error will not have a `message` property.
6952
6953
6953
- *Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
6954
- is no longer needed.
6954
+ *Note*:
6955
+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
6956
+ Creating an Error object with no error type is not valid.
6957
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
6958
+ - The `message_sz` value will be freed in this function.
6955
6959
6956
6960
**Prototype**
6957
6961
6958
6962
```c
6959
6963
jerry_value_t
6960
- jerry_error_sz (jerry_error_t error_type, const char *message_p );
6964
+ jerry_error_sz (jerry_error_t error_type, const jerry_value_t message_sz );
6961
6965
```
6962
6966
6963
6967
- `error_type` - type of the error
6964
- - `message_p ` - value of ' message' property of the constructed error object
6968
+ - `message_sz ` - message of the error that will be free/take
6965
6969
- return value - constructed error object
6966
6970
6967
6971
**Example**
6968
6972
6969
6973
```c
6970
6974
{
6971
- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, "error");
6975
+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, jerry_string_sz ( "error") );
6972
6976
6973
6977
... // usage of error_obj
6974
6978
@@ -7472,26 +7476,28 @@ main (void)
7472
7476
7473
7477
**Summary**
7474
7478
7475
- Create string from a zero-terminated ASCII string.
7479
+ Create string value from the zero-terminated UTF-8 encoded literal string.
7480
+ The content of the buffer is assumed be encoded correctly, it's the callers
7481
+ responsibility to validate the input.
7476
7482
7477
- *Note*: Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
7478
- is no longer needed.
7483
+ *Note*:
7484
+ - This is a macro that only accept literal string
7485
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7479
7486
7480
7487
**Prototype**
7481
7488
7482
7489
```c
7483
- jerry_value_t
7484
- jerry_string_sz (const char *str_p);
7490
+ #define jerry_string_sz(str)
7485
7491
```
7486
7492
7487
- - `str_p ` - non-null pointer to string
7493
+ - `str ` - An zero-terminated UTF-8 encoded literal string
7488
7494
- return value - created string
7489
7495
7490
7496
**Example**
7491
7497
7492
7498
```c
7493
7499
{
7494
- const char char_array[] = "a string";
7500
+ #define char_array "a string"
7495
7501
jerry_value_t string_value = jerry_string_sz (char_array);
7496
7502
7497
7503
... // usage of string_value
@@ -7502,7 +7508,7 @@ jerry_string_sz (const char *str_p);
7502
7508
7503
7509
**See also**
7504
7510
7505
- - [jerry_string ](#jerry_string )
7511
+ - [jerry_string_utf8 ](#jerry_string_utf8 )
7506
7512
7507
7513
7508
7514
## jerry_string
@@ -7548,31 +7554,120 @@ jerry_string (const jerry_char_t *buffer_p,
7548
7554
7549
7555
- [jerry_validate_string](#jerry_validate_string)
7550
7556
- [jerry_string_sz](#jerry_string_sz)
7557
+ - [jerry_string_utf8](#jerry_string_utf8)
7558
+ - [jerry_string_cesu8](#jerry_string_cesu8)
7551
7559
7552
7560
7553
- ## jerry_string_external_sz
7561
+ ## jerry_string_utf8
7554
7562
7555
7563
**Summary**
7556
7564
7557
- Create an external string from a zero-terminated ASCII string. The string buffer passed to the function
7558
- should not be modified until the free callback is called. This function can be used to avoid
7559
- the duplication of large strings .
7565
+ Create a string value from the input buffer using the UTF-8 encoding.
7566
+ The content of the buffer is assumed to be valid in the UTF-8 encoding,
7567
+ it's the callers responsibility to validate the input .
7560
7568
7561
7569
*Note*:
7562
- - The free callback can be set by [jerry_string_external_on_free](#jerry_string_external_on_free)
7563
- - Returned value must be freed with [jerry_value_free](#jerry_value_free)
7564
- when it is no longer needed.
7570
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7565
7571
7566
7572
**Prototype**
7567
7573
7568
7574
```c
7569
7575
jerry_value_t
7570
- jerry_string_external_sz (const char *str_p, void *user_p);
7576
+ jerry_string_utf8 (const jerry_char_t *buffer_p,
7577
+ jerry_size_t buf_size)
7571
7578
```
7572
7579
7573
- - `str_p` - non-null pointer to string
7580
+ - `buffer_p` - non-null pointer to buffer
7581
+ - `buf_size` - size of the buffer
7582
+
7583
+ **Example**
7584
+
7585
+ ```c
7586
+ {
7587
+ const jerry_char_t char_array[] = "a string";
7588
+ jerry_value_t string_value = jerry_string_utf8 (char_array,
7589
+ sizeof (char_array) - 1);
7590
+
7591
+ ... // usage of string_value
7592
+
7593
+ jerry_value_free (string_value);
7594
+ }
7595
+
7596
+ ```
7597
+
7598
+ **See also**
7599
+
7600
+ - [jerry_validate_string](#jerry_validate_string)
7601
+ - [jerry_string_sz](#jerry_string_sz)
7602
+ - [jerry_string](#jerry_string)
7603
+
7604
+
7605
+ ## jerry_string_cesu8
7606
+
7607
+ **Summary**
7608
+
7609
+ Create a string value from the input buffer using the CESU-8 encoding.
7610
+ The content of the buffer is assumed to be valid in the CESU-8 encoding,
7611
+ it's the callers responsibility to validate the input.
7612
+
7613
+ *Note*:
7614
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7615
+
7616
+ **Prototype**
7617
+
7618
+ ```c
7619
+ jerry_value_t
7620
+ jerry_string_cesu8 (const jerry_char_t *buffer_p,
7621
+ jerry_size_t buf_size)
7622
+ ```
7623
+
7624
+ - `buffer_p` - non-null pointer to buffer
7625
+ - `buf_size` - size of the buffer
7626
+
7627
+ **Example**
7628
+
7629
+ ```c
7630
+ {
7631
+ const jerry_char_t char_array[] = "\xed\xa0\x83\xed\xb2\x80";
7632
+ jerry_value_t string_value = jerry_string_cesu8 (char_array,
7633
+ sizeof (char_array) - 1);
7634
+
7635
+ ... // usage of string_value
7636
+
7637
+ jerry_value_free (string_value);
7638
+ }
7639
+
7640
+ ```
7641
+
7642
+ **See also**
7643
+
7644
+ - [jerry_validate_string](#jerry_validate_string)
7645
+ - [jerry_string](#jerry_string)
7646
+
7647
+
7648
+ ## jerry_string_external_sz
7649
+
7650
+ **Summary**
7651
+
7652
+ Create external string from the zero-terminated ASCII encoded literal string.
7653
+ The content of the buffer is assumed be encoded correctly, it's the callers
7654
+ responsibility to validate the input.
7655
+
7656
+ *Note*:
7657
+ - This is a macro that only accept literal string
7658
+ - The free callback can be set by [jerry_string_external_on_free](#jerry_string_external_on_free)
7659
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free)
7660
+ when it is no longer needed.
7661
+
7662
+ **Prototype**
7663
+
7664
+ ```c
7665
+ #define jerry_string_external_sz(str, user_p)
7666
+ ```
7667
+
7668
+ - `str_p` - zero-terminated ASCII encoded literal string
7574
7669
- `user_p` - user pointer passed to the callback when the string is freed
7575
- - return value - value of the created string
7670
+ - return value - created external string
7576
7671
7577
7672
*New in version 2.4*.
7578
7673
@@ -7794,10 +7889,10 @@ jerry_regexp_sz (const jerry_char_t *pattern_p, uint16_t flags);
7794
7889
7795
7890
```c
7796
7891
{
7797
- jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
7892
+ #define pattern "[cgt]gggtaaa|tttaccc[acg]"
7798
7893
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
7799
7894
7800
- jerry_value_t regexp = jerry_regexp_sz (pattern_p , pattern_flags);
7895
+ jerry_value_t regexp = jerry_regexp_sz (jerry_string_sz (pattern) , pattern_flags);
7801
7896
7802
7897
...
7803
7898
@@ -7836,7 +7931,7 @@ jerry_regexp (const jerry_value_t pattern, uint16_t flags);
7836
7931
{
7837
7932
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
7838
7933
jerry_size_t pattern_size = sizeof (pattern_p) - 1;
7839
- jerry_value_t pattern_str = jerry_string (pattern_p, pattern_size, JERRY_ENCODING_UTF8 );
7934
+ jerry_value_t pattern_str = jerry_string_utf8 (pattern_p, pattern_size);
7840
7935
7841
7936
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
7842
7937
0 commit comments