[njs] Passing value and default attributes to njs_object_prop_alloc().
Dmitry Volyntsev
xeioex at nginx.com
Tue Jun 13 14:51:36 UTC 2017
details: http://hg.nginx.org/njs/rev/8b5f5dbcbfe7
branches:
changeset: 363:8b5f5dbcbfe7
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Jun 13 17:49:05 2017 +0300
description:
Passing value and default attributes to njs_object_prop_alloc().
diffstat:
njs/njs_object.c | 26 ++++++++++----------------
njs/njs_object.h | 3 ++-
njs/njs_regexp.c | 6 ++----
njs/njs_vm.c | 2 +-
4 files changed, 15 insertions(+), 22 deletions(-)
diffs (133 lines):
diff -r 096d526744d5 -r 8b5f5dbcbfe7 njs/njs_object.c
--- a/njs/njs_object.c Tue Jun 13 14:33:51 2017 +0300
+++ b/njs/njs_object.c Tue Jun 13 17:49:05 2017 +0300
@@ -181,7 +181,8 @@ njs_object_hash_test(nxt_lvlhsh_query_t
njs_object_prop_t *
-njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name)
+njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
+ const njs_value_t *value, uint8_t attributes)
{
njs_object_prop_t *prop;
@@ -189,15 +190,16 @@ njs_object_prop_alloc(njs_vm_t *vm, cons
sizeof(njs_object_prop_t));
if (nxt_fast_path(prop != NULL)) {
- prop->value = njs_value_void;
+ /* GC: retain. */
+ prop->value = *value;
/* GC: retain. */
prop->name = *name;
prop->type = NJS_PROPERTY;
- prop->enumerable = 1;
- prop->writable = 1;
- prop->configurable = 1;
+ prop->enumerable = attributes;
+ prop->writable = attributes;
+ prop->configurable = attributes;
}
return prop;
@@ -494,16 +496,12 @@ njs_define_property(njs_vm_t *vm, njs_ob
ret = nxt_lvlhsh_find(&object->hash, &lhq);
if (ret != NXT_OK) {
- prop = njs_object_prop_alloc(vm, name);
+ prop = njs_object_prop_alloc(vm, name, &njs_value_void, 0);
if (nxt_slow_path(prop == NULL)) {
return NXT_ERROR;
}
- prop->configurable = 0;
- prop->enumerable = 0;
- prop->writable = 0;
-
lhq.value = prop;
} else {
@@ -647,7 +645,7 @@ njs_property_prototype_create(njs_vm_t *
static const njs_value_t prototype_string = njs_string("prototype");
- prop = njs_object_prop_alloc(vm, &prototype_string);
+ prop = njs_object_prop_alloc(vm, &prototype_string, &njs_value_void, 0);
if (nxt_slow_path(prop == NULL)) {
return NULL;
}
@@ -658,10 +656,6 @@ njs_property_prototype_create(njs_vm_t *
prop->value.type = prototype->type;
prop->value.data.truth = 1;
- prop->enumerable = 0;
- prop->writable = 0;
- prop->configurable = 0;
-
lhq.value = prop;
lhq.key_hash = NJS_PROTOTYPE_HASH;
lhq.key = nxt_string_value("prototype");
@@ -835,7 +829,7 @@ njs_property_constructor_create(njs_vm_t
static const njs_value_t constructor_string = njs_string("constructor");
- prop = njs_object_prop_alloc(vm, &constructor_string);
+ prop = njs_object_prop_alloc(vm, &constructor_string, constructor, 1);
if (nxt_slow_path(prop == NULL)) {
return NULL;
}
diff -r 096d526744d5 -r 8b5f5dbcbfe7 njs/njs_object.h
--- a/njs/njs_object.h Tue Jun 13 14:33:51 2017 +0300
+++ b/njs/njs_object.h Tue Jun 13 17:49:05 2017 +0300
@@ -47,7 +47,8 @@ nxt_int_t njs_object_hash_create(njs_vm_
const njs_object_prop_t *prop, nxt_uint_t n);
njs_ret_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused);
-njs_object_prop_t *njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name);
+njs_object_prop_t *njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
+ const njs_value_t *value, uint8_t attributes);
njs_ret_t njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value);
njs_ret_t njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value);
njs_value_t *njs_property_prototype_create(njs_vm_t *vm, nxt_lvlhsh_t *hash,
diff -r 096d526744d5 -r 8b5f5dbcbfe7 njs/njs_regexp.c
--- a/njs/njs_regexp.c Tue Jun 13 14:33:51 2017 +0300
+++ b/njs/njs_regexp.c Tue Jun 13 17:49:05 2017 +0300
@@ -749,7 +749,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs
}
}
- prop = njs_object_prop_alloc(vm, &njs_string_index);
+ prop = njs_object_prop_alloc(vm, &njs_string_index, &njs_value_void, 1);
if (nxt_slow_path(prop == NULL)) {
goto fail;
}
@@ -774,13 +774,11 @@ njs_regexp_exec_result(njs_vm_t *vm, njs
goto fail;
}
- prop = njs_object_prop_alloc(vm, &njs_string_input);
+ prop = njs_object_prop_alloc(vm, &njs_string_input, ®exp->string, 1);
if (nxt_slow_path(prop == NULL)) {
goto fail;
}
- njs_string_copy(&prop->value, ®exp->string);
-
lhq.key_hash = NJS_INPUT_HASH;
lhq.key = nxt_string_value("input");
lhq.value = prop;
diff -r 096d526744d5 -r 8b5f5dbcbfe7 njs/njs_vm.c
--- a/njs/njs_vm.c Tue Jun 13 14:33:51 2017 +0300
+++ b/njs/njs_vm.c Tue Jun 13 17:49:05 2017 +0300
@@ -683,7 +683,7 @@ njs_vmcode_property_set(njs_vm_t *vm, nj
break;
case NXT_DECLINED:
- prop = njs_object_prop_alloc(vm, &pq.value);
+ prop = njs_object_prop_alloc(vm, &pq.value, &njs_value_void, 1);
if (nxt_slow_path(prop == NULL)) {
return NXT_ERROR;
}
More information about the nginx-devel
mailing list