]> git.kaiwu.me - njs.git/commitdiff
Extending njs_prop_handler_t prototype.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 31 Oct 2019 15:17:30 +0000 (18:17 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 31 Oct 2019 15:17:30 +0000 (18:17 +0300)
13 files changed:
src/njs_array.c
src/njs_builtin.c
src/njs_error.c
src/njs_function.c
src/njs_function.h
src/njs_object.c
src/njs_object.h
src/njs_object_prop.c
src/njs_regexp.c
src/njs_string.c
src/njs_value.c
src/njs_value.h
src/njs_vmcode.c

index d6415aec17fbdc0ad6c80291c5970afc7114747b..06021bbf3707f078d88fcdb643192693a7f77806 100644 (file)
@@ -329,8 +329,8 @@ const njs_object_init_t  njs_array_constructor_init = {
 
 
 static njs_int_t
-njs_array_length(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval,
-    njs_value_t *retval)
+njs_array_length(njs_vm_t *vm,njs_object_prop_t *prop, njs_value_t *value,
+    njs_value_t *setval, njs_value_t *retval)
 {
     double        num;
     int64_t       size;
index 83f9045952075d808a85c89807e1d6d232cb28da..3beda05a3543f5ee5c81753df724b8e30c0520b7 100644 (file)
@@ -1211,8 +1211,8 @@ const njs_object_init_t  njs_njs_object_init = {
 
 
 static njs_int_t
-njs_process_object_argv(njs_vm_t *vm, njs_value_t *process,
-    njs_value_t *unused, njs_value_t *retval)
+njs_process_object_argv(njs_vm_t *vm, njs_object_prop_t *pr,
+    njs_value_t *process, njs_value_t *unused, njs_value_t *retval)
 {
     char                **arg;
     njs_int_t           ret;
@@ -1324,8 +1324,8 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlhsh_t *hash, char **environment)
 
 
 static njs_int_t
-njs_process_object_env(njs_vm_t *vm, njs_value_t *process,
-    njs_value_t *unused, njs_value_t *retval)
+njs_process_object_env(njs_vm_t *vm, njs_object_prop_t *pr,
+    njs_value_t *process, njs_value_t *unused, njs_value_t *retval)
 {
     njs_int_t           ret;
     njs_object_t        *env;
@@ -1369,8 +1369,8 @@ njs_process_object_env(njs_vm_t *vm, njs_value_t *process,
 
 
 static njs_int_t
-njs_process_object_pid(njs_vm_t *vm, njs_value_t *unused,
-    njs_value_t *unused2, njs_value_t *retval)
+njs_process_object_pid(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *unused, njs_value_t *unused2, njs_value_t *retval)
 {
     njs_set_number(retval, getpid());
 
@@ -1379,8 +1379,8 @@ njs_process_object_pid(njs_vm_t *vm, njs_value_t *unused,
 
 
 static njs_int_t
-njs_process_object_ppid(njs_vm_t *vm, njs_value_t *unused,
-    njs_value_t *unused2, njs_value_t *retval)
+njs_process_object_ppid(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *unused, njs_value_t *unused2, njs_value_t *retval)
 {
     njs_set_number(retval, getppid());
 
index bcda87027c30dfac69e2607449620a0ab6aee368..831bdf98cc2ace546e77b2f654fa7d707031c90c 100644 (file)
@@ -545,8 +545,8 @@ njs_memory_error_constructor(njs_vm_t *vm, njs_value_t *args,
 
 
 static njs_int_t
-njs_memory_error_prototype_create(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_memory_error_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     int32_t            index;
     njs_function_t     *function;
index c59189c8ba4181abe0154b098fc6c6a54fbbb490..9e2ef4c8f90e4369f743f1933d0f7ceb8eb8f058 100644 (file)
@@ -681,8 +681,8 @@ njs_function_property_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
  */
 
 njs_int_t
-njs_function_prototype_create(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_value_t     *proto, proto_value, *cons;
     njs_object_t    *prototype;
@@ -883,8 +883,8 @@ const njs_object_init_t  njs_function_constructor_init = {
  *      the typical number of arguments expected by the function.
  */
 static njs_int_t
-njs_function_instance_length(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_function_instance_length(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_object_t    *proto;
     njs_function_t  *function;
index efaffc8193ef611d579bb437addceab287b89599..82ca3a3b182a6b0816d14b66ab2736fa90f7bc0b 100644 (file)
@@ -105,8 +105,8 @@ njs_int_t njs_function_arguments_object_init(njs_vm_t *vm,
     njs_native_frame_t *frame);
 njs_int_t njs_function_rest_parameters_init(njs_vm_t *vm,
     njs_native_frame_t *frame);
-njs_int_t njs_function_prototype_create(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
+njs_int_t njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 njs_int_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
index f6599be8147c4399c7dfde415816b487b89800f8..6b3de94afef881e30a6955f61db31cf00866dc5b 100644 (file)
@@ -1311,7 +1311,7 @@ njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     value = njs_arg(args, nargs, 1);
 
     if (njs_is_object(value)) {
-        njs_object_prototype_proto(vm, value, NULL, &vm->retval);
+        njs_object_prototype_proto(vm, NULL, value, NULL, &vm->retval);
         return NJS_OK;
     }
 
@@ -1563,8 +1563,8 @@ njs_object_is_extensible(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
  */
 
 njs_int_t
-njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_uint_t    index;
     njs_object_t  *proto;
@@ -1594,8 +1594,8 @@ njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value,
  */
 
 njs_int_t
-njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_object_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     int32_t            index;
     njs_function_t     *function;
@@ -1877,8 +1877,8 @@ njs_object_set_prototype_of(njs_vm_t *vm, njs_object_t *object,
 
 
 njs_int_t
-njs_object_prototype_proto(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_object_prototype_proto(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_int_t     ret;
     njs_object_t  *proto, *object;
@@ -1924,8 +1924,8 @@ njs_object_prototype_proto(njs_vm_t *vm, njs_value_t *value,
  */
 
 njs_int_t
-njs_object_prototype_create_constructor(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_object_prototype_create_constructor(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     int32_t                 index;
     njs_value_t             *cons;
index e04a8cc25e25ebf525ccdb2897e4f23d7f195d71..1f21f6f865a375086586edbfb10610b5fe17d7d4 100644 (file)
@@ -55,16 +55,18 @@ njs_int_t njs_object_hash_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
     const njs_object_prop_t *prop, njs_uint_t n);
 njs_int_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
-njs_int_t njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
+njs_int_t njs_primitive_prototype_get_proto(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
+njs_int_t njs_object_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 njs_value_t *njs_property_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
     njs_object_t *prototype);
-njs_int_t njs_object_prototype_proto(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
-njs_int_t njs_object_prototype_create_constructor(njs_vm_t *vm,
+njs_int_t njs_object_prototype_proto(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
+njs_int_t njs_object_prototype_create_constructor(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
 njs_value_t *njs_property_constructor_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
     njs_value_t *constructor);
 njs_int_t njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
index b272f1b69f4933f4b153756082d9de0403e6cf60..546b902393339da3927f6cc96c3a7d7e9925d506 100644 (file)
@@ -338,7 +338,8 @@ done:
     if (njs_is_valid(&prop->value)) {
         if (prev->type == NJS_PROPERTY_HANDLER) {
             if (njs_is_data_descriptor(prev) && prev->writable) {
-                ret = prev->value.data.u.prop_handler(vm, object, &prop->value,
+                ret = prev->value.data.u.prop_handler(vm, prev, object,
+                                                      &prop->value,
                                                       &vm->retval);
                 if (njs_slow_path(ret == NJS_ERROR)) {
                     return ret;
@@ -600,7 +601,7 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
         case NJS_PROPERTY_HANDLER:
             pq.scratch = *prop;
             prop = &pq.scratch;
-            ret = prop->value.data.u.prop_handler(vm, value, NULL,
+            ret = prop->value.data.u.prop_handler(vm, prop, value, NULL,
                                                   &prop->value);
             if (njs_slow_path(ret == NJS_ERROR)) {
                 return ret;
index a52f8e63a7a605919ace312fa149471e1f3548c7..e11d4705f9da605f63ee30fcb2631a798532d8b8 100644 (file)
@@ -19,8 +19,9 @@ static void *njs_regexp_malloc(size_t size, void *memory_data);
 static void njs_regexp_free(void *p, void *memory_data);
 static njs_regexp_flags_t njs_regexp_flags(u_char **start, u_char *end,
     njs_bool_t bound);
-static njs_int_t njs_regexp_prototype_source(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
+static njs_int_t njs_regexp_prototype_source(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
 static int njs_regexp_pattern_compile(njs_vm_t *vm, njs_regex_t *regex,
     u_char *source, int options);
 static u_char *njs_regexp_compile_trace_handler(njs_trace_t *trace,
@@ -126,7 +127,7 @@ njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     re_flags = 0;
 
     if (njs_is_regexp(pattern)) {
-        ret = njs_regexp_prototype_source(vm, pattern, NULL, &source);
+        ret = njs_regexp_prototype_source(vm, NULL, pattern, NULL, &source);
         if (njs_slow_path(ret != NJS_OK)) {
             return ret;
         }
@@ -723,8 +724,8 @@ njs_regexp_alloc(njs_vm_t *vm, njs_regexp_pattern_t *pattern)
 
 
 static njs_int_t
-njs_regexp_prototype_last_index(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_regexp_prototype_last_index(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     uint32_t           index;
     njs_regexp_t       *regexp;
@@ -744,8 +745,8 @@ njs_regexp_prototype_last_index(njs_vm_t *vm, njs_value_t *value,
 
 
 static njs_int_t
-njs_regexp_prototype_global(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_regexp_prototype_global(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_regexp_pattern_t  *pattern;
 
@@ -758,8 +759,8 @@ njs_regexp_prototype_global(njs_vm_t *vm, njs_value_t *value,
 
 
 static njs_int_t
-njs_regexp_prototype_ignore_case(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_regexp_prototype_ignore_case(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_regexp_pattern_t  *pattern;
 
@@ -772,8 +773,8 @@ njs_regexp_prototype_ignore_case(njs_vm_t *vm, njs_value_t *value,
 
 
 static njs_int_t
-njs_regexp_prototype_multiline(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_regexp_prototype_multiline(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     njs_regexp_pattern_t  *pattern;
 
@@ -786,8 +787,8 @@ njs_regexp_prototype_multiline(njs_vm_t *vm, njs_value_t *value,
 
 
 static njs_int_t
-njs_regexp_prototype_source(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_regexp_prototype_source(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     u_char                *source;
     int32_t               length;
index e12d013483525f3b54738f551fa96ba797293a6c..5ce3adf227195d29b2702dac685f70d0381a53cf 100644 (file)
@@ -637,8 +637,8 @@ const njs_object_init_t  njs_string_constructor_init = {
 
 
 static njs_int_t
-njs_string_instance_length(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval)
+njs_string_instance_length(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     size_t              size;
     uintptr_t           length;
index 4b8b421d222edb9c55711984ccc8491025045cb7..f86a4ed99a91100c1a6ab036704ea4453a0fcbd8 100644 (file)
@@ -17,10 +17,12 @@ static njs_int_t njs_string_property_query(njs_vm_t *vm,
     njs_property_query_t *pq, njs_value_t *object, uint32_t index);
 static njs_int_t njs_external_property_query(njs_vm_t *vm,
     njs_property_query_t *pq, njs_value_t *object);
-static njs_int_t njs_external_property_set(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
-static njs_int_t njs_external_property_delete(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
+static njs_int_t njs_external_property_set(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
+static njs_int_t njs_external_property_delete(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
 
 
 const njs_value_t  njs_value_null =         njs_value(NJS_NULL, 0, 0.0);
@@ -870,8 +872,8 @@ done:
 
 
 static njs_int_t
-njs_external_property_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval,
-    njs_value_t *retval)
+njs_external_property_set(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
     void                  *obj;
     njs_int_t             ret;
@@ -899,8 +901,8 @@ njs_external_property_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval,
 
 
 static njs_int_t
-njs_external_property_delete(njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *unused, njs_value_t *unused2)
+njs_external_property_delete(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *unused, njs_value_t *unused2)
 {
     void                  *obj;
     njs_property_query_t  *pq;
@@ -949,7 +951,7 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
         case NJS_PROPERTY_HANDLER:
             pq.scratch = *prop;
             prop = &pq.scratch;
-            ret = prop->value.data.u.prop_handler(vm, value, NULL,
+            ret = prop->value.data.u.prop_handler(vm, prop, value, NULL,
                                                   &prop->value);
 
             if (njs_slow_path(ret == NJS_ERROR)) {
@@ -1029,7 +1031,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
         }
 
         if (prop->type == NJS_PROPERTY_HANDLER) {
-            ret = prop->value.data.u.prop_handler(vm, value, setval,
+            ret = prop->value.data.u.prop_handler(vm, prop, value, setval,
                                                   &vm->retval);
             if (njs_slow_path(ret != NJS_DECLINED)) {
                 return ret;
@@ -1134,7 +1136,7 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
     switch (prop->type) {
     case NJS_PROPERTY_HANDLER:
         if (njs_is_external(value)) {
-            ret = prop->value.data.u.prop_handler(vm, value, NULL, NULL);
+            ret = prop->value.data.u.prop_handler(vm, prop, value, NULL, NULL);
             if (njs_slow_path(ret != NJS_OK)) {
                 return NJS_ERROR;
             }
index 99e929964c21a41fec9201e5ace6ef636873ba73..b84d10d67b43ded76f0fe7812b7b81418b706612 100644 (file)
@@ -69,6 +69,19 @@ typedef enum {
 } njs_value_type_t;
 
 
+typedef struct njs_object_prop_s      njs_object_prop_t;
+typedef struct njs_string_s           njs_string_t;
+typedef struct njs_object_s           njs_object_t;
+typedef struct njs_object_value_s     njs_object_value_t;
+typedef struct njs_function_lambda_s  njs_function_lambda_t;
+typedef struct njs_regexp_pattern_s   njs_regexp_pattern_t;
+typedef struct njs_array_s            njs_array_t;
+typedef struct njs_regexp_s           njs_regexp_t;
+typedef struct njs_date_s             njs_date_t;
+typedef struct njs_property_next_s    njs_property_next_t;
+typedef struct njs_object_init_s      njs_object_init_t;
+
+
 /*
  * njs_prop_handler_t operates as a property getter and/or setter.
  * The handler receives NULL setval if it is invoked in GET context and
@@ -80,23 +93,11 @@ typedef enum {
  *   NJS_DECLINED - handler was applied to inappropriate object, vm->retval
  *   contains undefined value.
  */
-typedef njs_int_t (*njs_prop_handler_t) (njs_vm_t *vm, njs_value_t *value,
-    njs_value_t *setval, njs_value_t *retval);
+typedef njs_int_t (*njs_prop_handler_t) (njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 typedef njs_int_t (*njs_function_native_t) (njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t retval);
 
-
-typedef struct njs_string_s           njs_string_t;
-typedef struct njs_object_s           njs_object_t;
-typedef struct njs_object_value_s     njs_object_value_t;
-typedef struct njs_function_lambda_s  njs_function_lambda_t;
-typedef struct njs_regexp_pattern_s   njs_regexp_pattern_t;
-typedef struct njs_array_s            njs_array_t;
-typedef struct njs_regexp_s           njs_regexp_t;
-typedef struct njs_date_s             njs_date_t;
-typedef struct njs_property_next_s    njs_property_next_t;
-typedef struct njs_object_init_s      njs_object_init_t;
-
 #if (!NJS_HAVE_GCC_ATTRIBUTE_ALIGNED)
 #error "aligned attribute is required"
 #endif
@@ -312,7 +313,7 @@ typedef enum {
 } njs_object_attribute_t;
 
 
-typedef struct {
+struct njs_object_prop_s {
     /* Must be aligned to njs_value_t. */
     njs_value_t                 value;
     njs_value_t                 name;
@@ -325,7 +326,7 @@ typedef struct {
     njs_object_attribute_t      writable:8;      /* 2 bits */
     njs_object_attribute_t      enumerable:8;    /* 2 bits */
     njs_object_attribute_t      configurable:8;  /* 2 bits */
-} njs_object_prop_t;
+};
 
 
 typedef struct {
index caeb24d79b2682a8bf6332473ddb8823bbfad2e6..4f4238d00d2e999e39d85901495483b8ff312224 100644 (file)
@@ -1241,7 +1241,7 @@ njs_vmcode_proto_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *unused,
         goto fail;
     }
 
-    ret = prop->value.data.u.prop_handler(vm, value, init, &vm->retval);
+    ret = prop->value.data.u.prop_handler(vm, prop, value, init, &vm->retval);
     if (njs_slow_path(ret != NJS_OK)) {
         goto fail;
     }