]> git.kaiwu.me - njs.git/commitdiff
Fixed Object prototype methods according to the spec.
authorVadim Zhestikov <v.zhestikov@f5.com>
Mon, 10 Nov 2025 16:56:28 +0000 (08:56 -0800)
committerVadimZhestikov <108960056+VadimZhestikov@users.noreply.github.com>
Fri, 14 Nov 2025 00:05:28 +0000 (16:05 -0800)
src/njs_object.c

index 26e8182b954637a1f325cd0f2563522f625b294e..0f277fea5687fbb62b26208d637b647f427c66e6 100644 (file)
@@ -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;