Welcome! Log In Create A New Profile

Advanced

[njs] Added njs_date_alloc().

Dmitry Volyntsev
November 02, 2021 08:44AM
details: https://hg.nginx.org/njs/rev/4ddfb2f2227f
branches:
changeset: 1738:4ddfb2f2227f
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Nov 02 12:38:42 2021 +0000
description:
Added njs_date_alloc().

diffstat:

src/njs_date.c | 42 ++++++++++++++++++++++++++++--------------
src/njs_date.h | 1 +
2 files changed, 29 insertions(+), 14 deletions(-)

diffs (74 lines):

diff -r 0c5745fc200d -r 4ddfb2f2227f src/njs_date.c
--- a/src/njs_date.c Tue Nov 02 12:38:02 2021 +0000
+++ b/src/njs_date.c Tue Nov 02 12:38:42 2021 +0000
@@ -346,6 +346,33 @@ njs_date_args(njs_vm_t *vm, njs_value_t
}


+njs_date_t *
+njs_date_alloc(njs_vm_t *vm, double time)
+{
+ njs_date_t *date;
+
+ date = njs_mp_alloc(vm->mem_pool, sizeof(njs_date_t));
+ if (njs_slow_path(date == NULL)) {
+ njs_memory_error(vm);
+ return NULL;
+ }
+
+ njs_lvlhsh_init(&date->object.hash);
+ njs_lvlhsh_init(&date->object.shared_hash);
+ date->object.type = NJS_DATE;
+ date->object.shared = 0;
+ date->object.extensible = 1;
+ date->object.error_data = 0;
+ date->object.fast_array = 0;
+ date->object.__proto__ = &vm->prototypes[NJS_OBJ_TYPE_DATE].object;
+ date->object.slots = NULL;
+
+ date->time = time;
+
+ return date;
+}
+
+
static njs_int_t
njs_date_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
@@ -393,24 +420,11 @@ njs_date_constructor(njs_vm_t *vm, njs_v
time = njs_make_date(tm, 1);
}

- date = njs_mp_alloc(vm->mem_pool, sizeof(njs_date_t));
+ date = njs_date_alloc(vm, time);
if (njs_slow_path(date == NULL)) {
- njs_memory_error(vm);
return NJS_ERROR;
}

- njs_lvlhsh_init(&date->object.hash);
- njs_lvlhsh_init(&date->object.shared_hash);
- date->object.type = NJS_DATE;
- date->object.shared = 0;
- date->object.extensible = 1;
- date->object.error_data = 0;
- date->object.fast_array = 0;
- date->object.__proto__ = &vm->prototypes[NJS_OBJ_TYPE_DATE].object;
- date->object.slots = NULL;
-
- date->time = time;
-
njs_set_date(&vm->retval, date);

return NJS_OK;
diff -r 0c5745fc200d -r 4ddfb2f2227f src/njs_date.h
--- a/src/njs_date.h Tue Nov 02 12:38:02 2021 +0000
+++ b/src/njs_date.h Tue Nov 02 12:38:42 2021 +0000
@@ -8,6 +8,7 @@
#define _NJS_DATE_H_INCLUDED_


+njs_date_t *njs_date_alloc(njs_vm_t *vm, double time);
njs_int_t njs_date_to_string(njs_vm_t *vm, njs_value_t *retval,
const njs_value_t *date);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added njs_date_alloc().

Dmitry Volyntsev 183 November 02, 2021 08:44AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 50
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready