@@ -3836,7 +3836,7 @@ jerry_error_type (const jerry_value_t value);
3836
3836
3837
3837
```c
3838
3838
{
3839
- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, "error msg");
3839
+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_RANGE, jerry_string_sz ( "error msg") );
3840
3840
jerry_error_t error_type = jerry_error_type (error_obj);
3841
3841
3842
3842
// error_type is now JERRY_ERROR_RANGE.
@@ -3958,7 +3958,7 @@ void main(void)
3958
3958
3959
3959
jerry_error_on_created (error_object_created_callback, NULL);
3960
3960
3961
- jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, "Message"));
3961
+ jerry_value_free (jerry_error_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Message") ));
3962
3962
3963
3963
jerry_cleanup ();
3964
3964
} /* main */
@@ -4153,7 +4153,7 @@ throw_exception (const jerry_call_info_t *call_info_p, /**< call info */
4153
4153
(void) argv;
4154
4154
(void) argc;
4155
4155
4156
- jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, "Error!");
4156
+ jerry_value_t result_value = jerry_throw_sz (JERRY_ERROR_COMMON, jerry_string_sz ( "Error!") );
4157
4157
4158
4158
/* Ignore calling the vm_throw_callback function. */
4159
4159
jerry_exception_allow_capture (result_value, false);
@@ -4541,7 +4541,7 @@ main (void)
4541
4541
4542
4542
jerry_string_external_on_free (external_string_free_callback);
4543
4543
4544
- const char * string_p = "This is a long external string, should not be duplicated!";
4544
+ #define string_p "This is a long external string, should not be duplicated!"
4545
4545
jerry_value_t external_string = jerry_string_external_sz (string_p, NULL);
4546
4546
/* The external_string_free_callback is called. */
4547
4547
jerry_value_free (external_string);
@@ -4602,7 +4602,7 @@ main (void)
4602
4602
{
4603
4603
jerry_init (JERRY_INIT_EMPTY);
4604
4604
4605
- const char * string_p = "This is a long external string, should not be duplicated!";
4605
+ #define string_p "This is a long external string, should not be duplicated!"
4606
4606
4607
4607
jerry_value_t external_string = jerry_string_external_sz (string_p, (void *) &user_value);
4608
4608
@@ -7158,12 +7158,12 @@ jerry_boolean (bool value);
7158
7158
7159
7159
**Summary**
7160
7160
7161
- Create new JavaScript Error object with the specified error message.
7162
-
7163
- Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7164
- Creating an Error object with no error type is not valid.
7161
+ Create an Error object with the provided `message` string value as the error `message` property.
7162
+ If the `message` value is not a string, the created error will not have a `message` property.
7165
7163
7166
7164
*Note*:
7165
+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7166
+ Creating an Error object with no error type is not valid.
7167
7167
- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
7168
7168
is no longer needed.
7169
7169
@@ -7206,21 +7206,25 @@ jerry_error (jerry_error_t error_type, jerry_value_t message);
7206
7206
7207
7207
**Summary**
7208
7208
7209
- Create new JavaScript Error object, using the a zero-terminated string as the error message.
7209
+ Create an Error object with the provided `message_sz` string value as the error `message` property.
7210
+ If the `message_sz` value is not a string, the created error will not have a `message` property.
7210
7211
7211
7212
*Note*:
7213
+ - Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
7214
+ Creating an Error object with no error type is not valid.
7212
7215
- Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
7213
7216
is no longer needed.
7217
+ - The `message_sz` value will be freed in this function.
7214
7218
7215
7219
**Prototype**
7216
7220
7217
7221
```c
7218
7222
jerry_value_t
7219
- jerry_error_sz (jerry_error_t error_type, const char *message_p );
7223
+ jerry_error_sz (jerry_error_t error_type, const jerry_value_t message_sz );
7220
7224
```
7221
7225
7222
7226
- `error_type` - type of the error
7223
- - `message_p ` - value of ' message' property of the constructed error object
7227
+ - `message_sz ` - message of the error that will be free/take
7224
7228
- return value - constructed error object
7225
7229
7226
7230
*Renamed in version 3.0, it was previously known as `jerry_create_error` in earlier versions.*
@@ -7229,7 +7233,7 @@ jerry_error_sz (jerry_error_t error_type, const char *message_p);
7229
7233
7230
7234
```c
7231
7235
{
7232
- jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, "error");
7236
+ jerry_value_t error_obj = jerry_error_sz (JERRY_ERROR_TYPE, jerry_string_sz ( "error") );
7233
7237
7234
7238
... // usage of error_obj
7235
7239
@@ -7757,20 +7761,21 @@ main (void)
7757
7761
7758
7762
**Summary**
7759
7763
7760
- Create string from a zero-terminated ASCII string.
7764
+ Create string value from the zero-terminated UTF-8 encoded literal string.
7765
+ The content of the buffer is assumed be encoded correctly, it's the callers
7766
+ responsibility to validate the input.
7761
7767
7762
7768
*Note*:
7763
- - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it
7764
- is no longer needed.
7769
+ - This is a macro that only accept literal string
7770
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7765
7771
7766
7772
**Prototype**
7767
7773
7768
7774
```c
7769
- jerry_value_t
7770
- jerry_string_sz (const char *str_p);
7775
+ #define jerry_string_sz(str)
7771
7776
```
7772
7777
7773
- - `str_p ` - non-null pointer to zero-terminated string
7778
+ - `str ` - A zero-terminated UTF-8 encoded literal string
7774
7779
- return value - created string
7775
7780
7776
7781
*Renamed in version 3.0, it was previously known as `jerry_create_string` in earlier versions.*
@@ -7779,7 +7784,7 @@ jerry_string_sz (const char *str_p);
7779
7784
7780
7785
```c
7781
7786
{
7782
- const char char_array[] = "a string";
7787
+ #define char_array "a string"
7783
7788
jerry_value_t string_value = jerry_string_sz (char_array);
7784
7789
7785
7790
... // usage of string_value
@@ -7790,7 +7795,7 @@ jerry_string_sz (const char *str_p);
7790
7795
7791
7796
**See also**
7792
7797
7793
- - [jerry_string ](#jerry_string )
7798
+ - [jerry_string_utf8 ](#jerry_string_utf8 )
7794
7799
7795
7800
7796
7801
## jerry_string
@@ -7839,31 +7844,120 @@ jerry_string (const jerry_char_t *buffer_p,
7839
7844
7840
7845
- [jerry_validate_string](#jerry_validate_string)
7841
7846
- [jerry_string_sz](#jerry_string_sz)
7847
+ - [jerry_string_utf8](#jerry_string_utf8)
7848
+ - [jerry_string_cesu8](#jerry_string_cesu8)
7849
+
7850
+
7851
+ ## jerry_string_utf8
7852
+
7853
+ **Summary**
7854
+
7855
+ Create a string value from the input buffer using the UTF-8 encoding.
7856
+ The content of the buffer is assumed to be valid in the UTF-8 encoding,
7857
+ it's the callers responsibility to validate the input.
7858
+
7859
+ *Note*:
7860
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7861
+
7862
+ **Prototype**
7863
+
7864
+ ```c
7865
+ jerry_value_t
7866
+ jerry_string_utf8 (const jerry_char_t *buffer_p,
7867
+ jerry_size_t buf_size)
7868
+ ```
7869
+
7870
+ - `buffer_p` - non-null pointer to buffer
7871
+ - `buf_size` - size of the buffer
7872
+
7873
+ **Example**
7874
+
7875
+ ```c
7876
+ {
7877
+ const jerry_char_t char_array[] = "a string";
7878
+ jerry_value_t string_value = jerry_string_utf8 (char_array,
7879
+ sizeof (char_array) - 1);
7880
+
7881
+ ... // usage of string_value
7882
+
7883
+ jerry_value_free (string_value);
7884
+ }
7885
+
7886
+ ```
7887
+
7888
+ **See also**
7889
+
7890
+ - [jerry_validate_string](#jerry_validate_string)
7891
+ - [jerry_string_sz](#jerry_string_sz)
7892
+ - [jerry_string](#jerry_string)
7893
+
7894
+
7895
+ ## jerry_string_cesu8
7896
+
7897
+ **Summary**
7898
+
7899
+ Create a string value from the input buffer using the CESU-8 encoding.
7900
+ The content of the buffer is assumed to be valid in the CESU-8 encoding,
7901
+ it's the callers responsibility to validate the input.
7902
+
7903
+ *Note*:
7904
+ - Returned value must be freed with [jerry_value_free](#jerry_value_free) when it is no longer needed.
7905
+
7906
+ **Prototype**
7907
+
7908
+ ```c
7909
+ jerry_value_t
7910
+ jerry_string_cesu8 (const jerry_char_t *buffer_p,
7911
+ jerry_size_t buf_size)
7912
+ ```
7913
+
7914
+ - `buffer_p` - non-null pointer to buffer
7915
+ - `buf_size` - size of the buffer
7916
+
7917
+ **Example**
7918
+
7919
+ ```c
7920
+ {
7921
+ const jerry_char_t char_array[] = "\xed\xa0\x83\xed\xb2\x80";
7922
+ jerry_value_t string_value = jerry_string_cesu8 (char_array,
7923
+ sizeof (char_array) - 1);
7924
+
7925
+ ... // usage of string_value
7926
+
7927
+ jerry_value_free (string_value);
7928
+ }
7929
+
7930
+ ```
7931
+
7932
+ **See also**
7933
+
7934
+ - [jerry_validate_string](#jerry_validate_string)
7935
+ - [jerry_string](#jerry_string)
7842
7936
7843
7937
7844
7938
## jerry_string_external_sz
7845
7939
7846
7940
**Summary**
7847
7941
7848
- Create an external string from a zero-terminated ASCII string. The string buffer passed to the function
7849
- should not be modified until the free callback is called. This function can be used to avoid
7850
- the duplication of large strings .
7942
+ Create external string from the zero-terminated CESU encoded literal string.
7943
+ The content of the buffer is assumed be encoded correctly, it's the callers
7944
+ responsibility to validate the input .
7851
7945
7852
7946
*Note*:
7947
+ - This is a macro that only accept literal string
7853
7948
- The free callback can be set by [jerry_string_external_on_free](#jerry_string_external_on_free)
7854
7949
- Returned value must be freed with [jerry_value_free](#jerry_value_free)
7855
7950
when it is no longer needed.
7856
7951
7857
7952
**Prototype**
7858
7953
7859
7954
```c
7860
- jerry_value_t
7861
- jerry_string_external_sz (const char *str_p, void *user_p);
7955
+ #define jerry_string_external_sz(str, user_p)
7862
7956
```
7863
7957
7864
- - `str_p` - non-null pointer to a zero-terminated string
7958
+ - `str_p` - A zero-terminated CESU-8 encoded literal string
7865
7959
- `user_p` - user pointer passed to the callback when the string is freed
7866
- - return value - value of the created string
7960
+ - return value - created external string
7867
7961
7868
7962
*Introduced in version 2.4*.
7869
7963
@@ -8096,10 +8190,10 @@ jerry_regexp_sz (const jerry_char_t *pattern_p, uint16_t flags);
8096
8190
8097
8191
```c
8098
8192
{
8099
- jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
8193
+ #define pattern "[cgt]gggtaaa|tttaccc[acg]"
8100
8194
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
8101
8195
8102
- jerry_value_t regexp = jerry_regexp_sz (pattern_p , pattern_flags);
8196
+ jerry_value_t regexp = jerry_regexp_sz (jerry_string_sz (pattern) , pattern_flags);
8103
8197
8104
8198
...
8105
8199
@@ -8141,7 +8235,7 @@ jerry_regexp (const jerry_value_t pattern, uint16_t flags);
8141
8235
{
8142
8236
jerry_char_t pattern_p = "[cgt]gggtaaa|tttaccc[acg]";
8143
8237
jerry_size_t pattern_size = sizeof (pattern_p) - 1;
8144
- jerry_value_t pattern_str = jerry_string (pattern_p, pattern_size, JERRY_ENCODING_UTF8 );
8238
+ jerry_value_t pattern_str = jerry_string_utf8 (pattern_p, pattern_size);
8145
8239
8146
8240
uint16_t pattern_flags = JERRY_REGEXP_FLAG_IGNORE_CASE;
8147
8241
0 commit comments