Coverage Report

Created: 2025-07-11 06:57

/src/quickjs/quickjs.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * QuickJS Javascript Engine
3
 *
4
 * Copyright (c) 2017-2021 Fabrice Bellard
5
 * Copyright (c) 2017-2021 Charlie Gordon
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
#ifndef QUICKJS_H
26
#define QUICKJS_H
27
28
#include <stdio.h>
29
#include <stdint.h>
30
#include <string.h>
31
32
#ifdef __cplusplus
33
extern "C" {
34
#endif
35
36
#if defined(__GNUC__) || defined(__clang__)
37
#define js_likely(x)          __builtin_expect(!!(x), 1)
38
13.7M
#define js_unlikely(x)        __builtin_expect(!!(x), 0)
39
#define js_force_inline       inline __attribute__((always_inline))
40
#define __js_printf_like(f, a)   __attribute__((format(printf, f, a)))
41
#else
42
#define js_likely(x)     (x)
43
#define js_unlikely(x)   (x)
44
#define js_force_inline  inline
45
#define __js_printf_like(a, b)
46
#endif
47
48
#define JS_BOOL int
49
50
typedef struct JSRuntime JSRuntime;
51
typedef struct JSContext JSContext;
52
typedef struct JSClass JSClass;
53
typedef uint32_t JSClassID;
54
typedef uint32_t JSAtom;
55
56
#if INTPTR_MAX >= INT64_MAX
57
#define JS_PTR64
58
#define JS_PTR64_DEF(a) a
59
#else
60
#define JS_PTR64_DEF(a)
61
#endif
62
63
#ifndef JS_PTR64
64
#define JS_NAN_BOXING
65
#endif
66
67
#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
68
493M
#define JS_LIMB_BITS 64
69
#else
70
#define JS_LIMB_BITS 32
71
#endif
72
73
0
#define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS
74
    
75
enum {
76
    /* all tags with a reference count are negative */
77
    JS_TAG_FIRST       = -9, /* first negative tag */
78
    JS_TAG_BIG_INT     = -9,
79
    JS_TAG_SYMBOL      = -8,
80
    JS_TAG_STRING      = -7,
81
    JS_TAG_STRING_ROPE = -6,
82
    JS_TAG_MODULE      = -3, /* used internally */
83
    JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
84
    JS_TAG_OBJECT      = -1,
85
86
    JS_TAG_INT         = 0,
87
    JS_TAG_BOOL        = 1,
88
    JS_TAG_NULL        = 2,
89
    JS_TAG_UNDEFINED   = 3,
90
    JS_TAG_UNINITIALIZED = 4,
91
    JS_TAG_CATCH_OFFSET = 5,
92
    JS_TAG_EXCEPTION   = 6,
93
    JS_TAG_SHORT_BIG_INT = 7,
94
    JS_TAG_FLOAT64     = 8,
95
    /* any larger tag is FLOAT64 if JS_NAN_BOXING */
96
};
97
98
typedef struct JSRefCountHeader {
99
    int ref_count;
100
} JSRefCountHeader;
101
102
219k
#define JS_FLOAT64_NAN NAN
103
104
#ifdef CONFIG_CHECK_JSVALUE
105
/* JSValue consistency : it is not possible to run the code in this
106
   mode, but it is useful to detect simple reference counting
107
   errors. It would be interesting to modify a static C analyzer to
108
   handle specific annotations (clang has such annotations but only
109
   for objective C) */
110
typedef struct __JSValue *JSValue;
111
typedef const struct __JSValue *JSValueConst;
112
113
#define JS_VALUE_GET_TAG(v) (int)((uintptr_t)(v) & 0xf)
114
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
115
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
116
#define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)
117
#define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)
118
#define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)
119
#define JS_VALUE_GET_SHORT_BIG_INT(v) JS_VALUE_GET_INT(v)
120
#define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)
121
122
#define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
123
#define JS_MKPTR(tag, p) (JSValue)((intptr_t)(p) | (tag))
124
125
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
126
127
#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64, 1)
128
129
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
130
{
131
    return JS_MKVAL(JS_TAG_FLOAT64, (int)d);
132
}
133
134
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
135
{
136
    return 0;
137
}
138
139
static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
140
{
141
    return JS_MKVAL(JS_TAG_SHORT_BIG_INT, d);
142
}
143
144
#elif defined(JS_NAN_BOXING)
145
146
typedef uint64_t JSValue;
147
148
#define JSValueConst JSValue
149
150
#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
151
#define JS_VALUE_GET_INT(v) (int)(v)
152
#define JS_VALUE_GET_BOOL(v) (int)(v)
153
#define JS_VALUE_GET_SHORT_BIG_INT(v) (int)(v)
154
#define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)
155
156
#define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
157
#define JS_MKPTR(tag, ptr) (((uint64_t)(tag) << 32) | (uintptr_t)(ptr))
158
159
#define JS_FLOAT64_TAG_ADDEND (0x7ff80000 - JS_TAG_FIRST + 1) /* quiet NaN encoding */
160
161
static inline double JS_VALUE_GET_FLOAT64(JSValue v)
162
{
163
    union {
164
        JSValue v;
165
        double d;
166
    } u;
167
    u.v = v;
168
    u.v += (uint64_t)JS_FLOAT64_TAG_ADDEND << 32;
169
    return u.d;
170
}
171
172
#define JS_NAN (0x7ff8000000000000 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32))
173
174
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
175
{
176
    union {
177
        double d;
178
        uint64_t u64;
179
    } u;
180
    JSValue v;
181
    u.d = d;
182
    /* normalize NaN */
183
    if (js_unlikely((u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000))
184
        v = JS_NAN;
185
    else
186
        v = u.u64 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32);
187
    return v;
188
}
189
190
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)((tag) - JS_TAG_FIRST) >= (JS_TAG_FLOAT64 - JS_TAG_FIRST))
191
192
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
193
static inline int JS_VALUE_GET_NORM_TAG(JSValue v)
194
{
195
    uint32_t tag;
196
    tag = JS_VALUE_GET_TAG(v);
197
    if (JS_TAG_IS_FLOAT64(tag))
198
        return JS_TAG_FLOAT64;
199
    else
200
        return tag;
201
}
202
203
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
204
{
205
    uint32_t tag;
206
    tag = JS_VALUE_GET_TAG(v);
207
    return tag == (JS_NAN >> 32);
208
}
209
210
static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
211
{
212
    return JS_MKVAL(JS_TAG_SHORT_BIG_INT, d);
213
}
214
215
#else /* !JS_NAN_BOXING */
216
217
typedef union JSValueUnion {
218
    int32_t int32;
219
    double float64;
220
    void *ptr;
221
#if JS_SHORT_BIG_INT_BITS == 32
222
    int32_t short_big_int;
223
#else
224
    int64_t short_big_int;
225
#endif
226
} JSValueUnion;
227
228
typedef struct JSValue {
229
    JSValueUnion u;
230
    int64_t tag;
231
} JSValue;
232
233
2.54M
#define JSValueConst JSValue
234
235
86.9M
#define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)
236
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
237
13.8M
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
238
5.59M
#define JS_VALUE_GET_INT(v) ((v).u.int32)
239
0
#define JS_VALUE_GET_BOOL(v) ((v).u.int32)
240
376k
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
241
2.19M
#define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int)
242
48.1M
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
243
244
21.2M
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
245
8.87M
#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
246
247
627k
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
248
249
219k
#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
250
251
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
252
188k
{
253
188k
    JSValue v;
254
188k
    v.tag = JS_TAG_FLOAT64;
255
188k
    v.u.float64 = d;
256
188k
    return v;
257
188k
}
Unexecuted instantiation: fuzz_eval.c:__JS_NewFloat64
Unexecuted instantiation: fuzz_common.c:__JS_NewFloat64
quickjs.c:__JS_NewFloat64
Line
Count
Source
252
188k
{
253
188k
    JSValue v;
254
188k
    v.tag = JS_TAG_FLOAT64;
255
188k
    v.u.float64 = d;
256
188k
    return v;
257
188k
}
Unexecuted instantiation: quickjs-libc.c:__JS_NewFloat64
Unexecuted instantiation: fuzz_compile.c:__JS_NewFloat64
Unexecuted instantiation: fuzz_regexp.c:__JS_NewFloat64
258
259
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
260
402
{
261
402
    union {
262
402
        double d;
263
402
        uint64_t u64;
264
402
    } u;
265
402
    if (v.tag != JS_TAG_FLOAT64)
266
373
        return 0;
267
29
    u.d = v.u.float64;
268
29
    return (u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000;
269
402
}
Unexecuted instantiation: fuzz_eval.c:JS_VALUE_IS_NAN
Unexecuted instantiation: fuzz_common.c:JS_VALUE_IS_NAN
quickjs.c:JS_VALUE_IS_NAN
Line
Count
Source
260
402
{
261
402
    union {
262
402
        double d;
263
402
        uint64_t u64;
264
402
    } u;
265
402
    if (v.tag != JS_TAG_FLOAT64)
266
373
        return 0;
267
29
    u.d = v.u.float64;
268
29
    return (u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000;
269
402
}
Unexecuted instantiation: quickjs-libc.c:JS_VALUE_IS_NAN
Unexecuted instantiation: fuzz_compile.c:JS_VALUE_IS_NAN
Unexecuted instantiation: fuzz_regexp.c:JS_VALUE_IS_NAN
270
271
static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
272
1.97M
{
273
1.97M
    JSValue v;
274
1.97M
    v.tag = JS_TAG_SHORT_BIG_INT;
275
1.97M
    v.u.short_big_int = d;
276
1.97M
    return v;
277
1.97M
}
Unexecuted instantiation: fuzz_eval.c:__JS_NewShortBigInt
Unexecuted instantiation: fuzz_common.c:__JS_NewShortBigInt
quickjs.c:__JS_NewShortBigInt
Line
Count
Source
272
1.97M
{
273
1.97M
    JSValue v;
274
1.97M
    v.tag = JS_TAG_SHORT_BIG_INT;
275
1.97M
    v.u.short_big_int = d;
276
1.97M
    return v;
277
1.97M
}
Unexecuted instantiation: quickjs-libc.c:__JS_NewShortBigInt
Unexecuted instantiation: fuzz_compile.c:__JS_NewShortBigInt
Unexecuted instantiation: fuzz_regexp.c:__JS_NewShortBigInt
278
279
#endif /* !JS_NAN_BOXING */
280
281
#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
282
219k
#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) && JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)))
283
284
44.2M
#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)
285
286
/* special values */
287
1.01M
#define JS_NULL      JS_MKVAL(JS_TAG_NULL, 0)
288
11.4M
#define JS_UNDEFINED JS_MKVAL(JS_TAG_UNDEFINED, 0)
289
0
#define JS_FALSE     JS_MKVAL(JS_TAG_BOOL, 0)
290
518
#define JS_TRUE      JS_MKVAL(JS_TAG_BOOL, 1)
291
1.22M
#define JS_EXCEPTION JS_MKVAL(JS_TAG_EXCEPTION, 0)
292
345k
#define JS_UNINITIALIZED JS_MKVAL(JS_TAG_UNINITIALIZED, 0)
293
294
/* flags for object properties */
295
5.25M
#define JS_PROP_CONFIGURABLE  (1 << 0)
296
4.12M
#define JS_PROP_WRITABLE      (1 << 1)
297
3.30M
#define JS_PROP_ENUMERABLE    (1 << 2)
298
2.61M
#define JS_PROP_C_W_E         (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE | JS_PROP_ENUMERABLE)
299
439k
#define JS_PROP_LENGTH        (1 << 3) /* used internally in Arrays */
300
4.18M
#define JS_PROP_TMASK         (3 << 4) /* mask for NORMAL, GETSET, VARREF, AUTOINIT */
301
188k
#define JS_PROP_NORMAL         (0 << 4)
302
276k
#define JS_PROP_GETSET         (1 << 4)
303
429k
#define JS_PROP_VARREF         (2 << 4) /* used internally */
304
295k
#define JS_PROP_AUTOINIT       (3 << 4) /* used internally */
305
306
/* flags for JS_DefineProperty */
307
525k
#define JS_PROP_HAS_SHIFT        8
308
2.36M
#define JS_PROP_HAS_CONFIGURABLE (1 << 8)
309
2.51M
#define JS_PROP_HAS_WRITABLE     (1 << 9)
310
2.36M
#define JS_PROP_HAS_ENUMERABLE   (1 << 10)
311
3.88M
#define JS_PROP_HAS_GET          (1 << 11)
312
3.88M
#define JS_PROP_HAS_SET          (1 << 12)
313
4.04M
#define JS_PROP_HAS_VALUE        (1 << 13)
314
315
/* throw an exception if false would be returned
316
   (JS_DefineProperty/JS_SetProperty) */
317
2.14M
#define JS_PROP_THROW            (1 << 14)
318
/* throw an exception if false would be returned in strict mode
319
   (JS_SetProperty) */
320
60
#define JS_PROP_THROW_STRICT     (1 << 15)
321
322
0
#define JS_PROP_NO_ADD           (1 << 16) /* internal use */
323
420
#define JS_PROP_NO_EXOTIC        (1 << 17) /* internal use */
324
325
#ifndef JS_DEFAULT_STACK_SIZE
326
30
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
327
#endif
328
329
/* JS_Eval() flags */
330
261
#define JS_EVAL_TYPE_GLOBAL   (0 << 0) /* global code (default) */
331
207
#define JS_EVAL_TYPE_MODULE   (1 << 0) /* module code */
332
31.8k
#define JS_EVAL_TYPE_DIRECT   (2 << 0) /* direct call (internal use) */
333
73
#define JS_EVAL_TYPE_INDIRECT (3 << 0) /* indirect call (internal use) */
334
122
#define JS_EVAL_TYPE_MASK     (3 << 0)
335
336
62
#define JS_EVAL_FLAG_STRICT   (1 << 3) /* force 'strict' mode */
337
/* compile but do not run. The result is an object with a
338
   JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed
339
   with JS_EvalFunction(). */
340
94
#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)
341
/* don't include the stack frames before this eval in the Error() backtraces */
342
62
#define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6)
343
/* allow top-level await in normal script. JS_Eval() returns a
344
   promise. Only allowed with JS_EVAL_TYPE_GLOBAL */
345
22
#define JS_EVAL_FLAG_ASYNC (1 << 7)
346
347
typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
348
typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
349
typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);
350
351
typedef struct JSMallocState {
352
    size_t malloc_count;
353
    size_t malloc_size;
354
    size_t malloc_limit;
355
    void *opaque; /* user opaque */
356
} JSMallocState;
357
358
typedef struct JSMallocFunctions {
359
    void *(*js_malloc)(JSMallocState *s, size_t size);
360
    void (*js_free)(JSMallocState *s, void *ptr);
361
    void *(*js_realloc)(JSMallocState *s, void *ptr, size_t size);
362
    size_t (*js_malloc_usable_size)(const void *ptr);
363
} JSMallocFunctions;
364
365
typedef struct JSGCObjectHeader JSGCObjectHeader;
366
367
JSRuntime *JS_NewRuntime(void);
368
/* info lifetime must exceed that of rt */
369
void JS_SetRuntimeInfo(JSRuntime *rt, const char *info);
370
void JS_SetMemoryLimit(JSRuntime *rt, size_t limit);
371
void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);
372
/* use 0 to disable maximum stack size check */
373
void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size);
374
/* should be called when changing thread to update the stack top value
375
   used to check stack overflow. */
