}
-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)
{
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 } },
+};
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_ */
#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)
{
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 } } },
+};
#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_ */
#include <njs_main.h>
-typedef struct {
- njs_function_native_t native;
-} njs_function_init_t;
-
-
typedef struct {
enum {
NJS_BUILTIN_TRAVERSE_KEYS,
} 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);
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,
};
-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,
};
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");
}
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 =
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;
}
-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)
{
/* 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),
};
-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)
};
};
-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),
};
};
-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),
};
+++ /dev/null
-
-/*
- * 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_ */
};
-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)
{
};
+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)
};
-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)
{
};
+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)
{
#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_ */
}
-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)
{
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 } },
+};
#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_ */
}
-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)
{
};
-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)
{
};
-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)
{
};
-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)
{
};
-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)
{
};
-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)
{
};
-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)
{
};
-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)
{
}
-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)
{
};
+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[] =
{
{
};
+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)
};
+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[] =
{
{
};
+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[] =
{
{
};
+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[] =
{
{
};
+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[] =
{
{
};
+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[] =
{
{
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 } },
+};
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_ */
#ifndef _NJS_FS_H_INCLUDED_
#define _NJS_FS_H_INCLUDED_
+
extern const njs_object_init_t njs_fs_object_init;
}
-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)
{
}
-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 } } },
};
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);
}
-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_ */
#include <njs_fs.h>
#include <njs_crypto.h>
-#include <njs_builtin.h>
#include <njs_event.h>
#include <njs_extern.h>
#include <njs_module.h>
}
-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)
{
}
-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),
-};
-
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,
}
-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_ */
}
-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)
{
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 } },
+};
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);
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
}
-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)
{
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 } },
+};
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,
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_ */
}
-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)
{
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 } } },
+};
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);
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_ */
} 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,
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,