From: Dmitry Volyntsev Date: Mon, 24 Aug 2020 11:28:21 +0000 (+0000) Subject: Fixed function "constructor" property handler while setting. X-Git-Tag: 0.4.4~30 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=0fad824b1ef90bf1d1f119d1eb961273501c4ed3;p=njs.git Fixed function "constructor" property handler while setting. --- diff --git a/src/njs_function.c b/src/njs_function.c index 796624e6..db1ef31f 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -853,8 +853,7 @@ njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop, 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 --git a/src/njs_object.c b/src/njs_object.c index 154be583..e77e3737 100644 --- a/src/njs_object.c +++ b/src/njs_object.c @@ -2216,6 +2216,22 @@ njs_object_prototype_create_constructor(njs_vm_t *vm, njs_object_prop_t *prop, 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(njs_vm_t *vm, njs_object_prop_t *prop, } while (object != NULL); - njs_thread_log_alert("prototype not found"); - return NJS_ERROR; } else { @@ -2242,23 +2256,21 @@ njs_object_prototype_create_constructor(njs_vm_t *vm, njs_object_prop_t *prop, 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_create(vm, &prototype->object.hash, setval); - if (njs_fast_path(cons != NULL)) { - *retval = *cons; - return NJS_OK; + cons = njs_property_constructor_set(vm, &prototype->object.hash, setval); + if (njs_slow_path(cons == NULL)) { + return NJS_ERROR; } - 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 --git a/src/njs_object.h b/src/njs_object.h index ddea784e..d4c40aed 100644 --- a/src/njs_object.h +++ b/src/njs_object.h @@ -63,7 +63,7 @@ njs_int_t njs_object_prototype_proto(njs_vm_t *vm, njs_object_prop_t *prop, 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);