376
void JS_UpdateStackTop(JSRuntime *rt);
377
JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque);
378
void JS_FreeRuntime(JSRuntime *rt);
379
void *JS_GetRuntimeOpaque(JSRuntime *rt);
380
void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque);
381
typedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp);
382
void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func);
383
void JS_RunGC(JSRuntime *rt);
384
JS_BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj);
385
386
JSContext *JS_NewContext(JSRuntime *rt);
387
void JS_FreeContext(JSContext *s);
388
JSContext *JS_DupContext(JSContext *ctx);
389
void *JS_GetContextOpaque(JSContext *ctx);
390
void JS_SetContextOpaque(JSContext *ctx, void *opaque);
391
JSRuntime *JS_GetRuntime(JSContext *ctx);
392
void JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj);
393
JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id);
394
395
/* the following functions are used to select the intrinsic object to
396
   save memory */
397
JSContext *JS_NewContextRaw(JSRuntime *rt);
398
void JS_AddIntrinsicBaseObjects(JSContext *ctx);
399
void JS_AddIntrinsicDate(JSContext *ctx);
400
void JS_AddIntrinsicEval(JSContext *ctx);
401
void JS_AddIntrinsicStringNormalize(JSContext *ctx);
402
void JS_AddIntrinsicRegExpCompiler(JSContext *ctx);
403
void JS_AddIntrinsicRegExp(JSContext *ctx);
404
void JS_AddIntrinsicJSON(JSContext *ctx);
405
void JS_AddIntrinsicProxy(JSContext *ctx);
406
void JS_AddIntrinsicMapSet(JSContext *ctx);
407
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
408
void JS_AddIntrinsicPromise(JSContext *ctx);
409
void JS_AddIntrinsicWeakRef(JSContext *ctx);
410
411
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
412
                                 int argc, JSValueConst *argv);
