]> git.kaiwu.me - njs.git/commitdiff
Refactored object type initialization.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 31 Oct 2019 15:17:33 +0000 (18:17 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 31 Oct 2019 15:17:33 +0000 (18:17 +0300)
26 files changed:
src/njs_array.c
src/njs_array.h
src/njs_boolean.c
src/njs_boolean.h
src/njs_builtin.c
src/njs_builtin.h [deleted file]
src/njs_crypto.c
src/njs_crypto.h
src/njs_date.c
src/njs_date.h
src/njs_error.c
src/njs_error.h
src/njs_fs.h
src/njs_function.c
src/njs_function.h
src/njs_main.h
src/njs_number.c
src/njs_number.h
src/njs_object.c
src/njs_object.h
src/njs_regexp.c
src/njs_regexp.h
src/njs_string.c
src/njs_string.h
src/njs_value.h
src/njs_vm.h

index 3fd1cb361bfa6e012f47412901d95e4baa3cc0ff..c7f9cbd6ccd1dcfa7a752b1679fed851df40c87a 100644 (file)
@@ -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_instance_init = {
     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 } },
+};
index 242430c8da8f511640882188417c4330ffe509b7..1fe184728352ccc41ba702a3643c04a1f66365c0 100644 (file)
@@ -21,12 +21,10 @@ njs_int_t njs_array_string_add(njs_vm_t *vm, njs_array_t *array,
     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_ */
index 0dc4860ec1a073195cc5d85362131bcb5937c93e..a9e6e99a0b106c95481e6b187bdac2c70f010157 100644 (file)
@@ -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_prototype_init = {
     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 } } },
+};
index a936706ba7a91506ec06a21a5b96f0353a52e819..26181d985b162f5082c52833baf8ae4f3b7254bc 100644 (file)
@@ -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_ */
index 4dd710fdb10bec2e3c32c3438f1297c39dd0872b..d08c42014dfa3ed6c8e2137037912b7ee5d14e08 100644 (file)
@@ -9,11 +9,6 @@
 #include <njs_main.h>
 
 
-typedef struct {
-    njs_function_native_t  native;
-} njs_function_init_t;
-
-
 typedef struct {
     enum {
        NJS_BUILTIN_TRAVERSE_KEYS,
@@ -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_vm_t *vm, njs_lvlhsh_t *hash,
     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_init[] = {
 };
 
 
-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
-};
-
-
-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
-};
-
-
-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 },
-};
-
-
-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 } },
-
-    /*
-     * 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 } },
+static const njs_object_type_init_t *const
+    njs_object_type_init[NJS_OBJ_TYPE_MAX] =
+{
+    /* Global types. */
+
+    &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,
+
+    /* Hidden types. */
+
+    &njs_hash_type_init,
+    &njs_hmac_type_init,
+
+    /* Error types. */
+
+    &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;
+    constructor = shared->constructors;
 
-    for (p = njs_constructor_init; *p != NULL; p++) {
-        obj = *p;
+    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->object.type = NJS_FUNCTION;
-        func->object.shared = 0;
-        func->object.extensible = 1;
-        func->native = 1;
-        func->ctor = 1;
-        func->args_offset = 1;
+        constructor[i].u.native = njs_object_type_init[i]->constructor;
 
-        func->u.native = f->native;
-
-        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_t *vm, njs_function_t *function,
 
     /* 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_global_this_object_properties[] =
 };
 
 
-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_object_properties[] =
 };
 
 
-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_process_object_properties[] =
 };
 
 
-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 --git a/src/njs_builtin.h b/src/njs_builtin.h
deleted file mode 100644 (file)
index 8c169f2..0000000
+++ /dev/null
@@ -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_ */
index 1b75ee3e17767e782068d5449f0073f61a8a3405..61c8802f32e31d6ae8d68674f5428c8b4babc9a0 100644 (file)
@@ -352,7 +352,7 @@ const njs_object_init_t  njs_hash_prototype_init = {
 };
 
 
-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_constructor_init = {
 };
 
 
+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_prototype_init = {
 };
 
 
-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_object_init = {
 };
 
 
+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)
 {
index ce00d3a3eb5db844fb5360cb58ceaf88d1533783..27472f1d4a36230c762c97a5c2958461fa11aa92 100644 (file)
@@ -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_ */
index 4ee839434e3fd04f7183b1fed9cb40280ef7ed6d..43e9d8c7a438bf37f3a77f35de2eef2e74635026 100644 (file)
@@ -168,7 +168,7 @@ njs_make_date(int64_t days, int64_t time, njs_bool_t local)
 }
 
 
