static const njs_object_prop_t njs_dirent_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Dirent"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Dirent"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 2.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(2),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
return NJS_DECLINED;
}
- switch (prop->value.data.magic32 & 0xf) {
+ switch (njs_prop_magic32(prop) & 0xf) {
case NJS_FS_STAT_DEV:
v = st->st_dev;
break;
break;
}
- switch (prop->value.data.magic32 >> 4) {
+ switch (njs_prop_magic32(prop) >> 4) {
case NJS_NUMBER:
njs_set_number(retval, v);
break;
static const njs_object_prop_t njs_fs_promises_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readFile"),
- .value = njs_native_function2(njs_fs_read_file, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readFile", njs_fs_read_file, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readSync"),
- .value = njs_native_function2(njs_fs_read, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readSync", njs_fs_read, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("appendFile"),
- .value = njs_native_function2(njs_fs_write_file, 0,
- njs_fs_magic(NJS_FS_PROMISE, NJS_FS_APPEND)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("appendFile", njs_fs_write_file, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_APPEND)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeFile"),
- .value = njs_native_function2(njs_fs_write_file, 0,
- njs_fs_magic(NJS_FS_PROMISE, NJS_FS_TRUNC)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeFile", njs_fs_write_file, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_TRUNC)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("access"),
- .value = njs_native_function2(njs_fs_access, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("access", njs_fs_access, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("mkdir"),
- .value = njs_native_function2(njs_fs_mkdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("mkdir", njs_fs_mkdir, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("open"),
- .value = njs_native_function2(njs_fs_open, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("open", njs_fs_open, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("close"),
- .value = njs_native_function2(njs_fs_close, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("close", njs_fs_close, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("rename"),
- .value = njs_native_function2(njs_fs_rename, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("rename", njs_fs_rename, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("rmdir"),
- .value = njs_native_function2(njs_fs_rmdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("rmdir", njs_fs_rmdir, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readdir"),
- .value = njs_native_function2(njs_fs_readdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readdir", njs_fs_readdir, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fstat"),
- .value = njs_native_function2(njs_fs_stat, 0,
- njs_fs_magic(NJS_FS_PROMISE, NJS_FS_FSTAT)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fstat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_FSTAT)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("lstat"),
- .value = njs_native_function2(njs_fs_stat, 0,
- njs_fs_magic(NJS_FS_PROMISE, NJS_FS_LSTAT)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("lstat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_LSTAT)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("stat"),
- .value = njs_native_function2(njs_fs_stat, 0,
- njs_fs_magic(NJS_FS_PROMISE, NJS_FS_STAT)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("stat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_STAT)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("symlink"),
- .value = njs_native_function2(njs_fs_symlink, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("symlink", njs_fs_symlink, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("unlink"),
- .value = njs_native_function2(njs_fs_unlink, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("unlink", njs_fs_unlink, 0, NJS_FS_PROMISE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("realpath"),
- .value = njs_native_function2(njs_fs_realpath, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("realpath", njs_fs_realpath, 0, NJS_FS_PROMISE),
};
static const njs_object_prop_t njs_fs_constants_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("F_OK"),
- .value = njs_value(NJS_NUMBER, 0, F_OK),
- .enumerable = 1,
- },
- {
- .type = NJS_PROPERTY,
- .name = njs_string("R_OK"),
- .value = njs_value(NJS_NUMBER, 1, R_OK),
- .enumerable = 1,
- },
- {
- .type = NJS_PROPERTY,
- .name = njs_string("W_OK"),
- .value = njs_value(NJS_NUMBER, 1, W_OK),
- .enumerable = 1,
- },
- {
- .type = NJS_PROPERTY,
- .name = njs_string("X_OK"),
- .value = njs_value(NJS_NUMBER, 1, X_OK),
- .enumerable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("F_OK", njs_value(NJS_NUMBER, 0, F_OK),
+ NJS_OBJECT_PROP_VALUE_E),
+
+ NJS_DECLARE_PROP_VALUE("R_OK", njs_value(NJS_NUMBER, 0, R_OK),
+ NJS_OBJECT_PROP_VALUE_E),
+
+ NJS_DECLARE_PROP_VALUE("W_OK", njs_value(NJS_NUMBER, 0, W_OK),
+ NJS_OBJECT_PROP_VALUE_E),
+
+ NJS_DECLARE_PROP_VALUE("X_OK", njs_value(NJS_NUMBER, 0, X_OK),
+ NJS_OBJECT_PROP_VALUE_E),
};
return NJS_ERROR;
}
- prop->value = array->start[i];
+ njs_value_assign(njs_prop_value(prop), &array->start[i]);
}
}
prop->enumerable = 0;
prop->configurable = 0;
- njs_value_number_set(&prop->value, length);
+ njs_value_number_set(njs_prop_value(prop), length);
return NJS_OK;
}
return NJS_ERROR;
}
- ret = njs_value_to_length(vm, &prev->value, &prev_length);
+ ret = njs_value_to_length(vm, njs_prop_value(prev), &prev_length);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
static const njs_object_prop_t njs_array_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isArray"),
- .value = njs_native_function(njs_array_is_array, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isArray", njs_array_is_array, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("of"),
- .value = njs_native_function(njs_array_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("of", njs_array_of, 0, 0),
};
}
prop->type = NJS_PROPERTY;
- njs_set_number(&prop->value, length);
+ njs_set_number(njs_prop_value(prop), length);
- *retval = *setval;
+ njs_value_assign(retval, setval);
return NJS_OK;
}
static const njs_object_prop_t njs_array_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_array_length),
- .writable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_array_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_W),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("concat"),
- .value = njs_native_function(njs_array_prototype_concat, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("concat", njs_array_prototype_concat, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("copyWithin"),
- .value = njs_native_function(njs_array_prototype_copy_within, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("copyWithin", njs_array_prototype_copy_within, 2,
+ 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("entries"),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_BOTH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("entries", njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_BOTH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("every"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_EVERY)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("every", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_EVERY)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fill"),
- .value = njs_native_function(njs_array_prototype_fill, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fill", njs_array_prototype_fill, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("filter"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_FILTER)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("filter", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FILTER)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("find"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_FIND)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("find", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FIND)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("findIndex"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_FIND_INDEX)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("findIndex", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FIND_INDEX)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("forEach"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_FOR_EACH)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("forEach", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FOR_EACH)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("includes"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_arg(NJS_ARRAY_INCLUDES)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("includes", njs_array_prototype_iterator, 1,
+ njs_array_arg(NJS_ARRAY_INCLUDES)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("indexOf"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_arg(NJS_ARRAY_INDEX_OF)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("indexOf", njs_array_prototype_iterator, 1,
+ njs_array_arg(NJS_ARRAY_INDEX_OF)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("join"),
- .value = njs_native_function(njs_array_prototype_join, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("join", njs_array_prototype_join, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("keys"),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_KEYS),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("keys", njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_KEYS),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("lastIndexOf"),
- .value = njs_native_function2(njs_array_prototype_reverse_iterator, 1,
- NJS_ARRAY_LAST_INDEX_OF),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("lastIndexOf",
+ njs_array_prototype_reverse_iterator, 1,
+ NJS_ARRAY_LAST_INDEX_OF),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("map"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_MAP)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("map", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_MAP)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("pop"),
- .value = njs_native_function(njs_array_prototype_pop, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("pop", njs_array_prototype_pop, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("push"),
- .value = njs_native_function(njs_array_prototype_push, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("push", njs_array_prototype_push, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reduce"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_REDUCE)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reduce", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_REDUCE)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reduceRight"),
- .value = njs_native_function2(njs_array_prototype_reverse_iterator, 1,
- NJS_ARRAY_REDUCE_RIGHT),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reduceRight",
+ njs_array_prototype_reverse_iterator, 1,
+ njs_array_func(NJS_ARRAY_REDUCE_RIGHT)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reverse"),
- .value = njs_native_function(njs_array_prototype_reverse, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reverse", njs_array_prototype_reverse, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("shift"),
- .value = njs_native_function(njs_array_prototype_shift, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("shift", njs_array_prototype_shift, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function(njs_array_prototype_slice, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("slice", njs_array_prototype_slice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("some"),
- .value = njs_native_function2(njs_array_prototype_iterator, 1,
- njs_array_func(NJS_ARRAY_SOME)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("some", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_SOME)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sort"),
- .value = njs_native_function(njs_array_prototype_sort, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sort", njs_array_prototype_sort, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("splice"),
- .value = njs_native_function(njs_array_prototype_splice, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("splice", njs_array_prototype_splice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_array_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_array_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("unshift"),
- .value = njs_native_function(njs_array_prototype_unshift, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("unshift", njs_array_prototype_unshift, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("values"),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_VALUES),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("values", njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_VALUES),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_ITERATOR),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_VALUES),
+ .u.value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_VALUES),
.writable = 1,
.configurable = 1,
},
const njs_object_prop_t njs_array_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_array_length),
- .writable = 1
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_array_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_W),
};
static const njs_object_prop_t njs_array_buffer_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("ArrayBuffer"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("ArrayBuffer"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_array_buffer_get_this, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
+ .u.accessor = njs_getter(njs_array_buffer_get_this, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
- .enumerable = 0,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isView"),
- .value = njs_native_function(njs_array_buffer_is_view, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isView", njs_array_buffer_is_view, 1, 0),
};
static const njs_object_prop_t njs_array_buffer_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("byteLength"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_array_buffer_prototype_byte_length,
- 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("byteLength",
+ njs_array_buffer_prototype_byte_length, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function(njs_array_buffer_prototype_slice, 2),
- .writable = 1,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_NATIVE("slice", njs_array_buffer_prototype_slice, 2, 0),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("ArrayBuffer"),
+ .u.value = njs_string("ArrayBuffer"),
.configurable = 1,
},
};
static const njs_object_prop_t njs_async_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("AsyncFunction"),
+ .u.value = njs_string("AsyncFunction"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
};
const njs_object_prop_t njs_async_function_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_function_instance_length),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_function_instance_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("name"),
- .value = njs_prop_handler(njs_function_instance_name),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("name", njs_function_instance_name, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
};
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
- .value = njs_string("Boolean"),
+ .u.value = njs_string("Boolean"),
.configurable = 1,
},
{
.type = NJS_PROPERTY,
.name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
+ .u.value = njs_value(NJS_NUMBER, 1, 1.0),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_boolean_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_primitive_prototype_get_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_boolean_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_boolean_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_boolean_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_boolean_prototype_to_string, 0, 0),
};
&& !(njs_is_object(&retval)
&& njs_object(&retval) == njs_object(value)))
{
- *value = retval;
+ njs_value_assign(value, &retval);
goto next;
}
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("Buffer"),
+ .u.value = njs_string("Buffer"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_buffer_prototype_length),
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_buffer_prototype_length, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readInt8"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(1, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readInt8", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(1, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUInt8"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(1, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUInt8", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(1, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readInt16LE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(2, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readInt16LE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(2, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUInt16LE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(2, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUInt16LE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(2, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readInt16BE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(2, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readInt16BE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(2, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUInt16BE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(2, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUInt16BE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(2, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readInt32LE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(4, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readInt32LE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(4, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUInt32LE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(4, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUInt32LE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(4, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readInt32BE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(4, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readInt32BE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(4, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUInt32BE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 1,
- njs_buffer_magic(4, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUInt32BE", njs_buffer_prototype_read_int, 1,
+ njs_buffer_magic(4, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readIntLE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 2,
- njs_buffer_magic(0, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readIntLE", njs_buffer_prototype_read_int, 2,
+ njs_buffer_magic(0, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUIntLE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 2,
- njs_buffer_magic(0, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUIntLE", njs_buffer_prototype_read_int, 2,
+ njs_buffer_magic(0, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readIntBE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 2,
- njs_buffer_magic(0, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readIntBE", njs_buffer_prototype_read_int, 2,
+ njs_buffer_magic(0, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readUIntBE"),
- .value = njs_native_function2(njs_buffer_prototype_read_int, 2,
- njs_buffer_magic(0, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readUIntBE", njs_buffer_prototype_read_int, 2,
+ njs_buffer_magic(0, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readFloatLE"),
- .value = njs_native_function2(njs_buffer_prototype_read_float, 1,
- njs_buffer_magic(4, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readFloatLE", njs_buffer_prototype_read_float, 1,
+ njs_buffer_magic(4, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readFloatBE"),
- .value = njs_native_function2(njs_buffer_prototype_read_float, 1,
- njs_buffer_magic(4, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readFloatBE", njs_buffer_prototype_read_float, 1,
+ njs_buffer_magic(4, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readDoubleLE"),
- .value = njs_native_function2(njs_buffer_prototype_read_float, 1,
- njs_buffer_magic(8, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readDoubleLE", njs_buffer_prototype_read_float, 1,
+ njs_buffer_magic(8, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readDoubleBE"),
- .value = njs_native_function2(njs_buffer_prototype_read_float, 1,
- njs_buffer_magic(8, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("readDoubleBE", njs_buffer_prototype_read_float, 1,
+ njs_buffer_magic(8, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeInt8"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(1, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeInt8", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(1, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUInt8"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(1, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUInt8", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(1, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeInt16LE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(2, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeInt16LE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(2, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUInt16LE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(2, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUInt16LE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(2, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeInt16BE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(2, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeInt16BE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(2, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUInt16BE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(2, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUInt16BE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(2, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeInt32LE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(4, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeInt32LE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(4, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUInt32LE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(4, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUInt32LE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(4, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeInt32BE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(4, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeInt32BE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(4, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUInt32BE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 1,
- njs_buffer_magic(4, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUInt32BE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(4, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeIntLE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 3,
- njs_buffer_magic(0, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeIntLE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(0, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUIntLE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 3,
- njs_buffer_magic(0, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUIntLE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(0, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeIntBE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 3,
- njs_buffer_magic(0, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeIntBE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(0, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeUIntBE"),
- .value = njs_native_function2(njs_buffer_prototype_write_int, 3,
- njs_buffer_magic(0, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeUIntBE", njs_buffer_prototype_write_int, 1,
+ njs_buffer_magic(0, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeFloatLE"),
- .value = njs_native_function2(njs_buffer_prototype_write_float, 1,
- njs_buffer_magic(4, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeFloatLE", njs_buffer_prototype_write_float,
+ 1, njs_buffer_magic(4, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeFloatBE"),
- .value = njs_native_function2(njs_buffer_prototype_write_float, 1,
- njs_buffer_magic(4, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeFloatBE", njs_buffer_prototype_write_float,
+ 1, njs_buffer_magic(4, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeDoubleLE"),
- .value = njs_native_function2(njs_buffer_prototype_write_float, 1,
- njs_buffer_magic(8, 0, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeDoubleLE", njs_buffer_prototype_write_float,
+ 1, njs_buffer_magic(8, 0, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("writeDoubleBE"),
- .value = njs_native_function2(njs_buffer_prototype_write_float, 1,
- njs_buffer_magic(8, 0, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("writeDoubleBE", njs_buffer_prototype_write_float,
+ 1, njs_buffer_magic(8, 0, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("write"),
- .value = njs_native_function(njs_buffer_prototype_write, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("write", njs_buffer_prototype_write, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fill"),
- .value = njs_native_function(njs_buffer_prototype_fill, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fill", njs_buffer_prototype_fill, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_buffer_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_buffer_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("compare"),
- .value = njs_native_function(njs_buffer_prototype_compare, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("compare", njs_buffer_prototype_compare, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("copy"),
- .value = njs_native_function(njs_buffer_prototype_copy, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("copy", njs_buffer_prototype_copy, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("equals"),
- .value = njs_native_function(njs_buffer_prototype_equals, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("equals", njs_buffer_prototype_equals, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("indexOf"),
- .value = njs_native_function2(njs_buffer_prototype_index_of, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("indexOf", njs_buffer_prototype_index_of, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("lastIndexOf"),
- .value = njs_native_function2(njs_buffer_prototype_index_of, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("lastIndexOf", njs_buffer_prototype_index_of, 1,
+ 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("includes"),
- .value = njs_native_function(njs_buffer_prototype_includes, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("includes", njs_buffer_prototype_includes, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("subarray"),
- .value = njs_native_function2(njs_buffer_prototype_slice, 2, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("subarray", njs_buffer_prototype_slice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function2(njs_buffer_prototype_slice, 2, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("slice", njs_buffer_prototype_slice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("swap16"),
- .value = njs_native_function2(njs_buffer_prototype_swap, 0, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("swap16", njs_buffer_prototype_swap, 0, 2),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("swap32"),
- .value = njs_native_function2(njs_buffer_prototype_swap, 0, 4),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("swap32", njs_buffer_prototype_swap, 0, 4),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("swap64"),
- .value = njs_native_function2(njs_buffer_prototype_swap, 0, 8),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("swap64", njs_buffer_prototype_swap, 0, 8),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toJSON"),
- .value = njs_native_function(njs_buffer_prototype_to_json, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toJSON", njs_buffer_prototype_to_json, 0, 0),
};
static const njs_object_prop_t njs_buffer_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Buffer"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Buffer"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("alloc"),
- .value = njs_native_function2(njs_buffer_alloc_safe, 0, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("allocUnsafe"),
- .value = njs_native_function2(njs_buffer_alloc_safe, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("alloc", njs_buffer_alloc_safe, 0, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("allocUnsafeSlow"),
- .value = njs_native_function2(njs_buffer_alloc_safe, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("allocUnsafe", njs_buffer_alloc_safe, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("byteLength"),
- .value = njs_native_function(njs_buffer_byte_length, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("allocUnsafeSlow", njs_buffer_alloc_safe, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("compare"),
- .value = njs_native_function(njs_buffer_compare, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("byteLength", njs_buffer_byte_length, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("concat"),
- .value = njs_native_function(njs_buffer_concat, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("compare", njs_buffer_compare, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("from"),
- .value = njs_native_function(njs_buffer_from, 3),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("concat", njs_buffer_concat, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isBuffer"),
- .value = njs_native_function(njs_buffer_is_buffer, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("from", njs_buffer_from, 3, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isEncoding"),
- .value = njs_native_function(njs_buffer_is_encoding, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isBuffer", njs_buffer_is_buffer, 1, 0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_NATIVE("isEncoding", njs_buffer_is_encoding, 1, 0),
};
static const njs_object_prop_t njs_buffer_constants_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("MAX_LENGTH"),
- .value = njs_value(NJS_NUMBER, 1, INT32_MAX),
- .enumerable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("MAX_LENGTH", njs_value(NJS_NUMBER, 1, INT32_MAX),
+ NJS_OBJECT_PROP_VALUE_E),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("MAX_STRING_LENGTH"),
- .value = njs_value(NJS_NUMBER, 1, NJS_STRING_MAX_LENGTH),
- .enumerable = 1,
- },
+ NJS_DECLARE_PROP_LVALUE("MAX_STRING_LENGTH",
+ njs_value(NJS_NUMBER, 1, NJS_STRING_MAX_LENGTH),
+ NJS_OBJECT_PROP_VALUE_E),
};
njs_int_t ret, n;
njs_str_t name;
njs_bool_t symbol;
- njs_value_t key;
- njs_function_t *func;
+ njs_value_t key, *value;
+ njs_function_t *func, *target;
njs_object_prop_t *prop;
njs_lvlhsh_query_t lhq;
njs_builtin_traverse_t *ctx;
prop = traverse->prop;
func = ctx->func;
- if (!(njs_is_function(&prop->value)
- && njs_function(&prop->value)->native
- && njs_native_function_same(njs_function(&prop->value), func)))
+ if (njs_is_accessor_descriptor(prop)) {
+ target = njs_prop_getter(prop);
+
+ } else {
+ value = njs_prop_value(prop);
+ target = (njs_is_function(value) && njs_function(value)->native)
+ ? njs_function(value)
+ : NULL;
+ }
+
+ if (target == NULL
+ || !njs_native_function_same(target, func))
{
return NJS_OK;
}
prop = lhq.value;
- if (!njs_is_object(&prop->value)) {
+ if (njs_is_accessor_descriptor(prop) ||
+ !njs_is_object(njs_prop_value(prop)))
+ {
return NULL;
}
- value = &prop->value;
+ value = njs_prop_value(prop);
}
return njs_object_completions(vm, value);
value = njs_scope_valid_value(vm, var->index);
if (var->type == NJS_VARIABLE_FUNCTION && njs_is_undefined(value)) {
- *value = var->value;
+ njs_value_assign(value, &var->value);
function = njs_function_value_copy(vm, value);
if (njs_slow_path(function == NULL)) {
}
if (setval != NULL) {
- *value = *setval;
+ njs_value_assign(value, setval);
}
- *retval = *value;
+ njs_value_assign(retval, value);
return NJS_OK;
}
njs_object_prop_t *prop;
njs_lvlhsh_query_t lhq;
- *retval = *global;
+ njs_value_assign(retval, global);
if (njs_slow_path(setval != NULL)) {
- *retval = *setval;
+ njs_value_assign(retval, setval);
} else if (njs_slow_path(retval == NULL)) {
return NJS_DECLINED;
return NJS_ERROR;
}
- /* GC */
-
- prop->value = *retval;
+ njs_value_assign(njs_prop_value(prop), retval);
prop->enumerable = self->enumerable;
lhq.value = prop;
njs_string_get(&self->name, &lhq.key);
- lhq.key_hash = self->value.data.magic32;
+ lhq.key_hash = njs_prop_magic32(self);
lhq.replace = 1;
lhq.pool = vm->mem_pool;
lhq.proto = &njs_object_hash_proto;
njs_lvlhsh_query_t lhq;
if (njs_slow_path(setval != NULL)) {
- *retval = *setval;
+ njs_value_assign(retval, setval);
} else {
if (njs_slow_path(retval == NULL)) {
return NJS_DECLINED;
}
- njs_set_object(retval, &vm->shared->objects[self->value.data.magic16]);
+ njs_set_object(retval, &vm->shared->objects[njs_prop_magic16(self)]);
object = njs_object_value_copy(vm, retval);
if (njs_slow_path(object == NULL)) {
return NJS_ERROR;
}
- /* GC */
-
- prop->value = *retval;
+ njs_value_assign(njs_prop_value(prop), retval);
prop->enumerable = self->enumerable;
lhq.value = prop;
njs_string_get(&self->name, &lhq.key);
- lhq.key_hash = self->value.data.magic32;
+ lhq.key_hash = njs_prop_magic32(self);
lhq.replace = 1;
lhq.pool = vm->mem_pool;
lhq.proto = &njs_object_hash_proto;
njs_lvlhsh_query_t lhq;
if (njs_slow_path(setval != NULL)) {
- *retval = *setval;
+ njs_value_assign(retval, setval);
} else {
if (njs_slow_path(retval == NULL)) {
return NJS_DECLINED;
}
- ctor = &vm->constructors[self->value.data.magic16];
+ ctor = &vm->constructors[njs_prop_magic16(self)];
njs_set_function(retval, ctor);
}
return NJS_ERROR;
}
- /* GC */
-
- prop->value = *retval;
+ njs_value_assign(njs_prop_value(prop), retval);
prop->enumerable = 0;
lhq.value = prop;
njs_string_get(&self->name, &lhq.key);
- lhq.key_hash = self->value.data.magic32;
+ lhq.key_hash = njs_prop_magic32(self);
lhq.replace = 1;
lhq.pool = vm->mem_pool;
lhq.proto = &njs_object_hash_proto;
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("global"),
+ .u.value = njs_string("global"),
.configurable = 1,
},
/* Global aliases. */
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("global"),
- .value = njs_prop_handler2(njs_global_this_object, 0, NJS_GLOBAL_HASH),
- .writable = 1,
- .enumerable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("global", njs_global_this_object, 0,
+ NJS_GLOBAL_HASH, NJS_OBJECT_PROP_VALUE_ECW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("globalThis"),
- .value = njs_prop_handler2(njs_global_this_object, 0,
- NJS_GLOBAL_THIS_HASH),
- .writable = 1,
- .enumerable = 0,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("globalThis", njs_global_this_object, 0,
+ NJS_GLOBAL_THIS_HASH, NJS_OBJECT_PROP_VALUE_CW),
/* Global constants. */
- {
- .type = NJS_PROPERTY,
- .name = njs_string("NaN"),
- .value = njs_value(NJS_NUMBER, 0, NAN),
- },
+ NJS_DECLARE_PROP_VALUE("NaN", njs_value(NJS_NUMBER, 0, NAN), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("Infinity"),
- .value = njs_value(NJS_NUMBER, 1, INFINITY),
- },
+ NJS_DECLARE_PROP_VALUE("Infinity", njs_value(NJS_NUMBER, 1, INFINITY), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("undefined"),
- .value = njs_value(NJS_UNDEFINED, 0, NAN),
- },
+ NJS_DECLARE_PROP_VALUE("undefined", njs_value(NJS_UNDEFINED, 0, NAN), 0),
/* Global functions. */
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isFinite"),
- .value = njs_native_function(njs_number_global_is_finite, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isFinite", njs_number_global_is_finite, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isNaN"),
- .value = njs_native_function(njs_number_global_is_nan, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isNaN", njs_number_global_is_nan, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parseFloat"),
- .value = njs_native_function(njs_number_parse_float, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parseFloat", njs_number_parse_float, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parseInt"),
- .value = njs_native_function(njs_number_parse_int, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parseInt", njs_number_parse_int, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_object_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_object_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("encodeURI"),
- .value = njs_native_function2(njs_string_encode_uri, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("encodeURI", njs_string_encode_uri, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("encodeURIComponent"),
- .value = njs_native_function2(njs_string_encode_uri, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("encodeURIComponent", njs_string_encode_uri, 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("decodeURI"),
- .value = njs_native_function2(njs_string_decode_uri, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("decodeURI", njs_string_decode_uri, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("decodeURIComponent"),
- .value = njs_native_function2(njs_string_decode_uri, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("decodeURIComponent", njs_string_decode_uri, 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("atob"),
- .value = njs_native_function(njs_string_atob, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("atob", njs_string_atob, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("btoa"),
- .value = njs_native_function(njs_string_btoa, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("btoa", njs_string_btoa, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("eval"),
- .value = njs_native_function(njs_eval_function, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("eval", njs_eval_function, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setTimeout"),
- .value = njs_native_function(njs_set_timeout, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setTimeout", njs_set_timeout, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setImmediate"),
- .value = njs_native_function(njs_set_immediate, 4),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setImmediate", njs_set_immediate, 4, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("clearTimeout"),
- .value = njs_native_function(njs_clear_timeout, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("clearTimeout", njs_clear_timeout, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("require"),
- .value = njs_native_function(njs_module_require, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("require", njs_module_require, 1, 0),
/* Global objects. */
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("njs"),
- .value = njs_prop_handler2(njs_top_level_object, NJS_OBJECT_NJS,
- NJS_NJS_HASH),
- .writable = 1,
- .enumerable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("njs", njs_top_level_object, NJS_OBJECT_NJS,
+ NJS_NJS_HASH, NJS_OBJECT_PROP_VALUE_ECW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("process"),
- .value = njs_prop_handler2(njs_top_level_object, NJS_OBJECT_PROCESS,
- NJS_PROCESS_HASH),
- .writable = 1,
- .enumerable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("process", njs_top_level_object,
+ NJS_OBJECT_PROCESS, NJS_PROCESS_HASH,
+ NJS_OBJECT_PROP_VALUE_ECW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Math"),
- .value = njs_prop_handler2(njs_top_level_object, NJS_OBJECT_MATH,
- NJS_MATH_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Math", njs_top_level_object,
+ NJS_OBJECT_MATH, NJS_MATH_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
+
+ NJS_DECLARE_PROP_HANDLER("JSON", njs_top_level_object,
+ NJS_OBJECT_JSON, NJS_JSON_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("JSON"),
- .value = njs_prop_handler2(njs_top_level_object, NJS_OBJECT_JSON,
- NJS_JSON_HASH),
- .writable = 1,
- .configurable = 1,
- },
#ifdef NJS_TEST262
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("$262"),
- .value = njs_prop_handler2(njs_top_level_object, NJS_OBJECT_262,
- NJS_262_HASH),
- .writable = 1,
- .enumerable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("$262", njs_top_level_object,
+ NJS_OBJECT_262, NJS_262_HASH,
+ NJS_OBJECT_PROP_VALUE_ECW),
#endif
/* Global constructors. */
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Object"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_OBJECT, NJS_OBJECT_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Object", njs_top_level_constructor,
+ NJS_OBJ_TYPE_OBJECT, NJS_OBJECT_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_ARRAY, NJS_ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_ARRAY, NJS_ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("ArrayBuffer"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_ARRAY_BUFFER,
- NJS_ARRAY_BUFFER_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("ArrayBuffer", njs_top_level_constructor,
+ NJS_OBJ_TYPE_ARRAY_BUFFER, NJS_ARRAY_BUFFER_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("DataView"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_DATA_VIEW,
- NJS_DATA_VIEW_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("DataView", njs_top_level_constructor,
+ NJS_OBJ_TYPE_DATA_VIEW, NJS_DATA_VIEW_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("TextDecoder"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_TEXT_DECODER,
- NJS_TEXT_DECODER_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("TextDecoder", njs_top_level_constructor,
+ NJS_OBJ_TYPE_TEXT_DECODER, NJS_TEXT_DECODER_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("TextEncoder"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_TEXT_ENCODER,
- NJS_TEXT_ENCODER_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("TextEncoder", njs_top_level_constructor,
+ NJS_OBJ_TYPE_TEXT_ENCODER, NJS_TEXT_ENCODER_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Buffer"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_BUFFER, NJS_BUFFER_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Buffer", njs_top_level_constructor,
+ NJS_OBJ_TYPE_BUFFER, NJS_BUFFER_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Uint8Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_UINT8_ARRAY,
- NJS_UINT8ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Uint8Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_UINT8_ARRAY, NJS_UINT8ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Uint16Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_UINT16_ARRAY,
- NJS_UINT16ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Uint16Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_UINT16_ARRAY, NJS_UINT16ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Uint32Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_UINT32_ARRAY,
- NJS_UINT32ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Uint32Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_UINT32_ARRAY, NJS_UINT32ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Int8Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_INT8_ARRAY,
- NJS_INT8ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Int8Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_INT8_ARRAY, NJS_INT8ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Int16Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_INT16_ARRAY,
- NJS_INT16ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Int16Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_INT16_ARRAY, NJS_INT16ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Int32Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_INT32_ARRAY,
- NJS_INT32ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Int32Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_INT32_ARRAY, NJS_INT32ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Float32Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_FLOAT32_ARRAY,
- NJS_FLOAT32ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Float32Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_FLOAT32_ARRAY, NJS_FLOAT32ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Float64Array"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_FLOAT64_ARRAY,
- NJS_FLOAT64ARRAY_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Float64Array", njs_top_level_constructor,
+ NJS_OBJ_TYPE_FLOAT64_ARRAY, NJS_FLOAT64ARRAY_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
{
.type = NJS_PROPERTY_HANDLER,
.name = njs_long_string("Uint8ClampedArray"),
- .value = njs_prop_handler2(njs_top_level_constructor,
+ .u.value = njs_prop_handler2(njs_top_level_constructor,
NJS_OBJ_TYPE_UINT8_CLAMPED_ARRAY,
NJS_UINT8CLAMPEDARRAY_HASH),
.writable = 1,
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Boolean"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_BOOLEAN, NJS_BOOLEAN_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Boolean", njs_top_level_constructor,
+ NJS_OBJ_TYPE_BOOLEAN, NJS_BOOLEAN_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Number"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_NUMBER, NJS_NUMBER_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Number", njs_top_level_constructor,
+ NJS_OBJ_TYPE_NUMBER, NJS_NUMBER_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Symbol"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_SYMBOL, NJS_SYMBOL_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Symbol", njs_top_level_constructor,
+ NJS_OBJ_TYPE_SYMBOL, NJS_SYMBOL_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("String"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_STRING, NJS_STRING_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("String", njs_top_level_constructor,
+ NJS_OBJ_TYPE_STRING, NJS_STRING_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Function"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_FUNCTION, NJS_FUNCTION_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Function", njs_top_level_constructor,
+ NJS_OBJ_TYPE_FUNCTION, NJS_FUNCTION_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("RegExp"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_REGEXP, NJS_REGEXP_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("RegExp", njs_top_level_constructor,
+ NJS_OBJ_TYPE_REGEXP, NJS_REGEXP_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Date"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_DATE, NJS_DATE_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Date", njs_top_level_constructor,
+ NJS_OBJ_TYPE_DATE, NJS_DATE_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Promise"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_PROMISE, NJS_PROMISE_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Promise", njs_top_level_constructor,
+ NJS_OBJ_TYPE_PROMISE, NJS_PROMISE_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("Error"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_ERROR, NJS_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("Error", njs_top_level_constructor,
+ NJS_OBJ_TYPE_ERROR, NJS_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("EvalError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_EVAL_ERROR,
- NJS_EVAL_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("EvalError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_EVAL_ERROR, NJS_EVAL_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("InternalError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_INTERNAL_ERROR,
- NJS_INTERNAL_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("InternalError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_INTERNAL_ERROR,
+ NJS_INTERNAL_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("RangeError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_RANGE_ERROR,
- NJS_RANGE_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("RangeError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_RANGE_ERROR, NJS_RANGE_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("ReferenceError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_REF_ERROR, NJS_REF_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("ReferenceError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_REF_ERROR, NJS_REF_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("SyntaxError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_SYNTAX_ERROR,
- NJS_SYNTAX_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("SyntaxError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_SYNTAX_ERROR, NJS_SYNTAX_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("TypeError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_TYPE_ERROR,
- NJS_TYPE_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("TypeError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_TYPE_ERROR, NJS_TYPE_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("URIError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_URI_ERROR,
- NJS_URI_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("URIError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_URI_ERROR, NJS_URI_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("MemoryError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_MEMORY_ERROR,
- NJS_MEMORY_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("MemoryError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_MEMORY_ERROR, NJS_MEMORY_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("AggregateError"),
- .value = njs_prop_handler2(njs_top_level_constructor,
- NJS_OBJ_TYPE_AGGREGATE_ERROR,
- NJS_AGGREGATE_ERROR_HASH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("AggregateError", njs_top_level_constructor,
+ NJS_OBJ_TYPE_AGGREGATE_ERROR,
+ NJS_AGGREGATE_ERROR_HASH,
+ NJS_OBJECT_PROP_VALUE_CW),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("njs"),
+ .u.value = njs_string("njs"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("version"),
- .value = njs_string(NJS_VERSION),
- .configurable = 1,
- .enumerable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("version", njs_string(NJS_VERSION),
+ NJS_OBJECT_PROP_VALUE_EC),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("version_number"),
- .value = njs_value(NJS_NUMBER, 1, NJS_VERSION_NUMBER),
- .configurable = 1,
- .enumerable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("version_number",
+ njs_value(NJS_NUMBER, 1, NJS_VERSION_NUMBER),
+ NJS_OBJECT_PROP_VALUE_EC),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("dump"),
- .value = njs_native_function(njs_ext_dump, 0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("dump", njs_ext_dump, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("on"),
- .value = njs_native_function(njs_ext_on, 0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("on", njs_ext_on, 0, 0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("memoryStats"),
- .value = njs_prop_handler(njs_ext_memory_stats),
- },
+ NJS_DECLARE_PROP_HANDLER("memoryStats", njs_ext_memory_stats, 0, 0,
+ NJS_OBJECT_PROP_VALUE_EC),
};
return NJS_ERROR;
}
- njs_set_array(&prop->value, argv);
+ njs_set_array(njs_prop_value(prop), argv);
lhq.value = prop;
lhq.key_hash = NJS_ARGV_HASH;
ret = njs_lvlhsh_insert(njs_object_hash(process), &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
return NJS_OK;
}
val++;
- ret = njs_string_create(vm, &prop->value, (char *) val,
+ ret = njs_string_create(vm, njs_prop_value(prop), (char *) val,
njs_strlen(val));
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
prev = lhq.value;
- if (!njs_values_same(&prop->value, &prev->value)) {
+ if (!njs_values_same(njs_prop_value(prop), njs_prop_value(prev))) {
njs_vm_warn(vm, "environment variable \"%V\" has more than one"
" value\n", &lhq.key);
}
return NJS_ERROR;
}
- njs_set_object(&prop->value, env);
+ njs_set_object(njs_prop_value(prop), env);
lhq.replace = 1;
lhq.pool = vm->mem_pool;
ret = njs_lvlhsh_insert(njs_object_hash(process), &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
return NJS_OK;
}
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("process"),
+ .u.value = njs_string("process"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("argv"),
- .value = njs_prop_handler(njs_process_object_argv),
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("env"),
- .value = njs_prop_handler(njs_process_object_env),
- },
+ NJS_DECLARE_PROP_HANDLER("argv", njs_process_object_argv, 0, 0, 0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("pid"),
- .value = njs_prop_handler(njs_process_object_pid),
- },
+ NJS_DECLARE_PROP_HANDLER("env", njs_process_object_env, 0, 0, 0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("ppid"),
- .value = njs_prop_handler(njs_process_object_ppid),
- },
+ NJS_DECLARE_PROP_HANDLER("pid", njs_process_object_pid, 0, 0, 0),
+ NJS_DECLARE_PROP_HANDLER("ppid", njs_process_object_ppid, 0, 0, 0),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("$262"),
+ .u.value = njs_string("$262"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("detachArrayBuffer"),
- .value = njs_native_function(njs_262_detach_array_buffer, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("detachArrayBuffer", njs_262_detach_array_buffer,
+ 2, 0),
};
static const njs_object_prop_t njs_date_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Date"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Date"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 7.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(7),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("UTC"),
- .value = njs_native_function(njs_date_utc, 7),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("UTC", njs_date_utc, 7, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("now"),
- .value = njs_native_function(njs_date_now, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("now", njs_date_now, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parse"),
- .value = njs_native_function(njs_date_parse, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parse", njs_date_parse, 1, 0),
};
static const njs_object_prop_t njs_date_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_primitive_prototype_get_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_date_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_date_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toDateString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_DATE_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toDateString", njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_DATE_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toTimeString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_TIME_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toTimeString", njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_TIME_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toLocaleString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toLocaleString", njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("toLocaleDateString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_DATE_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("toLocaleDateString",
+ njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_DATE_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("toLocaleTimeString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_TIME_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("toLocaleTimeString",
+ njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_TIME_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toUTCString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_UTC_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toUTCString",
+ njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_UTC_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toISOString"),
- .value = njs_native_function2(njs_date_prototype_to_string, 0,
- NJS_DATE_FMT_TO_ISO_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toISOString",
+ njs_date_prototype_to_string, 0,
+ NJS_DATE_FMT_TO_ISO_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toJSON"),
- .value = njs_native_function(njs_date_prototype_to_json, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toJSON", njs_date_prototype_to_json, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getTime"),
- .value = njs_native_function(njs_date_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getTime", njs_date_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getFullYear"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_YR, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getFullYear",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_YR, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCFullYear"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_YR, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCFullYear",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_YR, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getMonth"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MON, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getMonth",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MON, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCMonth"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MON, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCMonth",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MON, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getDate"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_DAY, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getDate",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_DAY, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCDate"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_DAY, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCDate",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_DAY, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getDay"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_WDAY, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getDay",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_WDAY, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCDay"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_WDAY, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCDay",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_WDAY, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getHours"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_HR, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getHours",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_HR, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCHours"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_HR, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCHours",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_HR, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getMinutes"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MIN, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getMinutes",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MIN, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCMinutes"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MIN, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCMinutes",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MIN, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getSeconds"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_SEC, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getSeconds",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_SEC, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUTCSeconds"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_SEC, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUTCSeconds",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_SEC, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getMilliseconds"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MSEC, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getMilliseconds",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MSEC, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getUTCMilliseconds"),
- .value = njs_native_function2(njs_date_prototype_get_field, 0,
- njs_date_magic(NJS_DATE_MSEC, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getUTCMilliseconds",
+ njs_date_prototype_get_field, 0,
+ njs_date_magic(NJS_DATE_MSEC, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getTimezoneOffset"),
- .value = njs_native_function(njs_date_prototype_get_timezone_offset, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getTimezoneOffset",
+ njs_date_prototype_get_timezone_offset, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setTime"),
- .value = njs_native_function(njs_date_prototype_set_time, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setTime", njs_date_prototype_set_time, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("setMilliseconds"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 1,
- njs_date_magic2(NJS_DATE_MSEC, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("setMilliseconds",
+ njs_date_prototype_set_fields, 1,
+ njs_date_magic2(NJS_DATE_MSEC, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("setUTCMilliseconds"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 1,
- njs_date_magic2(NJS_DATE_MSEC, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("setUTCMilliseconds",
+ njs_date_prototype_set_fields, 1,
+ njs_date_magic2(NJS_DATE_MSEC, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setSeconds"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 2,
- njs_date_magic2(NJS_DATE_SEC, 2, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setSeconds",
+ njs_date_prototype_set_fields, 2,
+ njs_date_magic2(NJS_DATE_SEC, 2, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCSeconds"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 2,
- njs_date_magic2(NJS_DATE_SEC, 2, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCSeconds",
+ njs_date_prototype_set_fields, 2,
+ njs_date_magic2(NJS_DATE_SEC, 2, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setMinutes"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 3,
- njs_date_magic2(NJS_DATE_MIN, 3, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setMinutes",
+ njs_date_prototype_set_fields, 3,
+ njs_date_magic2(NJS_DATE_MIN, 3, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCMinutes"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 3,
- njs_date_magic2(NJS_DATE_MIN, 3, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCMinutes",
+ njs_date_prototype_set_fields, 3,
+ njs_date_magic2(NJS_DATE_MIN, 3, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setHours"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 4,
- njs_date_magic2(NJS_DATE_HR, 4, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setHours",
+ njs_date_prototype_set_fields, 4,
+ njs_date_magic2(NJS_DATE_HR, 4, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCHours"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 4,
- njs_date_magic2(NJS_DATE_HR, 4, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCHours",
+ njs_date_prototype_set_fields, 4,
+ njs_date_magic2(NJS_DATE_HR, 4, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setDate"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 1,
- njs_date_magic2(NJS_DATE_DAY, 1, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setDate",
+ njs_date_prototype_set_fields, 1,
+ njs_date_magic2(NJS_DATE_DAY, 1, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCDate"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 1,
- njs_date_magic2(NJS_DATE_DAY, 1, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCDate",
+ njs_date_prototype_set_fields, 1,
+ njs_date_magic2(NJS_DATE_DAY, 1, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setMonth"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 2,
- njs_date_magic2(NJS_DATE_MON, 2, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setMonth",
+ njs_date_prototype_set_fields, 2,
+ njs_date_magic2(NJS_DATE_MON, 2, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCMonth"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 2,
- njs_date_magic2(NJS_DATE_MON, 2, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCMonth",
+ njs_date_prototype_set_fields, 2,
+ njs_date_magic2(NJS_DATE_MON, 2, 0)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setFullYear"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 3,
- njs_date_magic2(NJS_DATE_YR, 3, 1)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setFullYear",
+ njs_date_prototype_set_fields, 3,
+ njs_date_magic2(NJS_DATE_YR, 3, 1)),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUTCFullYear"),
- .value = njs_native_function2(njs_date_prototype_set_fields, 3,
- njs_date_magic2(NJS_DATE_YR, 3, 0)),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUTCFullYear",
+ njs_date_prototype_set_fields, 3,
+ njs_date_magic2(NJS_DATE_YR, 3, 0)),
};
static const njs_object_prop_t njs_text_encoder_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("encoding"),
- .value = njs_string("utf-8"),
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("encode"),
- .value = njs_native_function(njs_text_encoder_encode, 0),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("encodeInto"),
- .value = njs_native_function(njs_text_encoder_encode_into, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
+
+ NJS_DECLARE_PROP_VALUE("encoding", njs_string("utf-8"), 0),
+
+ NJS_DECLARE_PROP_NATIVE("encode", njs_text_encoder_encode, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("encodeInto", njs_text_encoder_encode_into, 2, 0),
};
static const njs_object_prop_t njs_text_encoder_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("TextEncoder"),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_NAME("TextEncoder"),
+
+ NJS_DECLARE_PROP_LENGTH(0),
+
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_text_decoder_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("encoding"),
- .value = njs_prop_handler(njs_text_decoder_encoding),
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("fatal"),
- .value = njs_prop_handler(njs_text_decoder_fatal),
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("ignoreBOM"),
- .value = njs_prop_handler(njs_text_decoder_ignore_bom),
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("decode"),
- .value = njs_native_function(njs_text_decoder_decode, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
+
+ NJS_DECLARE_PROP_HANDLER("encoding", njs_text_decoder_encoding, 0, 0, 0),
+
+ NJS_DECLARE_PROP_HANDLER("fatal", njs_text_decoder_fatal, 0, 0, 0),
+
+ NJS_DECLARE_PROP_HANDLER("ignoreBOM", njs_text_decoder_ignore_bom, 0, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("decode", njs_text_decoder_decode, 0, 0),
};
static const njs_object_prop_t njs_text_decoder_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("TextDecoder"),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_NAME("TextDecoder"),
+
+ NJS_DECLARE_PROP_LENGTH(0),
+
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
njs_int_t
njs_error_stack_attach(njs_vm_t *vm, njs_value_t *value)
{
- njs_int_t ret;
- njs_object_t *error;
- njs_object_prop_t *prop;
- njs_lvlhsh_query_t lhq;
+ njs_int_t ret;
+ njs_value_t stack;
- if (njs_slow_path(!njs_is_error(value))) {
+ if (njs_slow_path(!njs_is_error(value))
+ || njs_object(value)->stack_attached)
+ {
return NJS_DECLINED;
}
return NJS_OK;
}
- error = njs_object(value);
-
- lhq.replace = 0;
- lhq.pool = vm->mem_pool;
- lhq.proto = &njs_object_hash_proto;
-
- lhq.key = njs_str_value("stack");
- lhq.key_hash = NJS_STACK_HASH;
-
- prop = njs_object_prop_alloc(vm, &njs_error_stack_string,
- &njs_value_undefined, 1);
- if (njs_slow_path(prop == NULL)) {
- return NJS_ERROR;
- }
-
- prop->enumerable = 0;
-
- ret = njs_error_stack_new(vm, error, &prop->value);
- if (njs_slow_path(ret == NJS_ERROR)) {
+ ret = njs_error_stack_new(vm, njs_object(value), &stack);
+ if (njs_slow_path(ret != NJS_OK)) {
njs_internal_error(vm, "njs_error_stack_new() failed");
return NJS_ERROR;
}
- if (ret == NJS_OK) {
- lhq.value = prop;
+ njs_object(value)->stack_attached = 1;
- ret = njs_lvlhsh_insert(&error->hash, &lhq);
- if (njs_slow_path(ret == NJS_ERROR)) {
- njs_internal_error(vm, "lvlhsh insert failed");
- return NJS_ERROR;
- }
- }
-
- return NJS_OK;
+ return njs_object_prop_define(vm, value,
+ njs_value_arg(&njs_error_stack_string),
+ &stack, NJS_OBJECT_PROP_VALUE_CW,
+ NJS_STACK_HASH);
}
error->extensible = 1;
error->fast_array = 0;
error->error_data = 1;
+ error->stack_attached = 0;
error->__proto__ = &vm->prototypes[type].object;
error->slots = NULL;
static const njs_object_prop_t njs_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Error"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Error"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_eval_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("EvalError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("EvalError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_internal_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("InternalError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("InternalError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_range_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("RangeError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("RangeError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_reference_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("ReferenceError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("ReferenceError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_syntax_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("SyntaxError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("SyntaxError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_type_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("TypeError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("TypeError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_uri_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("URIError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("URIError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_aggregate_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("AggregateError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("AggregateError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_memory_error_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("MemoryError"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("MemoryError"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_memory_error_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_memory_error_prototype_create,
+ 0, 0, 0),
};
static const njs_object_prop_t njs_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Error"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("Error"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_error_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_error_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_error_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_error_prototype_to_string, 0, 0),
};
static const njs_object_prop_t njs_eval_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("EvalError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("EvalError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_internal_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("InternalError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("InternalError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_internal_error_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_internal_error_prototype_to_string,
+ 0, 0),
};
static const njs_object_prop_t njs_range_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("RangeError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("RangeError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_reference_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("ReferenceError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("ReferenceError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_syntax_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("SyntaxError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("SyntaxError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_type_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("TypeError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("TypeError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_uri_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("URIError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("URIError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
static const njs_object_prop_t njs_aggregate_error_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("AggregateError"),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("message"),
- .value = njs_string(""),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("name", njs_string("AggregateError"),
+ NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("message", njs_string(""), NJS_OBJECT_PROP_VALUE_CW),
};
function->magic8 = external->u.method.magic8;
function->ctor = external->u.method.ctor;
- njs_set_function(&prop->value, function);
+ njs_set_function(njs_prop_value(prop), function);
break;
case NJS_EXTERN_PROPERTY:
if (external->u.property.handler != NULL) {
prop->type = NJS_PROPERTY_HANDLER;
- prop->value.type = NJS_INVALID;
- prop->value.data.truth = 1;
- prop->value.data.magic16 = external->u.property.magic16;
- prop->value.data.magic32 = external->u.property.magic32;
- prop->value.data.u.prop_handler = external->u.property.handler;
+ prop->u.value.type = NJS_INVALID;
+ prop->u.value.data.truth = 1;
+ njs_prop_magic16(prop) = external->u.property.magic16;
+ njs_prop_magic32(prop) = external->u.property.magic32;
+ njs_prop_handler(prop) = external->u.property.handler;
} else {
start = (u_char *) external->u.property.value;
length = 0;
}
- ret = njs_string_new(vm, &prop->value, start, size, length);
+ ret = njs_string_new(vm, &prop->u.value, start, size, length);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
}
prop->type = NJS_PROPERTY_HANDLER;
- prop->value.type = NJS_INVALID;
- prop->value.data.truth = 1;
- prop->value.data.magic16 = next - slot;
- prop->value.data.magic32 = lhq.key_hash;
- prop->value.data.u.prop_handler = njs_external_prop_handler;
+ prop->u.value.type = NJS_INVALID;
+ prop->u.value.data.truth = 1;
+ njs_prop_magic16(prop) = next - slot;
+ njs_prop_magic32(prop) = lhq.key_hash;
+ njs_prop_handler(prop) = njs_external_prop_handler;
next->writable = external->u.object.writable;
next->configurable = external->u.object.configurable;
return NJS_ERROR;
}
- slots = njs_object(value)->slots + self->value.data.magic16;
+ slots = njs_object(value)->slots + njs_prop_magic16(self);
ov->object.shared_hash = slots->external_shared_hash;
ov->object.slots = slots;
lhq.value = prop;
njs_string_get(&self->name, &lhq.key);
- lhq.key_hash = self->value.data.magic32;
+ lhq.key_hash = njs_prop_magic32(self);
lhq.replace = 1;
lhq.pool = vm->mem_pool;
lhq.proto = &njs_object_hash_proto;
njs_function_t *
njs_function_value_copy(njs_vm_t *vm, njs_value_t *value)
{
- njs_function_t *function, *copy;
- njs_object_type_t type;
+ njs_function_t *function, *copy;
function = njs_function(value);
return NULL;
}
- type = njs_function_object_type(vm, function);
-
- if (copy->ctor) {
- copy->object.shared_hash = vm->shared->function_instance_hash;
-
- } else if (type == NJS_OBJ_TYPE_ASYNC_FUNCTION) {
- copy->object.shared_hash = vm->shared->async_function_instance_hash;
-
- } else {
- copy->object.shared_hash = vm->shared->arrow_instance_hash;
- }
-
value->data.u.function = copy;
return copy;
symbol = 0;
- if (njs_is_symbol(&prop->value)) {
+ if (njs_is_symbol(njs_prop_value(prop))) {
symbol = 2;
- prop->value = *njs_symbol_description(&prop->value);
+ njs_value_assign(njs_prop_value(prop),
+ njs_symbol_description(njs_prop_value(prop)));
}
if (prefix != NULL || symbol != 0) {
- if (njs_is_defined(&prop->value)) {
- value = prop->value;
+ if (njs_is_defined(njs_prop_value(prop))) {
+ njs_value_assign(&value, njs_prop_value(prop));
(void) njs_string_prop(&string, &value);
len = (prefix != NULL) ? njs_strlen(prefix) + 1: 0;
- p = njs_string_alloc(vm, &prop->value, string.size + len + symbol,
+ p = njs_string_alloc(vm, njs_prop_value(prop),
+ string.size + len + symbol,
string.length + len + symbol);
if (njs_slow_path(p == NULL)) {
return NJS_ERROR;
}
} else {
- njs_value_assign(&prop->value, &njs_string_empty);
+ njs_value_assign(njs_prop_value(prop), &njs_string_empty);
}
}
copy->object.__proto__ = &vm->prototypes[type].object;
copy->object.shared = 0;
+ if (copy->ctor) {
+ copy->object.shared_hash = vm->shared->function_instance_hash;
+
+ } else if (type == NJS_OBJ_TYPE_ASYNC_FUNCTION) {
+ copy->object.shared_hash = vm->shared->async_function_instance_hash;
+
+ } else {
+ copy->object.shared_hash = vm->shared->arrow_instance_hash;
+ }
+
if (n == 0) {
return copy;
}
njs_int_t
njs_function_arguments_object_init(njs_vm_t *vm, njs_native_frame_t *frame)
{
- njs_int_t ret;
- njs_uint_t nargs, n;
- njs_value_t value;
- njs_object_t *arguments;
- njs_object_prop_t *prop;
- njs_lvlhsh_query_t lhq;
+ njs_int_t ret;
+ njs_uint_t n;
+ njs_value_t value, length;
+ njs_object_t *arguments;
- static const njs_value_t njs_string_length = njs_string("length");
+ static const njs_value_t string_length = njs_string("length");
arguments = njs_object_alloc(vm);
if (njs_slow_path(arguments == NULL)) {
arguments->shared_hash = vm->shared->arguments_object_instance_hash;
- nargs = frame->nargs;
-
- njs_set_number(&value, nargs);
-
- prop = njs_object_prop_alloc(vm, &njs_string_length, &value, 1);
- if (njs_slow_path(prop == NULL)) {
- return NJS_ERROR;
- }
+ njs_set_object(&value, arguments);
+ njs_set_number(&length, frame->nargs);
- prop->enumerable = 0;
-
- lhq.value = prop;
- lhq.key_hash = NJS_LENGTH_HASH;
- njs_string_get(&prop->name, &lhq.key);
-
- lhq.replace = 0;
- lhq.pool = vm->mem_pool;
- lhq.proto = &njs_object_hash_proto;
-
- ret = njs_lvlhsh_insert(&arguments->hash, &lhq);
+ ret = njs_object_prop_define(vm, &value, njs_value_arg(&string_length),
+ &length, NJS_OBJECT_PROP_VALUE_CW,
+ NJS_LENGTH_HASH);
if (njs_slow_path(ret != NJS_OK)) {
- njs_internal_error(vm, "lvlhsh insert failed");
return NJS_ERROR;
}
- for (n = 0; n < nargs; n++) {
- njs_uint32_to_string(&value, n);
-
- prop = njs_object_prop_alloc(vm, &value, &frame->arguments[n], 1);
- if (njs_slow_path(prop == NULL)) {
- return NJS_ERROR;
- }
-
- lhq.value = prop;
- njs_string_get(&prop->name, &lhq.key);
- lhq.key_hash = njs_djb_hash(lhq.key.start, lhq.key.length);
-
- ret = njs_lvlhsh_insert(&arguments->hash, &lhq);
+ for (n = 0; n < frame->nargs; n++) {
+ ret = njs_value_create_data_prop_i64(vm, &value, n,
+ &frame->arguments[n], 0);
if (njs_slow_path(ret != NJS_OK)) {
- njs_internal_error(vm, "lvlhsh insert failed");
return NJS_ERROR;
}
}
const njs_object_prop_t njs_arguments_object_instance_properties[] =
{
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_string("callee"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_function_prototype_thrower, 0),
- .setter = njs_native_function(njs_function_prototype_thrower, 0),
+ .u.accessor = njs_accessor(njs_function_prototype_thrower, 0,
+ njs_function_prototype_thrower, 0),
.writable = NJS_ATTRIBUTE_UNSET,
},
};
ret = njs_lvlhsh_insert(hash, &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- return &prop->value;
+ return njs_prop_value(prop);
}
njs_internal_error(vm, "lvlhsh insert failed");
static const njs_object_prop_t njs_function_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Function"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Function"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_function_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string(""),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME(""),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("call"),
- .value = njs_native_function(njs_function_prototype_call, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("call", njs_function_prototype_call, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("apply"),
- .value = njs_native_function(njs_function_prototype_apply, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("apply", njs_function_prototype_apply, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("bind"),
- .value = njs_native_function(njs_function_prototype_bind, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("bind", njs_function_prototype_bind, 1, 0),
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_string("caller"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_function_prototype_thrower, 0),
- .setter = njs_native_function(njs_function_prototype_thrower, 0),
+ .u.accessor = njs_accessor(njs_function_prototype_thrower, 0,
+ njs_function_prototype_thrower, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
},
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_string("arguments"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_function_prototype_thrower, 0),
- .setter = njs_native_function(njs_function_prototype_thrower, 0),
+ .u.accessor = njs_accessor(njs_function_prototype_thrower, 0,
+ njs_function_prototype_thrower, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
},
const njs_object_prop_t njs_function_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_function_instance_length),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_function_instance_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("name"),
- .value = njs_prop_handler(njs_function_instance_name),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("name", njs_function_instance_name, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_function_prototype_create),
- .writable = 1
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_function_prototype_create, 0, 0,
+ NJS_OBJECT_PROP_VALUE_W),
};
const njs_object_prop_t njs_arrow_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_function_instance_length),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_function_instance_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("name"),
- .value = njs_prop_handler(njs_function_instance_name),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("name", njs_function_instance_name, 0, 0,
+ NJS_OBJECT_PROP_VALUE_C),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_ITERATOR),
- .value = njs_native_function(njs_iterator_prototype_get_this, 0),
+ .u.value = njs_native_function(njs_iterator_prototype_get_this, 0),
.configurable = 1,
.writable = 1,
},
return NJS_ERROR;
}
- ret = njs_array_iterator_next(vm, this, &prop_value->value);
+ ret = njs_array_iterator_next(vm, this, njs_prop_value(prop_value));
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
if (njs_slow_path(ret == NJS_DECLINED)) {
- njs_set_undefined(&prop_value->value);
- njs_set_boolean(&prop_done->value, 1);
+ njs_set_undefined(njs_prop_value(prop_value));
+ njs_set_boolean(njs_prop_value(prop_done), 1);
return NJS_OK;
}
- njs_set_boolean(&prop_done->value, 0);
+ njs_set_boolean(njs_prop_value(prop_done), 0);
return NJS_OK;
}
static const njs_object_prop_t njs_array_iterator_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("next"),
- .value = njs_native_function2(njs_array_iterator_prototype_next, 0,
- NJS_DATA_TAG_ARRAY_ITERATOR),
- .configurable = 1,
- .writable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("next", njs_array_iterator_prototype_next, 0,
+ NJS_DATA_TAG_ARRAY_ITERATOR),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("Array Iterator"),
+ .u.value = njs_string("Array Iterator"),
.configurable = 1,
},
};
{
njs_function_t *parse;
- parse = njs_function(&njs_json_object_properties[1].value);
+ parse = njs_function(&njs_json_object_properties[1].u.value);
return njs_vm_call(vm, parse, args, nargs);
}
{
njs_function_t *stringify;
- stringify = njs_function(&njs_json_object_properties[2].value);
+ stringify = njs_function(&njs_json_object_properties[2].u.value);
return njs_vm_call(vm, stringify, args, nargs);
}
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("JSON"),
+ .u.value = njs_string("JSON"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parse"),
- .value = njs_native_function(njs_json_parse, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parse", njs_json_parse, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("stringify"),
- .value = njs_native_function(njs_json_stringify, 3),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("stringify", njs_json_stringify, 3, 0),
};
continue;
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 0);
key = &state->keys->start[state->index++];
}
}
- val = &prop->value;
+ val = njs_prop_value(prop);
if (!state->fast_array) {
if (prop->type == NJS_PROPERTY_HANDLER) {
pq.scratch = *prop;
prop = &pq.scratch;
- ret = prop->value.data.u.prop_handler(vm, prop, &state->value,
- NULL, &prop->value);
+ ret = njs_prop_handler(prop)(vm, prop, &state->value, NULL,
+ njs_prop_value(prop));
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
- val = &prop->value;
+ val = njs_prop_value(prop);
}
if (njs_is_accessor_descriptor(prop)) {
- if (njs_is_defined(&prop->getter)) {
- if (njs_is_defined(&prop->setter)) {
+ if (njs_prop_getter(prop) != NULL) {
+ if (njs_prop_setter(prop) != NULL) {
val = njs_value_arg(&string_get_set);
} else {
#include <njs_value.h>
#include <njs_vm.h>
+#include <njs_object_prop_declare.h>
#include <njs_error.h>
#include <njs_number.h>
#include <njs_value_conversion.h>
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("Math"),
+ .u.value = njs_string("Math"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("E"),
- .value = njs_value(NJS_NUMBER, 1, M_E),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("LN10"),
- .value = njs_value(NJS_NUMBER, 1, M_LN10),
- },
+ NJS_DECLARE_PROP_VALUE("E", njs_value(NJS_NUMBER, 1, M_E), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("LN2"),
- .value = njs_value(NJS_NUMBER, 1, M_LN2),
- },
+ NJS_DECLARE_PROP_VALUE("LN10", njs_value(NJS_NUMBER, 1, M_LN10), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("LOG10E"),
- .value = njs_value(NJS_NUMBER, 1, M_LOG10E),
- },
+ NJS_DECLARE_PROP_VALUE("LN2", njs_value(NJS_NUMBER, 1, M_LN2), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("LOG2E"),
- .value = njs_value(NJS_NUMBER, 1, M_LOG2E),
- },
+ NJS_DECLARE_PROP_VALUE("LOG10E", njs_value(NJS_NUMBER, 1, M_LOG10E), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("PI"),
- .value = njs_value(NJS_NUMBER, 1, M_PI),
- },
+ NJS_DECLARE_PROP_VALUE("LOG2E", njs_value(NJS_NUMBER, 1, M_LOG2E), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("SQRT1_2"),
- .value = njs_value(NJS_NUMBER, 1, M_SQRT1_2),
- },
+ NJS_DECLARE_PROP_VALUE("PI", njs_value(NJS_NUMBER, 1, M_PI), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("SQRT2"),
- .value = njs_value(NJS_NUMBER, 1, M_SQRT2),
- },
+ NJS_DECLARE_PROP_VALUE("SQRT1_2", njs_value(NJS_NUMBER, 1, M_SQRT1_2), 0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_object_prototype_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_VALUE("SQRT2", njs_value(NJS_NUMBER, 1, M_SQRT2), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("abs"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ABS),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("abs", njs_object_math_func, 1, NJS_MATH_ABS),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("acos"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ACOS),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("acos", njs_object_math_func, 1, NJS_MATH_ACOS),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("acosh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ACOSH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("acosh", njs_object_math_func, 1, NJS_MATH_ACOSH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("asin"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ASIN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("asin", njs_object_math_func, 1, NJS_MATH_ASIN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("asinh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ASINH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("asinh", njs_object_math_func, 1, NJS_MATH_ASINH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("atan"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ATAN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("atan", njs_object_math_func, 1, NJS_MATH_ATAN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("atan2"),
- .value = njs_native_function2(njs_object_math_func, 2, NJS_MATH_ATAN2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("atan2", njs_object_math_func, 2, NJS_MATH_ATAN2),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("atanh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ATANH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("atanh", njs_object_math_func, 1, NJS_MATH_ATANH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("cbrt"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_CBRT),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("cbrt", njs_object_math_func, 1, NJS_MATH_CBRT),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("ceil"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_CEIL),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("ceil", njs_object_math_func, 1, NJS_MATH_CEIL),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("clz32"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_CLZ32),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("clz32", njs_object_math_func, 1, NJS_MATH_CLZ32),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("cos"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_COS),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("cos", njs_object_math_func, 1, NJS_MATH_COS),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("cosh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_COSH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("cosh", njs_object_math_func, 1, NJS_MATH_COSH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("exp"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_EXP),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("exp", njs_object_math_func, 1, NJS_MATH_EXP),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("expm1"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_EXPM1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("expm1", njs_object_math_func, 1, NJS_MATH_EXPM1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("floor"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_FLOOR),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("floor", njs_object_math_func, 1, NJS_MATH_FLOOR),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fround"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_FROUND),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fround", njs_object_math_func, 1,
+ NJS_MATH_FROUND),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("hypot"),
- .value = njs_native_function(njs_object_math_hypot, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("hypot", njs_object_math_hypot, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("imul"),
- .value = njs_native_function2(njs_object_math_func, 2, NJS_MATH_IMUL),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("imul", njs_object_math_func, 2, NJS_MATH_IMUL),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("log"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_LOG),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("log", njs_object_math_func, 1, NJS_MATH_LOG),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("log10"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_LOG10),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("log10", njs_object_math_func, 1, NJS_MATH_LOG10),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("log1p"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_LOG1P),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("log1p", njs_object_math_func, 1, NJS_MATH_LOG1P),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("log2"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_LOG2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("log2", njs_object_math_func, 1, NJS_MATH_LOG2),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("max"),
- .value = njs_native_function2(njs_object_math_min_max, 2, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("max", njs_object_math_min_max, 2, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("min"),
- .value = njs_native_function2(njs_object_math_min_max, 2, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("min", njs_object_math_min_max, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("pow"),
- .value = njs_native_function2(njs_object_math_func, 2, NJS_MATH_POW),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("pow", njs_object_math_func, 2, NJS_MATH_POW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("random"),
- .value = njs_native_function(njs_object_math_random, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("random", njs_object_math_random, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("round"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_ROUND),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("round", njs_object_math_func, 1, NJS_MATH_ROUND),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sign"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_SIGN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sign", njs_object_math_func, 1, NJS_MATH_SIGN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sin"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_SIN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sin", njs_object_math_func, 1, NJS_MATH_SIN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sinh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_SINH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sinh", njs_object_math_func, 1, NJS_MATH_SINH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sqrt"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_SQRT),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sqrt", njs_object_math_func, 1, NJS_MATH_SQRT),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("tan"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_TAN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("tan", njs_object_math_func, 1, NJS_MATH_TAN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("tanh"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_TANH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("tanh", njs_object_math_func, 1, NJS_MATH_TANH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("trunc"),
- .value = njs_native_function2(njs_object_math_func, 1, NJS_MATH_TRUNC),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("trunc", njs_object_math_func, 1, NJS_MATH_TRUNC),
};
static const njs_object_prop_t njs_number_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Number"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Number"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("EPSILON"),
- .value = njs_value(NJS_NUMBER, 1, DBL_EPSILON),
- },
+ NJS_DECLARE_PROP_VALUE("EPSILON", njs_value(NJS_NUMBER, 1, DBL_EPSILON), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("MAX_SAFE_INTEGER"),
- .value = njs_value(NJS_NUMBER, 1, NJS_MAX_SAFE_INTEGER),
- },
+ NJS_DECLARE_PROP_LVALUE("MAX_SAFE_INTEGER",
+ njs_value(NJS_NUMBER, 1, NJS_MAX_SAFE_INTEGER), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("MIN_SAFE_INTEGER"),
- .value = njs_value(NJS_NUMBER, 1, -NJS_MAX_SAFE_INTEGER),
- },
+ NJS_DECLARE_PROP_LVALUE("MIN_SAFE_INTEGER",
+ njs_value(NJS_NUMBER, 1, -NJS_MAX_SAFE_INTEGER), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("MAX_VALUE"),
- .value = njs_value(NJS_NUMBER, 1, DBL_MAX),
- },
+ NJS_DECLARE_PROP_VALUE("MAX_VALUE", njs_value(NJS_NUMBER, 1, DBL_MAX), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("MIN_VALUE"),
- .value = njs_value(NJS_NUMBER, 1, DBL_MIN),
- },
+ NJS_DECLARE_PROP_VALUE("MIN_VALUE", njs_value(NJS_NUMBER, 1, DBL_MIN), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("NaN"),
- .value = njs_value(NJS_NUMBER, 0, NAN),
- },
+ NJS_DECLARE_PROP_VALUE("NaN", njs_value(NJS_NUMBER, 0, NAN), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("POSITIVE_INFINITY"),
- .value = njs_value(NJS_NUMBER, 1, INFINITY),
- },
+ NJS_DECLARE_PROP_LVALUE("POSITIVE_INFINITY",
+ njs_value(NJS_NUMBER, 1, INFINITY), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("NEGATIVE_INFINITY"),
- .value = njs_value(NJS_NUMBER, 1, -INFINITY),
- },
+ NJS_DECLARE_PROP_LVALUE("NEGATIVE_INFINITY",
+ njs_value(NJS_NUMBER, 1, -INFINITY), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isFinite"),
- .value = njs_native_function(njs_number_is_finite, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isFinite", njs_number_is_finite, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isInteger"),
- .value = njs_native_function(njs_number_is_integer, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isInteger", njs_number_is_integer, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isSafeInteger"),
- .value = njs_native_function(njs_number_is_safe_integer, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isSafeInteger", njs_number_is_safe_integer, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isNaN"),
- .value = njs_native_function(njs_number_is_nan, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isNaN", njs_number_is_nan, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parseFloat"),
- .value = njs_native_function(njs_number_parse_float, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parseFloat", njs_number_parse_float, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("parseInt"),
- .value = njs_native_function(njs_number_parse_int, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("parseInt", njs_number_parse_int, 2, 0),
};
static const njs_object_prop_t njs_number_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_primitive_prototype_get_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_number_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_number_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_number_prototype_to_string, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_number_prototype_to_string, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toFixed"),
- .value = njs_native_function(njs_number_prototype_to_fixed, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toFixed", njs_number_prototype_to_fixed, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toPrecision"),
- .value = njs_native_function(njs_number_prototype_to_precision, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toPrecision", njs_number_prototype_to_precision,
+ 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toExponential"),
- .value = njs_native_function(njs_number_prototype_to_exponential, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toExponential",
+ njs_number_prototype_to_exponential, 1, 0),
};
njs_object_enum_type_t type, njs_bool_t all)
{
njs_int_t ret;
- njs_value_t value;
+ njs_value_t value, *v;
njs_array_t *entry;
njs_lvlhsh_each_t lhe;
njs_object_prop_t *prop, *ext_prop;
if (ext_prop == NULL && prop->type != NJS_WHITEOUT
&& (prop->enumerable || all))
{
- ret = njs_array_add(vm, items, &prop->value);
+ v = (prop->type != NJS_ACCESSOR)
+ ? njs_prop_value(prop)
+ : njs_value_arg(&njs_value_undefined);
+ ret = njs_array_add(vm, items, v);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
ext_prop = njs_object_exist_in_proto(parent, object, &lhq);
if (ext_prop == NULL && (prop->enumerable || all)) {
- ret = njs_array_add(vm, items, &prop->value);
+ v = (prop->type != NJS_ACCESSOR)
+ ? njs_prop_value(prop)
+ : njs_value_arg(&njs_value_undefined);
+ ret = njs_array_add(vm, items, v);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
}
njs_string_copy(&entry->start[0], &prop->name);
- entry->start[1] = prop->value;
+
+ v = (prop->type != NJS_ACCESSOR)
+ ? njs_prop_value(prop)
+ : njs_value_arg(&njs_value_undefined);
+
+ njs_value_assign(&entry->start[1], v);
njs_set_array(&value, entry);
}
njs_string_copy(&entry->start[0], &prop->name);
- entry->start[1] = prop->value;
+ njs_value_assign(&entry->start[1], njs_prop_value(prop));
njs_set_array(&value, entry);
continue;
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 0);
key = &s->keys->start[s->index++];
ret = njs_property_query(vm, &pq, &s->value, key);
return ret;
}
- njs_value_assign(&value, &prop->value);
+ if (njs_is_accessor_descriptor(prop)) {
+ continue;
+ }
+
+ njs_value_assign(&value, njs_prop_value(prop));
if (prop->type == NJS_PROPERTY_HANDLER) {
- ret = prop->value.data.u.prop_handler(vm, prop, &s->value, NULL,
- &value);
+ ret = njs_prop_handler(prop)(vm, prop, &s->value, NULL, &value);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
name = njs_lvalue_arg(&lvalue, args, nargs, 2);
ret = njs_object_prop_define(vm, value, name, desc,
- NJS_OBJECT_PROP_DESCRIPTOR);
+ NJS_OBJECT_PROP_DESCRIPTOR, 0);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
length = keys->length;
value = njs_argument(args, 1);
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 0);
for (i = 0; i < length; i++) {
+ pq.lhq.key_hash = 0;
+
ret = njs_property_query(vm, &pq, descs, &keys->start[i]);
if (njs_slow_path(ret == NJS_ERROR)) {
goto done;
}
ret = njs_object_prop_define(vm, value, &keys->start[i], &desc,
- NJS_OBJECT_PROP_DESCRIPTOR);
+ NJS_OBJECT_PROP_DESCRIPTOR, 0);
if (njs_slow_path(ret != NJS_OK)) {
goto done;
}
for (j = 0; j < length; j++) {
key = &names->start[j];
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 1);
ret = njs_property_query(vm, &pq, source, key);
if (njs_slow_path(ret != NJS_OK)) {
/* GC */
- njs_set_type_object(&prop->value, prototype, prototype->type);
+ njs_set_type_object(njs_prop_value(prop), prototype, prototype->type);
lhq.value = prop;
lhq.key_hash = NJS_PROTOTYPE_HASH;
ret = njs_lvlhsh_insert(hash, &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- return &prop->value;
+ return njs_prop_value(prop);
}
njs_internal_error(vm, "lvlhsh insert failed");
static const njs_object_prop_t njs_object_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Object"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Object"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("create"),
- .value = njs_native_function(njs_object_create, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("create", njs_object_create, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("keys"),
- .value = njs_native_function(njs_object_keys, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("keys", njs_object_keys, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("values"),
- .value = njs_native_function(njs_object_values, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("values", njs_object_values, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("entries"),
- .value = njs_native_function(njs_object_entries, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("entries", njs_object_entries, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("defineProperty"),
- .value = njs_native_function(njs_object_define_property, 3),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("defineProperty", njs_object_define_property, 3, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("defineProperties"),
- .value = njs_native_function(njs_object_define_properties, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("defineProperties",
+ njs_object_define_properties, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getOwnPropertyDescriptor"),
- .value = njs_native_function(njs_object_get_own_property_descriptor, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getOwnPropertyDescriptor",
+ njs_object_get_own_property_descriptor, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getOwnPropertyDescriptors"),
- .value = njs_native_function(njs_object_get_own_property_descriptors,
- 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getOwnPropertyDescriptors",
+ njs_object_get_own_property_descriptors, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getOwnPropertyNames"),
- .value = njs_native_function2(njs_object_get_own_property, 1,
- NJS_ENUM_STRING),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getOwnPropertyNames",
+ njs_object_get_own_property, 1, NJS_ENUM_STRING),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("getOwnPropertySymbols"),
- .value = njs_native_function2(njs_object_get_own_property, 1,
- NJS_ENUM_SYMBOL),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("getOwnPropertySymbols",
+ njs_object_get_own_property, 1, NJS_ENUM_SYMBOL),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getPrototypeOf"),
- .value = njs_native_function(njs_object_get_prototype_of, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getPrototypeOf", njs_object_get_prototype_of, 1,
+ 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setPrototypeOf"),
- .value = njs_native_function(njs_object_set_prototype_of, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setPrototypeOf", njs_object_set_prototype_of, 2,
+ 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("freeze"),
- .value = njs_native_function2(njs_object_set_integrity_level,
- 1, NJS_OBJECT_INTEGRITY_FROZEN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("freeze", njs_object_set_integrity_level, 1,
+ NJS_OBJECT_INTEGRITY_FROZEN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isFrozen"),
- .value = njs_native_function2(njs_object_test_integrity_level,
- 1, NJS_OBJECT_INTEGRITY_FROZEN),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isFrozen", njs_object_test_integrity_level, 1,
+ NJS_OBJECT_INTEGRITY_FROZEN),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("seal"),
- .value = njs_native_function2(njs_object_set_integrity_level,
- 1, NJS_OBJECT_INTEGRITY_SEALED),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("seal", njs_object_set_integrity_level, 1,
+ NJS_OBJECT_INTEGRITY_SEALED),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isSealed"),
- .value = njs_native_function2(njs_object_test_integrity_level,
- 1, NJS_OBJECT_INTEGRITY_SEALED),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isSealed", njs_object_test_integrity_level, 1,
+ NJS_OBJECT_INTEGRITY_SEALED),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("preventExtensions"),
- .value = njs_native_function(njs_object_prevent_extensions, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("preventExtensions", njs_object_prevent_extensions,
+ 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isExtensible"),
- .value = njs_native_function(njs_object_is_extensible, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isExtensible", njs_object_is_extensible, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("assign"),
- .value = njs_native_function(njs_object_assign, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("assign", njs_object_assign, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("is"),
- .value = njs_native_function(njs_object_is, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("is", njs_object_is, 2, 0),
};
/* GC */
- prop->value = *constructor;
+ njs_value_assign(njs_prop_value(prop), constructor);
prop->enumerable = 0;
lhq.value = prop;
ret = njs_lvlhsh_insert(hash, &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- return &prop->value;
+ return njs_prop_value(prop);
}
njs_internal_error(vm, "lvlhsh insert/replace failed");
}
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 1);
ret = njs_property_query(vm, &pq, value, property);
}
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 1);
ret = njs_property_query(vm, &pq, value, property);
static const njs_object_prop_t njs_object_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_object_prototype_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_object_prototype_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_object_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_object_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_object_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_object_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("hasOwnProperty"),
- .value = njs_native_function(njs_object_prototype_has_own_property, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("hasOwnProperty",
+ njs_object_prototype_has_own_property, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("propertyIsEnumerable"),
- .value = njs_native_function(njs_object_prototype_prop_is_enumerable,
- 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LNATIVE("propertyIsEnumerable",
+ njs_object_prototype_prop_is_enumerable, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isPrototypeOf"),
- .value = njs_native_function(njs_object_prototype_is_prototype_of, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("isPrototypeOf",
+ njs_object_prototype_is_prototype_of, 1, 0),
};
typedef enum {
- NJS_OBJECT_PROP_DESCRIPTOR,
- NJS_OBJECT_PROP_GETTER,
- NJS_OBJECT_PROP_SETTER,
-} njs_object_prop_define_t;
+ NJS_OBJECT_PROP_DESCRIPTOR = 0,
+ NJS_OBJECT_PROP_VALUE = 1,
+ NJS_OBJECT_PROP_GETTER = 2,
+ NJS_OBJECT_PROP_SETTER = 3,
+#define njs_prop_type(flags) (flags & 3)
+ NJS_OBJECT_PROP_CREATE = 4,
+ NJS_OBJECT_PROP_ENUMERABLE = 8,
+ NJS_OBJECT_PROP_CONFIGURABLE = 16,
+ NJS_OBJECT_PROP_WRITABLE = 32,
+#define NJS_OBJECT_PROP_VALUE_ECW (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_ENUMERABLE \
+ | NJS_OBJECT_PROP_CONFIGURABLE \
+ | NJS_OBJECT_PROP_WRITABLE)
+#define NJS_OBJECT_PROP_VALUE_EC (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_ENUMERABLE \
+ | NJS_OBJECT_PROP_CONFIGURABLE)
+#define NJS_OBJECT_PROP_VALUE_CW (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_CONFIGURABLE \
+ | NJS_OBJECT_PROP_WRITABLE)
+#define NJS_OBJECT_PROP_VALUE_E (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_ENUMERABLE)
+#define NJS_OBJECT_PROP_VALUE_C (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_CONFIGURABLE)
+#define NJS_OBJECT_PROP_VALUE_W (NJS_OBJECT_PROP_VALUE \
+ | NJS_OBJECT_PROP_WRITABLE)
+} njs_object_prop_flags_t;
struct njs_object_init_s {
njs_uint_t nargs, njs_index_t unused);
njs_int_t njs_object_length(njs_vm_t *vm, njs_value_t *value, int64_t *dst);
-njs_int_t njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq);
+njs_int_t njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq,
+ njs_object_t *proto);
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_object_prop_t *njs_object_property_add(njs_vm_t *vm, njs_value_t *object,
njs_value_t *key, njs_bool_t replace);
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_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);
const char *njs_prop_type_string(njs_object_prop_type_t type);
njs_is_data_descriptor(njs_object_prop_t *prop)
{
return prop->writable != NJS_ATTRIBUTE_UNSET
- || njs_is_valid(&prop->value)
+ || (prop->type != NJS_ACCESSOR && njs_is_valid(njs_prop_value(prop)))
|| prop->type == NJS_PROPERTY_HANDLER;
}
njs_inline njs_bool_t
njs_is_accessor_descriptor(njs_object_prop_t *prop)
{
- return njs_is_function_or_undefined(&prop->getter)
- || njs_is_function_or_undefined(&prop->setter);
+ return prop->type == NJS_ACCESSOR;
}
}
+njs_inline njs_int_t
+njs_value_create_data_prop(njs_vm_t *vm, njs_value_t *value,
+ njs_value_t *name, njs_value_t *setval, uint32_t hash)
+{
+ return njs_object_prop_define(vm, value, name, setval,
+ NJS_OBJECT_PROP_CREATE
+ | NJS_OBJECT_PROP_VALUE_ECW, hash);
+}
+
+
+njs_inline njs_int_t
+njs_value_create_data_prop_i64(njs_vm_t *vm, njs_value_t *value, int64_t index,
+ njs_value_t *setval, uint32_t hash)
+{
+ njs_int_t ret;
+ njs_value_t key;
+
+ ret = njs_int64_to_string(vm, &key, index);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return ret;
+ }
+
+ return njs_value_create_data_prop(vm, value, &key, setval, hash);
+}
+
+
njs_inline njs_int_t
njs_object_length_set(njs_vm_t *vm, njs_value_t *value, int64_t length)
{
sizeof(njs_object_prop_t));
if (njs_fast_path(prop != NULL)) {
- /* GC: retain. */
- prop->value = *value;
-
- /* GC: retain. */
- prop->name = *name;
+ njs_value_assign(&prop->name, name);
+ njs_value_assign(njs_prop_value(prop), value);
prop->type = NJS_PROPERTY;
prop->writable = attributes;
prop->enumerable = attributes;
prop->configurable = attributes;
- njs_set_invalid(&prop->getter);
- njs_set_invalid(&prop->setter);
-
return prop;
}
prop = lhq->value;
if (njs_is_data_descriptor(prop)) {
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
return NJS_OK;
}
- if (njs_is_undefined(&prop->getter)) {
+ if (njs_prop_getter(prop) == NULL) {
njs_set_undefined(retval);
return NJS_OK;
}
- return njs_function_apply(vm, njs_function(&prop->getter), value,
- 1, retval);
+ return njs_function_apply(vm, njs_prop_getter(prop), value, 1, 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_value_t *name, njs_value_t *value, unsigned flags, uint32_t hash)
{
uint32_t length;
njs_int_t ret;
again:
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, hash, 1);
+
+ ret = (flags & NJS_OBJECT_PROP_CREATE)
+ ? NJS_DECLINED
+ : njs_property_query(vm, &pq, object, name);
- ret = njs_property_query(vm, &pq, object, name);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
return NJS_ERROR;
}
- switch (type) {
-
+ switch (njs_prop_type(flags)) {
case NJS_OBJECT_PROP_DESCRIPTOR:
if (njs_descriptor_prop(vm, prop, value) != NJS_OK) {
return NJS_ERROR;
break;
+ case NJS_OBJECT_PROP_VALUE:
+ njs_value_assign(njs_prop_value(prop), value);
+ prop->enumerable = !!(flags & NJS_OBJECT_PROP_ENUMERABLE);
+ prop->configurable = !!(flags & NJS_OBJECT_PROP_CONFIGURABLE);
+ prop->writable = !!(flags & NJS_OBJECT_PROP_WRITABLE);
+
+ break;
+
case NJS_OBJECT_PROP_GETTER:
- prop->getter = *value;
- njs_set_invalid(&prop->setter);
+ if (!njs_is_function(value)) {
+ njs_type_error(vm, "Getter must be a function");
+ return NJS_ERROR;
+ }
+
+ prop->type = NJS_ACCESSOR;
+ njs_prop_getter(prop) = njs_function(value);
+ njs_prop_setter(prop) = NJS_PROP_PTR_UNSET;
prop->enumerable = NJS_ATTRIBUTE_TRUE;
prop->configurable = NJS_ATTRIBUTE_TRUE;
break;
case NJS_OBJECT_PROP_SETTER:
- prop->setter = *value;
- njs_set_invalid(&prop->getter);
+ if (!njs_is_function(value)) {
+ njs_type_error(vm, "Setter must be a function");
+ return NJS_ERROR;
+ }
+
+ prop->type = NJS_ACCESSOR;
+ njs_prop_getter(prop) = NJS_PROP_PTR_UNSET;
+ njs_prop_setter(prop) = njs_function(value);
prop->enumerable = NJS_ATTRIBUTE_TRUE;
prop->configurable = NJS_ATTRIBUTE_TRUE;
set_prop:
if (!njs_object(object)->extensible) {
- njs_key_string_get(vm, &pq.key, &pq.lhq.key);
+ njs_key_string_get(vm, name, &pq.lhq.key);
njs_type_error(vm, "Cannot add property \"%V\", "
"object is not extensible", &pq.lhq.key);
return NJS_ERROR;
/* 6.2.5.6 CompletePropertyDescriptor */
if (njs_is_accessor_descriptor(prop)) {
- if (!njs_is_valid(&prop->getter)) {
- njs_set_undefined(&prop->getter);
+ if (njs_prop_getter(prop) == NJS_PROP_PTR_UNSET) {
+ njs_prop_getter(prop) = NULL;
}
- if (!njs_is_valid(&prop->setter)) {
- njs_set_undefined(&prop->setter);
+ if (njs_prop_setter(prop) == NJS_PROP_PTR_UNSET) {
+ njs_prop_setter(prop) = NULL;
}
} else {
prop->writable = 0;
}
- if (!njs_is_valid(&prop->value)) {
- njs_set_undefined(&prop->value);
+ if (!njs_is_valid(njs_prop_value(prop))) {
+ njs_set_undefined(njs_prop_value(prop));
}
}
}
} else {
+
+ if ((flags & NJS_OBJECT_PROP_CREATE)) {
+ ret = njs_primitive_value_to_key(vm, &pq.key, name);
+ if (njs_slow_path(ret != NJS_OK)) {
+ return NJS_ERROR;
+ }
+
+ if (njs_is_symbol(name)) {
+ pq.lhq.key_hash = njs_symbol_key(name);
+ pq.lhq.key.start = NULL;
+
+ } else {
+ njs_string_get(&pq.key, &pq.lhq.key);
+ pq.lhq.key_hash = (hash == 0)
+ ? njs_djb_hash(pq.lhq.key.start,
+ pq.lhq.key.length)
+ : hash;
+ }
+
+ pq.lhq.proto = &njs_object_hash_proto;
+ }
+
pq.lhq.value = prop;
pq.lhq.replace = 0;
pq.lhq.pool = vm->mem_pool;
switch (prev->type) {
case NJS_PROPERTY:
+ case NJS_ACCESSOR:
case NJS_PROPERTY_HANDLER:
break;
goto again;
}
- if (njs_is_valid(&prop->value)) {
- *prev->value.data.u.value = prop->value;
+ if (njs_is_valid(njs_prop_value(prop))) {
+ njs_value_assign(njs_prop_ref(prop), njs_prop_value(prop));
+
} else {
- njs_set_undefined(prev->value.data.u.value);
+ njs_set_undefined(njs_prop_ref(prop));
}
return NJS_OK;
goto exception;
}
- if (njs_is_valid(&prop->value)) {
- return njs_typed_array_set_value(vm, njs_typed_array(&prev->value),
- prev->value.data.magic32,
- &prop->value);
+ if (njs_is_valid(njs_prop_value(prop))) {
+ return njs_typed_array_set_value(vm,
+ njs_typed_array(njs_prop_value(prev)),
+ njs_prop_magic32(prev),
+ njs_prop_value(prop));
}
return NJS_OK;
goto set_prop;
}
- prev->type = prop->type;
-
if (njs_is_data_descriptor(prev)) {
- njs_set_undefined(&prev->getter);
- njs_set_undefined(&prev->setter);
-
- njs_set_invalid(&prev->value);
prev->writable = NJS_ATTRIBUTE_UNSET;
+ njs_prop_getter(prev) = NULL;
+ njs_prop_setter(prev) = NULL;
} else {
- njs_set_undefined(&prev->value);
prev->writable = NJS_ATTRIBUTE_FALSE;
- njs_set_invalid(&prev->getter);
- njs_set_invalid(&prev->setter);
+ njs_set_undefined(njs_prop_value(prev));
}
+ prev->type = prop->type;
} else if (njs_is_data_descriptor(prev)
&& njs_is_data_descriptor(prop))
goto exception;
}
- if (njs_is_valid(&prop->value)
+ if (njs_is_valid(njs_prop_value(prop))
&& prev->type != NJS_PROPERTY_HANDLER
- && !njs_values_same(&prop->value, &prev->value))
+ && !njs_values_same(njs_prop_value(prop), njs_prop_value(prev)))
{
goto exception;
}
} else {
if (!prev->configurable) {
- if (njs_is_valid(&prop->getter)
- && !njs_values_strict_equal(&prop->getter, &prev->getter))
+ if (njs_prop_getter(prop) != NJS_PROP_PTR_UNSET
+ && njs_prop_getter(prop) != njs_prop_getter(prev))
{
goto exception;
}
- if (njs_is_valid(&prop->setter)
- && !njs_values_strict_equal(&prop->setter, &prev->setter))
+ if (njs_prop_setter(prop) != NJS_PROP_PTR_UNSET
+ && njs_prop_setter(prop) != njs_prop_setter(prev))
{
goto exception;
}
done:
- if (njs_is_valid(&prop->value)) {
+ if (njs_is_accessor_descriptor(prop)) {
+ prev->type = prop->type;
+
+ if (njs_prop_getter(prop) != NJS_PROP_PTR_UNSET) {
+ njs_prop_getter(prev) = njs_prop_getter(prop);
+ }
+
+ if (njs_prop_setter(prop) != NJS_PROP_PTR_UNSET) {
+ njs_prop_setter(prev) = njs_prop_setter(prop);
+ }
+
+ } else if (njs_is_valid(njs_prop_value(prop))) {
+
if (prev->type == NJS_PROPERTY_HANDLER) {
if (prev->writable) {
- ret = prev->value.data.u.prop_handler(vm, prev, object,
- &prop->value,
- &vm->retval);
+ ret = njs_prop_handler(prev)(vm, prev, object,
+ njs_prop_value(prop), &vm->retval);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
} else {
prev->type = prop->type;
- njs_value_assign(&prev->value, &prop->value);
+ njs_value_assign(njs_prop_value(prev), njs_prop_value(prop));
}
} else {
if (prev->configurable != 1 &&
prev->writable != 1 &&
- !njs_values_strict_equal(&prev->value,
- &prop->value))
+ !njs_values_strict_equal(njs_prop_value(prev),
+ njs_prop_value(prop)))
{
njs_type_error(vm, "Cannot redefine "
"property: \"length\"");
}
return njs_array_length_set(vm, object, prev,
- &prop->value);
+ njs_prop_value(prop));
}
}
}
- prev->value = prop->value;
+ njs_value_assign(njs_prop_value(prev), njs_prop_value(prop));
}
}
* attribute of the property named P of object O to the value of the field.
*/
- if (njs_is_valid(&prop->getter)) {
- prev->getter = prop->getter;
- }
-
- if (njs_is_valid(&prop->setter)) {
- prev->setter = prop->setter;
- }
-
if (prop->writable != NJS_ATTRIBUTE_UNSET) {
prev->writable = prop->writable;
}
njs_int_t
-njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq)
+njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq,
+ njs_object_t *proto)
{
njs_int_t ret;
njs_value_t *value;
pq->lhq.value = prop;
pq->lhq.pool = vm->mem_pool;
- ret = njs_lvlhsh_insert(&pq->prototype->hash, &pq->lhq);
+ ret = njs_lvlhsh_insert(&proto->hash, &pq->lhq);
if (njs_slow_path(ret != NJS_OK)) {
njs_internal_error(vm, "lvlhsh insert failed");
return NJS_ERROR;
}
if (njs_is_accessor_descriptor(prop)) {
- if (njs_is_function(&prop->getter)) {
- function = njs_function_value_copy(vm, &prop->getter);
+ if (njs_prop_getter(prop) != NULL) {
+ function = njs_function_copy(vm, njs_prop_getter(prop));
if (njs_slow_path(function == NULL)) {
return NJS_ERROR;
}
- if (njs_is_function(&prop->setter)
- && function->native && njs_function(&prop->setter)->native
- && function->u.native == njs_function(&prop->setter)->u.native)
+ njs_prop_getter(prop) = function;
+
+ if (njs_prop_setter(prop) != NULL
+ && function->native && njs_prop_setter(prop)->native
+ && function->u.native == njs_prop_setter(prop)->u.native)
{
- prop->setter = prop->getter;
+ njs_prop_setter(prop) = njs_prop_getter(prop);
return NJS_OK;
}
}
- if (njs_is_function(&prop->setter)) {
- function = njs_function_value_copy(vm, &prop->setter);
+ if (njs_prop_setter(prop) != NULL) {
+ function = njs_function_copy(vm, njs_prop_setter(prop));
if (njs_slow_path(function == NULL)) {
return NJS_ERROR;
}
+
+ njs_prop_setter(prop) = function;
}
return NJS_OK;
}
- value = &prop->value;
+ value = njs_prop_value(prop);
switch (value->type) {
case NJS_OBJECT:
return NJS_OK;
case NJS_FUNCTION:
- function = njs_function_value_copy(vm, &prop->value);
+ function = njs_function_value_copy(vm, value);
if (njs_slow_path(function == NULL)) {
return NJS_ERROR;
}
njs_int_t ret;
njs_bool_t data, accessor;
njs_value_t value;
+ njs_function_t *getter, *setter;
njs_lvlhsh_query_t lhq;
static const njs_value_t get_string = njs_string("get");
data = 0;
accessor = 0;
+ getter = NJS_PROP_PTR_UNSET;
+ setter = NJS_PROP_PTR_UNSET;
njs_object_property_init(&lhq, &get_string, NJS_GET_HASH);
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return NJS_ERROR;
}
}
accessor = 1;
- prop->getter = value;
-
- } else {
- /* NJS_DECLINED */
- njs_set_invalid(&prop->getter);
+ getter = njs_is_function(&value) ? njs_function(&value) : NULL;
}
lhq.key = njs_str_value("set");
lhq.key_hash = NJS_SET_HASH;
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
}
accessor = 1;
- prop->setter = value;
-
- } else {
- /* NJS_DECLINED */
- njs_set_invalid(&prop->setter);
+ setter = njs_is_function(&value) ? njs_function(&value) : NULL;
}
lhq.key = njs_str_value("value");
lhq.key_hash = NJS_VALUE_HASH;
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
if (ret == NJS_OK) {
data = 1;
- prop->value = value;
+ njs_value_assign(njs_prop_value(prop), &value);
}
lhq.key = njs_str_value("writable");
lhq.key_hash = NJS_WRITABABLE_HASH;
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
prop->writable = njs_is_true(&value);
}
+ if (accessor && data) {
+ njs_type_error(vm, "Cannot both specify accessors "
+ "and a value or writable attribute");
+ return NJS_ERROR;
+ }
+
lhq.key = njs_str_value("enumerable");
lhq.key_hash = NJS_ENUMERABLE_HASH;
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
lhq.key_hash = NJS_CONFIGURABLE_HASH;
ret = njs_object_property(vm, desc, &lhq, &value);
-
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
prop->configurable = njs_is_true(&value);
}
- if (accessor && data) {
- njs_type_error(vm, "Cannot both specify accessors "
- "and a value or writable attribute");
- return NJS_ERROR;
+ if (accessor) {
+ prop->type = NJS_ACCESSOR;
+ njs_prop_getter(prop) = getter;
+ njs_prop_setter(prop) = setter;
}
return NJS_OK;
njs_lvlhsh_query_t lhq;
njs_property_query_t pq;
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 1);
if (njs_slow_path(!njs_is_key(key))) {
ret = njs_value_to_key(vm, key, key);
switch (prop->type) {
case NJS_PROPERTY:
+ case NJS_ACCESSOR:
break;
case NJS_PROPERTY_HANDLER:
pq.scratch = *prop;
prop = &pq.scratch;
- ret = prop->value.data.u.prop_handler(vm, prop, value, NULL,
- &prop->value);
+ ret = njs_prop_handler(prop)(vm, prop, value, NULL,
+ njs_prop_value(prop));
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
lhq.key = njs_str_value("value");
lhq.key_hash = NJS_VALUE_HASH;
- pr = njs_object_prop_alloc(vm, &njs_object_value_string, &prop->value,
- 1);
+ pr = njs_object_prop_alloc(vm, &njs_object_value_string,
+ njs_prop_value(prop), 1);
if (njs_slow_path(pr == NULL)) {
return NJS_ERROR;
}
lhq.key = njs_str_value("get");
lhq.key_hash = NJS_GET_HASH;
- pr = njs_object_prop_alloc(vm, &njs_object_get_string, &prop->getter,
- 1);
+ pr = njs_object_prop_alloc(vm, &njs_object_get_string,
+ &njs_value_undefined, 1);
if (njs_slow_path(pr == NULL)) {
return NJS_ERROR;
}
+ if (njs_prop_getter(prop) != NULL) {
+ njs_set_function(njs_prop_value(pr), njs_prop_getter(prop));
+ }
+
lhq.value = pr;
ret = njs_lvlhsh_insert(&desc->hash, &lhq);
lhq.key = njs_str_value("set");
lhq.key_hash = NJS_SET_HASH;
- pr = njs_object_prop_alloc(vm, &njs_object_set_string, &prop->setter,
- 1);
+ pr = njs_object_prop_alloc(vm, &njs_object_set_string,
+ &njs_value_undefined, 1);
if (njs_slow_path(pr == NULL)) {
return NJS_ERROR;
}
+ if (njs_prop_setter(prop) != NULL) {
+ njs_set_function(njs_prop_value(pr), njs_prop_setter(prop));
+ }
+
lhq.value = pr;
ret = njs_lvlhsh_insert(&desc->hash, &lhq);
*prop = *base;
prop->type = NJS_PROPERTY;
- njs_set_object(&prop->value, object);
+ njs_set_object(njs_prop_value(prop), object);
lhq.proto = &njs_object_hash_proto;
njs_string_get(&prop->name, &lhq.key);
ret = njs_lvlhsh_insert(njs_object_hash(value), &lhq);
if (njs_fast_path(ret == NJS_OK)) {
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
return NJS_OK;
}
--- /dev/null
+
+/*
+ * Copyright (C) Dmitry Volyntsev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NJS_OBJECT_PROP_DECLARE_H_INCLUDED_
+#define _NJS_OBJECT_PROP_DECLARE_H_INCLUDED_
+
+#define NJS_DECLARE_PROP_VALUE(_name, _v, _fl) \
+ { \
+ .type = NJS_PROPERTY, \
+ .name = njs_string(_name), \
+ .u.value = _v, \
+ .enumerable = !!(_fl & NJS_OBJECT_PROP_ENUMERABLE), \
+ .configurable = !!(_fl & NJS_OBJECT_PROP_CONFIGURABLE), \
+ .writable = !!(_fl & NJS_OBJECT_PROP_WRITABLE), \
+ }
+
+
+#define NJS_DECLARE_PROP_LVALUE(_name, _v, _fl) \
+ { \
+ .type = NJS_PROPERTY, \
+ .name = njs_long_string(_name), \
+ .u.value = _v, \
+ .enumerable = !!(_fl & NJS_OBJECT_PROP_ENUMERABLE), \
+ .configurable = !!(_fl & NJS_OBJECT_PROP_CONFIGURABLE), \
+ .writable = !!(_fl & NJS_OBJECT_PROP_WRITABLE), \
+ }
+
+
+#define NJS_DECLARE_PROP_NATIVE(_name, _native, _nargs, _magic) \
+ NJS_DECLARE_PROP_VALUE(_name, \
+ njs_native_function2(_native, _nargs, _magic), \
+ NJS_OBJECT_PROP_VALUE_CW)
+
+
+#define NJS_DECLARE_PROP_LNATIVE(_name, _native, _nargs, _magic) \
+ NJS_DECLARE_PROP_LVALUE(_name, \
+ njs_native_function2(_native, _nargs, _magic), \
+ NJS_OBJECT_PROP_VALUE_CW)
+
+
+#define NJS_DECLARE_PROP_HANDLER(_name, _native, _m16, _m32, _fl) \
+ { \
+ .type = NJS_PROPERTY_HANDLER, \
+ .name = njs_string(_name), \
+ .u.value = njs_prop_handler2(_native, _m16, _m32), \
+ .enumerable = !!(_fl & NJS_OBJECT_PROP_ENUMERABLE), \
+ .configurable = !!(_fl & NJS_OBJECT_PROP_CONFIGURABLE), \
+ .writable = !!(_fl & NJS_OBJECT_PROP_WRITABLE), \
+ }
+
+
+#define NJS_DECLARE_PROP_GETTER(_name, _native, _magic) \
+ { \
+ .type = NJS_ACCESSOR, \
+ .name = njs_string(_name), \
+ .u.accessor = njs_getter(_native, _magic), \
+ .writable = NJS_ATTRIBUTE_UNSET, \
+ .configurable = 1, \
+ }
+
+
+#define NJS_DECLARE_PROP_NAME(_name) \
+ NJS_DECLARE_PROP_VALUE("name", njs_string(_name), NJS_OBJECT_PROP_VALUE_C)
+
+
+#define NJS_DECLARE_PROP_LENGTH(_v) \
+ NJS_DECLARE_PROP_VALUE("length", njs_value(NJS_NUMBER, !!(_v), _v), \
+ NJS_OBJECT_PROP_VALUE_C)
+
+
+#endif /* _NJS_OBJECT_PROP_DECLARE_H_INCLUDED_ */
static const njs_object_prop_t njs_promise_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Promise"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Promise"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("resolve"),
- .value = njs_native_function(njs_promise_object_resolve, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("resolve", njs_promise_object_resolve, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reject"),
- .value = njs_native_function(njs_promise_object_reject, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reject", njs_promise_object_reject, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("all"),
- .value = njs_native_function2(njs_promise_all, 1, NJS_PROMISE_ALL),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("all", njs_promise_all, 1, NJS_PROMISE_ALL),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("allSettled"),
- .value = njs_native_function2(njs_promise_all, 1,
- NJS_PROMISE_ALL_SETTLED),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("allSettled", njs_promise_all, 1,
+ NJS_PROMISE_ALL_SETTLED),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("any"),
- .value = njs_native_function2(njs_promise_all, 1, NJS_PROMISE_ANY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("any", njs_promise_all, 1, NJS_PROMISE_ANY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("race"),
- .value = njs_native_function(njs_promise_race, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("race", njs_promise_race, 1, 0),
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_promise_species, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
+ .u.accessor = njs_getter(njs_promise_species, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
- .enumerable = 0,
},
};
static const njs_object_prop_t njs_promise_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("Promise"),
+ .u.value = njs_string("Promise"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("then"),
- .value = njs_native_function(njs_promise_prototype_then, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("then", njs_promise_prototype_then, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("catch"),
- .value = njs_native_function(njs_promise_prototype_catch, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("catch", njs_promise_prototype_catch, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("finally"),
- .value = njs_native_function(njs_promise_prototype_finally, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("finally", njs_promise_prototype_finally, 1, 0),
};
index = c;
}
- njs_set_number(&prop->value, index);
+ njs_set_number(&prop->u.value, index);
if (pattern->global || pattern->sticky) {
c = njs_regex_capture(match_data, 1);
goto fail;
}
- njs_set_object(&prop->value, groups);
+ njs_set_object(&prop->u.value, groups);
i = 0;
static const njs_object_prop_t njs_regexp_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("RegExp"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("RegExp"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 2.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(2),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
static const njs_object_prop_t njs_regexp_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("flags"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_regexp_prototype_flags, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("flags", njs_regexp_prototype_flags, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("global"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function2(njs_regexp_prototype_flag, 0,
- NJS_REGEX_GLOBAL),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("global", njs_regexp_prototype_flag,
+ NJS_REGEX_GLOBAL),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("ignoreCase"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function2(njs_regexp_prototype_flag, 0,
- NJS_REGEX_IGNORE_CASE),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("ignoreCase", njs_regexp_prototype_flag,
+ NJS_REGEX_IGNORE_CASE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("multiline"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function2(njs_regexp_prototype_flag, 0,
- NJS_REGEX_MULTILINE),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("multiline", njs_regexp_prototype_flag,
+ NJS_REGEX_MULTILINE),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("source"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_regexp_prototype_source, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("source", njs_regexp_prototype_source, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sticky"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function2(njs_regexp_prototype_flag, 0,
- NJS_REGEX_STICKY),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("sticky", njs_regexp_prototype_flag,
+ NJS_REGEX_STICKY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_regexp_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_regexp_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("test"),
- .value = njs_native_function(njs_regexp_prototype_test, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("test", njs_regexp_prototype_test, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("exec"),
- .value = njs_native_function(njs_regexp_prototype_exec, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("exec", njs_regexp_prototype_exec, 1, 0),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_REPLACE),
- .value = njs_native_function(njs_regexp_prototype_symbol_replace, 2),
+ .u.value = njs_native_function(njs_regexp_prototype_symbol_replace, 2),
.writable = 1,
.configurable = 1,
},
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_SPLIT),
- .value = njs_native_function(njs_regexp_prototype_symbol_split, 2),
+ .u.value = njs_native_function(njs_regexp_prototype_symbol_split, 2),
.writable = 1,
.configurable = 1,
},
const njs_object_prop_t njs_regexp_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("lastIndex"),
- .value = njs_prop_handler(njs_regexp_prototype_last_index),
- .writable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("lastIndex", njs_regexp_prototype_last_index,
+ 0, 0, NJS_OBJECT_PROP_VALUE_W),
};
static const njs_object_prop_t njs_string_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("String"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("String"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("bytesFrom"),
- .value = njs_native_function(njs_string_bytes_from, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("bytesFrom", njs_string_bytes_from, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fromCharCode"),
- .value = njs_native_function2(njs_string_from_char_code, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fromCharCode", njs_string_from_char_code, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fromCodePoint"),
- .value = njs_native_function2(njs_string_from_char_code, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fromCodePoint", njs_string_from_char_code, 1, 1),
};
static const njs_object_prop_t njs_string_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_primitive_prototype_get_proto),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_string_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_string_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_string_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_string_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("concat"),
- .value = njs_native_function(njs_string_prototype_concat, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("concat", njs_string_prototype_concat, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fromUTF8"),
- .value = njs_native_function(njs_string_prototype_from_utf8, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fromUTF8", njs_string_prototype_from_utf8, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toUTF8"),
- .value = njs_native_function(njs_string_prototype_to_utf8, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toUTF8", njs_string_prototype_to_utf8, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fromBytes"),
- .value = njs_native_function(njs_string_prototype_from_bytes, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fromBytes", njs_string_prototype_from_bytes, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toBytes"),
- .value = njs_native_function(njs_string_prototype_to_bytes, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toBytes", njs_string_prototype_to_bytes, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function(njs_string_prototype_slice, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("slice", njs_string_prototype_slice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("substring"),
- .value = njs_native_function(njs_string_prototype_substring, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("substring", njs_string_prototype_substring, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("substr"),
- .value = njs_native_function(njs_string_prototype_substr, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("substr", njs_string_prototype_substr, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("charAt"),
- .value = njs_native_function(njs_string_prototype_char_at, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("charAt", njs_string_prototype_char_at, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("charCodeAt"),
- .value = njs_native_function(njs_string_prototype_char_code_at, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("charCodeAt", njs_string_prototype_char_code_at, 1,
+ 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("codePointAt"),
- .value = njs_native_function(njs_string_prototype_char_code_at, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("codePointAt", njs_string_prototype_char_code_at,
+ 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("indexOf"),
- .value = njs_native_function(njs_string_prototype_index_of, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("indexOf", njs_string_prototype_index_of, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("lastIndexOf"),
- .value = njs_native_function(njs_string_prototype_last_index_of, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("lastIndexOf", njs_string_prototype_last_index_of,
+ 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("includes"),
- .value = njs_native_function(njs_string_prototype_includes, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("includes", njs_string_prototype_includes, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("startsWith"),
- .value = njs_native_function2(njs_string_prototype_starts_or_ends_with,
- 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("startsWith",
+ njs_string_prototype_starts_or_ends_with, 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("endsWith"),
- .value = njs_native_function2(njs_string_prototype_starts_or_ends_with,
- 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("endsWith",
+ njs_string_prototype_starts_or_ends_with, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toLowerCase"),
- .value = njs_native_function(njs_string_prototype_to_lower_case, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toLowerCase", njs_string_prototype_to_lower_case,
+ 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toUpperCase"),
- .value = njs_native_function(njs_string_prototype_to_upper_case, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toUpperCase", njs_string_prototype_to_upper_case,
+ 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("trim"),
- .value = njs_native_function2(njs_string_prototype_trim, 0,
- NJS_TRIM_START | NJS_TRIM_END),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("trim", njs_string_prototype_trim, 0,
+ NJS_TRIM_START | NJS_TRIM_END),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("trimStart"),
- .value = njs_native_function2(njs_string_prototype_trim, 0,
- NJS_TRIM_START),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("trimStart", njs_string_prototype_trim, 0,
+ NJS_TRIM_START),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("trimEnd"),
- .value = njs_native_function2(njs_string_prototype_trim, 0,
- NJS_TRIM_END),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("trimEnd", njs_string_prototype_trim, 0,
+ NJS_TRIM_END),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("repeat"),
- .value = njs_native_function(njs_string_prototype_repeat, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("repeat", njs_string_prototype_repeat, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("padStart"),
- .value = njs_native_function2(njs_string_prototype_pad, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("padStart", njs_string_prototype_pad, 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("padEnd"),
- .value = njs_native_function2(njs_string_prototype_pad, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("padEnd", njs_string_prototype_pad, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("search"),
- .value = njs_native_function(njs_string_prototype_search, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("search", njs_string_prototype_search, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("match"),
- .value = njs_native_function(njs_string_prototype_match, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("match", njs_string_prototype_match, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("split"),
- .value = njs_native_function(njs_string_prototype_split, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("split", njs_string_prototype_split, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("replace"),
- .value = njs_native_function(njs_string_prototype_replace, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("replace", njs_string_prototype_replace, 2, 0),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_ITERATOR),
- .value = njs_native_function2(njs_string_prototype_iterator_obj, 0,
- NJS_ENUM_VALUES),
+ .u.value = njs_native_function2(njs_string_prototype_iterator_obj, 0,
+ NJS_ENUM_VALUES),
.writable = 1,
.configurable = 1,
},
const njs_object_prop_t njs_string_instance_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("length"),
- .value = njs_prop_handler(njs_string_instance_length),
- },
+ NJS_DECLARE_PROP_HANDLER("length", njs_string_instance_length, 0, 0, 0),
};
static const njs_object_prop_t njs_symbol_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Symbol"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Symbol"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("for"),
- .value = njs_native_function(njs_symbol_for, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("keyFor"),
- .value = njs_native_function(njs_symbol_key_for, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("for", njs_symbol_for, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("asyncIterator"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_ASYNC_ITERATOR),
- },
+ NJS_DECLARE_PROP_NATIVE("keyFor", njs_symbol_key_for, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("hasInstance"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_HAS_INSTANCE),
- },
+ NJS_DECLARE_PROP_VALUE("asyncIterator",
+ njs_wellknown_symbol(NJS_SYMBOL_ASYNC_ITERATOR), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("isConcatSpreadable"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_IS_CONCAT_SPREADABLE),
- },
+ NJS_DECLARE_PROP_VALUE("hasInstance",
+ njs_wellknown_symbol(NJS_SYMBOL_HAS_INSTANCE), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("iterator"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_ITERATOR),
- },
+ NJS_DECLARE_PROP_LVALUE("isConcatSpreadable",
+ njs_wellknown_symbol(NJS_SYMBOL_IS_CONCAT_SPREADABLE), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("match"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_MATCH),
- },
+ NJS_DECLARE_PROP_VALUE("iterator",
+ njs_wellknown_symbol(NJS_SYMBOL_ITERATOR), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("matchAll"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_MATCH_ALL),
- },
+ NJS_DECLARE_PROP_VALUE("match",
+ njs_wellknown_symbol(NJS_SYMBOL_MATCH), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("replace"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_REPLACE),
- },
+ NJS_DECLARE_PROP_VALUE("matchAll",
+ njs_wellknown_symbol(NJS_SYMBOL_MATCH_ALL), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("search"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_SEARCH),
- },
+ NJS_DECLARE_PROP_VALUE("replace",
+ njs_wellknown_symbol(NJS_SYMBOL_REPLACE), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("species"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
- },
+ NJS_DECLARE_PROP_VALUE("search",
+ njs_wellknown_symbol(NJS_SYMBOL_SEARCH), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("split"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_SPLIT),
- },
+ NJS_DECLARE_PROP_VALUE("species",
+ njs_wellknown_symbol(NJS_SYMBOL_SPECIES), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toPrimitive"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_TO_PRIMITIVE),
- },
+ NJS_DECLARE_PROP_VALUE("split",
+ njs_wellknown_symbol(NJS_SYMBOL_SPLIT), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toStringTag"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- },
+ NJS_DECLARE_PROP_VALUE("toPrimitive",
+ njs_wellknown_symbol(NJS_SYMBOL_TO_PRIMITIVE), 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("unscopables"),
- .value = njs_wellknown_symbol(NJS_SYMBOL_UNSCOPABLES),
- },
+ NJS_DECLARE_PROP_VALUE("toStringTag",
+ njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG), 0),
+ NJS_DECLARE_PROP_VALUE("unscopables",
+ njs_wellknown_symbol(NJS_SYMBOL_UNSCOPABLES), 0),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("Symbol"),
+ .u.value = njs_string("Symbol"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("__proto__"),
- .value = njs_prop_handler(njs_primitive_prototype_get_proto),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("__proto__", njs_primitive_prototype_get_proto,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("valueOf"),
- .value = njs_native_function(njs_symbol_prototype_value_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("valueOf", njs_symbol_prototype_value_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_symbol_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_symbol_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("description"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_symbol_prototype_description, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_GETTER("description", njs_symbol_prototype_description, 0),
};
static const njs_object_prop_t njs_typed_array_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("TypedArray"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("TypedArray"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 0, 0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(0),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_get_this, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
+ .u.accessor = njs_getter(njs_typed_array_get_this, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
.enumerable = 0,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("of"),
- .value = njs_native_function(njs_typed_array_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("of", njs_typed_array_of, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("from"),
- .value = njs_native_function(njs_typed_array_from, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("from", njs_typed_array_from, 1, 0),
};
static const njs_object_prop_t njs_typed_array_prototype_properties[] =
{
{
- .type = NJS_PROPERTY,
+ .type = NJS_ACCESSOR,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_get_string_tag,
- 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
+ .u.accessor = njs_getter(njs_typed_array_get_string_tag, 0),
.writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
.enumerable = 0,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("buffer"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_buffer, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("buffer", njs_typed_array_prototype_buffer, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("byteLength"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_byte_length, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("byteLength",
+ njs_typed_array_prototype_byte_length, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("byteOffset"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_byte_offset, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("byteOffset",
+ njs_typed_array_prototype_byte_offset, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_length, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("length", njs_typed_array_prototype_length, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("copyWithin"),
- .value = njs_native_function(njs_typed_array_prototype_copy_within, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("copyWithin",
+ njs_typed_array_prototype_copy_within, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("entries"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator_obj, 0,
- NJS_ENUM_BOTH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("entries",
+ njs_typed_array_prototype_iterator_obj, 0,
+ NJS_ENUM_BOTH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("every"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_EVERY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("every",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_EVERY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("filter"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_FILTER),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("filter",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_FILTER),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("find"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_FIND),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("find",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_FIND),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("findIndex"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_FIND_INDEX),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("findIndex",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_FIND_INDEX),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("forEach"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_FOR_EACH),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("forEach",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_FOR_EACH),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("includes"),
- .value = njs_native_function2(njs_typed_array_prototype_index_of, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("includes",
+ njs_typed_array_prototype_index_of, 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("indexOf"),
- .value = njs_native_function2(njs_typed_array_prototype_index_of, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("indexOf",
+ njs_typed_array_prototype_index_of, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("join"),
- .value = njs_native_function(njs_typed_array_prototype_join, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("join", njs_typed_array_prototype_join, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fill"),
- .value = njs_native_function(njs_typed_array_prototype_fill, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("fill", njs_typed_array_prototype_fill, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("keys"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator_obj, 0,
- NJS_ENUM_KEYS),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("keys", njs_typed_array_prototype_iterator_obj, 0,
+ NJS_ENUM_KEYS),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("lastIndexOf"),
- .value = njs_native_function2(njs_typed_array_prototype_index_of, 1, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("lastIndexOf",
+ njs_typed_array_prototype_index_of, 1, 2),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("map"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_MAP),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("map",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_MAP),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reduce"),
- .value = njs_native_function2(njs_typed_array_prototype_reduce, 1, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reduce", njs_typed_array_prototype_reduce, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reduceRight"),
- .value = njs_native_function2(njs_typed_array_prototype_reduce, 1, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reduceRight", njs_typed_array_prototype_reduce,
+ 1, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reverse"),
- .value = njs_native_function(njs_typed_array_prototype_reverse, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("reverse", njs_typed_array_prototype_reverse, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("set"),
- .value = njs_native_function(njs_typed_array_prototype_set, 2),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("set", njs_typed_array_prototype_set, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function2(njs_typed_array_prototype_slice, 2, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("slice", njs_typed_array_prototype_slice, 2, 1),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("some"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator, 1,
- NJS_ARRAY_SOME),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("some",
+ njs_typed_array_prototype_iterator, 1,
+ NJS_ARRAY_SOME),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sort"),
- .value = njs_native_function(njs_typed_array_prototype_sort, 1),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("sort", njs_typed_array_prototype_sort, 1, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("subarray"),
- .value = njs_native_function2(njs_typed_array_prototype_slice, 2, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("subarray", njs_typed_array_prototype_slice, 2, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_array_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("toString", njs_array_prototype_to_string, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("values"),
- .value = njs_native_function2(njs_typed_array_prototype_iterator_obj, 0,
- NJS_ENUM_VALUES),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("values", njs_typed_array_prototype_iterator_obj,
+ 0, NJS_ENUM_VALUES),
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_ITERATOR),
- .value = njs_native_function2(njs_typed_array_prototype_iterator_obj, 0,
- NJS_ENUM_VALUES),
+ .u.value = njs_native_function2(njs_typed_array_prototype_iterator_obj,
+ 0, NJS_ENUM_VALUES),
.writable = 1,
.configurable = 1,
},
static const njs_object_prop_t njs_data_view_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("DataView"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("DataView"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(1),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
{
.type = NJS_PROPERTY,
.name = njs_wellknown_symbol(NJS_SYMBOL_TO_STRING_TAG),
- .value = njs_string("DataView"),
+ .u.value = njs_string("DataView"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("buffer"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_buffer, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("buffer", njs_typed_array_prototype_buffer, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("byteLength"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_byte_length, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("byteLength",
+ njs_typed_array_prototype_byte_length, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("byteOffset"),
- .value = njs_value(NJS_INVALID, 1, NAN),
- .getter = njs_native_function(njs_typed_array_prototype_byte_offset, 0),
- .setter = njs_value(NJS_UNDEFINED, 0, NAN),
- .writable = NJS_ATTRIBUTE_UNSET,
- .configurable = 1,
- .enumerable = 0,
- },
+ NJS_DECLARE_PROP_GETTER("byteOffset",
+ njs_typed_array_prototype_byte_offset, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUint8"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_UINT8_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUint8", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_UINT8_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getInt8"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_INT8_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getInt8", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_INT8_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUint16"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_UINT16_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUint16", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_UINT16_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getInt16"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_INT16_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getInt16", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_INT16_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getUint32"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_UINT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getUint32", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_UINT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getInt32"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_INT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getInt32", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_INT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getFloat32"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_FLOAT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getFloat32", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_FLOAT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("getFloat64"),
- .value = njs_native_function2(njs_data_view_prototype_get, 1,
- NJS_OBJ_TYPE_FLOAT64_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("getFloat64", njs_data_view_prototype_get, 1,
+ NJS_OBJ_TYPE_FLOAT64_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUint8"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_UINT8_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUint8", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_UINT8_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setInt8"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_INT8_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setInt8", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_INT8_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUint16"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_UINT16_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUint16", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_UINT16_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setInt16"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_INT16_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setInt16", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_INT16_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setUint32"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_UINT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setUint32", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_UINT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setInt32"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_INT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setInt32", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_INT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setFloat32"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_FLOAT32_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setFloat32", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_FLOAT32_ARRAY),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("setFloat64"),
- .value = njs_native_function2(njs_data_view_prototype_set, 2,
- NJS_OBJ_TYPE_FLOAT64_ARRAY),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NATIVE("setFloat64", njs_data_view_prototype_set, 2,
+ NJS_OBJ_TYPE_FLOAT64_ARRAY),
};
static const njs_object_prop_t njs_typed_array_u8_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Uint8Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Uint8Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u8_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
{
.type = NJS_PROPERTY,
.name = njs_string("name"),
- .value = njs_long_string("Uint8ClampedArray"),
+ .u.value = njs_long_string("Uint8ClampedArray"),
.configurable = 1,
},
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u8c_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i8_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Int8Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Int8Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i8_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 1),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 1),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u16_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Uint16Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Uint16Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 2),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 2),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u16_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 2),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 2),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i16_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Int16Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Int16Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 2),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 2),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i16_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 2),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 2),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u32_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Uint32Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Uint32Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_u32_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i32_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Int32Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Int32Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_i32_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_f32_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Float32Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Float32Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_f32_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 4),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 4),
+ 0),
};
static const njs_object_prop_t njs_typed_array_f64_constructor_props[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Float64Array"),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Float64Array"),
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 3.0),
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_LENGTH(3),
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 8),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 8),
+ 0),
};
static const njs_object_prop_t njs_typed_array_f64_prototype_properties[] =
{
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("constructor"),
- .value = njs_prop_handler(njs_object_prototype_create_constructor),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .type = NJS_PROPERTY,
- .name = njs_long_string("BYTES_PER_ELEMENT"),
- .value = njs_value(NJS_NUMBER, 1, 8),
- .configurable = 0,
- .enumerable = 0,
- .writable = 0,
- },
+ NJS_DECLARE_PROP_LVALUE("BYTES_PER_ELEMENT", njs_value(NJS_NUMBER, 1, 8),
+ 0),
};
} else {
njs_string_get(&pq->key, &pq->lhq.key);
- pq->lhq.key_hash = njs_djb_hash(pq->lhq.key.start,
- pq->lhq.key.length);
+
+ if (pq->lhq.key_hash == 0) {
+ pq->lhq.key_hash = njs_djb_hash(pq->lhq.key.start,
+ pq->lhq.key.length);
+ }
}
ret = njs_object_property_query(vm, pq, obj, key);
proto = object;
do {
- pq->prototype = proto;
-
- if (!njs_is_null_or_undefined_or_boolean(key)) {
- switch (proto->type) {
- case NJS_ARRAY:
- array = (njs_array_t *) proto;
- num = njs_key_to_index(key);
-
- if (njs_fast_path(njs_key_is_integer_index(num, key))) {
- ret = njs_array_property_query(vm, pq, array, num);
- if (njs_fast_path(ret != NJS_DECLINED)) {
- return (ret == NJS_DONE) ? NJS_DECLINED : ret;
- }
+ switch (proto->type) {
+ case NJS_ARRAY:
+ array = (njs_array_t *) proto;
+ num = njs_key_to_index(key);
+
+ if (njs_fast_path(njs_key_is_integer_index(num, key))) {
+ ret = njs_array_property_query(vm, pq, array, num);
+ if (njs_fast_path(ret != NJS_DECLINED)) {
+ return (ret == NJS_DONE) ? NJS_DECLINED : ret;
}
+ }
- break;
+ break;
- case NJS_TYPED_ARRAY:
- num = njs_key_to_index(key);
- if (njs_fast_path(njs_key_is_integer_index(num, key))) {
- tarray = (njs_typed_array_t *) proto;
- return njs_typed_array_property_query(vm, pq, tarray, num);
- }
+ case NJS_TYPED_ARRAY:
+ num = njs_key_to_index(key);
+ if (njs_fast_path(njs_key_is_integer_index(num, key))) {
+ tarray = (njs_typed_array_t *) proto;
+ return njs_typed_array_property_query(vm, pq, tarray, num);
+ }
- if (!isnan(num)) {
- return NJS_DECLINED;
- }
+ if (!isnan(num)) {
+ return NJS_DECLINED;
+ }
+ break;
+
+ case NJS_OBJECT_VALUE:
+ ov = (njs_object_value_t *) proto;
+ if (!njs_is_string(&ov->value)) {
break;
+ }
- case NJS_OBJECT_VALUE:
+ num = njs_key_to_index(key);
+ if (njs_fast_path(njs_key_is_integer_index(num, key))) {
ov = (njs_object_value_t *) proto;
- if (!njs_is_string(&ov->value)) {
- break;
- }
-
- num = njs_key_to_index(key);
- if (njs_fast_path(njs_key_is_integer_index(num, key))) {
- ov = (njs_object_value_t *) proto;
- ret = njs_string_property_query(vm, pq, &ov->value, num);
- if (njs_fast_path(ret != NJS_DECLINED)) {
- return ret;
- }
+ ret = njs_string_property_query(vm, pq, &ov->value, num);
+ if (njs_fast_path(ret != NJS_DECLINED)) {
+ return ret;
}
+ }
- break;
+ break;
- default:
- break;
- }
+ default:
+ break;
}
ret = njs_lvlhsh_find(&proto->hash, &pq->lhq);
ret = njs_lvlhsh_find(&proto->shared_hash, &pq->lhq);
if (ret == NJS_OK) {
- return njs_prop_private_copy(vm, pq);
+ return njs_prop_private_copy(vm, pq, proto);
}
}
return NJS_DECLINED;
}
- prop->value = array->start[index];
+ njs_value_assign(njs_prop_value(prop), &array->start[index]);
prop->type = NJS_PROPERTY;
} else {
- prop->value.data.u.value = &array->start[index];
+ njs_prop_ref(prop) = &array->start[index];
prop->type = NJS_PROPERTY_REF;
}
prop = &pq->scratch;
if (pq->query == NJS_PROPERTY_QUERY_GET) {
- njs_set_number(&prop->value, njs_typed_array_prop(array, index));
+ njs_set_number(njs_prop_value(prop),
+ njs_typed_array_prop(array, index));
prop->type = NJS_PROPERTY;
} else {
- prop->value.data.u.typed_array = array;
- prop->value.data.magic32 = index;
+ njs_prop_typed_ref(prop) = array;
+ njs_prop_magic32(prop) = index;
prop->type = NJS_PROPERTY_TYPED_ARRAY_REF;
}
* A single codepoint string fits in retval
* so the function cannot fail.
*/
- (void) njs_string_slice(vm, &prop->value, &string, &slice);
+ (void) njs_string_slice(vm, njs_prop_value(prop), &string, &slice);
prop->type = NJS_PROPERTY;
prop->writable = 0;
* prop->type = NJS_PROPERTY;
* prop->writable = 0;
* prop->configurable = 0;
- * njs_set_null(&prop->getter);
- * njs_set_null(&prop->setter);
*/
- prop->value.data.magic32 = slots->magic32;
+ njs_prop_magic32(prop) = slots->magic32;
prop->name = pq->key;
pq->lhq.value = prop;
switch (pq->query) {
case NJS_PROPERTY_QUERY_GET:
- return slots->prop_handler(vm, prop, value, NULL, &prop->value);
+ return slots->prop_handler(vm, prop, value, NULL, njs_prop_value(prop));
case NJS_PROPERTY_QUERY_SET:
if (slots->writable == 0) {
}
prop->type = NJS_PROPERTY_HANDLER;
- prop->value.data.u.prop_handler = slots->prop_handler;
+ njs_prop_handler(prop) = slots->prop_handler;
return NJS_OK;
}
goto slow_path;
}
- *retval = array->start[index];
+ njs_value_assign(retval, &array->start[index]);
return NJS_OK;
}
slow_path:
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 0);
ret = njs_property_query(vm, &pq, value, key);
prop = pq.lhq.value;
switch (prop->type) {
-
case NJS_PROPERTY:
+ case NJS_ACCESSOR:
if (njs_is_data_descriptor(prop)) {
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
break;
}
- if (njs_is_undefined(&prop->getter)) {
+ if (njs_prop_getter(prop) == NULL) {
njs_set_undefined(retval);
break;
}
- return njs_function_apply(vm, njs_function(&prop->getter), value,
- 1, retval);
+ return njs_function_apply(vm, njs_prop_getter(prop), value, 1,
+ retval);
case NJS_PROPERTY_HANDLER:
pq.scratch = *prop;
prop = &pq.scratch;
- ret = prop->value.data.u.prop_handler(vm, prop, value, NULL,
- &prop->value);
+ ret = njs_prop_handler(prop)(vm, prop, value, NULL,
+ njs_prop_value(prop));
if (njs_slow_path(ret != NJS_OK)) {
if (ret == NJS_ERROR) {
return ret;
}
- njs_set_undefined(&prop->value);
+ njs_set_undefined(njs_prop_value(prop));
}
- *retval = prop->value;
+ njs_value_assign(retval, njs_prop_value(prop));
break;
goto slow_path;
}
- array->start[index] = *setval;
+ njs_value_assign(&array->start[index], setval);
return NJS_OK;
}
return NJS_ERROR;
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_SET, 0, 0);
ret = njs_property_query(vm, &pq, value, key);
}
} else {
- if (njs_is_function(&prop->setter)) {
- return njs_function_call(vm, njs_function(&prop->setter),
+ if (njs_prop_setter(prop) != NULL) {
+ return njs_function_call(vm, njs_prop_setter(prop),
value, setval, 1, &vm->retval);
}
}
if (prop->type == NJS_PROPERTY_HANDLER) {
- ret = prop->value.data.u.prop_handler(vm, prop, value, setval,
- &vm->retval);
+ ret = njs_prop_handler(prop)(vm, prop, value, setval, &vm->retval);
if (njs_slow_path(ret != NJS_DECLINED)) {
return ret;
}
goto found;
case NJS_PROPERTY_REF:
- *prop->value.data.u.value = *setval;
+ njs_value_assign(njs_prop_ref(prop), setval);
return NJS_OK;
case NJS_PROPERTY_TYPED_ARRAY_REF:
return njs_typed_array_set_value(vm,
- njs_typed_array(&prop->value),
- prop->value.data.magic32,
- setval);
+ njs_typed_array(njs_prop_value(prop)),
+ njs_prop_magic32(prop),
+ setval);
default:
njs_internal_error(vm, "unexpected property type \"%s\" "
found:
- prop->value = *setval;
+ njs_value_assign(njs_prop_value(prop), setval);
return NJS_OK;
key = &primitive;
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_DELETE, 1);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_DELETE, 0, 1);
ret = njs_property_query(vm, &pq, value, key);
if (njs_slow_path(ret != NJS_OK)) {
switch (prop->type) {
case NJS_PROPERTY_HANDLER:
if (njs_is_object(value) && njs_object_slots(value) != NULL) {
- ret = prop->value.data.u.prop_handler(vm, prop, value, NULL, NULL);
+ ret = njs_prop_handler(prop)(vm, prop, value, NULL, NULL);
if (njs_slow_path(ret != NJS_DECLINED)) {
return ret;
}
/* Fall through. */
case NJS_PROPERTY:
- if (njs_is_data_descriptor(prop) || removed == NULL) {
+ break;
+
+ case NJS_ACCESSOR:
+ if (removed == NULL) {
break;
}
- if (njs_is_undefined(&prop->getter)) {
+ if (njs_prop_getter(prop) == NULL) {
njs_set_undefined(removed);
break;
}
- return njs_function_apply(vm, njs_function(&prop->getter), value,
- 1, removed);
+ return njs_function_apply(vm, njs_prop_getter(prop), value, 1, removed);
case NJS_PROPERTY_REF:
if (removed != NULL) {
- *removed = *prop->value.data.u.value;
+ njs_value_assign(removed, njs_prop_ref(prop));
}
- njs_set_invalid(prop->value.data.u.value);
+ njs_set_invalid(njs_prop_ref(prop));
return NJS_OK;
default:
/* GC: release value. */
if (removed != NULL) {
- *removed = prop->value;
+ njs_value_assign(removed, njs_prop_value(prop));
}
prop->type = NJS_WHITEOUT;
- njs_set_invalid(&prop->value);
+ njs_set_invalid(njs_prop_value(prop));
return NJS_OK;
}
uint8_t extensible:1;
uint8_t error_data:1;
+ uint8_t stack_attached:1;
uint8_t fast_array:1;
};
typedef enum {
NJS_PROPERTY = 0,
+ NJS_ACCESSOR,
NJS_PROPERTY_REF,
NJS_PROPERTY_TYPED_ARRAY_REF,
NJS_PROPERTY_HANDLER,
} njs_object_prop_type_t;
+typedef enum {
+ NJS_PROPERTY_QUERY_GET = 0,
+ NJS_PROPERTY_QUERY_SET,
+ NJS_PROPERTY_QUERY_DELETE,
+} njs_prop_query_t;
+
+
/*
* Attributes are generally used as Boolean values.
* The UNSET value is can be seen:
struct njs_object_prop_s {
- /* Must be aligned to njs_value_t. */
- njs_value_t value;
njs_value_t name;
- njs_value_t getter;
- njs_value_t setter;
- /* TODO: get rid of types */
+ union {
+ njs_value_t value;
+ struct {
+ njs_function_t *getter;
+ njs_function_t *setter;
+ } accessor;
+ } u;
+
+#define njs_prop_value(_p) (&(_p)->u.value)
+#define njs_prop_handler(_p) (_p)->u.value.data.u.prop_handler
+#define njs_prop_ref(_p) (_p)->u.value.data.u.value
+#define njs_prop_typed_ref(_p) (_p)->u.value.data.u.typed_array
+#define njs_prop_magic16(_p) (_p)->u.value.data.magic16
+#define njs_prop_magic32(_p) (_p)->u.value.data.magic32
+#define NJS_PROP_PTR_UNSET ((void *) (uintptr_t) -1)
+#define njs_prop_getter(_p) (_p)->u.accessor.getter
+#define njs_prop_setter(_p) (_p)->u.accessor.setter
+
njs_object_prop_type_t type:8; /* 3 bits */
njs_object_attribute_t writable:8; /* 2 bits */
typedef struct {
njs_lvlhsh_query_t lhq;
+ uint8_t query;
+
/* scratch is used to get the value of an NJS_PROPERTY_HANDLER property. */
njs_object_prop_t scratch;
njs_value_t key;
- njs_object_t *prototype;
+
njs_object_prop_t *own_whiteout;
- uint8_t query;
- uint8_t shared;
uint8_t temp;
uint8_t own;
} njs_property_query_t;
_njs_native_function(_function, _args_count, 0, _magic)
-#define njs_native_ctor(_function, _args_count, _magic) \
- _njs_function(_function, _args_count, 1, _magic)
+#define njs_getter(_function, _magic) \
+ { \
+ .getter = & (njs_function_t) _njs_function(_function, 0, 0, _magic), \
+ .setter = NULL, \
+ }
-#define njs_prop_handler(_handler) { \
- .data = { \
- .type = NJS_INVALID, \
- .truth = 1, \
- .u = { .prop_handler = _handler } \
- } \
-}
+#define njs_accessor(_getter, _m1, _setter, _m2) \
+ { \
+ .getter = & (njs_function_t) _njs_function(_getter, 0, 0, _m1), \
+ .setter = & (njs_function_t) _njs_function(_setter, 0, 0, _m2), \
+ }
+
+
+#define njs_native_ctor(_function, _args_count, _magic) \
+ _njs_function(_function, _args_count, 1, _magic)
#define njs_prop_handler2(_handler, _magic16, _magic32) { \
#endif
-#define njs_property_query_init(pq, _query, _own) \
- do { \
- (pq)->lhq.key.length = 0; \
- (pq)->lhq.key.start = NULL; \
- (pq)->lhq.value = NULL; \
- (pq)->own_whiteout = NULL; \
- (pq)->query = _query; \
- (pq)->shared = 0; \
- (pq)->own = _own; \
- (pq)->temp = 0; \
- } while (0)
-
void njs_value_retain(njs_value_t *value);
void njs_value_release(njs_vm_t *vm, njs_value_t *value);
njs_value_t *retval);
+njs_inline void
+njs_property_query_init(njs_property_query_t *pq, njs_prop_query_t query,
+ uint32_t hash, uint8_t own)
+{
+ pq->query = query;
+ pq->lhq.key_hash = hash;
+ pq->own = own;
+
+ if (query == NJS_PROPERTY_QUERY_SET) {
+ pq->lhq.value = NULL;
+ pq->own_whiteout = NULL;
+ pq->temp = 0;
+ }
+}
+
+
njs_inline njs_int_t
njs_value_property_i64(njs_vm_t *vm, njs_value_t *value, int64_t index,
njs_value_t *retval)
uint16_t
njs_vm_prop_magic16(njs_object_prop_t *prop)
{
- return prop->value.data.magic16;
+ return njs_prop_magic16(prop);
}
uint32_t
njs_vm_prop_magic32(njs_object_prop_t *prop)
{
- return prop->value.data.magic32;
+ return njs_prop_magic32(prop);
}
#define NJS_MAX_STACK_SIZE (256 * 1024)
-/*
- * NJS_PROPERTY_QUERY_GET must be less to NJS_PROPERTY_QUERY_SET
- * and NJS_PROPERTY_QUERY_DELETE.
- */
-#define NJS_PROPERTY_QUERY_GET 0
-#define NJS_PROPERTY_QUERY_SET 1
-#define NJS_PROPERTY_QUERY_DELETE 2
-
-
typedef struct njs_frame_s njs_frame_t;
typedef struct njs_native_frame_s njs_native_frame_t;
typedef struct njs_parser_s njs_parser_t;
}
ret = njs_object_prop_define(vm, value1, &name, function,
- accessor->type);
+ accessor->type, 0);
if (njs_slow_path(ret != NJS_OK)) {
goto error;
}
goto fail;
}
- ret = prop->value.data.u.prop_handler(vm, prop, value, init, &vm->retval);
+ ret = njs_prop_handler(prop)(vm, prop, value, init, &vm->retval);
if (njs_slow_path(ret != NJS_OK)) {
goto fail;
}
key = &primitive;
}
- njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0);
+ njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0, 0);
ret = njs_property_query(vm, &pq, value, key);
if (njs_slow_path(ret == NJS_ERROR)) {
"Object.values(o)"),
njs_str("1,3,2") },
+ { njs_str("var o = { a: 'A', get b() { this.c = 'C'; return 'B'; } };"
+ "Object.values(o).length"),
+ njs_str("2") },
+
{ njs_str("var o = {a:1, c:2}; Object.defineProperty(o, 'b', {});"
"Object.entries(o)"),
njs_str("a,1,c,2") },
"Object.entries(o)"),
njs_str("a,1,c,3,b,2") },
+ { njs_str("var o = { a: 'A', get b() { this.c = 'C'; return 'B'; } };"
+ "Object.entries(o).length"),
+ njs_str("2") },
+
{ njs_str("var o = {}; Object.defineProperty(o, 'a', {}); o.a = 1"),
njs_str("TypeError: Cannot assign to read-only property \"a\" of object") },
{ njs_str("var o = { get get() { return 'bar'; } }; o.get"),
njs_str("bar") },
+ { njs_str("var d = Object.getOwnPropertyDescriptor({ get a() { return 'bar'; } }, 'a');"
+ "d.hasOwnProperty('set')"),
+ njs_str("true") },
+
{ njs_str("var o = { get() { return 'bar'; } }; o.get()"),
njs_str("bar") },
{ njs_str("import x from ''"),
njs_str("SyntaxError: Cannot find module \"\" in 1") },
- { njs_str("import x from 'crypto'"),
- njs_str("undefined") },
-
- { njs_str("import x from 'crypto' 1"),
- njs_str("SyntaxError: Unexpected token \"1\" in 1") },
-
- { njs_str("if (1) {import x from 'crypto'}"),
- njs_str("SyntaxError: Illegal import statement in 1") },
-
{ njs_str("export"),
njs_str("SyntaxError: Illegal export statement in 1") },
static njs_unit_test_t njs_crypto_module_test[] =
{
+ { njs_str("import x from 'crypto'"),
+ njs_str("undefined") },
+
+ { njs_str("import x from 'crypto' 1"),
+ njs_str("SyntaxError: Unexpected token \"1\" in 1") },
+
+ { njs_str("if (1) {import x from 'crypto'}"),
+ njs_str("SyntaxError: Illegal import statement in 1") },
+
{ njs_str("var h = require('crypto').createHash('sha1');"
"[Object.prototype.toString.call(h), njs.dump(h),h]"),
njs_str("[object Hash],Hash {},[object Hash]") },
" at Math.max (native)\n"
" at main (:1)\n") },
+#ifdef NJS_TEST262
+ { njs_str("var ab = new ArrayBuffer(1);"
+ "$262.detachArrayBuffer(ab);"
+ "ab.byteLength"),
+ njs_str("TypeError: detached buffer\n"
+ " at ArrayBuffer.prototype.byteLength (native)\n"
+ " at main (:1)\n") },
+#endif
+
{ njs_str("Object.prototype()"),
njs_str("TypeError: (intermediate value)[\"prototype\"] is not a function\n"
" at main (:1)\n") },