@@ -31,6 +31,19 @@ Possible types of an error:
3131 - JERRY_ERROR_TYPE - type error
3232 - JERRY_ERROR_URI - URI error
3333
34+ ## jerry_feature_t
35+
36+ Possible compile time enabled feature types:
37+
38+ - JERRY_FEATURE_CPOINTER_32_BIT - 32 bit compressed pointers
39+ - JERRY_FEATURE_ERROR_MESSAGES - error messages
40+ - JERRY_FEATURE_JS_PARSER - js-parser
41+ - JERRY_FEATURE_MEM_STATS - memory statistics
42+ - JERRY_FEATURE_PARSER_DUMP - parser byte-code dumps
43+ - JERRY_FEATURE_REGEXP_DUMP - regexp byte-code dumps
44+ - JERRY_FEATURE_SNAPSHOT_SAVE - saving snapshot files
45+ - JERRY_FEATURE_SNAPSHOT_EXEC - executing snapshot files
46+
3447## jerry_char_t
3548
3649**Summary**
@@ -251,6 +264,8 @@ jerry_cleanup (void);
251264
252265Registers an external magic string array.
253266
267+ *Note*: The strings in the array must be sorted by size at first, then lexicographically.
268+
254269**Prototype**
255270
256271```c
@@ -271,11 +286,12 @@ jerry_register_magic_strings (const jerry_char_ptr_t *ex_str_items_p,
271286 jerry_init (JERRY_INIT_EMPTY);
272287
273288 // must be static, because 'jerry_register_magic_strings' does not copy
289+ // the items must be sorted by size at first, then lexicographically
274290 static const jerry_char_ptr_t magic_string_items[] = {
275291 (const jerry_char_ptr_t) "magicstring1",
276292 (const jerry_char_ptr_t) "magicstring2",
277293 (const jerry_char_ptr_t) "magicstring3"
278- };
294+ };
279295 uint32_t num_magic_string_items = (uint32_t) (sizeof (magic_string_items) / sizeof (jerry_char_ptr_t));
280296
281297 // must be static, because 'jerry_register_magic_strings' does not copy
@@ -292,6 +308,7 @@ jerry_register_magic_strings (const jerry_char_ptr_t *ex_str_items_p,
292308
293309- [jerry_init](#jerryinit)
294310- [jerry_cleanup](#jerrycleanup)
311+ - [jerry_parse_and_save_literals](#jerryparseandsaveliterals)
295312
296313
297314## jerry_get_memory_limits
@@ -926,6 +943,38 @@ jerry_value_is_undefined (const jerry_value_t value)
926943
927944- [jerry_release_value](#jerryreleasevalue)
928945
946+ ## jerry_is_feature_enabled
947+
948+ **Summary**
949+
950+ Returns whether the specified compile time feature is enabled.
951+
952+ **Prototype**
953+
954+ ```c
955+ bool
956+ jerry_is_feature_enabled (const jerry_feature_t feature);
957+ ```
958+
959+ - `feature` - jerry feature
960+ - return value
961+ - true, if the given `jerry_feature_t` is enabled
962+ - false, otherwise
963+
964+ **Example**
965+
966+ ```c
967+ {
968+ ...
969+ jerry_feature_t feature = JERRY_FEATURE_SNAPSHOT_SAVE;
970+
971+ if (jerry_is_feature_enabled (feature))
972+ {
973+ ...
974+ }
975+
976+ }
977+ ```
929978
930979# Error flag manipulation functions
931980
@@ -1159,6 +1208,44 @@ jerry_get_string_size (const jerry_value_t value);
11591208- [jerry_get_string_length](#jerrygetstringlength)
11601209
11611210
1211+ ## jerry_get_utf8_string_size
1212+
1213+ **Summary**
1214+
1215+ Get the size of an utf8-encoded string. Returns zero, if the value parameter is not a string.
1216+
1217+ *Note*: The difference from [jerry_get_string_size](#jerrygetstringsize) is that it returns with utf-8 string size
1218+ instead of the cesu-8 string size.
1219+
1220+ **Prototype**
1221+
1222+ ```c
1223+ jerry_size_t
1224+ jerry_get_utf8_string_size (const jerry_value_t value);
1225+ ```
1226+ - `value` - api value
1227+ - return value - number of bytes in the buffer needed to represent the utf8-encoded string.
1228+
1229+ **Example**
1230+
1231+ ```c
1232+ {
1233+ const jerry_char_t char_array[] = "a string";
1234+ jerry_value_t string = jerry_create_string (char_array);
1235+
1236+ jerry_size_t string_size = jerry_get_utf8_string_size (string);
1237+
1238+ ... // usage of string_size
1239+
1240+ jerry_release_value (string);
1241+ }
1242+ ```
1243+
1244+ **See also**
1245+
1246+ - [jerry_create_string_from_utf8](#jerrycreatestringfromutf8)
1247+ - [jerry_get_utf8_string_length](#jerrygetutf8stringlength)
1248+
11621249## jerry_get_string_length
11631250
11641251**Summary**
@@ -1195,6 +1282,44 @@ jerry_get_string_length (const jerry_value_t value);
11951282- [jerry_create_string](#jerrycreatestring)
11961283- [jerry_get_string_size](#jerrygetstringsize)
11971284
1285+ ## jerry_get_utf8_string_length
1286+
1287+ **Summary**
1288+
1289+ Get the length of an UTF-8 encoded string. Returns zero, if the value parameter is not a string.
1290+
1291+ *Note*: The difference from [jerry_get_string_length](#jerrygetstringlength) is that it
1292+ returns with utf-8 string length instead of the cesu-8 string length.
1293+
1294+ **Prototype**
1295+
1296+ ```c
1297+ jerry_length_t
1298+ jerry_get_utf8_string_length (const jerry_value_t value);
1299+ ```
1300+
1301+ - `value` - input string value
1302+ - return value - number of characters in the string
1303+
1304+ **Example**
1305+
1306+ ```c
1307+ {
1308+ const jerry_char_t char_array[] = "a string";
1309+ jerry_value_t string = jerry_create_string_from_utf8 (char_array);
1310+
1311+ jerry_length_t string_length = jerry_get_utf8_string_length (string);
1312+
1313+ ... // usage of string_length
1314+
1315+ jerry_release_value (string);
1316+ }
1317+ ```
1318+
1319+ **See also**
1320+
1321+ - [jerry_create_string_from_utf8](#jerrycreatestringfromutf8)
1322+ - [jerry_get_utf8_string_size](#jerrygetutf8stringsize)
11981323
11991324## jerry_string_to_char_buffer
12001325
@@ -1240,6 +1365,49 @@ jerry_string_to_char_buffer (const jerry_value_t value,
12401365- [jerry_create_string](#jerrycreatestring)
12411366- [jerry_get_string_size](#jerrygetstringsize)
12421367
1368+ ## jerry_string_to_utf8_char_buffer
1369+
1370+ **Summary**
1371+
1372+ Copy the characters of a string into a specified utf-8 buffer.
1373+ The '\0' character could occur in character buffer. Returns 0,
1374+ if the value parameter is not a string or the buffer isn't
1375+ large enough for the whole string.
1376+
1377+ **Prototype**
1378+
1379+ ```c
1380+ jerry_size_t
1381+ jerry_string_to_utf8_char_buffer (const jerry_value_t value,
1382+ jerry_char_t *buffer_p,
1383+ jerry_size_t buffer_size);
1384+ ```
1385+
1386+ - `value` - input string value
1387+ - `buffer_p` - pointer to output buffer
1388+ - `buffer_size` - size of the buffer
1389+ - return value - number of bytes, actually copied to the buffer
1390+
1391+ **Example**
1392+
1393+ ```c
1394+ {
1395+ jerry_value_t value;
1396+ ... // create or acquire value
1397+
1398+ jerry_size_t req_sz = jerry_get_utf8_string_size (value);
1399+ jerry_char_t str_buf_p[req_sz];
1400+
1401+ jerry_string_to_utf8_char_buffer (value, str_buf_p, req_sz);
1402+
1403+ jerry_release_value (value);
1404+ }
1405+ ```
1406+
1407+ **See also**
1408+
1409+ - [jerry_create_string_from_utf8](#jerrycreatestringfromutf8)
1410+ - [jerry_get_utf8_string_size](#jerrygetutf8stringsize)
12431411
12441412# Functions for array object values
12451413
@@ -1990,6 +2158,80 @@ jerry_create_string_sz (const jerry_char_t *str_p,
19902158
19912159- [jerry_create_string](#jerrycreatestring)
19922160
2161+ ## jerry_create_string_from_utf8
2162+
2163+ **Summary**
2164+
2165+ Create string from a valid UTF8 string.
2166+
2167+ *Note*: The difference from [jerry_create_string](#jerrycreatestring) is that it accepts utf-8 string instead of cesu-8 string.
2168+
2169+ **Prototype**
2170+
2171+ ```c
2172+ jerry_value_t
2173+ jerry_create_string_from_utf8 (const jerry_char_t *str_p);
2174+ ```
2175+
2176+ - `str_p` - pointer to string
2177+ - return value - value of the created string
2178+
2179+ **Example**
2180+
2181+ ```c
2182+ {
2183+ const jerry_char_t char_array[] = "a string";
2184+ jerry_value_t string_value = jerry_create_string_from_utf8 (char_array);
2185+
2186+ ... // usage of string_value
2187+
2188+ jerry_release_value (string_value);
2189+ }
2190+ ```
2191+
2192+ **See also**
2193+
2194+ - [jerry_create_string_sz_from_utf8](#jerrycreatestringszfromutf8)
2195+
2196+
2197+ ## jerry_create_string_sz_from_utf8
2198+
2199+ **Summary**
2200+
2201+ Create string from a valid UTF8 string.
2202+
2203+ *Note*: The difference from [jerry_create_string_sz](#jerrycreatestringsz) is that it accepts utf-8 string instead of cesu-8 string.
2204+
2205+ **Prototype**
2206+
2207+ ```c
2208+ jerry_value_t
2209+ jerry_create_string_sz (const jerry_char_t *str_p,
2210+ jerry_size_t str_size)
2211+ ```
2212+
2213+ - `str_p` - pointer to string
2214+ - `str_size` - size of the string
2215+ - return value - value of the created string
2216+
2217+ **Example**
2218+
2219+ ```c
2220+ {
2221+ const jerry_char_t char_array[] = "a string";
2222+ jerry_value_t string_value = jerry_create_string_sz_from_utf8 (char_array,
2223+ strlen ((const char *) char_array));
2224+
2225+ ... // usage of string_value
2226+
2227+ jerry_release_value (string_value);
2228+ }
2229+
2230+ ```
2231+
2232+ **See also**
2233+
2234+ - [jerry_create_string_from_utf8](#jerrycreatestringfromutf8)
19932235
19942236## jerry_create_undefined
19952237
@@ -3018,3 +3260,67 @@ jerry_exec_snapshot (const void *snapshot_p,
30183260- [jerry_init](#jerryinit)
30193261- [jerry_cleanup](#jerrycleanup)
30203262- [jerry_parse_and_save_snapshot](#jerryparseandsavesnapshot)
3263+
3264+
3265+ ## jerry_parse_and_save_literals
3266+
3267+ **Summary**
3268+
3269+ Collect the used literals from the given source code and save them into a specific file in a list or C format.
3270+ These literals are generated by the parser, they are valid identifiers and none of them are magic string.
3271+
3272+ **Prototype**
3273+
3274+ ```c
3275+ size_t
3276+ jerry_parse_and_save_literals (const jerry_char_t *source_p,
3277+ size_t source_size,
3278+ bool is_strict,
3279+ uint8_t *buffer_p,
3280+ size_t buffer_size,
3281+ bool is_c_format);
3282+ ```
3283+
3284+ - `source_p` - script source, it must be a valid utf8 string.
3285+ - `source_size` - script source size, in bytes.
3286+ - `is_strict` - strict mode.
3287+ - `buffer_p` - buffer to save literals to.
3288+ - `buffer_size` - the buffer's size.
3289+ - `is_c_format` - the output format would be C-style (true) or a simple list (false).
3290+ - return value
3291+ - the size of the literal-list, if it was generated succesfully (i.e. the list of literals isn't empty,
3292+ and literal-save support is enabled in current configuration through JERRY_ENABLE_SNAPSHOT_SAVE)
3293+ - 0 otherwise.
3294+
3295+ **Example**
3296+
3297+ ```c
3298+ {
3299+ jerry_init (JERRY_INIT_EMPTY);
3300+
3301+ static uint8_t save_literal_buffer[1024];
3302+ const jerry_char_t *code_for_literal_save_p = "var obj = { a:'aa', bb:'Bb' }";
3303+
3304+ size_t literal_sizes = jerry_parse_and_save_literals (code_for_literal_save_p,
3305+ strlen ((const char *) code_for_literal_save_p),
3306+ false,
3307+ save_literal_buffer,
3308+ sizeof (save_literal_buffer),
3309+ true);
3310+
3311+ if (literal_sizes != 0)
3312+ {
3313+ FILE *literal_file_p = fopen ("literals.txt", "w");
3314+ fwrite (save_literal_buffer, sizeof (uint8_t), literal_sizes, literal_file_p);
3315+ fclose (literal_file_p);
3316+ }
3317+
3318+ jerry_cleanup ();
3319+ }
3320+ ```
3321+
3322+ **See also**
3323+
3324+ - [jerry_init](#jerryinit)
3325+ - [jerry_cleanup](#jerrycleanup)
3326+ - [jerry_register_magic_strings](#jerryregistermagicstrings)
0 commit comments