[njs] Introduced njs_object_proto_lookup() where appropriate.
Dmitry Volyntsev
xeioex at nginx.com
Fri Sep 30 00:05:29 UTC 2022
details: https://hg.nginx.org/njs/rev/7f43ac9cdc30
branches:
changeset: 1970:7f43ac9cdc30
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Sep 29 16:32:45 2022 -0700
description:
Introduced njs_object_proto_lookup() where appropriate.
diffstat:
src/njs_function.c | 21 +++++----------------
src/njs_string.c | 16 +++-------------
2 files changed, 8 insertions(+), 29 deletions(-)
diffs (68 lines):
diff -r c2a05d35ad72 -r 7f43ac9cdc30 src/njs_function.c
--- a/src/njs_function.c Thu Sep 29 00:47:43 2022 -0700
+++ b/src/njs_function.c Thu Sep 29 16:32:45 2022 -0700
@@ -1302,26 +1302,15 @@ njs_int_t
njs_function_instance_length(njs_vm_t *vm, njs_object_prop_t *prop,
njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
{
- njs_object_t *proto;
njs_function_t *function;
- proto = njs_object(value);
-
- do {
- if (njs_fast_path(proto->type == NJS_FUNCTION)) {
- break;
- }
-
- proto = proto->__proto__;
- } while (proto != NULL);
-
- if (njs_slow_path(proto == NULL)) {
- njs_internal_error(vm, "no function in proto chain");
- return NJS_ERROR;
+ function = njs_object_proto_lookup(njs_object(value), NJS_FUNCTION,
+ njs_function_t);
+ if (njs_slow_path(function == NULL)) {
+ njs_set_undefined(retval);
+ return NJS_DECLINED;
}
- function = (njs_function_t *) proto;
-
njs_set_number(retval, function->args_count);
return NJS_OK;
diff -r c2a05d35ad72 -r 7f43ac9cdc30 src/njs_string.c
--- a/src/njs_string.c Thu Sep 29 00:47:43 2022 -0700
+++ b/src/njs_string.c Thu Sep 29 16:32:45 2022 -0700
@@ -664,7 +664,6 @@ njs_string_instance_length(njs_vm_t *vm,
{
size_t size;
uintptr_t length;
- njs_object_t *proto;
njs_object_value_t *ov;
/*
@@ -674,18 +673,9 @@ njs_string_instance_length(njs_vm_t *vm,
length = 0;
if (njs_slow_path(njs_is_object(value))) {
- proto = njs_object(value);
-
- do {
- if (njs_fast_path(proto->type == NJS_OBJECT_VALUE)) {
- break;
- }
-
- proto = proto->__proto__;
- } while (proto != NULL);
-
- if (proto != NULL) {
- ov = (njs_object_value_t *) proto;
+ ov = njs_object_proto_lookup(njs_object(value), NJS_OBJECT_VALUE,
+ njs_object_value_t);
+ if (ov != NULL) {
value = &ov->value;
}
}
More information about the nginx-devel
mailing list