[njs] Using njs_set_undefined() and njs_set_invalid() where appropriate.
Dmitry Volyntsev
xeioex at nginx.com
Mon Aug 12 18:05:17 UTC 2019
details: https://hg.nginx.org/njs/rev/5f2162f7c3df
branches:
changeset: 1124:5f2162f7c3df
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Aug 12 21:04:50 2019 +0300
description:
Using njs_set_undefined() and njs_set_invalid() where appropriate.
diffstat:
src/njs_array.c | 14 +++++++-------
src/njs_builtin.c | 2 +-
src/njs_fs.c | 16 ++++++++--------
src/njs_function.c | 2 +-
src/njs_generator.c | 2 +-
src/njs_json.c | 6 +++---
src/njs_object.c | 4 ++--
src/njs_object_prop.c | 40 ++++++++++++++++++++--------------------
src/njs_parser.c | 2 +-
src/njs_parser_terminal.c | 4 ++--
src/njs_regexp.c | 2 +-
src/njs_shell.c | 10 +++++-----
src/njs_string.c | 4 ++--
src/njs_timer.c | 4 ++--
src/njs_value.c | 4 ++--
src/njs_vm.c | 4 ++--
src/njs_vmcode.c | 4 ++--
src/test/njs_unit_test.c | 2 +-
18 files changed, 63 insertions(+), 63 deletions(-)
diffs (562 lines):
diff -r 03008af6253b -r 5f2162f7c3df src/njs_array.c
--- a/src/njs_array.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_array.c Mon Aug 12 21:04:50 2019 +0300
@@ -543,7 +543,7 @@ njs_array_prototype_slice_copy(njs_vm_t
ret = njs_value_property(vm, this, &name, value);
if (ret != NJS_OK) {
- *value = njs_value_invalid;
+ njs_set_invalid(value);
}
length--;
@@ -556,7 +556,7 @@ njs_array_prototype_slice_copy(njs_vm_t
value = array->start;
do {
- *value++ = njs_value_invalid;
+ njs_set_invalid(value++);
length--;
} while (length != 0);
}
@@ -1398,7 +1398,7 @@ njs_array_prototype_for_each(njs_vm_t *v
length = njs_min(length, njs_array_len(array));
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1576,7 +1576,7 @@ njs_array_prototype_find(njs_vm_t *vm, n
value = njs_array_start(array)[i];
if (!njs_is_valid(&value)) {
- value = njs_value_undefined;
+ njs_set_undefined(&value);
}
ret = njs_array_iterator_call(vm, function, this_arg, &value, i, array);
@@ -1624,7 +1624,7 @@ njs_array_prototype_find_index(njs_vm_t
value = njs_array_start(array)[i];
if (!njs_is_valid(&value)) {
- value = njs_value_undefined;
+ njs_set_undefined(&value);
}
ret = njs_array_iterator_call(vm, function, this_arg, &value, i, array);
@@ -1712,7 +1712,7 @@ njs_array_iterator_reduce(njs_vm_t *vm,
/* GC: array elt, array */
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
arguments[1] = *accumulator;
arguments[2] = *value;
njs_set_number(&arguments[3], n);
@@ -1924,7 +1924,7 @@ start:
if (njs_is_valid(&start[n])) {
if (njs_is_valid(&start[n - 1])) {
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
/* GC: array elt, array */
arguments[1] = start[n - 1];
diff -r 03008af6253b -r 5f2162f7c3df src/njs_builtin.c
--- a/src/njs_builtin.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_builtin.c Mon Aug 12 21:04:50 2019 +0300
@@ -415,7 +415,7 @@ static njs_int_t
njs_prototype_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_fs.c
--- a/src/njs_fs.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_fs.c Mon Aug 12 21:04:50 2019 +0300
@@ -280,13 +280,13 @@ done:
return NJS_ERROR;
}
- arguments[2] = njs_value_undefined;
+ njs_set_undefined(&arguments[2]);
} else {
- arguments[1] = njs_value_undefined;
+ njs_set_undefined(&arguments[1]);
}
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
ret = njs_function_apply(vm, njs_function(callback), arguments, 3,
&vm->retval);
@@ -295,7 +295,7 @@ done:
return ret;
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
@@ -722,10 +722,10 @@ done:
}
} else {
- arguments[1] = njs_value_undefined;
+ njs_set_undefined(&arguments[1]);
}
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
ret = njs_function_apply(vm, njs_function(callback), arguments, 2,
&vm->retval);
@@ -734,7 +734,7 @@ done:
return ret;
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -899,7 +899,7 @@ done:
}
} else {
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
}
return NJS_OK;
diff -r 03008af6253b -r 5f2162f7c3df src/njs_function.c
--- a/src/njs_function.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_function.c Mon Aug 12 21:04:50 2019 +0300
@@ -399,7 +399,7 @@ njs_function_lambda_frame(njs_vm_t *vm,
}
while (max_args != 0) {
- *value++ = njs_value_undefined;
+ njs_set_undefined(value++);
max_args--;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_generator.c
--- a/src/njs_generator.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_generator.c Mon Aug 12 21:04:50 2019 +0300
@@ -2477,7 +2477,7 @@ njs_generate_scope(njs_vm_t *vm, njs_gen
value = (njs_value_t *) (p + size);
for (n = scope_size - size; n != 0; n -= sizeof(njs_value_t)) {
- *value++ = njs_value_undefined;
+ njs_set_undefined(value++);
}
if (vm->codes == NULL) {
diff -r 03008af6253b -r 5f2162f7c3df src/njs_json.c
--- a/src/njs_json.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_json.c Mon Aug 12 21:04:50 2019 +0300
@@ -271,7 +271,7 @@ njs_json_stringify(njs_vm_t *vm, njs_val
}
} else {
- stringify->replacer = njs_value_undefined;
+ njs_set_undefined(&stringify->replacer);
}
stringify->space.length = 0;
@@ -1470,7 +1470,7 @@ done:
* An empty object means empty result.
*/
if (str.length <= njs_length("{\n\n}")) {
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
goto release;
}
@@ -2417,7 +2417,7 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_
stringify->nodes = NULL;
stringify->last = NULL;
stringify->stack.items = 0;
- stringify->replacer = njs_value_undefined;
+ njs_set_undefined(&stringify->replacer);
if (!njs_dump_is_object(value)) {
ret = njs_dump_value(stringify, value, console);
diff -r 03008af6253b -r 5f2162f7c3df src/njs_object.c
--- a/src/njs_object.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_object.c Mon Aug 12 21:04:50 2019 +0300
@@ -1327,7 +1327,7 @@ njs_object_freeze(njs_vm_t *vm, njs_valu
value = njs_arg(args, nargs, 1);
if (!njs_is_object(value)) {
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1902,7 +1902,7 @@ njs_object_prototype_proto(njs_vm_t *vm,
}
}
- *retval = njs_value_undefined;
+ njs_set_undefined(retval);
return NJS_OK;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_object_prop.c
--- a/src/njs_object_prop.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_object_prop.c Mon Aug 12 21:04:50 2019 +0300
@@ -33,8 +33,8 @@ njs_object_prop_alloc(njs_vm_t *vm, cons
prop->enumerable = attributes;
prop->configurable = attributes;
- prop->getter = njs_value_invalid;
- prop->setter = njs_value_invalid;
+ njs_set_invalid(&prop->getter);
+ njs_set_invalid(&prop->setter);
return prop;
}
@@ -72,7 +72,7 @@ njs_object_property(njs_vm_t *vm, const
} while (object != NULL);
- *retval = njs_value_undefined;
+ njs_set_undefined(retval);
return NJS_DECLINED;
@@ -86,7 +86,7 @@ found:
}
if (njs_is_undefined(&prop->getter)) {
- *retval = njs_value_undefined;
+ njs_set_undefined(retval);
return NJS_OK;
}
@@ -133,7 +133,7 @@ njs_object_prop_define(njs_vm_t *vm, njs
case NJS_OBJECT_PROP_GETTER:
prop->getter = *value;
- prop->setter = njs_value_invalid;
+ njs_set_invalid(&prop->setter);
prop->enumerable = NJS_ATTRIBUTE_TRUE;
prop->configurable = NJS_ATTRIBUTE_TRUE;
@@ -141,7 +141,7 @@ njs_object_prop_define(njs_vm_t *vm, njs
case NJS_OBJECT_PROP_SETTER:
prop->setter = *value;
- prop->getter = njs_value_invalid;
+ njs_set_invalid(&prop->getter);
prop->enumerable = NJS_ATTRIBUTE_TRUE;
prop->configurable = NJS_ATTRIBUTE_TRUE;
@@ -150,15 +150,15 @@ njs_object_prop_define(njs_vm_t *vm, njs
if (njs_fast_path(ret == NJS_DECLINED)) {
- /* 6.2.5.6 CompletePropertypropriptor */
+ /* 6.2.5.6 CompletePropertyDescriptor */
if (njs_is_accessor_descriptor(prop)) {
if (!njs_is_valid(&prop->getter)) {
- prop->getter = njs_value_undefined;
+ njs_set_undefined(&prop->getter);
}
if (!njs_is_valid(&prop->setter)) {
- prop->setter = njs_value_undefined;
+ njs_set_undefined(&prop->setter);
}
} else {
@@ -167,7 +167,7 @@ njs_object_prop_define(njs_vm_t *vm, njs
}
if (!njs_is_valid(&prop->value)) {
- prop->value = njs_value_undefined;
+ njs_set_undefined(&prop->value);
}
}
@@ -215,7 +215,7 @@ njs_object_prop_define(njs_vm_t *vm, njs
if (njs_is_valid(&prop->value)) {
*prev->value.data.u.value = prop->value;
} else {
- *prev->value.data.u.value = njs_value_undefined;
+ njs_set_undefined(prev->value.data.u.value);
}
return NJS_OK;
@@ -259,18 +259,18 @@ njs_object_prop_define(njs_vm_t *vm, njs
*/
if (njs_is_data_descriptor(prev)) {
- prev->getter = njs_value_undefined;
- prev->setter = njs_value_undefined;
+ njs_set_undefined(&prev->getter);
+ njs_set_undefined(&prev->setter);
- prev->value = njs_value_invalid;
+ njs_set_invalid(&prev->value);
prev->writable = NJS_ATTRIBUTE_UNSET;
} else {
- prev->value = njs_value_undefined;
+ njs_set_undefined(&prev->value);
prev->writable = NJS_ATTRIBUTE_FALSE;
- prev->getter = njs_value_invalid;
- prev->setter = njs_value_invalid;
+ njs_set_invalid(&prev->getter);
+ njs_set_invalid(&prev->setter);
}
@@ -390,7 +390,7 @@ njs_descriptor_prop(njs_vm_t *vm, njs_ob
} else {
/* NJS_DECLINED */
- prop->getter = njs_value_invalid;
+ njs_set_invalid(&prop->getter);
}
lhq.key = njs_str_value("set");
@@ -413,7 +413,7 @@ njs_descriptor_prop(njs_vm_t *vm, njs_ob
} else {
/* NJS_DECLINED */
- prop->setter = njs_value_invalid;
+ njs_set_invalid(&prop->setter);
}
lhq.key = njs_str_value("value");
@@ -534,7 +534,7 @@ njs_object_prop_descriptor(njs_vm_t *vm,
break;
case NJS_DECLINED:
- *dest = njs_value_undefined;
+ njs_set_undefined(dest);
return NJS_OK;
case NJS_ERROR:
diff -r 03008af6253b -r 5f2162f7c3df src/njs_parser.c
--- a/src/njs_parser.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_parser.c Mon Aug 12 21:04:50 2019 +0300
@@ -510,7 +510,7 @@ njs_parser_variable_node(njs_vm_t *vm, n
switch (type) {
case NJS_VARIABLE_VAR:
- var->value = njs_value_undefined;
+ njs_set_undefined(&var->value);
break;
default:
diff -r 03008af6253b -r 5f2162f7c3df src/njs_parser_terminal.c
--- a/src/njs_parser_terminal.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_parser_terminal.c Mon Aug 12 21:04:50 2019 +0300
@@ -227,7 +227,7 @@ njs_parser_reference(njs_vm_t *vm, njs_p
case NJS_TOKEN_UNDEFINED:
njs_thread_log_debug("JS: undefined");
- node->u.value = njs_value_undefined;
+ njs_set_undefined(&node->u.value);
break;
case NJS_TOKEN_THIS:
@@ -264,7 +264,7 @@ njs_parser_reference(njs_vm_t *vm, njs_p
node->token = NJS_TOKEN_GLOBAL_THIS;
if (vm->options.module) {
- node->u.value = njs_value_undefined;
+ njs_set_undefined(&node->u.value);
break;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_regexp.c
--- a/src/njs_regexp.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_regexp.c Mon Aug 12 21:04:50 2019 +0300
@@ -994,7 +994,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs
}
} else {
- array->start[i] = njs_value_undefined;
+ njs_set_undefined(&array->start[i]);
}
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_shell.c
--- a/src/njs_shell.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_shell.c Mon Aug 12 21:04:50 2019 +0300
@@ -989,7 +989,7 @@ njs_ext_console_log(njs_vm_t *vm, njs_va
njs_printf("\n");
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1021,7 +1021,7 @@ njs_ext_console_dump(njs_vm_t *vm, njs_v
njs_printf("\n");
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1052,7 +1052,7 @@ njs_ext_console_help(njs_vm_t *vm, njs_v
njs_printf("\n");
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1076,7 +1076,7 @@ njs_ext_console_time(njs_vm_t *vm, njs_v
console->time = njs_time();
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -1116,7 +1116,7 @@ njs_ext_console_time_end(njs_vm_t *vm, n
njs_printf("Timer \"default\" doesn’t exist.\n");
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_string.c
--- a/src/njs_string.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_string.c Mon Aug 12 21:04:50 2019 +0300
@@ -3318,7 +3318,7 @@ njs_string_replace_regexp_function(njs_v
return NJS_ERROR;
}
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
/* Matched substring and parenthesized submatch strings. */
for (k = 0, i = 1; i <= n; i++) {
@@ -3460,7 +3460,7 @@ njs_string_replace_search_function(njs_v
njs_value_t string;
njs_value_t arguments[4];
- arguments[0] = njs_value_undefined;
+ njs_set_undefined(&arguments[0]);
/* GC, args[0], args[1] */
diff -r 03008af6253b -r 5f2162f7c3df src/njs_timer.c
--- a/src/njs_timer.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_timer.c Mon Aug 12 21:04:50 2019 +0300
@@ -104,7 +104,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu
njs_lvlhsh_query_t lhq;
if (njs_fast_path(nargs < 2) || !njs_is_number(&args[1])) {
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
@@ -123,7 +123,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu
njs_del_event(vm, event, NJS_EVENT_RELEASE | NJS_EVENT_DELETE);
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
diff -r 03008af6253b -r 5f2162f7c3df src/njs_value.c
--- a/src/njs_value.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_value.c Mon Aug 12 21:04:50 2019 +0300
@@ -1005,7 +1005,7 @@ njs_value_property(njs_vm_t *vm, njs_val
}
if (njs_is_undefined(&prop->getter)) {
- *retval = njs_value_undefined;
+ njs_set_undefined(retval);
break;
}
@@ -1036,7 +1036,7 @@ njs_value_property(njs_vm_t *vm, njs_val
break;
case NJS_DECLINED:
- *retval = njs_value_undefined;
+ njs_set_undefined(retval);
return NJS_DECLINED;
diff -r 03008af6253b -r 5f2162f7c3df src/njs_vm.c
--- a/src/njs_vm.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_vm.c Mon Aug 12 21:04:50 2019 +0300
@@ -180,7 +180,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
njs_arr_reset(vm->backtrace);
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
ret = njs_parser(vm, parser, prev);
if (njs_slow_path(ret != NJS_OK)) {
@@ -374,7 +374,7 @@ njs_vm_init(njs_vm_t *vm)
}
if (njs_is_null(&vm->retval)) {
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
}
return NJS_OK;
diff -r 03008af6253b -r 5f2162f7c3df src/njs_vmcode.c
--- a/src/njs_vmcode.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_vmcode.c Mon Aug 12 21:04:50 2019 +0300
@@ -552,7 +552,7 @@ next:
break;
case NJS_VMCODE_VOID:
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
ret = sizeof(njs_vmcode_2addr_t);
break;
@@ -1436,7 +1436,7 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs
retval = &njs_value_false;
if (njs_is_object(object)) {
- value = njs_value_undefined;
+ njs_set_undefined(&value);
ret = njs_value_property(vm, constructor, &prototype_string, &value);
if (njs_slow_path(ret == NJS_ERROR)) {
diff -r 03008af6253b -r 5f2162f7c3df src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Mon Aug 12 21:04:49 2019 +0300
+++ b/src/test/njs_unit_test.c Mon Aug 12 21:04:50 2019 +0300
@@ -13940,7 +13940,7 @@ njs_unit_test_method_external(njs_vm_t *
r->uri.length);
}
- vm->retval = njs_value_undefined;
+ njs_set_undefined(&vm->retval);
return NJS_OK;
}
More information about the nginx-devel
mailing list