blob: 4943077a7d8c865b6776aa34ed3c368e80e18b6f [file] [log] [blame]
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#ifndef _NJS_OBJECT_H_INCLUDED_
#define _NJS_OBJECT_H_INCLUDED_
#define njs_is_data_descriptor(prop) \
((prop)->writable != NJS_ATTRIBUTE_UNSET || njs_is_valid(&(prop)->value))
#define njs_is_accessor_descriptor(prop) \
(njs_is_function_or_undefined(&(prop)->getter) \
|| njs_is_function_or_undefined(&(prop)->setter))
#define njs_is_generic_descriptor(prop) \
(!njs_is_data_descriptor(prop) && !njs_is_accessor_descriptor(prop))
#define njs_object_property_init(lhq, _key, hash) \
do { \
(lhq)->proto = &njs_object_hash_proto; \
(lhq)->key_hash = hash; \
(lhq)->key = njs_str_value(_key); \
} while (0)
typedef enum {
NJS_OBJECT_PROP_DESCRIPTOR,
NJS_OBJECT_PROP_GETTER,
NJS_OBJECT_PROP_SETTER,
} njs_object_prop_define_t;
struct njs_object_init_s {
const njs_object_prop_t *properties;
njs_uint_t items;
};
typedef struct njs_traverse_s njs_traverse_t;
struct njs_traverse_s {
struct njs_traverse_s *parent;
njs_object_prop_t *prop;
njs_object_t *object;
njs_lvlhsh_t *hash;
njs_lvlhsh_each_t lhe;
#define NJS_TRAVERSE_MAX_DEPTH 32
};
typedef njs_int_t (*njs_object_traverse_cb_t)(njs_vm_t *vm,
njs_traverse_t *traverse, void *ctx);
njs_object_t *njs_object_alloc(njs_vm_t *vm);
njs_object_t *njs_object_value_copy(njs_vm_t *vm, njs_value_t *value);
njs_object_t *njs_object_value_alloc(njs_vm_t *vm, const njs_value_t *value,
njs_uint_t type);
njs_array_t *njs_object_enumerate(njs_vm_t *vm, const njs_object_t *object,
njs_object_enum_t kind, njs_bool_t all);
njs_array_t *njs_object_own_enumerate(njs_vm_t *vm, const njs_object_t *object,
njs_object_enum_t kind, njs_bool_t all);
njs_int_t njs_object_traverse(njs_vm_t *vm, njs_object_t *object, void *ctx,
njs_object_traverse_cb_t cb);
njs_int_t njs_object_hash_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
const njs_object_prop_t *prop, njs_uint_t n);
njs_int_t njs_primitive_prototype_get_proto(njs_vm_t *vm,
njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
njs_value_t *retval);
njs_int_t njs_object_prototype_create(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_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
njs_object_t *prototype);
njs_int_t njs_object_prototype_proto(njs_vm_t *vm, njs_object_prop_t *prop,
njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
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 *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);
njs_int_t njs_object_length(njs_vm_t *vm, njs_value_t *value, uint32_t *dest);
njs_int_t njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq);
njs_object_prop_t *njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
const njs_value_t *value, uint8_t attributes);
njs_int_t njs_object_property(njs_vm_t *vm, const njs_value_t *value,
njs_lvlhsh_query_t *lhq, njs_value_t *retval);
njs_int_t njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
njs_value_t *name, njs_value_t *value, njs_object_prop_define_t type);
njs_int_t njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
njs_value_t *value, njs_value_t *setval);
const char *njs_prop_type_string(njs_object_prop_type_t type);
extern const njs_object_type_init_t njs_obj_type_init;
njs_inline njs_int_t
njs_object_length_set(njs_vm_t *vm, njs_value_t *value, uint32_t length)
{
njs_value_t index;
static const njs_value_t string_length = njs_string("length");
njs_value_number_set(&index, length);
return njs_value_property_set(vm, value, njs_value_arg(&string_length),
&index);
}
#endif /* _NJS_OBJECT_H_INCLUDED_ */