[njs] The njs_vm_trap_value() macro.

Igor Sysoev igor at sysoev.ru
Tue Mar 28 16:24:57 UTC 2017


details:   http://hg.nginx.org/njs/rev/8e1030bce13c
branches:  
changeset: 319:8e1030bce13c
user:      Igor Sysoev <igor at sysoev.ru>
date:      Tue Mar 21 16:35:36 2017 +0300
description:
The njs_vm_trap_value() macro.

diffstat:

 njs/njs_array.c    |  4 ++--
 njs/njs_date.c     |  4 ++--
 njs/njs_function.h |  5 +++++
 njs/njs_math.c     |  6 +++---
 njs/njs_string.c   |  4 ++--
 njs/njs_vm.c       |  2 +-
 6 files changed, 15 insertions(+), 10 deletions(-)

diffs (120 lines):

diff -r 705129b55888 -r 8e1030bce13c njs/njs_array.c
--- a/njs/njs_array.c	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_array.c	Tue Mar 21 16:35:36 2017 +0300
@@ -840,7 +840,7 @@ njs_array_prototype_join_continuation(nj
                 value = &values[n++];
 
                 if (!njs_is_string(value)) {
-                    vm->frame->trap_scratch.data.u.value = value;
+                    njs_vm_trap_value(vm, value);
 
                     return NJS_TRAP_STRING_ARG;
                 }
@@ -1733,7 +1733,7 @@ njs_array_string_sort(njs_vm_t *vm, njs_
 
     for (i = 1; i < nargs; i++) {
         if (!njs_is_string(&args[i])) {
-            vm->frame->trap_scratch.data.u.value = &args[i];
+            njs_vm_trap_value(vm, &args[i]);
             return NJS_TRAP_STRING_ARG;
         }
     }
diff -r 705129b55888 -r 8e1030bce13c njs/njs_date.c
--- a/njs/njs_date.c	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_date.c	Tue Mar 21 16:35:36 2017 +0300
@@ -108,7 +108,7 @@ njs_date_constructor(njs_vm_t *vm, njs_v
 
             for (i = 1; i < n; i++) {
                 if (!njs_is_numeric(&args[i])) {
-                    vm->frame->trap_scratch.data.u.value = &args[i];
+                    njs_vm_trap_value(vm, &args[i]);
                     return NJS_TRAP_NUMBER_ARG;
                 }
 
@@ -187,7 +187,7 @@ njs_date_utc(njs_vm_t *vm, njs_value_t *
 
         for (i = 1; i < n; i++) {
             if (!njs_is_numeric(&args[i])) {
-                vm->frame->trap_scratch.data.u.value = &args[i];
+                njs_vm_trap_value(vm, &args[i]);
                 return NJS_TRAP_NUMBER_ARG;
             }
 
diff -r 705129b55888 -r 8e1030bce13c njs/njs_function.h
--- a/njs/njs_function.h	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_function.h	Tue Mar 21 16:35:36 2017 +0300
@@ -68,6 +68,11 @@ typedef struct {
 #define NJS_CONTINUATION_SIZE      njs_continuation_size(njs_continuation_t)
 
 
+#define njs_vm_trap_value(vm, val)                                            \
+    (vm)->frame->trap_scratch.data.u.value = val
+
+
+
 typedef struct njs_exception_s     njs_exception_t;
 
 struct njs_exception_s {
diff -r 705129b55888 -r 8e1030bce13c njs/njs_math.c
--- a/njs/njs_math.c	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_math.c	Tue Mar 21 16:35:36 2017 +0300
@@ -376,7 +376,7 @@ njs_object_math_hypot(njs_vm_t *vm, njs_
 
     for (i = 1; i < nargs; i++) {
         if (!njs_is_numeric(&args[i])) {
-            vm->frame->trap_scratch.data.u.value = &args[i];
+            njs_vm_trap_value(vm, &args[i]);
 
             return NJS_TRAP_NUMBER_ARG;
         }
@@ -516,7 +516,7 @@ njs_object_math_max(njs_vm_t *vm, njs_va
     if (nargs > 1) {
         for (i = 1; i < nargs; i++) {
             if (!njs_is_numeric(&args[i])) {
-                vm->frame->trap_scratch.data.u.value = &args[i];
+                njs_vm_trap_value(vm, &args[i]);
                 return NJS_TRAP_NUMBER_ARG;
             }
         }
@@ -547,7 +547,7 @@ njs_object_math_min(njs_vm_t *vm, njs_va
     if (nargs > 1) {
         for (i = 1; i < nargs; i++) {
             if (!njs_is_numeric(&args[i])) {
-                vm->frame->trap_scratch.data.u.value = &args[i];
+                njs_vm_trap_value(vm, &args[i]);
                 return NJS_TRAP_NUMBER_ARG;
             }
         }
diff -r 705129b55888 -r 8e1030bce13c njs/njs_string.c
--- a/njs/njs_string.c	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_string.c	Tue Mar 21 16:35:36 2017 +0300
@@ -581,7 +581,7 @@ njs_string_prototype_concat(njs_vm_t *vm
 
     for (i = 0; i < nargs; i++) {
         if (!njs_is_string(&args[i])) {
-            vm->frame->trap_scratch.data.u.value = &args[i];
+            njs_vm_trap_value(vm, &args[i]);
 
             return NJS_TRAP_STRING_ARG;
         }
@@ -1130,7 +1130,7 @@ njs_string_from_char_code(njs_vm_t *vm, 
 
     for (i = 1; i < nargs; i++) {
         if (!njs_is_numeric(&args[i])) {
-            vm->frame->trap_scratch.data.u.value = &args[i];
+            njs_vm_trap_value(vm, &args[i]);
             return NJS_TRAP_NUMBER_ARG;
         }
     }
diff -r 705129b55888 -r 8e1030bce13c njs/njs_vm.c
--- a/njs/njs_vm.c	Tue Mar 21 16:35:22 2017 +0300
+++ b/njs/njs_vm.c	Tue Mar 21 16:35:36 2017 +0300
@@ -2518,7 +2518,7 @@ njs_normalize_args(njs_vm_t *vm, njs_val
 
 trap:
 
-    vm->frame->trap_scratch.data.u.value = args;
+    njs_vm_trap_value(vm, args);
 
     return trap;
 


More information about the nginx-devel mailing list