413
414
void *js_malloc_rt(JSRuntime *rt, size_t size);
415
void js_free_rt(JSRuntime *rt, void *ptr);
416
void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size);
417
size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr);
418
void *js_mallocz_rt(JSRuntime *rt, size_t size);
419
420
void *js_malloc(JSContext *ctx, size_t size);
421
void js_free(JSContext *ctx, void *ptr);
422
void *js_realloc(JSContext *ctx, void *ptr, size_t size);
423
size_t js_malloc_usable_size(JSContext *ctx, const void *ptr);
424
void *js_realloc2(JSContext *ctx, void *ptr, size_t size, size_t *pslack);
425
void *js_mallocz(JSContext *ctx, size_t size);
426
char *js_strdup(JSContext *ctx, const char *str);
427
char *js_strndup(JSContext *ctx, const char *s, size_t n);
428
429
typedef struct JSMemoryUsage {
430
    int64_t malloc_size, malloc_limit, memory_used_size;
431
    int64_t malloc_count;
432
    int64_t memory_used_count;
433
    int64_t atom_count, atom_size;
434
    int64_t str_count, str_size;
435
    int64_t obj_count, obj_size;
436
    int64_t prop_count, prop_size;
437
    int64_t shape_count, shape_size;
438
    int64_t js_func_count, js_func_size, js_func_code_size;
439
    int64_t js_func_pc2line_count, js_func_pc2line_size;
440
    int64_t c_func_count, array_count;
441
    int64_t fast_array_count, fast_array_elements;
442
    int64_t binary_object_count, binary_object_size;
443
} JSMemoryUsage;
444
445
void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s);
446
void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt);
447
448
/* atom support */
449
3.96M
#define JS_ATOM_NULL 0
450
451
JSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len);
452
JSAtom JS_NewAtom(JSContext *ctx, const char *str);
453
JSAtom JS_NewAtomUInt32(JSContext *ctx, uint32_t n);
454
JSAtom JS_DupAtom(JSContext *ctx, JSAtom v);
455
void JS_FreeAtom(JSContext *ctx, JSAtom v);
456
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
457
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
458
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
459
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom);
460
static inline const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
461
94.2k
{
462
94.2k
    return JS_AtomToCStringLen(ctx, NULL, atom);
463
94.2k
}
Unexecuted instantiation: fuzz_eval.c:JS_AtomToCString
Unexecuted instantiation: fuzz_common.c:JS_AtomToCString
quickjs.c:JS_AtomToCString
Line
Count
Source
461
94.2k
{
462
94.2k
    return JS_AtomToCStringLen(ctx, NULL, atom);
463
94.2k
}
quickjs-libc.c:JS_AtomToCString
Line
Count
Source
461
37
{
462
37
    return JS_AtomToCStringLen(ctx, NULL, atom);
463
37
}
Unexecuted instantiation: fuzz_compile.c:JS_AtomToCString
Unexecuted instantiation: fuzz_regexp.c:JS_AtomToCString
464
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
465
466
/* object class support */
467
468
typedef struct JSPropertyEnum {
469
    JS_BOOL is_enumerable;
470
    JSAtom atom;
471
} JSPropertyEnum;
472
473
typedef struct JSPropertyDescriptor {
474
    int flags;
475
    JSValue value;
476
    JSValue getter;
477
    JSValue setter;
478
} JSPropertyDescriptor;
479
480
typedef struct JSClassExoticMethods {
481
    /* Return -1 if exception (can only happen in case of Proxy object),
482
       FALSE if the property does not exists, TRUE if it exists. If 1 is
483
       returned, the property descriptor 'desc' is filled if != NULL. */
484
    int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,
485
                             JSValueConst obj, JSAtom prop);
486
    /* '*ptab' should hold the '*plen' property keys. Return 0 if OK,
487
       -1 if exception. The 'is_enumerable' field is ignored.
488
    */
489
    int (*get_own_property_names)(JSContext *ctx, JSPropertyEnum **ptab,
490
                                  uint32_t *plen,
491
                                  JSValueConst obj);
492
    /* return < 0 if exception, or TRUE/FALSE */
493
    int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);
494
    /* return < 0 if exception or TRUE/FALSE */
495
    int (*define_own_property)(JSContext *ctx, JSValueConst this_obj,
496
                               JSAtom prop, JSValueConst val,
497
                               JSValueConst getter, JSValueConst setter,
498
                               int flags);
499
    /* The following methods can be emulated with the previous ones,
500
       so they are usually not needed */
501
    /* return < 0 if exception or TRUE/FALSE */
502
    int (*has_property)(JSContext *ctx, JSValueConst obj, JSAtom atom);
503
    JSValue (*get_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
504
                            JSValueConst receiver);
505
    /* return < 0 if exception or TRUE/FALSE */
506
    int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
507
                        JSValueConst value, JSValueConst receiver, int flags);
508
509
    /* To get a consistent object behavior when get_prototype != NULL,
510
       get_property, set_property and set_prototype must be != NULL
511
       and the object must be created with a JS_NULL prototype. */
512
    JSValue (*get_prototype)(JSContext *ctx, JSValueConst obj);
513
    /* return < 0 if exception or TRUE/FALSE */
514
    int (*set_prototype)(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
515
    /* return < 0 if exception or TRUE/FALSE */
516
    int (*is_extensible)(JSContext *ctx, JSValueConst obj);
517
    /* return < 0 if exception or TRUE/FALSE */
518
    int (*prevent_extensions)(JSContext *ctx, JSValueConst obj);
519
} JSClassExoticMethods;
520
521
typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
522
typedef void JSClassGCMark(JSRuntime *rt, JSValueConst val,
523
                           JS_MarkFunc *mark_func);
524
94.0k
#define JS_CALL_FLAG_CONSTRUCTOR (1 << 0)
525
typedef JSValue JSClassCall(JSContext *ctx, JSValueConst func_obj,
526
                            JSValueConst this_val, int argc, JSValueConst *argv,
527
                            int flags);
528
529
typedef struct JSClassDef {
530
    const char *class_name;
531
    JSClassFinalizer *finalizer;
532
    JSClassGCMark *gc_mark;
533
    /* if call != NULL, the object is a function. If (flags &
534
       JS_CALL_FLAG_CONSTRUCTOR) != 0, the function is called as a
535
       constructor. In this case, 'this_val' is new.target. A
536
       constructor call only happens if the object constructor bit is
537
       set (see JS_SetConstructorBit()). */
538
    JSClassCall *call;
539
    /* XXX: suppress this indirection ? It is here only to save memory
540
       because only a few classes need these methods */
541
    JSClassExoticMethods *exotic;
542
} JSClassDef;
543
544
0
#define JS_INVALID_CLASS_ID 0
545
JSClassID JS_NewClassID(JSClassID *pclass_id);
546
/* Returns the class ID if `v` is an object, otherwise returns JS_INVALID_CLASS_ID. */
547
JSClassID JS_GetClassID(JSValue v);
548
int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);
549
int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
550
551
/* value handling */
552
553
static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
554
1.12M
{
555
1.12M
    return JS_MKVAL(JS_TAG_BOOL, (val != 0));
556
1.12M
}
Unexecuted instantiation: fuzz_eval.c:JS_NewBool
Unexecuted instantiation: fuzz_common.c:JS_NewBool
quickjs.c:JS_NewBool
Line
Count
Source
554
1.12M
{
555
1.12M
    return JS_MKVAL(JS_TAG_BOOL, (val != 0));
556
1.12M
}
quickjs-libc.c:JS_NewBool
Line
Count
Source
554
7
{
555
7
    return JS_MKVAL(JS_TAG_BOOL, (val != 0));
556
7
}
Unexecuted instantiation: fuzz_compile.c:JS_NewBool
Unexecuted instantiation: fuzz_regexp.c:JS_NewBool
557
558
static js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)
559
5.79M
{
560
5.79M
    return JS_MKVAL(JS_TAG_INT, val);
561
5.79M
}
Unexecuted instantiation: fuzz_eval.c:JS_NewInt32
Unexecuted instantiation: fuzz_common.c:JS_NewInt32
quickjs.c:JS_NewInt32
Line
Count
Source
559
5.79M
{
560
5.79M
    return JS_MKVAL(JS_TAG_INT, val);
561
5.79M
}
Unexecuted instantiation: quickjs-libc.c:JS_NewInt32
Unexecuted instantiation: fuzz_compile.c:JS_NewInt32
Unexecuted instantiation: fuzz_regexp.c:JS_NewInt32
562
563
static js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val)
564
188k
{
565
188k
    return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);
