[njs] Refactored working with an object properties.
Dmitry Volyntsev
xeioex at nginx.com
Tue Oct 25 17:03:40 UTC 2022
details: https://hg.nginx.org/njs/rev/109e6cb4dea5
branches:
changeset: 1986:109e6cb4dea5
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Oct 25 09:19:32 2022 -0700
description:
Refactored working with an object properties.
1) njs_object_prop_t is compacted from 72 to 40 bytes on 64bit
platforms.
2) njs_object_prop_define() is revorked to accomodate fast
property creation using njs_value_create_data_prop()
which corresponds to CreateDataProperty() from the specs.
diffstat:
external/njs_fs_module.c | 241 +------
src/njs_array.c | 401 +++----------
src/njs_array_buffer.c | 77 +--
src/njs_async.c | 40 +-
src/njs_boolean.c | 47 +-
src/njs_buffer.c | 738 ++++++-------------------
src/njs_builtin.c | 769 ++++++-------------------
src/njs_date.c | 522 ++++-------------
src/njs_encoding.c | 110 +---
src/njs_error.c | 508 +++--------------
src/njs_extern.c | 28 +-
src/njs_function.c | 232 ++-----
src/njs_iterator.c | 22 +-
src/njs_json.c | 38 +-
src/njs_main.h | 1 +
src/njs_math.c | 383 ++----------
src/njs_number.c | 185 +-----
src/njs_object.c | 372 +++---------
src/njs_object.h | 66 +-
src/njs_object_prop.c | 269 +++++---
src/njs_object_prop_declare.h | 74 ++
src/njs_promise.c | 123 +---
src/njs_regexp.c | 144 +----
src/njs_string.c | 407 +++----------
src/njs_symbol.c | 183 +----
src/njs_typed_array.c | 1180 ++++++++++------------------------------
src/njs_value.c | 173 ++---
src/njs_value.h | 89 ++-
src/njs_vm.c | 4 +-
src/njs_vm.h | 9 -
src/njs_vmcode.c | 6 +-
src/test/njs_unit_test.c | 39 +-
32 files changed, 2076 insertions(+), 5404 deletions(-)
diffs (truncated from 9903 to 1000 lines):
diff -r 96a0be3dfb0b -r 109e6cb4dea5 external/njs_fs_module.c
--- a/external/njs_fs_module.c Tue Oct 25 09:19:14 2022 -0700
+++ b/external/njs_fs_module.c Tue Oct 25 09:19:32 2022 -0700
@@ -3231,25 +3231,11 @@ njs_fs_dirent_constructor(njs_vm_t *vm,
static const njs_object_prop_t njs_dirent_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Dirent"),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 2.0),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
+ NJS_DECLARE_PROP_NAME("Dirent"),
+
+ NJS_DECLARE_PROP_LENGTH(2),
+
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
};
@@ -3427,7 +3413,7 @@ njs_fs_stats_prop(njs_vm_t *vm, njs_obje
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;
@@ -3486,7 +3472,7 @@ njs_fs_stats_prop(njs_vm_t *vm, njs_obje
break;
}
- switch (prop->value.data.magic32 >> 4) {
+ switch (njs_prop_magic32(prop) >> 4) {
case NJS_NUMBER:
njs_set_number(retval, v);
break;
@@ -3635,146 +3621,44 @@ njs_fs_bytes_written_create(njs_vm_t *vm
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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readSync"),
- .value = njs_native_function2(njs_fs_read, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("access"),
- .value = njs_native_function2(njs_fs_access, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("mkdir"),
- .value = njs_native_function2(njs_fs_mkdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("open"),
- .value = njs_native_function2(njs_fs_open, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("close"),
- .value = njs_native_function2(njs_fs_close, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("rename"),
- .value = njs_native_function2(njs_fs_rename, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("rmdir"),
- .value = njs_native_function2(njs_fs_rmdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("readdir"),
- .value = njs_native_function2(njs_fs_readdir, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("symlink"),
- .value = njs_native_function2(njs_fs_symlink, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("unlink"),
- .value = njs_native_function2(njs_fs_unlink, 0, NJS_FS_PROMISE),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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("readFile", njs_fs_read_file, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("readSync", njs_fs_read, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("appendFile", njs_fs_write_file, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_APPEND)),
+
+ NJS_DECLARE_PROP_NATIVE("writeFile", njs_fs_write_file, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_TRUNC)),
+
+ NJS_DECLARE_PROP_NATIVE("access", njs_fs_access, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("mkdir", njs_fs_mkdir, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("open", njs_fs_open, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("close", njs_fs_close, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("rename", njs_fs_rename, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("rmdir", njs_fs_rmdir, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("readdir", njs_fs_readdir, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("fstat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_FSTAT)),
+
+ NJS_DECLARE_PROP_NATIVE("lstat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_LSTAT)),
+
+ NJS_DECLARE_PROP_NATIVE("stat", njs_fs_stat, 0,
+ njs_fs_magic(NJS_FS_PROMISE, NJS_FS_STAT)),
+
+ NJS_DECLARE_PROP_NATIVE("symlink", njs_fs_symlink, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("unlink", njs_fs_unlink, 0, NJS_FS_PROMISE),
+
+ NJS_DECLARE_PROP_NATIVE("realpath", njs_fs_realpath, 0, NJS_FS_PROMISE),
};
@@ -3794,30 +3678,17 @@ njs_fs_promises(njs_vm_t *vm, njs_object
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),
};
diff -r 96a0be3dfb0b -r 109e6cb4dea5 src/njs_array.c
--- a/src/njs_array.c Tue Oct 25 09:19:14 2022 -0700
+++ b/src/njs_array.c Tue Oct 25 09:19:32 2022 -0700
@@ -159,7 +159,7 @@ njs_array_convert_to_slow_array(njs_vm_t
return NJS_ERROR;
}
- prop->value = array->start[i];
+ njs_value_assign(njs_prop_value(prop), &array->start[i]);
}
}
@@ -197,7 +197,7 @@ njs_array_length_redefine(njs_vm_t *vm,
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;
}
@@ -224,7 +224,7 @@ njs_array_length_set(njs_vm_t *vm, njs_v
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;
}
@@ -523,41 +523,15 @@ njs_array_of(njs_vm_t *vm, njs_value_t *
static const njs_object_prop_t njs_array_constructor_properties[] =
{
- {
- .type = NJS_PROPERTY,
- .name = njs_string("name"),
- .value = njs_string("Array"),
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .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),
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("isArray"),
- .value = njs_native_function(njs_array_is_array, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("of"),
- .value = njs_native_function(njs_array_of, 0),
- .writable = 1,
- .configurable = 1,
- },
+ NJS_DECLARE_PROP_NAME("Array"),
+
+ NJS_DECLARE_PROP_LENGTH(1),
+
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("isArray", njs_array_is_array, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("of", njs_array_of, 0, 0),
};
@@ -646,9 +620,9 @@ njs_array_length(njs_vm_t *vm,njs_object
}
prop->type = NJS_PROPERTY;
- njs_set_number(&prop->value, length);
-
- *retval = *setval;
+ njs_set_number(njs_prop_value(prop), length);
+
+ njs_value_assign(retval, setval);
return NJS_OK;
}
@@ -2850,265 +2824,92 @@ njs_array_prototype_iterator_obj(njs_vm_
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,
- },
-
- {
- .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("concat"),
- .value = njs_native_function(njs_array_prototype_concat, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("copyWithin"),
- .value = njs_native_function(njs_array_prototype_copy_within, 2),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("entries"),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_BOTH),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("fill"),
- .value = njs_native_function(njs_array_prototype_fill, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("join"),
- .value = njs_native_function(njs_array_prototype_join, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("keys"),
- .value = njs_native_function2(njs_array_prototype_iterator_obj, 0,
- NJS_ENUM_KEYS),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("pop"),
- .value = njs_native_function(njs_array_prototype_pop, 0),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("push"),
- .value = njs_native_function(njs_array_prototype_push, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("reverse"),
- .value = njs_native_function(njs_array_prototype_reverse, 0),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("shift"),
- .value = njs_native_function(njs_array_prototype_shift, 0),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("slice"),
- .value = njs_native_function(njs_array_prototype_slice, 2),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("sort"),
- .value = njs_native_function(njs_array_prototype_sort, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("splice"),
- .value = njs_native_function(njs_array_prototype_splice, 2),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("toString"),
- .value = njs_native_function(njs_array_prototype_to_string, 0),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .type = NJS_PROPERTY,
- .name = njs_string("unshift"),
- .value = njs_native_function(njs_array_prototype_unshift, 1),
- .writable = 1,
- .configurable = 1,
- },
-
- {
- .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_HANDLER("length", njs_array_length, 0, 0,
+ NJS_OBJECT_PROP_VALUE_W),
+
+ NJS_DECLARE_PROP_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
+
+ NJS_DECLARE_PROP_NATIVE("concat", njs_array_prototype_concat, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("copyWithin", njs_array_prototype_copy_within, 2,
+ 0),
+
+ NJS_DECLARE_PROP_NATIVE("entries", njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_BOTH),
+
+ NJS_DECLARE_PROP_NATIVE("every", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_EVERY)),
+
+ NJS_DECLARE_PROP_NATIVE("fill", njs_array_prototype_fill, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("filter", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FILTER)),
+
+ NJS_DECLARE_PROP_NATIVE("find", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FIND)),
+
+ NJS_DECLARE_PROP_NATIVE("findIndex", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FIND_INDEX)),
+
+ NJS_DECLARE_PROP_NATIVE("forEach", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_FOR_EACH)),
+
+ NJS_DECLARE_PROP_NATIVE("includes", njs_array_prototype_iterator, 1,
+ njs_array_arg(NJS_ARRAY_INCLUDES)),
+
+ NJS_DECLARE_PROP_NATIVE("indexOf", njs_array_prototype_iterator, 1,
+ njs_array_arg(NJS_ARRAY_INDEX_OF)),
+
+ NJS_DECLARE_PROP_NATIVE("join", njs_array_prototype_join, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("keys", njs_array_prototype_iterator_obj, 0,
+ NJS_ENUM_KEYS),
+
+ NJS_DECLARE_PROP_NATIVE("lastIndexOf",
+ njs_array_prototype_reverse_iterator, 1,
+ NJS_ARRAY_LAST_INDEX_OF),
+
+ NJS_DECLARE_PROP_NATIVE("map", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_MAP)),
+
+ NJS_DECLARE_PROP_NATIVE("pop", njs_array_prototype_pop, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("push", njs_array_prototype_push, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("reduce", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_REDUCE)),
+
+ NJS_DECLARE_PROP_NATIVE("reduceRight",
+ njs_array_prototype_reverse_iterator, 1,
+ njs_array_func(NJS_ARRAY_REDUCE_RIGHT)),
+
+ NJS_DECLARE_PROP_NATIVE("reverse", njs_array_prototype_reverse, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("shift", njs_array_prototype_shift, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("slice", njs_array_prototype_slice, 2, 0),
+
+ NJS_DECLARE_PROP_NATIVE("some", njs_array_prototype_iterator, 1,
+ njs_array_func(NJS_ARRAY_SOME)),
+
+ NJS_DECLARE_PROP_NATIVE("sort", njs_array_prototype_sort, 1, 0),
+
+ NJS_DECLARE_PROP_NATIVE("splice", njs_array_prototype_splice, 2, 0),
+
+ NJS_DECLARE_PROP_NATIVE("toString", njs_array_prototype_to_string, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("unshift", njs_array_prototype_unshift, 1, 0),
+
+ 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,
},
@@ -3123,12 +2924,8 @@ const njs_object_init_t njs_array_proto
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),
};
diff -r 96a0be3dfb0b -r 109e6cb4dea5 src/njs_array_buffer.c
--- a/src/njs_array_buffer.c Tue Oct 25 09:19:14 2022 -0700
+++ b/src/njs_array_buffer.c Tue Oct 25 09:19:32 2022 -0700
@@ -141,44 +141,21 @@ njs_array_buffer_writable(njs_vm_t *vm,
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"),
+
+ NJS_DECLARE_PROP_LENGTH(1),
+
+ NJS_DECLARE_PROP_HANDLER("prototype", njs_object_prototype_create, 0, 0, 0),
{
- .type = NJS_PROPERTY,
- .name = njs_string("length"),
- .value = njs_value(NJS_NUMBER, 1, 1.0),
+ .type = NJS_ACCESSOR,
+ .name = njs_wellknown_symbol(NJS_SYMBOL_SPECIES),
+ .u.accessor = njs_getter(njs_array_buffer_get_this, 0),
+ .writable = NJS_ATTRIBUTE_UNSET,
.configurable = 1,
},
- {
- .type = NJS_PROPERTY_HANDLER,
- .name = njs_string("prototype"),
- .value = njs_prop_handler(njs_object_prototype_create),
- },
-
- {
- .type = NJS_PROPERTY,
- .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),
- .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),
};
@@ -265,39 +242,19 @@ njs_array_buffer_prototype_slice(njs_vm_
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,
},
};
diff -r 96a0be3dfb0b -r 109e6cb4dea5 src/njs_async.c
--- a/src/njs_async.c Tue Oct 25 09:19:14 2022 -0700
+++ b/src/njs_async.c Tue Oct 25 09:19:32 2022 -0700
@@ -167,18 +167,9 @@ njs_async_context_free(njs_vm_t *vm, njs
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),
};
@@ -193,16 +184,13 @@ static const njs_object_prop_t njs_asyn
{
.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),
};
@@ -222,19 +210,11 @@ const njs_object_type_init_t njs_async_
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),
};
diff -r 96a0be3dfb0b -r 109e6cb4dea5 src/njs_boolean.c
--- a/src/njs_boolean.c Tue Oct 25 09:19:14 2022 -0700
+++ b/src/njs_boolean.c Tue Oct 25 09:19:32 2022 -0700
@@ -43,22 +43,18 @@ static const njs_object_prop_t njs_bool
{
.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),
};
@@ -122,37 +118,16 @@ njs_boolean_prototype_to_string(njs_vm_t
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,
- },
-
- {
- .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("__proto__", njs_primitive_prototype_get_proto,
+ 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_HANDLER("constructor",
+ njs_object_prototype_create_constructor,
+ 0, 0, NJS_OBJECT_PROP_VALUE_CW),
- {
- .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("valueOf", njs_boolean_prototype_value_of, 0, 0),
+
+ NJS_DECLARE_PROP_NATIVE("toString", njs_boolean_prototype_to_string, 0, 0),
};
diff -r 96a0be3dfb0b -r 109e6cb4dea5 src/njs_buffer.c
--- a/src/njs_buffer.c Tue Oct 25 09:19:14 2022 -0700
+++ b/src/njs_buffer.c Tue Oct 25 09:19:32 2022 -0700
@@ -310,7 +310,7 @@ next:
&& !(njs_is_object(&retval)
&& njs_object(&retval) == njs_object(value)))
{
- *value = retval;
+ njs_value_assign(value, &retval);
goto next;
}
@@ -2340,467 +2340,154 @@ static const njs_object_prop_t njs_buff
{
.type = NJS_PROPERTY,
More information about the nginx-devel
mailing list