[njs] Added shortcuts for creating errors from the outside of a VM.

Dmitry Volyntsev xeioex at nginx.com
Mon Apr 9 18:02:48 UTC 2018


details:   http://hg.nginx.org/njs/rev/4466799a4231
branches:  
changeset: 496:4466799a4231
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Apr 09 21:02:10 2018 +0300
description:
Added shortcuts for creating errors from the outside of a VM.

njs_vm_error(), njs_vm_memory_error().

diffstat:

 njs/njscript.c |  7 +++++++
 njs/njscript.h |  5 +++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r 4f3424b390bd -r 4466799a4231 njs/njscript.c
--- a/njs/njscript.c	Thu Apr 05 19:06:35 2018 +0300
+++ b/njs/njscript.c	Mon Apr 09 21:02:10 2018 +0300
@@ -682,6 +682,13 @@ njs_vm_retval_set(njs_vm_t *vm, njs_opaq
 }
 
 
+nxt_noinline void
+njs_vm_memory_error(njs_vm_t *vm)
+{
+    njs_set_memory_error(vm, &vm->retval);
+}
+
+
 njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *retval)
 {
     if (vm->top_frame == NULL) {
diff -r 4f3424b390bd -r 4466799a4231 njs/njscript.h
--- a/njs/njscript.h	Thu Apr 05 19:06:35 2018 +0300
+++ b/njs/njscript.h	Mon Apr 09 21:02:10 2018 +0300
@@ -29,6 +29,9 @@ typedef struct {
 #define njs_argument(args, n)                                                 \
     (njs_value_t *) ((u_char *) args + n * 16)
 
+#define njs_vm_error(vm, fmt, ...)                                            \
+    njs_value_error_set(vm, njs_vm_retval(vm), fmt, ##__VA_ARGS__)
+
 
 typedef njs_ret_t (*njs_extern_get_t)(njs_vm_t *vm, njs_value_t *value,
     void *obj, uintptr_t data);
@@ -176,6 +179,8 @@ NXT_EXPORT njs_ret_t njs_vm_value_to_ext
 NXT_EXPORT njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm,
         nxt_str_t *retval);
 
+NXT_EXPORT void njs_vm_memory_error(njs_vm_t *vm);
+
 NXT_EXPORT void njs_value_void_set(njs_value_t *value);
 NXT_EXPORT void njs_value_boolean_set(njs_value_t *value, int yn);
 NXT_EXPORT void njs_value_number_set(njs_value_t *value, double num);


More information about the nginx-devel mailing list