[njs] Refactored object type initialization.

Dmitry Volyntsev xeioex at nginx.com
Thu Oct 31 15:18:04 UTC 2019


details:   https://hg.nginx.org/njs/rev/5abe92b2cfd0
branches:  
changeset: 1214:5abe92b2cfd0
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Oct 31 18:17:33 2019 +0300
description:
Refactored object type initialization.

diffstat:

 src/njs_array.c    |   10 +-
 src/njs_array.h    |    6 +-
 src/njs_boolean.c  |   11 +-
 src/njs_boolean.h  |    6 +-
 src/njs_builtin.c  |  288 +++++++++-------------------------------------------
 src/njs_builtin.h  |   17 ---
 src/njs_crypto.c   |   22 +++-
 src/njs_crypto.h   |   12 +-
 src/njs_date.c     |   10 +-
 src/njs_date.h     |    6 +-
 src/njs_error.c    |   90 ++++++++++++++-
 src/njs_error.h    |   46 +------
 src/njs_fs.h       |    1 +
 src/njs_function.c |   35 ++---
 src/njs_function.h |   13 +-
 src/njs_main.h     |    1 -
 src/njs_number.c   |   32 +----
 src/njs_number.h   |    5 +-
 src/njs_object.c   |   10 +-
 src/njs_object.h   |    5 +-
 src/njs_regexp.c   |   10 +-
 src/njs_regexp.h   |    6 +-
 src/njs_string.c   |   11 +-
 src/njs_string.h   |    5 +-
 src/njs_value.h    |    8 +
 src/njs_vm.h       |    2 +
 26 files changed, 265 insertions(+), 403 deletions(-)

diffs (truncated from 1251 to 1000 lines):

diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_array.c
--- a/src/njs_array.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_array.c	Thu Oct 31 18:17:33 2019 +0300
@@ -177,7 +177,7 @@ memory_error:
 }
 
 
-njs_int_t
+static njs_int_t
 njs_array_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -3006,3 +3006,11 @@ const njs_object_init_t  njs_array_insta
     njs_array_instance_properties,
     njs_nitems(njs_array_instance_properties),
 };
+
+
+const njs_object_type_init_t  njs_array_type_init = {
+    .constructor = njs_array_constructor,
+    .prototype_props = &njs_array_prototype_init,
+    .constructor_props = &njs_array_constructor_init,
+    .value = { .object = { .type = NJS_ARRAY } },
+};
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_array.h
--- a/src/njs_array.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_array.h	Thu Oct 31 18:17:33 2019 +0300
@@ -21,12 +21,10 @@ njs_int_t njs_array_string_add(njs_vm_t 
     const u_char *start, size_t size, size_t length);
 njs_int_t njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend,
     uint32_t append);
-njs_int_t njs_array_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
+
 
-extern const njs_object_init_t  njs_array_constructor_init;
-extern const njs_object_init_t  njs_array_prototype_init;
 extern const njs_object_init_t  njs_array_instance_init;
+extern const njs_object_type_init_t  njs_array_type_init;
 
 
 #endif /* _NJS_ARRAY_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_boolean.c
--- a/src/njs_boolean.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_boolean.c	Thu Oct 31 18:17:33 2019 +0300
@@ -8,7 +8,7 @@
 #include <njs_main.h>
 
 
-njs_int_t
+static njs_int_t
 njs_boolean_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -163,3 +163,12 @@ const njs_object_init_t  njs_boolean_pro
     njs_boolean_prototype_properties,
     njs_nitems(njs_boolean_prototype_properties),
 };
+
+
+const njs_object_type_init_t  njs_boolean_type_init = {
+   .constructor = njs_boolean_constructor,
+   .prototype_props = &njs_boolean_prototype_init,
+   .constructor_props = &njs_boolean_constructor_init,
+   .value = { .object_value = { .value = njs_value(NJS_BOOLEAN, 0, 0.0),
+                                .object = { .type = NJS_OBJECT_BOOLEAN } } },
+};
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_boolean.h
--- a/src/njs_boolean.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_boolean.h	Thu Oct 31 18:17:33 2019 +0300
@@ -8,11 +8,7 @@
 #define _NJS_BOOLEAN_H_INCLUDED_
 
 
