From: Vadim Zhestikov Date: Mon, 10 Nov 2025 16:56:28 +0000 (-0800) Subject: Fixed Object prototype methods according to the spec. X-Git-Tag: 0.9.5~30 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=2322b7d300fc2b15b1ab9919cf26fa2a86fa69c6;p=njs.git Fixed Object prototype methods according to the spec. --- diff --git a/src/njs_object.c b/src/njs_object.c index 26e8182b..0f277fea 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -2596,14 +2596,6 @@ njs_object_prototype_has_own_property(njs_vm_t *vm, njs_value_t *args, njs_value_t *value, *property, lvalue; njs_property_query_t pq; - value = njs_argument(args, 0); - - if (njs_is_null_or_undefined(value)) { - njs_type_error(vm, "cannot convert %s argument to object", - njs_type_string(value->type)); - return NJS_ERROR; - } - property = njs_lvalue_arg(&lvalue, args, nargs, 1); if (njs_slow_path(!njs_is_key(property))) { @@ -2613,6 +2605,14 @@ njs_object_prototype_has_own_property(njs_vm_t *vm, njs_value_t *args, } } + value = njs_argument(args, 0); + + if (njs_is_null_or_undefined(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); + return NJS_ERROR; + } + njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1); ret = njs_property_query_val(vm, &pq, value, property); @@ -2642,14 +2642,6 @@ njs_object_prototype_prop_is_enumerable(njs_vm_t *vm, njs_value_t *args, njs_object_prop_t *prop; njs_property_query_t pq; - value = njs_argument(args, 0); - - if (njs_is_null_or_undefined(value)) { - njs_type_error(vm, "cannot convert %s argument to object", - njs_type_string(value->type)); - return NJS_ERROR; - } - property = njs_lvalue_arg(&lvalue, args, nargs, 1); if (njs_slow_path(!njs_is_key(property))) { @@ -2659,6 +2651,14 @@ njs_object_prototype_prop_is_enumerable(njs_vm_t *vm, njs_value_t *args, } } + value = njs_argument(args, 0); + + if (njs_is_null_or_undefined(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); + return NJS_ERROR; + } + njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1); ret = njs_property_query_val(vm, &pq, value, property); @@ -2689,15 +2689,20 @@ njs_object_prototype_is_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_value_t *prototype, *value; njs_object_t *object, *proto; + value = njs_arg(args, nargs, 1); + + if (njs_slow_path(!njs_is_object(value))) { + goto ret_false; + } + if (njs_slow_path(njs_is_null_or_undefined(njs_argument(args, 0)))) { njs_type_error(vm, "cannot convert undefined to object"); return NJS_ERROR; } prototype = &args[0]; - value = njs_arg(args, nargs, 1); - if (njs_is_object(prototype) && njs_is_object(value)) { + if (njs_is_object(prototype)) { proto = njs_object(prototype); object = njs_object(value); @@ -2712,6 +2717,8 @@ njs_object_prototype_is_prototype_of(njs_vm_t *vm, njs_value_t *args, } while (object != NULL); } +ret_false: + njs_set_boolean(retval, 0); return NJS_OK;