Rework jerry_parse function. (#2282)

Remove jerry_parse_named_resource, merge its arguments to jerry_parse
and change is_strict argument to an option list for possible future extensions.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2018-04-17 09:51:52 +02:00
committed by GitHub
parent 3f3d4a64f1
commit 96b528a486
19 changed files with 146 additions and 146 deletions
+24 -45
View File
@@ -59,6 +59,14 @@ Possible compile time enabled feature types:
- JERRY_FEATURE_DATE - Date support
- JERRY_FEATURE_REGEXP - RegExp support
## jerry_parse_opts_t
Option bits for [jerry_parse](#jerry_parse) and
[jerry_parse_function](#jerry_parse_function) functions:
- JERRY_PARSE_NO_OPTS - no options passed
- JERRY_PARSE_STRICT_MODE - enable strict mode
## jerry_generate_snapshot_opts_t
Flags for [jerry_generate_snapshot](#jerry_generate_snapshot) and
@@ -806,8 +814,9 @@ main (void)
**Summary**
Parse script and construct an EcmaScript function. The
lexical environment is set to the global lexical environment.
Parse script and construct an EcmaScript function. The lexical environment is
set to the global lexical environment. The resource name can be used by
debugging systems to provide line / backtrace info.
*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
@@ -816,14 +825,18 @@ is no longer needed.
```c
jerry_value_t
jerry_parse (const jerry_char_t *source_p,
jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a file name) */
size_t resource_name_length, /**< length of resource name */
const jerry_char_t *source_p,
size_t source_size,
bool is_strict);
uint32_t parse_opts);
```
- `resource_name_p` - resource name, usually a file name (must be a valid UTF8 string).
- `resource_name_length` - size of the resource name, in bytes.
- `source_p` - string, containing source code to parse (must be a valid UTF8 string).
- `source_size` - size of the string, in bytes.
- `is_strict` - defines strict mode.
- `parse_opts` - any combination of [jerry_parse_opts_t](#jerry_parse_opts_t) flags.
- return value
- function object value, if script was parsed successfully,
- thrown error, otherwise
@@ -844,7 +857,7 @@ main (void)
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_release_value (parsed_code);
jerry_cleanup ();
@@ -855,40 +868,6 @@ main (void)
- [jerry_run](#jerry_run)
## jerry_parse_named_resource
**Summary**
Parse script and construct an ECMAScript function. The lexical
environment is set to the global lexical environment. The resource
name (usually a file name) is also passed to this function which is
used by the debugger to find the source code.
*Note*: The returned value must be freed with [jerry_release_value](#jerry_release_value) when it
is no longer needed.
**Prototype**
```c
jerry_value_t
jerry_parse_named_resource (const jerry_char_t *resource_name_p, /**< resource name (usually a file name) */
size_t resource_name_length, /**< length of resource name */
const jerry_char_t *source_p, /**< script source */
size_t source_size, /**< script source size */
bool is_strict) /**< strict mode */
```
- `resource_name_p` - resource name, usually a file name (must be a valid UTF8 string).
- `resource_name_length` - size of the resource name, in bytes.
- `source_p` - string, containing source code to parse (must be a valid UTF8 string).
- `source_size` - size of the string, in bytes.
- `is_strict` - defines strict mode.
- return value
- function object value, if script was parsed successfully,
- thrown error, otherwise
This function is identical to [jerry_parse](#jerry_parse), except that an additional filename parameter has been added.
## jerry_parse_function
**Summary**
@@ -913,7 +892,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
size_t arg_list_size, /**< script source size */
const jerry_char_t *source_p, /**< script source */
size_t source_size, /**< script source size */
bool is_strict) /**< strict mode */
uint32_t parse_opts) /**< strict mode */
```
- `resource_name_p` - resource name, usually a file name (must be a valid UTF8 string).
@@ -922,7 +901,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
- `arg_list_size` - size of the argument list, in bytes.
- `source_p` - string, containing source code to parse (must be a valid UTF8 string).
- `source_size` - size of the string, in bytes.
- `is_strict` - defines strict mode.
- `parse_opts` - any combination of [jerry_parse_opts_t](#jerry_parse_opts_t) flags.
- return value
- function object value, if script was parsed successfully,
- thrown error, otherwise
@@ -965,7 +944,7 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);
/* Setup Global scope code */
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
if (!jerry_value_has_error_flag (parsed_code))
{
@@ -1055,7 +1034,7 @@ main (void)
const jerry_char_t script[] = "new Promise(function(f,r) { f('Hello, World!'); }).then(function(x) { print(x); });";
size_t script_size = strlen ((const char *) script);
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t script_value = jerry_run (parsed_code);
jerry_value_t job_value = jerry_run_all_enqueued_jobs ();
@@ -5440,7 +5419,7 @@ main (void)
// Inifinte loop.
const char *src_p = "while(true) {}";
jerry_value_t src = jerry_parse ((jerry_char_t *) src_p, strlen (src_p), false);
jerry_value_t src = jerry_parse (NULL, 0, (jerry_char_t *) src_p, strlen (src_p), JERRY_PARSE_NO_OPTS);
jerry_release_value (jerry_run (src));
jerry_release_value (src);
jerry_cleanup ();
+1 -1
View File
@@ -55,7 +55,7 @@ main (void)
jerryx_handler_print);
/* Setup Global scope code */
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
if (!jerry_value_has_error_flag (parsed_code))
{
+8 -13
View File
@@ -69,14 +69,9 @@ The debugger can be enabled by calling the `jerry_debugger_init (uint16_t port)`
function after the `jerry_init ()` function. It initializes the debugger
and blocks until a client connects.
When the debugger is enabled it is recommended to use
`jerry_parse_named_resource ()` instead of `jerry_parse ()` because
the resource name (usually a file name) is also passed to this
function. This resource name is used by the client to identify
the corresponding resource. In general it is always recommended to
use `jerry_parse_named_resource ()` when the resource name is
available because it silently ignores the resource name if the
debugger is disabled.
The resource name provided to `jerry_parse ()` is used by the client
to identify the resource name of the source code. This resource name
is usually a file name.
## JerryScript debugger C-API interface
@@ -304,11 +299,11 @@ wait_for_source_callback (const jerry_char_t *resource_name_p, /**< resource nam
size_t source_size, /**< source code size */
void *user_p __attribute__((unused))) /**< user pointer */
{
jerry_value_t ret_val = jerry_parse_named_resource (resource_name_p,
resource_name_size,
source_p,
source_size,
false);
jerry_value_t ret_val = jerry_parse (resource_name_p,
resource_name_size,
source_p,
source_size,
JERRY_PARSE_NO_OPTS);
if (!jerry_value_has_error_flag (ret_val))
{