[njs] Introduced njs_object_property_descriptor().

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 28 18:27:14 UTC 2019


details:   https://hg.nginx.org/njs/rev/3033faf46265
branches:  
changeset: 859:3033faf46265
user:      Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date:      Wed Mar 27 20:45:39 2019 +0300
description:
Introduced njs_object_property_descriptor().

diffstat:

 njs/njs_object.c |  44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diffs (81 lines):

diff -r 2251d61554ac -r 3033faf46265 njs/njs_object.c
--- a/njs/njs_object.c	Thu Mar 28 20:42:11 2019 +0300
+++ b/njs/njs_object.c	Wed Mar 27 20:45:39 2019 +0300
@@ -1610,26 +1610,16 @@ static const njs_value_t  njs_object_wri
 
 
 static njs_ret_t
-njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args,
-    nxt_uint_t nargs, njs_index_t unused)
+njs_object_property_descriptor(njs_vm_t *vm, njs_value_t *dest,
+    const njs_value_t *value, const njs_value_t *property)
 {
     nxt_int_t             ret;
     njs_object_t          *descriptor;
     njs_object_prop_t     *pr, *prop;
-    const njs_value_t     *value, *property, *setval;
+    const njs_value_t     *setval;
     nxt_lvlhsh_query_t    lhq;
     njs_property_query_t  pq;
 
-    value = njs_arg(args, nargs, 1);
-
-    if (njs_is_null_or_undefined(value)) {
-        njs_type_error(vm, "cannot convert %s argument to object",
-                       njs_type_string(value->type));
-        return NXT_ERROR;
-    }
-
-    property = njs_arg(args, nargs, 2);
-
     njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
 
     ret = njs_property_query(vm, &pq, (njs_value_t *) value, property);
@@ -1639,7 +1629,7 @@ njs_object_get_own_property_descriptor(n
         break;
 
     case NXT_DECLINED:
-        vm->retval = njs_value_undefined;
+        *dest = njs_value_undefined;
         return NXT_OK;
 
     case NJS_TRAP:
@@ -1764,15 +1754,35 @@ njs_object_get_own_property_descriptor(n
         return NXT_ERROR;
     }
 
-    vm->retval.data.u.object = descriptor;
-    vm->retval.type = NJS_OBJECT;
-    vm->retval.data.truth = 1;
+    dest->data.u.object = descriptor;
+    dest->type = NJS_OBJECT;
+    dest->data.truth = 1;
 
     return NXT_OK;
 }
 
 
 static njs_ret_t
+njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args,
+    nxt_uint_t nargs, njs_index_t unused)
+{
+    const njs_value_t  *value, *property;
+
+    value = njs_arg(args, nargs, 1);
+
+    if (njs_is_null_or_undefined(value)) {
+        njs_type_error(vm, "cannot convert %s argument to object",
+                       njs_type_string(value->type));
+        return NXT_ERROR;
+    }
+
+    property = njs_arg(args, nargs, 2);
+
+    return njs_object_property_descriptor(vm, &vm->retval, value, property);
+}
+
+
+static njs_ret_t
 njs_object_get_own_property_names(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused)
 {


More information about the nginx-devel mailing list