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;
}
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);
} while (object != NULL);
- njs_thread_log_alert("prototype not found");
-
return NJS_ERROR;
} else {
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;
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);