]> git.kaiwu.me - njs.git/commitdiff
Refactored working with an object properties.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 25 Oct 2022 16:19:32 +0000 (09:19 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 25 Oct 2022 16:19:32 +0000 (09:19 -0700)
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.

32 files changed:
external/njs_fs_module.c
src/njs_array.c
src/njs_array_buffer.c
src/njs_async.c
src/njs_boolean.c
src/njs_buffer.c
src/njs_builtin.c
src/njs_date.c
src/njs_encoding.c
src/njs_error.c
src/njs_extern.c
src/njs_function.c
src/njs_iterator.c
src/njs_json.c
src/njs_main.h
src/njs_math.c
src/njs_number.c
src/njs_object.c
src/njs_object.h
src/njs_object_prop.c
src/njs_object_prop_declare.h [new file with mode: 0644]
src/njs_promise.c
src/njs_regexp.c
src/njs_string.c
src/njs_symbol.c
src/njs_typed_array.c
src/njs_value.c
src/njs_value.h
src/njs_vm.c
src/njs_vm.h
src/njs_vmcode.c
src/test/njs_unit_test.c

index 68549b27d9e0ac90b9832c571f3359c0559bdcf2..150016ef4047c0470132986147b764bd4e11533f 100644 (file)
@@ -3231,25 +3231,11 @@ njs_fs_dirent_constructor(njs_vm_t *vm, njs_value_t *args,
 
 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),
 };
 
 
@@ -3427,7 +3413,7 @@ njs_fs_stats_prop(njs_vm_t *vm, njs_object_prop_t *prop, njs_value_t *value,
         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_object_prop_t *prop, njs_value_t *value,
         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, int bytes, njs_value_t *buffer,
 
 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),
 };
 
 
@@ -3794,30 +3678,17 @@ njs_fs_promises(njs_vm_t *vm, njs_object_prop_t *prop, njs_value_t *value,
 
 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),
 };
 
 
index 6491c1da71155fe749143a735cd17823bf37b80e..8bd61c5cd5b9ad2266e138834480c1e1b2676e69 100644 (file)
@@ -159,7 +159,7 @@ njs_array_convert_to_slow_array(njs_vm_t *vm, njs_array_t *array)
                 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, njs_value_t *value, uint32_t length,
     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_value_t *value,
         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 *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -646,9 +620,9 @@ njs_array_length(njs_vm_t *vm,njs_object_prop_t *prop, njs_value_t *value,
     }
 
     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;
 }
@@ -2850,265 +2824,92 @@ njs_array_prototype_iterator_obj(njs_vm_t *vm, njs_value_t *args,
 
 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,
     },
@@ -3123,12 +2924,8 @@ const njs_object_init_t  njs_array_prototype_init = {
 
 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),
 };
 
 
index d5bd9b57a35ee4fa7fa13aebd43707dcd122c663..2155749d075c7a8c31d0f9e6a165ca158e89eda0 100644 (file)
@@ -141,44 +141,21 @@ njs_array_buffer_writable(njs_vm_t *vm, njs_array_buffer_t *buffer)
 
 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),
 };
 
 
@@ -265,39 +242,19 @@ njs_array_buffer_prototype_slice(njs_vm_t *vm, njs_value_t *args,
 
 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,
     },
 };
index a55a6b6a3ffb3146a2d04769f89308681ccab35e..1f918dfce234c7208096cabdd721f02da8d2d111 100644 (file)
@@ -167,18 +167,9 @@ njs_async_context_free(njs_vm_t *vm, njs_async_ctx_t *ctx)
 
 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_async_prototype_properties[] =
     {
         .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_function_type_init = {
 
 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),
 };
 
 
index 7b0cc5c952584e35129079ae1f1103116b855b7c..0d0cb5885eca56f9e20f5221872a454fc5bcccf2 100644 (file)
@@ -43,22 +43,18 @@ static const njs_object_prop_t  njs_boolean_constructor_properties[] =
     {
         .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 *vm, njs_value_t *args,
 
 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),
 };
 
 
index fcae9a38ae6168bf58663fb64ce58eb8ed21aa28..2a90686db6f9acc64227d30ff9eab21b72407b85 100644 (file)
@@ -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_buffer_prototype_properties[] =
     {
         .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),
 };
 
 
@@ -2812,97 +2499,29 @@ const njs_object_init_t  njs_buffer_prototype_init = {
 
 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),
 };
 
 
@@ -2922,19 +2541,12 @@ const njs_object_type_init_t  njs_buffer_type_init = {
 
 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),
 };
 
 