-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_prototype_init = {
     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 } },
+};
index 93263b222237a89e2798245f45d506e7b1036aee..d4fbb0621b6919700e81acc6f4529fc10ba41e1e 100644 (file)
@@ -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_ */
index e01845564e84dc155d8bd780ef6789ecd725c638..e84e8f40b7c73e62af061de465957aef87e5c267 100644 (file)
@@ -165,7 +165,7 @@ njs_error_create(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 }
 
 
-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_constructor_init = {
 };
 
 
-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_constructor_init = {
 };
 
 
-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_error_constructor_init = {
 };
 
 
-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_constructor_init = {
 };
 
 
-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_error_constructor_init = {
 };
 
 
-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_error_constructor_init = {
 };
 
 
-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_constructor_init = {
 };
 
 
-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_prototype_init = {
 };
 
 
+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_prototype_init = {
 };
 
 
+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_error_prototype_init = {
 };
 
 
+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_prototype_init = {
 };
 
 
+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_error_prototype_init = {
 };
 
 
+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_error_prototype_init = {
 };
 
 
+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_prototype_init = {
 };
 
 
+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_prototype_init = {
     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 } },
+};
index 8ef7d5f73f2145fc62f70e4a38b1816b5565f9e0..0d5f0e0ac84c37874370cf68afb0b6118f037a0b 100644 (file)
@@ -42,47 +42,19 @@ void njs_memory_error_set(njs_vm_t *vm, njs_value_t *value);
 
 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_ */
index 89e7fa610e1cc1712c9854abbb68c3a5aec9c5f8..db6a72e0097798b468ec4edd87225aa26d15e721 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _NJS_FS_H_INCLUDED_
 #define _NJS_FS_H_INCLUDED_
 
+
 extern const njs_object_init_t  njs_fs_object_init;
 
 
index 5b6dbc15403481401de76ad0f209fb2c8658ec86..d43bfb282d9ee7415dc30393a99a44475ac7da53 100644 (file)
@@ -723,7 +723,7 @@ njs_function_prototype_create(njs_vm_t *vm, njs_object_prop_t *prop,
 }
 
 
-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_value_t *args, njs_uint_t nargs,
 }
 
 
-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 } } },
 };
index 82ca3a3b182a6b0816d14b66ab2736fa90f7bc0b..9c80fb5ecee8ec696f7f5ca19234fd6c6b029462 100644 (file)
@@ -107,8 +107,8 @@ njs_int_t njs_function_rest_parameters_init(njs_vm_t *vm,
     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_function_t *function,
 }
 
 
-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_ */
index 4ee8748a7fdcad1119264a142c16fb723756d668..cd2c966339f4393f286135e356bd3f5a76bdb28e 100644 (file)
@@ -70,7 +70,6 @@
 #include <njs_fs.h>
 #include <njs_crypto.h>
 
-#include <njs_builtin.h>
 #include <njs_event.h>
 #include <njs_extern.h>
 #include <njs_module.h>
index ef3a55ead98e48aa57162b37754de3757714f8cc..48183b701c16d36b94497cd134a1a3fc16c940c7 100644 (file)
@@ -237,7 +237,7 @@ njs_number_to_string(njs_vm_t *vm, njs_value_t *string,
 }
 
 
-njs_int_t
+static njs_int_t
 njs_number_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -1123,28 +1123,10 @@ njs_number_parse_float(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 }
 
 