-njs_int_t njs_boolean_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-
-extern const njs_object_init_t  njs_boolean_constructor_init;
-extern const njs_object_init_t  njs_boolean_prototype_init;
+extern const njs_object_type_init_t  njs_boolean_type_init;
 
 
 #endif /* _NJS_BOOLEAN_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_builtin.c
--- a/src/njs_builtin.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_builtin.c	Thu Oct 31 18:17:33 2019 +0300
@@ -10,11 +10,6 @@
 
 
 typedef struct {
-    njs_function_native_t  native;
-} njs_function_init_t;
-
-
-typedef struct {
     enum {
        NJS_BUILTIN_TRAVERSE_KEYS,
        NJS_BUILTIN_TRAVERSE_MATCH,
@@ -27,8 +22,6 @@ typedef struct {
 } njs_builtin_traverse_t;
 
 
-static njs_int_t njs_prototype_function(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
 static njs_arr_t *njs_vm_expression_completions(njs_vm_t *vm,
     njs_str_t *expression);
 static njs_arr_t *njs_object_completions(njs_vm_t *vm, njs_object_t *object);
@@ -36,12 +29,12 @@ static njs_int_t njs_env_hash_init(njs_v
     char **environment);
 
 
-const njs_object_init_t  njs_global_this_init;
-const njs_object_init_t  njs_njs_object_init;
-const njs_object_init_t  njs_process_object_init;
+static const njs_object_init_t  njs_global_this_init;
+static const njs_object_init_t  njs_njs_object_init;
+static const njs_object_init_t  njs_process_object_init;
 
 
-const njs_object_init_t  *njs_object_init[] = {
+static const njs_object_init_t  *njs_object_init[] = {
     &njs_global_this_init,
     &njs_njs_object_init,
     &njs_process_object_init,
@@ -51,129 +44,43 @@ const njs_object_init_t  *njs_object_ini
 };
 
 
-const njs_object_init_t  *njs_module_init[] = {
+static const njs_object_init_t  *njs_module_init[] = {
     &njs_fs_object_init,
     &njs_crypto_object_init,
     NULL
 };
 
 
-const njs_object_init_t  *njs_prototype_init[] = {
-    &njs_object_prototype_init,
-    &njs_array_prototype_init,
-    &njs_boolean_prototype_init,
-    &njs_number_prototype_init,
-    &njs_string_prototype_init,
-    &njs_function_prototype_init,
-    &njs_regexp_prototype_init,
-    &njs_date_prototype_init,
-    &njs_hash_prototype_init,
-    &njs_hmac_prototype_init,
-    &njs_error_prototype_init,
-    &njs_eval_error_prototype_init,
-    &njs_internal_error_prototype_init,
-    &njs_range_error_prototype_init,
-    &njs_reference_error_prototype_init,
-    &njs_syntax_error_prototype_init,
-    &njs_type_error_prototype_init,
-    &njs_uri_error_prototype_init,
-    &njs_internal_error_prototype_init,
-    NULL
-};
-
+static const njs_object_type_init_t *const
+    njs_object_type_init[NJS_OBJ_TYPE_MAX] =
+{
+    /* Global types. */
 
-const njs_object_init_t  *njs_constructor_init[] = {
-    &njs_object_constructor_init,
-    &njs_array_constructor_init,
-    &njs_boolean_constructor_init,
-    &njs_number_constructor_init,
-    &njs_string_constructor_init,
-    &njs_function_constructor_init,
-    &njs_regexp_constructor_init,
-    &njs_date_constructor_init,
-    &njs_hash_constructor_init,
-    &njs_hmac_constructor_init,
-    &njs_error_constructor_init,
-    &njs_eval_error_constructor_init,
-    &njs_internal_error_constructor_init,
-    &njs_range_error_constructor_init,
-    &njs_reference_error_constructor_init,
-    &njs_syntax_error_constructor_init,
-    &njs_type_error_constructor_init,
-    &njs_uri_error_constructor_init,
-    &njs_memory_error_constructor_init,
-    NULL
-};
-
+    &njs_obj_type_init,
+    &njs_array_type_init,
+    &njs_boolean_type_init,
+    &njs_number_type_init,
+    &njs_string_type_init,
+    &njs_function_type_init,
+    &njs_regexp_type_init,
+    &njs_date_type_init,
 
-const njs_function_init_t  njs_native_constructors[] = {
-    /* SunC does not allow empty array initialization. */
-    { njs_object_constructor },
-    { njs_array_constructor },
-    { njs_boolean_constructor },
-    { njs_number_constructor },
-    { njs_string_constructor },
-    { njs_function_constructor},
-    { njs_regexp_constructor },
-    { njs_date_constructor },
-    { njs_hash_constructor },
-    { njs_hmac_constructor },
-    { njs_error_constructor },
-    { njs_eval_error_constructor },
-    { njs_internal_error_constructor },
-    { njs_range_error_constructor },
-    { njs_reference_error_constructor },
-    { njs_syntax_error_constructor },
-    { njs_type_error_constructor },
-    { njs_uri_error_constructor },
-    { njs_memory_error_constructor },
-};
+    /* Hidden types. */
 
+    &njs_hash_type_init,
+    &njs_hmac_type_init,
 
-const njs_object_prototype_t  njs_prototype_values[] = {
-    /*
-     * GCC 4 complains about uninitialized .shared field,
-     * if the .type field is initialized as .object.type.
-     */
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_ARRAY } },
+    /* Error types. */
 
-    /*
-     * The .object.type field must be initialzed after the .value field,
-     * otherwise SunC 5.9 treats the .value as .object.value or so.
-     */
-    { .object_value = { .value = njs_value(NJS_BOOLEAN, 0, 0.0),
-                        .object = { .type = NJS_OBJECT_BOOLEAN } } },
-
-    { .object_value = { .value = njs_value(NJS_NUMBER, 0, 0.0),
-                        .object = { .type = NJS_OBJECT_NUMBER } } },
-
-    { .object_value = { .value = njs_string(""),
-                        .object = { .type = NJS_OBJECT_STRING } } },
-
-    { .function =     { .native = 1,
-                        .args_offset = 1,
-                        .u.native = njs_prototype_function,
-                        .object = { .type = NJS_FUNCTION } } },
-
-    { .object =       { .type = NJS_REGEXP } },
-
-    { .object =       { .type = NJS_OBJECT } },
-
-    { .object_value = { .value = njs_value(NJS_DATA, 0, 0.0),
-                        .object = { .type = NJS_OBJECT } } },
-
-    { .object_value = { .value = njs_value(NJS_DATA, 0, 0.0),
-                        .object = { .type = NJS_OBJECT } } },
-
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
-    { .object =       { .type = NJS_OBJECT } },
+    &njs_error_type_init,
+    &njs_eval_error_type_init,
+    &njs_internal_error_type_init,
+    &njs_range_error_type_init,
+    &njs_reference_error_type_init,
+    &njs_syntax_error_type_init,
+    &njs_type_error_type_init,
+    &njs_uri_error_type_init,
+    &njs_memory_error_type_init,
 };
 
 
@@ -192,16 +99,16 @@ njs_int_t
 njs_builtin_objects_create(njs_vm_t *vm)
 {
     njs_int_t                  ret;
+    njs_uint_t                 i;
     njs_module_t               *module;
     njs_object_t               *object, *string_object;
-    njs_function_t             *func;
+    njs_function_t             *constructor;
     njs_vm_shared_t            *shared;
     njs_lvlhsh_query_t         lhq;
     njs_regexp_pattern_t       *pattern;
     njs_object_prototype_t     *prototype;
     const njs_object_prop_t    *prop;
     const njs_object_init_t    *obj, **p;
-    const njs_function_init_t  *f;
 
     static const njs_str_t  sandbox_key = njs_str("sandbox");
     static const njs_str_t  name_key = njs_str("name");
@@ -336,19 +243,17 @@ njs_builtin_objects_create(njs_vm_t *vm)
     }
 
     prototype = shared->prototypes;
-    memcpy(prototype, njs_prototype_values, sizeof(njs_prototype_values));
 
-    for (p = njs_prototype_init; *p != NULL; p++) {
-        obj = *p;
+    for (i = NJS_OBJ_TYPE_OBJECT; i < NJS_OBJ_TYPE_MAX; i++) {
+        prototype[i] = njs_object_type_init[i]->value;
 
-        ret = njs_object_hash_init(vm, &prototype->object.shared_hash, obj);
+        ret = njs_object_hash_init(vm, &prototype[i].object.shared_hash,
+                                   njs_object_type_init[i]->prototype_props);
         if (njs_slow_path(ret != NJS_OK)) {
             return NJS_ERROR;
         }
 
-        prototype->object.extensible = 1;
-
-        prototype++;
+        prototype[i].object.extensible = 1;
     }
 
     shared->prototypes[NJS_OBJ_TYPE_REGEXP].regexp.pattern =
@@ -361,28 +266,23 @@ njs_builtin_objects_create(njs_vm_t *vm)
     string_object->shared = 1;
     string_object->extensible = 0;
 
-    f = njs_native_constructors;
-    func = shared->constructors;
-
-    for (p = njs_constructor_init; *p != NULL; p++) {
-        obj = *p;
+    constructor = shared->constructors;
 
-        func->object.type = NJS_FUNCTION;
-        func->object.shared = 0;
-        func->object.extensible = 1;
-        func->native = 1;
-        func->ctor = 1;
-        func->args_offset = 1;
+    for (i = NJS_OBJ_TYPE_OBJECT; i < NJS_OBJ_TYPE_MAX; i++) {
+        constructor[i].object.type = NJS_FUNCTION;
+        constructor[i].object.shared = 0;
+        constructor[i].object.extensible = 1;
+        constructor[i].native = 1;
+        constructor[i].ctor = 1;
+        constructor[i].args_offset = 1;
 
-        func->u.native = f->native;
+        constructor[i].u.native = njs_object_type_init[i]->constructor;
 
-        ret = njs_object_hash_init(vm, &func->object.shared_hash, obj);
+        ret = njs_object_hash_init(vm, &constructor[i].object.shared_hash,
+                                   njs_object_type_init[i]->constructor_props);
         if (njs_slow_path(ret != NJS_OK)) {
             return NJS_ERROR;
         }
-
-        f++;
-        func++;
     }
 
     vm->shared = shared;
@@ -391,90 +291,6 @@ njs_builtin_objects_create(njs_vm_t *vm)
 }
 
 
-static njs_int_t
-njs_prototype_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused)
-{
-    njs_set_undefined(&vm->retval);
-
-    return NJS_OK;
-}
-
-
-/*
- * Object(),
- * Object.__proto__             -> Function.prototype,
- * Object.prototype.__proto__   -> null,
- *   the null value is handled by njs_object_prototype_proto(),
- *
- * Array(),
- * Array.__proto__              -> Function.prototype,
- * Array.prototype.__proto__    -> Object.prototype,
- *
- * Boolean(),
- * Boolean.__proto__            -> Function.prototype,
- * Boolean.prototype.__proto__  -> Object.prototype,
- *
- * Number(),
- * Number.__proto__             -> Function.prototype,
- * Number.prototype.__proto__   -> Object.prototype,
- *
- * String(),
- * String.__proto__             -> Function.prototype,
- * String.prototype.__proto__   -> Object.prototype,
- *
- * Function(),
- * Function.__proto__           -> Function.prototype,
- * Function.prototype.__proto__ -> Object.prototype,
- *
- * RegExp(),
- * RegExp.__proto__             -> Function.prototype,
- * RegExp.prototype.__proto__   -> Object.prototype,
- *
- * Date(),
- * Date.__proto__               -> Function.prototype,
- * Date.prototype.__proto__     -> Object.prototype,
- *
- * Error(),
- * Error.__proto__               -> Function.prototype,
- * Error.prototype.__proto__     -> Object.prototype,
- *
- * EvalError(),
- * EvalError.__proto__           -> Error,
- * EvalError.prototype.__proto__ -> Error.prototype,
- *
- * InternalError(),
- * InternalError.__proto__           -> Error,
- * InternalError.prototype.__proto__ -> Error.prototype,
- *
- * RangeError(),
- * RangeError.__proto__           -> Error,
- * RangeError.prototype.__proto__ -> Error.prototype,
- *
- * ReferenceError(),
- * ReferenceError.__proto__           -> Error,
- * ReferenceError.prototype.__proto__ -> Error.prototype,
- *
- * SyntaxError(),
- * SyntaxError.__proto__           -> Error,
- * SyntaxError.prototype.__proto__ -> Error.prototype,
- *
- * TypeError(),
- * TypeError.__proto__           -> Error,
- * TypeError.prototype.__proto__ -> Error.prototype,
- *
- * URIError(),
- * URIError.__proto__           -> Error,
- * URIError.prototype.__proto__ -> Error.prototype,
- *
- * MemoryError(),
- * MemoryError.__proto__           -> Error,
- * MemoryError.prototype.__proto__ -> Error.prototype,
- *
- * eval(),
- * eval.__proto__               -> Function.prototype.
- */
-
 njs_int_t
 njs_builtin_objects_clone(njs_vm_t *vm, njs_value_t *global)
 {
@@ -972,7 +788,7 @@ njs_builtin_match_native_function(njs_vm
 
     /* Constructor from built-in modules (not-mapped to global object). */
 
-    for (i = NJS_OBJ_TYPE_CRYPTO_HASH; i < NJS_OBJ_TYPE_ERROR; i++) {
+    for (i = NJS_OBJ_TYPE_HIDDEN_MIN; i < NJS_OBJ_TYPE_HIDDEN_MAX; i++) {
         njs_set_object(&value, &vm->constructors[i].object);
 
         ret = njs_value_property(vm, &value, njs_value_arg(&njs_string_name),
@@ -1475,7 +1291,7 @@ static const njs_object_prop_t  njs_glob
 };
 
 
-const njs_object_init_t  njs_global_this_init = {
+static const njs_object_init_t  njs_global_this_init = {
     njs_global_this_object_properties,
     njs_nitems(njs_global_this_object_properties)
 };
@@ -1500,7 +1316,7 @@ static const njs_object_prop_t  njs_njs_
 };
 
 
-const njs_object_init_t  njs_njs_object_init = {
+static const njs_object_init_t  njs_njs_object_init = {
     njs_njs_object_properties,
     njs_nitems(njs_njs_object_properties),
 };
@@ -1708,7 +1524,7 @@ static const njs_object_prop_t  njs_proc
 };
 
 
-const njs_object_init_t  njs_process_object_init = {
+static const njs_object_init_t  njs_process_object_init = {
     njs_process_object_properties,
     njs_nitems(njs_process_object_properties),
 };
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_builtin.h
--- a/src/njs_builtin.h	Thu Oct 31 18:17:32 2019 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-
-/*
- * Copyright (C) Dmitry Volyntsev
- * Copyright (C) NGINX, Inc.
- */
-
-#ifndef _NJS_BUILTIN_H_INCLUDED_
-#define _NJS_BUILTIN_H_INCLUDED_
-
-
-extern const njs_object_init_t  *njs_object_init[];
-extern const njs_object_init_t  *njs_module_init[];
-extern const njs_object_init_t  *njs_prototype_init[];
-extern const njs_object_init_t  *njs_constructor_init[];
-
-
-#endif /* _NJS_BUILTIN_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_crypto.c
--- a/src/njs_crypto.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_crypto.c	Thu Oct 31 18:17:33 2019 +0300
@@ -352,7 +352,7 @@ const njs_object_init_t  njs_hash_protot
 };
 
 
-njs_int_t
+static njs_int_t
 njs_hash_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -390,6 +390,15 @@ const njs_object_init_t  njs_hash_constr
 };
 
 
+const njs_object_type_init_t  njs_hash_type_init = {
+    .constructor = njs_hash_constructor,
+    .prototype_props = &njs_hash_prototype_init,
+    .constructor_props = &njs_hash_constructor_init,
+    .value = { .object_value = { .value = njs_value(NJS_DATA, 0, 0.0),
+                                 .object = { .type = NJS_OBJECT } } },
+};
+
+
 static njs_int_t
 njs_crypto_create_hmac(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
@@ -634,7 +643,7 @@ const njs_object_init_t  njs_hmac_protot
 };
 
 
-njs_int_t
+static njs_int_t
 njs_hmac_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -712,6 +721,15 @@ const njs_object_init_t  njs_crypto_obje
 };
 
 
+const njs_object_type_init_t  njs_hmac_type_init = {
+    .constructor = njs_hmac_constructor,
+    .prototype_props = &njs_hmac_prototype_init,
+    .constructor_props = &njs_hmac_constructor_init,
+    .value = { .object_value = { .value = njs_value(NJS_DATA, 0, 0.0),
+                                 .object = { .type = NJS_OBJECT } } },
+};
+
+
 static njs_hash_alg_t *
 njs_crypto_alg(njs_vm_t *vm, const njs_str_t *name)
 {
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_crypto.h
--- a/src/njs_crypto.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_crypto.h	Thu Oct 31 18:17:33 2019 +0300
@@ -7,18 +7,10 @@
 #ifndef _NJS_CRYPTO_H_INCLUDED_
 #define _NJS_CRYPTO_H_INCLUDED_
 
-njs_int_t njs_hash_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_hmac_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-
 extern const njs_object_init_t  njs_crypto_object_init;
 
-extern const njs_object_init_t  njs_hash_prototype_init;
-extern const njs_object_init_t  njs_hmac_prototype_init;
-
-extern const njs_object_init_t  njs_hash_constructor_init;
-extern const njs_object_init_t  njs_hmac_constructor_init;
+extern const njs_object_type_init_t  njs_hash_type_init;
+extern const njs_object_type_init_t  njs_hmac_type_init;
 
 
 #endif /* _NJS_CRYPTO_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_date.c
--- a/src/njs_date.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_date.c	Thu Oct 31 18:17:33 2019 +0300
@@ -168,7 +168,7 @@ njs_make_date(int64_t days, int64_t time
 }
 
 
-njs_int_t
+static njs_int_t
 njs_date_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -2890,3 +2890,11 @@ const njs_object_init_t  njs_date_protot
     njs_date_prototype_properties,
     njs_nitems(njs_date_prototype_properties),
 };
+
+
+const njs_object_type_init_t  njs_date_type_init = {
+   .constructor = njs_date_constructor,
+   .prototype_props = &njs_date_prototype_init,
+   .constructor_props = &njs_date_constructor_init,
+   .value = { .object = { .type = NJS_OBJECT } },
+};
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_date.h
--- a/src/njs_date.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_date.h	Thu Oct 31 18:17:33 2019 +0300
@@ -8,15 +8,11 @@
 #define _NJS_DATE_H_INCLUDED_
 
 
-njs_int_t njs_date_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-
 njs_int_t njs_date_to_string(njs_vm_t *vm, njs_value_t *retval,
     const njs_value_t *date);
 
 
-extern const njs_object_init_t  njs_date_constructor_init;
-extern const njs_object_init_t  njs_date_prototype_init;
+extern const njs_object_type_init_t  njs_date_type_init;
 
 
 #endif /* _NJS_DATE_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_error.c
--- a/src/njs_error.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_error.c	Thu Oct 31 18:17:33 2019 +0300
@@ -165,7 +165,7 @@ njs_error_create(njs_vm_t *vm, njs_value
 }
 
 
-njs_int_t
+static njs_int_t
 njs_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -206,7 +206,7 @@ const njs_object_init_t  njs_error_const
 };
 
 
-njs_int_t
+static njs_int_t
 njs_eval_error_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -247,7 +247,7 @@ const njs_object_init_t  njs_eval_error_
 };
 
 
-njs_int_t
+static njs_int_t
 njs_internal_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -288,7 +288,7 @@ const njs_object_init_t  njs_internal_er
 };
 
 
-njs_int_t
+static njs_int_t
 njs_range_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -329,7 +329,7 @@ const njs_object_init_t  njs_range_error
 };
 
 
-njs_int_t
+static njs_int_t
 njs_reference_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -370,7 +370,7 @@ const njs_object_init_t  njs_reference_e
 };
 
 
-njs_int_t
+static njs_int_t
 njs_syntax_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -411,7 +411,7 @@ const njs_object_init_t  njs_syntax_erro
 };
 
 