566
188k
}
Unexecuted instantiation: fuzz_eval.c:JS_NewCatchOffset
Unexecuted instantiation: fuzz_common.c:JS_NewCatchOffset
quickjs.c:JS_NewCatchOffset
Line
Count
Source
564
188k
{
565
188k
    return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);
566
188k
}
Unexecuted instantiation: quickjs-libc.c:JS_NewCatchOffset
Unexecuted instantiation: fuzz_compile.c:JS_NewCatchOffset
Unexecuted instantiation: fuzz_regexp.c:JS_NewCatchOffset
567
568
static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val)
569
525k
{
570
525k
    JSValue v;
571
525k
    if (val == (int32_t)val) {
572
525k
        v = JS_NewInt32(ctx, val);
573
525k
    } else {
574
0
        v = __JS_NewFloat64(ctx, val);
575
0
    }
576
525k
    return v;
577
525k
}
Unexecuted instantiation: fuzz_eval.c:JS_NewInt64
Unexecuted instantiation: fuzz_common.c:JS_NewInt64
quickjs.c:JS_NewInt64
Line
Count
Source
569
525k
{
570
525k
    JSValue v;
571
525k
    if (val == (int32_t)val) {
572
525k
        v = JS_NewInt32(ctx, val);
573
525k
    } else {
574
0
        v = __JS_NewFloat64(ctx, val);
575
0
    }
576
525k
    return v;
577
525k
}
Unexecuted instantiation: quickjs-libc.c:JS_NewInt64
Unexecuted instantiation: fuzz_compile.c:JS_NewInt64
Unexecuted instantiation: fuzz_regexp.c:JS_NewInt64
578
579
static js_force_inline JSValue JS_NewUint32(JSContext *ctx, uint32_t val)
580
651k
{
581
651k
    JSValue v;
582
651k
    if (val <= 0x7fffffff) {
583
651k
        v = JS_NewInt32(ctx, val);
584
651k
    } else {
585
0
        v = __JS_NewFloat64(ctx, val);
586
0
    }
587
651k
    return v;
588
651k
}
Unexecuted instantiation: fuzz_eval.c:JS_NewUint32
Unexecuted instantiation: fuzz_common.c:JS_NewUint32
quickjs.c:JS_NewUint32
Line
Count
Source
580
651k
{
581
651k
    JSValue v;
582
651k
    if (val <= 0x7fffffff) {
583
651k
        v = JS_NewInt32(ctx, val);
584
651k
    } else {
585
0
        v = __JS_NewFloat64(ctx, val);
586
0
    }
587
651k
    return v;
588
651k
}
Unexecuted instantiation: quickjs-libc.c:JS_NewUint32
Unexecuted instantiation: fuzz_compile.c:JS_NewUint32
Unexecuted instantiation: fuzz_regexp.c:JS_NewUint32
589
590
JSValue JS_NewBigInt64(JSContext *ctx, int64_t v);
591
JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v);
592
593
static js_force_inline JSValue JS_NewFloat64(JSContext *ctx, double d)
594
94.2k
{
595
94.2k
    int32_t val;
596
94.2k
    union {
597
94.2k
        double d;
598
94.2k
        uint64_t u;
599
94.2k
    } u, t;
600
94.2k
    if (d >= INT32_MIN && d <= INT32_MAX) {
601
94.2k
        u.d = d;
602
94.2k
        val = (int32_t)d;
603
94.2k
        t.d = val;
604
        /* -0 cannot be represented as integer, so we compare the bit
605
           representation */
606
94.2k
        if (u.u == t.u)
607
94.2k
            return JS_MKVAL(JS_TAG_INT, val);
608
94.2k
    }
609
29
    return __JS_NewFloat64(ctx, d);
610
94.2k
}
Unexecuted instantiation: fuzz_eval.c:JS_NewFloat64
Unexecuted instantiation: fuzz_common.c:JS_NewFloat64
quickjs.c:JS_NewFloat64
Line
Count
Source
594
94.2k
{
595
94.2k
    int32_t val;
596
94.2k
    union {
597
94.2k
        double d;
598
94.2k
        uint64_t u;
599
94.2k
    } u, t;
600
94.2k
    if (d >= INT32_MIN && d <= INT32_MAX) {
601
94.2k
        u.d = d;
602
94.2k
        val = (int32_t)d;
603
94.2k
        t.d = val;
604
        /* -0 cannot be represented as integer, so we compare the bit
605
           representation */
606
94.2k
        if (u.u == t.u)
607
94.2k
            return JS_MKVAL(JS_TAG_INT, val);
608
94.2k
    }
609
29
    return __JS_NewFloat64(ctx, d);
610
94.2k
}
Unexecuted instantiation: quickjs-libc.c:JS_NewFloat64
Unexecuted instantiation: fuzz_compile.c:JS_NewFloat64
Unexecuted instantiation: fuzz_regexp.c:JS_NewFloat64
611
612
static inline JS_BOOL JS_IsNumber(JSValueConst v)
613
94.0k
{
614
94.0k
    int tag = JS_VALUE_GET_TAG(v);
615
94.0k
    return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag);
616
94.0k
}
Unexecuted instantiation: fuzz_eval.c:JS_IsNumber
Unexecuted instantiation: fuzz_common.c:JS_IsNumber
quickjs.c:JS_IsNumber
Line
Count
Source
613
94.0k
{
614
94.0k
    int tag = JS_VALUE_GET_TAG(v);
615
94.0k
    return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag);
616
94.0k
}
Unexecuted instantiation: quickjs-libc.c:JS_IsNumber
Unexecuted instantiation: fuzz_compile.c:JS_IsNumber
Unexecuted instantiation: fuzz_regexp.c:JS_IsNumber
617
618
static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v)
619
0
{
620
0
    int tag = JS_VALUE_GET_TAG(v);
621
0
    return tag == JS_TAG_BIG_INT || tag == JS_TAG_SHORT_BIG_INT;
622
0
}
Unexecuted instantiation: fuzz_eval.c:JS_IsBigInt
Unexecuted instantiation: fuzz_common.c:JS_IsBigInt
Unexecuted instantiation: quickjs.c:JS_IsBigInt
Unexecuted instantiation: quickjs-libc.c:JS_IsBigInt
Unexecuted instantiation: fuzz_compile.c:JS_IsBigInt
Unexecuted instantiation: fuzz_regexp.c:JS_IsBigInt
623
624
static inline JS_BOOL JS_IsBool(JSValueConst v)
625
0
{
626
0
    return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL;
627
0
}
Unexecuted instantiation: fuzz_eval.c:JS_IsBool
Unexecuted instantiation: fuzz_common.c:JS_IsBool
Unexecuted instantiation: quickjs.c:JS_IsBool
Unexecuted instantiation: quickjs-libc.c:JS_IsBool
Unexecuted instantiation: fuzz_compile.c:JS_IsBool
Unexecuted instantiation: fuzz_regexp.c:JS_IsBool
628
629
static inline JS_BOOL JS_IsNull(JSValueConst v)
630
2.57M
{
631
2.57M
    return JS_VALUE_GET_TAG(v) == JS_TAG_NULL;
632
2.57M
}
Unexecuted instantiation: fuzz_eval.c:JS_IsNull
Unexecuted instantiation: fuzz_common.c:JS_IsNull
quickjs.c:JS_IsNull
Line
Count
Source
630
2.57M
{
631
2.57M
    return JS_VALUE_GET_TAG(v) == JS_TAG_NULL;
632
2.57M
}
Unexecuted instantiation: quickjs-libc.c:JS_IsNull
Unexecuted instantiation: fuzz_compile.c:JS_IsNull
Unexecuted instantiation: fuzz_regexp.c:JS_IsNull
633
634
static inline JS_BOOL JS_IsUndefined(JSValueConst v)
635
1.15M
{
636
1.15M
    return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;
637
1.15M
}
Unexecuted instantiation: fuzz_eval.c:JS_IsUndefined
Unexecuted instantiation: fuzz_common.c:JS_IsUndefined
quickjs.c:JS_IsUndefined
Line
Count
Source
635
1.15M
{
636
1.15M
    return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;
637
1.15M
}
Unexecuted instantiation: quickjs-libc.c:JS_IsUndefined
Unexecuted instantiation: fuzz_compile.c:JS_IsUndefined
Unexecuted instantiation: fuzz_regexp.c:JS_IsUndefined
638
639
static inline JS_BOOL JS_IsException(JSValueConst v)
640
13.6M
{
641
13.6M
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
13.6M
}
fuzz_eval.c:JS_IsException
Line
Count
Source
640
20
{
641
20
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
20
}
fuzz_common.c:JS_IsException
Line
Count
Source
640
30
{
641
30
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
30
}
quickjs.c:JS_IsException
Line
Count
Source
640
13.6M
{
641
13.6M
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
13.6M
}
quickjs-libc.c:JS_IsException
Line
Count
Source
640
94
{
641
94
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
94
}
fuzz_compile.c:JS_IsException
Line
Count
Source
640
24
{
641
24
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
642
24
}
Unexecuted instantiation: fuzz_regexp.c:JS_IsException
643
644
static inline JS_BOOL JS_IsUninitialized(JSValueConst v)
645
94.1k
{
646
94.1k
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED);
647
94.1k
}
Unexecuted instantiation: fuzz_eval.c:JS_IsUninitialized
Unexecuted instantiation: fuzz_common.c:JS_IsUninitialized
quickjs.c:JS_IsUninitialized
Line
Count
Source
645
94.1k
{
646
94.1k
    return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED);
