Coverage Report

Created: 2025-08-26 06:16

/src/njs/src/njs.h
Line
Count
Source (jump to first uncovered line)
1
2
/*
3
 * Copyright (C) Igor Sysoev
4
 * Copyright (C) NGINX, Inc.
5
 *
6
 * njs public header.
7
 */
8
9
#ifndef _NJS_H_INCLUDED_
10
#define _NJS_H_INCLUDED_
11
12
#include <njs_auto_config.h>
13
14
#define NJS_VERSION                 "0.9.2"
15
#define NJS_VERSION_NUMBER          0x000902
16
17
18
#include <string.h>
19
#include <njs_types.h>
20
#include <njs_clang.h>
21
#include <njs_str.h>
22
#include <njs_unicode.h>
23
#include <njs_utf8.h>
24
#include <njs_mp.h>
25
#include <njs_chb.h>
26
#include <njs_sprintf.h>
27
28
29
typedef uintptr_t                     njs_index_t;
30
typedef struct njs_vm_s               njs_vm_t;
31
typedef struct njs_mod_s              njs_mod_t;
32
typedef union  njs_value_s            njs_value_t;
33
typedef struct njs_function_s         njs_function_t;
34
typedef struct njs_vm_shared_s        njs_vm_shared_t;
35
typedef struct njs_object_init_s      njs_object_init_t;
36
typedef struct njs_object_prop_s      njs_object_prop_t;
37
typedef struct njs_object_prop_init_s njs_object_prop_init_t;
38
typedef struct njs_object_type_init_s njs_object_type_init_t;
39
typedef struct njs_external_s         njs_external_t;
40
41
/*
42
 * njs_opaque_value_t is the external storage type for native njs_value_t type.
43
 * sizeof(njs_opaque_value_t) == sizeof(njs_value_t).
44
 */
45
46
typedef struct {
47
    uint32_t                        filler[4];
48
} njs_opaque_value_t;
49
50
/* sizeof(njs_value_t) is 16 bytes. */
51
#define njs_argument(args, n)                                                 \
52
10.4M
    (njs_value_t *) ((u_char *) args + (n) * 16)
53
54
55
extern const njs_value_t            njs_value_undefined;
56
57
#define njs_arg(args, nargs, n)                                               \
58
4.20M
    ((n < nargs) ? njs_argument(args, n)                                      \
59
4.20M
                 : (njs_value_t *) &njs_value_undefined)
60
61
#define njs_value_assign(dst, src)                                            \
62
323M
    memcpy(dst, src, sizeof(njs_opaque_value_t))
63
64
13.8M
#define njs_value_arg(val) ((njs_value_t *) val)
65
66.5M
#define njs_value_atom(val) (((njs_opaque_value_t *) (val))->filler[0])
66
67
2.02G
#define njs_atom_is_number(atom_id) ((atom_id) & 0x80000000)
68
2.20G
#define njs_atom_number(atom_id) ((atom_id) & 0x7FFFFFFF)
69
228M
#define njs_number_atom(n) ((n) | 0x80000000)
70
71
#define njs_lvalue_arg(lvalue, args, nargs, n)                                \
72
1.94M
    ((n < nargs) ? njs_argument(args, n)                                      \
73
1.94M
                 : (njs_value_assign(lvalue, &njs_value_undefined), lvalue))