index 4821174e4e82ef5a90a5cdb574f9fce53007eaf4..6c0c7786573faadb74e2f3630fb10e689a818a19 100644 (file)
@@ -359,8 +359,8 @@ njs_builtin_traverse(njs_vm_t *vm, njs_traverse_t *traverse, void *data)
     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;
@@ -373,9 +373,18 @@ njs_builtin_traverse(njs_vm_t *vm, njs_traverse_t *traverse, void *data)
         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;
         }
@@ -608,11 +617,13 @@ njs_vm_expression_completions(njs_vm_t *vm, njs_str_t *expression)
 
         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);
@@ -1018,7 +1029,7 @@ njs_global_this_prop_handler(njs_vm_t *vm, njs_object_prop_t *prop,
     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)) {
@@ -1027,10 +1038,10 @@ njs_global_this_prop_handler(njs_vm_t *vm, njs_object_prop_t *prop,
     }
 
     if (setval != NULL) {
-        *value = *setval;
+        njs_value_assign(value, setval);
     }
 
-    *retval = *value;
+    njs_value_assign(retval, value);
 
     return NJS_OK;
 }
@@ -1044,10 +1055,10 @@ njs_global_this_object(njs_vm_t *vm, njs_object_prop_t *self,
     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;
@@ -1058,14 +1069,12 @@ njs_global_this_object(njs_vm_t *vm, njs_object_prop_t *self,
         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;
@@ -1090,14 +1099,14 @@ njs_top_level_object(njs_vm_t *vm, njs_object_prop_t *self,
     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)) {
@@ -1110,14 +1119,12 @@ njs_top_level_object(njs_vm_t *vm, njs_object_prop_t *self,
         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;
@@ -1142,14 +1149,14 @@ njs_top_level_constructor(njs_vm_t *vm, njs_object_prop_t *self,
     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);
     }
@@ -1159,14 +1166,12 @@ njs_top_level_constructor(njs_vm_t *vm, njs_object_prop_t *self,
         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;
@@ -1186,561 +1191,229 @@ static const njs_object_prop_t  njs_global_this_object_properties[] =
     {
         .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),
 };
 
 
@@ -1755,45 +1428,23 @@ static const njs_object_prop_t  njs_njs_object_properties[] =
     {
         .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),
 
 };
 
@@ -1834,7 +1485,7 @@ njs_process_object_argv(njs_vm_t *vm, njs_object_prop_t *pr,
         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;
@@ -1846,7 +1497,7 @@ njs_process_object_argv(njs_vm_t *vm, njs_object_prop_t *pr,
     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;
     }
 
@@ -1909,7 +1560,7 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlhsh_t *hash, char **environment)
 
         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;
@@ -1935,7 +1586,7 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlhsh_t *hash, char **environment)
 
             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);
             }
@@ -1969,7 +1620,7 @@ njs_process_object_env(njs_vm_t *vm, njs_object_prop_t *pr,
         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;
@@ -1981,7 +1632,7 @@ njs_process_object_env(njs_vm_t *vm, njs_object_prop_t *pr,
     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;
     }
 
@@ -2016,34 +1667,17 @@ static const njs_object_prop_t  njs_process_object_properties[] =
     {
         .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),
 };
 
 
@@ -2082,17 +1716,12 @@ static const njs_object_prop_t  njs_262_object_properties[] =
     {
         .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),
 };
 
 
index 88e793bc9bcee8c10ab125c4ea610541dc2d081b..e4772ce4308d38ad3386c240aef27e67a967eb1c 100644 (file)
@@ -1065,49 +1065,17 @@ njs_date_number_parse(int64_t *value, const u_char *p, const u_char *end,
 
 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),
 };
 
 
@@ -1440,403 +1408,171 @@ njs_date_prototype_to_json(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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)),
 };
 
 
index 2379bf168ef170811dcc986e5333392f4b6eb62d..e7371587e7c2a8c5945c27502b01d4479d790bc8 100644 (file)
@@ -235,35 +235,15 @@ njs_text_encoder_encode_into(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -275,25 +255,11 @@ const njs_object_init_t  njs_text_encoder_init = {
 
 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),
 };
 
 
@@ -604,39 +570,17 @@ njs_text_decoder_decode(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -648,25 +592,11 @@ const njs_object_init_t  njs_text_decoder_init = {
 
 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),
 };
 
 
index d3c2a93215204df78bf6b4ecc5a1c91d51e509f2..906dfd48467edcc9a07e30b3c404d0c1e71ab999 100644 (file)
@@ -128,12 +128,12 @@ njs_error_stack_new(njs_vm_t *vm, njs_object_t *error, njs_value_t *retval)
 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;
     }
 