647
94.1k
}
Unexecuted instantiation: quickjs-libc.c:JS_IsUninitialized
Unexecuted instantiation: fuzz_compile.c:JS_IsUninitialized
Unexecuted instantiation: fuzz_regexp.c:JS_IsUninitialized
648
649
static inline JS_BOOL JS_IsString(JSValueConst v)
650
188k
{
651
188k
    return JS_VALUE_GET_TAG(v) == JS_TAG_STRING ||
652
188k
        JS_VALUE_GET_TAG(v) == JS_TAG_STRING_ROPE;
653
188k
}
Unexecuted instantiation: fuzz_eval.c:JS_IsString
Unexecuted instantiation: fuzz_common.c:JS_IsString
quickjs.c:JS_IsString
Line
Count
Source
650
188k
{
651
188k
    return JS_VALUE_GET_TAG(v) == JS_TAG_STRING ||
652
188k
        JS_VALUE_GET_TAG(v) == JS_TAG_STRING_ROPE;
653
188k
}
Unexecuted instantiation: quickjs-libc.c:JS_IsString
Unexecuted instantiation: fuzz_compile.c:JS_IsString
Unexecuted instantiation: fuzz_regexp.c:JS_IsString
654
655
static inline JS_BOOL JS_IsSymbol(JSValueConst v)
656
0
{
657
0
    return JS_VALUE_GET_TAG(v) == JS_TAG_SYMBOL;
658
0
}
Unexecuted instantiation: fuzz_eval.c:JS_IsSymbol
Unexecuted instantiation: fuzz_common.c:JS_IsSymbol
Unexecuted instantiation: quickjs.c:JS_IsSymbol
Unexecuted instantiation: quickjs-libc.c:JS_IsSymbol
Unexecuted instantiation: fuzz_compile.c:JS_IsSymbol
Unexecuted instantiation: fuzz_regexp.c:JS_IsSymbol
659
660
static inline JS_BOOL JS_IsObject(JSValueConst v)
661
1.41M
{
662
1.41M
    return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;
663
1.41M
}
Unexecuted instantiation: fuzz_eval.c:JS_IsObject
Unexecuted instantiation: fuzz_common.c:JS_IsObject
quickjs.c:JS_IsObject
Line
Count
Source
661
1.41M
{
662
1.41M
    return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;
663
1.41M
}
Unexecuted instantiation: quickjs-libc.c:JS_IsObject
Unexecuted instantiation: fuzz_compile.c:JS_IsObject
Unexecuted instantiation: fuzz_regexp.c:JS_IsObject
664
665
JSValue JS_Throw(JSContext *ctx, JSValue obj);
666
void JS_SetUncatchableException(JSContext *ctx, JS_BOOL flag);
667
JSValue JS_GetException(JSContext *ctx);
668
JS_BOOL JS_HasException(JSContext *ctx);
669
JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
670
JSValue JS_NewError(JSContext *ctx);
671
JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
672
JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
673
JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...);
674
JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...);
675
JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
676
JSValue JS_ThrowOutOfMemory(JSContext *ctx);
677
678
void __JS_FreeValue(JSContext *ctx, JSValue v);
679
static inline void JS_FreeValue(JSContext *ctx, JSValue v)
680
20.5M
{
681
20.5M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
8.63M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
8.63M
        if (--p->ref_count <= 0) {
684
848k
            __JS_FreeValue(ctx, v);
685
848k
        }
686
8.63M
    }
687
20.5M
}
fuzz_eval.c:JS_FreeValue
Line
Count
Source
680
7
{
681
7
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
2
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
2
        if (--p->ref_count <= 0) {
684
2
            __JS_FreeValue(ctx, v);
685
2
        }
686
2
    }
687
7
}
fuzz_common.c:JS_FreeValue
Line
Count
Source
680
30
{
681
30
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
0
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
0
        if (--p->ref_count <= 0) {
684
0
            __JS_FreeValue(ctx, v);
685
0
        }
686
0
    }
687
30
}
quickjs.c:JS_FreeValue
Line
Count
Source
680
20.5M
{
681
20.5M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
8.63M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
8.63M
        if (--p->ref_count <= 0) {
684
848k
            __JS_FreeValue(ctx, v);
685
848k
        }
686
8.63M
    }
687
20.5M
}
quickjs-libc.c:JS_FreeValue
Line
Count
Source
680
66
{
681
66
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
66
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
66
        if (--p->ref_count <= 0) {
684
0
            __JS_FreeValue(ctx, v);
685
0
        }
686
66
    }
687
66
}
fuzz_compile.c:JS_FreeValue
Line
Count
Source
680
17
{
681
17
    if (JS_VALUE_HAS_REF_COUNT(v)) {
682
14
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
683
14
        if (--p->ref_count <= 0) {
684
0
            __JS_FreeValue(ctx, v);
685
0
        }
686
14
    }
687
17
}
Unexecuted instantiation: fuzz_regexp.c:JS_FreeValue
688
void __JS_FreeValueRT(JSRuntime *rt, JSValue v);
689
static inline void JS_FreeValueRT(JSRuntime *rt, JSValue v)
690
3.81M
{
691
3.81M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
692
3.15M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
693
3.15M
        if (--p->ref_count <= 0) {
694
712k
            __JS_FreeValueRT(rt, v);
695
712k
        }
696
3.15M
    }
697
3.81M
}
Unexecuted instantiation: fuzz_eval.c:JS_FreeValueRT
Unexecuted instantiation: fuzz_common.c:JS_FreeValueRT
quickjs.c:JS_FreeValueRT
Line
Count
Source
690
3.81M
{
691
3.81M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
692
3.15M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
693
3.15M
        if (--p->ref_count <= 0) {
694
712k
            __JS_FreeValueRT(rt, v);
695
712k
        }
696
3.15M
    }
697
3.81M
}
Unexecuted instantiation: quickjs-libc.c:JS_FreeValueRT
Unexecuted instantiation: fuzz_compile.c:JS_FreeValueRT
Unexecuted instantiation: fuzz_regexp.c:JS_FreeValueRT
698
699
static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
700
13.6M
{
701
13.6M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
702
10.2M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
703
10.2M
        p->ref_count++;
704
10.2M
    }
705
13.6M
    return (JSValue)v;