74
75
#define njs_vm_error(vm, fmt, ...)                                            \
76
0
    njs_vm_error2(vm, 0, fmt, ##__VA_ARGS__)
77
#define njs_vm_internal_error(vm, fmt, ...)                                   \
78
0
    njs_vm_error2(vm, 2, fmt, ##__VA_ARGS__)
79
#define njs_vm_range_error(vm, fmt, ...)                                      \
80
0
    njs_vm_error2(vm, 3, fmt, ##__VA_ARGS__)
81
#define njs_vm_ref_error(vm, fmt, ...)                                        \
82
    njs_vm_error2(vm, 4, fmt, ##__VA_ARGS__)
83
#define njs_vm_syntax_error(vm, fmt, ...)                                     \
84
    njs_vm_error2(vm, 5, fmt, ##__VA_ARGS__)
85
#define njs_vm_type_error(vm, fmt, ...)                                       \
86
0
    njs_vm_error2(vm, 6, fmt, ##__VA_ARGS__)
87
88
#define njs_deprecated(vm, text)                                             \
89
    do {                                                                     \
90
        static njs_bool_t  reported;                                         \
91
                                                                             \
92
        if (!reported) {                                                     \
93
            njs_vm_warn(vm, text " is deprecated "                           \
94
                        "and will be removed in the future");                \
95
            reported = 1;                                                    \
96
        }                                                                    \
97
    } while(0)
98
99
/*
100
 * njs_prop_handler_t operates as a property getter/setter or delete handler.
101
 * - retval != NULL && setval == NULL - GET context.
102
 * - retval != NULL && setval != NULL - SET context.
103
 * - retval == NULL - DELETE context.
104
 *
105
 * njs_prop_handler_t is expected to return:
106
 *   NJS_OK - handler executed successfully;
107
 *   NJS_DECLINED - handler was applied to inappropriate object, retval
108
 *   contains undefined value;
109
 *   NJS_ERROR - some error, njs_vm_exception_get(vm) can be used to get
110
 *   the exception value.
111
 */
112
typedef njs_int_t (*njs_prop_handler_t) (njs_vm_t *vm, njs_object_prop_t *prop,
113
    uint32_t atom_id, njs_value_t *value, njs_value_t *setval,
114
    njs_value_t *retval);
115
typedef njs_int_t (*njs_exotic_keys_t)(njs_vm_t *vm, njs_value_t *value,
116
    njs_value_t *retval);
117
typedef njs_int_t (*njs_function_native_t) (njs_vm_t *vm, njs_value_t *args,
118
    njs_uint_t nargs, njs_index_t magic8, njs_value_t *retval);
119
120
121
typedef enum {
122
    NJS_SYMBOL_INVALID,
123
    NJS_SYMBOL_ASYNC_ITERATOR,
124
    NJS_SYMBOL_HAS_INSTANCE,
125
    NJS_SYMBOL_IS_CONCAT_SPREADABLE,
126
    NJS_SYMBOL_ITERATOR,
127
    NJS_SYMBOL_MATCH,
128
    NJS_SYMBOL_MATCH_ALL,
129
    NJS_SYMBOL_REPLACE,
130
    NJS_SYMBOL_SEARCH,
131
    NJS_SYMBOL_SPECIES,
132
    NJS_SYMBOL_SPLIT,
133
    NJS_SYMBOL_TO_PRIMITIVE,
134
    NJS_SYMBOL_TO_STRING_TAG,
135
    NJS_SYMBOL_UNSCOPABLES,
136
    NJS_SYMBOL_KNOWN_MAX,
137
} njs_wellknown_symbol_t;
138
139
140
typedef enum {
141
434k
#define njs_object_enum_kind(flags) (flags & 7)
142
    NJS_ENUM_KEYS = 1,
143
    NJS_ENUM_VALUES = 2,
144
    NJS_ENUM_BOTH = 4,
145
#define njs_object_enum(flags) (flags & (NJS_ENUM_STRING | NJS_ENUM_SYMBOL))
146
    NJS_ENUM_STRING = 8,
147
    NJS_ENUM_SYMBOL = 16,
148
    NJS_ENUM_ENUMERABLE_ONLY = 32,
149
    NJS_ENUM_NON_SHARED_ONLY = 64,
150
} njs_object_enum_t;
151
152
153
typedef enum {
154
    /*
155
     * Extern property type.
156
     */
157
    NJS_EXTERN_PROPERTY = 0,
158
    NJS_EXTERN_METHOD = 1,
159
    NJS_EXTERN_OBJECT = 2,
160
    NJS_EXTERN_SELF = 3,
161
1.63M
#define NJS_EXTERN_TYPE_MASK    3
162
    /*
163
     * Extern property flags.
164
     */
165
    NJS_EXTERN_SYMBOL = 4,
166
} njs_extern_flag_t;
167
168
169
typedef enum {
170
    NJS_EXTERN_TYPE_INT = 0,
171
    NJS_EXTERN_TYPE_UINT = 1,
172
    NJS_EXTERN_TYPE_VALUE = 2,
173
} njs_extern_type_t;
174
175
176
struct njs_external_s {
177
    njs_extern_flag_t               flags;
178
179
    union {
180
        njs_str_t                   string;
181
        uint32_t                    symbol;
182
    } name;
183
184
    unsigned                        writable;
185
    unsigned                        configurable;
186
    unsigned                        enumerable;
187
188
    union {
189
        struct {
190
            const char              *value;
191
            njs_prop_handler_t      handler;
192
            uint16_t                magic16;
193
            uint32_t                magic32;
194
        } property;
195
196
        struct {
197
            njs_function_native_t   native;
198
            uint8_t                 magic8;
199
            uint8_t                 ctor;
200
        } method;
201
202
        struct {
203
            njs_external_t          *properties;
204
            njs_uint_t              nproperties;
205
206
            unsigned                writable;
207
            unsigned                configurable;
208
            unsigned                enumerable;
209
            njs_prop_handler_t      prop_handler;
210
            uint32_t                magic32;
211
            njs_exotic_keys_t       keys;
212
        } object;
213
    } u;
214
};
215
216
217
typedef void *                      njs_external_ptr_t;
218
219
typedef njs_mod_t *(*njs_module_loader_t)(njs_vm_t *vm,
220
    njs_external_ptr_t external, njs_str_t *name);
221
typedef void (*njs_rejection_tracker_t)(njs_vm_t *vm,
222
    njs_external_ptr_t external, njs_bool_t is_handled, njs_value_t *promise,
223
    njs_value_t *reason);
224
225
226
typedef struct {
227
    size_t                          size;
228
    uintptr_t                       *values;
229
} njs_vm_meta_t;
230
231
232
typedef njs_int_t (*njs_addon_init_pt)(njs_vm_t *vm);
233
234
typedef struct {
235
    njs_str_t                       name;
236
    njs_addon_init_pt               preinit;
237
    njs_addon_init_pt               init;
238
} njs_module_t;
239
240
241
typedef struct {
242
    njs_external_ptr_t              external;
243
    njs_vm_shared_t                 *shared;
244
    njs_vm_meta_t                   *metas;
245
    njs_module_t                    **addons;
246
    njs_str_t                       file;
247
248
    char                            **argv;
249
    njs_uint_t                      argc;
250
251
    njs_uint_t                      max_stack_size;
252
253
/*
254
 * interactive  - enables "interactive" mode.
255
 *  (REPL). Allows starting parent VM without cloning.
256
 * disassemble   - enables disassemble.
257
 * backtrace     - enables backtraces.
258
 * quiet         - removes filenames from backtraces. To produce comparable
259
    test262 diffs.
260
 * sandbox       - "sandbox" mode. Disables file access.
261
 * unsafe        - enables unsafe language features:
262
 *   - Function constructors.
263
 * module        - ES6 "module" mode. Script mode is default.
264
 * ast           - print AST.
265
 */
266
    uint8_t                         interactive;     /* 1 bit */
267
    uint8_t                         trailer;         /* 1 bit */
268
    uint8_t                         init;            /* 1 bit */
269
    uint8_t                         disassemble;     /* 1 bit */
270
    uint8_t                         backtrace;       /* 1 bit */
271
    uint8_t                         quiet;           /* 1 bit */
272
    uint8_t                         sandbox;         /* 1 bit */
273
    uint8_t                         unsafe;          /* 1 bit */
274
    uint8_t                         module;          /* 1 bit */
275
    uint8_t                         ast;             /* 1 bit */
276
#ifdef NJS_DEBUG_OPCODE
277
    uint8_t                         opcode_debug;    /* 1 bit */
278
#endif
279
#ifdef NJS_DEBUG_GENERATOR
280
    uint8_t                         generator_debug; /* 1 bit */
281
#endif
282
} njs_vm_opt_t;
283
284
285
typedef struct {
286
    njs_function_t      *function;
287
    njs_opaque_value_t  argument;
288
    njs_opaque_value_t  value;
289
290
    void                *data;
291
292
    int64_t             from;
293
    int64_t             to;
294
} njs_iterator_args_t;
295
296
297
typedef njs_int_t (*njs_iterator_handler_t)(njs_vm_t *vm,
298
    njs_iterator_args_t *args, njs_value_t *entry, int64_t n,
299
    njs_value_t *retval);
300
301
302
NJS_EXPORT void njs_vm_opt_init(njs_vm_opt_t *options);
303
NJS_EXPORT njs_vm_t *njs_vm_create(njs_vm_opt_t *options);
304
NJS_EXPORT void njs_vm_destroy(njs_vm_t *vm);
305
306
NJS_EXPORT njs_int_t njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end);
307
NJS_EXPORT void njs_vm_set_module_loader(njs_vm_t *vm,
308
    njs_module_loader_t module_loader, void *opaque);
309
NJS_EXPORT njs_mod_t *njs_vm_add_module(njs_vm_t *vm, njs_str_t *name,
310
    njs_value_t *value);
311
NJS_EXPORT njs_mod_t *njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name,
312
    u_char **start, u_char *end);
313
NJS_EXPORT njs_int_t njs_vm_reuse(njs_vm_t *vm);
314
NJS_EXPORT njs_vm_t *njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external);
315
316
NJS_EXPORT njs_int_t njs_vm_enqueue_job(njs_vm_t *vm, njs_function_t *function,
317
    const njs_value_t *args, njs_uint_t nargs);
318
/*
319
 * Executes a single pending job.
320
 *  1 successful run.
321
 *  NJS_OK pending job was not found.
322
 *  NJS_ERROR some exception or internal error happens.
323
 */
324
NJS_EXPORT njs_int_t njs_vm_execute_pending_job(njs_vm_t *vm);
325
NJS_EXPORT njs_int_t njs_vm_pending(njs_vm_t *vm);
326
327
NJS_EXPORT void njs_vm_set_rejection_tracker(njs_vm_t *vm,
328
    njs_rejection_tracker_t rejection_tracker, void *opaque);
329
330
/*
331
 * Runs the specified function with provided arguments.
332
 *  NJS_OK successful run.
333
 *  NJS_ERROR some exception or internal error happens.
334
 *
335
 *  njs_vm_exception_get(vm) can be used to get the exception value.
336
 */
337
NJS_EXPORT njs_int_t njs_vm_call(njs_vm_t *vm, njs_function_t *function,
338
    const njs_value_t *args, njs_uint_t nargs);
339
NJS_EXPORT njs_int_t njs_vm_invoke(njs_vm_t *vm, njs_function_t *function,
340
    const njs_value_t *args, njs_uint_t nargs, njs_value_t *retval);
341
342
/*
343
 * Runs the global code.
344
 *   NJS_OK successful run.
345
 *   NJS_ERROR some exception or internal error happens.
346
 *
347
 *   njs_vm_exception_get(vm) can be used to get the exception value.
348
 */
349
NJS_EXPORT njs_int_t njs_vm_start(njs_vm_t *vm, njs_value_t *retval);
350
351
5
#define NJS_PROTO_ID_ANY    (-1)
352
353
NJS_EXPORT njs_int_t njs_vm_external_prototype(njs_vm_t *vm,
354
    const njs_external_t *definition, njs_uint_t n);
355
NJS_EXPORT njs_int_t njs_vm_external_constructor(njs_vm_t *vm,
356
    const njs_str_t *name, njs_function_native_t native,
357
    const njs_external_t *ctor_props, njs_uint_t ctor_nprops,
358
    const njs_external_t *proto_props, njs_uint_t proto_nprops);
359
NJS_EXPORT njs_int_t njs_vm_external_create(njs_vm_t *vm, njs_value_t *value,
360
    njs_int_t proto_id, njs_external_ptr_t external, njs_bool_t shared);
361
NJS_EXPORT njs_external_ptr_t njs_vm_external(njs_vm_t *vm,
362
    njs_int_t proto_id, const njs_value_t *value);
363
NJS_EXPORT njs_int_t njs_external_property(njs_vm_t *vm,
364
    njs_object_prop_t *prop, uint32_t unused, njs_value_t *value,
365
    njs_value_t *setval, njs_value_t *retval);
366
NJS_EXPORT njs_int_t njs_atom_atomize_key(njs_vm_t *vm, njs_value_t *value);
367
NJS_EXPORT njs_int_t njs_value_property(njs_vm_t *vm, njs_value_t *value,
368
    uint32_t atom_id, njs_value_t *retval);
369
NJS_EXPORT njs_int_t njs_value_property_set(njs_vm_t *vm, njs_value_t *value,
370
    uint32_t atom_id, njs_value_t *setval);
371
NJS_EXPORT uintptr_t njs_vm_meta(njs_vm_t *vm, njs_uint_t index);
372
NJS_EXPORT njs_vm_opt_t *njs_vm_options(njs_vm_t *vm);
373
374
NJS_EXPORT njs_int_t njs_error_constructor(njs_vm_t *vm, njs_value_t *args,
375
    njs_uint_t nargs, njs_index_t type, njs_value_t *retval);
376
NJS_EXPORT njs_int_t njs_object_prototype_create_constructor(njs_vm_t *vm,
377
    njs_object_prop_t *prop, uint32_t unused, njs_value_t *value,
378
    njs_value_t *setval, njs_value_t *retval);
379
NJS_EXPORT njs_int_t njs_object_prototype_create(njs_vm_t *vm,
380
    njs_object_prop_t *prop, uint32_t unused, njs_value_t *value,
381
    njs_value_t *setval, njs_value_t *retval);
382
383
NJS_EXPORT njs_function_t *njs_vm_function_alloc(njs_vm_t *vm,
384
    njs_function_native_t native, njs_bool_t shared, njs_bool_t ctor);
385
386
NJS_EXPORT void njs_disassembler(njs_vm_t *vm);
387
388
NJS_EXPORT njs_int_t njs_vm_bind(njs_vm_t *vm, const njs_str_t *var_name,
389
    const njs_value_t *value, njs_bool_t shared);
390
njs_int_t njs_vm_bind_handler(njs_vm_t *vm, const njs_str_t *var_name,
391
    njs_prop_handler_t handler, uint16_t magic16, uint32_t magic32,
392
    njs_bool_t shared);
393
NJS_EXPORT njs_int_t njs_vm_global(njs_vm_t *vm, njs_value_t *retval);
394
NJS_EXPORT njs_int_t njs_vm_value(njs_vm_t *vm, const njs_str_t *path,
395
    njs_value_t *retval);
396
NJS_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, const njs_str_t *name);
397
NJS_EXPORT njs_bool_t njs_vm_constructor(njs_vm_t *vm);
398
NJS_EXPORT njs_int_t njs_vm_prototype(njs_vm_t *vm, njs_value_t *value,
399
    njs_value_t *retval);
400
401
NJS_EXPORT void njs_vm_throw(njs_vm_t *vm, const njs_value_t *value);
402
NJS_EXPORT void njs_vm_error2(njs_vm_t *vm, unsigned error_type,
403
    const char *fmt, ...);
404
NJS_EXPORT void njs_vm_error3(njs_vm_t *vm, unsigned type, const char *fmt,
405
    ...);
406
NJS_EXPORT void njs_vm_exception_get(njs_vm_t *vm, njs_value_t *retval);
407
NJS_EXPORT njs_mp_t *njs_vm_memory_pool(njs_vm_t *vm);
408
NJS_EXPORT njs_external_ptr_t njs_vm_external_ptr(njs_vm_t *vm);
409
410
NJS_EXPORT njs_int_t njs_value_to_integer(njs_vm_t *vm, njs_value_t *value,
411
    int64_t *dst);
412
413
/*  Gets string value, no copy. */
414
NJS_EXPORT void njs_value_string_get(njs_vm_t *vm, njs_value_t *value,
415
    njs_str_t *dst);
416
NJS_EXPORT njs_int_t njs_vm_value_string_create(njs_vm_t *vm,
417
    njs_value_t *value, const u_char *start, uint32_t size);
418
NJS_EXPORT njs_int_t njs_vm_value_string_create_chb(njs_vm_t *vm,
419
    njs_value_t *value, njs_chb_t *chain);
420
NJS_EXPORT njs_int_t njs_vm_string_compare(njs_vm_t *vm, const njs_value_t *v1,
421
    const njs_value_t *v2);
422
423
NJS_EXPORT njs_int_t njs_vm_value_array_buffer_set(njs_vm_t *vm,
424
    njs_value_t *value, const u_char *start, uint32_t size);
425
426
NJS_EXPORT njs_int_t njs_value_buffer_get(njs_vm_t *vm, njs_value_t *value,
427
    njs_str_t *dst);
428
/*
429
 * Sets a Buffer value.
430
 *   start data is not copied and should not be freed.
431
 */
432
NJS_EXPORT njs_int_t njs_vm_value_buffer_set(njs_vm_t *vm, njs_value_t *value,
433
    const u_char *start, uint32_t size);
434
435
NJS_EXPORT njs_int_t njs_value_to_string(njs_vm_t *vm, njs_value_t *dst,
436
    njs_value_t *value);
437
/*
438
 * Converts a value to bytes.
439
 */
440
NJS_EXPORT njs_int_t njs_vm_value_to_bytes(njs_vm_t *vm, njs_str_t *dst,
441
    njs_value_t *src);
442
443
/*
444
 * Converts a value to string.
445
 */
446
NJS_EXPORT njs_int_t njs_vm_value_to_string(njs_vm_t *vm, njs_str_t *dst,
447
    njs_value_t *src);
448
449
/*
450
 * Calls njs_vm_value_to_string(), if exception was thrown adds backtrace.
451
 */
452
NJS_EXPORT njs_int_t njs_vm_value_string(njs_vm_t *vm, njs_str_t *dst,
453
    njs_value_t *src);
454
/*
455
 * If string value is null-terminated the corresponding C string
456
 * is returned as is, otherwise the new copy is allocated with
457
 * the terminating zero byte.
458
 */
459
NJS_EXPORT const char *njs_vm_value_to_c_string(njs_vm_t *vm,
460
    njs_value_t *value);
461
NJS_EXPORT njs_int_t njs_vm_exception_string(njs_vm_t *vm, njs_str_t *dst);
462
463
NJS_EXPORT njs_int_t njs_vm_value_dump(njs_vm_t *vm, njs_str_t *dst,
464
    njs_value_t *value, njs_uint_t console, njs_uint_t indent);
465
466
NJS_EXPORT void njs_vm_memory_error(njs_vm_t *vm);
467
468
NJS_EXPORT void njs_value_undefined_set(njs_value_t *value);
469
NJS_EXPORT void njs_value_null_set(njs_value_t *value);
470
NJS_EXPORT void njs_value_invalid_set(njs_value_t *value);
471
NJS_EXPORT void njs_value_boolean_set(njs_value_t *value, int yn);
472
NJS_EXPORT void njs_value_number_set(njs_value_t *value, double num);
473
NJS_EXPORT void njs_value_function_set(njs_value_t *value,
474
    njs_function_t *function);
475
NJS_EXPORT void njs_value_external_set(njs_value_t *value,
476
    njs_external_ptr_t external);
477
478
NJS_EXPORT uint8_t njs_value_bool(const njs_value_t *value);
479
NJS_EXPORT double njs_value_number(const njs_value_t *value);
480
NJS_EXPORT njs_function_t *njs_value_function(const njs_value_t *value);
481
NJS_EXPORT njs_function_native_t njs_value_native_function(
482
    const njs_value_t *value);
483
NJS_EXPORT void *njs_value_ptr(const njs_value_t *value);
484
njs_external_ptr_t njs_value_external(const njs_value_t *value);
485
NJS_EXPORT njs_int_t njs_value_external_tag(const njs_value_t *value);
486
487
NJS_EXPORT uint16_t njs_vm_prop_magic16(njs_object_prop_t *prop);
488
NJS_EXPORT uint32_t njs_vm_prop_magic32(njs_object_prop_t *prop);
489
NJS_EXPORT njs_int_t njs_vm_prop_name(njs_vm_t *vm, uint32_t atom_id,
490
    njs_str_t *dst);
491
492
NJS_EXPORT njs_int_t njs_value_is_null(const njs_value_t *value);
493
NJS_EXPORT njs_int_t njs_value_is_undefined(const njs_value_t *value);
494
NJS_EXPORT njs_int_t njs_value_is_null_or_undefined(const njs_value_t *value);
495
NJS_EXPORT njs_int_t njs_value_is_valid(const njs_value_t *value);
496
NJS_EXPORT njs_int_t njs_value_is_boolean(const njs_value_t *value);
497
NJS_EXPORT njs_int_t njs_value_is_number(const njs_value_t *value);
498
NJS_EXPORT njs_int_t njs_value_is_valid_number(const njs_value_t *value);
499
NJS_EXPORT njs_int_t njs_value_is_string(const njs_value_t *value);
500
NJS_EXPORT njs_int_t njs_value_is_object(const njs_value_t *value);
501
NJS_EXPORT njs_int_t njs_value_is_error(const njs_value_t *value);
502
NJS_EXPORT njs_int_t njs_value_is_external(const njs_value_t *value,
503
    njs_int_t proto_id);
504
NJS_EXPORT njs_int_t njs_value_is_array(const njs_value_t *value);
505
NJS_EXPORT njs_int_t njs_value_is_function(const njs_value_t *value);
506
NJS_EXPORT njs_int_t njs_value_is_buffer(const njs_value_t *value);
507
NJS_EXPORT njs_int_t njs_value_is_data_view(const njs_value_t *value);
508
509
NJS_EXPORT njs_int_t njs_vm_object_alloc(njs_vm_t *vm, njs_value_t *retval,
510
    ...);
511
NJS_EXPORT njs_value_t *njs_vm_object_keys(njs_vm_t *vm, njs_value_t *value,
512
    njs_value_t *retval);
513
NJS_EXPORT njs_value_t *njs_vm_value_enumerate(njs_vm_t *vm, njs_value_t *value,
514
    uint32_t flags, njs_value_t *retval);
515
NJS_EXPORT njs_value_t *njs_vm_value_own_enumerate(njs_vm_t *vm,
516
    njs_value_t *value, uint32_t flags, njs_value_t *retval);
517
NJS_EXPORT njs_value_t *njs_vm_object_prop(njs_vm_t *vm,
518
    njs_value_t *value, const njs_str_t *key, njs_opaque_value_t *retval);
519
NJS_EXPORT njs_int_t njs_vm_object_prop_set(njs_vm_t *vm, njs_value_t *value,
520
    const njs_str_t *prop, njs_opaque_value_t *setval);
521
NJS_EXPORT njs_int_t njs_vm_object_iterate(njs_vm_t *vm,
522
    njs_iterator_args_t *args, njs_iterator_handler_t handler,
523
    njs_value_t *retval);
524
525
NJS_EXPORT njs_int_t njs_vm_array_alloc(njs_vm_t *vm, njs_value_t *retval,
526
    uint32_t spare);
527
NJS_EXPORT njs_int_t njs_vm_array_length(njs_vm_t *vm, njs_value_t *value,
528
    int64_t *length);
529
NJS_EXPORT njs_value_t *njs_vm_array_start(njs_vm_t *vm, njs_value_t *value);
530
NJS_EXPORT njs_value_t *njs_vm_array_prop(njs_vm_t *vm,
531
    njs_value_t *value, int64_t index, njs_opaque_value_t *retval);
532
NJS_EXPORT njs_value_t *njs_vm_array_push(njs_vm_t *vm, njs_value_t *value);
533
NJS_EXPORT njs_int_t njs_vm_date_alloc(njs_vm_t *vm, njs_value_t *retval,
534
    double time);
535
536
NJS_EXPORT njs_int_t njs_vm_json_parse(njs_vm_t *vm, njs_value_t *args,
537
    njs_uint_t nargs, njs_value_t *retval);
538
NJS_EXPORT njs_int_t njs_vm_json_stringify(njs_vm_t *vm, njs_value_t *args,
539
    njs_uint_t nargs, njs_value_t *retval);
540
541
NJS_EXPORT njs_int_t njs_vm_query_string_parse(njs_vm_t *vm, u_char *start,
542
    u_char *end, njs_value_t *retval);
543
544
NJS_EXPORT njs_int_t njs_vm_promise_create(njs_vm_t *vm, njs_value_t *retval,
545
    njs_value_t *callbacks);
546
547
548
njs_inline njs_int_t
549
njs_value_property_val(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
550
    njs_value_t *retval)
551
11.9M
{
552
11.9M
    njs_int_t  ret;
553
554
11.9M
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
555
430k
        ret = njs_atom_atomize_key(vm, key);
556
430k
        if (ret != NJS_OK) {
557
0
            return ret;
558
0
        }
559
430k
    }
560
561
11.9M
    return njs_value_property(vm, value, njs_value_atom(key), retval);
562
11.9M
}
Unexecuted instantiation: njs_shell.c:njs_value_property_val
Unexecuted instantiation: njs_arr.c:njs_value_property_val
Unexecuted instantiation: njs_rbtree.c:njs_value_property_val
Unexecuted instantiation: njs_mp.c:njs_value_property_val
Unexecuted instantiation: njs_sprintf.c:njs_value_property_val
Unexecuted instantiation: njs_value.c:njs_value_property_val
Unexecuted instantiation: njs_atom.c:njs_value_property_val
Unexecuted instantiation: njs_vm.c:njs_value_property_val
njs_vmcode.c:njs_value_property_val
Line
Count
Source
551
7.60M
{
552
7.60M
    njs_int_t  ret;
553
554
7.60M
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
555
0
        ret = njs_atom_atomize_key(vm, key);
556
0
        if (ret != NJS_OK) {
557
0
            return ret;
558
0
        }
559
0
    }
560
561
7.60M
    return njs_value_property(vm, value, njs_value_atom(key), retval);
562
7.60M
}
Unexecuted instantiation: njs_parser.c:njs_value_property_val
Unexecuted instantiation: njs_variable.c:njs_value_property_val
Unexecuted instantiation: njs_scope.c:njs_value_property_val
Unexecuted instantiation: njs_generator.c:njs_value_property_val
Unexecuted instantiation: njs_disassembler.c:njs_value_property_val
Unexecuted instantiation: njs_module.c:njs_value_property_val
Unexecuted instantiation: njs_extern.c:njs_value_property_val
Unexecuted instantiation: njs_number.c:njs_value_property_val
Unexecuted instantiation: njs_symbol.c:njs_value_property_val
njs_string.c:njs_value_property_val
Line
Count
Source
551
229
{
552
229
    njs_int_t  ret;
553
554
229
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
555
229
        ret = njs_atom_atomize_key(vm, key);
556
229
        if (ret != NJS_OK) {
557
0
            return ret;
558
0
        }
559
229
    }