-static const njs_object_prop_t  njs_is_finite_function_properties[] =
-{
-    /* isFinite.name == "isFinite". */
-    {
-        .type = NJS_PROPERTY,
-        .name = njs_string("name"),
-        .value = njs_string("isFinite"),
-        .configurable = 1,
-    },
-
-    /* isFinite.length == 1. */
-    {
-        .type = NJS_PROPERTY,
-        .name = njs_string("length"),
-        .value = njs_value(NJS_NUMBER, 1, 1.0),
-        .configurable = 1,
-    },
+const njs_object_type_init_t  njs_number_type_init = {
+   .constructor = njs_number_constructor,
+   .prototype_props = &njs_number_prototype_init,
+   .constructor_props = &njs_number_constructor_init,
+   .value = { .object_value = { .value = njs_value(NJS_NUMBER, 0, 0.0),
+                                .object = { .type = NJS_OBJECT_NUMBER } } },
 };
-
-
-const njs_object_init_t  njs_is_finite_function_init = {
-    njs_is_finite_function_properties,
-    njs_nitems(njs_is_finite_function_properties),
-};
-
index 3fcc5c0b7cfa0241ea2bac2fe653fe2fc9e7df3d..dcce83fce0615fcb5132d0ad130a230011b4e851 100644 (file)
@@ -17,8 +17,6 @@ int64_t njs_number_radix_parse(const u_char **start, const u_char *end,
     uint8_t radix);
 njs_int_t njs_number_to_string(njs_vm_t *vm, njs_value_t *string,
     const njs_value_t *number);
-njs_int_t njs_number_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_number_global_is_nan(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_number_global_is_finite(njs_vm_t *vm, njs_value_t *args,
@@ -154,8 +152,7 @@ njs_uint32_to_string(njs_value_t *value, uint32_t u32)
 }
 
 
-extern const njs_object_init_t  njs_number_constructor_init;
-extern const njs_object_init_t  njs_number_prototype_init;
+extern const njs_object_type_init_t  njs_number_type_init;
 
 
 #endif /* _NJS_NUMBER_H_INCLUDED_ */
index fd27472cd1c9fe05dec2381894b10af059b4ff63..26c051def1681b56ef89b757b44833919d99c2e9 100644 (file)
@@ -190,7 +190,7 @@ njs_object_hash_test(njs_lvlhsh_query_t *lhq, void *data)
 }
 
 
-njs_int_t
+static njs_int_t
 njs_object_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -2388,3 +2388,11 @@ njs_object_length(njs_vm_t *vm, njs_value_t *value, uint32_t *length)
 
     return njs_value_to_length(vm, &value_length, length);
 }
+
+
+const njs_object_type_init_t  njs_obj_type_init = {
+    .constructor = njs_object_constructor,
+    .prototype_props = &njs_object_prototype_init,
+    .constructor_props = &njs_object_constructor_init,
+    .value = { .object = { .type = NJS_OBJECT } },
+};
index f8936bdf67bf24cd9022ec9eb4360cd3eae289e4..4943077a7d8c865b6776aa34ed3c368e80e18b6f 100644 (file)
@@ -72,8 +72,6 @@ njs_int_t njs_object_traverse(njs_vm_t *vm, njs_object_t *object, void *ctx,
     njs_object_traverse_cb_t cb);
 njs_int_t njs_object_hash_create(njs_vm_t *vm, njs_lvlhsh_t *hash,
     const njs_object_prop_t *prop, njs_uint_t n);
-njs_int_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_primitive_prototype_get_proto(njs_vm_t *vm,
     njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
     njs_value_t *retval);
@@ -103,8 +101,7 @@ njs_int_t njs_object_prop_descriptor(njs_vm_t *vm, njs_value_t *dest,
     njs_value_t *value, njs_value_t *setval);
 const char *njs_prop_type_string(njs_object_prop_type_t type);
 
-extern const njs_object_init_t  njs_object_constructor_init;
-extern const njs_object_init_t  njs_object_prototype_init;
+extern const njs_object_type_init_t  njs_obj_type_init;
 
 
 njs_inline njs_int_t
index cf8465e659ddd822554a560359fc779b98a81a14..4234ac21c079c211bd5aaf1159c8cf332e510bdf 100644 (file)
@@ -96,7 +96,7 @@ njs_regexp_value_flags(njs_vm_t *vm, const njs_value_t *regexp)
 }
 
 
-njs_int_t
+static njs_int_t
 njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -1268,3 +1268,11 @@ const njs_object_init_t  njs_regexp_prototype_init = {
     njs_regexp_prototype_properties,
     njs_nitems(njs_regexp_prototype_properties),
 };
