Skip to content

Commit

Permalink
Expose a non nul-terminated exec
Browse files Browse the repository at this point in the history
Requested in cesanta/v7#576

PUBLISHED_FROM=f950c3ef6db3d69a54e1588544f6f84570584a66
  • Loading branch information
Marko Mikulicic authored and cesantabot committed Oct 25, 2016
1 parent 95b87af commit 3d65589
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions v7/v7.c
Original file line number Diff line number Diff line change
Expand Up @@ -5401,6 +5401,7 @@ extern "C" {
/*
* Execute JavaScript `js_code`. The result of evaluation is stored in
* the `result` variable.
* The code can be either a JavaScript source or a precompiled bytecode.
*
* Return:
*
Expand Down Expand Up @@ -5441,6 +5442,16 @@ struct v7_exec_opts {
enum v7_err v7_exec_opt(struct v7 *v7, const char *js_code,
const struct v7_exec_opts *opts, v7_val_t *res);

/*
* Like v7_exec but it expects an explicit length instead of treating the code
* as a null terminated string.
*
* The code can be either a JS source or a precompiled bytecode.
*/
WARN_UNUSED_RESULT
enum v7_err v7_exec_buf(struct v7 *v7, const char *js_code, size_t len,
v7_val_t *result);

/*
* Same as `v7_exec()`, but loads source code from `path` file.
*/
Expand Down Expand Up @@ -17597,6 +17608,12 @@ enum v7_err v7_exec_opt(struct v7 *v7, const char *js_code,
opts->is_json, 0, 0, res);
}

enum v7_err v7_exec_buf(struct v7 *v7, const char *js_code, size_t len,
v7_val_t *res) {
return b_exec(v7, js_code, len, NULL, V7_UNDEFINED, V7_UNDEFINED,
V7_UNDEFINED, 0, 0, 0, res);
}

enum v7_err v7_parse_json(struct v7 *v7, const char *str, v7_val_t *res) {
return b_exec(v7, str, strlen(str), NULL, V7_UNDEFINED, V7_UNDEFINED,
V7_UNDEFINED, 1, 0, 0, res);
Expand Down
11 changes: 11 additions & 0 deletions v7/v7.h
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,7 @@ extern "C" {
/*
* Execute JavaScript `js_code`. The result of evaluation is stored in
* the `result` variable.
* The code can be either a JavaScript source or a precompiled bytecode.
*
* Return:
*
Expand Down Expand Up @@ -1771,6 +1772,16 @@ struct v7_exec_opts {
enum v7_err v7_exec_opt(struct v7 *v7, const char *js_code,
const struct v7_exec_opts *opts, v7_val_t *res);

/*
* Like v7_exec but it expects an explicit length instead of treating the code
* as a null terminated string.
*
* The code can be either a JS source or a precompiled bytecode.
*/
WARN_UNUSED_RESULT
enum v7_err v7_exec_buf(struct v7 *v7, const char *js_code, size_t len,
v7_val_t *result);

/*
* Same as `v7_exec()`, but loads source code from `path` file.
*/
Expand Down

0 comments on commit 3d65589

Please sign in to comment.