560
561
229
    return njs_value_property(vm, value, njs_value_atom(key), retval);
562
229
}
Unexecuted instantiation: njs_object.c:njs_value_property_val
Unexecuted instantiation: njs_object_prop.c:njs_value_property_val
njs_array.c:njs_value_property_val
Line
Count
Source
551
472k
{
552
472k
    njs_int_t  ret;
553
554
472k
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
555
430k
        ret = njs_atom_atomize_key(vm, key);
556
430k
        if (ret != NJS_OK) {
557
0
            return ret;
558
0
        }
559
430k
    }
560
561
472k
    return njs_value_property(vm, value, njs_value_atom(key), retval);
562
472k
}
Unexecuted instantiation: njs_json.c:njs_value_property_val
Unexecuted instantiation: njs_function.c:njs_value_property_val
Unexecuted instantiation: njs_regexp.c:njs_value_property_val
Unexecuted instantiation: njs_date.c:njs_value_property_val
Unexecuted instantiation: njs_error.c:njs_value_property_val
Unexecuted instantiation: njs_array_buffer.c:njs_value_property_val
Unexecuted instantiation: njs_typed_array.c:njs_value_property_val
Unexecuted instantiation: njs_promise.c:njs_value_property_val
njs_iterator.c:njs_value_property_val
Line
Count
Source
551
3.91M
{
552
3.91M
    njs_int_t  ret;
553
554
3.91M
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
555
0
        ret = njs_atom_atomize_key(vm, key);
556
0
        if (ret != NJS_OK) {
557
0
            return ret;
558
0
        }
559
0
    }
