diff --git a/docs/c-api/exec_public.h/intro.md b/docs/c-api/exec_public.h/intro.md index 11fee7ddf..a645005b2 100644 --- a/docs/c-api/exec_public.h/intro.md +++ b/docs/c-api/exec_public.h/intro.md @@ -5,6 +5,7 @@ decl_name: "exec_public.h" items: - { name: v7_exec.md } - { name: v7_exec_opt.md } + - { name: v7_exec_buf.md } - { name: v7_exec_file.md } - { name: v7_parse_json.md } - { name: v7_parse_json_file.md } diff --git a/docs/c-api/exec_public.h/v7_exec.md b/docs/c-api/exec_public.h/v7_exec.md index a594bddd4..d7ac198e1 100644 --- a/docs/c-api/exec_public.h/v7_exec.md +++ b/docs/c-api/exec_public.h/v7_exec.md @@ -8,6 +8,7 @@ signature: | 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: diff --git a/docs/c-api/exec_public.h/v7_exec_buf.md b/docs/c-api/exec_public.h/v7_exec_buf.md new file mode 100644 index 000000000..1b8142be2 --- /dev/null +++ b/docs/c-api/exec_public.h/v7_exec_buf.md @@ -0,0 +1,14 @@ +--- +title: "v7_exec_buf()" +decl_name: "v7_exec_buf" +symbol_kind: "func" +signature: | + enum v7_err v7_exec_buf(struct v7 *v7, const char *js_code, size_t len, + v7_val_t *result); +--- + +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. + diff --git a/v7.c b/v7.c index 277692fab..09c47a498 100644 --- a/v7.c +++ b/v7.c @@ -338,12 +338,24 @@ typedef struct _stati64 cs_stat_t; #include #include +#ifdef __APPLE__ +#include +#ifndef BYTE_ORDER +#define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN +#define BIG_ENDIAN __DARWIN_BIG_ENDIAN +#define PDP_ENDIAN __DARWIN_PDP_ENDIAN +#define BYTE_ORDER __DARWIN_BYTE_ORDER +#endif +#endif + /* * osx correctly avoids defining strtoll when compiling in strict ansi mode. + * c++ 11 standard defines strtoll as well. * We require strtoll, and if your embedded pre-c99 compiler lacks one, please * implement a shim. */ -#if !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200809L) +#if !(defined(__cplusplus) && __cplusplus >= 201103L) && \ + !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200809L) long long strtoll(const char *, char **, int); #endif @@ -871,6 +883,10 @@ struct timeval { #if MG_NET_IF == MG_NET_IF_SIMPLELINK +#define MG_SIMPLELINK_NO_OSI 1 + +#include + typedef int sock_t; #define INVALID_SOCKET (-1) @@ -908,6 +924,8 @@ int inet_pton(int af, const char *src, void *dst); #include #include +#define to64(x) strtoll(x, NULL, 10) + #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_PROVIDE_ERRNO 1 @@ -5383,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: * @@ -5423,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. */ @@ -17579,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); diff --git a/v7.h b/v7.h index 79966b00b..6e46cf314 100644 --- a/v7.h +++ b/v7.h @@ -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: * @@ -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. */