Skip to content

Commit 1c6b18e

Browse files
authored
Add missing info in API doc (#4733)
As a few methods were removed and replaced it is a good idea to describe which method(s) can reproduce the same functionality. In addition add a bit of extra comments for various methods/structs. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com
1 parent bf049fb commit 1c6b18e

File tree

2 files changed

+58
-18
lines changed

2 files changed

+58
-18
lines changed

docs/02.API-REFERENCE.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ Enum that contains JerryScript **object** value types:
6767

6868
*New in version 2.4*.
6969

70-
*Changed in version [[NEXT_RELEASE]]*: Added `JERRY_OBJECT_TYPE_SCRIPT`, `JERRY_OBJECT_TYPE_MODULE` values.
70+
*Changed in version [[NEXT_RELEASE]]*: Added `JERRY_OBJECT_TYPE_MODULE_NAMESPACE`, `JERRY_OBJECT_TYPE_PROMISE`, `JERRY_OBJECT_TYPE_DATAVIEW`,
71+
`JERRY_OBJECT_TYPE_ERROR`, `JERRY_OBJECT_TYPE_SHARED_ARRAYBUFFER`, `JERRY_OBJECT_TYPE_WEAKREF`,
72+
`JERRY_OBJECT_TYPE_SCRIPT`, and `JERRY_OBJECT_TYPE_MODULE` values.
7173

7274
## jerry_function_type_t
7375

@@ -180,7 +182,8 @@ Possible compile time enabled feature types:
180182

181183
*Changed in version 2.4*: Added `JERRY_FEATURE_BIGINT`, `JERRY_FEATURE_REALM` values.
182184

183-
*Changed in version [[NEXT_RELEASE]]*: Added `JERRY_FEATURE_GLOBAL_THIS`, `JERRY_FEATURE_PROMISE_CALLBACK`, `JERRY_FEATURE_MODULE` values.
185+
*Changed in version [[NEXT_RELEASE]]*: Added `JERRY_FEATURE_VM_THROW`, `JERRY_FEATURE_GLOBAL_THIS`,
186+
`JERRY_FEATURE_PROMISE_CALLBACK`, and `JERRY_FEATURE_MODULE` values.
184187

185188
## jerry_container_type_t
186189

@@ -243,13 +246,16 @@ Option bits for [jerry_parse_options_t](#jerry_parse_options_t).
243246
- JERRY_PARSE_NO_OPTS - No options passed
244247
- JERRY_PARSE_STRICT_MODE - Enable strict mode
245248
- JERRY_PARSE_MODULE - Parse source as an ECMAScript module
246-
- JERRY_PARSE_HAS_ARGUMENT_LIST - `argument_list` field is valid
249+
- JERRY_PARSE_HAS_ARGUMENT_LIST - `argument_list` field is valid, this also means that function parsing will be done
247250
- JERRY_PARSE_HAS_RESOURCE - `resource_name` field is valid
248251
- JERRY_PARSE_HAS_START - `start_line` and `start_column` fields are valid
249252
- JERRY_PARSE_HAS_USER_VALUE - `user_value` field is valid
250253

251254
*New in version [[NEXT_RELEASE]]*.
252255

256+
Using both `JERRY_PARSE_MODULE` and `JERRY_PARSE_HAS_ARGUMENT_LIST` is an invalid combination and will result in
257+
an error during parsing.
258+
253259
**See also**
254260

255261
- [jerry_parse_options_t](#jerry_parse_options_t)
@@ -304,6 +310,7 @@ when the snapshot is generated and executed. Furthermore the
304310
`JERRY_SNAPSHOT_EXEC_COPY_DATA` option is not allowed.
305311

306312
*New in version 2.0*.
313+
307314
*Changed in version [[NEXT_RELEASE]]*: The `JERRY_SNAPSHOT_SAVE_STRICT` value is removed, `JERRY_PARSE_STRICT_MODE` should be used instead.
308315

309316
## jerry_exec_snapshot_opts_t
@@ -594,6 +601,11 @@ typedef struct
594601
} jerry_property_descriptor_t;
595602
```
596603

604+
*Changed in version [[NEXT_RELEASE]]*: The `is_value_defined`, `is_get_defined`, `is_set_defined`,
605+
`is_writable_defined`, `is_writable`, `is_enumerable_defined`,
606+
`is_enumerable`, `is_configurable_defined`, and `is_configurable`
607+
fields are replaced by the `flags` field.
608+
597609
**See also**
598610

599611
- [jerry_property_descriptor_flags_t](#jerry_property_descriptor_flags_t)
@@ -686,7 +698,7 @@ typedef struct jerry_call_info_t
686698
} jerry_call_info_t;
687699
```
688700

689-
*New in version [[NEXT_RELEASE]]*.
701+
*New in version [[NEXT_RELEASE]]*. Contents of this struct replaces the `jerry_get_new_target` function.
690702

691703
**See also**
692704

@@ -1745,11 +1757,13 @@ jerry_parse (const jerry_char_t *source_p,
17451757
- thrown error, otherwise
17461758

17471759
*Changed in version 2.0*: Added `resource_name_p`, and `resource_name_length` arguments.
1760+
17481761
*Changed in version [[NEXT_RELEASE]]*: The `resource_name_p`, `resource_name_length`, and `parse_opts` arguments are replaced by `options_p`.
1762+
This function replaces the `jerry_parse_function` method.
17491763

1750-
**Example**
1764+
**Example 1**
17511765

1752-
[doctest]: # ()
1766+
[doctest]: # (name="02.API-REFERENCE-parse-simple.c")
17531767

17541768
```c
17551769
#include "jerryscript.h"
@@ -1772,26 +1786,51 @@ main (void)
17721786
jerry_value_t parsed_code = jerry_parse (script, sizeof (script) - 1, &parse_options);
17731787
jerry_release_value (parse_options.resource_name);
17741788

1789+
/* Run the "parsed_code" script with "jerry_run". */
1790+
17751791
jerry_release_value (jerry_run (parsed_code));
17761792
jerry_release_value (parsed_code);
17771793

1778-
/* Parsing a function. */
1794+
jerry_cleanup ();
1795+
return 0;
1796+
}
1797+
```
1798+
1799+
**Example - function parsing**
1800+
1801+
[doctest]: # (name="02.API-REFERENCE-parse-function.c")
1802+
1803+
```c
1804+
#include "jerryscript.h"
1805+
1806+
int
1807+
main (void)
1808+
{
1809+
jerry_init (JERRY_INIT_EMPTY);
1810+
1811+
/* Specifly the argument list to parse a function. */
1812+
jerry_parse_options_t parse_options;
17791813
parse_options.options = JERRY_PARSE_HAS_ARGUMENT_LIST;
17801814
parse_options.argument_list = jerry_create_string ((const jerry_char_t *) "a, b");
17811815

17821816
const jerry_char_t function_code[] = "return a + b;";
17831817
jerry_value_t parsed_function = jerry_parse (function_code, sizeof (function_code) - 1, &parse_options);
17841818
jerry_release_value (parse_options.argument_list);
17851819

1820+
/* Use the "parsed_function" as a normal JavaScript function. */
1821+
17861822
jerry_value_t args[] = {
17871823
jerry_create_number (3),
17881824
jerry_create_number (4),
17891825
};
17901826
jerry_size_t argc = sizeof (args) / sizeof (args[0]);
1791-
jerry_release_value (jerry_call_function (parsed_function,
1792-
jerry_create_undefined(),
1793-
args,
1794-
argc));
1827+
jerry_value_t call_result = jerry_call_function (parsed_function,
1828+
jerry_create_undefined(),
1829+
args,
1830+
argc);
1831+
1832+
/* use the function result */
1833+
jerry_release_value (call_result);
17951834
jerry_release_value (parsed_function);
17961835

17971836
jerry_cleanup ();
@@ -2312,7 +2351,7 @@ jerry_value_is_true (const jerry_value_t value);
23122351
- true, if the given `jerry_value_t` is true value
23132352
- false, otherwise
23142353

2315-
*New in version [[NEXT_RELEASE]]*.
2354+
*New in version [[NEXT_RELEASE]]*. Replaces the `jerry_value_is_boolean` method.
23162355

23172356
**Example**
23182357

@@ -2352,7 +2391,7 @@ jerry_value_is_false (const jerry_value_t value);
23522391
- true, if the given `jerry_value_t` is false value
23532392
- false, otherwise
23542393

2355-
*New in version [[NEXT_RELEASE]]*.
2394+
*New in version [[NEXT_RELEASE]]*. Replaces the `jerry_value_is_boolean` method.
23562395

23572396
**Example**
23582397

@@ -6656,8 +6695,6 @@ jerry_create_shared_arraybuffer_external (const jerry_length_t size
66566695

66576696
*New in version [[NEXT_RELEASE]]*.
66586697

6659-
*Changed in version [[NEXT_RELEASE]]*: type of `free_cb` has been changed.
6660-
66616698
**Example**
66626699

66636700
```c
@@ -9060,7 +9097,7 @@ jerry_get_own_property_descriptor (const jerry_value_t obj_val,
90609097
- `prop_desc_p` - pointer to property descriptor
90619098
- return value
90629099

9063-
*Changed in version [[NEXT_RELEASE]]*: return value is changed to `jerry_value_t`
9100+
*Changed in version [[NEXT_RELEASE]]*: Return value type is changed to `jerry_value_t`.
90649101

90659102
**Example**
90669103

@@ -10589,7 +10626,9 @@ jerry_generate_snapshot (jerry_value_t compiled_code,
1058910626
*Changed in version [[NEXT_RELEASE]]*: The `source_p`, `source_size`, `resource_name_p`,
1059010627
and `resource_name_length` arguments are replaced by `compiled_code`
1059110628
which should contain a compiled ECMAScript script / function.
10592-
10629+
The `jerry_generate_function_snapshot` is now removed and can be reproduced
10630+
by calling `jerry_parse` with function arguments and using this method
10631+
(see [jerry_exec_snapshot](#jerry_exec_snapshot)).
1059310632
**Example**
1059410633

1059510634
[doctest]: # ()

jerry-core/include/jerryscript-types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ typedef enum
167167
JERRY_PARSE_NO_OPTS = 0, /**< no options passed */
168168
JERRY_PARSE_STRICT_MODE = (1 << 0), /**< enable strict mode */
169169
JERRY_PARSE_MODULE = (1 << 1), /**< parse source as an ECMAScript module */
170-
JERRY_PARSE_HAS_ARGUMENT_LIST = (1 << 2), /**< argument_list field is valid */
170+
JERRY_PARSE_HAS_ARGUMENT_LIST = (1 << 2), /**< argument_list field is valid,
171+
* this also means that function parsing will be done */
171172
JERRY_PARSE_HAS_RESOURCE = (1 << 3), /**< resource_name field is valid */
172173
JERRY_PARSE_HAS_START = (1 << 4), /**< start_line and start_column fields are valid */
173174
JERRY_PARSE_HAS_USER_VALUE = (1 << 5), /**< user_value field is valid */

0 commit comments

Comments
 (0)