706
13.6M
}
Unexecuted instantiation: fuzz_eval.c:JS_DupValue
Unexecuted instantiation: fuzz_common.c:JS_DupValue
quickjs.c:JS_DupValue
Line
Count
Source
700
13.6M
{
701
13.6M
    if (JS_VALUE_HAS_REF_COUNT(v)) {
702
10.2M
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
703
10.2M
        p->ref_count++;
704
10.2M
    }
705
13.6M
    return (JSValue)v;
706
13.6M
}
Unexecuted instantiation: quickjs-libc.c:JS_DupValue
Unexecuted instantiation: fuzz_compile.c:JS_DupValue
Unexecuted instantiation: fuzz_regexp.c:JS_DupValue
707
708
static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
709
0
{
710
0
    if (JS_VALUE_HAS_REF_COUNT(v)) {
711
0
        JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
712
0
        p->ref_count++;
713
0
    }
714
0
    return (JSValue)v;
715
0
}
Unexecuted instantiation: fuzz_eval.c:JS_DupValueRT
Unexecuted instantiation: fuzz_common.c:JS_DupValueRT
Unexecuted instantiation: quickjs.c:JS_DupValueRT
Unexecuted instantiation: quickjs-libc.c:JS_DupValueRT
Unexecuted instantiation: fuzz_compile.c:JS_DupValueRT
Unexecuted instantiation: fuzz_regexp.c:JS_DupValueRT
716
717
JS_BOOL JS_StrictEq(JSContext *ctx, JSValueConst op1, JSValueConst op2);
718
JS_BOOL JS_SameValue(JSContext *ctx, JSValueConst op1, JSValueConst op2);
719
JS_BOOL JS_SameValueZero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
720
721
int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
722
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
723
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
724
20
{
725
20
    return JS_ToInt32(ctx, (int32_t*)pres, val);
726
20
}
Unexecuted instantiation: fuzz_eval.c:JS_ToUint32
Unexecuted instantiation: fuzz_common.c:JS_ToUint32
quickjs.c:JS_ToUint32
Line
Count
Source
724
20
{
725
20
    return JS_ToInt32(ctx, (int32_t*)pres, val);
726
20
}
Unexecuted instantiation: quickjs-libc.c:JS_ToUint32
Unexecuted instantiation: fuzz_compile.c:JS_ToUint32
Unexecuted instantiation: fuzz_regexp.c:JS_ToUint32
727
int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
728
int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val);
729
int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);
730
/* return an exception if 'val' is a Number */
731
int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
732
/* same as JS_ToInt64() but allow BigInt */
733
int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
734
735
JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
736
static inline JSValue JS_NewString(JSContext *ctx, const char *str)
737
376k
{
738
376k
    return JS_NewStringLen(ctx, str, strlen(str));
739
376k
}
Unexecuted instantiation: fuzz_eval.c:JS_NewString
Unexecuted instantiation: fuzz_common.c:JS_NewString
quickjs.c:JS_NewString
Line
Count
Source
737
376k
{
738
376k
    return JS_NewStringLen(ctx, str, strlen(str));
739
376k
}
quickjs-libc.c:JS_NewString
Line
Count
Source
737
7
{
738
7
    return JS_NewStringLen(ctx, str, strlen(str));
739
7
}
Unexecuted instantiation: fuzz_compile.c:JS_NewString
Unexecuted instantiation: fuzz_regexp.c:JS_NewString
740
JSValue JS_NewAtomString(JSContext *ctx, const char *str);
741
JSValue JS_ToString(JSContext *ctx, JSValueConst val);
742
JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val);
743
const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, JS_BOOL cesu8);
744
static inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValueConst val1)
745
251k
{
746
251k
    return JS_ToCStringLen2(ctx, plen, val1, 0);
747
251k
}
Unexecuted instantiation: fuzz_eval.c:JS_ToCStringLen
Unexecuted instantiation: fuzz_common.c:JS_ToCStringLen
quickjs.c:JS_ToCStringLen
Line
Count
Source
745
251k
{
746
251k
    return JS_ToCStringLen2(ctx, plen, val1, 0);
747
251k
}
Unexecuted instantiation: quickjs-libc.c:JS_ToCStringLen
Unexecuted instantiation: fuzz_compile.c:JS_ToCStringLen
Unexecuted instantiation: fuzz_regexp.c:JS_ToCStringLen
748
static inline const char *JS_ToCString(JSContext *ctx, JSValueConst val1)
749
219k
{
750
219k
    return JS_ToCStringLen2(ctx, NULL, val1, 0);
751
219k
}
Unexecuted instantiation: fuzz_eval.c:JS_ToCString
Unexecuted instantiation: fuzz_common.c:JS_ToCString
quickjs.c:JS_ToCString
Line
Count
Source
749
219k
{
750
219k
    return JS_ToCStringLen2(ctx, NULL, val1, 0);
751
219k
}
Unexecuted instantiation: quickjs-libc.c:JS_ToCString
Unexecuted instantiation: fuzz_compile.c:JS_ToCString
Unexecuted instantiation: fuzz_regexp.c:JS_ToCString
752
void JS_FreeCString(JSContext *ctx, const char *ptr);
753
754
JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto, JSClassID class_id);
755
JSValue JS_NewObjectClass(JSContext *ctx, int class_id);
756
JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto);
757
JSValue JS_NewObject(JSContext *ctx);
758
759
JS_BOOL JS_IsFunction(JSContext* ctx, JSValueConst val);
760
JS_BOOL JS_IsConstructor(JSContext* ctx, JSValueConst val);
761
JS_BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, JS_BOOL val);
762
763
JSValue JS_NewArray(JSContext *ctx);
764
int JS_IsArray(JSContext *ctx, JSValueConst val);
765
766
JSValue JS_NewDate(JSContext *ctx, double epoch_ms);
767
768
JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
769
                               JSAtom prop, JSValueConst receiver,
770
                               JS_BOOL throw_ref_error);
771
static js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj,
772
                                              JSAtom prop)
773
2.27M
{
774
2.27M
    return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);
775
2.27M
}
Unexecuted instantiation: fuzz_eval.c:JS_GetProperty
Unexecuted instantiation: fuzz_common.c:JS_GetProperty
quickjs.c:JS_GetProperty
Line
Count
Source
773
2.27M
{
774
2.27M
    return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);
775
2.27M
}
Unexecuted instantiation: quickjs-libc.c:JS_GetProperty
Unexecuted instantiation: fuzz_compile.c:JS_GetProperty
Unexecuted instantiation: fuzz_regexp.c:JS_GetProperty
776
JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,
777
                          const char *prop);
778
JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
779
                             uint32_t idx);
780
781
int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj,
782
                           JSAtom prop, JSValue val, JSValueConst this_obj,
783
                           int flags);
784
static inline int JS_SetProperty(JSContext *ctx, JSValueConst this_obj,
785
                                 JSAtom prop, JSValue val)
786
2.08M
{
787
2.08M
    return JS_SetPropertyInternal(ctx, this_obj, prop, val, this_obj, JS_PROP_THROW);
788
2.08M
}
Unexecuted instantiation: fuzz_eval.c:JS_SetProperty
Unexecuted instantiation: fuzz_common.c:JS_SetProperty
quickjs.c:JS_SetProperty
Line
Count
Source
786
2.08M
{
787
2.08M
    return JS_SetPropertyInternal(ctx, this_obj, prop, val, this_obj, JS_PROP_THROW);
788
2.08M
}
Unexecuted instantiation: quickjs-libc.c:JS_SetProperty
Unexecuted instantiation: fuzz_compile.c:JS_SetProperty
Unexecuted instantiation: fuzz_regexp.c:JS_SetProperty
789
int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
790
                         uint32_t idx, JSValue val);
791
int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
792
                        int64_t idx, JSValue val);
793
int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
794
                      const char *prop, JSValue val);
795
int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
796
int JS_IsExtensible(JSContext *ctx, JSValueConst obj);
797
int JS_PreventExtensions(JSContext *ctx, JSValueConst obj);
798
int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags);
799
int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
800
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
801
802
33
#define JS_GPN_STRING_MASK  (1 << 0)
803
30
#define JS_GPN_SYMBOL_MASK  (1 << 1)
804
#define JS_GPN_PRIVATE_MASK (1 << 2)
805
/* only include the enumerable properties */
806
152
#define JS_GPN_ENUM_ONLY    (1 << 4)
807
/* set theJSPropertyEnum.is_enumerable field */
808
1
#define JS_GPN_SET_ENUM     (1 << 5)
809
810
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
811
                           uint32_t *plen, JSValueConst obj, int flags);
812
void JS_FreePropertyEnum(JSContext *ctx, JSPropertyEnum *tab,
813
                         uint32_t len);
814
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
815
                      JSValueConst obj, JSAtom prop);
816
817
JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,
818
                int argc, JSValueConst *argv);
819
JSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,
820
                  int argc, JSValueConst *argv);
821
JSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,
822
                           int argc, JSValueConst *argv);
823
JSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,
824
                            JSValueConst new_target,
825
                            int argc, JSValueConst *argv);
826
JS_BOOL JS_DetectModule(const char *input, size_t input_len);
827
/* 'input' must be zero terminated i.e. input[input_len] = '\0'. */
828
JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
829
                const char *filename, int eval_flags);
830
/* same as JS_Eval() but with an explicit 'this_obj' parameter */
831
JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj,
832
                    const char *input, size_t input_len,
833
                    const char *filename, int eval_flags);
834
JSValue JS_GetGlobalObject(JSContext *ctx);
835
int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj);
836
int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
837
                      JSAtom prop, JSValueConst val,
