[njs] Introduced njs_vm_prototype() to get a value's prototype.

Dmitry Volyntsev xeioex at nginx.com
Tue Mar 19 05:56:52 UTC 2024


details:   https://hg.nginx.org/njs/rev/6808a27d254a
branches:  
changeset: 2298:6808a27d254a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Mar 14 23:28:03 2024 -0700
description:
Introduced njs_vm_prototype() to get a value's prototype.

diffstat:

 src/njs.h        |   2 ++
 src/njs_object.c |   2 +-
 src/njs_object.h |   2 ++
 src/njs_vm.c     |  13 +++++++++++++
 4 files changed, 18 insertions(+), 1 deletions(-)

diffs (59 lines):

diff -r 00b89201fb71 -r 6808a27d254a src/njs.h
--- a/src/njs.h	Thu Mar 14 23:28:03 2024 -0700
+++ b/src/njs.h	Thu Mar 14 23:28:03 2024 -0700
@@ -373,6 +373,8 @@ NJS_EXPORT njs_int_t njs_vm_value(njs_vm
     njs_value_t *retval);
 NJS_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, const njs_str_t *name);
 NJS_EXPORT njs_bool_t njs_vm_constructor(njs_vm_t *vm);
+NJS_EXPORT njs_int_t njs_vm_prototype(njs_vm_t *vm, njs_value_t *value,
+    njs_value_t *retval);
 
 NJS_EXPORT void njs_vm_throw(njs_vm_t *vm, const njs_value_t *value);
 NJS_EXPORT void njs_vm_error2(njs_vm_t *vm, unsigned error_type,
diff -r 00b89201fb71 -r 6808a27d254a src/njs_object.c
--- a/src/njs_object.c	Thu Mar 14 23:28:03 2024 -0700
+++ b/src/njs_object.c	Thu Mar 14 23:28:03 2024 -0700
@@ -1598,7 +1598,7 @@ njs_object_get_own_property(njs_vm_t *vm
 }
 
 
-static njs_int_t
+njs_int_t
 njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused, njs_value_t *retval)
 {
diff -r 00b89201fb71 -r 6808a27d254a src/njs_object.h
--- a/src/njs_object.h	Thu Mar 14 23:28:03 2024 -0700
+++ b/src/njs_object.h	Thu Mar 14 23:28:03 2024 -0700
@@ -106,6 +106,8 @@ njs_int_t njs_object_prop_define(njs_vm_
     njs_value_t *name, njs_value_t *value, unsigned flags, uint32_t hash);
 njs_int_t njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
     njs_value_t *value, njs_value_t *setval);
+njs_int_t njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args,
+    njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
 const char *njs_prop_type_string(njs_object_prop_type_t type);
 njs_int_t njs_object_prop_init(njs_vm_t *vm, const njs_object_init_t* init,
     const njs_object_prop_t *base, njs_value_t *value, njs_value_t *retval);
diff -r 00b89201fb71 -r 6808a27d254a src/njs_vm.c
--- a/src/njs_vm.c	Thu Mar 14 23:28:03 2024 -0700
+++ b/src/njs_vm.c	Thu Mar 14 23:28:03 2024 -0700
@@ -1201,6 +1201,19 @@ njs_vm_object_keys(njs_vm_t *vm, njs_val
 
 
 njs_int_t
+njs_vm_prototype(njs_vm_t *vm, njs_value_t *value, njs_value_t *retval)
+{
+    njs_value_t arguments[2];
+
+    njs_set_undefined(&arguments[0]);
+    njs_value_assign(&arguments[1], value);
+
+    return njs_object_get_prototype_of(vm, njs_value_arg(&arguments), 2, 0,
+                                       retval);
+}
+
+
+njs_int_t
 njs_vm_array_alloc(njs_vm_t *vm, njs_value_t *retval, uint32_t spare)
 {
     njs_array_t  *array;


More information about the nginx-devel mailing list