@mikrojs/quickjs 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/deps/quickjs/LICENSE +24 -0
- package/deps/quickjs/api-test.c +985 -0
- package/deps/quickjs/builtin-array-fromasync.h +119 -0
- package/deps/quickjs/builtin-iterator-zip-keyed.h +332 -0
- package/deps/quickjs/builtin-iterator-zip.h +337 -0
- package/deps/quickjs/ctest.c +17 -0
- package/deps/quickjs/cutils.h +1997 -0
- package/deps/quickjs/dtoa.c +1619 -0
- package/deps/quickjs/dtoa.h +87 -0
- package/deps/quickjs/fuzz.c +51 -0
- package/deps/quickjs/libregexp-opcode.h +58 -0
- package/deps/quickjs/libregexp.c +2610 -0
- package/deps/quickjs/libregexp.h +96 -0
- package/deps/quickjs/libunicode-table.h +4707 -0
- package/deps/quickjs/libunicode.c +1746 -0
- package/deps/quickjs/libunicode.h +126 -0
- package/deps/quickjs/list.h +107 -0
- package/deps/quickjs/lre-test.c +52 -0
- package/deps/quickjs/qjs-wasi-reactor.c +208 -0
- package/deps/quickjs/qjs.c +748 -0
- package/deps/quickjs/qjsc.c +673 -0
- package/deps/quickjs/quickjs-atom.h +268 -0
- package/deps/quickjs/quickjs-c-atomics.h +54 -0
- package/deps/quickjs/quickjs-libc.c +5018 -0
- package/deps/quickjs/quickjs-libc.h +87 -0
- package/deps/quickjs/quickjs-opcode.h +369 -0
- package/deps/quickjs/quickjs.c +60883 -0
- package/deps/quickjs/quickjs.h +1426 -0
- package/deps/quickjs/run-test262.c +2374 -0
- package/deps/quickjs/unicode_gen.c +3108 -0
- package/deps/quickjs/unicode_gen_def.h +310 -0
- package/index.js +13 -0
- package/package.json +41 -0
- package/postinstall.js +125 -0
- package/quickjs.cmake +83 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tiny float64 printing and parsing library
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 Fabrice Bellard
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
19
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
#ifndef DTOA_H
|
|
25
|
+
#define DTOA_H
|
|
26
|
+
|
|
27
|
+
//#define JS_DTOA_DUMP_STATS
|
|
28
|
+
|
|
29
|
+
/* maximum number of digits for fixed and frac formats */
|
|
30
|
+
#define JS_DTOA_MAX_DIGITS 101
|
|
31
|
+
|
|
32
|
+
/* radix != 10 is only supported with flags = JS_DTOA_FORMAT_FREE */
|
|
33
|
+
/* use as many digits as necessary */
|
|
34
|
+
#define JS_DTOA_FORMAT_FREE (0 << 0)
|
|
35
|
+
/* use n_digits significant digits (1 <= n_digits <= JS_DTOA_MAX_DIGITS) */
|
|
36
|
+
#define JS_DTOA_FORMAT_FIXED (1 << 0)
|
|
37
|
+
/* force fractional format: [-]dd.dd with n_digits fractional digits.
|
|
38
|
+
0 <= n_digits <= JS_DTOA_MAX_DIGITS */
|
|
39
|
+
#define JS_DTOA_FORMAT_FRAC (2 << 0)
|
|
40
|
+
#define JS_DTOA_FORMAT_MASK (3 << 0)
|
|
41
|
+
|
|
42
|
+
/* select exponential notation either in fixed or free format */
|
|
43
|
+
#define JS_DTOA_EXP_AUTO (0 << 2)
|
|
44
|
+
#define JS_DTOA_EXP_ENABLED (1 << 2)
|
|
45
|
+
#define JS_DTOA_EXP_DISABLED (2 << 2)
|
|
46
|
+
#define JS_DTOA_EXP_MASK (3 << 2)
|
|
47
|
+
|
|
48
|
+
#define JS_DTOA_MINUS_ZERO (1 << 4) /* show the minus sign for -0 */
|
|
49
|
+
|
|
50
|
+
/* only accepts integers (no dot, no exponent) */
|
|
51
|
+
#define JS_ATOD_INT_ONLY (1 << 0)
|
|
52
|
+
/* accept Oo and Ob prefixes in addition to 0x prefix if radix = 0 */
|
|
53
|
+
#define JS_ATOD_ACCEPT_BIN_OCT (1 << 1)
|
|
54
|
+
/* accept O prefix as octal if radix == 0 and properly formed (Annex B) */
|
|
55
|
+
#define JS_ATOD_ACCEPT_LEGACY_OCTAL (1 << 2)
|
|
56
|
+
/* accept _ between digits as a digit separator */
|
|
57
|
+
#define JS_ATOD_ACCEPT_UNDERSCORES (1 << 3)
|
|
58
|
+
|
|
59
|
+
typedef struct {
|
|
60
|
+
uint64_t mem[37];
|
|
61
|
+
} JSDTOATempMem;
|
|
62
|
+
|
|
63
|
+
typedef struct {
|
|
64
|
+
uint64_t mem[27];
|
|
65
|
+
} JSATODTempMem;
|
|
66
|
+
|
|
67
|
+
/* return a maximum bound of the string length */
|
|
68
|
+
int js_dtoa_max_len(double d, int radix, int n_digits, int flags);
|
|
69
|
+
/* return the string length */
|
|
70
|
+
int js_dtoa(char *buf, double d, int radix, int n_digits, int flags,
|
|
71
|
+
JSDTOATempMem *tmp_mem);
|
|
72
|
+
double js_atod(const char *str, const char **pnext, int radix, int flags,
|
|
73
|
+
JSATODTempMem *tmp_mem);
|
|
74
|
+
|
|
75
|
+
#ifdef JS_DTOA_DUMP_STATS
|
|
76
|
+
void js_dtoa_dump_stats(void);
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
/* additional exported functions */
|
|
80
|
+
size_t u32toa(char *buf, uint32_t n);
|
|
81
|
+
size_t i32toa(char *buf, int32_t n);
|
|
82
|
+
size_t u64toa(char *buf, uint64_t n);
|
|
83
|
+
size_t i64toa(char *buf, int64_t n);
|
|
84
|
+
size_t u64toa_radix(char *buf, uint64_t n, unsigned int radix);
|
|
85
|
+
size_t i64toa_radix(char *buf, int64_t n, unsigned int radix);
|
|
86
|
+
|
|
87
|
+
#endif /* DTOA_H */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// clang -g -O1 -fsanitize=fuzzer -o fuzz fuzz.c
|
|
2
|
+
#include "quickjs.h"
|
|
3
|
+
#include "quickjs.c"
|
|
4
|
+
#include "cutils.h"
|
|
5
|
+
#include "libregexp.c"
|
|
6
|
+
#include "libunicode.c"
|
|
7
|
+
#include "dtoa.c"
|
|
8
|
+
|
|
9
|
+
#include <stdint.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
#include <string.h>
|
|
12
|
+
|
|
13
|
+
// note: LLVM output does not contain checksum, needs to be added
|
|
14
|
+
// manually (4 byte field at position 1) when adding to the corpus
|
|
15
|
+
//
|
|
16
|
+
// fill in UINT32_MAX to disable checksumming
|
|
17
|
+
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
|
|
18
|
+
{
|
|
19
|
+
if (!len)
|
|
20
|
+
return 0;
|
|
21
|
+
JSRuntime *rt = JS_NewRuntime();
|
|
22
|
+
if (!rt)
|
|
23
|
+
exit(1);
|
|
24
|
+
JSContext *ctx = JS_NewContext(rt);
|
|
25
|
+
if (!ctx)
|
|
26
|
+
exit(1);
|
|
27
|
+
size_t newlen = len + 4;
|
|
28
|
+
uint8_t *newbuf = malloc(newlen);
|
|
29
|
+
if (!newbuf)
|
|
30
|
+
exit(1);
|
|
31
|
+
uint32_t csum = bc_csum(&buf[1], len-1); // skip version field
|
|
32
|
+
newbuf[0] = buf[0]; // copy version field
|
|
33
|
+
put_u32(&newbuf[1], csum); // insert checksum
|
|
34
|
+
memcpy(&newbuf[5], &buf[1], len-1); // copy rest of payload
|
|
35
|
+
JSValue val = JS_ReadObject(ctx, newbuf, newlen, /*flags*/0);
|
|
36
|
+
free(newbuf);
|
|
37
|
+
if (JS_IsException(val)) {
|
|
38
|
+
JSValue exc = JS_GetException(ctx);
|
|
39
|
+
const char *str = JS_ToCString(ctx, exc);
|
|
40
|
+
JS_FreeValue(ctx, exc);
|
|
41
|
+
if (!str)
|
|
42
|
+
exit(1);
|
|
43
|
+
if (strstr(str, "checksum error"))
|
|
44
|
+
exit(1);
|
|
45
|
+
JS_FreeCString(ctx, str);
|
|
46
|
+
}
|
|
47
|
+
JS_FreeValue(ctx, val);
|
|
48
|
+
JS_FreeContext(ctx);
|
|
49
|
+
JS_FreeRuntime(rt);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Regular Expression Engine
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2018 Fabrice Bellard
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
19
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#ifdef DEF
|
|
26
|
+
|
|
27
|
+
DEF(invalid, 1) /* never used */
|
|
28
|
+
DEF(char8, 2) /* 7 bits in fact */
|
|
29
|
+
DEF(char16, 3)
|
|
30
|
+
DEF(char32, 5)
|
|
31
|
+
DEF(dot, 1)
|
|
32
|
+
DEF(any, 1) /* same as dot but match any character including line terminator */
|
|
33
|
+
DEF(line_start, 1)
|
|
34
|
+
DEF(line_end, 1)
|
|
35
|
+
DEF(goto, 5)
|
|
36
|
+
DEF(split_goto_first, 5)
|
|
37
|
+
DEF(split_next_first, 5)
|
|
38
|
+
DEF(match, 1)
|
|
39
|
+
DEF(save_start, 2) /* save start position */
|
|
40
|
+
DEF(save_end, 2) /* save end position, must come after saved_start */
|
|
41
|
+
DEF(save_reset, 3) /* reset save positions */
|
|
42
|
+
DEF(loop, 5) /* decrement the top the stack and goto if != 0 */
|
|
43
|
+
DEF(push_i32, 5) /* push integer on the stack */
|
|
44
|
+
DEF(drop, 1)
|
|
45
|
+
DEF(word_boundary, 1)
|
|
46
|
+
DEF(not_word_boundary, 1)
|
|
47
|
+
DEF(back_reference, 2)
|
|
48
|
+
DEF(backward_back_reference, 2) /* must come after back_reference */
|
|
49
|
+
DEF(range, 3) /* variable length */
|
|
50
|
+
DEF(range32, 3) /* variable length */
|
|
51
|
+
DEF(lookahead, 5)
|
|
52
|
+
DEF(negative_lookahead, 5)
|
|
53
|
+
DEF(push_char_pos, 1) /* push the character position on the stack */
|
|
54
|
+
DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */
|
|
55
|
+
DEF(prev, 1) /* go to the previous char */
|
|
56
|
+
DEF(simple_greedy_quant, 17)
|
|
57
|
+
|
|
58
|
+
#endif /* DEF */
|