From: Dmitry Volyntsev Date: Thu, 31 Oct 2019 15:17:30 +0000 (+0300) Subject: Extending njs_prop_handler_t prototype. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/%7B@url%7D?a=commitdiff_plain;h=f0d08a9e1b0bc4ca056395bff755a998e51de499;p=njs.git Extending njs_prop_handler_t prototype. --- diff --git a/src/njs_array.c b/src/njs_array.c index d6415aec..06021bbf 100644 --- a/src/njs_array.c +++ b/src/njs_array.c @@ -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; diff --git a/src/njs_builtin.c b/src/njs_builtin.c index 83f90459..3beda05a 100644 --- a/src/njs_builtin.c +++ b/src/njs_builtin.c @@ -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()); diff --git a/src/njs_error.c b/src/njs_error.c index bcda8702..831bdf98 100644 --- a/src/njs_error.c +++ b/src/njs_error.c @@ -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; diff --git a/src/njs_function.c b/src/njs_function.c index c59189c8..9e2ef4c8 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -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; diff --git a/src/njs_function.h b/src/njs_function.h index efaffc81..82ca3a3b 100644 --- a/src/njs_function.h +++ b/src/njs_function.h @@ -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, diff --git a/src/njs_object.c b/src/njs_object.c index f6599be8..6b3de94a 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -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; diff --git a/src/njs_object.h b/src/njs_object.h index e04a8cc2..1f21f6f8 100644 --- a/src/njs_object.h +++ b/src/njs_object.h @@ -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, diff --git a/src/njs_object_prop.c b/src/njs_object_prop.c index b272f1b6..546b9023 100644 --- a/src/njs_object_prop.c +++ b/src/njs_object_prop.c @@ -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; diff --git a/src/njs_regexp.c b/src/njs_regexp.c index a52f8e63..e11d4705 100644 --- a/src/njs_regexp.c +++ b/src/njs_regexp.c @@ -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; diff --git a/src/njs_string.c b/src/njs_string.c index e12d0134..5ce3adf2 100644 --- a/src/njs_string.c +++ b/src/njs_string.c @@ -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; diff --git a/src/njs_value.c b/src/njs_value.c index 4b8b421d..f86a4ed9 100644 --- a/src/njs_value.c +++ b/src/njs_value.c @@ -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; } diff --git a/src/njs_value.h b/src/njs_value.h index 99e92996..b84d10d6 100644 --- a/src/njs_value.h +++ b/src/njs_value.h @@ -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 { diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c index caeb24d7..4f4238d0 100644 --- a/src/njs_vmcode.c +++ b/src/njs_vmcode.c @@ -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; }