@@ -141,40 +141,18 @@ njs_error_stack_attach(njs_vm_t *vm, njs_value_t *value)
         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);
 }
 
 
@@ -218,6 +196,7 @@ njs_error_alloc(njs_vm_t *vm, njs_object_type_t type, const njs_value_t *name,
     error->extensible = 1;
     error->fast_array = 0;
     error->error_data = 1;
+    error->stack_attached = 0;
     error->__proto__ = &vm->prototypes[type].object;
     error->slots = NULL;
 
@@ -349,25 +328,11 @@ njs_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -379,25 +344,11 @@ const njs_object_init_t  njs_error_constructor_init = {
 
 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),
 };
 
 
@@ -409,25 +360,11 @@ const njs_object_init_t  njs_eval_error_constructor_init = {
 
 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),
 };
 
 
@@ -439,25 +376,11 @@ const njs_object_init_t  njs_internal_error_constructor_init = {
 
 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),
 };
 
 
@@ -469,25 +392,11 @@ const njs_object_init_t  njs_range_error_constructor_init = {
 
 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),
 };
 
 
@@ -499,25 +408,11 @@ const njs_object_init_t  njs_reference_error_constructor_init = {
 
 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),
 };
 
 
@@ -529,25 +424,11 @@ const njs_object_init_t  njs_syntax_error_constructor_init = {
 
 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),
 };
 
 
@@ -559,25 +440,11 @@ const njs_object_init_t  njs_type_error_constructor_init = {
 
 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),
 };
 
 
@@ -589,25 +456,11 @@ const njs_object_init_t  njs_uri_error_constructor_init = {
 
 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),
 };
 
 
@@ -689,25 +542,12 @@ njs_memory_error_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
 
 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),
 };
 
 
@@ -852,45 +692,18 @@ njs_error_to_string(njs_vm_t *vm, njs_value_t *retval, const njs_value_t *error)
 
 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),
 };
 
 
@@ -911,29 +724,14 @@ const njs_object_type_init_t  njs_error_type_init = {
 
 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),
 };
 
 
@@ -974,29 +772,13 @@ njs_internal_error_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
 
 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),
 };
 
 
@@ -1025,29 +807,14 @@ const njs_object_type_init_t  njs_memory_error_type_init = {
 
 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),
 };
 
 
@@ -1068,29 +835,14 @@ const njs_object_type_init_t  njs_range_error_type_init = {
 
 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),
 };
 
 
@@ -1111,29 +863,14 @@ const njs_object_type_init_t  njs_reference_error_type_init = {
 
 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),
 };
 
 
@@ -1154,29 +891,14 @@ const njs_object_type_init_t  njs_syntax_error_type_init = {
 
 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),
 };
 
 
@@ -1197,29 +919,14 @@ const njs_object_type_init_t  njs_type_error_type_init = {
 
 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),
 };
 
 
@@ -1240,29 +947,14 @@ const njs_object_type_init_t  njs_uri_error_type_init = {
 
 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),
 };
 
 
index 5e9d0dd46c72c27098698c0648d6ce41e1abe7ab..39cb17f2f64aba2de790820a966b9a2bb49bc329 100644 (file)
@@ -82,18 +82,18 @@ njs_external_add(njs_vm_t *vm, njs_arr_t *protos,
             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;
@@ -103,7 +103,7 @@ njs_external_add(njs_vm_t *vm, njs_arr_t *protos,
                     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;
                 }
@@ -122,11 +122,11 @@ njs_external_add(njs_vm_t *vm, njs_arr_t *protos,
             }
 
             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;
@@ -184,7 +184,7 @@ njs_external_prop_handler(njs_vm_t *vm, njs_object_prop_t *self,
             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;
@@ -208,7 +208,7 @@ njs_external_prop_handler(njs_vm_t *vm, njs_object_prop_t *self,
 
     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;
index 62b4c7d3a2e691f13be2b023cb4ad77efdc48fe8..7a88e1d76023295e4240d7dfc9eb973545bc31f5 100644 (file)
@@ -85,8 +85,7 @@ njs_vm_function_alloc(njs_vm_t *vm, njs_function_native_t native)
 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);
 
@@ -100,18 +99,6 @@ njs_function_value_copy(njs_vm_t *vm, njs_value_t *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;
@@ -137,18 +124,20 @@ njs_function_name_set(njs_vm_t *vm, njs_function_t *function,
 
     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;
@@ -170,7 +159,7 @@ njs_function_name_set(njs_vm_t *vm, njs_function_t *function,
             }
 
         } else {
-            njs_value_assign(&prop->value, &njs_string_empty);
+            njs_value_assign(njs_prop_value(prop), &njs_string_empty);
         }
     }
 
@@ -217,6 +206,16 @@ njs_function_copy(njs_vm_t *vm, njs_function_t *function)
     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;
     }
@@ -238,14 +237,12 @@ njs_function_copy(njs_vm_t *vm, njs_function_t *function)
 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)) {
@@ -254,46 +251,20 @@ njs_function_arguments_object_init(njs_vm_t *vm, njs_native_frame_t *frame)
 
     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;
         }
     }
