@suchipi/quickjs 0.5.0 → 0.7.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 +67 -43
- 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 +15 -4
- package/build/dts/quickjs-libcontext.d.ts +3 -3
- package/build/dts/{quickjs-libmodule.d.ts → quickjs-libengine.d.ts} +29 -1
- package/build/dts/quickjs-modulesys.d.ts +27 -43
- 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/.gitmodules +0 -6
package/README.md
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# suchipi/quickjs
|
|
2
2
|
|
|
3
|
-
Fork of the fantastic QuickJS engine by Fabrice Bellard, with
|
|
3
|
+
Fork of the fantastic QuickJS engine by Fabrice Bellard, with many changes.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## High-level List of Most Notable Changes
|
|
6
|
+
|
|
7
|
+
- APIs from 'std' and 'os' modules were changed to be more idiomatic-to-JS; notably, they throw Errors on failure instead of returning null or errno numbers.
|
|
8
|
+
- TypeScript-format type interface files (`.d.ts` files) were added for everything.
|
|
9
|
+
- Hooks have been added to the module loader that make its functionality more customizable.
|
|
10
|
+
- Some ES2022 features were added, and some non-standard ECMAScript proposals and extensions were added.
|
|
11
|
+
- The way the project is organized and built was changed dramatically.
|
|
12
|
+
- Several new JS bindings for C APIs have been added, such as `strftime`, `access`, `fsync`, `setvbuf`, `getuid`...
|
|
13
|
+
- Scripts were added that cross-compile binaries for several operating systems and architectures
|
|
14
|
+
- FreeBSD support added
|
|
15
|
+
|
|
16
|
+
## Detailed List of Changes
|
|
17
|
+
|
|
18
|
+
### Changes to `quickjs`:
|
|
6
19
|
|
|
7
20
|
- A TypeScript `.d.ts` file is provided for all QuickJS-specific APIs (operator overloading APIs, BigInt extensions, BigFloat, BigDecimal, etc).
|
|
8
21
|
- Non-standard `Object.toPrimitive` added (static method that invokes ToPrimitive on the given value, using the optionally-provided hint).
|
|
@@ -23,8 +36,9 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
|
|
|
23
36
|
- `JS_FreezeObjectValue` (performs Object.freeze)
|
|
24
37
|
- `JS_IsPrimitive`
|
|
25
38
|
- ModuleDefs now have an optional "user_data" property (pointer to void) which can be accessed during module initialization (via `JS_GetModuleUserData` and `JS_SetModuleUserData`)
|
|
39
|
+
- Added `JS_SetContextOpaqueValue` and `JS_GetContextOpaqueValue`, which let you associate a JSValue with a JSContext, which will be garbage-collected when that JSContext is garbage-collected.
|
|
26
40
|
|
|
27
|
-
|
|
41
|
+
### Changes to `quickjs-libc`:
|
|
28
42
|
|
|
29
43
|
- `std` and `os` builtin modules are now namespaced under "quickjs:". In other words, you have to import them as "quickjs:std" and "quickjs:os".
|
|
30
44
|
- APIs in `std` and `os` no longer return errno anywhere; instead, Error objects are thrown. `errno` is available as a property on the thrown Error objects.
|
|
@@ -35,6 +49,7 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
|
|
|
35
49
|
- `os.access` function added (wrapper for libc `access`).
|
|
36
50
|
- `FILE.prototype.sync` method added (wrapper for `fsync`).
|
|
37
51
|
- `FILE.prototype.setvbuf` method added (wrapper for `setvbuf`).
|
|
52
|
+
- `FILE.prototype.writeTo` method added (pipe data from one FILE to another, given a buffer size and limit).
|
|
38
53
|
- `std.isFILE` function added (returns whether the provided object is a `FILE` (via `js_std_file_class_id`)).
|
|
39
54
|
- `os.{WUNTRACED,WEXITSTATUS,WTERMSIG,WSTOPSIG,WIFEXITED,WIFSIGNALED,WIFSTOPPED,WIFCONTINUED}` added, for working with `os.waitpid`.
|
|
40
55
|
- `os.{S_IRWXU,S_IRUSR,S_IWUSR,S_IXUSR,S_IRWXG,S_IRGRP,S_IWGRP,S_IXGRP,S_IRWXO,S_IROTH,S_IWOTH,S_IXOTH}` added, for working with file modes.
|
|
@@ -42,24 +57,25 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
|
|
|
42
57
|
- `std.strftime` added (wrapper for libc `strftime`).
|
|
43
58
|
- Added `std.getuid`, `std.geteuid`, `std.getgid`, and `std.getegid` (wrappers for the libc functions of the same names).
|
|
44
59
|
- Most module-loading-related code was moved into `quickjs-modulesys`.
|
|
45
|
-
- Synchronous import function added (`std.importModule`), which provides the same module record object you would get via dynamic (async) import.
|
|
46
|
-
- JS api for using the engine's configured module name normalization function was added (`std.resolveModule`).
|
|
47
60
|
- `setTimeout` and `clearTimeout` are now available as globals (previously they were only available as exports).
|
|
48
61
|
- `setInterval` and `clearInterval` are added, available as globals.
|
|
49
62
|
- `String.dedent` added (template tag function, like the proposed [String.dedent](https://github.com/tc39/proposal-string-dedent)).
|
|
50
63
|
- Several C-side helper functions were moved out of quickjs-libc and into quickjs-utils.
|
|
51
64
|
- Most module-related code (setting import.meta, etc) was moved into quickjs-modulesys.
|
|
52
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"`.
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
### Changes to the `qjs` binary:
|
|
55
69
|
|
|
56
|
-
- The new `inspect` global is used to print results
|
|
57
|
-
- The last error is accessible via the `_error` global
|
|
58
|
-
- If a thrown error has additional properties added onto it, those are printed along with the thrown error
|
|
59
|
-
- Ctrl+W deletes words backwards from the cursor position
|
|
60
70
|
- Blocking the main thread is allowed
|
|
71
|
+
- `-m` (module mode) now affects eval strings passed to `-e`
|
|
72
|
+
- Changes to the repl:
|
|
73
|
+
- Ctrl+W deletes words backwards from the cursor position
|
|
74
|
+
- The last error is accessible via the `_error` global
|
|
75
|
+
- If a thrown error has additional properties added onto it, those are printed along with the thrown error
|
|
76
|
+
- The new `inspect` global is used to print results
|
|
61
77
|
|
|
62
|
-
|
|
78
|
+
### New binary: `qjsbootstrap`:
|
|
63
79
|
|
|
64
80
|
Appending some JS code to the end of this binary changes it into a binary that executes that JS code:
|
|
65
81
|
|
|
@@ -74,23 +90,23 @@ You can use this to create distributable binaries that run JS code without needi
|
|
|
74
90
|
|
|
75
91
|
> Note: On FreeBSD, `qjsbootstrap` requires procfs. You can mount it with `mount -t procfs proc /proc`. I started some work to use libprocstat instead, but haven't completed it yet.
|
|
76
92
|
|
|
77
|
-
|
|
93
|
+
### New binary: `quickjs-run`:
|
|
78
94
|
|
|
79
95
|
Barebones binary for running files, without any of the arg parsing logic from qjs. Good for testing some unusual cases, or writing programs with custom argv parsing logic.
|
|
80
96
|
|
|
81
|
-
|
|
97
|
+
### New module: "quickjs:bytecode"
|
|
82
98
|
|
|
83
99
|
A Module that exposes QuickJS's value <-> bytecode (de)serialization APIs to JavaScript code. Generated bytecode can be combined with `qjsbootstrap-bytecode` in the same way that source code strings can be combined with `qjsbootstrap`.
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
### New module: "quickjs:context"
|
|
86
102
|
|
|
87
103
|
A Module that allows JS code to create new JS Contexts (Realms). You can create new Contexts and run code inside them. Contexts can have certain features disabled (like eval) for security purposes. You can share values between Contexts. Contexts are destroyed when they get garbage-collected.
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
### New module: "quickjs:pointer"
|
|
90
106
|
|
|
91
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.
|
|
92
108
|
|
|
93
|
-
|
|
109
|
+
### New library: `quickjs-utils`
|
|
94
110
|
|
|
95
111
|
Helper structs, functions, and macros that make it easier to work with QuickJS in C code.
|
|
96
112
|
|
|
@@ -98,55 +114,63 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
|
|
|
98
114
|
- Helper function for loading a file from disk into char a buffer
|
|
99
115
|
- Helper functions for printing JS errors to stderr
|
|
100
116
|
|
|
101
|
-
|
|
117
|
+
### New module: "quickjs:engine"
|
|
102
118
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
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.
|
|
120
|
+
|
|
121
|
+
### Changes to the module loader
|
|
122
|
+
|
|
123
|
+
- `.js` extensions can now be omitted from import specifiers; they're optional.
|
|
124
|
+
- If your import specifier points to a folder, it will attempt to load `index.js` from that folder.
|
|
106
125
|
- Adds the global `require`, a CommonJS-like synchronous module loading function.
|
|
107
126
|
- The `require` function is not fully CommonJS-compliant; for instance, `require.main` is not present. `require.resolve` is, though.
|
|
108
127
|
- Adds `import.meta.require`
|
|
109
128
|
- 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`.
|
|
110
129
|
- Adds `import.meta.resolve`
|
|
111
130
|
- 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`.
|
|
131
|
+
- Module and eval helpers have been moved from "quickjs:std" to the new module "quickjs:engine".
|
|
132
|
+
- Makes the module loader's resolution and loading behavior configurable
|
|
133
|
+
- The module "quickjs:engine" exports an object called `ModuleDelegate`.
|
|
134
|
+
- You can specify additional implicit import specifier extensions by adding to the `ModuleDelegate.searchExtensions` array.
|
|
135
|
+
- 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.
|
|
136
|
+
- You can override module name normalization (aka module resolution) by replacing the `ModuleDelegate.resolve` function.
|
|
137
|
+
- Note that you must handle `ModuleDelegate.searchExtensions` yourself in your replacement implementation.
|
|
138
|
+
- You can override the method used to load modules by replacing the `ModuleDelegate.read` function.
|
|
139
|
+
- Note that you must handle `ModuleDelegate.compilers` yourself in your replacement implementation.
|
|
112
140
|
- Makes `import.meta.main` configurable
|
|
113
|
-
-
|
|
114
|
-
- You can use `
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
- Note that you must handle `Module.compilers` yourself in your replacement implementation.
|
|
124
|
-
- The `eval_*` functions that were duplicated in each of the programs (`eval_buf`, `eval_file`, and `eval_binary`) were moved here
|
|
125
|
-
- The default module loader function from quickjs-libc was moved here and augmented to support the features related to the `Module` global as mentioned above
|
|
126
|
-
- 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 user-defined properties on `Module` to add some CommonJS <-> ESM interop. Note, however, that dynamic import and `std.importModule` always receive the usual module namespace object.
|
|
127
|
-
|
|
128
|
-
## Changes to project organization
|
|
141
|
+
- The module "quickjs:engine" exports two functions named `setMainModule` and `isMainModule`.
|
|
142
|
+
- 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`.
|
|
143
|
+
- You can use `isMainModule` to check if a given module would be the main module without loading it.
|
|
144
|
+
- New `isModuleNamespace` function lets users identify module namespace objects
|
|
145
|
+
- New `defineBuiltinModule` function lets users add their own builtin modules
|
|
146
|
+
- 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.
|
|
147
|
+
- Synchronous import function added (`importModule`), which provides the same module record object you would get via dynamic (async) import.
|
|
148
|
+
- JS api for using the engine's configured module name normalization function was added (`resolveModule`).
|
|
149
|
+
|
|
150
|
+
### Changes to project organization
|
|
129
151
|
|
|
130
152
|
- Stuff is reorganized into separate folders under `src`.
|
|
131
153
|
- 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).
|
|
132
154
|
- Line endings have been made consistent and trailing whitespace has been removed
|
|
133
155
|
- The tests are authored in a new format which leverages jest snapshot testing.
|
|
156
|
+
- Some parts of `quickjs-libc` were moved into `quickjs-modulesys` and `quickjs-libengine`.
|
|
157
|
+
- 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`.
|
|
134
158
|
|
|
135
|
-
|
|
159
|
+
### More target OSes/runtimes
|
|
136
160
|
|
|
137
161
|
We now include support for more platforms, and cross-compilation scripts to build most of those platforms from any platform where Docker is available.
|
|
138
162
|
|
|
139
163
|
See the `meta/ninja/envs` folder to see all the supported platforms. The `host` folder represents the machine where compilation is taking place, and the `target` folder represents the target platform for the output binaries.
|
|
140
164
|
|
|
141
|
-
|
|
165
|
+
### Library Archives
|
|
142
166
|
|
|
143
167
|
We create `.a` files containing all of quickjs as part of the build.
|
|
144
168
|
|
|
145
|
-
|
|
169
|
+
### Other changes
|
|
146
170
|
|
|
147
171
|
There are also probably some other miscellaneous changes I forgot to write down in the README.
|
|
148
172
|
|
|
149
|
-
|
|
173
|
+
## Compiling
|
|
150
174
|
|
|
151
175
|
The repo has stuff set up to compile quickjs binaries for:
|
|
152
176
|
|
|
@@ -164,9 +188,9 @@ QuickJS itself has no external dependencies outside this repo except pthreads, a
|
|
|
164
188
|
|
|
165
189
|
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.
|
|
166
190
|
|
|
167
|
-
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.
|
|
191
|
+
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.
|
|
168
192
|
|
|
169
|
-
|
|
193
|
+
### Compilation Instructions
|
|
170
194
|
|
|
171
195
|
To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
|
|
172
196
|
|
|
@@ -177,7 +201,7 @@ To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
|
|
|
177
201
|
|
|
178
202
|
Or, to compile binaries for just your own unix system:
|
|
179
203
|
|
|
180
|
-
- 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.
|
|
204
|
+
- 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.
|
|
181
205
|
- Clone the repo and cd to its folder
|
|
182
206
|
- Run `meta/build.sh`
|
|
183
207
|
- 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
|
/**
|
|
@@ -98,6 +98,20 @@ declare interface FILE {
|
|
|
98
98
|
/** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
|
|
99
99
|
write(buffer: ArrayBuffer, position: number, length: number): number;
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Write this file into `target`, using a memory buffer of size `bufferSize`.
|
|
103
|
+
*
|
|
104
|
+
* If `limit` is specified, only that amount of bytes will be read and
|
|
105
|
+
* written. Otherwise, data is read and written until this file reaches EOF.
|
|
106
|
+
*
|
|
107
|
+
* A `limit` of 0 is treated the same as not specifying a limit.
|
|
108
|
+
*
|
|
109
|
+
* Internally, this function uses libc `fread` and `fwrite` in a loop.
|
|
110
|
+
*
|
|
111
|
+
* Returns the number of bytes read and written.
|
|
112
|
+
*/
|
|
113
|
+
writeTo(target: FILE, bufferSize: number, limit?: number): number;
|
|
114
|
+
|
|
101
115
|
/**
|
|
102
116
|
* Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
|
|
103
117
|
*
|
|
@@ -257,9 +271,6 @@ declare module "quickjs:std" {
|
|
|
257
271
|
/** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
|
|
258
272
|
export var _IONBF: number;
|
|
259
273
|
|
|
260
|
-
/** 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. */
|
|
261
|
-
export function gc(): void;
|
|
262
|
-
|
|
263
274
|
/** Return the value of the environment variable `name` or `undefined` if it is not defined. */
|
|
264
275
|
export function getenv(name: string): string | undefined;
|
|
265
276
|
|
|
@@ -910,7 +921,7 @@ declare module "quickjs:os" {
|
|
|
910
921
|
export function dup2(oldfd: number, newfd: number): number;
|
|
911
922
|
|
|
912
923
|
/** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
|
|
913
|
-
export function pipe():
|
|
924
|
+
export function pipe(): [number, number];
|
|
914
925
|
|
|
915
926
|
/** Sleep for `delay_ms` milliseconds. */
|
|
916
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
|
*
|
|
@@ -69,4 +69,32 @@ declare module "quickjs:module" {
|
|
|
69
69
|
* @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
|
|
70
70
|
*/
|
|
71
71
|
export function getFileNameFromStack(stackLevels?: number): string;
|
|
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
|
+
|
|
87
|
+
/**
|
|
88
|
+
* An object which lets you configure the module loader (import/export/require).
|
|
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).
|
|
95
|
+
*
|
|
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.
|
|
98
|
+
*/
|
|
99
|
+
export function gc(): void;
|
|
72
100
|
}
|