[njs] Extending njs_prop_handler_t prototype.
Dmitry Volyntsev
xeioex at nginx.com
Thu Oct 31 15:18:02 UTC 2019
details: https://hg.nginx.org/njs/rev/796870eab669
branches:
changeset: 1209:796870eab669
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Oct 31 18:17:30 2019 +0300
description:
Extending njs_prop_handler_t prototype.
diffstat:
src/njs_array.c | 4 ++--
src/njs_builtin.c | 16 ++++++++--------
src/njs_error.c | 4 ++--
src/njs_function.c | 8 ++++----
src/njs_function.h | 4 ++--
src/njs_object.c | 18 +++++++++---------
src/njs_object.h | 16 +++++++++-------
src/njs_object_prop.c | 5 +++--
src/njs_regexp.c | 27 ++++++++++++++-------------
src/njs_string.c | 4 ++--
src/njs_value.c | 24 +++++++++++++-----------
src/njs_value.h | 33 +++++++++++++++++----------------
src/njs_vmcode.c | 2 +-
13 files changed, 86 insertions(+), 79 deletions(-)
diffs (462 lines):
diff -r 758bbc9f105a -r 796870eab669 src/njs_array.c
--- a/src/njs_array.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_array.c Thu Oct 31 18:17:30 2019 +0300
@@ -329,8 +329,8 @@ const njs_object_init_t njs_array_const
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 -r 758bbc9f105a -r 796870eab669 src/njs_builtin.c
--- a/src/njs_builtin.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_builtin.c Thu Oct 31 18:17:30 2019 +0300
@@ -1211,8 +1211,8 @@ const njs_object_init_t njs_njs_object_
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_lvlh
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
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
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 -r 758bbc9f105a -r 796870eab669 src/njs_error.c
--- a/src/njs_error.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_error.c Thu Oct 31 18:17:30 2019 +0300
@@ -545,8 +545,8 @@ njs_memory_error_constructor(njs_vm_t *v
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 -r 758bbc9f105a -r 796870eab669 src/njs_function.c
--- a/src/njs_function.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_function.c Thu Oct 31 18:17:30 2019 +0300
@@ -681,8 +681,8 @@ njs_function_property_prototype_create(n
*/
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_co
* 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 -r 758bbc9f105a -r 796870eab669 src/njs_function.h
--- a/src/njs_function.h Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_function.h Thu Oct 31 18:17:30 2019 +0300
@@ -105,8 +105,8 @@ njs_int_t njs_function_arguments_object_
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 -r 758bbc9f105a -r 796870eab669 src/njs_object.c
--- a/src/njs_object.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_object.c Thu Oct 31 18:17:30 2019 +0300
@@ -1311,7 +1311,7 @@ njs_object_get_prototype_of(njs_vm_t *vm
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, n
*/
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
*/
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_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_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 -r 758bbc9f105a -r 796870eab669 src/njs_object.h
--- a/src/njs_object.h Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_object.h Thu Oct 31 18:17:30 2019 +0300
@@ -55,16 +55,18 @@ njs_int_t njs_object_hash_create(njs_vm_
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_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_value_t *value, njs_value_t *setval, njs_value_t *retval);
+ 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 -r 758bbc9f105a -r 796870eab669 src/njs_object_prop.c
--- a/src/njs_object_prop.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_object_prop.c Thu Oct 31 18:17:30 2019 +0300
@@ -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,
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 -r 758bbc9f105a -r 796870eab669 src/njs_regexp.c
--- a/src/njs_regexp.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_regexp.c Thu Oct 31 18:17:30 2019 +0300
@@ -19,8 +19,9 @@ static void *njs_regexp_malloc(size_t si
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
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_regex
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
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
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_
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
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 -r 758bbc9f105a -r 796870eab669 src/njs_string.c
--- a/src/njs_string.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_string.c Thu Oct 31 18:17:30 2019 +0300
@@ -637,8 +637,8 @@ const njs_object_init_t njs_string_cons
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 -r 758bbc9f105a -r 796870eab669 src/njs_value.c
--- a/src/njs_value.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_value.c Thu Oct 31 18:17:30 2019 +0300
@@ -17,10 +17,12 @@ static njs_int_t njs_string_property_que
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,
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_val
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
}
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,
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 -r 758bbc9f105a -r 796870eab669 src/njs_value.h
--- a/src/njs_value.h Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_value.h Thu Oct 31 18:17:30 2019 +0300
@@ -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 -r 758bbc9f105a -r 796870eab669 src/njs_vmcode.c
--- a/src/njs_vmcode.c Wed Oct 30 16:43:12 2019 +0300
+++ b/src/njs_vmcode.c Thu Oct 31 18:17:30 2019 +0300
@@ -1241,7 +1241,7 @@ njs_vmcode_proto_init(njs_vm_t *vm, njs_
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;
}
More information about the nginx-devel
mailing list