@suchipi/quickjs 0.8.1 → 0.10.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 +9 -6
- package/build/aarch64-apple-darwin/bin/file-to-bytecode.js +3 -3
- package/build/aarch64-apple-darwin/bin/qjs +0 -0
- package/build/aarch64-apple-darwin/bin/qjsbootstrap +0 -0
- package/build/aarch64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
- package/build/aarch64-apple-darwin/bin/qjsc +0 -0
- package/build/aarch64-apple-darwin/bin/quickjs-run +0 -0
- package/build/aarch64-apple-darwin/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-apple-darwin/extras/run-test262 +0 -0
- package/build/aarch64-apple-darwin/extras/sample-program/sum +0 -0
- package/build/aarch64-apple-darwin/extras/stack-limit-test +0 -0
- package/build/aarch64-apple-darwin/include/quickjs-bytecode.h +8 -0
- package/build/aarch64-apple-darwin/include/quickjs-context.h +8 -0
- package/build/aarch64-apple-darwin/include/quickjs-encoding.h +8 -0
- package/build/aarch64-apple-darwin/include/quickjs-engine.h +8 -0
- package/build/aarch64-apple-darwin/include/quickjs-full-init.h +19 -0
- package/build/aarch64-apple-darwin/include/quickjs-inspect.h +9 -0
- package/build/aarch64-apple-darwin/include/quickjs-intervals.h +9 -0
- package/build/aarch64-apple-darwin/include/quickjs-libc.h +65 -0
- package/build/aarch64-apple-darwin/include/quickjs-modulesys.h +68 -0
- package/build/aarch64-apple-darwin/include/quickjs-pointer.h +9 -0
- package/build/aarch64-apple-darwin/include/quickjs-print.h +9 -0
- package/build/aarch64-apple-darwin/include/quickjs-utils.h +49 -0
- package/build/aarch64-apple-darwin/include/quickjs.h +1195 -0
- package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
- package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
- package/build/aarch64-unknown-linux-gnu/bin/file-to-bytecode.js +3 -3
- package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
- package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
- package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
- package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
- package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/run-test262 +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/sample-program/sum +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/stack-limit-test +0 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-bytecode.h +8 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-context.h +8 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-encoding.h +8 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-engine.h +8 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-full-init.h +19 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-inspect.h +9 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-intervals.h +9 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-libc.h +65 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-modulesys.h +68 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-pointer.h +9 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-print.h +9 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs-utils.h +49 -0
- package/build/aarch64-unknown-linux-gnu/include/quickjs.h +1195 -0
- package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
- package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
- package/build/aarch64-unknown-linux-musl/bin/file-to-bytecode.js +3 -3
- package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
- package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
- package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
- package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
- package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
- package/build/aarch64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-musl/extras/run-test262 +0 -0
- package/build/aarch64-unknown-linux-musl/extras/sample-program/sum +0 -0
- package/build/aarch64-unknown-linux-musl/extras/stack-limit-test +0 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-bytecode.h +8 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-context.h +8 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-encoding.h +8 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-engine.h +8 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-full-init.h +19 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-inspect.h +9 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-intervals.h +9 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-libc.h +65 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-modulesys.h +68 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-pointer.h +9 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-print.h +9 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs-utils.h +49 -0
- package/build/aarch64-unknown-linux-musl/include/quickjs.h +1195 -0
- package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
- package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
- package/build/aarch64-unknown-linux-static/bin/file-to-bytecode.js +3 -3
- package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
- package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
- package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
- package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
- package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
- package/build/aarch64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-static/extras/run-test262 +0 -0
- package/build/aarch64-unknown-linux-static/extras/sample-program/sum +0 -0
- package/build/aarch64-unknown-linux-static/extras/stack-limit-test +0 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-bytecode.h +8 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-context.h +8 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-encoding.h +8 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-engine.h +8 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-full-init.h +19 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-inspect.h +9 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-intervals.h +9 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-libc.h +65 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-modulesys.h +68 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-pointer.h +9 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-print.h +9 -0
- package/build/aarch64-unknown-linux-static/include/quickjs-utils.h +49 -0
- package/build/aarch64-unknown-linux-static/include/quickjs.h +1195 -0
- package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
- package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
- package/build/dts/{quickjs-libcontext.d.ts → quickjs-context.d.ts} +0 -3
- package/build/dts/quickjs-intervals.d.ts +4 -0
- package/build/dts/quickjs-libc.d.ts +21 -76
- package/build/dts/quickjs-modulesys.d.ts +9 -0
- package/build/dts/{quickjs-libpointer.d.ts → quickjs-pointer.d.ts} +1 -1
- package/build/dts/quickjs-print.d.ts +26 -0
- package/build/x86_64-apple-darwin/bin/file-to-bytecode.js +3 -3
- package/build/x86_64-apple-darwin/bin/qjs +0 -0
- package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
- package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
- package/build/x86_64-apple-darwin/bin/qjsc +0 -0
- package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
- package/build/x86_64-apple-darwin/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-apple-darwin/extras/run-test262 +0 -0
- package/build/x86_64-apple-darwin/extras/sample-program/sum +0 -0
- package/build/x86_64-apple-darwin/extras/stack-limit-test +0 -0
- package/build/x86_64-apple-darwin/include/quickjs-bytecode.h +8 -0
- package/build/x86_64-apple-darwin/include/quickjs-context.h +8 -0
- package/build/x86_64-apple-darwin/include/quickjs-encoding.h +8 -0
- package/build/x86_64-apple-darwin/include/quickjs-engine.h +8 -0
- package/build/x86_64-apple-darwin/include/quickjs-full-init.h +19 -0
- package/build/x86_64-apple-darwin/include/quickjs-inspect.h +9 -0
- package/build/x86_64-apple-darwin/include/quickjs-intervals.h +9 -0
- package/build/x86_64-apple-darwin/include/quickjs-libc.h +65 -0
- package/build/x86_64-apple-darwin/include/quickjs-modulesys.h +68 -0
- package/build/x86_64-apple-darwin/include/quickjs-pointer.h +9 -0
- package/build/x86_64-apple-darwin/include/quickjs-print.h +9 -0
- package/build/x86_64-apple-darwin/include/quickjs-utils.h +49 -0
- package/build/x86_64-apple-darwin/include/quickjs.h +1195 -0
- package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
- package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
- package/build/x86_64-pc-windows-static/bin/file-to-bytecode.js +3 -3
- package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
- package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
- package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
- package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
- package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
- package/build/x86_64-pc-windows-static/extras/is-stdin-a-tty.exe +0 -0
- package/build/x86_64-pc-windows-static/extras/run-test262.exe +0 -0
- package/build/x86_64-pc-windows-static/extras/sample-program/sum.exe +0 -0
- package/build/x86_64-pc-windows-static/extras/stack-limit-test.exe +0 -0
- package/build/x86_64-pc-windows-static/include/quickjs-bytecode.h +8 -0
- package/build/x86_64-pc-windows-static/include/quickjs-context.h +8 -0
- package/build/x86_64-pc-windows-static/include/quickjs-encoding.h +8 -0
- package/build/x86_64-pc-windows-static/include/quickjs-engine.h +8 -0
- package/build/x86_64-pc-windows-static/include/quickjs-full-init.h +19 -0
- package/build/x86_64-pc-windows-static/include/quickjs-inspect.h +9 -0
- package/build/x86_64-pc-windows-static/include/quickjs-intervals.h +9 -0
- package/build/x86_64-pc-windows-static/include/quickjs-libc.h +65 -0
- package/build/x86_64-pc-windows-static/include/quickjs-modulesys.h +68 -0
- package/build/x86_64-pc-windows-static/include/quickjs-pointer.h +9 -0
- package/build/x86_64-pc-windows-static/include/quickjs-print.h +9 -0
- package/build/x86_64-pc-windows-static/include/quickjs-utils.h +49 -0
- package/build/x86_64-pc-windows-static/include/quickjs.h +1195 -0
- package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
- package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
- package/build/x86_64-unknown-linux-gnu/bin/file-to-bytecode.js +3 -3
- package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
- package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
- package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
- package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
- package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/run-test262 +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/sample-program/sum +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/stack-limit-test +0 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-bytecode.h +8 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-context.h +8 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-encoding.h +8 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-engine.h +8 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-full-init.h +19 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-inspect.h +9 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-intervals.h +9 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-libc.h +65 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-modulesys.h +68 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-pointer.h +9 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-print.h +9 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs-utils.h +49 -0
- package/build/x86_64-unknown-linux-gnu/include/quickjs.h +1195 -0
- package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
- package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
- package/build/x86_64-unknown-linux-musl/bin/file-to-bytecode.js +3 -3
- package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
- package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
- package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
- package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
- package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
- package/build/x86_64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-musl/extras/run-test262 +0 -0
- package/build/x86_64-unknown-linux-musl/extras/sample-program/sum +0 -0
- package/build/x86_64-unknown-linux-musl/extras/stack-limit-test +0 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-bytecode.h +8 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-context.h +8 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-encoding.h +8 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-engine.h +8 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-full-init.h +19 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-inspect.h +9 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-intervals.h +9 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-libc.h +65 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-modulesys.h +68 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-pointer.h +9 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-print.h +9 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs-utils.h +49 -0
- package/build/x86_64-unknown-linux-musl/include/quickjs.h +1195 -0
- package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
- package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
- package/build/x86_64-unknown-linux-static/bin/file-to-bytecode.js +3 -3
- package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
- package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
- package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
- package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
- package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
- package/build/x86_64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-static/extras/run-test262 +0 -0
- package/build/x86_64-unknown-linux-static/extras/sample-program/sum +0 -0
- package/build/x86_64-unknown-linux-static/extras/stack-limit-test +0 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-bytecode.h +8 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-context.h +8 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-encoding.h +8 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-engine.h +8 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-full-init.h +19 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-inspect.h +9 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-intervals.h +9 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-libc.h +65 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-modulesys.h +68 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-pointer.h +9 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-print.h +9 -0
- package/build/x86_64-unknown-linux-static/include/quickjs-utils.h +49 -0
- package/build/x86_64-unknown-linux-static/include/quickjs.h +1195 -0
- package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
- package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
- package/package.json +3 -3
- package/tsconfig.json +2 -5
- package/build/aarch64-apple-darwin/extras/log-argv +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/log-argv +0 -0
- package/build/aarch64-unknown-linux-musl/extras/log-argv +0 -0
- package/build/aarch64-unknown-linux-static/extras/log-argv +0 -0
- package/build/x86_64-apple-darwin/extras/log-argv +0 -0
- package/build/x86_64-pc-windows-static/extras/log-argv.exe +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/log-argv +0 -0
- package/build/x86_64-unknown-linux-musl/extras/log-argv +0 -0
- package/build/x86_64-unknown-linux-static/extras/log-argv +0 -0
- /package/build/dts/{quickjs-libbytecode.d.ts → quickjs-bytecode.d.ts} +0 -0
- /package/build/dts/{quickjs-libencoding.d.ts → quickjs-encoding.d.ts} +0 -0
- /package/build/dts/{quickjs-libengine.d.ts → quickjs-engine.d.ts} +0 -0
- /package/build/dts/{inspect.d.ts → quickjs-inspect.d.ts} +0 -0
|
@@ -0,0 +1,1195 @@
|
|
|
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
|
+
|
|
31
|
+
#ifdef __cplusplus
|
|
32
|
+
extern "C" {
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
36
|
+
#define js_likely(x) __builtin_expect(!!(x), 1)
|
|
37
|
+
#define js_unlikely(x) __builtin_expect(!!(x), 0)
|
|
38
|
+
#define js_force_inline inline __attribute__((always_inline))
|
|
39
|
+
#define __js_printf_like(f, a) __attribute__((format(printf, f, a)))
|
|
40
|
+
#else
|
|
41
|
+
#define js_likely(x) (x)
|
|
42
|
+
#define js_unlikely(x) (x)
|
|
43
|
+
#define js_force_inline inline
|
|
44
|
+
#define __js_printf_like(a, b)
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
#define JS_BOOL int
|
|
48
|
+
|
|
49
|
+
typedef struct JSRuntime JSRuntime;
|
|
50
|
+
typedef struct JSContext JSContext;
|
|
51
|
+
typedef struct JSObject JSObject;
|
|
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
|
+
enum {
|
|
68
|
+
/* all tags with a reference count are negative */
|
|
69
|
+
JS_TAG_FIRST = -11, /* first negative tag */
|
|
70
|
+
JS_TAG_BIG_DECIMAL = -11,
|
|
71
|
+
JS_TAG_BIG_INT = -10,
|
|
72
|
+
JS_TAG_BIG_FLOAT = -9,
|
|
73
|
+
JS_TAG_SYMBOL = -8,
|
|
74
|
+
JS_TAG_STRING = -7,
|
|
75
|
+
JS_TAG_MODULE = -3, /* used internally */
|
|
76
|
+
JS_TAG_FUNCTION_BYTECODE = -2, /* used internally */
|
|
77
|
+
JS_TAG_OBJECT = -1,
|
|
78
|
+
|
|
79
|
+
JS_TAG_INT = 0,
|
|
80
|
+
JS_TAG_BOOL = 1,
|
|
81
|
+
JS_TAG_NULL = 2,
|
|
82
|
+
JS_TAG_UNDEFINED = 3,
|
|
83
|
+
JS_TAG_UNINITIALIZED = 4,
|
|
84
|
+
JS_TAG_CATCH_OFFSET = 5,
|
|
85
|
+
JS_TAG_EXCEPTION = 6,
|
|
86
|
+
JS_TAG_FLOAT64 = 7,
|
|
87
|
+
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
enum {
|
|
92
|
+
/* classid tag */ /* union usage | properties */
|
|
93
|
+
JS_CLASS_OBJECT = 1, /* must be first */
|
|
94
|
+
JS_CLASS_ARRAY, /* u.array | length */
|
|
95
|
+
JS_CLASS_ERROR,
|
|
96
|
+
JS_CLASS_NUMBER, /* u.object_data */
|
|
97
|
+
JS_CLASS_STRING, /* u.object_data */
|
|
98
|
+
JS_CLASS_BOOLEAN, /* u.object_data */
|
|
99
|
+
JS_CLASS_SYMBOL, /* u.object_data */
|
|
100
|
+
JS_CLASS_ARGUMENTS, /* u.array | length */
|
|
101
|
+
JS_CLASS_MAPPED_ARGUMENTS, /* | length */
|
|
102
|
+
JS_CLASS_DATE, /* u.object_data */
|
|
103
|
+
JS_CLASS_MODULE_NS,
|
|
104
|
+
JS_CLASS_C_FUNCTION, /* u.cfunc */
|
|
105
|
+
JS_CLASS_BYTECODE_FUNCTION, /* u.func */
|
|
106
|
+
JS_CLASS_BOUND_FUNCTION, /* u.bound_function */
|
|
107
|
+
JS_CLASS_C_FUNCTION_DATA, /* u.c_function_data_record */
|
|
108
|
+
JS_CLASS_GENERATOR_FUNCTION, /* u.func */
|
|
109
|
+
JS_CLASS_FOR_IN_ITERATOR, /* u.for_in_iterator */
|
|
110
|
+
JS_CLASS_REGEXP, /* u.regexp */
|
|
111
|
+
JS_CLASS_ARRAY_BUFFER, /* u.array_buffer */
|
|
112
|
+
JS_CLASS_SHARED_ARRAY_BUFFER, /* u.array_buffer */
|
|
113
|
+
JS_CLASS_UINT8C_ARRAY, /* u.array (typed_array) */
|
|
114
|
+
JS_CLASS_INT8_ARRAY, /* u.array (typed_array) */
|
|
115
|
+
JS_CLASS_UINT8_ARRAY, /* u.array (typed_array) */
|
|
116
|
+
JS_CLASS_INT16_ARRAY, /* u.array (typed_array) */
|
|
117
|
+
JS_CLASS_UINT16_ARRAY, /* u.array (typed_array) */
|
|
118
|
+
JS_CLASS_INT32_ARRAY, /* u.array (typed_array) */
|
|
119
|
+
JS_CLASS_UINT32_ARRAY, /* u.array (typed_array) */
|
|
120
|
+
JS_CLASS_BIG_INT64_ARRAY, /* u.array (typed_array) */
|
|
121
|
+
JS_CLASS_BIG_UINT64_ARRAY, /* u.array (typed_array) */
|
|
122
|
+
JS_CLASS_FLOAT32_ARRAY, /* u.array (typed_array) */
|
|
123
|
+
JS_CLASS_FLOAT64_ARRAY, /* u.array (typed_array) */
|
|
124
|
+
JS_CLASS_DATAVIEW, /* u.typed_array */
|
|
125
|
+
JS_CLASS_BIG_INT, /* u.object_data */
|
|
126
|
+
#ifdef CONFIG_BIGNUM
|
|
127
|
+
JS_CLASS_BIG_FLOAT, /* u.object_data */
|
|
128
|
+
JS_CLASS_FLOAT_ENV, /* u.float_env */
|
|
129
|
+
JS_CLASS_BIG_DECIMAL, /* u.object_data */
|
|
130
|
+
JS_CLASS_OPERATOR_SET, /* u.operator_set */
|
|
131
|
+
#endif
|
|
132
|
+
JS_CLASS_MAP, /* u.map_state */
|
|
133
|
+
JS_CLASS_SET, /* u.map_state */
|
|
134
|
+
JS_CLASS_WEAKMAP, /* u.map_state */
|
|
135
|
+
JS_CLASS_WEAKSET, /* u.map_state */
|
|
136
|
+
JS_CLASS_MAP_ITERATOR, /* u.map_iterator_data */
|
|
137
|
+
JS_CLASS_SET_ITERATOR, /* u.map_iterator_data */
|
|
138
|
+
JS_CLASS_ARRAY_ITERATOR, /* u.array_iterator_data */
|
|
139
|
+
JS_CLASS_STRING_ITERATOR, /* u.array_iterator_data */
|
|
140
|
+
JS_CLASS_REGEXP_STRING_ITERATOR, /* u.regexp_string_iterator_data */
|
|
141
|
+
JS_CLASS_GENERATOR, /* u.generator_data */
|
|
142
|
+
JS_CLASS_PROXY, /* u.proxy_data */
|
|
143
|
+
JS_CLASS_PROMISE, /* u.promise_data */
|
|
144
|
+
JS_CLASS_PROMISE_RESOLVE_FUNCTION, /* u.promise_function_data */
|
|
145
|
+
JS_CLASS_PROMISE_REJECT_FUNCTION, /* u.promise_function_data */
|
|
146
|
+
JS_CLASS_ASYNC_FUNCTION, /* u.func */
|
|
147
|
+
JS_CLASS_ASYNC_FUNCTION_RESOLVE, /* u.async_function_data */
|
|
148
|
+
JS_CLASS_ASYNC_FUNCTION_REJECT, /* u.async_function_data */
|
|
149
|
+
JS_CLASS_ASYNC_FROM_SYNC_ITERATOR, /* u.async_from_sync_iterator_data */
|
|
150
|
+
JS_CLASS_ASYNC_GENERATOR_FUNCTION, /* u.func */
|
|
151
|
+
JS_CLASS_ASYNC_GENERATOR, /* u.async_generator_data */
|
|
152
|
+
|
|
153
|
+
JS_CLASS_INIT_COUNT, /* last entry for predefined classes */
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
typedef struct JSRefCountHeader {
|
|
157
|
+
int ref_count;
|
|
158
|
+
} JSRefCountHeader;
|
|
159
|
+
|
|
160
|
+
#define JS_FLOAT64_NAN NAN
|
|
161
|
+
|
|
162
|
+
#ifdef CONFIG_CHECK_JSVALUE
|
|
163
|
+
/* JSValue consistency : it is not possible to run the code in this
|
|
164
|
+
mode, but it is useful to detect simple reference counting
|
|
165
|
+
errors. It would be interesting to modify a static C analyzer to
|
|
166
|
+
handle specific annotations (clang has such annotations but only
|
|
167
|
+
for objective C) */
|
|
168
|
+
typedef struct __JSValue *JSValue;
|
|
169
|
+
typedef const struct __JSValue *JSValueConst;
|
|
170
|
+
|
|
171
|
+
#define JS_VALUE_GET_TAG(v) (int)((uintptr_t)(v) & 0xf)
|
|
172
|
+
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
|
|
173
|
+
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
|
|
174
|
+
#define JS_VALUE_GET_INT(v) (int)((intptr_t)(v) >> 4)
|
|
175
|
+
#define JS_VALUE_GET_BOOL(v) JS_VALUE_GET_INT(v)
|
|
176
|
+
#define JS_VALUE_GET_FLOAT64(v) (double)JS_VALUE_GET_INT(v)
|
|
177
|
+
#define JS_VALUE_GET_PTR(v) (void *)((intptr_t)(v) & ~0xf)
|
|
178
|
+
|
|
179
|
+
#define JS_MKVAL(tag, val) (JSValue)(intptr_t)(((val) << 4) | (tag))
|
|
180
|
+
#define JS_MKPTR(tag, p) (JSValue)((intptr_t)(p) | (tag))
|
|
181
|
+
|
|
182
|
+
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
|
|
183
|
+
|
|
184
|
+
#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64, 1)
|
|
185
|
+
|
|
186
|
+
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
|
|
187
|
+
{
|
|
188
|
+
return JS_MKVAL(JS_TAG_FLOAT64, (int)d);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
|
192
|
+
{
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#elif defined(JS_NAN_BOXING)
|
|
197
|
+
|
|
198
|
+
typedef uint64_t JSValue;
|
|
199
|
+
|
|
200
|
+
#define JSValueConst JSValue
|
|
201
|
+
|
|
202
|
+
#define JS_VALUE_GET_TAG(v) (int)((v) >> 32)
|
|
203
|
+
#define JS_VALUE_GET_INT(v) (int)(v)
|
|
204
|
+
#define JS_VALUE_GET_BOOL(v) (int)(v)
|
|
205
|
+
#define JS_VALUE_GET_PTR(v) (void *)(intptr_t)(v)
|
|
206
|
+
|
|
207
|
+
#define JS_MKVAL(tag, val) (((uint64_t)(tag) << 32) | (uint32_t)(val))
|
|
208
|
+
#define JS_MKPTR(tag, ptr) (((uint64_t)(tag) << 32) | (uintptr_t)(ptr))
|
|
209
|
+
|
|
210
|
+
#define JS_FLOAT64_TAG_ADDEND (0x7ff80000 - JS_TAG_FIRST + 1) /* quiet NaN encoding */
|
|
211
|
+
|
|
212
|
+
static inline double JS_VALUE_GET_FLOAT64(JSValue v)
|
|
213
|
+
{
|
|
214
|
+
union {
|
|
215
|
+
JSValue v;
|
|
216
|
+
double d;
|
|
217
|
+
} u;
|
|
218
|
+
u.v = v;
|
|
219
|
+
u.v += (uint64_t)JS_FLOAT64_TAG_ADDEND << 32;
|
|
220
|
+
return u.d;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#define JS_NAN (0x7ff8000000000000 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32))
|
|
224
|
+
|
|
225
|
+
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
|
|
226
|
+
{
|
|
227
|
+
union {
|
|
228
|
+
double d;
|
|
229
|
+
uint64_t u64;
|
|
230
|
+
} u;
|
|
231
|
+
JSValue v;
|
|
232
|
+
u.d = d;
|
|
233
|
+
/* normalize NaN */
|
|
234
|
+
if (js_unlikely((u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000))
|
|
235
|
+
v = JS_NAN;
|
|
236
|
+
else
|
|
237
|
+
v = u.u64 - ((uint64_t)JS_FLOAT64_TAG_ADDEND << 32);
|
|
238
|
+
return v;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)((tag) - JS_TAG_FIRST) >= (JS_TAG_FLOAT64 - JS_TAG_FIRST))
|
|
242
|
+
|
|
243
|
+
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
|
|
244
|
+
static inline int JS_VALUE_GET_NORM_TAG(JSValue v)
|
|
245
|
+
{
|
|
246
|
+
uint32_t tag;
|
|
247
|
+
tag = JS_VALUE_GET_TAG(v);
|
|
248
|
+
if (JS_TAG_IS_FLOAT64(tag))
|
|
249
|
+
return JS_TAG_FLOAT64;
|
|
250
|
+
else
|
|
251
|
+
return tag;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
|
255
|
+
{
|
|
256
|
+
uint32_t tag;
|
|
257
|
+
tag = JS_VALUE_GET_TAG(v);
|
|
258
|
+
return tag == (JS_NAN >> 32);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
#else /* !JS_NAN_BOXING */
|
|
262
|
+
|
|
263
|
+
typedef union JSValueUnion {
|
|
264
|
+
int32_t int32;
|
|
265
|
+
double float64;
|
|
266
|
+
void *ptr;
|
|
267
|
+
} JSValueUnion;
|
|
268
|
+
|
|
269
|
+
typedef struct JSValue {
|
|
270
|
+
JSValueUnion u;
|
|
271
|
+
int64_t tag;
|
|
272
|
+
} JSValue;
|
|
273
|
+
|
|
274
|
+
#define JSValueConst JSValue
|
|
275
|
+
|
|
276
|
+
#define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)
|
|
277
|
+
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
|
|
278
|
+
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
|
|
279
|
+
#define JS_VALUE_GET_INT(v) ((v).u.int32)
|
|
280
|
+
#define JS_VALUE_GET_BOOL(v) ((v).u.int32)
|
|
281
|
+
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
|
|
282
|
+
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
|
|
283
|
+
|
|
284
|
+
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
|
|
285
|
+
#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
|
|
286
|
+
|
|
287
|
+
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
|
|
288
|
+
|
|
289
|
+
#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
|
|
290
|
+
|
|
291
|
+
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
|
|
292
|
+
{
|
|
293
|
+
JSValue v;
|
|
294
|
+
v.tag = JS_TAG_FLOAT64;
|
|
295
|
+
v.u.float64 = d;
|
|
296
|
+
return v;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
|
300
|
+
{
|
|
301
|
+
union {
|
|
302
|
+
double d;
|
|
303
|
+
uint64_t u64;
|
|
304
|
+
} u;
|
|
305
|
+
if (v.tag != JS_TAG_FLOAT64)
|
|
306
|
+
return 0;
|
|
307
|
+
u.d = v.u.float64;
|
|
308
|
+
return (u.u64 & 0x7fffffffffffffff) > 0x7ff0000000000000;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#endif /* !JS_NAN_BOXING */
|
|
312
|
+
|
|
313
|
+
#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
|
|
314
|
+
#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)))
|
|
315
|
+
|
|
316
|
+
#define JS_VALUE_GET_OBJ(v) ((JSObject *)JS_VALUE_GET_PTR(v))
|
|
317
|
+
#define JS_VALUE_GET_STRING(v) ((JSString *)JS_VALUE_GET_PTR(v))
|
|
318
|
+
#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)
|
|
319
|
+
|
|
320
|
+
JSClassID JS_VALUE_GET_CLASS_ID(JSValue v);
|
|
321
|
+
|
|
322
|
+
/* special values */
|
|
323
|
+
#define JS_NULL JS_MKVAL(JS_TAG_NULL, 0)
|
|
324
|
+
#define JS_UNDEFINED JS_MKVAL(JS_TAG_UNDEFINED, 0)
|
|
325
|
+
#define JS_FALSE JS_MKVAL(JS_TAG_BOOL, 0)
|
|
326
|
+
#define JS_TRUE JS_MKVAL(JS_TAG_BOOL, 1)
|
|
327
|
+
#define JS_EXCEPTION JS_MKVAL(JS_TAG_EXCEPTION, 0) /* indicates that a value was thrown. */
|
|
328
|
+
#define JS_UNINITIALIZED JS_MKVAL(JS_TAG_UNINITIALIZED, 0)
|
|
329
|
+
|
|
330
|
+
/* flags for object properties */
|
|
331
|
+
#define JS_PROP_CONFIGURABLE (1 << 0)
|
|
332
|
+
#define JS_PROP_WRITABLE (1 << 1)
|
|
333
|
+
#define JS_PROP_ENUMERABLE (1 << 2)
|
|
334
|
+
#define JS_PROP_C_W_E (JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE | JS_PROP_ENUMERABLE)
|
|
335
|
+
#define JS_PROP_LENGTH (1 << 3) /* used internally in Arrays */
|
|
336
|
+
#define JS_PROP_TMASK (3 << 4) /* mask for NORMAL, GETSET, VARREF, AUTOINIT */
|
|
337
|
+
#define JS_PROP_NORMAL (0 << 4)
|
|
338
|
+
#define JS_PROP_GETSET (1 << 4)
|
|
339
|
+
#define JS_PROP_VARREF (2 << 4) /* used internally */
|
|
340
|
+
#define JS_PROP_AUTOINIT (3 << 4) /* used internally */
|
|
341
|
+
|
|
342
|
+
/* flags for JS_DefineProperty */
|
|
343
|
+
#define JS_PROP_HAS_SHIFT 8
|
|
344
|
+
#define JS_PROP_HAS_CONFIGURABLE (1 << 8)
|
|
345
|
+
#define JS_PROP_HAS_WRITABLE (1 << 9)
|
|
346
|
+
#define JS_PROP_HAS_ENUMERABLE (1 << 10)
|
|
347
|
+
#define JS_PROP_HAS_GET (1 << 11)
|
|
348
|
+
#define JS_PROP_HAS_SET (1 << 12)
|
|
349
|
+
#define JS_PROP_HAS_VALUE (1 << 13)
|
|
350
|
+
|
|
351
|
+
/* throw an exception if false would be returned
|
|
352
|
+
(JS_DefineProperty/JS_SetProperty) */
|
|
353
|
+
#define JS_PROP_THROW (1 << 14)
|
|
354
|
+
/* throw an exception if false would be returned in strict mode
|
|
355
|
+
(JS_SetProperty) */
|
|
356
|
+
#define JS_PROP_THROW_STRICT (1 << 15)
|
|
357
|
+
|
|
358
|
+
#define JS_PROP_NO_ADD (1 << 16) /* internal use */
|
|
359
|
+
#define JS_PROP_NO_EXOTIC (1 << 17) /* internal use */
|
|
360
|
+
|
|
361
|
+
#define JS_DEFAULT_STACK_SIZE (256 * 1024)
|
|
362
|
+
|
|
363
|
+
/* JS_Eval() flags */
|
|
364
|
+
#define JS_EVAL_TYPE_GLOBAL (0 << 0) /* global code (default) */
|
|
365
|
+
#define JS_EVAL_TYPE_MODULE (1 << 0) /* module code */
|
|
366
|
+
#define JS_EVAL_TYPE_DIRECT (2 << 0) /* direct call (internal use) */
|
|
367
|
+
#define JS_EVAL_TYPE_INDIRECT (3 << 0) /* indirect call (internal use) */
|
|
368
|
+
#define JS_EVAL_TYPE_MASK (3 << 0)
|
|
369
|
+
|
|
370
|
+
#define JS_EVAL_FLAG_STRICT (1 << 3) /* force 'strict' mode */
|
|
371
|
+
#define JS_EVAL_FLAG_STRIP (1 << 4) /* force 'strip' mode */
|
|
372
|
+
/* compile but do not run. The result is an object with a
|
|
373
|
+
JS_TAG_FUNCTION_BYTECODE or JS_TAG_MODULE tag. It can be executed
|
|
374
|
+
with JS_EvalFunction(). */
|
|
375
|
+
#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)
|
|
376
|
+
/* don't include the stack frames before this eval in the Error() backtraces */
|
|
377
|
+
#define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6)
|
|
378
|
+
|
|
379
|
+
typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
|
|
380
|
+
typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
|
|
381
|
+
typedef JSValue JSCFunctionData(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data);
|
|
382
|
+
|
|
383
|
+
typedef struct JSMallocState {
|
|
384
|
+
size_t malloc_count;
|
|
385
|
+
size_t malloc_size;
|
|
386
|
+
size_t malloc_limit;
|
|
387
|
+
void *opaque; /* user opaque */
|
|
388
|
+
} JSMallocState;
|
|
389
|
+
|
|
390
|
+
typedef struct JSMallocFunctions {
|
|
391
|
+
void *(*js_malloc)(JSMallocState *s, size_t size);
|
|
392
|
+
void (*js_free)(JSMallocState *s, void *ptr);
|
|
393
|
+
void *(*js_realloc)(JSMallocState *s, void *ptr, size_t size);
|
|
394
|
+
size_t (*js_malloc_usable_size)(const void *ptr);
|
|
395
|
+
} JSMallocFunctions;
|
|
396
|
+
|
|
397
|
+
typedef struct JSGCObjectHeader JSGCObjectHeader;
|
|
398
|
+
|
|
399
|
+
JSRuntime *JS_NewRuntime(void);
|
|
400
|
+
/* info lifetime must exceed that of rt */
|
|
401
|
+
void JS_SetRuntimeInfo(JSRuntime *rt, const char *info);
|
|
402
|
+
void JS_SetMemoryLimit(JSRuntime *rt, size_t limit);
|
|
403
|
+
void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold);
|
|
404
|
+
/* use 0 to disable maximum stack size check */
|
|
405
|
+
void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size);
|
|
406
|
+
/* should be called when changing thread to update the stack top value
|
|
407
|
+
used to check stack overflow. */
|
|
408
|
+
void JS_UpdateStackTop(JSRuntime *rt);
|
|
409
|
+
JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque);
|
|
410
|
+
void JS_FreeRuntime(JSRuntime *rt);
|
|
411
|
+
void *JS_GetRuntimeOpaque(JSRuntime *rt);
|
|
412
|
+
void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque);
|
|
413
|
+
void JS_SetRuntimeOpaqueValue(JSRuntime *rt, JSValue value);
|
|
414
|
+
/* NOTE: you must free it! */
|
|
415
|
+
JSValue JS_GetRuntimeOpaqueValue(JSRuntime *rt);
|
|
416
|
+
typedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp);
|
|
417
|
+
void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func);
|
|
418
|
+
void JS_RunGC(JSRuntime *rt);
|
|
419
|
+
JS_BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj);
|
|
420
|
+
|
|
421
|
+
JSContext *JS_NewContext(JSRuntime *rt);
|
|
422
|
+
void JS_FreeContext(JSContext *s);
|
|
423
|
+
JSContext *JS_DupContext(JSContext *ctx);
|
|
424
|
+
void *JS_GetContextOpaque(JSContext *ctx);
|
|
425
|
+
void JS_SetContextOpaque(JSContext *ctx, void *opaque);
|
|
426
|
+
void JS_SetContextOpaqueValue(JSContext *ctx, JSValue value);
|
|
427
|
+
/* NOTE: you must free it! */
|
|
428
|
+
JSValue JS_GetContextOpaqueValue(JSContext *ctx);
|
|
429
|
+
JSRuntime *JS_GetRuntime(JSContext *ctx);
|
|
430
|
+
void JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj);
|
|
431
|
+
JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id);
|
|
432
|
+
|
|
433
|
+
/* the following functions are used to select the intrinsic object to
|
|
434
|
+
save memory */
|
|
435
|
+
JSContext *JS_NewContextRaw(JSRuntime *rt);
|
|
436
|
+
void JS_AddIntrinsicBaseObjects(JSContext *ctx);
|
|
437
|
+
void JS_AddIntrinsicDate(JSContext *ctx);
|
|
438
|
+
void JS_AddIntrinsicEval(JSContext *ctx);
|
|
439
|
+
void JS_AddIntrinsicStringNormalize(JSContext *ctx);
|
|
440
|
+
void JS_AddIntrinsicRegExpCompiler(JSContext *ctx);
|
|
441
|
+
void JS_AddIntrinsicRegExp(JSContext *ctx);
|
|
442
|
+
void JS_AddIntrinsicJSON(JSContext *ctx);
|
|
443
|
+
void JS_AddIntrinsicProxy(JSContext *ctx);
|
|
444
|
+
void JS_AddIntrinsicMapSet(JSContext *ctx);
|
|
445
|
+
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
|
|
446
|
+
void JS_AddIntrinsicPromise(JSContext *ctx);
|
|
447
|
+
void JS_AddIntrinsicBigInt(JSContext *ctx);
|
|
448
|
+
void JS_AddIntrinsicBigFloat(JSContext *ctx);
|
|
449
|
+
void JS_AddIntrinsicBigDecimal(JSContext *ctx);
|
|
450
|
+
/* enable operator overloading */
|
|
451
|
+
void JS_AddIntrinsicOperators(JSContext *ctx);
|
|
452
|
+
/* enable "use math" */
|
|
453
|
+
void JS_EnableBignumExt(JSContext *ctx, JS_BOOL enable);
|
|
454
|
+
|
|
455
|
+
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
|
|
456
|
+
int argc, JSValueConst *argv);
|
|
457
|
+
|
|
458
|
+
void *js_malloc_rt(JSRuntime *rt, size_t size);
|
|
459
|
+
void js_free_rt(JSRuntime *rt, void *ptr);
|
|
460
|
+
void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size);
|
|
461
|
+
size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr);
|
|
462
|
+
void *js_mallocz_rt(JSRuntime *rt, size_t size);
|
|
463
|
+
|
|
464
|
+
void *js_malloc(JSContext *ctx, size_t size);
|
|
465
|
+
void js_free(JSContext *ctx, void *ptr);
|
|
466
|
+
void *js_realloc(JSContext *ctx, void *ptr, size_t size);
|
|
467
|
+
size_t js_malloc_usable_size(JSContext *ctx, const void *ptr);
|
|
468
|
+
void *js_realloc2(JSContext *ctx, void *ptr, size_t size, size_t *pslack);
|
|
469
|
+
void *js_mallocz(JSContext *ctx, size_t size);
|
|
470
|
+
char *js_strdup(JSContext *ctx, const char *str);
|
|
471
|
+
char *js_strndup(JSContext *ctx, const char *s, size_t n);
|
|
472
|
+
|
|
473
|
+
typedef struct JSMemoryUsage {
|
|
474
|
+
int64_t malloc_size, malloc_limit, memory_used_size;
|
|
475
|
+
int64_t malloc_count;
|
|
476
|
+
int64_t memory_used_count;
|
|
477
|
+
int64_t atom_count, atom_size;
|
|
478
|
+
int64_t str_count, str_size;
|
|
479
|
+
int64_t obj_count, obj_size;
|
|
480
|
+
int64_t prop_count, prop_size;
|
|
481
|
+
int64_t shape_count, shape_size;
|
|
482
|
+
int64_t js_func_count, js_func_size, js_func_code_size;
|
|
483
|
+
int64_t js_func_pc2line_count, js_func_pc2line_size;
|
|
484
|
+
int64_t c_func_count, array_count;
|
|
485
|
+
int64_t fast_array_count, fast_array_elements;
|
|
486
|
+
int64_t binary_object_count, binary_object_size;
|
|
487
|
+
} JSMemoryUsage;
|
|
488
|
+
|
|
489
|
+
void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s);
|
|
490
|
+
void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt);
|
|
491
|
+
|
|
492
|
+
/* atom support */
|
|
493
|
+
#define JS_ATOM_NULL 0
|
|
494
|
+
|
|
495
|
+
JSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len);
|
|
496
|
+
JSAtom JS_NewAtom(JSContext *ctx, const char *str);
|
|
497
|
+
JSAtom JS_NewAtomUInt32(JSContext *ctx, uint32_t n);
|
|
498
|
+
JSAtom JS_DupAtom(JSContext *ctx, JSAtom v);
|
|
499
|
+
void JS_FreeAtom(JSContext *ctx, JSAtom v);
|
|
500
|
+
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
|
|
501
|
+
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
|
|
502
|
+
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
|
|
503
|
+
const char *JS_AtomToCString(JSContext *ctx, JSAtom atom);
|
|
504
|
+
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
|
|
505
|
+
|
|
506
|
+
/* object class support */
|
|
507
|
+
|
|
508
|
+
typedef struct JSPropertyEnum {
|
|
509
|
+
JS_BOOL is_enumerable;
|
|
510
|
+
JSAtom atom;
|
|
511
|
+
} JSPropertyEnum;
|
|
512
|
+
|
|
513
|
+
typedef struct JSPropertyDescriptor {
|
|
514
|
+
int flags;
|
|
515
|
+
JSValue value;
|
|
516
|
+
JSValue getter;
|
|
517
|
+
JSValue setter;
|
|
518
|
+
} JSPropertyDescriptor;
|
|
519
|
+
|
|
520
|
+
typedef struct JSClassExoticMethods {
|
|
521
|
+
/* Return -1 if exception (can only happen in case of Proxy object),
|
|
522
|
+
FALSE if the property does not exist, TRUE if it exists. If 1 is
|
|
523
|
+
returned, the property descriptor 'desc' is filled if != NULL. */
|
|
524
|
+
int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,
|
|
525
|
+
JSValueConst obj, JSAtom prop);
|
|
526
|
+
/* '*ptab' should hold the '*plen' property keys. Return 0 if OK,
|
|
527
|
+
-1 if exception. The 'is_enumerable' field is ignored.
|
|
528
|
+
*/
|
|
529
|
+
int (*get_own_property_names)(JSContext *ctx, JSPropertyEnum **ptab,
|
|
530
|
+
uint32_t *plen,
|
|
531
|
+
JSValueConst obj);
|
|
532
|
+
/* return < 0 if exception, or TRUE/FALSE */
|
|
533
|
+
int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);
|
|
534
|
+
/* return < 0 if exception or TRUE/FALSE */
|
|
535
|
+
int (*define_own_property)(JSContext *ctx, JSValueConst this_obj,
|
|
536
|
+
JSAtom prop, JSValueConst val,
|
|
537
|
+
JSValueConst getter, JSValueConst setter,
|
|
538
|
+
int flags);
|
|
539
|
+
/* The following methods can be emulated with the previous ones,
|
|
540
|
+
so they are usually not needed */
|
|
541
|
+
/* return < 0 if exception or TRUE/FALSE */
|
|
542
|
+
int (*has_property)(JSContext *ctx, JSValueConst obj, JSAtom atom);
|
|
543
|
+
JSValue (*get_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
|
|
544
|
+
JSValueConst receiver);
|
|
545
|
+
/* return < 0 if exception or TRUE/FALSE */
|
|
546
|
+
int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
|
|
547
|
+
JSValueConst value, JSValueConst receiver, int flags);
|
|
548
|
+
} JSClassExoticMethods;
|
|
549
|
+
|
|
550
|
+
typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
|
|
551
|
+
typedef void JSClassGCMark(JSRuntime *rt, JSValueConst val,
|
|
552
|
+
JS_MarkFunc *mark_func);
|
|
553
|
+
#define JS_CALL_FLAG_CONSTRUCTOR (1 << 0)
|
|
554
|
+
typedef JSValue JSClassCall(JSContext *ctx, JSValueConst func_obj,
|
|
555
|
+
JSValueConst this_val, int argc, JSValueConst *argv,
|
|
556
|
+
int flags);
|
|
557
|
+
|
|
558
|
+
typedef struct JSClassDef {
|
|
559
|
+
const char *class_name;
|
|
560
|
+
JSClassFinalizer *finalizer;
|
|
561
|
+
JSClassGCMark *gc_mark;
|
|
562
|
+
/* if call != NULL, the object is a function. If (flags &
|
|
563
|
+
JS_CALL_FLAG_CONSTRUCTOR) != 0, the function is called as a
|
|
564
|
+
constructor. In this case, 'this_val' is new.target. A
|
|
565
|
+
constructor call only happens if the object constructor bit is
|
|
566
|
+
set (see JS_SetConstructorBit()). */
|
|
567
|
+
JSClassCall *call;
|
|
568
|
+
/* XXX: suppress this indirection ? It is here only to save memory
|
|
569
|
+
because only a few classes need these methods */
|
|
570
|
+
JSClassExoticMethods *exotic;
|
|
571
|
+
} JSClassDef;
|
|
572
|
+
|
|
573
|
+
JSClassID JS_NewClassID(JSClassID *pclass_id);
|
|
574
|
+
int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);
|
|
575
|
+
int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
|
|
576
|
+
|
|
577
|
+
/* value handling */
|
|
578
|
+
|
|
579
|
+
static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
|
|
580
|
+
{
|
|
581
|
+
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
static js_force_inline JSValue JS_NewInt32(JSContext *ctx, int32_t val)
|
|
585
|
+
{
|
|
586
|
+
return JS_MKVAL(JS_TAG_INT, val);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
static js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val)
|
|
590
|
+
{
|
|
591
|
+
return JS_MKVAL(JS_TAG_CATCH_OFFSET, val);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val)
|
|
595
|
+
{
|
|
596
|
+
JSValue v;
|
|
597
|
+
if (val == (int32_t)val) {
|
|
598
|
+
v = JS_NewInt32(ctx, val);
|
|
599
|
+
} else {
|
|
600
|
+
v = __JS_NewFloat64(ctx, val);
|
|
601
|
+
}
|
|
602
|
+
return v;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
static js_force_inline JSValue JS_NewUint32(JSContext *ctx, uint32_t val)
|
|
606
|
+
{
|
|
607
|
+
JSValue v;
|
|
608
|
+
if (val <= 0x7fffffff) {
|
|
609
|
+
v = JS_NewInt32(ctx, val);
|
|
610
|
+
} else {
|
|
611
|
+
v = __JS_NewFloat64(ctx, val);
|
|
612
|
+
}
|
|
613
|
+
return v;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
JSValue JS_NewBigInt64(JSContext *ctx, int64_t v);
|
|
617
|
+
JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v);
|
|
618
|
+
|
|
619
|
+
static js_force_inline JSValue JS_NewFloat64(JSContext *ctx, double d)
|
|
620
|
+
{
|
|
621
|
+
JSValue v;
|
|
622
|
+
int32_t val;
|
|
623
|
+
union {
|
|
624
|
+
double d;
|
|
625
|
+
uint64_t u;
|
|
626
|
+
} u, t;
|
|
627
|
+
u.d = d;
|
|
628
|
+
val = (int32_t)d;
|
|
629
|
+
t.d = val;
|
|
630
|
+
/* -0 cannot be represented as integer, so we compare the bit
|
|
631
|
+
representation */
|
|
632
|
+
if (u.u == t.u) {
|
|
633
|
+
v = JS_MKVAL(JS_TAG_INT, val);
|
|
634
|
+
} else {
|
|
635
|
+
v = __JS_NewFloat64(ctx, d);
|
|
636
|
+
}
|
|
637
|
+
return v;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
static inline JS_BOOL JS_IsNumber(JSValueConst v)
|
|
641
|
+
{
|
|
642
|
+
int tag = JS_VALUE_GET_TAG(v);
|
|
643
|
+
return tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v)
|
|
647
|
+
{
|
|
648
|
+
int tag = JS_VALUE_GET_TAG(v);
|
|
649
|
+
return tag == JS_TAG_BIG_INT;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
static inline JS_BOOL JS_IsBigFloat(JSValueConst v)
|
|
653
|
+
{
|
|
654
|
+
int tag = JS_VALUE_GET_TAG(v);
|
|
655
|
+
return tag == JS_TAG_BIG_FLOAT;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
static inline JS_BOOL JS_IsBigDecimal(JSValueConst v)
|
|
659
|
+
{
|
|
660
|
+
int tag = JS_VALUE_GET_TAG(v);
|
|
661
|
+
return tag == JS_TAG_BIG_DECIMAL;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
static inline JS_BOOL JS_IsBool(JSValueConst v)
|
|
665
|
+
{
|
|
666
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
static inline JS_BOOL JS_IsNull(JSValueConst v)
|
|
670
|
+
{
|
|
671
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_NULL;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
static inline JS_BOOL JS_IsUndefined(JSValueConst v)
|
|
675
|
+
{
|
|
676
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
static inline JS_BOOL JS_IsException(JSValueConst v)
|
|
680
|
+
{
|
|
681
|
+
return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
static inline JS_BOOL JS_IsUninitialized(JSValueConst v)
|
|
685
|
+
{
|
|
686
|
+
return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_UNINITIALIZED);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
static inline JS_BOOL JS_IsString(JSValueConst v)
|
|
690
|
+
{
|
|
691
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_STRING;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
static inline JS_BOOL JS_IsSymbol(JSValueConst v)
|
|
695
|
+
{
|
|
696
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_SYMBOL;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
static inline JS_BOOL JS_IsObject(JSValueConst v)
|
|
700
|
+
{
|
|
701
|
+
return JS_VALUE_GET_TAG(v) == JS_TAG_OBJECT;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
JS_BOOL JS_IsPrimitive(JSValueConst value);
|
|
705
|
+
|
|
706
|
+
JSValue JS_Throw(JSContext *ctx, JSValue obj);
|
|
707
|
+
JSValue JS_GetException(JSContext *ctx);
|
|
708
|
+
JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
|
|
709
|
+
void JS_ResetUncatchableError(JSContext *ctx);
|
|
710
|
+
JSValue JS_NewError(JSContext *ctx);
|
|
711
|
+
JSValue __js_printf_like(2, 3) JS_ThrowError(JSContext *ctx, const char *fmt, ...);
|
|
712
|
+
JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...);
|
|
713
|
+
JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...);
|
|
714
|
+
JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...);
|
|
715
|
+
JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...);
|
|
716
|
+
JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
|
|
717
|
+
JSValue JS_ThrowOutOfMemory(JSContext *ctx);
|
|
718
|
+
void JS_AddPropertyToException(JSContext *ctx, const char *propName, JSValue value);
|
|
719
|
+
|
|
720
|
+
void __JS_FreeValue(JSContext *ctx, JSValue v);
|
|
721
|
+
static inline void JS_FreeValue(JSContext *ctx, JSValue v)
|
|
722
|
+
{
|
|
723
|
+
if (JS_VALUE_HAS_REF_COUNT(v)) {
|
|
724
|
+
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
|
|
725
|
+
if (--p->ref_count <= 0) {
|
|
726
|
+
__JS_FreeValue(ctx, v);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
void __JS_FreeValueRT(JSRuntime *rt, JSValue v);
|
|
731
|
+
static inline void JS_FreeValueRT(JSRuntime *rt, JSValue v)
|
|
732
|
+
{
|
|
733
|
+
if (JS_VALUE_HAS_REF_COUNT(v)) {
|
|
734
|
+
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
|
|
735
|
+
if (--p->ref_count <= 0) {
|
|
736
|
+
__JS_FreeValueRT(rt, v);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v)
|
|
742
|
+
{
|
|
743
|
+
if (JS_VALUE_HAS_REF_COUNT(v)) {
|
|
744
|
+
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
|
|
745
|
+
p->ref_count++;
|
|
746
|
+
}
|
|
747
|
+
return (JSValue)v;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
|
|
751
|
+
{
|
|
752
|
+
if (JS_VALUE_HAS_REF_COUNT(v)) {
|
|
753
|
+
JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
|
|
754
|
+
p->ref_count++;
|
|
755
|
+
}
|
|
756
|
+
return (JSValue)v;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/* returns -1 when exception has been thrown, 0 or 1 when ok */
|
|
760
|
+
int JS_ToBool(JSContext *ctx, JSValueConst val);
|
|
761
|
+
/* returns -1 when exception has been thrown, 0 when ok */
|
|
762
|
+
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
|
|
763
|
+
/* returns -1 when exception has been thrown, 0 when ok */
|
|
764
|
+
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
|
|
765
|
+
{
|
|
766
|
+
return JS_ToInt32(ctx, (int32_t*)pres, val);
|
|
767
|
+
}
|
|
768
|
+
/* returns -1 when exception has been thrown, 0 when ok */
|
|
769
|
+
int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
|
770
|
+
/* returns -1 when exception has been thrown, 0 when ok */
|
|
771
|
+
int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val);
|
|
772
|
+
/* returns -1 when exception has been thrown, 0 when ok */
|
|
773
|
+
int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val);
|
|
774
|
+
/* returns -1 when exception has been thrown, 0 when ok. throws an exception if 'val' is a Number */
|
|
775
|
+
int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val);
|
|
776
|
+
/* same as JS_ToInt64() but allows BigInt. returns -1 when exception has been thrown, 0 when ok */
|
|
777
|
+
int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val);
|
|
778
|
+
|
|
779
|
+
/* creates a string from a UTF-8 buffer. the buffer is copied. */
|
|
780
|
+
JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1);
|
|
781
|
+
/* creates a string from a UTF-8 buffer. the buffer is copied. */
|
|
782
|
+
JSValue JS_NewString(JSContext *ctx, const char *str);
|
|
783
|
+
JSValue JS_NewAtomString(JSContext *ctx, const char *str);
|
|
784
|
+
JSValue JS_ToString(JSContext *ctx, JSValueConst val);
|
|
785
|
+
JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val);
|
|
786
|
+
const char *JS_ToCStringLen2(JSContext *ctx, size_t *plen, JSValueConst val1, JS_BOOL cesu8);
|
|
787
|
+
static inline const char *JS_ToCStringLen(JSContext *ctx, size_t *plen, JSValueConst val1)
|
|
788
|
+
{
|
|
789
|
+
return JS_ToCStringLen2(ctx, plen, val1, 0);
|
|
790
|
+
}
|
|
791
|
+
static inline const char *JS_ToCString(JSContext *ctx, JSValueConst val1)
|
|
792
|
+
{
|
|
793
|
+
return JS_ToCStringLen2(ctx, NULL, val1, 0);
|
|
794
|
+
}
|
|
795
|
+
void JS_FreeCString(JSContext *ctx, const char *ptr);
|
|
796
|
+
|
|
797
|
+
JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto, JSClassID class_id);
|
|
798
|
+
JSValue JS_NewObjectClass(JSContext *ctx, int class_id);
|
|
799
|
+
JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto);
|
|
800
|
+
JSValue JS_NewObject(JSContext *ctx);
|
|
801
|
+
|
|
802
|
+
JS_BOOL JS_IsFunction(JSContext* ctx, JSValueConst val);
|
|
803
|
+
JS_BOOL JS_IsConstructor(JSContext* ctx, JSValueConst val);
|
|
804
|
+
/* returns whether the bit was set (doesn't get set if func_obj is a primitive) */
|
|
805
|
+
JS_BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, JS_BOOL val);
|
|
806
|
+
|
|
807
|
+
JSValue JS_NewArray(JSContext *ctx);
|
|
808
|
+
int JS_IsArray(JSContext *ctx, JSValueConst val);
|
|
809
|
+
|
|
810
|
+
JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
|
|
811
|
+
JSAtom prop, JSValueConst receiver,
|
|
812
|
+
JS_BOOL throw_ref_error);
|
|
813
|
+
static js_force_inline JSValue JS_GetProperty(JSContext *ctx, JSValueConst this_obj,
|
|
814
|
+
JSAtom prop)
|
|
815
|
+
{
|
|
816
|
+
return JS_GetPropertyInternal(ctx, this_obj, prop, this_obj, 0);
|
|
817
|
+
}
|
|
818
|
+
JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,
|
|
819
|
+
const char *prop);
|
|
820
|
+
JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
|
|
821
|
+
uint32_t idx);
|
|
822
|
+
|
|
823
|
+
/*
|
|
824
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is
|
|
825
|
+
freed by the function. 'flags' is a bitmask of JS_PROP_NO_ADD,
|
|
826
|
+
JS_PROP_THROW or JS_PROP_THROW_STRICT. If JS_PROP_NO_ADD is set,
|
|
827
|
+
the new property is not added and an error is raised.
|
|
828
|
+
*/
|
|
829
|
+
int JS_SetPropertyInternal(JSContext *ctx, JSValueConst this_obj,
|
|
830
|
+
JSAtom prop, JSValue val,
|
|
831
|
+
int flags);
|
|
832
|
+
|
|
833
|
+
/*
|
|
834
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is freed by the
|
|
835
|
+
function.
|
|
836
|
+
*/
|
|
837
|
+
static inline int JS_SetProperty(JSContext *ctx, JSValueConst this_obj,
|
|
838
|
+
JSAtom prop, JSValue val)
|
|
839
|
+
{
|
|
840
|
+
return JS_SetPropertyInternal(ctx, this_obj, prop, val, JS_PROP_THROW);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/*
|
|
844
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is freed by the
|
|
845
|
+
function.
|
|
846
|
+
*/
|
|
847
|
+
int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
|
|
848
|
+
uint32_t idx, JSValue val);
|
|
849
|
+
|
|
850
|
+
/*
|
|
851
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is freed by the
|
|
852
|
+
function.
|
|
853
|
+
*/
|
|
854
|
+
int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
|
|
855
|
+
int64_t idx, JSValue val);
|
|
856
|
+
|
|
857
|
+
/*
|
|
858
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is freed by the
|
|
859
|
+
function.
|
|
860
|
+
*/
|
|
861
|
+
int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
|
|
862
|
+
const char *prop, JSValue val);
|
|
863
|
+
|
|
864
|
+
/*
|
|
865
|
+
return -1 in case of exception or TRUE or FALSE. Warning: 'val' is
|
|
866
|
+
freed by the function. 'flags' is a bitmask of JS_PROP_THROW and/or
|
|
867
|
+
JS_PROP_THROW_STRICT.
|
|
868
|
+
*/
|
|
869
|
+
int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
|
|
870
|
+
JSValue prop, JSValue val, int flags);
|
|
871
|
+
int JS_HasProperty(JSContext *ctx, JSValueConst this_obj, JSAtom prop);
|
|
872
|
+
int JS_IsExtensible(JSContext *ctx, JSValueConst obj);
|
|
873
|
+
int JS_PreventExtensions(JSContext *ctx, JSValueConst obj);
|
|
874
|
+
int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int flags);
|
|
875
|
+
int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
|
|
876
|
+
JSValue JS_GetPrototype(JSContext *ctx, JSValueConst val);
|
|
877
|
+
|
|
878
|
+
#define JS_GPN_STRING_MASK (1 << 0)
|
|
879
|
+
#define JS_GPN_SYMBOL_MASK (1 << 1)
|
|
880
|
+
#define JS_GPN_PRIVATE_MASK (1 << 2)
|
|
881
|
+
/* only include the enumerable properties */
|
|
882
|
+
#define JS_GPN_ENUM_ONLY (1 << 4)
|
|
883
|
+
/* set the JSPropertyEnum.is_enumerable field */
|
|
884
|
+
#define JS_GPN_SET_ENUM (1 << 5)
|
|
885
|
+
|
|
886
|
+
int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
|
|
887
|
+
uint32_t *plen, JSValueConst obj, int flags);
|
|
888
|
+
int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
|
|
889
|
+
JSValueConst obj, JSAtom prop);
|
|
890
|
+
|
|
891
|
+
JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj,
|
|
892
|
+
int argc, JSValueConst *argv);
|
|
893
|
+
JSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,
|
|
894
|
+
int argc, JSValueConst *argv);
|
|
895
|
+
JSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,
|
|
896
|
+
int argc, JSValueConst *argv);
|
|
897
|
+
JSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,
|
|
898
|
+
JSValueConst new_target,
|
|
899
|
+
int argc, JSValueConst *argv);
|
|
900
|
+
JS_BOOL JS_DetectModule(const char *input, size_t input_len);
|
|
901
|
+
/* 'input' must be zero terminated i.e. input[input_len] = '\0'. */
|
|
902
|
+
JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
|
|
903
|
+
const char *filename, int eval_flags);
|
|
904
|
+
/* same as JS_Eval() but with an explicit 'this_obj' parameter */
|
|
905
|
+
JSValue JS_EvalThis(JSContext *ctx, JSValueConst this_obj,
|
|
906
|
+
const char *input, size_t input_len,
|
|
907
|
+
const char *filename, int eval_flags);
|
|
908
|
+
/* A way to eval code even if the context itself doesn't have eval */
|
|
909
|
+
JSValue JS_EvalThis_Privileged(JSContext *ctx, JSValueConst this_obj,
|
|
910
|
+
const char *input, size_t input_len,
|
|
911
|
+
const char *filename, int eval_flags);
|
|
912
|
+
/* NOTE: you must free it! */
|
|
913
|
+
JSValue JS_GetGlobalObject(JSContext *ctx);
|
|
914
|
+
int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj);
|
|
915
|
+
int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
|
|
916
|
+
JSAtom prop, JSValueConst val,
|
|
917
|
+
JSValueConst getter, JSValueConst setter, int flags);
|
|
918
|
+
int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,
|
|
919
|
+
JSAtom prop, JSValue val, int flags);
|
|
920
|
+
int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
|
|
921
|
+
uint32_t idx, JSValue val, int flags);
|
|
922
|
+
int JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,
|
|
923
|
+
const char *prop, JSValue val, int flags);
|
|
924
|
+
int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
|
|
925
|
+
JSAtom prop, JSValue getter, JSValue setter,
|
|
926
|
+
int flags);
|
|
927
|
+
void JS_SetOpaque(JSValue obj, void *opaque);
|
|
928
|
+
void *JS_GetOpaque(JSValueConst obj, JSClassID class_id);
|
|
929
|
+
void *JS_GetOpaque2(JSContext *ctx, JSValueConst obj, JSClassID class_id);
|
|
930
|
+
|
|
931
|
+
/* 'buf' must be zero terminated i.e. buf[buf_len] = '\0'. */
|
|
932
|
+
JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
|
|
933
|
+
const char *filename);
|
|
934
|
+
#define JS_PARSE_JSON_EXT (1 << 0) /* allow extended JSON */
|
|
935
|
+
JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
|
|
936
|
+
const char *filename, int flags);
|
|
937
|
+
JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
|
|
938
|
+
JSValueConst replacer, JSValueConst space0);
|
|
939
|
+
|
|
940
|
+
typedef void JSFreeArrayBufferDataFunc(JSRuntime *rt, void *opaque, void *ptr);
|
|
941
|
+
JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
|
942
|
+
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
|
943
|
+
JS_BOOL is_shared);
|
|
944
|
+
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
|
945
|
+
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
|
|
946
|
+
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
|
|
947
|
+
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
|
|
948
|
+
size_t *pbyte_offset,
|
|
949
|
+
size_t *pbyte_length,
|
|
950
|
+
size_t *pbytes_per_element);
|
|
951
|
+
typedef struct {
|
|
952
|
+
void *(*sab_alloc)(void *opaque, size_t size);
|
|
953
|
+
void (*sab_free)(void *opaque, void *ptr);
|
|
954
|
+
void (*sab_dup)(void *opaque, void *ptr);
|
|
955
|
+
void *sab_opaque;
|
|
956
|
+
} JSSharedArrayBufferFunctions;
|
|
957
|
+
void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
|
|
958
|
+
const JSSharedArrayBufferFunctions *sf);
|
|
959
|
+
|
|
960
|
+
JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs);
|
|
961
|
+
|
|
962
|
+
/* is_handled = TRUE means that the rejection is handled */
|
|
963
|
+
typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,
|
|
964
|
+
JSValueConst reason,
|
|
965
|
+
JS_BOOL is_handled, void *opaque);
|
|
966
|
+
void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
|
|
967
|
+
|
|
968
|
+
/* return != 0 if the JS code needs to be interrupted */
|
|
969
|
+
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);
|
|
970
|
+
void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void *opaque);
|
|
971
|
+
/* if can_block is TRUE, Atomics.wait() can be used */
|
|
972
|
+
void JS_SetCanBlock(JSRuntime *rt, JS_BOOL can_block);
|
|
973
|
+
/* set the [IsHTMLDDA] internal slot */
|
|
974
|
+
void JS_SetIsHTMLDDA(JSContext *ctx, JSValueConst obj);
|
|
975
|
+
|
|
976
|
+
typedef struct JSModuleDef JSModuleDef;
|
|
977
|
+
|
|
978
|
+
/* return the module specifier (allocated with js_malloc()) or NULL if
|
|
979
|
+
exception */
|
|
980
|
+
typedef char *JSModuleNormalizeFunc(JSContext *ctx,
|
|
981
|
+
const char *module_base_name,
|
|
982
|
+
const char *module_name, void *opaque);
|
|
983
|
+
typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx,
|
|
984
|
+
const char *module_name, void *opaque);
|
|
985
|
+
|
|
986
|
+
void JS_SetModuleLoaderFunc(JSRuntime *rt,
|
|
987
|
+
JSModuleLoaderFunc *module_loader);
|
|
988
|
+
/* return the value set by JS_SetModuleLoaderFunc. could be NULL. */
|
|
989
|
+
JSModuleLoaderFunc *JS_GetModuleLoaderFunc(JSRuntime *rt);
|
|
990
|
+
|
|
991
|
+
/* module_normalize = NULL is allowed and invokes the default module
|
|
992
|
+
filename normalizer */
|
|
993
|
+
void JS_SetModuleNormalizeFunc(JSRuntime *rt,
|
|
994
|
+
JSModuleNormalizeFunc *module_normalize);
|
|
995
|
+
/* return the value set by JS_SetModuleNormalizeFunc. could be NULL. */
|
|
996
|
+
JSModuleNormalizeFunc *JS_GetModuleNormalizeFunc(JSRuntime *rt);
|
|
997
|
+
|
|
998
|
+
void JS_SetModuleLoaderOpaque(JSRuntime *rt, void *opaque);
|
|
999
|
+
/* return the value set by JS_SetModuleLoaderOpaque. could be NULL. */
|
|
1000
|
+
void *JS_GetModuleLoaderOpaque(JSRuntime *rt);
|
|
1001
|
+
|
|
1002
|
+
/* return the import.meta object of a module. you'll have to free it when done */
|
|
1003
|
+
JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m);
|
|
1004
|
+
JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m);
|
|
1005
|
+
|
|
1006
|
+
/* JS Job support */
|
|
1007
|
+
|
|
1008
|
+
typedef JSValue JSJobFunc(JSContext *ctx, int argc, JSValueConst *argv);
|
|
1009
|
+
int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, int argc, JSValueConst *argv);
|
|
1010
|
+
|
|
1011
|
+
JS_BOOL JS_IsJobPending(JSRuntime *rt);
|
|
1012
|
+
int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx);
|
|
1013
|
+
|
|
1014
|
+
/* Object Writer/Reader (currently only used to handle precompiled code) */
|
|
1015
|
+
#define JS_WRITE_OBJ_BYTECODE (1 << 0) /* allow function/module */
|
|
1016
|
+
#define JS_WRITE_OBJ_BSWAP (1 << 1) /* byte swapped output */
|
|
1017
|
+
#define JS_WRITE_OBJ_SAB (1 << 2) /* allow SharedArrayBuffer */
|
|
1018
|
+
#define JS_WRITE_OBJ_REFERENCE (1 << 3) /* allow object references to
|
|
1019
|
+
encode arbitrary object
|
|
1020
|
+
graph */
|
|
1021
|
+
uint8_t *JS_WriteObject(JSContext *ctx, size_t *psize, JSValueConst obj,
|
|
1022
|
+
int flags);
|
|
1023
|
+
uint8_t *JS_WriteObject2(JSContext *ctx, size_t *psize, JSValueConst obj,
|
|
1024
|
+
int flags, uint8_t ***psab_tab, size_t *psab_tab_len);
|
|
1025
|
+
|
|
1026
|
+
#define JS_READ_OBJ_BYTECODE (1 << 0) /* allow function/module */
|
|
1027
|
+
#define JS_READ_OBJ_ROM_DATA (1 << 1) /* avoid duplicating 'buf' data */
|
|
1028
|
+
#define JS_READ_OBJ_SAB (1 << 2) /* allow SharedArrayBuffer */
|
|
1029
|
+
#define JS_READ_OBJ_REFERENCE (1 << 3) /* allow object references */
|
|
1030
|
+
JSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,
|
|
1031
|
+
int flags);
|
|
1032
|
+
/* instantiate and evaluate a bytecode function. Only used when
|
|
1033
|
+
reading a script or module with JS_ReadObject() */
|
|
1034
|
+
JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj);
|
|
1035
|
+
/* load the dependencies of the module 'obj'. Useful when JS_ReadObject()
|
|
1036
|
+
returns a module. returns 0 on success, -1 on error. */
|
|
1037
|
+
int JS_ResolveModule(JSContext *ctx, JSValueConst obj);
|
|
1038
|
+
|
|
1039
|
+
JSAtom JS_GetScriptOrModuleName(JSContext *ctx, int n_stack_levels);
|
|
1040
|
+
JSModuleDef *JS_RunModule(JSContext *ctx, const char *basename,
|
|
1041
|
+
const char *filename);
|
|
1042
|
+
|
|
1043
|
+
/* Freeze a value with Object.freeze. */
|
|
1044
|
+
JSValue JS_FreezeObjectValue(JSContext *ctx, JSValueConst val);
|
|
1045
|
+
|
|
1046
|
+
/* C function definition */
|
|
1047
|
+
typedef enum JSCFunctionEnum { /* XXX: should rename for namespace isolation */
|
|
1048
|
+
JS_CFUNC_generic,
|
|
1049
|
+
JS_CFUNC_generic_magic,
|
|
1050
|
+
JS_CFUNC_constructor,
|
|
1051
|
+
JS_CFUNC_constructor_magic,
|
|
1052
|
+
JS_CFUNC_constructor_or_func,
|
|
1053
|
+
JS_CFUNC_constructor_or_func_magic,
|
|
1054
|
+
JS_CFUNC_f_f,
|
|
1055
|
+
JS_CFUNC_f_f_f,
|
|
1056
|
+
JS_CFUNC_getter,
|
|
1057
|
+
JS_CFUNC_setter,
|
|
1058
|
+
JS_CFUNC_getter_magic,
|
|
1059
|
+
JS_CFUNC_setter_magic,
|
|
1060
|
+
JS_CFUNC_iterator_next,
|
|
1061
|
+
} JSCFunctionEnum;
|
|
1062
|
+
|
|
1063
|
+
typedef union JSCFunctionType {
|
|
1064
|
+
JSCFunction *generic;
|
|
1065
|
+
JSValue (*generic_magic)(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
|
|
1066
|
+
JSCFunction *constructor;
|
|
1067
|
+
JSValue (*constructor_magic)(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic);
|
|
1068
|
+
JSCFunction *constructor_or_func;
|
|
1069
|
+
double (*f_f)(double);
|
|
1070
|
+
double (*f_f_f)(double, double);
|
|
1071
|
+
JSValue (*getter)(JSContext *ctx, JSValueConst this_val);
|
|
1072
|
+
JSValue (*setter)(JSContext *ctx, JSValueConst this_val, JSValueConst val);
|
|
1073
|
+
JSValue (*getter_magic)(JSContext *ctx, JSValueConst this_val, int magic);
|
|
1074
|
+
JSValue (*setter_magic)(JSContext *ctx, JSValueConst this_val, JSValueConst val, int magic);
|
|
1075
|
+
JSValue (*iterator_next)(JSContext *ctx, JSValueConst this_val,
|
|
1076
|
+
int argc, JSValueConst *argv, int *pdone, int magic);
|
|
1077
|
+
} JSCFunctionType;
|
|
1078
|
+
|
|
1079
|
+
JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
|
|
1080
|
+
const char *name,
|
|
1081
|
+
int length, JSCFunctionEnum cproto, int magic);
|
|
1082
|
+
JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
|
|
1083
|
+
int length, int magic, int data_len,
|
|
1084
|
+
JSValueConst *data);
|
|
1085
|
+
|
|
1086
|
+
static inline JSValue JS_NewCFunction(JSContext *ctx, JSCFunction *func, const char *name,
|
|
1087
|
+
int length)
|
|
1088
|
+
{
|
|
1089
|
+
return JS_NewCFunction2(ctx, func, name, length, JS_CFUNC_generic, 0);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
static inline JSValue JS_NewCFunctionMagic(JSContext *ctx, JSCFunctionMagic *func,
|
|
1093
|
+
const char *name,
|
|
1094
|
+
int length, JSCFunctionEnum cproto, int magic)
|
|
1095
|
+
{
|
|
1096
|
+
return JS_NewCFunction2(ctx, (JSCFunction *)func, name, length, cproto, magic);
|
|
1097
|
+
}
|
|
1098
|
+
void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
|
|
1099
|
+
JSValueConst proto);
|
|
1100
|
+
|
|
1101
|
+
/* C property definition */
|
|
1102
|
+
|
|
1103
|
+
typedef struct JSCFunctionListEntry {
|
|
1104
|
+
const char *name;
|
|
1105
|
+
uint8_t prop_flags;
|
|
1106
|
+
uint8_t def_type;
|
|
1107
|
+
int16_t magic;
|
|
1108
|
+
union {
|
|
1109
|
+
struct {
|
|
1110
|
+
uint8_t length; /* XXX: should move outside union */
|
|
1111
|
+
uint8_t cproto; /* XXX: should move outside union */
|
|
1112
|
+
JSCFunctionType cfunc;
|
|
1113
|
+
} func;
|
|
1114
|
+
struct {
|
|
1115
|
+
JSCFunctionType get;
|
|
1116
|
+
JSCFunctionType set;
|
|
1117
|
+
} getset;
|
|
1118
|
+
struct {
|
|
1119
|
+
const char *name;
|
|
1120
|
+
int base;
|
|
1121
|
+
} alias;
|
|
1122
|
+
struct {
|
|
1123
|
+
const struct JSCFunctionListEntry *tab;
|
|
1124
|
+
int len;
|
|
1125
|
+
} prop_list;
|
|
1126
|
+
const char *str;
|
|
1127
|
+
int32_t i32;
|
|
1128
|
+
int64_t i64;
|
|
1129
|
+
double f64;
|
|
1130
|
+
} u;
|
|
1131
|
+
} JSCFunctionListEntry;
|
|
1132
|
+
|
|
1133
|
+
#define JS_DEF_CFUNC 0
|
|
1134
|
+
#define JS_DEF_CGETSET 1
|
|
1135
|
+
#define JS_DEF_CGETSET_MAGIC 2
|
|
1136
|
+
#define JS_DEF_PROP_STRING 3
|
|
1137
|
+
#define JS_DEF_PROP_INT32 4
|
|
1138
|
+
#define JS_DEF_PROP_INT64 5
|
|
1139
|
+
#define JS_DEF_PROP_DOUBLE 6
|
|
1140
|
+
#define JS_DEF_PROP_UNDEFINED 7
|
|
1141
|
+
#define JS_DEF_OBJECT 8
|
|
1142
|
+
#define JS_DEF_ALIAS 9
|
|
1143
|
+
|
|
1144
|
+
/* Note: c++ does not like nested designators */
|
|
1145
|
+
#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 } } } }
|
|
1146
|
+
#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 } } } }
|
|
1147
|
+
#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 } } } }
|
|
1148
|
+
#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 } } } }
|
|
1149
|
+
#define JS_CGETSET_DEF(name, fgetter, fsetter) { name, JS_PROP_CONFIGURABLE, JS_DEF_CGETSET, 0, .u = { .getset = { .get = { .getter = fgetter }, .set = { .setter = fsetter } } } }
|
|
1150
|
+
#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 } } } }
|
|
1151
|
+
#define JS_PROP_STRING_DEF(name, cstr, prop_flags) { name, prop_flags, JS_DEF_PROP_STRING, 0, .u = { .str = cstr } }
|
|
1152
|
+
#define JS_PROP_INT32_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT32, 0, .u = { .i32 = val } }
|
|
1153
|
+
#define JS_PROP_INT64_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_INT64, 0, .u = { .i64 = val } }
|
|
1154
|
+
#define JS_PROP_DOUBLE_DEF(name, val, prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, .u = { .f64 = val } }
|
|
1155
|
+
#define JS_PROP_UNDEFINED_DEF(name, prop_flags) { name, prop_flags, JS_DEF_PROP_UNDEFINED, 0, .u = { .i32 = 0 } }
|
|
1156
|
+
#define JS_OBJECT_DEF(name, tab, len, prop_flags) { name, prop_flags, JS_DEF_OBJECT, 0, .u = { .prop_list = { tab, len } } }
|
|
1157
|
+
#define JS_ALIAS_DEF(name, from) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, -1 } } }
|
|
1158
|
+
#define JS_ALIAS_BASE_DEF(name, from, base) { name, JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE, JS_DEF_ALIAS, 0, .u = { .alias = { from, base } } }
|
|
1159
|
+
|
|
1160
|
+
void JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
|
|
1161
|
+
const JSCFunctionListEntry *tab,
|
|
1162
|
+
int len);
|
|
1163
|
+
|
|
1164
|
+
/* C module definition */
|
|
1165
|
+
|
|
1166
|
+
typedef int JSModuleInitFunc(JSContext *ctx, JSModuleDef *m);
|
|
1167
|
+
|
|
1168
|
+
/* user_data can be NULL */
|
|
1169
|
+
JSModuleDef *JS_NewCModule(JSContext *ctx, const char *name_str,
|
|
1170
|
+
JSModuleInitFunc *func, void *user_data);
|
|
1171
|
+
void *JS_GetModuleUserData(JSModuleDef *m);
|
|
1172
|
+
void JS_SetModuleUserData(JSModuleDef *m, void *user_data);
|
|
1173
|
+
/* can only be called before the module is instantiated */
|
|
1174
|
+
int JS_AddModuleExport(JSContext *ctx, JSModuleDef *m, const char *name_str);
|
|
1175
|
+
int JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,
|
|
1176
|
+
const JSCFunctionListEntry *tab, int len);
|
|
1177
|
+
/* can only be called after the module is instantiated */
|
|
1178
|
+
int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
|
|
1179
|
+
JSValue val);
|
|
1180
|
+
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
|
|
1181
|
+
const JSCFunctionListEntry *tab, int len);
|
|
1182
|
+
|
|
1183
|
+
/* module-related addons */
|
|
1184
|
+
JSValue JS_DynamicImportAsync(JSContext *ctx, JSValueConst specifier);
|
|
1185
|
+
JSValue JS_DynamicImportSync(JSContext *ctx, JSValueConst specifier);
|
|
1186
|
+
JSValue JS_DynamicImportSync2(JSContext *ctx, JSValueConst specifier, JSValueConst basename);
|
|
1187
|
+
|
|
1188
|
+
#undef js_unlikely
|
|
1189
|
+
#undef js_force_inline
|
|
1190
|
+
|
|
1191
|
+
#ifdef __cplusplus
|
|
1192
|
+
} /* extern "C" { */
|
|
1193
|
+
#endif
|
|
1194
|
+
|
|
1195
|
+
#endif /* QUICKJS_H */
|