@@ -352,11 +323,10 @@ njs_function_prototype_thrower(njs_vm_t *vm, njs_value_t *args,
 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,
     },
 };
@@ -974,7 +944,7 @@ njs_function_property_prototype_set(njs_vm_t *vm, njs_lvlhsh_t *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");
@@ -1199,25 +1169,11 @@ fail:
 
 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),
 };
 
 
@@ -1522,68 +1478,34 @@ njs_function_prototype_bind(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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,
     },
@@ -1598,26 +1520,14 @@ const njs_object_init_t  njs_function_prototype_init = {
 
 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),
 };
 
 
@@ -1629,19 +1539,11 @@ const njs_object_init_t  njs_function_instance_init = {
 
 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),
 };
 
 
index 93096772a5eedf5439c634dedda932aefa193678..7ce0abf2152db141ebd9f4cdcdb3f0baad76b45f 100644 (file)
@@ -185,7 +185,7 @@ static const njs_object_prop_t  njs_iterator_prototype_properties[] =
     {
         .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,
     },
@@ -245,19 +245,19 @@ njs_array_iterator_prototype_next(njs_vm_t *vm, njs_value_t *args,
         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;
 }
@@ -265,19 +265,13 @@ njs_array_iterator_prototype_next(njs_vm_t *vm, njs_value_t *args,
 
 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,
     },
 };
index 803d3155299d22c7e567b77ed3f8c8056d941dfd..a8d314a9f55a71bc4bef9a72b6b7f54fcd591be5 100644 (file)
@@ -166,7 +166,7 @@ njs_vm_json_parse(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs)
 {
     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);
 }
@@ -282,7 +282,7 @@ njs_vm_json_stringify(njs_vm_t *vm, njs_value_t *args, njs_uint_t 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);
 }
@@ -1642,25 +1642,13 @@ static const njs_object_prop_t  njs_json_object_properties[] =
     {
         .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),
 };
 
 
@@ -2046,7 +2034,7 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_t *retval, njs_value_t *value,
             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++];
 
@@ -2096,25 +2084,25 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_t *retval, njs_value_t *value,
             }
         }
 
-        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 {
index 939f16e18f1364ee4534390218d65d21410e0a8e..b02a4311a1e697050dde4b1f7b809ba93ff57743 100644 (file)
@@ -49,6 +49,7 @@
 #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>
index 1b2dd300564d52ba39efbf4fea8db9b50fae4aca..3f9192306265b21c25e66cbd9592d2c8f3fde964 100644 (file)
@@ -379,345 +379,98 @@ static const njs_object_prop_t  njs_math_object_properties[] =
     {
         .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),
 };
 
 
index 14a7750e7bfaafc8ddda05e07a507b4ee9301867..7a892bc1b659fe957e4cfe34827ff41725478759 100644 (file)
@@ -437,121 +437,43 @@ njs_number_is_finite(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -960,61 +882,24 @@ njs_number_to_string_radix(njs_vm_t *vm, njs_value_t *string,
 
 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),
 };
 
 
index 580634f060926ef463e7b25c49bbce662d1a3b76..cc3bc02d78a1cb49210f279c0fecc08a92757a84 100644 (file)
@@ -877,7 +877,7 @@ njs_object_own_enumerate_object(njs_vm_t *vm, const njs_object_t *object,
     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;
@@ -967,7 +967,10 @@ njs_object_own_enumerate_object(njs_vm_t *vm, const njs_object_t *object,
             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;
                 }
@@ -996,7 +999,10 @@ njs_object_own_enumerate_object(njs_vm_t *vm, const njs_object_t *object,
                 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;
                     }
@@ -1031,7 +1037,12 @@ njs_object_own_enumerate_object(njs_vm_t *vm, const njs_object_t *object,
                 }
 
                 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);
 
