]> git.kaiwu.me - njs.git/commitdiff
Fixed handling of missing arg of Object.getOwnPropertyDescriptor().
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Apr 2018 16:24:55 +0000 (19:24 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 26 Apr 2018 16:24:55 +0000 (19:24 +0300)
This fixes #5 issue on GitHub.

njs/njs_object.c
njs/test/njs_unit_test.c

index 06a31e72dec7d8871273714ffc08d86168745cd8..ec993cf462f15832c1c315a0f54ef26c7826025c 100644 (file)
@@ -629,9 +629,14 @@ njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args,
     value = njs_arg(args, nargs, 1);
 
     if (!njs_is_object(value)) {
-        njs_type_error(vm, "cannot convert %s argument to object",
-                       njs_type_string(value->type));
-        return NXT_ERROR;
+        if (njs_is_null_or_void(value)) {
+            njs_type_error(vm, "cannot convert %s argument to object",
+                           njs_type_string(value->type));
+            return NXT_ERROR;
+        }
+
+        vm->retval = njs_value_void;
+        return NXT_OK;
     }
 
     prop = NULL;
@@ -662,7 +667,7 @@ njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args,
         ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq);
 
         if (ret != NXT_OK) {
-            vm->retval = njs_string_void;
+            vm->retval = njs_value_void;
             return NXT_OK;
         }
 
@@ -1164,7 +1169,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
         .type = NJS_METHOD,
         .name = njs_long_string("getOwnPropertyDescriptor"),
         .value = njs_native_function(njs_object_get_own_property_descriptor, 0,
-                                     NJS_SKIP_ARG, NJS_OBJECT_ARG,
+                                     NJS_SKIP_ARG, NJS_SKIP_ARG,
                                      NJS_STRING_ARG),
     },
 
index 96c11f44721645e093c9c3511d3e445847e4e815..c8f46b505a9ca70ff6abf2b6d24c97e83d89f49e 100644 (file)
@@ -6603,7 +6603,13 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("undefined") },
 
     { nxt_string("Object.getOwnPropertyDescriptor(1, '0')"),
-      nxt_string("TypeError: cannot convert number argument to object") },
+      nxt_string("undefined") },
+
+    { nxt_string("Object.getOwnPropertyDescriptor()"),
+      nxt_string("TypeError: cannot convert void argument to object") },
+
+    { nxt_string("Object.getOwnPropertyDescriptor(undefined)"),
+      nxt_string("TypeError: cannot convert void argument to object") },
 
     { nxt_string("Object.defineProperty(Object.freeze({}), 'b', {})"),
       nxt_string("TypeError: object is not extensible") },