From 826d2fbaaa4275e5a2bc147013cfad061cece273 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 29 Sep 2022 16:32:45 -0700 Subject: [PATCH] Introduced njs_object_proto_lookup() where appropriate. --- src/njs_function.c | 21 +++++---------------- src/njs_string.c | 16 +++------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/njs_function.c b/src/njs_function.c index 58fef67a..e4eb801b 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -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 --git a/src/njs_string.c b/src/njs_string.c index 62bece0d..86755be0 100644 --- a/src/njs_string.c +++ b/src/njs_string.c @@ -664,7 +664,6 @@ njs_string_instance_length(njs_vm_t *vm, njs_object_prop_t *prop, { 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, njs_object_prop_t *prop, 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; } } -- 2.47.3