@@ -1070,7 +1081,7 @@ njs_object_own_enumerate_object(njs_vm_t *vm, const njs_object_t *object,
                     }
 
                     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);
 
@@ -1177,7 +1188,7 @@ njs_object_traverse(njs_vm_t *vm, njs_object_t *object, void *ctx,
             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);
@@ -1197,11 +1208,14 @@ njs_object_traverse(njs_vm_t *vm, njs_object_t *object, void *ctx,
             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;
 
@@ -1266,7 +1280,7 @@ njs_object_define_property(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     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;
     }
@@ -1307,9 +1321,11 @@ njs_object_define_properties(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
     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;
@@ -1327,7 +1343,7 @@ njs_object_define_properties(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
         }
 
         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;
         }
@@ -1764,7 +1780,7 @@ njs_object_assign(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
         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)) {
@@ -1899,7 +1915,7 @@ njs_property_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
 
     /* 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;
@@ -1911,7 +1927,7 @@ njs_property_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *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");
@@ -1922,192 +1938,63 @@ njs_property_prototype_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
 
 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),
 };
 
 
@@ -2279,7 +2166,7 @@ njs_property_constructor_set(njs_vm_t *vm, njs_lvlhsh_t *hash,
 
     /* GC */
 
-    prop->value = *constructor;
+    njs_value_assign(njs_prop_value(prop), constructor);
     prop->enumerable = 0;
 
     lhq.value = prop;
@@ -2292,7 +2179,7 @@ njs_property_constructor_set(njs_vm_t *vm, njs_lvlhsh_t *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/replace failed");
@@ -2470,7 +2357,7 @@ njs_object_prototype_has_own_property(njs_vm_t *vm, njs_value_t *args,
         }
     }
 
-    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);
 
@@ -2517,7 +2404,7 @@ njs_object_prototype_prop_is_enumerable(njs_vm_t *vm, njs_value_t *args,
         }
     }
 
-    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);
 
@@ -2582,62 +2469,25 @@ njs_object_prototype_is_prototype_of(njs_vm_t *vm, njs_value_t *args,
 
 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),
 };
 
 
index 90cf923589f4d3f1ac4f8d5a6e96b7d1104819e9..9ff555e0cbfae9fb398705ddec88b1900033cc05 100644 (file)
@@ -9,10 +9,32 @@
 
 
 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 {
@@ -71,7 +93,8 @@ njs_int_t njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_object_length(njs_vm_t *vm, njs_value_t *value, 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,
@@ -79,7 +102,7 @@ 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);
@@ -91,7 +114,7 @@ njs_inline njs_bool_t
 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;
 
 }
@@ -100,8 +123,7 @@ njs_is_data_descriptor(njs_object_prop_t *prop)
 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;
 }
 
 
@@ -244,6 +266,32 @@ njs_key_string_get(njs_vm_t *vm, njs_value_t *key, njs_str_t *str)
 }
 
 
+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)
 {
index fadc944418edb24ada35f88d4f51acf861946734..d6e0c27f588d44f9e0089ec2a27a081ac38a4dd7 100644 (file)
@@ -22,20 +22,14 @@ njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name,
                         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;
     }
 
@@ -81,17 +75,16 @@ found:
     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);
 }
 
 
@@ -136,7 +129,7 @@ njs_object_property_add(njs_vm_t *vm, njs_value_t *object, njs_value_t *key,
  */
 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;
@@ -170,9 +163,12 @@ njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
 
 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;
     }
@@ -183,8 +179,7 @@ again:
         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;
@@ -192,17 +187,37 @@ again:
 
         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;
 
@@ -214,7 +229,7 @@ again:
 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;
