prop->name = *name;
prop->type = NJS_PROPERTY;
- prop->enumerable = attributes;
prop->writable = attributes;
+ prop->enumerable = attributes;
prop->configurable = attributes;
+
return prop;
}
prop->type = NJS_PROPERTY_REF;
}
- prop->configurable = 1;
- prop->enumerable = 1;
prop->writable = 1;
+ prop->enumerable = 1;
+ prop->configurable = 1;
pq->lhq.value = prop;
* so the function cannot fail.
*/
(void) njs_string_slice(vm, &prop->value, &string, &slice);
+
prop->type = NJS_PROPERTY;
- prop->configurable = 0;
- prop->enumerable = 1;
prop->writable = 0;
+ prop->enumerable = 1;
+ prop->configurable = 0;
pq->lhq.value = prop;
prop = &pq->scratch;
prop->type = NJS_PROPERTY;
- prop->configurable = 0;
- prop->enumerable = 1;
prop->writable = 0;
+ prop->enumerable = 1;
+ prop->configurable = 0;
ext_proto = object->external.proto;
}
-static uint8_t
-njs_descriptor_attribute(njs_vm_t *vm, const njs_object_t *descriptor,
- nxt_lvlhsh_query_t *pq, nxt_bool_t unset)
-{
- njs_object_prop_t *prop;
-
- prop = njs_object_property(vm, descriptor, pq);
- if (prop != NULL) {
- return prop->value.data.truth;
- }
-
- return unset ? NJS_ATTRIBUTE_UNSET : 0;
-}
-
-
static njs_object_prop_t *
njs_descriptor_prop(njs_vm_t *vm, const njs_value_t *name,
- const njs_object_t *descriptor, nxt_bool_t unset)
+ const njs_object_t *descriptor)
{
- const njs_value_t *value;
njs_object_prop_t *prop, *pr;
nxt_lvlhsh_query_t pq;
- value = unset ? &njs_value_invalid : &njs_value_undefined;
- prop = njs_object_prop_alloc(vm, name, value, 0);
+ prop = njs_object_prop_alloc(vm, name, &njs_value_invalid,
+ NJS_ATTRIBUTE_UNSET);
if (nxt_slow_path(prop == NULL)) {
return NULL;
}
- pq.key = nxt_string_value("configurable");
- pq.key_hash = NJS_CONFIGURABLE_HASH;
- prop->configurable = njs_descriptor_attribute(vm, descriptor, &pq, unset);
+ pq.key = nxt_string_value("value");
+ pq.key_hash = NJS_VALUE_HASH;
- pq.key = nxt_string_value("enumerable");
- pq.key_hash = NJS_ENUMERABLE_HASH;
- prop->enumerable = njs_descriptor_attribute(vm, descriptor, &pq, unset);
+ pr = njs_object_property(vm, descriptor, &pq);
+ if (pr != NULL) {
+ prop->value = pr->value;
+ }
pq.key = nxt_string_value("writable");
pq.key_hash = NJS_WRITABABLE_HASH;
- prop->writable = njs_descriptor_attribute(vm, descriptor, &pq, unset);
- pq.key = nxt_string_value("value");
- pq.key_hash = NJS_VALUE_HASH;
- pq.proto = &njs_object_hash_proto;
+ pr = njs_object_property(vm, descriptor, &pq);
+ if (pr != NULL) {
+ prop->writable = pr->value.data.truth;
+ }
+
+ pq.key = nxt_string_value("enumerable");
+ pq.key_hash = NJS_ENUMERABLE_HASH;
pr = njs_object_property(vm, descriptor, &pq);
if (pr != NULL) {
- prop->value = pr->value;
+ prop->enumerable = pr->value.data.truth;
+ }
+
+ pq.key = nxt_string_value("configurable");
+ pq.key_hash = NJS_CONFIGURABLE_HASH;
+
+ pr = njs_object_property(vm, descriptor, &pq);
+ if (pr != NULL) {
+ prop->configurable = pr->value.data.truth;
}
return prop;
const njs_object_t *descriptor)
{
nxt_int_t ret;
- nxt_bool_t unset;
njs_object_prop_t *desc, *current;
njs_property_query_t pq;
return ret;
}
- unset = (ret == NXT_OK);
- desc = njs_descriptor_prop(vm, name, descriptor, unset);
+ desc = njs_descriptor_prop(vm, name, descriptor);
if (nxt_slow_path(desc == NULL)) {
return NXT_ERROR;
}
if (nxt_fast_path(ret == NXT_DECLINED)) {
+
+ if (!njs_is_valid(&desc->value)) {
+ desc->value = njs_value_undefined;
+ }
+
+ if (desc->writable == NJS_ATTRIBUTE_UNSET) {
+ desc->writable = 0;
+ }
+
+ if (desc->enumerable == NJS_ATTRIBUTE_UNSET) {
+ desc->enumerable = 0;
+ }
+
+ if (desc->configurable == NJS_ATTRIBUTE_UNSET) {
+ desc->configurable = 0;
+ }
+
if (nxt_slow_path(pq.lhq.value != NULL)) {
current = pq.lhq.value;
}
if (!current->configurable) {
- if (desc->configurable == NJS_ATTRIBUTE_TRUE) {
- goto exception;
- }
- if (desc->enumerable != NJS_ATTRIBUTE_UNSET
- && current->enumerable != desc->enumerable)
+ if (njs_is_valid(&desc->value)
+ && current->writable == NJS_ATTRIBUTE_FALSE
+ && !njs_values_strict_equal(&desc->value, ¤t->value))
{
goto exception;
}
goto exception;
}
- if (njs_is_valid(&desc->value)
- && current->writable == NJS_ATTRIBUTE_FALSE
- && !njs_values_strict_equal(&desc->value, ¤t->value))
+ if (desc->enumerable != NJS_ATTRIBUTE_UNSET
+ && current->enumerable != desc->enumerable)
{
goto exception;
}
- }
- if (desc->configurable != NJS_ATTRIBUTE_UNSET) {
- current->configurable = desc->configurable;
+ if (desc->configurable == NJS_ATTRIBUTE_TRUE) {
+ goto exception;
+ }
}
- if (desc->enumerable != NJS_ATTRIBUTE_UNSET) {
- current->enumerable = desc->enumerable;
+ if (njs_is_valid(&desc->value)) {
+ current->value = desc->value;
}
if (desc->writable != NJS_ATTRIBUTE_UNSET) {
current->writable = desc->writable;
}
- if (njs_is_valid(&desc->value)) {
- current->value = desc->value;
+ if (desc->enumerable != NJS_ATTRIBUTE_UNSET) {
+ current->enumerable = desc->enumerable;
+ }
+
+ if (desc->configurable != NJS_ATTRIBUTE_UNSET) {
+ current->configurable = desc->configurable;
}
return NXT_OK;
static const njs_value_t njs_object_value_string = njs_string("value");
-static const njs_value_t njs_object_configurable_string =
- njs_string("configurable");
-static const njs_value_t njs_object_enumerable_string =
- njs_string("enumerable");
static const njs_value_t njs_object_writable_string =
njs_string("writable");
+static const njs_value_t njs_object_enumerable_string =
+ njs_string("enumerable");
+static const njs_value_t njs_object_configurable_string =
+ njs_string("configurable");
static njs_ret_t
lhq.proto = &njs_object_hash_proto;
lhq.replace = 0;
lhq.pool = vm->mem_pool;
- lhq.proto = &njs_object_hash_proto;
lhq.key = nxt_string_value("value");
lhq.key_hash = NJS_VALUE_HASH;
return NXT_ERROR;
}
- lhq.key = nxt_string_value("configurable");
- lhq.key_hash = NJS_CONFIGURABLE_HASH;
+ lhq.key = nxt_string_value("writable");
+ lhq.key_hash = NJS_WRITABABLE_HASH;
- setval = (prop->configurable == 1) ? &njs_value_true : &njs_value_false;
+ setval = (prop->writable == 1) ? &njs_value_true : &njs_value_false;
- pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, setval, 1);
+ pr = njs_object_prop_alloc(vm, &njs_object_writable_string, setval, 1);
if (nxt_slow_path(pr == NULL)) {
return NXT_ERROR;
}
return NXT_ERROR;
}
- lhq.key = nxt_string_value("writable");
- lhq.key_hash = NJS_WRITABABLE_HASH;
+ lhq.key = nxt_string_value("configurable");
+ lhq.key_hash = NJS_CONFIGURABLE_HASH;
- setval = (prop->writable == 1) ? &njs_value_true : &njs_value_false;
+ setval = (prop->configurable == 1) ? &njs_value_true : &njs_value_false;
- pr = njs_object_prop_alloc(vm, &njs_object_writable_string, setval, 1);
+ pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, setval, 1);
if (nxt_slow_path(pr == NULL)) {
return NXT_ERROR;
}