838
                      JSValueConst getter, JSValueConst setter, int flags);
839
int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,
840
                           JSAtom prop, JSValue val, int flags);
841
int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
842
                                 uint32_t idx, JSValue val, int flags);
843
int JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,
844
                              const char *prop, JSValue val, int flags);
845
int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
846
                            JSAtom prop, JSValue getter, JSValue setter,
847
                            int flags);
848
void JS_SetOpaque(JSValue obj, void *opaque);
849
void *JS_GetOpaque(JSValueConst obj, JSClassID class_id);
850
void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
851
void *JS_GetAnyOpaque(JSValueConst obj, JSClassID *class_id);
852
853
/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
854
JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
855
                     const char *filename);
856
0
#define JS_PARSE_JSON_EXT (1 << 0) /* allow extended JSON */
857
JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
858
                      const char *filename, int flags);
859
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
860
                         JSValueConst replacer, JSValueConst space0);
861
862
typedef void JSFreeArrayBufferDataFunc(JSRuntime *rt, void *opaque, void *ptr);
863
JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
864
                          JSFreeArrayBufferDataFunc *free_func, void *opaque,
865
                          JS_BOOL is_shared);
866
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
867
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
868
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
869
870
typedef enum JSTypedArrayEnum {
871
    JS_TYPED_ARRAY_UINT8C = 0,
872
    JS_TYPED_ARRAY_INT8,
873
    JS_TYPED_ARRAY_UINT8,
874
    JS_TYPED_ARRAY_INT16,
875
    JS_TYPED_ARRAY_UINT16,
876
    JS_TYPED_ARRAY_INT32,
877
    JS_TYPED_ARRAY_UINT32,
878
    JS_TYPED_ARRAY_BIG_INT64,
879
    JS_TYPED_ARRAY_BIG_UINT64,
880
    JS_TYPED_ARRAY_FLOAT16,
881
    JS_TYPED_ARRAY_FLOAT32,
882
    JS_TYPED_ARRAY_FLOAT64,
883
} JSTypedArrayEnum;
884
885
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
886
                         JSTypedArrayEnum array_type);
887
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
888
                               size_t *pbyte_offset,
889
                               size_t *pbyte_length,
890
                               size_t *pbytes_per_element);
891
typedef struct {
892
    void *(*sab_alloc)(void *opaque, size_t size);
893
    void (*sab_free)(void *opaque, void *ptr);
894
    void (*sab_dup)(void *opaque, void *ptr);
895
    void *sab_opaque;
896
} JSSharedArrayBufferFunctions;
897
void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
898
                                      const JSSharedArrayBufferFunctions *sf);
899
900
typedef enum JSPromiseStateEnum {
901
    JS_PROMISE_PENDING,
902
    JS_PROMISE_FULFILLED,
903
    JS_PROMISE_REJECTED,
904
} JSPromiseStateEnum;
905
906
JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
907
JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise);
908
JSValue JS_PromiseResult(JSContext *ctx, JSValue promise);
909
910
/* is_handled = TRUE means that the rejection is handled */
911
typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,
912
                                           JSValueConst reason,
913
                                           JS_BOOL is_handled, void *opaque);
914
void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
915
916
/* return != 0 if the JS code needs to be interrupted */
917
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
918
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
919
/* if can_block is TRUE, Atomics.wait() can be used */
920
void JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);
921
/* select which debug info is stripped from the compiled code */
922
100
#define JS_STRIP_SOURCE (1 << 0) /* strip source code */
923
200
#define JS_STRIP_DEBUG  (1 << 1) /* strip all debug info including source code */
924
void JS_SetStripInfo(JSRuntime *rt, int flags);
925
int JS_GetStripInfo(JSRuntime *rt);
926
927
/* set the [IsHTMLDDA] internal slot */
928
void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj);
929
930
typedef struct JSModuleDef JSModuleDef;
931
932
/* return the module specifier (allocated with js_malloc()) or NULL if
933
   exception */
934
typedef char *JSModuleNormalizeFunc(JSContext *ctx,
935
                                    const char *module_base_name,
936
                                    const char *module_name, void *opaque);
937
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
938
                                        const char *module_name, void *opaque);
939
typedef JSModuleDef *JSModuleLoaderFunc2(JSContext *ctx,
940
                                         const char *module_name, void *opaque,
941
                                         JSValueConst attributes);
942
/* return -1 if exception, 0 if OK */
943
typedef int JSModuleCheckSupportedImportAttributes(JSContext *ctx, void *opaque,
944
                                                   JSValueConst attributes);
945
                                                   
946
/* module_normalize = NULL is allowed and invokes the default module
947
   filename normalizer */
948
void JS_SetModuleLoaderFunc(JSRuntime *rt,
949
                            JSModuleNormalizeFunc *module_normalize,
950
                            JSModuleLoaderFunc *module_loader, void *opaque);
951
/* same as JS_SetModuleLoaderFunc but with attributes. if
952
   module_check_attrs = NULL, no attribute checking is done. */
953
void JS_SetModuleLoaderFunc2(JSRuntime *rt,
954
                             JSModuleNormalizeFunc *module_normalize,
955
                             JSModuleLoaderFunc2 *module_loader,
956
                             JSModuleCheckSupportedImportAttributes *module_check_attrs,
957
                             void *opaque);
958
/* return the import.meta object of a module */
959
JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
960
JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
961
JSValue JS_GetModuleNamespace(JSContext *ctx, JSModuleDef *m);
962
963
/* JS Job support */
964
965
typedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValueConst *argv);
966
int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, int argc, JSValueConst *argv);
967
968
JS_BOOL JS_IsJobPending(JSRuntime *rt);
969
int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);
970
971
/* Object Writer/Reader (currently only used to handle precompiled code) */
972
14
#define JS_WRITE_OBJ_BYTECODE  (1 << 0) /* allow function/module */
973
#define JS_WRITE_OBJ_BSWAP     (1 << 1) /* byte swapped output */
974
7
#define JS_WRITE_OBJ_SAB       (1 << 2) /* allow SharedArrayBuffer */
975
7
#define JS_WRITE_OBJ_REFERENCE (1 << 3) /* allow object references to
976
                                           encode arbitrary object
977
                                           graph */
978
uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,
979
                        int flags);
980
uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,
981
                         int flags, uint8_t ***psab_tab, size_t *psab_tab_len);
982
983
14
#define JS_READ_OBJ_BYTECODE  (1 << 0) /* allow function/module */
984
7
#define JS_READ_OBJ_ROM_DATA  (1 << 1) /* avoid duplicating 'buf' data */
985
7
#define JS_READ_OBJ_SAB       (1 << 2) /* allow SharedArrayBuffer */
986
7
#define JS_READ_OBJ_REFERENCE (1 << 3) /* allow object references */
987
JSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,
988
                      int flags);
989
/* instantiate and evaluate a bytecode function. Only used when
990
   reading a script or module with JS_ReadObject() */
991
JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj);
992
/* load the dependencies of the module 'obj'. Useful when JS_ReadObject()
993
   returns a module. */
994
int JS_ResolveModule(JSContext *ctx, JSValueConst obj);
995
996
/* only exported for os.Worker() */
997
JSAtom JS_GetScriptOrModuleName(JSContext *ctx, int n_stack_levels);
998
/* only exported for os.Worker() */
999
JSValue JS_LoadModule(JSContext *ctx, const char *basename,
1000
                      const char *filename);
1001
1002
/* C function definition */
1003
typedef enum JSCFunctionEnum {  /* XXX: should rename for namespace isolation */
1004
    JS_CFUNC_generic,
1005
    JS_CFUNC_generic_magic,
1006
    JS_CFUNC_constructor,
1007
    JS_CFUNC_constructor_magic,
1008
    JS_CFUNC_constructor_or_func,
1009
    JS_CFUNC_constructor_or_func_magic,
1010
    JS_CFUNC_f_f,
1011
    JS_CFUNC_f_f_f,
1012
    JS_CFUNC_getter,
1013
    JS_CFUNC_setter,
1014
    JS_CFUNC_getter_magic,
1015
    JS_CFUNC_setter_magic,
1016
    JS_CFUNC_iterator_next,
1017
} JSCFunctionEnum;
1018
1019
typedef union JSCFunctionType {
1020
    JSCFunction *generic;
1021
    JSValue (*generic_magic)(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
1022
    JSCFunction *constructor;
1023
    JSValue (*constructor_magic)(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic);
1024
    JSCFunction *constructor_or_func;
1025
    double (*f_f)(double);
1026
    double (*f_f_f)(double, double);
1027
    JSValue (*getter)(JSContext *ctx, JSValueConst this_val);
1028
    JSValue (*setter)(JSContext *ctx, JSValueConst this_val, JSValueConst val);
1029
    JSValue (*getter_magic)(JSContext *ctx, JSValueConst this_val, int magic);
1030
    JSValue (*setter_magic)(JSContext *ctx, JSValueConst this_val, JSValueConst val, int magic);
1031
    JSValue (*iterator_next)(JSContext *ctx, JSValueConst this_val,
1032
                             int argc, JSValueConst *argv, int *pdone, int magic);
1033
} JSCFunctionType;
1034
1035
JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
1036
                         const char *name,
1037
                         int length, JSCFunctionEnum cproto, int magic);