@@ -233,12 +248,12 @@ set_prop:
         /* 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 {
@@ -246,8 +261,8 @@ set_prop:
                 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));
             }
         }
 
@@ -268,6 +283,28 @@ set_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;
@@ -288,6 +325,7 @@ set_prop:
 
     switch (prev->type) {
     case NJS_PROPERTY:
+    case NJS_ACCESSOR:
     case NJS_PROPERTY_HANDLER:
         break;
 
@@ -313,10 +351,11 @@ set_prop:
             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;
@@ -333,10 +372,11 @@ set_prop:
             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;
@@ -386,23 +426,18 @@ set_prop:
             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))
@@ -412,9 +447,9 @@ set_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;
             }
@@ -422,14 +457,14 @@ set_prop:
 
     } 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;
             }
@@ -438,12 +473,23 @@ set_prop:
 
 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;
                 }
@@ -456,7 +502,7 @@ done:
             } else {
 
                 prev->type = prop->type;
-                njs_value_assign(&prev->value, &prop->value);
+                njs_value_assign(njs_prop_value(prev), njs_prop_value(prop));
             }
 
         } else {
@@ -467,8 +513,8 @@ done:
 
                         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\"");
@@ -480,12 +526,12 @@ done:
                         }
 
                         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));
         }
     }
 
@@ -494,14 +540,6 @@ done:
      * 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;
     }
@@ -526,7 +564,8 @@ exception:
 
 
 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;
@@ -548,39 +587,43 @@ njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq)
     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:
@@ -594,7 +637,7 @@ njs_prop_private_copy(njs_vm_t *vm, njs_property_query_t *pq)
         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;
         }
@@ -616,6 +659,7 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
     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");
@@ -627,11 +671,12 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
 
     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;
     }
@@ -643,18 +688,13 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
         }
 
         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;
     }
@@ -666,32 +706,26 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
         }
 
         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;
     }
@@ -701,11 +735,16 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
         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;
     }
@@ -718,7 +757,6 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
     lhq.key_hash = NJS_CONFIGURABLE_HASH;
 
     ret = njs_object_property(vm, desc, &lhq, &value);
-
     if (njs_slow_path(ret == NJS_ERROR)) {
         return ret;
     }
@@ -727,10 +765,10 @@ njs_descriptor_prop(njs_vm_t *vm, njs_object_prop_t *prop,
         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;
@@ -759,7 +797,7 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
     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);
@@ -776,13 +814,14 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
 
         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;
             }
@@ -820,8 +859,8 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
         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;
         }
@@ -857,12 +896,16 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
         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);
@@ -874,12 +917,16 @@ njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
         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);
@@ -983,7 +1030,7 @@ njs_object_prop_init(njs_vm_t *vm, const njs_object_init_t* init,
     *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);
@@ -994,7 +1041,7 @@ njs_object_prop_init(njs_vm_t *vm, const njs_object_init_t* init,
 
     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;
     }
 
diff --git a/src/njs_object_prop_declare.h b/src/njs_object_prop_declare.h
new file mode 100644 (file)
index 0000000..ecc0801
--- /dev/null
@@ -0,0 +1,74 @@
+
+/*
+ * 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_ */
index 63ce4bea4d9242fa810aacf90ec161ba293fcf9f..91bb7d0f49095d799f941801600550393e99af90 100644 (file)
@@ -1825,84 +1825,31 @@ njs_promise_species(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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,
     },
 };
 
@@ -1915,44 +1862,22 @@ const njs_object_init_t  njs_promise_constructor_init = {
 
 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 44b48297e6490be007ffe021d8528f1e2476cd2b..3f82b4c324f229c47a6ebe04f2c44e745baf02a0 100644 (file)
@@ -1001,7 +1001,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_value_t *r, njs_utf8_t utf8,
         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);
@@ -1067,7 +1067,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_value_t *r, njs_utf8_t utf8,
             goto fail;
         }
 
-        njs_set_object(&prop->value, groups);
+        njs_set_object(&prop->u.value, groups);
 
         i = 0;
 
@@ -1752,25 +1752,11 @@ done:
 
 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),
 };
 
 
@@ -1782,112 +1768,36 @@ const njs_object_init_t  njs_regexp_constructor_init = {
 
 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,
     },
@@ -1895,7 +1805,7 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
     {
         .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,
     },
@@ -1904,12 +1814,8 @@ static const njs_object_prop_t  njs_regexp_prototype_properties[] =
 
 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),
 };
 
 
index 86755be07d971d41c02883f775087932eeaf66e8..1561831bbd26ea2d03c0bfb945d9c3e8c52d1976 100644 (file)
@@ -606,49 +606,17 @@ njs_string_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -4022,277 +3990,90 @@ njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value)
 
 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,
     },
@@ -4307,11 +4088,7 @@ const njs_object_init_t  njs_string_prototype_init = {
 
 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),
 };
 
 
index f2898b291d9fe61bda96e92d407f5e67077ce3e7..0b7e3e5a0882b9f99d7b995ad331778b7bf9093f 100644 (file)
@@ -231,120 +231,54 @@ njs_symbol_key_for(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
 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),
 };
 
 
@@ -418,51 +352,22 @@ static const njs_object_prop_t  njs_symbol_prototype_properties[] =
     {
         .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),
 };
 
 
