[njs] Implement OrdinaryDelete() which does not throw exception.
Dmitry Volyntsev
xeioex at nginx.com
Wed May 4 23:58:40 UTC 2022
details: https://hg.nginx.org/njs/rev/723873b4e315
branches:
changeset: 1848:723873b4e315
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed May 04 16:23:46 2022 -0700
description:
Implement OrdinaryDelete() which does not throw exception.
diffstat:
src/njs_array.c | 4 ++--
src/njs_value.c | 14 +++++++++-----
src/njs_value.h | 4 ++--
src/njs_vmcode.c | 2 +-
4 files changed, 14 insertions(+), 10 deletions(-)
diffs (85 lines):
diff -r 900d3ba62bcb -r 723873b4e315 src/njs_array.c
--- a/src/njs_array.c Thu Apr 28 17:59:03 2022 -0700
+++ b/src/njs_array.c Wed May 04 16:23:46 2022 -0700
@@ -243,7 +243,7 @@ njs_array_length_set(njs_vm_t *vm, njs_v
idx = njs_string_to_index(&keys->start[i]);
if (idx >= length) {
ret = njs_value_property_delete(vm, value, &keys->start[i],
- NULL);
+ NULL, 1);
if (njs_slow_path(ret == NJS_ERROR)) {
goto done;
}
@@ -1064,7 +1064,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
while (from > 0) {
ret = njs_value_property_delete(vm, this, &keys->start[--from],
- &entry);
+ &entry, 1);
if (njs_slow_path(ret == NJS_ERROR)) {
njs_array_destroy(vm, keys);
return ret;
diff -r 900d3ba62bcb -r 723873b4e315 src/njs_value.c
--- a/src/njs_value.c Thu Apr 28 17:59:03 2022 -0700
+++ b/src/njs_value.c Wed May 04 16:23:46 2022 -0700
@@ -1327,7 +1327,7 @@ fail:
njs_int_t
njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
- njs_value_t *removed)
+ njs_value_t *removed, njs_bool_t thrw)
{
njs_int_t ret;
njs_object_prop_t *prop;
@@ -1343,10 +1343,14 @@ njs_value_property_delete(njs_vm_t *vm,
prop = pq.lhq.value;
if (njs_slow_path(!prop->configurable)) {
- njs_key_string_get(vm, &pq.key, &pq.lhq.key);
- njs_type_error(vm, "Cannot delete property \"%V\" of %s",
- &pq.lhq.key, njs_type_string(value->type));
- return NJS_ERROR;
+ if (thrw) {
+ njs_key_string_get(vm, &pq.key, &pq.lhq.key);
+ njs_type_error(vm, "Cannot delete property \"%V\" of %s",
+ &pq.lhq.key, njs_type_string(value->type));
+ return NJS_ERROR;
+ }
+
+ return NJS_OK;
}
switch (prop->type) {
diff -r 900d3ba62bcb -r 723873b4e315 src/njs_value.h
--- a/src/njs_value.h Thu Apr 28 17:59:03 2022 -0700
+++ b/src/njs_value.h Wed May 04 16:23:46 2022 -0700
@@ -1062,7 +1062,7 @@ njs_int_t njs_value_property(njs_vm_t *v
njs_int_t njs_value_property_set(njs_vm_t *vm, njs_value_t *value,
njs_value_t *key, njs_value_t *setval);
njs_int_t njs_value_property_delete(njs_vm_t *vm, njs_value_t *value,
- njs_value_t *key, njs_value_t *removed);
+ njs_value_t *key, njs_value_t *removed, njs_bool_t thrw);
njs_int_t njs_value_to_object(njs_vm_t *vm, njs_value_t *value);
void njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string);
@@ -1110,7 +1110,7 @@ njs_value_property_i64_delete(njs_vm_t *
return ret;
}
- return njs_value_property_delete(vm, value, &key, removed);
+ return njs_value_property_delete(vm, value, &key, removed, 1);
}
diff -r 900d3ba62bcb -r 723873b4e315 src/njs_vmcode.c
--- a/src/njs_vmcode.c Thu Apr 28 17:59:03 2022 -0700
+++ b/src/njs_vmcode.c Wed May 04 16:23:46 2022 -0700
@@ -500,7 +500,7 @@ next:
break;
case NJS_VMCODE_PROPERTY_DELETE:
- ret = njs_value_property_delete(vm, value1, value2, NULL);
+ ret = njs_value_property_delete(vm, value1, value2, NULL, 1);
if (njs_fast_path(ret != NJS_ERROR)) {
vm->retval = njs_value_true;
More information about the nginx-devel
mailing list