560
561
3.91M
    return njs_value_property(vm, value, njs_value_atom(key), retval);
562
3.91M
}
Unexecuted instantiation: njs_async.c:njs_value_property_val
Unexecuted instantiation: njs_builtin.c:njs_value_property_val
Unexecuted instantiation: njs_regex.c:njs_value_property_val
Unexecuted instantiation: njs_buffer.c:njs_value_property_val
Unexecuted instantiation: njs_modules.c:njs_value_property_val
Unexecuted instantiation: njs_dtoa.c:njs_value_property_val
Unexecuted instantiation: njs_dtoa_fixed.c:njs_value_property_val
Unexecuted instantiation: njs_strtod.c:njs_value_property_val
Unexecuted instantiation: njs_djb_hash.c:njs_value_property_val
Unexecuted instantiation: njs_utf8.c:njs_value_property_val
Unexecuted instantiation: njs_utf16.c:njs_value_property_val
Unexecuted instantiation: njs_flathsh.c:njs_value_property_val
Unexecuted instantiation: njs_trace.c:njs_value_property_val
Unexecuted instantiation: njs_malloc.c:njs_value_property_val
Unexecuted instantiation: njs_utils.c:njs_value_property_val
Unexecuted instantiation: njs_chb.c:njs_value_property_val
Unexecuted instantiation: njs_lexer.c:njs_value_property_val
Unexecuted instantiation: njs_boolean.c:njs_value_property_val
Unexecuted instantiation: njs_math.c:njs_value_property_val
Unexecuted instantiation: njs_encoding.c:njs_value_property_val
Unexecuted instantiation: njs_crypto_module.c:njs_value_property_val
Unexecuted instantiation: njs_webcrypto_module.c:njs_value_property_val
Unexecuted instantiation: njs_fs_module.c:njs_value_property_val
Unexecuted instantiation: njs_query_string_module.c:njs_value_property_val
Unexecuted instantiation: njs_diyfp.c:njs_value_property_val
Unexecuted instantiation: njs_str.c:njs_value_property_val
Unexecuted instantiation: njs_random.c:njs_value_property_val
563
564
565
njs_inline njs_int_t
566
njs_value_property_val_set(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
567
    njs_value_t *setval)