1038
JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
1039
                            int length, int magic, int data_len,
1040
                            JSValueConst *data);
1041
1042
static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,
1043
                                      int length)
1044
180
{
1045
180
    return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);
1046
180
}
Unexecuted instantiation: fuzz_eval.c:JS_NewCFunction
Unexecuted instantiation: fuzz_common.c:JS_NewCFunction
quickjs.c:JS_NewCFunction
Line
Count
Source
1044
60
{
1045
60
    return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);
1046
60
}
quickjs-libc.c:JS_NewCFunction
Line
Count
Source
1044
120
{
1045
120
    return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);
1046
120
}
Unexecuted instantiation: fuzz_compile.c:JS_NewCFunction
Unexecuted instantiation: fuzz_regexp.c:JS_NewCFunction
1047
1048
static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *func,
1049
                                           const char *name,
1050
                                           int length, JSCFunctionEnum cproto, int magic)
1051
180
{
1052
180
    return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
1053
180
}
Unexecuted instantiation: fuzz_eval.c:JS_NewCFunctionMagic
Unexecuted instantiation: fuzz_common.c:JS_NewCFunctionMagic
quickjs.c:JS_NewCFunctionMagic
Line
Count
Source
1051
180
{
1052
180
    return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
1053
180
}
Unexecuted instantiation: quickjs-libc.c:JS_NewCFunctionMagic
Unexecuted instantiation: fuzz_compile.c:JS_NewCFunctionMagic
Unexecuted instantiation: fuzz_regexp.c:JS_NewCFunctionMagic
1054
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
1055
                       JSValueConst proto);
1056
1057
/* C property definition */
1058
1059
typedef struct JSCFunctionListEntry {
1060
    const char *name;
1061
    uint8_t prop_flags;
1062
    uint8_t def_type;
1063
    int16_t magic;
1064
    union {
1065
        struct {
1066
            uint8_t length; /* XXX: should move outside union */
1067
            uint8_t cproto; /* XXX: should move outside union */
1068
            JSCFunctionType cfunc;
1069
        } func;
1070
        struct {
1071
            JSCFunctionType get;
1072
            JSCFunctionType set;
1073
        } getset;
1074
        struct {
1075
            const char *name;
1076
            int base;
1077
        } alias;
1078
        struct {
1079
            const struct JSCFunctionListEntry *tab;
1080
            int len;
1081
        } prop_list;
1082
        const char *str;
1083
        int32_t i32;
1084
        int64_t i64;
1085
        double f64;
1086
    } u;
1087
} JSCFunctionListEntry;
1088
1089
12.5k
#define JS_DEF_CFUNC          0
1090
450
#define JS_DEF_CGETSET        1
1091
2.13k
#define JS_DEF_CGETSET_MAGIC  2
1092
779
#define JS_DEF_PROP_STRING    3
1093
1.45k
#define JS_DEF_PROP_INT32     4
1094
0
#define JS_DEF_PROP_INT64     5
1095
300
#define JS_DEF_PROP_DOUBLE    6
1096
30
#define JS_DEF_PROP_UNDEFINED 7
1097
899
#define JS_DEF_OBJECT         8
1098
300
#define JS_DEF_ALIAS          9
1099
1100
/* Note: c++ does not like nested designators */
1101
#define JS_CFUNC_DEF(name, length, func1) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_generic, { .generic = func1 } } } }
1102
#define JS_CFUNC_MAGIC_DEF(name, length, func1, magic) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, magic, .u = { .func = { length, JS_CFUNC_generic_magic, { .generic_magic = func1 } } } }
1103
#define JS_CFUNC_SPECIAL_DEF(name, length, cproto, func1) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, 0, .u = { .func = { length, JS_CFUNC_ ## cproto, { .cproto = func1 } } } }
1104
#define JS_ITERATOR_NEXT_DEF(name, length, func1, magic) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_CFUNC, magic, .u = { .func = { length, JS_CFUNC_iterator_next, { .iterator_next = func1 } } } }
1105
#define JS_CGETSET_DEF(name, fgetter, fsetter) { name, JS_PROP_CONFIGURABLE, JS_DEF_CGETSET, 0, .u = { .getset = { .get = { .getter = fgetter }, .set = { .setter = fsetter } } } }
1106
#define JS_CGETSET_MAGIC_DEF(name, fgetter, fsetter, magic) { name, JS_PROP_CONFIGURABLE, JS_DEF_CGETSET_MAGIC, magic, .u = { .getset = { .get = { .getter_magic = fgetter }, .set = { .setter_magic = fsetter } } } }
1107
#define JS_PROP_STRING_DEF(name, cstr, prop_flags) { name, prop_flags, JS_DEF_PROP_STRING, 0, .u = { .str = cstr } }
1108
#define JS_PROP_INT32_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT32, 0, .u = { .i32 = val } }
1109
#define JS_PROP_INT64_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT64, 0, .u = { .i64 = val } }
1110
#define JS_PROP_DOUBLE_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, .u = { .f64 = val } }
1111
#define JS_PROP_UNDEFINED_DEF(name, prop_flags) { name, prop_flags, JS_DEF_PROP_UNDEFINED, 0, .u = { .i32 = 0 } }
1112
#define JS_OBJECT_DEF(name, tab, len, prop_flags) { name, prop_flags, JS_DEF_OBJECT, 0, .u = { .prop_list = { tab, len } } }
1113
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
1114
#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }
1115
1116
int JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
1117
                               const JSCFunctionListEntry *tab,
1118
                               int len);
1119
1120
/* C module definition */
1121
1122
typedef int JSModuleInitFunc(JSContext *ctx, JSModuleDef *m);
1123
1124
JSModuleDef *JS_NewCModule(JSContext *ctx, const char *name_str,
1125
                           JSModuleInitFunc *func);
1126
/* can only be called before the module is instantiated */
1127
int JS_AddModuleExport(JSContext *ctx, JSModuleDef *m, const char *name_str);
1128
int JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,
1129
                           const JSCFunctionListEntry *tab, int len);
1130
/* can only be called after the module is instantiated */
1131
int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
1132
                       JSValue val);
1133
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
1134
                           const JSCFunctionListEntry *tab, int len);
1135
/* associate a JSValue to a C module */
1136
int JS_SetModulePrivateValue(JSContext *ctx, JSModuleDef *m, JSValue val);
1137
JSValue JS_GetModulePrivateValue(JSContext *ctx, JSModuleDef *m);
1138
                        
1139
/* debug value output */
1140
1141
typedef struct {
1142
    JS_BOOL show_hidden : 8; /* only show enumerable properties */
1143
    JS_BOOL raw_dump : 8; /* avoid doing autoinit and avoid any malloc() call (for internal use) */
1144
    uint32_t max_depth; /* recurse up to this depth, 0 = no limit */
1145
    uint32_t max_string_length; /* print no more than this length for
1146
                                   strings, 0 = no limit */
1147
    uint32_t max_item_count; /*  print no more than this count for
1148
                                 arrays or objects, 0 = no limit */
1149
} JSPrintValueOptions;
1150
1151
typedef void JSPrintValueWrite(void *opaque, const char *buf, size_t len);
1152
1153
void JS_PrintValueSetDefaultOptions(JSPrintValueOptions *options);
1154
void JS_PrintValueRT(JSRuntime *rt, JSPrintValueWrite *write_func, void *write_opaque,
1155
                     JSValueConst val, const JSPrintValueOptions *options);
1156
void JS_PrintValue(JSContext *ctx, JSPrintValueWrite *write_func, void *write_opaque,
1157
                   JSValueConst val, const JSPrintValueOptions *options);
1158
1159
#undef js_unlikely
1160
#undef js_force_inline
1161
1162
#ifdef __cplusplus
1163
} /* extern "C" { */
1164
#endif
1165
1166
#endif /* QUICKJS_H */