+
+
+const njs_object_type_init_t  njs_regexp_type_init = {
+   .constructor = njs_regexp_constructor,
+   .prototype_props = &njs_regexp_prototype_init,
+   .constructor_props = &njs_regexp_constructor_init,
+   .value = { .object = { .type = NJS_REGEXP } },
+};
index 12f5798130e351218868c373c52b7aa39d3f37ea..0873d713e0d2313f6105f8cd6b9ec5f267e767c8 100644 (file)
@@ -17,8 +17,6 @@ typedef enum {
 
 
 njs_int_t njs_regexp_init(njs_vm_t *vm);
-njs_int_t njs_regexp_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_regexp_create(njs_vm_t *vm, njs_value_t *value, u_char *start,
     size_t length, njs_regexp_flags_t flags);
 njs_token_t njs_regexp_literal(njs_vm_t *vm, njs_parser_t *parser,
@@ -34,8 +32,8 @@ njs_int_t njs_regexp_prototype_exec(njs_vm_t *vm, njs_value_t *args,
 njs_int_t njs_regexp_to_string(njs_vm_t *vm, njs_value_t *retval,
     const njs_value_t *regexp);
 
-extern const njs_object_init_t  njs_regexp_constructor_init;
-extern const njs_object_init_t  njs_regexp_prototype_init;
+
+extern const njs_object_type_init_t  njs_regexp_type_init;
 
 
 #endif /* _NJS_REGEXP_H_INCLUDED_ */
index f5e0ba2bdae4707f91ced116e4baea87a284e25b..698c3450d0b49794f73cec348e8a7e1d2b48bbf2 100644 (file)
@@ -537,7 +537,7 @@ njs_string_prop(njs_string_prop_t *string, const njs_value_t *value)
 }
 
 
-njs_int_t
+static njs_int_t
 njs_string_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
@@ -5265,3 +5265,12 @@ njs_value_index(njs_vm_t *vm, const njs_value_t *src, njs_uint_t runtime)
 
     return (njs_index_t) value;
 }
+
+
+const njs_object_type_init_t  njs_string_type_init = {
+    .constructor = njs_string_constructor,
+    .prototype_props = &njs_string_prototype_init,
+    .constructor_props = &njs_string_constructor_init,
+    .value = { .object_value = { .value = njs_string(""),
+                                 .object = { .type = NJS_OBJECT_STRING } } },
+};
index ef88a1abdec309fc3bdd30adb33d92005b2c6af4..edf78f4f4ed2df88854303b2d20db2520d8d8471 100644 (file)
@@ -165,8 +165,6 @@ void njs_string_copy(njs_value_t *dst, njs_value_t *src);
 njs_int_t njs_string_validate(njs_vm_t *vm, njs_string_prop_t *string,
     njs_value_t *value);
 size_t njs_string_prop(njs_string_prop_t *string, const njs_value_t *value);
-njs_int_t njs_string_constructor(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_string_cmp(const njs_value_t *val1, const njs_value_t *val2);
 void njs_string_slice_string_prop(njs_string_prop_t *dst,
     const njs_string_prop_t *string, const njs_slice_prop_t *slice);
@@ -194,9 +192,8 @@ njs_int_t njs_string_prototype_concat(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
 
 
-extern const njs_object_init_t  njs_string_constructor_init;
-extern const njs_object_init_t  njs_string_prototype_init;
 extern const njs_object_init_t  njs_string_instance_init;
+extern const njs_object_type_init_t  njs_string_type_init;
 
 
 #endif /* _NJS_STRING_H_INCLUDED_ */
index 60f871758961a055d6da876bbf7b164d3452e02f..75a1ec2ecc0e1bba87d9986d95a49344b0ce45ee 100644 (file)
@@ -284,6 +284,14 @@ typedef union {
 } njs_object_prototype_t;
 
 
+typedef struct {
+    njs_function_native_t     constructor;
+    const njs_object_init_t   *prototype_props;
+    const njs_object_init_t   *constructor_props;
+    njs_object_prototype_t    value;
+} njs_object_type_init_t;
+
+
 typedef enum {
     NJS_ENUM_KEYS,
     NJS_ENUM_VALUES,
index 5475b515748ca2e53f459f7c231ace275856b0fc..63f3059ecadeea75e7590c6697d93d6a15020cbc 100644 (file)
@@ -89,7 +89,9 @@ typedef enum {
     NJS_OBJ_TYPE_REGEXP,
     NJS_OBJ_TYPE_DATE,
     NJS_OBJ_TYPE_CRYPTO_HASH,
+#define NJS_OBJ_TYPE_HIDDEN_MIN    (NJS_OBJ_TYPE_CRYPTO_HASH)
     NJS_OBJ_TYPE_CRYPTO_HMAC,
+#define NJS_OBJ_TYPE_HIDDEN_MAX    (NJS_OBJ_TYPE_CRYPTO_HMAC + 1)
     NJS_OBJ_TYPE_ERROR,
     NJS_OBJ_TYPE_EVAL_ERROR,
     NJS_OBJ_TYPE_INTERNAL_ERROR,