568
0
{
569
0
    njs_int_t  ret;
570
571
0
    if (njs_value_atom(key) == 0 /* NJS_ATOM_STRING_unknown */) {
572
0
        ret = njs_atom_atomize_key(vm, key);
573
0
        if (ret != NJS_OK) {
574
0
            return ret;
575
0
        }
576
0
    }
577
578
0
    return njs_value_property_set(vm, value, njs_value_atom(key), setval);
579
0
}
Unexecuted instantiation: njs_shell.c:njs_value_property_val_set
Unexecuted instantiation: njs_arr.c:njs_value_property_val_set
Unexecuted instantiation: njs_rbtree.c:njs_value_property_val_set
Unexecuted instantiation: njs_mp.c:njs_value_property_val_set
Unexecuted instantiation: njs_sprintf.c:njs_value_property_val_set
Unexecuted instantiation: njs_value.c:njs_value_property_val_set
Unexecuted instantiation: njs_atom.c:njs_value_property_val_set
Unexecuted instantiation: njs_vm.c:njs_value_property_val_set
Unexecuted instantiation: njs_vmcode.c:njs_value_property_val_set
Unexecuted instantiation: njs_parser.c:njs_value_property_val_set
Unexecuted instantiation: njs_variable.c:njs_value_property_val_set
Unexecuted instantiation: njs_scope.c:njs_value_property_val_set
Unexecuted instantiation: njs_generator.c:njs_value_property_val_set
Unexecuted instantiation: njs_disassembler.c:njs_value_property_val_set
Unexecuted instantiation: njs_module.c:njs_value_property_val_set
Unexecuted instantiation: njs_extern.c:njs_value_property_val_set
Unexecuted instantiation: njs_number.c:njs_value_property_val_set
Unexecuted instantiation: njs_symbol.c:njs_value_property_val_set
Unexecuted instantiation: njs_string.c:njs_value_property_val_set
Unexecuted instantiation: njs_object.c:njs_value_property_val_set
Unexecuted instantiation: njs_object_prop.c:njs_value_property_val_set
Unexecuted instantiation: njs_array.c:njs_value_property_val_set
Unexecuted instantiation: njs_json.c:njs_value_property_val_set
Unexecuted instantiation: njs_function.c:njs_value_property_val_set
Unexecuted instantiation: njs_regexp.c:njs_value_property_val_set
Unexecuted instantiation: njs_date.c:njs_value_property_val_set
Unexecuted instantiation: njs_error.c:njs_value_property_val_set
Unexecuted instantiation: njs_array_buffer.c:njs_value_property_val_set
Unexecuted instantiation: njs_typed_array.c:njs_value_property_val_set
Unexecuted instantiation: njs_promise.c:njs_value_property_val_set
Unexecuted instantiation: njs_iterator.c:njs_value_property_val_set
Unexecuted instantiation: njs_async.c:njs_value_property_val_set
Unexecuted instantiation: njs_builtin.c:njs_value_property_val_set
Unexecuted instantiation: njs_regex.c:njs_value_property_val_set
Unexecuted instantiation: njs_buffer.c:njs_value_property_val_set
Unexecuted instantiation: njs_modules.c:njs_value_property_val_set
Unexecuted instantiation: njs_dtoa.c:njs_value_property_val_set
Unexecuted instantiation: njs_dtoa_fixed.c:njs_value_property_val_set
Unexecuted instantiation: njs_strtod.c:njs_value_property_val_set
Unexecuted instantiation: njs_djb_hash.c:njs_value_property_val_set
Unexecuted instantiation: njs_utf8.c:njs_value_property_val_set
Unexecuted instantiation: njs_utf16.c:njs_value_property_val_set
Unexecuted instantiation: njs_flathsh.c:njs_value_property_val_set
Unexecuted instantiation: njs_trace.c:njs_value_property_val_set
Unexecuted instantiation: njs_malloc.c:njs_value_property_val_set
Unexecuted instantiation: njs_utils.c:njs_value_property_val_set
Unexecuted instantiation: njs_chb.c:njs_value_property_val_set
Unexecuted instantiation: njs_lexer.c:njs_value_property_val_set
Unexecuted instantiation: njs_boolean.c:njs_value_property_val_set
Unexecuted instantiation: njs_math.c:njs_value_property_val_set
Unexecuted instantiation: njs_encoding.c:njs_value_property_val_set
Unexecuted instantiation: njs_crypto_module.c:njs_value_property_val_set
Unexecuted instantiation: njs_webcrypto_module.c:njs_value_property_val_set
Unexecuted instantiation: njs_fs_module.c:njs_value_property_val_set
Unexecuted instantiation: njs_query_string_module.c:njs_value_property_val_set
Unexecuted instantiation: njs_diyfp.c:njs_value_property_val_set
Unexecuted instantiation: njs_str.c:njs_value_property_val_set
Unexecuted instantiation: njs_random.c:njs_value_property_val_set
580
581
582
njs_inline size_t
583
njs_value_string_length(njs_vm_t *vm, njs_value_t *value)
584
0
{
585
0
    njs_str_t  str;
586
587
0
    njs_value_string_get(vm, value, &str);
588
589
0
    return str.length;
590
0
}
Unexecuted instantiation: njs_shell.c:njs_value_string_length
Unexecuted instantiation: njs_arr.c:njs_value_string_length
Unexecuted instantiation: njs_rbtree.c:njs_value_string_length
Unexecuted instantiation: njs_mp.c:njs_value_string_length
Unexecuted instantiation: njs_sprintf.c:njs_value_string_length
Unexecuted instantiation: njs_value.c:njs_value_string_length
Unexecuted instantiation: njs_atom.c:njs_value_string_length
Unexecuted instantiation: njs_vm.c:njs_value_string_length
Unexecuted instantiation: njs_vmcode.c:njs_value_string_length
Unexecuted instantiation: njs_parser.c:njs_value_string_length
Unexecuted instantiation: njs_variable.c:njs_value_string_length
Unexecuted instantiation: njs_scope.c:njs_value_string_length
Unexecuted instantiation: njs_generator.c:njs_value_string_length
Unexecuted instantiation: njs_disassembler.c:njs_value_string_length
Unexecuted instantiation: njs_module.c:njs_value_string_length
Unexecuted instantiation: njs_extern.c:njs_value_string_length
Unexecuted instantiation: njs_number.c:njs_value_string_length
Unexecuted instantiation: njs_symbol.c:njs_value_string_length
Unexecuted instantiation: njs_string.c:njs_value_string_length
Unexecuted instantiation: njs_object.c:njs_value_string_length
Unexecuted instantiation: njs_object_prop.c:njs_value_string_length
Unexecuted instantiation: njs_array.c:njs_value_string_length
Unexecuted instantiation: njs_json.c:njs_value_string_length
Unexecuted instantiation: njs_function.c:njs_value_string_length
Unexecuted instantiation: njs_regexp.c:njs_value_string_length
Unexecuted instantiation: njs_date.c:njs_value_string_length
Unexecuted instantiation: njs_error.c:njs_value_string_length
Unexecuted instantiation: njs_array_buffer.c:njs_value_string_length
Unexecuted instantiation: njs_typed_array.c:njs_value_string_length
Unexecuted instantiation: njs_promise.c:njs_value_string_length
Unexecuted instantiation: njs_iterator.c:njs_value_string_length
Unexecuted instantiation: njs_async.c:njs_value_string_length
Unexecuted instantiation: njs_builtin.c:njs_value_string_length
Unexecuted instantiation: njs_regex.c:njs_value_string_length
Unexecuted instantiation: njs_buffer.c:njs_value_string_length
Unexecuted instantiation: njs_modules.c:njs_value_string_length
Unexecuted instantiation: njs_dtoa.c:njs_value_string_length
Unexecuted instantiation: njs_dtoa_fixed.c:njs_value_string_length
Unexecuted instantiation: njs_strtod.c:njs_value_string_length
Unexecuted instantiation: njs_djb_hash.c:njs_value_string_length
Unexecuted instantiation: njs_utf8.c:njs_value_string_length
Unexecuted instantiation: njs_utf16.c:njs_value_string_length
Unexecuted instantiation: njs_flathsh.c:njs_value_string_length
Unexecuted instantiation: njs_trace.c:njs_value_string_length
Unexecuted instantiation: njs_malloc.c:njs_value_string_length
Unexecuted instantiation: njs_utils.c:njs_value_string_length
Unexecuted instantiation: njs_chb.c:njs_value_string_length
Unexecuted instantiation: njs_lexer.c:njs_value_string_length
Unexecuted instantiation: njs_boolean.c:njs_value_string_length
Unexecuted instantiation: njs_math.c:njs_value_string_length
Unexecuted instantiation: njs_encoding.c:njs_value_string_length
Unexecuted instantiation: njs_crypto_module.c:njs_value_string_length
Unexecuted instantiation: njs_webcrypto_module.c:njs_value_string_length
Unexecuted instantiation: njs_fs_module.c:njs_value_string_length
Unexecuted instantiation: njs_query_string_module.c:njs_value_string_length
Unexecuted instantiation: njs_diyfp.c:njs_value_string_length
Unexecuted instantiation: njs_str.c:njs_value_string_length
Unexecuted instantiation: njs_random.c:njs_value_string_length
591
592
593
#endif /* _NJS_H_INCLUDED_ */