@zappdev/cli 0.1.0
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 +55 -0
- package/dist/zapp-cli.js +9471 -0
- package/native/src/app/app.zc +490 -0
- package/native/src/event/event.zc +24 -0
- package/native/src/event/events.zc +70 -0
- package/native/src/platform/darwin/backend.zc +923 -0
- package/native/src/platform/darwin/backend_bootstrap.zc +9 -0
- package/native/src/platform/darwin/bootstrap.zc +9 -0
- package/native/src/platform/darwin/engine_jsc.zc +86 -0
- package/native/src/platform/darwin/engine_qjs.zc +92 -0
- package/native/src/platform/darwin/platform.zc +156 -0
- package/native/src/platform/darwin/webview.zc +550 -0
- package/native/src/platform/darwin/webview_bootstrap.zc +9 -0
- package/native/src/platform/darwin/window.zc +1223 -0
- package/native/src/platform/darwin/worker/common.zc +223 -0
- package/native/src/platform/darwin/worker/core/base64_core.zc +29 -0
- package/native/src/platform/darwin/worker/core/crypto_core.zc +19 -0
- package/native/src/platform/darwin/worker/core/encoding_core.zc +32 -0
- package/native/src/platform/darwin/worker/core/fetch_core.zc +145 -0
- package/native/src/platform/darwin/worker/core/url_core.zc +69 -0
- package/native/src/platform/darwin/worker/core/websocket_core.zc +179 -0
- package/native/src/platform/darwin/worker/dispatch.zc +55 -0
- package/native/src/platform/darwin/worker/jsc/base64_jsc.zc +39 -0
- package/native/src/platform/darwin/worker/jsc/crypto_jsc.zc +49 -0
- package/native/src/platform/darwin/worker/jsc/encoding_jsc.zc +86 -0
- package/native/src/platform/darwin/worker/jsc/fetch_jsc.zc +149 -0
- package/native/src/platform/darwin/worker/jsc/url_jsc.zc +54 -0
- package/native/src/platform/darwin/worker/jsc/websocket_jsc.zc +127 -0
- package/native/src/platform/darwin/worker/jsc.zc +670 -0
- package/native/src/platform/darwin/worker/mod.zc +30 -0
- package/native/src/platform/darwin/worker/qjs/fetch_qjs.zc +233 -0
- package/native/src/platform/darwin/worker/qjs/qjs_macros.zc +23 -0
- package/native/src/platform/darwin/worker/qjs/websocket_qjs.zc +223 -0
- package/native/src/platform/darwin/worker/qjs.zc +1053 -0
- package/native/src/platform/darwin/worker/timers.zc +149 -0
- package/native/src/platform/darwin/worker/timers_qjs.zc +209 -0
- package/native/src/platform/platform.zc +64 -0
- package/native/src/platform/shared/log.zc +156 -0
- package/native/src/platform/shared/worker/qjs/base64_qjs.zc +38 -0
- package/native/src/platform/shared/worker/qjs/crypto_qjs.zc +44 -0
- package/native/src/platform/shared/worker/qjs/encoding_qjs.zc +95 -0
- package/native/src/platform/shared/worker/qjs/url_qjs.zc +65 -0
- package/native/src/platform/shared/worker_registry.zc +206 -0
- package/native/src/platform/window.zc +446 -0
- package/native/src/platform/windows/backend.zc +452 -0
- package/native/src/platform/windows/backend_bootstrap.zc +9 -0
- package/native/src/platform/windows/bootstrap.zc +9 -0
- package/native/src/platform/windows/engine_qjs.zc +60 -0
- package/native/src/platform/windows/platform.zc +387 -0
- package/native/src/platform/windows/webview.zc +1175 -0
- package/native/src/platform/windows/webview_bootstrap.zc +9 -0
- package/native/src/platform/windows/window.zc +1271 -0
- package/native/src/platform/windows/worker/common.zc +409 -0
- package/native/src/platform/windows/worker/core/base64_core.zc +52 -0
- package/native/src/platform/windows/worker/core/crypto_core.zc +34 -0
- package/native/src/platform/windows/worker/core/encoding_core.zc +60 -0
- package/native/src/platform/windows/worker/core/fetch_core.zc +274 -0
- package/native/src/platform/windows/worker/core/url_core.zc +216 -0
- package/native/src/platform/windows/worker/core/websocket_core.zc +343 -0
- package/native/src/platform/windows/worker/dispatch.zc +34 -0
- package/native/src/platform/windows/worker/mod.zc +46 -0
- package/native/src/platform/windows/worker/qjs/fetch_qjs.zc +255 -0
- package/native/src/platform/windows/worker/qjs/websocket_qjs.zc +263 -0
- package/native/src/platform/windows/worker/qjs.zc +1049 -0
- package/native/src/platform/windows/worker/timers_qjs.zc +288 -0
- package/native/src/platform/worker.zc +8 -0
- package/native/src/service/service.zc +228 -0
- package/native/vendor/quickjs-ng/.gitattributes +4 -0
- package/native/vendor/quickjs-ng/.github/dependabot.yml +7 -0
- package/native/vendor/quickjs-ng/.github/workflows/ci.yml +812 -0
- package/native/vendor/quickjs-ng/.github/workflows/docs.yml +49 -0
- package/native/vendor/quickjs-ng/.github/workflows/release.yml +162 -0
- package/native/vendor/quickjs-ng/.github/workflows/test-docs.yml +23 -0
- package/native/vendor/quickjs-ng/.github/workflows/tsan.yml +32 -0
- package/native/vendor/quickjs-ng/.github/workflows/valgrind.yml +33 -0
- package/native/vendor/quickjs-ng/.gitmodules +5 -0
- package/native/vendor/quickjs-ng/CMakeLists.txt +553 -0
- package/native/vendor/quickjs-ng/LICENSE +24 -0
- package/native/vendor/quickjs-ng/Makefile +149 -0
- package/native/vendor/quickjs-ng/amalgam.js +53 -0
- package/native/vendor/quickjs-ng/api-test.c +927 -0
- package/native/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
- package/native/vendor/quickjs-ng/builtin-array-fromasync.js +36 -0
- package/native/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
- package/native/vendor/quickjs-ng/builtin-iterator-zip-keyed.js +194 -0
- package/native/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
- package/native/vendor/quickjs-ng/builtin-iterator-zip.js +210 -0
- package/native/vendor/quickjs-ng/ctest.c +17 -0
- package/native/vendor/quickjs-ng/cutils.h +2013 -0
- package/native/vendor/quickjs-ng/cxxtest.cc +2 -0
- package/native/vendor/quickjs-ng/dtoa.c +1619 -0
- package/native/vendor/quickjs-ng/dtoa.h +87 -0
- package/native/vendor/quickjs-ng/examples/fib.c +67 -0
- package/native/vendor/quickjs-ng/examples/fib_module.js +10 -0
- package/native/vendor/quickjs-ng/examples/hello.js +1 -0
- package/native/vendor/quickjs-ng/examples/hello_module.js +6 -0
- package/native/vendor/quickjs-ng/examples/meson.build +17 -0
- package/native/vendor/quickjs-ng/examples/pi_bigint.js +118 -0
- package/native/vendor/quickjs-ng/examples/point.c +154 -0
- package/native/vendor/quickjs-ng/examples/test_fib.js +8 -0
- package/native/vendor/quickjs-ng/examples/test_point.js +43 -0
- package/native/vendor/quickjs-ng/fuzz.c +51 -0
- package/native/vendor/quickjs-ng/gen/function_source.c +81 -0
- package/native/vendor/quickjs-ng/gen/hello.c +53 -0
- package/native/vendor/quickjs-ng/gen/hello_module.c +106 -0
- package/native/vendor/quickjs-ng/gen/repl.c +3053 -0
- package/native/vendor/quickjs-ng/gen/standalone.c +324 -0
- package/native/vendor/quickjs-ng/gen/test_fib.c +81 -0
- package/native/vendor/quickjs-ng/libregexp-opcode.h +58 -0
- package/native/vendor/quickjs-ng/libregexp.c +2687 -0
- package/native/vendor/quickjs-ng/libregexp.h +98 -0
- package/native/vendor/quickjs-ng/libunicode-table.h +4707 -0
- package/native/vendor/quickjs-ng/libunicode.c +1746 -0
- package/native/vendor/quickjs-ng/libunicode.h +126 -0
- package/native/vendor/quickjs-ng/list.h +107 -0
- package/native/vendor/quickjs-ng/lre-test.c +73 -0
- package/native/vendor/quickjs-ng/meson.build +684 -0
- package/native/vendor/quickjs-ng/meson_options.txt +6 -0
- package/native/vendor/quickjs-ng/qjs-wasi-reactor.c +208 -0
- package/native/vendor/quickjs-ng/qjs.c +748 -0
- package/native/vendor/quickjs-ng/qjsc.c +673 -0
- package/native/vendor/quickjs-ng/quickjs-atom.h +267 -0
- package/native/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
- package/native/vendor/quickjs-ng/quickjs-libc.c +4986 -0
- package/native/vendor/quickjs-ng/quickjs-libc.h +79 -0
- package/native/vendor/quickjs-ng/quickjs-opcode.h +369 -0
- package/native/vendor/quickjs-ng/quickjs.c +60259 -0
- package/native/vendor/quickjs-ng/quickjs.h +1419 -0
- package/native/vendor/quickjs-ng/repl.js +1927 -0
- package/native/vendor/quickjs-ng/run-test262.c +2417 -0
- package/native/vendor/quickjs-ng/standalone.js +129 -0
- package/native/vendor/quickjs-ng/tests/assert.js +49 -0
- package/native/vendor/quickjs-ng/tests/bug1221.js +16 -0
- package/native/vendor/quickjs-ng/tests/bug1296.js +12 -0
- package/native/vendor/quickjs-ng/tests/bug1297.js +22 -0
- package/native/vendor/quickjs-ng/tests/bug1301.js +21 -0
- package/native/vendor/quickjs-ng/tests/bug1302.js +24 -0
- package/native/vendor/quickjs-ng/tests/bug1305.js +26 -0
- package/native/vendor/quickjs-ng/tests/bug1318.js +54 -0
- package/native/vendor/quickjs-ng/tests/bug1352.js +8 -0
- package/native/vendor/quickjs-ng/tests/bug1354.js +6 -0
- package/native/vendor/quickjs-ng/tests/bug1355.js +58 -0
- package/native/vendor/quickjs-ng/tests/bug1368.js +9 -0
- package/native/vendor/quickjs-ng/tests/bug39/1.js +6 -0
- package/native/vendor/quickjs-ng/tests/bug39/2.js +6 -0
- package/native/vendor/quickjs-ng/tests/bug39/3.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug488-upstream.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug633/0.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug633/1.js +4 -0
- package/native/vendor/quickjs-ng/tests/bug633/2.js +4 -0
- package/native/vendor/quickjs-ng/tests/bug633/3.js +4 -0
- package/native/vendor/quickjs-ng/tests/bug645/0.js +4 -0
- package/native/vendor/quickjs-ng/tests/bug645/1.js +9 -0
- package/native/vendor/quickjs-ng/tests/bug645/2.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug648.js +13 -0
- package/native/vendor/quickjs-ng/tests/bug652.js +4 -0
- package/native/vendor/quickjs-ng/tests/bug741.js +19 -0
- package/native/vendor/quickjs-ng/tests/bug775.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug776.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug832.js +2 -0
- package/native/vendor/quickjs-ng/tests/bug858.js +26 -0
- package/native/vendor/quickjs-ng/tests/bug904.js +6 -0
- package/native/vendor/quickjs-ng/tests/bug988.js +7 -0
- package/native/vendor/quickjs-ng/tests/bug999.js +3 -0
- package/native/vendor/quickjs-ng/tests/destructured-export.js +8 -0
- package/native/vendor/quickjs-ng/tests/detect_module/0.js +1 -0
- package/native/vendor/quickjs-ng/tests/detect_module/1.js +2 -0
- package/native/vendor/quickjs-ng/tests/detect_module/2.js +1 -0
- package/native/vendor/quickjs-ng/tests/detect_module/3.js +8 -0
- package/native/vendor/quickjs-ng/tests/detect_module/4.js +3 -0
- package/native/vendor/quickjs-ng/tests/empty.js +0 -0
- package/native/vendor/quickjs-ng/tests/fixture_cyclic_import.js +2 -0
- package/native/vendor/quickjs-ng/tests/fixture_string_exports.js +12 -0
- package/native/vendor/quickjs-ng/tests/function_source.js +14 -0
- package/native/vendor/quickjs-ng/tests/microbench.js +1267 -0
- package/native/vendor/quickjs-ng/tests/null_or_undefined.js +38 -0
- package/native/vendor/quickjs-ng/tests/str-pad-leak.js +5 -0
- package/native/vendor/quickjs-ng/tests/test_bigint.js +107 -0
- package/native/vendor/quickjs-ng/tests/test_bjson.js +366 -0
- package/native/vendor/quickjs-ng/tests/test_builtin.js +1314 -0
- package/native/vendor/quickjs-ng/tests/test_closure.js +220 -0
- package/native/vendor/quickjs-ng/tests/test_cyclic_import.js +12 -0
- package/native/vendor/quickjs-ng/tests/test_domexception.js +35 -0
- package/native/vendor/quickjs-ng/tests/test_language.js +755 -0
- package/native/vendor/quickjs-ng/tests/test_loop.js +367 -0
- package/native/vendor/quickjs-ng/tests/test_queue_microtask.js +39 -0
- package/native/vendor/quickjs-ng/tests/test_std.js +340 -0
- package/native/vendor/quickjs-ng/tests/test_string_exports.js +25 -0
- package/native/vendor/quickjs-ng/tests/test_worker.js +43 -0
- package/native/vendor/quickjs-ng/tests/test_worker_module.js +30 -0
- package/native/vendor/quickjs-ng/tests.conf +14 -0
- package/native/vendor/quickjs-ng/unicode_download.sh +19 -0
- package/native/vendor/quickjs-ng/unicode_gen.c +3108 -0
- package/native/vendor/quickjs-ng/unicode_gen_def.h +310 -0
- package/native/vendor/quickjs-ng/update-version.sh +32 -0
- package/native/vendor/webview2/include/WebView2.h +60636 -0
- package/native/vendor/webview2/include/WebView2EnvironmentOptions.h +406 -0
- package/package.json +33 -0
- package/src/backend.ts +139 -0
- package/src/build-config.ts +87 -0
- package/src/build.ts +276 -0
- package/src/common.ts +195 -0
- package/src/config.ts +89 -0
- package/src/dev.ts +164 -0
- package/src/generate.ts +200 -0
- package/src/icons.ts +116 -0
- package/src/init.ts +190 -0
- package/src/package.ts +150 -0
- package/src/zapp-cli.ts +263 -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,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* QuickJS: Example of C module
|
|
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
|
+
#include <quickjs.h>
|
|
26
|
+
|
|
27
|
+
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
|
28
|
+
|
|
29
|
+
static int fib(int n)
|
|
30
|
+
{
|
|
31
|
+
if (n <= 0)
|
|
32
|
+
return 0;
|
|
33
|
+
else if (n == 1)
|
|
34
|
+
return 1;
|
|
35
|
+
else
|
|
36
|
+
return fib(n - 1) + fib(n - 2);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static JSValue js_fib(JSContext *ctx, JSValue this_val,
|
|
40
|
+
int argc, JSValue *argv)
|
|
41
|
+
{
|
|
42
|
+
int n, res;
|
|
43
|
+
if (JS_ToInt32(ctx, &n, argv[0]))
|
|
44
|
+
return JS_EXCEPTION;
|
|
45
|
+
res = fib(n);
|
|
46
|
+
return JS_NewInt32(ctx, res);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static const JSCFunctionListEntry js_fib_funcs[] = {
|
|
50
|
+
JS_CFUNC_DEF("fib", 1, js_fib ),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static int js_fib_init(JSContext *ctx, JSModuleDef *m)
|
|
54
|
+
{
|
|
55
|
+
return JS_SetModuleExportList(ctx, m, js_fib_funcs,
|
|
56
|
+
countof(js_fib_funcs));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
JS_MODULE_EXTERN JSModuleDef *js_init_module(JSContext *ctx, const char *module_name)
|
|
60
|
+
{
|
|
61
|
+
JSModuleDef *m;
|
|
62
|
+
m = JS_NewCModule(ctx, module_name, js_fib_init);
|
|
63
|
+
if (!m)
|
|
64
|
+
return NULL;
|
|
65
|
+
JS_AddModuleExportList(ctx, m, js_fib_funcs, countof(js_fib_funcs));
|
|
66
|
+
return m;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("Hello World");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
shared_module(
|
|
2
|
+
'fib',
|
|
3
|
+
'fib.c',
|
|
4
|
+
|
|
5
|
+
name_prefix: '',
|
|
6
|
+
gnu_symbol_visibility: 'hidden',
|
|
7
|
+
dependencies: qjs_module_dep,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
shared_module(
|
|
11
|
+
'point',
|
|
12
|
+
'point.c',
|
|
13
|
+
|
|
14
|
+
name_prefix: '',
|
|
15
|
+
gnu_symbol_visibility: 'hidden',
|
|
16
|
+
dependencies: qjs_module_dep,
|
|
17
|
+
)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* PI computation in Javascript using the BigInt type
|
|
3
|
+
*/
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/* return floor(log2(a)) for a > 0 and 0 for a = 0 */
|
|
7
|
+
function floor_log2(a)
|
|
8
|
+
{
|
|
9
|
+
var k_max, a1, k, i;
|
|
10
|
+
k_max = 0n;
|
|
11
|
+
while ((a >> (2n ** k_max)) != 0n) {
|
|
12
|
+
k_max++;
|
|
13
|
+
}
|
|
14
|
+
k = 0n;
|
|
15
|
+
a1 = a;
|
|
16
|
+
for(i = k_max - 1n; i >= 0n; i--) {
|
|
17
|
+
a1 = a >> (2n ** i);
|
|
18
|
+
if (a1 != 0n) {
|
|
19
|
+
a = a1;
|
|
20
|
+
k |= (1n << i);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return k;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* return ceil(log2(a)) for a > 0 */
|
|
27
|
+
function ceil_log2(a)
|
|
28
|
+
{
|
|
29
|
+
return floor_log2(a - 1n) + 1n;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* return floor(sqrt(a)) (not efficient but simple) */
|
|
33
|
+
function int_sqrt(a)
|
|
34
|
+
{
|
|
35
|
+
var l, u, s;
|
|
36
|
+
if (a == 0n)
|
|
37
|
+
return a;
|
|
38
|
+
l = ceil_log2(a);
|
|
39
|
+
u = 1n << ((l + 1n) / 2n);
|
|
40
|
+
/* u >= floor(sqrt(a)) */
|
|
41
|
+
for(;;) {
|
|
42
|
+
s = u;
|
|
43
|
+
u = ((a / s) + s) / 2n;
|
|
44
|
+
if (u >= s)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return s;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* return pi * 2**prec */
|
|
51
|
+
function calc_pi(prec) {
|
|
52
|
+
const CHUD_A = 13591409n;
|
|
53
|
+
const CHUD_B = 545140134n;
|
|
54
|
+
const CHUD_C = 640320n;
|
|
55
|
+
const CHUD_C3 = 10939058860032000n; /* C^3/24 */
|
|
56
|
+
const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */
|
|
57
|
+
|
|
58
|
+
/* return [P, Q, G] */
|
|
59
|
+
function chud_bs(a, b, need_G) {
|
|
60
|
+
var c, P, Q, G, P1, Q1, G1, P2, Q2, G2;
|
|
61
|
+
if (a == (b - 1n)) {
|
|
62
|
+
G = (2n * b - 1n) * (6n * b - 1n) * (6n * b - 5n);
|
|
63
|
+
P = G * (CHUD_B * b + CHUD_A);
|
|
64
|
+
if (b & 1n)
|
|
65
|
+
P = -P;
|
|
66
|
+
Q = b * b * b * CHUD_C3;
|
|
67
|
+
} else {
|
|
68
|
+
c = (a + b) >> 1n;
|
|
69
|
+
[P1, Q1, G1] = chud_bs(a, c, true);
|
|
70
|
+
[P2, Q2, G2] = chud_bs(c, b, need_G);
|
|
71
|
+
P = P1 * Q2 + P2 * G1;
|
|
72
|
+
Q = Q1 * Q2;
|
|
73
|
+
if (need_G)
|
|
74
|
+
G = G1 * G2;
|
|
75
|
+
else
|
|
76
|
+
G = 0n;
|
|
77
|
+
}
|
|
78
|
+
return [P, Q, G];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var n, P, Q, G;
|
|
82
|
+
/* number of serie terms */
|
|
83
|
+
n = BigInt(Math.ceil(Number(prec) / CHUD_BITS_PER_TERM)) + 10n;
|
|
84
|
+
[P, Q, G] = chud_bs(0n, n, false);
|
|
85
|
+
Q = (CHUD_C / 12n) * (Q << prec) / (P + Q * CHUD_A);
|
|
86
|
+
G = int_sqrt(CHUD_C << (2n * prec));
|
|
87
|
+
return (Q * G) >> prec;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function main(args) {
|
|
91
|
+
var r, n_digits, n_bits, out;
|
|
92
|
+
if (args.length < 1) {
|
|
93
|
+
print("usage: pi n_digits");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
n_digits = args[0] | 0;
|
|
97
|
+
|
|
98
|
+
/* we add more bits to reduce the probability of bad rounding for
|
|
99
|
+
the last digits */
|
|
100
|
+
n_bits = BigInt(Math.ceil(n_digits * Math.log2(10))) + 32n;
|
|
101
|
+
r = calc_pi(n_bits);
|
|
102
|
+
r = ((10n ** BigInt(n_digits)) * r) >> n_bits;
|
|
103
|
+
out = r.toString();
|
|
104
|
+
print(out[0] + "." + out.slice(1));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
var args;
|
|
108
|
+
if (typeof scriptArgs != "undefined") {
|
|
109
|
+
args = scriptArgs;
|
|
110
|
+
args.shift();
|
|
111
|
+
} else if (typeof arguments != "undefined") {
|
|
112
|
+
args = arguments;
|
|
113
|
+
} else {
|
|
114
|
+
/* default: 1000 digits */
|
|
115
|
+
args=[1000];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
main(args);
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* QuickJS: Example of C module with a class
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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
|
+
#include <math.h>
|
|
26
|
+
|
|
27
|
+
#include <quickjs.h>
|
|
28
|
+
|
|
29
|
+
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
|
30
|
+
|
|
31
|
+
/* Point Class */
|
|
32
|
+
|
|
33
|
+
typedef struct {
|
|
34
|
+
int x;
|
|
35
|
+
int y;
|
|
36
|
+
} JSPointData;
|
|
37
|
+
|
|
38
|
+
static JSClassID js_point_class_id;
|
|
39
|
+
|
|
40
|
+
static void js_point_finalizer(JSRuntime *rt, JSValue val)
|
|
41
|
+
{
|
|
42
|
+
JSPointData *s = JS_GetOpaque(val, js_point_class_id);
|
|
43
|
+
/* Note: 's' can be NULL in case JS_SetOpaque() was not called */
|
|
44
|
+
js_free_rt(rt, s);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static JSValue js_point_ctor(JSContext *ctx,
|
|
48
|
+
JSValue new_target,
|
|
49
|
+
int argc, JSValue *argv)
|
|
50
|
+
{
|
|
51
|
+
JSPointData *s;
|
|
52
|
+
JSValue obj = JS_UNDEFINED;
|
|
53
|
+
JSValue proto;
|
|
54
|
+
|
|
55
|
+
s = js_mallocz(ctx, sizeof(*s));
|
|
56
|
+
if (!s)
|
|
57
|
+
return JS_EXCEPTION;
|
|
58
|
+
if (JS_ToInt32(ctx, &s->x, argv[0]))
|
|
59
|
+
goto fail;
|
|
60
|
+
if (JS_ToInt32(ctx, &s->y, argv[1]))
|
|
61
|
+
goto fail;
|
|
62
|
+
/* using new_target to get the prototype is necessary when the
|
|
63
|
+
class is extended. */
|
|
64
|
+
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
|
|
65
|
+
if (JS_IsException(proto))
|
|
66
|
+
goto fail;
|
|
67
|
+
obj = JS_NewObjectProtoClass(ctx, proto, js_point_class_id);
|
|
68
|
+
JS_FreeValue(ctx, proto);
|
|
69
|
+
if (JS_IsException(obj))
|
|
70
|
+
goto fail;
|
|
71
|
+
JS_SetOpaque(obj, s);
|
|
72
|
+
return obj;
|
|
73
|
+
fail:
|
|
74
|
+
js_free(ctx, s);
|
|
75
|
+
JS_FreeValue(ctx, obj);
|
|
76
|
+
return JS_EXCEPTION;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static JSValue js_point_get_xy(JSContext *ctx, JSValue this_val, int magic)
|
|
80
|
+
{
|
|
81
|
+
JSPointData *s = JS_GetOpaque2(ctx, this_val, js_point_class_id);
|
|
82
|
+
if (!s)
|
|
83
|
+
return JS_EXCEPTION;
|
|
84
|
+
if (magic == 0)
|
|
85
|
+
return JS_NewInt32(ctx, s->x);
|
|
86
|
+
else
|
|
87
|
+
return JS_NewInt32(ctx, s->y);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static JSValue js_point_set_xy(JSContext *ctx, JSValue this_val, JSValue val, int magic)
|
|
91
|
+
{
|
|
92
|
+
JSPointData *s = JS_GetOpaque2(ctx, this_val, js_point_class_id);
|
|
93
|
+
int v;
|
|
94
|
+
if (!s)
|
|
95
|
+
return JS_EXCEPTION;
|
|
96
|
+
if (JS_ToInt32(ctx, &v, val))
|
|
97
|
+
return JS_EXCEPTION;
|
|
98
|
+
if (magic == 0)
|
|
99
|
+
s->x = v;
|
|
100
|
+
else
|
|
101
|
+
s->y = v;
|
|
102
|
+
return JS_UNDEFINED;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static JSValue js_point_norm(JSContext *ctx, JSValue this_val,
|
|
106
|
+
int argc, JSValue *argv)
|
|
107
|
+
{
|
|
108
|
+
JSPointData *s = JS_GetOpaque2(ctx, this_val, js_point_class_id);
|
|
109
|
+
if (!s)
|
|
110
|
+
return JS_EXCEPTION;
|
|
111
|
+
return JS_NewFloat64(ctx, sqrt((double)s->x * s->x + (double)s->y * s->y));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static JSClassDef js_point_class = {
|
|
115
|
+
"Point",
|
|
116
|
+
.finalizer = js_point_finalizer,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
static const JSCFunctionListEntry js_point_proto_funcs[] = {
|
|
120
|
+
JS_CGETSET_MAGIC_DEF("x", js_point_get_xy, js_point_set_xy, 0),
|
|
121
|
+
JS_CGETSET_MAGIC_DEF("y", js_point_get_xy, js_point_set_xy, 1),
|
|
122
|
+
JS_CFUNC_DEF("norm", 0, js_point_norm),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
static int js_point_init(JSContext *ctx, JSModuleDef *m)
|
|
126
|
+
{
|
|
127
|
+
JSValue point_proto, point_class;
|
|
128
|
+
JSRuntime *rt = JS_GetRuntime(ctx);
|
|
129
|
+
|
|
130
|
+
/* create the Point class */
|
|
131
|
+
JS_NewClassID(rt, &js_point_class_id);
|
|
132
|
+
JS_NewClass(rt, js_point_class_id, &js_point_class);
|
|
133
|
+
|
|
134
|
+
point_proto = JS_NewObject(ctx);
|
|
135
|
+
JS_SetPropertyFunctionList(ctx, point_proto, js_point_proto_funcs, countof(js_point_proto_funcs));
|
|
136
|
+
|
|
137
|
+
point_class = JS_NewCFunction2(ctx, js_point_ctor, "Point", 2, JS_CFUNC_constructor, 0);
|
|
138
|
+
/* set proto.constructor and ctor.prototype */
|
|
139
|
+
JS_SetConstructor(ctx, point_class, point_proto);
|
|
140
|
+
JS_SetClassProto(ctx, js_point_class_id, point_proto);
|
|
141
|
+
|
|
142
|
+
JS_SetModuleExport(ctx, m, "Point", point_class);
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
JS_MODULE_EXTERN JSModuleDef *js_init_module(JSContext *ctx, const char *module_name)
|
|
147
|
+
{
|
|
148
|
+
JSModuleDef *m;
|
|
149
|
+
m = JS_NewCModule(ctx, module_name, js_point_init);
|
|
150
|
+
if (!m)
|
|
151
|
+
return NULL;
|
|
152
|
+
JS_AddModuleExport(ctx, m, "Point");
|
|
153
|
+
return m;
|
|
154
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* example of JS module importing a C module */
|
|
2
|
+
import * as os from "qjs:os";
|
|
3
|
+
|
|
4
|
+
const isWin = os.platform === 'win32';
|
|
5
|
+
const { Point } = await import(`./point.${isWin ? 'dll' : 'so'}`);
|
|
6
|
+
|
|
7
|
+
function assert(b, str)
|
|
8
|
+
{
|
|
9
|
+
if (b) {
|
|
10
|
+
return;
|
|
11
|
+
} else {
|
|
12
|
+
throw Error("assertion failed: " + str);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class ColorPoint extends Point {
|
|
17
|
+
constructor(x, y, color) {
|
|
18
|
+
super(x, y);
|
|
19
|
+
this.color = color;
|
|
20
|
+
}
|
|
21
|
+
get_color() {
|
|
22
|
+
return this.color;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function main()
|
|
27
|
+
{
|
|
28
|
+
var pt, pt2;
|
|
29
|
+
|
|
30
|
+
pt = new Point(2, 3);
|
|
31
|
+
assert(pt.x === 2);
|
|
32
|
+
assert(pt.y === 3);
|
|
33
|
+
pt.x = 4;
|
|
34
|
+
assert(pt.x === 4);
|
|
35
|
+
assert(pt.norm() == 5);
|
|
36
|
+
|
|
37
|
+
pt2 = new ColorPoint(2, 3, 0xffffff);
|
|
38
|
+
assert(pt2.x === 2);
|
|
39
|
+
assert(pt2.color === 0xffffff);
|
|
40
|
+
assert(pt2.get_color() === 0xffffff);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main();
|
|
@@ -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_le(&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,81 @@
|
|
|
1
|
+
/* File generated automatically by the QuickJS-ng compiler. */
|
|
2
|
+
|
|
3
|
+
#include "quickjs-libc.h"
|
|
4
|
+
|
|
5
|
+
const uint32_t qjsc_function_source_size = 332;
|
|
6
|
+
|
|
7
|
+
const uint8_t qjsc_function_source[332] = {
|
|
8
|
+
0x18, 0x08, 0x1e, 0x5a, 0xf2, 0x05, 0x01, 0x30,
|
|
9
|
+
0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x66, 0x75,
|
|
10
|
+
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x73,
|
|
11
|
+
0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x6a, 0x73,
|
|
12
|
+
0x01, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61, 0x6c,
|
|
13
|
+
0x01, 0x02, 0x66, 0x01, 0x0c, 0x65, 0x78, 0x70,
|
|
14
|
+
0x65, 0x63, 0x74, 0x01, 0x34, 0x66, 0x75, 0x6e,
|
|
15
|
+
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x28,
|
|
16
|
+
0x29, 0x20, 0x7b, 0x20, 0x72, 0x65, 0x74, 0x75,
|
|
17
|
+
0x72, 0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d, 0x0d,
|
|
18
|
+
0xca, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
|
|
19
|
+
0x20, 0x0a, 0x01, 0xa2, 0x01, 0x00, 0x05, 0x00,
|
|
20
|
+
0x03, 0x02, 0x02, 0x01, 0x74, 0x05, 0xcc, 0x03,
|
|
21
|
+
0x02, 0x00, 0x30, 0xce, 0x03, 0x04, 0x00, 0x70,
|
|
22
|
+
0x01, 0xcc, 0x03, 0x04, 0x02, 0x70, 0x00, 0x10,
|
|
23
|
+
0x00, 0x01, 0x00, 0xe4, 0x01, 0x00, 0x01, 0x00,
|
|
24
|
+
0xd0, 0x03, 0x00, 0x1e, 0xce, 0x03, 0x01, 0x06,
|
|
25
|
+
0x0c, 0x43, 0x0a, 0x01, 0xce, 0x03, 0x00, 0x00,
|
|
26
|
+
0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0xbc,
|
|
27
|
+
0x2a, 0x28, 0xca, 0x03, 0x03, 0x01, 0x00, 0x1a,
|
|
28
|
+
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
|
29
|
+
0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72,
|
|
30
|
+
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32,
|
|
31
|
+
0x20, 0x7d, 0x0c, 0x03, 0xc2, 0x04, 0x08, 0xcc,
|
|
32
|
+
0x08, 0xea, 0x05, 0xbf, 0x00, 0xe2, 0x29, 0x04,
|
|
33
|
+
0xe9, 0x00, 0x00, 0x00, 0xe1, 0x60, 0x00, 0x00,
|
|
34
|
+
0xde, 0x41, 0x38, 0x00, 0x00, 0x00, 0x24, 0x00,
|
|
35
|
+
0x00, 0xc9, 0x61, 0x00, 0x00, 0x64, 0x00, 0x00,
|
|
36
|
+
0xae, 0xea, 0x0b, 0x38, 0x98, 0x00, 0x00, 0x00,
|
|
37
|
+
0x61, 0x00, 0x00, 0xef, 0x30, 0x60, 0x02, 0x00,
|
|
38
|
+
0x60, 0x01, 0x00, 0x38, 0x3b, 0x00, 0x00, 0x00,
|
|
39
|
+
0x64, 0x00, 0x00, 0x04, 0xe7, 0x00, 0x00, 0x00,
|
|
40
|
+
0x9c, 0x32, 0x01, 0x00, 0x03, 0x00, 0xca, 0x61,
|
|
41
|
+
0x01, 0x00, 0x41, 0x38, 0x00, 0x00, 0x00, 0x24,
|
|
42
|
+
0x00, 0x00, 0xcb, 0x61, 0x02, 0x00, 0x64, 0x00,
|
|
43
|
+
0x00, 0xae, 0xea, 0x0b, 0x38, 0x98, 0x00, 0x00,
|
|
44
|
+
0x00, 0x61, 0x02, 0x00, 0xef, 0x30, 0x67, 0x02,
|
|
45
|
+
0x00, 0x67, 0x01, 0x00, 0x06, 0x2f, 0xca, 0x03,
|
|
46
|
+
0x01, 0x01, 0x18, 0x00, 0x1c, 0x0a, 0x2a, 0x26,
|
|
47
|
+
0x03, 0x20, 0x1c, 0x1b, 0x0c, 0x00, 0x10, 0x08,
|
|
48
|
+
0x27, 0x11, 0x12, 0x67, 0x0d, 0x26, 0x03, 0x20,
|
|
49
|
+
0x1c, 0x1b, 0x0c, 0x00,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
static JSContext *JS_NewCustomContext(JSRuntime *rt)
|
|
53
|
+
{
|
|
54
|
+
JSContext *ctx = JS_NewContext(rt);
|
|
55
|
+
if (!ctx)
|
|
56
|
+
return NULL;
|
|
57
|
+
return ctx;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
int main(int argc, char **argv)
|
|
61
|
+
{
|
|
62
|
+
int r;
|
|
63
|
+
JSRuntime *rt;
|
|
64
|
+
JSContext *ctx;
|
|
65
|
+
r = 0;
|
|
66
|
+
rt = JS_NewRuntime();
|
|
67
|
+
js_std_set_worker_new_context_func(JS_NewCustomContext);
|
|
68
|
+
js_std_init_handlers(rt);
|
|
69
|
+
JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);
|
|
70
|
+
ctx = JS_NewCustomContext(rt);
|
|
71
|
+
js_std_add_helpers(ctx, argc, argv);
|
|
72
|
+
js_std_eval_binary(ctx, qjsc_function_source, qjsc_function_source_size, 0);
|
|
73
|
+
r = js_std_loop(ctx);
|
|
74
|
+
if (r) {
|
|
75
|
+
js_std_dump_error(ctx);
|
|
76
|
+
}
|
|
77
|
+
js_std_free_handlers(rt);
|
|
78
|
+
JS_FreeContext(ctx);
|
|
79
|
+
JS_FreeRuntime(rt);
|
|
80
|
+
return r;
|
|
81
|
+
}
|