index 9242159456ae780efdf385b8eb9802e0e37d395a..0124c431e073a74ac3c467c18bf96cefe4a878ed 100644 (file)
@@ -2201,52 +2201,24 @@ njs_typed_array_constructor_intrinsic(njs_vm_t *vm, njs_value_t *args,
 
 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),
 };
 
 
@@ -2259,276 +2231,104 @@ static const njs_object_init_t  njs_typed_array_constructor_init = {
 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,
     },
@@ -2633,25 +2433,11 @@ memory_error:
 
 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),
 };
 
 
@@ -2895,194 +2681,69 @@ static const njs_object_prop_t  njs_data_view_prototype_properties[] =
     {
         .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),
 };
 
 
@@ -3102,34 +2763,14 @@ const njs_object_type_init_t  njs_data_view_type_init = {
 
 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),
 };
 
 
@@ -3141,22 +2782,12 @@ static const njs_object_init_t  njs_typed_array_u8_constructor_init = {
 
 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),
 };
 
 
@@ -3180,31 +2811,16 @@ static const njs_object_prop_t  njs_typed_array_u8c_constructor_props[] =
     {
         .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),
 };
 
 
@@ -3216,22 +2832,12 @@ static const njs_object_init_t  njs_typed_array_u8c_constructor_init = {
 
 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),
 };
 
 
@@ -3252,34 +2858,14 @@ const njs_object_type_init_t  njs_typed_array_u8clamped_type_init = {
 
 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),
 };
 
 
@@ -3291,22 +2877,12 @@ static const njs_object_init_t  njs_typed_array_i8_constructor_init = {
 
 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),
 };
 
 
@@ -3327,34 +2903,14 @@ const njs_object_type_init_t  njs_typed_array_i8_type_init = {
 
 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),
 };
 
 
@@ -3366,22 +2922,12 @@ static const njs_object_init_t  njs_typed_array_u16_constructor_init = {
 
 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),
 };
 
 
@@ -3402,34 +2948,14 @@ const njs_object_type_init_t  njs_typed_array_u16_type_init = {
 
 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),
 };
 
 
@@ -3441,22 +2967,12 @@ static const njs_object_init_t  njs_typed_array_i16_constructor_init = {
 
 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),
 };
 
 
@@ -3477,34 +2993,14 @@ const njs_object_type_init_t  njs_typed_array_i16_type_init = {
 
 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),
 };
 
 
@@ -3516,22 +3012,12 @@ static const njs_object_init_t  njs_typed_array_u32_constructor_init = {
 
 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),
 };
 
 
@@ -3552,34 +3038,14 @@ const njs_object_type_init_t  njs_typed_array_u32_type_init = {
 
 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),
 };
 
 
@@ -3591,22 +3057,12 @@ static const njs_object_init_t  njs_typed_array_i32_constructor_init = {
 
 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),
 };
 
 
@@ -3627,34 +3083,14 @@ const njs_object_type_init_t  njs_typed_array_i32_type_init = {
 
 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),
 };
 
 
@@ -3666,22 +3102,12 @@ static const njs_object_init_t  njs_typed_array_f32_constructor_init = {
 
 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),
 };
 
 
@@ -3702,34 +3128,14 @@ const njs_object_type_init_t  njs_typed_array_f32_type_init = {
 
 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),
 };
 
 
@@ -3741,22 +3147,12 @@ static const njs_object_init_t  njs_typed_array_f64_constructor_init = {
 
 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),
 };
 
 
index 74a08b9431073d373a25a7d7cd7b77bae54d17f6..48cf9ed331a4cd5baa39c4eace745555e9baf073 100644 (file)
@@ -609,8 +609,11 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
 
         } 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);
@@ -645,56 +648,52 @@ njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
     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);
@@ -714,7 +713,7 @@ njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq,
             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);
             }
         }
 
@@ -825,11 +824,11 @@ prop:
             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;
     }
 
@@ -863,12 +862,13 @@ njs_typed_array_property_query(njs_vm_t *vm, njs_property_query_t *pq,
     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;
     }
 
@@ -901,7 +901,7 @@ njs_string_property_query(njs_vm_t *vm, njs_property_query_t *pq,
          * 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;
@@ -946,11 +946,9 @@ njs_external_property_query(njs_vm_t *vm, njs_property_query_t *pq,
      *   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;
@@ -962,7 +960,7 @@ njs_external_property_query(njs_vm_t *vm, njs_property_query_t *pq,
     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) {
@@ -980,7 +978,7 @@ njs_external_property_query(njs_vm_t *vm, njs_property_query_t *pq,
     }
 
     prop->type = NJS_PROPERTY_HANDLER;
-    prop->value.data.u.prop_handler = slots->prop_handler;
+    njs_prop_handler(prop) = slots->prop_handler;
 
     return NJS_OK;
 }
@@ -1042,14 +1040,14 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
             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);
 
@@ -1059,36 +1057,36 @@ slow_path:
         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;
 
@@ -1166,7 +1164,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
             goto slow_path;
         }
 
