[njs] Fixed function "constructor" property handler while setting.
Dmitry Volyntsev
xeioex at nginx.com
Tue Aug 25 12:08:06 UTC 2020
details: https://hg.nginx.org/njs/rev/85bfd770a3da
branches:
changeset: 1501:85bfd770a3da
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Aug 24 11:28:21 2020 +0000
description:
Fixed function "constructor" property handler while setting.
diffstat:
src/njs_function.c | 3 +--
src/njs_object.c | 38 +++++++++++++++++++++++++-------------
src/njs_object.h | 2 +-
3 files changed, 27 insertions(+), 16 deletions(-)
diffs (93 lines):
diff -r 775c81dcbe61 -r 85bfd770a3da src/njs_function.c
--- a/src/njs_function.c Fri Aug 21 13:07:54 2020 +0000
+++ b/src/njs_function.c Mon Aug 24 11:28:21 2020 +0000
@@ -853,8 +853,7 @@ njs_function_prototype_create(njs_vm_t *
if (setval == &proto_value && njs_is_object(proto)) {
/* Only in getter context. */
- cons = njs_property_constructor_create(vm, njs_object_hash(proto),
- value);
+ cons = njs_property_constructor_set(vm, njs_object_hash(proto), value);
if (njs_slow_path(cons == NULL)) {
return NJS_ERROR;
}
diff -r 775c81dcbe61 -r 85bfd770a3da src/njs_object.c
--- a/src/njs_object.c Fri Aug 21 13:07:54 2020 +0000
+++ b/src/njs_object.c Mon Aug 24 11:28:21 2020 +0000
@@ -2216,6 +2216,22 @@ njs_object_prototype_create_constructor(
njs_object_t *object;
njs_object_prototype_t *prototype;
+ if (setval != NULL) {
+ if (!njs_is_object(value)) {
+ njs_type_error(vm, "Cannot create propery \"constructor\" on %s",
+ njs_type_string(value->type));
+ return NJS_ERROR;
+ }
+
+ cons = njs_property_constructor_set(vm, njs_object_hash(value), setval);
+ if (njs_slow_path(cons == NULL)) {
+ return NJS_ERROR;
+ }
+
+ *retval = *cons;
+ return NJS_OK;
+ }
+
if (njs_is_object(value)) {
object = njs_object(value);
@@ -2231,8 +2247,6 @@ njs_object_prototype_create_constructor(
} while (object != NULL);
- njs_thread_log_alert("prototype not found");
-
return NJS_ERROR;
} else {
@@ -2242,23 +2256,21 @@ njs_object_prototype_create_constructor(
found:
- if (setval == NULL) {
- njs_set_function(&constructor, &vm->constructors[index]);
- setval = &constructor;
+ njs_set_function(&constructor, &vm->constructors[index]);
+ setval = &constructor;
+
+ cons = njs_property_constructor_set(vm, &prototype->object.hash, setval);
+ if (njs_slow_path(cons == NULL)) {
+ return NJS_ERROR;
}
- cons = njs_property_constructor_create(vm, &prototype->object.hash, setval);
- if (njs_fast_path(cons != NULL)) {
- *retval = *cons;
- return NJS_OK;
- }
-
- return NJS_ERROR;
+ *retval = *cons;
+ return NJS_OK;
}
njs_value_t *
-njs_property_constructor_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
+njs_property_constructor_set(njs_vm_t *vm, njs_lvlhsh_t *hash,
njs_value_t *constructor)
{
njs_int_t ret;
diff -r 775c81dcbe61 -r 85bfd770a3da src/njs_object.h
--- a/src/njs_object.h Fri Aug 21 13:07:54 2020 +0000
+++ b/src/njs_object.h Mon Aug 24 11:28:21 2020 +0000
@@ -63,7 +63,7 @@ njs_int_t njs_object_prototype_proto(njs
njs_int_t njs_object_prototype_create_constructor(njs_vm_t *vm,
njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
njs_value_t *retval);
-njs_value_t *njs_property_constructor_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
+njs_value_t *njs_property_constructor_set(njs_vm_t *vm, njs_lvlhsh_t *hash,
njs_value_t *constructor);
njs_int_t njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
njs_uint_t nargs, njs_index_t unused);
More information about the nginx-devel
mailing list