-njs_int_t
+static njs_int_t
 njs_type_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -452,7 +452,7 @@ const njs_object_init_t  njs_type_error_
 };
 
 
-njs_int_t
+static njs_int_t
 njs_uri_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -526,7 +526,7 @@ njs_memory_error(njs_vm_t *vm)
 }
 
 
-njs_int_t
+static njs_int_t
 njs_memory_error_constructor(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
 {
@@ -758,6 +758,14 @@ const njs_object_init_t  njs_error_proto
 };
 
 
+const njs_object_type_init_t  njs_error_type_init = {
+    .constructor = njs_error_constructor,
+    .prototype_props = &njs_error_prototype_init,
+    .constructor_props = &njs_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_eval_error_prototype_properties[] =
 {
     {
@@ -792,6 +800,14 @@ const njs_object_init_t  njs_eval_error_
 };
 
 
+const njs_object_type_init_t  njs_eval_error_type_init = {
+    .constructor = njs_eval_error_constructor,
+    .prototype_props = &njs_eval_error_prototype_init,
+    .constructor_props = &njs_eval_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static njs_int_t
 njs_internal_error_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused)
@@ -846,6 +862,22 @@ const njs_object_init_t  njs_internal_er
 };
 
 
+const njs_object_type_init_t  njs_internal_error_type_init = {
+    .constructor = njs_internal_error_constructor,
+    .prototype_props = &njs_internal_error_prototype_init,
+    .constructor_props = &njs_internal_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
+const njs_object_type_init_t  njs_memory_error_type_init = {
+    .constructor = njs_memory_error_constructor,
+    .prototype_props = &njs_internal_error_prototype_init,
+    .constructor_props = &njs_memory_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_range_error_prototype_properties[] =
 {
     {
@@ -880,6 +912,14 @@ const njs_object_init_t  njs_range_error
 };
 
 
+const njs_object_type_init_t  njs_range_error_type_init = {
+    .constructor = njs_range_error_constructor,
+    .prototype_props = &njs_range_error_prototype_init,
+    .constructor_props = &njs_range_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_reference_error_prototype_properties[] =
 {
     {
@@ -914,6 +954,14 @@ const njs_object_init_t  njs_reference_e
 };
 
 
+const njs_object_type_init_t  njs_reference_error_type_init = {
+    .constructor = njs_reference_error_constructor,
+    .prototype_props = &njs_reference_error_prototype_init,
+    .constructor_props = &njs_reference_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_syntax_error_prototype_properties[] =
 {
     {
@@ -948,6 +996,14 @@ const njs_object_init_t  njs_syntax_erro
 };
 
 
+const njs_object_type_init_t  njs_syntax_error_type_init = {
+    .constructor = njs_syntax_error_constructor,
+    .prototype_props = &njs_syntax_error_prototype_init,
+    .constructor_props = &njs_syntax_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_type_error_prototype_properties[] =
 {
     {
@@ -982,6 +1038,14 @@ const njs_object_init_t  njs_type_error_
 };
 
 
+const njs_object_type_init_t  njs_type_error_type_init = {
+    .constructor = njs_type_error_constructor,
+    .prototype_props = &njs_type_error_prototype_init,
+    .constructor_props = &njs_type_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
+
+
 static const njs_object_prop_t  njs_uri_error_prototype_properties[] =
 {
     {
@@ -1014,3 +1078,11 @@ const njs_object_init_t  njs_uri_error_p
     njs_uri_error_prototype_properties,
     njs_nitems(njs_uri_error_prototype_properties),
 };
+
+
+const njs_object_type_init_t  njs_uri_error_type_init = {
+    .constructor = njs_uri_error_constructor,
+    .prototype_props = &njs_uri_error_prototype_init,
+    .constructor_props = &njs_uri_error_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_error.h
--- a/src/njs_error.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_error.h	Thu Oct 31 18:17:33 2019 +0300
@@ -42,47 +42,19 @@ void njs_memory_error_set(njs_vm_t *vm, 
 
 njs_object_t *njs_error_alloc(njs_vm_t *vm, njs_object_type_t type,
     const njs_value_t *name, const njs_value_t *message);
-njs_int_t njs_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_eval_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_internal_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_range_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_reference_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_syntax_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_type_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_uri_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-njs_int_t njs_memory_error_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
-
 njs_int_t njs_error_to_string(njs_vm_t *vm, njs_value_t *retval,
     const njs_value_t *error);
 
-extern const njs_object_init_t  njs_error_constructor_init;
-extern const njs_object_init_t  njs_eval_error_constructor_init;
-extern const njs_object_init_t  njs_internal_error_constructor_init;
-extern const njs_object_init_t  njs_range_error_constructor_init;
-extern const njs_object_init_t  njs_reference_error_constructor_init;
-extern const njs_object_init_t  njs_syntax_error_constructor_init;
-extern const njs_object_init_t  njs_type_error_constructor_init;
-extern const njs_object_init_t  njs_uri_error_constructor_init;
-extern const njs_object_init_t  njs_memory_error_constructor_init;
 
-
-extern const njs_object_init_t  njs_error_prototype_init;
-extern const njs_object_init_t  njs_eval_error_prototype_init;
-extern const njs_object_init_t  njs_internal_error_prototype_init;
-extern const njs_object_init_t  njs_range_error_prototype_init;
-extern const njs_object_init_t  njs_reference_error_prototype_init;
-extern const njs_object_init_t  njs_syntax_error_prototype_init;
-extern const njs_object_init_t  njs_type_error_prototype_init;
-extern const njs_object_init_t  njs_uri_error_prototype_init;
+extern const njs_object_type_init_t  njs_error_type_init;
+extern const njs_object_type_init_t  njs_eval_error_type_init;
+extern const njs_object_type_init_t  njs_internal_error_type_init;
+extern const njs_object_type_init_t  njs_range_error_type_init;
+extern const njs_object_type_init_t  njs_reference_error_type_init;
+extern const njs_object_type_init_t  njs_syntax_error_type_init;
+extern const njs_object_type_init_t  njs_type_error_type_init;
+extern const njs_object_type_init_t  njs_uri_error_type_init;
+extern const njs_object_type_init_t  njs_memory_error_type_init;
 
 
 #endif /* _NJS_BOOLEAN_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_fs.h
--- a/src/njs_fs.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_fs.h	Thu Oct 31 18:17:33 2019 +0300
@@ -7,6 +7,7 @@
 #ifndef _NJS_FS_H_INCLUDED_
 #define _NJS_FS_H_INCLUDED_
 
+
 extern const njs_object_init_t  njs_fs_object_init;
 
 
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_function.c
--- a/src/njs_function.c	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_function.c	Thu Oct 31 18:17:33 2019 +0300
@@ -723,7 +723,7 @@ njs_function_prototype_create(njs_vm_t *
 }
 
 
-njs_int_t
+static njs_int_t
 njs_function_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -1211,27 +1211,22 @@ njs_eval_function(njs_vm_t *vm, njs_valu
 }
 
 
-static const njs_object_prop_t  njs_eval_function_properties[] =
+static njs_int_t
+njs_prototype_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+    njs_index_t unused)
 {
-    /* eval.name == "eval". */
-    {
-        .type = NJS_PROPERTY,
-        .name = njs_string("name"),
-        .value = njs_string("eval"),
-        .configurable = 1,
-    },
+    njs_set_undefined(&vm->retval);
 
-    /* eval.length == 1. */
-    {
-        .type = NJS_PROPERTY,
-        .name = njs_string("length"),
-        .value = njs_value(NJS_NUMBER, 1, 1.0),
-        .configurable = 1,
-    },
-};
+    return NJS_OK;
+}
 
 
-const njs_object_init_t  njs_eval_function_init = {
-    njs_eval_function_properties,
-    njs_nitems(njs_eval_function_properties),
+const njs_object_type_init_t  njs_function_type_init = {
+   .constructor = njs_function_constructor,
+   .prototype_props = &njs_function_prototype_init,
+   .constructor_props = &njs_function_constructor_init,
+   .value = { .function = { .native = 1,
+                            .args_offset = 1,
+                            .u.native = njs_prototype_function,
+                            .object = { .type = NJS_FUNCTION } } },
 };
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_function.h
--- a/src/njs_function.h	Thu Oct 31 18:17:32 2019 +0300
+++ b/src/njs_function.h	Thu Oct 31 18:17:33 2019 +0300
@@ -107,8 +107,8 @@ njs_int_t njs_function_rest_parameters_i
     njs_native_frame_t *frame);
 njs_int_t njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
-njs_int_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
+njs_int_t njs_eval_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+    njs_index_t unused);
 njs_int_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
     const njs_value_t *this, const njs_value_t *args, njs_uint_t nargs,
     njs_bool_t ctor);
@@ -194,16 +194,9 @@ njs_function_apply(njs_vm_t *vm, njs_fun
 }
 
 
-extern const njs_object_init_t  njs_function_constructor_init;
-extern const njs_object_init_t  njs_function_prototype_init;
+extern const njs_object_type_init_t  njs_function_type_init;
 extern const njs_object_init_t  njs_function_instance_init;
 extern const njs_object_init_t  njs_arrow_instance_init;
 extern const njs_object_init_t  njs_arguments_object_instance_init;
 
-njs_int_t njs_eval_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused);
-
-extern const njs_object_init_t  njs_eval_function_init;
-
-
 #endif /* _NJS_FUNCTION_H_INCLUDED_ */
diff -r ce17b8cd9630 -r 5abe92b2cfd0 src/njs_main.h


More information about the nginx-devel mailing list