aboutsummaryrefslogtreecommitdiff
path: root/src/njs_value.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/njs_value.c')
-rw-r--r--src/njs_value.c55
1 files changed, 17 insertions, 38 deletions
diff --git a/src/njs_value.c b/src/njs_value.c
index dcdab5a2..78f03821 100644
--- a/src/njs_value.c
+++ b/src/njs_value.c
@@ -8,8 +8,9 @@
#include <njs_main.h>
-static njs_int_t njs_object_property_query(njs_vm_t *vm,
- njs_property_query_t *pq, njs_object_t *object, uint32_t atom_id);
+njs_inline njs_int_t
+njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
+ njs_object_t *object, uint32_t atom_id);
static njs_int_t njs_array_property_query(njs_vm_t *vm,
njs_property_query_t *pq, njs_array_t *array, uint32_t index,
uint32_t atom_id);
@@ -560,9 +561,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
{
uint32_t index;
njs_int_t ret;
- njs_value_t key;
njs_object_t *obj;
- njs_function_t *function;
njs_assert(atom_id != NJS_ATOM_STRING_unknown);
@@ -585,6 +584,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
case NJS_OBJECT:
case NJS_ARRAY:
+ case NJS_FUNCTION:
case NJS_ARRAY_BUFFER:
case NJS_DATA_VIEW:
case NJS_TYPED_ARRAY:
@@ -595,31 +595,12 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
obj = njs_object(value);
break;
- case NJS_FUNCTION:
- function = njs_function_value_copy(vm, value);
- if (njs_slow_path(function == NULL)) {
- return NJS_ERROR;
- }
-
- obj = &function->object;
- break;
-
case NJS_UNDEFINED:
case NJS_NULL:
default:
- ret = njs_atom_to_value(vm, &key, atom_id);
-
- if (njs_fast_path(ret == NJS_OK)) {
- njs_string_get(vm, &key, &pq->lhq.key);
- njs_type_error(vm, "cannot get property \"%V\" of %s",
- &pq->lhq.key, njs_is_null(value) ? "null"
- : "undefined");
- return NJS_ERROR;
- }
-
- njs_type_error(vm, "cannot get property \"unknown\" of %s",
- njs_is_null(value) ? "null" : "undefined");
-
+ njs_atom_string_get(vm, atom_id, &pq->lhq.key);
+ njs_type_error(vm, "cannot get property \"%V\" of %s", &pq->lhq.key,
+ njs_type_string(value->type));
return NJS_ERROR;
}
@@ -979,6 +960,7 @@ njs_external_property_query(njs_vm_t *vm, njs_property_query_t *pq,
pq->lhq.value = prop;
+ prop->type = NJS_PROPERTY;
prop->writable = slots->writable;
prop->configurable = slots->configurable;
prop->enumerable = slots->enumerable;
@@ -1029,8 +1011,7 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, uint32_t atom_id,
tarray = njs_typed_array(value);
if (njs_slow_path(njs_is_detached_buffer(tarray->buffer))) {
- njs_type_error(vm, "detached buffer");
- return NJS_ERROR;
+ goto not_found;
}
if (njs_slow_path(index >= njs_typed_array_length(tarray))) {
@@ -1119,6 +1100,7 @@ slow_path:
break;
case NJS_DECLINED:
+not_found:
njs_set_undefined(retval);
return NJS_DECLINED;
@@ -1298,10 +1280,7 @@ slow_path:
return NJS_ERROR;
}
- elt->value = (&pq.lhq)->value;
-
- prop = (njs_object_prop_t *) elt->value;
-
+ prop = (njs_object_prop_t *) elt;
prop->type = NJS_PROPERTY;
prop->enumerable = 1;
prop->configurable = 1;
@@ -1337,13 +1316,8 @@ slow_path:
goto fail;
}
- prop = njs_object_prop_alloc(vm, &njs_value_undefined, 1);
- if (njs_slow_path(prop == NULL)) {
- return NJS_ERROR;
- }
pq.lhq.replace = 0;
- pq.lhq.value = prop;
pq.lhq.key_hash = atom_id;
pq.lhq.pool = vm->mem_pool;
@@ -1353,6 +1327,12 @@ slow_path:
return NJS_ERROR;
}
+ prop = pq.lhq.value;
+ prop->type = NJS_PROPERTY;
+ prop->enumerable = 1;
+ prop->configurable = 1;
+ prop->writable = 1;
+
found:
njs_value_assign(njs_prop_value(prop), setval);
@@ -1471,7 +1451,6 @@ slow_path:
}
prop->type = NJS_WHITEOUT;
- prop->enum_in_object_hash = 1;
return NJS_OK;
}