@suchipi/quickjs 0.6.0 → 0.7.1
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 +26 -19
- package/build/aarch64-apple-darwin/bin/file-to-bytecode.js +7 -2
- 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/fib.so +0 -0
- package/build/aarch64-apple-darwin/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-apple-darwin/extras/log-argv +0 -0
- package/build/aarch64-apple-darwin/extras/point.so +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/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 +7 -2
- 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/fib.so +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/log-argv +0 -0
- package/build/aarch64-unknown-linux-gnu/extras/point.so +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/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 +7 -2
- 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/fib.so +0 -0
- package/build/aarch64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-musl/extras/point.so +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/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 +7 -2
- 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/fib.so +0 -0
- package/build/aarch64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
- package/build/aarch64-unknown-linux-static/extras/point.so +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/lib/quickjs-core.a +0 -0
- package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
- package/build/dts/quickjs-libbytecode.d.ts +5 -1
- package/build/dts/quickjs-libc.d.ts +1 -4
- package/build/dts/quickjs-libcontext.d.ts +3 -3
- package/build/dts/quickjs-libencoding.d.ts +5 -0
- package/build/dts/{quickjs-libmodule.d.ts → quickjs-libengine.d.ts} +24 -5
- package/build/dts/quickjs-modulesys.d.ts +19 -33
- package/build/x86_64-apple-darwin/bin/file-to-bytecode.js +7 -2
- 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/fib.so +0 -0
- package/build/x86_64-apple-darwin/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-apple-darwin/extras/log-argv +0 -0
- package/build/x86_64-apple-darwin/extras/point.so +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/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 +7 -2
- 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/log-argv.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/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 +7 -2
- 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/fib.so +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/log-argv +0 -0
- package/build/x86_64-unknown-linux-gnu/extras/point.so +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/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 +7 -2
- 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/fib.so +0 -0
- package/build/x86_64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-musl/extras/point.so +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/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 +7 -2
- 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/fib.so +0 -0
- package/build/x86_64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
- package/build/x86_64-unknown-linux-static/extras/point.so +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/lib/quickjs-core.a +0 -0
- package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with many changes.
|
|
|
63
63
|
- Several C-side helper functions were moved out of quickjs-libc and into quickjs-utils.
|
|
64
64
|
- Most module-related code (setting import.meta, etc) was moved into quickjs-modulesys.
|
|
65
65
|
- Added `std.setExitCode`, `std.getExitCode`, and made `std.exit`'s parameter optional. The value passed to `std.setExitCode` will be used when the process exits normally, or when `std.exit` is called without any arguments. `std.setExitCode`, `std.getExitCode`, and `std.exit` throw if called from a thread other than the main thread (ie. a Worker).
|
|
66
|
+
- The manual garbage collection function `std.gc()` was moved to `"quickjs:engine"`.
|
|
66
67
|
|
|
67
68
|
### Changes to the `qjs` binary:
|
|
68
69
|
|
|
@@ -105,6 +106,10 @@ A Module that allows JS code to create new JS Contexts (Realms). You can create
|
|
|
105
106
|
|
|
106
107
|
A barebones Module that exports a JS class which can be used to represent an opaque pointer. C modules can use the `js_new_pointer` function provided by this module to pass opaque pointer handles to users without needing to make their own wrapper class for stuff. This is mostly just useful in order to have a codified convention for how FFI libraries and such should represent foreign pointers.
|
|
107
108
|
|
|
109
|
+
### New module: "quickjs:encoding"
|
|
110
|
+
|
|
111
|
+
Text encoding/decoding functions. Currently just exports an ArrayBuffer-to-utf8-string function.
|
|
112
|
+
|
|
108
113
|
### New library: `quickjs-utils`
|
|
109
114
|
|
|
110
115
|
Helper structs, functions, and macros that make it easier to work with QuickJS in C code.
|
|
@@ -113,6 +118,10 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
|
|
|
113
118
|
- Helper function for loading a file from disk into char a buffer
|
|
114
119
|
- Helper functions for printing JS errors to stderr
|
|
115
120
|
|
|
121
|
+
### New module: "quickjs:engine"
|
|
122
|
+
|
|
123
|
+
This module contains APIs related to engine internals like script execution, module loading, code eval, filename reflection, and garbage collection. Several parts of quickjs-libc were moved here so that quickjs-libc could be focused on "C standard library" bindings.
|
|
124
|
+
|
|
116
125
|
### Changes to the module loader
|
|
117
126
|
|
|
118
127
|
- `.js` extensions can now be omitted from import specifiers; they're optional.
|
|
@@ -123,24 +132,22 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
|
|
|
123
132
|
- It's the same as the global `require`; it's just added to import.meta for compatibility with bundlers that output `import.meta.require`, like `bun`.
|
|
124
133
|
- Adds `import.meta.resolve`
|
|
125
134
|
- Similar to [the one in the browser](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve#specifications), but it's actually just `require.resolve` exposed via `import.meta`.
|
|
126
|
-
- Module and eval helpers have been moved from "quickjs:std" to the new module "quickjs:
|
|
127
|
-
- Makes the module loader's resolution and loading behavior configurable
|
|
128
|
-
- The module "quickjs:
|
|
129
|
-
- You can specify additional implicit import specifier extensions by adding to the `
|
|
130
|
-
- You can transform any file prior to evaluating it as a module by adding a function to the `
|
|
131
|
-
- You can
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- Note that you must handle `Module.compilers` yourself in your replacement implementation.
|
|
135
|
+
- Module and eval helpers have been moved from "quickjs:std" to the new module "quickjs:engine".
|
|
136
|
+
- Makes the module loader's resolution and loading behavior configurable
|
|
137
|
+
- The module "quickjs:engine" exports an object called `ModuleDelegate`.
|
|
138
|
+
- You can specify additional implicit import specifier extensions by adding to the `ModuleDelegate.searchExtensions` array.
|
|
139
|
+
- You can transform any file prior to evaluating it as a module by adding a function to the `ModuleDelegate.compilers` object. Useful for compile-to-ts languages like TypeScript, Coffeescript, etc.
|
|
140
|
+
- You can override module name normalization (aka module resolution) by replacing the `ModuleDelegate.resolve` function.
|
|
141
|
+
- Note that you must handle `ModuleDelegate.searchExtensions` yourself in your replacement implementation.
|
|
142
|
+
- You can override the method used to load modules by replacing the `ModuleDelegate.read` function.
|
|
143
|
+
- Note that you must handle `ModuleDelegate.compilers` yourself in your replacement implementation.
|
|
136
144
|
- Makes `import.meta.main` configurable
|
|
137
|
-
- The module "quickjs:
|
|
138
|
-
- You can use `setMainModule` to make `import.meta.main` true within that module's code. Note, however, that it does not work retroactively; only modules loaded after the `setMainModule` call will be affected. To defer module load, use `import()`, `importModule` from "quickjs:
|
|
145
|
+
- The module "quickjs:engine" exports two functions named `setMainModule` and `isMainModule`.
|
|
146
|
+
- You can use `setMainModule` to make `import.meta.main` true within that module's code. Note, however, that it does not work retroactively; only modules loaded after the `setMainModule` call will be affected. To defer module load, use `import()`, `importModule` from "quickjs:engine", or `require`.
|
|
139
147
|
- You can use `isMainModule` to check if a given module would be the main module without loading it.
|
|
140
|
-
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- When using `require` to load a module which contains an export named `__cjsExports`, the value of the `__cjsExports` property will be returned from `require` instead of the usual module namespace object. This can be leveraged by users configuring the module loader to add some CommonJS <-> ESM interop. Note, however, that dynamic import and `"quickjs:module"`'s `importModule` always receive the usual module namespace object.
|
|
148
|
+
- New `isModuleNamespace` function lets users identify module namespace objects
|
|
149
|
+
- New `defineBuiltinModule` function lets users add their own builtin modules
|
|
150
|
+
- When using `require` to load a module which contains an export named `__cjsExports`, the value of the `__cjsExports` property will be returned from `require` instead of the usual module namespace object. This can be leveraged by users configuring the module loader to add some CommonJS <-> ESM interop. Note, however, that dynamic import and `"quickjs:engine"`'s `importModule` always receive the usual module namespace object.
|
|
144
151
|
- Synchronous import function added (`importModule`), which provides the same module record object you would get via dynamic (async) import.
|
|
145
152
|
- JS api for using the engine's configured module name normalization function was added (`resolveModule`).
|
|
146
153
|
|
|
@@ -150,7 +157,7 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
|
|
|
150
157
|
- Ninja is used instead of make. Ninja build config is generated via `.ninja.js` files which get loaded into [@suchipi/shinobi](https://github.com/suchipi/shinobi).
|
|
151
158
|
- Line endings have been made consistent and trailing whitespace has been removed
|
|
152
159
|
- The tests are authored in a new format which leverages jest snapshot testing.
|
|
153
|
-
-
|
|
160
|
+
- Some parts of `quickjs-libc` were moved into `quickjs-modulesys` and `quickjs-libengine`.
|
|
154
161
|
- The `eval_*` functions that were duplicated in each of the programs (`eval_buf`, `eval_file`, and `eval_binary`) were deduplicated and moved into `quickjs-modulesys`.
|
|
155
162
|
|
|
156
163
|
### More target OSes/runtimes
|
|
@@ -185,7 +192,7 @@ QuickJS itself has no external dependencies outside this repo except pthreads, a
|
|
|
185
192
|
|
|
186
193
|
Linux, macOS, iOS, and Windows binaries can be compiled using Docker. Or, you can compile binaries for just your own unix system, without using Docker.
|
|
187
194
|
|
|
188
|
-
If you're not gonna use Docker, you'll need to install [Ninja](https://ninja-build.org/) and [Node.js](https://nodejs.org/) in order to compile. I use Ninja 1.10.1 and Node.js 18.
|
|
195
|
+
If you're not gonna use Docker, you'll need to install [Ninja](https://ninja-build.org/) and [Node.js](https://nodejs.org/) in order to compile. I use Ninja 1.10.1 and Node.js 18.18.0, but it should work with most versions of both of those.
|
|
189
196
|
|
|
190
197
|
### Compilation Instructions
|
|
191
198
|
|
|
@@ -198,7 +205,7 @@ To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
|
|
|
198
205
|
|
|
199
206
|
Or, to compile binaries for just your own unix system:
|
|
200
207
|
|
|
201
|
-
- Make sure you have both [Ninja](https://ninja-build.org/) and [Node.js](https://nodejs.org/) installed. I use Ninja 1.10.1 and Node.js 18.
|
|
208
|
+
- Make sure you have both [Ninja](https://ninja-build.org/) and [Node.js](https://nodejs.org/) installed. I use Ninja 1.10.1 and Node.js 18.18.0, but it should work with most versions of both of those.
|
|
202
209
|
- Clone the repo and cd to its folder
|
|
203
210
|
- Run `meta/build.sh`
|
|
204
211
|
- Build artifacts will be placed in the `build` folder. You're probably most interested in stuff in the `build/bin` and `build/lib` folders.
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -6,7 +6,11 @@ declare module "quickjs:bytecode" {
|
|
|
6
6
|
*/
|
|
7
7
|
export function fromFile(
|
|
8
8
|
path: string,
|
|
9
|
-
options?: {
|
|
9
|
+
options?: {
|
|
10
|
+
byteSwap?: boolean;
|
|
11
|
+
sourceType?: "module" | "script";
|
|
12
|
+
encodedFileName?: string;
|
|
13
|
+
}
|
|
10
14
|
): ArrayBuffer;
|
|
11
15
|
|
|
12
16
|
/**
|
|
@@ -271,9 +271,6 @@ declare module "quickjs:std" {
|
|
|
271
271
|
/** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
|
|
272
272
|
export var _IONBF: number;
|
|
273
273
|
|
|
274
|
-
/** Manually invoke the cycle removal algorithm (garbage collector). The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing. */
|
|
275
|
-
export function gc(): void;
|
|
276
|
-
|
|
277
274
|
/** Return the value of the environment variable `name` or `undefined` if it is not defined. */
|
|
278
275
|
export function getenv(name: string): string | undefined;
|
|
279
276
|
|
|
@@ -924,7 +921,7 @@ declare module "quickjs:os" {
|
|
|
924
921
|
export function dup2(oldfd: number, newfd: number): number;
|
|
925
922
|
|
|
926
923
|
/** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
|
|
927
|
-
export function pipe():
|
|
924
|
+
export function pipe(): [number, number];
|
|
928
925
|
|
|
929
926
|
/** Sleep for `delay_ms` milliseconds. */
|
|
930
927
|
export function sleep(delay_ms: number): void;
|
|
@@ -137,7 +137,7 @@ declare module "quickjs:context" {
|
|
|
137
137
|
console?: boolean;
|
|
138
138
|
/** Enables `print`. Defaults to `true`. */
|
|
139
139
|
print?: boolean;
|
|
140
|
-
/** Enables `require
|
|
140
|
+
/** Enables `require`. Defaults to `true`. */
|
|
141
141
|
moduleGlobals?: boolean;
|
|
142
142
|
/**
|
|
143
143
|
* Enables `setTimeout`, `clearTimeout`, `setInterval`, and
|
|
@@ -155,8 +155,8 @@ declare module "quickjs:context" {
|
|
|
155
155
|
"quickjs:bytecode"?: boolean;
|
|
156
156
|
/** Enables the "quickjs:context" module. Defaults to `true`. */
|
|
157
157
|
"quickjs:context"?: boolean;
|
|
158
|
-
/** Enables the "quickjs:
|
|
159
|
-
"quickjs:
|
|
158
|
+
/** Enables the "quickjs:engine" module. Defaults to `true`. */
|
|
159
|
+
"quickjs:engine"?: boolean;
|
|
160
160
|
};
|
|
161
161
|
});
|
|
162
162
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module "quickjs:
|
|
1
|
+
declare module "quickjs:engine" {
|
|
2
2
|
/**
|
|
3
3
|
* Return whether the provided resolved module path is set as the main module.
|
|
4
4
|
*
|
|
@@ -70,12 +70,31 @@ declare module "quickjs:module" {
|
|
|
70
70
|
*/
|
|
71
71
|
export function getFileNameFromStack(stackLevels?: number): string;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Returns true if `target` is a module namespace object.
|
|
75
|
+
*/
|
|
76
|
+
export function isModuleNamespace(target: any): boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create a virtual built-in module whose exports consist of the own
|
|
80
|
+
* enumerable properties of `obj`.
|
|
81
|
+
*/
|
|
82
|
+
export function defineBuiltinModule(
|
|
83
|
+
name: string,
|
|
84
|
+
obj: { [key: string]: any }
|
|
85
|
+
): void;
|
|
86
|
+
|
|
73
87
|
/**
|
|
74
88
|
* An object which lets you configure the module loader (import/export/require).
|
|
75
|
-
* You can
|
|
89
|
+
* You can change these properties to add support for importing new filetypes.
|
|
90
|
+
*/
|
|
91
|
+
export const ModuleDelegate: ModuleDelegate;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Manually invoke the cycle removal algorithm (garbage collector).
|
|
76
95
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
96
|
+
* The cycle removal algorithm is automatically started when needed, so this
|
|
97
|
+
* function is useful in case of specific memory constraints or for testing.
|
|
79
98
|
*/
|
|
80
|
-
export
|
|
99
|
+
export function gc(): void;
|
|
81
100
|
}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An object which lets you configure the module loader (import/export/require).
|
|
3
|
-
* You can
|
|
4
|
-
*
|
|
5
|
-
* This object can also be used to identify whether an object is a module
|
|
6
|
-
* namespace record.
|
|
3
|
+
* You can change these properties to add support for importing new filetypes.
|
|
7
4
|
*/
|
|
8
|
-
interface
|
|
9
|
-
/**
|
|
10
|
-
* Returns true if `target` is a module namespace object.
|
|
11
|
-
*/
|
|
12
|
-
[Symbol.hasInstance](target: any): target is {
|
|
13
|
-
[key: string | number | symbol]: any;
|
|
14
|
-
};
|
|
15
|
-
|
|
5
|
+
interface ModuleDelegate {
|
|
16
6
|
/**
|
|
17
7
|
* A list of filetype extensions that may be omitted from an import specifier
|
|
18
8
|
* string.
|
|
@@ -51,7 +41,7 @@ interface Module {
|
|
|
51
41
|
* ```js
|
|
52
42
|
* import * as std from "std";
|
|
53
43
|
*
|
|
54
|
-
*
|
|
44
|
+
* ModuleDelegate.compilers[".txt"] = (filename, content) => {
|
|
55
45
|
* return `export default ${JSON.stringify(content)}`;
|
|
56
46
|
* }
|
|
57
47
|
* ```
|
|
@@ -71,19 +61,14 @@ interface Module {
|
|
|
71
61
|
[extensionWithDot: string]: (filename: string, content: string) => string;
|
|
72
62
|
};
|
|
73
63
|
|
|
74
|
-
/**
|
|
75
|
-
* Create a virtual built-in module whose exports consist of the own
|
|
76
|
-
* enumerable properties of `obj`.
|
|
77
|
-
*/
|
|
78
|
-
define(name: string, obj: { [key: string]: any }): void;
|
|
79
|
-
|
|
80
64
|
/**
|
|
81
65
|
* Resolves a require/import request from `fromFile` into a canonicalized
|
|
82
66
|
* path.
|
|
83
67
|
*
|
|
84
68
|
* To change native module resolution behavior, replace this function with
|
|
85
69
|
* your own implementation. Note that you must handle
|
|
86
|
-
* `
|
|
70
|
+
* `ModuleDelegate.searchExtensions` yourself in your replacement
|
|
71
|
+
* implementation.
|
|
87
72
|
*/
|
|
88
73
|
resolve(name: string, fromFile: string): string;
|
|
89
74
|
|
|
@@ -91,8 +76,8 @@ interface Module {
|
|
|
91
76
|
* Reads the contents of the given resolved module name into a string.
|
|
92
77
|
*
|
|
93
78
|
* To change native module loading behavior, replace this function with your
|
|
94
|
-
* own implementation. Note that you must handle `
|
|
95
|
-
* in your replacement implementation.
|
|
79
|
+
* own implementation. Note that you must handle `ModuleDelegate.compilers`
|
|
80
|
+
* yourself in your replacement implementation.
|
|
96
81
|
*/
|
|
97
82
|
read(modulePath: string): string;
|
|
98
83
|
}
|
|
@@ -105,8 +90,8 @@ interface RequireFunction {
|
|
|
105
90
|
*
|
|
106
91
|
* If `source` does not have a file extension, and a file without an extension
|
|
107
92
|
* cannot be found, the engine will check for files with the extensions in
|
|
108
|
-
* {@link
|
|
109
|
-
* behavior also happens when using normal `import` statements.
|
|
93
|
+
* {@link ModuleDelegate.searchExtensions}, and use one of those if present.
|
|
94
|
+
* This behavior also happens when using normal `import` statements.
|
|
110
95
|
*
|
|
111
96
|
* For example, if you write:
|
|
112
97
|
*
|
|
@@ -115,8 +100,8 @@ interface RequireFunction {
|
|
|
115
100
|
* ```
|
|
116
101
|
*
|
|
117
102
|
* but there's no file named `somewhere` in the same directory as the file
|
|
118
|
-
* where that import appears, and `
|
|
119
|
-
* value:
|
|
103
|
+
* where that import appears, and `ModuleDelegate.searchExtensions` is the
|
|
104
|
+
* default value:
|
|
120
105
|
*
|
|
121
106
|
* ```js
|
|
122
107
|
* [".js"]
|
|
@@ -126,9 +111,9 @@ interface RequireFunction {
|
|
|
126
111
|
* engine will look for `somewhere/index.js`. If *that* doesn't exist, an
|
|
127
112
|
* error will be thrown.
|
|
128
113
|
*
|
|
129
|
-
* If you add more extensions to `
|
|
130
|
-
* will use those, too. It will search in the same order as the strings
|
|
131
|
-
* in the `
|
|
114
|
+
* If you add more extensions to `ModuleDelegate.searchExtensions`, then the
|
|
115
|
+
* engine will use those, too. It will search in the same order as the strings
|
|
116
|
+
* appear in the `ModuleDelegate.searchExtensions` array.
|
|
132
117
|
*/
|
|
133
118
|
(source: string): any;
|
|
134
119
|
|
|
@@ -168,11 +153,12 @@ interface ImportMeta {
|
|
|
168
153
|
*
|
|
169
154
|
* Equivalent to `globalThis.require.resolve`.
|
|
170
155
|
*
|
|
171
|
-
* Behaves similarly to [the browser
|
|
156
|
+
* Behaves similarly to [the browser
|
|
157
|
+
* import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
|
|
172
158
|
* but it does not ensure that the returned string is a valid URL, because it
|
|
173
|
-
* delegates directly to {@link
|
|
174
|
-
* want this to return URL strings, change `
|
|
175
|
-
* to work with URL strings.
|
|
159
|
+
* delegates directly to {@link ModuleDelegate.resolve} to resolve the name.
|
|
160
|
+
* If you want this to return URL strings, change `ModuleDelegate.resolve` and
|
|
161
|
+
* `ModuleDelegate.read` to work with URL strings.
|
|
176
162
|
*/
|
|
177
163
|
resolve: RequireFunction["resolve"];
|
|
178
164
|
}
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -11,7 +11,8 @@ import * as std from "quickjs:std";
|
|
|
11
11
|
import * as Bytecode from "quickjs:bytecode";
|
|
12
12
|
|
|
13
13
|
function main() {
|
|
14
|
-
|
|
14
|
+
let [_quickjsRun, _thisScript, inputFile, outputFile, encodedFileName] =
|
|
15
|
+
scriptArgs;
|
|
15
16
|
|
|
16
17
|
if (!(inputFile && outputFile)) {
|
|
17
18
|
throw new Error(
|
|
@@ -19,7 +20,11 @@ function main() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
if (!encodedFileName) {
|
|
24
|
+
encodedFileName = inputFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const bytecode = Bytecode.fromFile(inputFile, { encodedFileName });
|
|
23
28
|
const out = std.open(outputFile, "wb");
|
|
24
29
|
out.write(bytecode, 0, bytecode.byteLength);
|
|
25
30
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suchipi/quickjs",
|
|
3
3
|
"description": "Suchipi's QuickJS Fork",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"main": "./npm/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"qjs": "npm/cli/qjs.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@babel/preset-env": "^7.20.2",
|
|
14
14
|
"@babel/preset-typescript": "^7.18.6",
|
|
15
15
|
"@suchipi/print": "^2.5.0",
|
|
16
|
-
"@suchipi/shinobi": "^0.
|
|
16
|
+
"@suchipi/shinobi": "^1.0.0",
|
|
17
17
|
"@types/jest": "^29.2.4",
|
|
18
18
|
"@types/node": "^18.11.9",
|
|
19
19
|
"@types/shelljs": "^0.8.11",
|