-        array->start[index] = *setval;
+        njs_value_assign(&array->start[index], setval);
 
         return NJS_OK;
     }
@@ -1179,7 +1177,7 @@ slow_path:
         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);
 
@@ -1198,8 +1196,8 @@ slow_path:
             }
 
         } 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);
             }
 
@@ -1211,8 +1209,7 @@ slow_path:
         }
 
         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;
             }
@@ -1232,14 +1229,14 @@ slow_path:
                 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\" "
@@ -1309,7 +1306,7 @@ slow_path:
 
 found:
 
-    prop->value = *setval;
+    njs_value_assign(njs_prop_value(prop), setval);
 
     return NJS_OK;
 
@@ -1341,7 +1338,7 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
         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)) {
@@ -1364,7 +1361,7 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
     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;
             }
@@ -1373,24 +1370,26 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
         /* 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:
@@ -1401,11 +1400,11 @@ njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
 
     /* 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;
 }
index c41fb798481ef0ba65138c16ae9760bea551b9c6..9003853bf6723f4d0b0880b19dc1bfe2d1c00150 100644 (file)
@@ -198,6 +198,7 @@ struct njs_object_s {
 
     uint8_t                           extensible:1;
     uint8_t                           error_data:1;
+    uint8_t                           stack_attached:1;
     uint8_t                           fast_array:1;
 };
 
@@ -327,6 +328,7 @@ typedef enum {
 
 typedef enum {
     NJS_PROPERTY = 0,
+    NJS_ACCESSOR,
     NJS_PROPERTY_REF,
     NJS_PROPERTY_TYPED_ARRAY_REF,
     NJS_PROPERTY_HANDLER,
@@ -334,6 +336,13 @@ typedef enum {
 } 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:
@@ -349,13 +358,26 @@ typedef enum {
 
 
 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 */
@@ -367,14 +389,14 @@ struct njs_object_prop_s {
 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;
@@ -454,17 +476,22 @@ typedef struct {
     _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) {                     \
@@ -1028,18 +1055,6 @@ njs_set_object_value(njs_value_t *value, njs_object_value_t *object_value)
 #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);
@@ -1082,6 +1097,22 @@ njs_int_t njs_value_method(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
     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)
index 2cae37220b37d3c561416109b3157e31a4e8ed01..7480b57e15bc338abbeafc6d0a0c3596d596c381 100644 (file)
@@ -833,14 +833,14 @@ njs_vm_function(njs_vm_t *vm, const njs_str_t *path)
 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);
 }
 
 
index 3758c2afa8c305585c28dd5f1182be407f9d9c67..da53711665f6f4ad4d3236e3bf86efe79b111b42 100644 (file)
 #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;
index 033177f450891212bebc31e1f75cb5fafdae4a3c..4fd13249c02ad238f04c139b4a7857ba8dece1f1 100644 (file)
@@ -1331,7 +1331,7 @@ NEXT_LBL;
         }
 
         ret = njs_object_prop_define(vm, value1, &name, function,
-                                     accessor->type);
+                                     accessor->type, 0);
         if (njs_slow_path(ret != NJS_OK)) {
             goto error;
         }
@@ -2196,7 +2196,7 @@ njs_vmcode_proto_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *unused,
         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;
     }
@@ -2232,7 +2232,7 @@ njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *value, njs_value_t *key)
         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)) {
index 35614708a2ebdbeeef60b0d06f87259c76560619..b5fc0616eb6e9b4821322e942d5c7a1860d2f7fa 100644 (file)
@@ -13965,6 +13965,10 @@ static njs_unit_test_t  njs_test[] =
                  "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") },
@@ -13979,6 +13983,10 @@ static njs_unit_test_t  njs_test[] =
                  "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") },
 
@@ -14572,6 +14580,10 @@ static njs_unit_test_t  njs_test[] =
     { 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") },
 
@@ -18381,15 +18393,6 @@ static njs_unit_test_t  njs_test[] =
     { 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") },
 
@@ -19735,6 +19738,15 @@ static njs_unit_test_t  njs_fs_module_test[] =
 
 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]") },
@@ -22198,6 +22210,15 @@ static njs_unit_test_t  njs_backtraces_test[] =
               "    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") },