@suchipi/quickjs 0.6.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.
Files changed (136) hide show
  1. package/README.md +22 -19
  2. package/build/aarch64-apple-darwin/bin/file-to-bytecode.js +7 -2
  3. package/build/aarch64-apple-darwin/bin/qjs +0 -0
  4. package/build/aarch64-apple-darwin/bin/qjsbootstrap +0 -0
  5. package/build/aarch64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  6. package/build/aarch64-apple-darwin/bin/qjsc +0 -0
  7. package/build/aarch64-apple-darwin/bin/quickjs-run +0 -0
  8. package/build/aarch64-apple-darwin/extras/fib.so +0 -0
  9. package/build/aarch64-apple-darwin/extras/is-stdin-a-tty +0 -0
  10. package/build/aarch64-apple-darwin/extras/log-argv +0 -0
  11. package/build/aarch64-apple-darwin/extras/point.so +0 -0
  12. package/build/aarch64-apple-darwin/extras/run-test262 +0 -0
  13. package/build/aarch64-apple-darwin/extras/sample-program/sum +0 -0
  14. package/build/aarch64-apple-darwin/extras/stack-limit-test +0 -0
  15. package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
  16. package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
  17. package/build/aarch64-unknown-linux-gnu/bin/file-to-bytecode.js +7 -2
  18. package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
  19. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  20. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  21. package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
  22. package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
  23. package/build/aarch64-unknown-linux-gnu/extras/fib.so +0 -0
  24. package/build/aarch64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  25. package/build/aarch64-unknown-linux-gnu/extras/log-argv +0 -0
  26. package/build/aarch64-unknown-linux-gnu/extras/point.so +0 -0
  27. package/build/aarch64-unknown-linux-gnu/extras/run-test262 +0 -0
  28. package/build/aarch64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  29. package/build/aarch64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  30. package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  31. package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  32. package/build/aarch64-unknown-linux-musl/bin/file-to-bytecode.js +7 -2
  33. package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
  34. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  35. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  36. package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
  37. package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
  38. package/build/aarch64-unknown-linux-musl/extras/fib.so +0 -0
  39. package/build/aarch64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  40. package/build/aarch64-unknown-linux-musl/extras/point.so +0 -0
  41. package/build/aarch64-unknown-linux-musl/extras/run-test262 +0 -0
  42. package/build/aarch64-unknown-linux-musl/extras/sample-program/sum +0 -0
  43. package/build/aarch64-unknown-linux-musl/extras/stack-limit-test +0 -0
  44. package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  45. package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  46. package/build/aarch64-unknown-linux-static/bin/file-to-bytecode.js +7 -2
  47. package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
  48. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
  49. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  50. package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
  51. package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
  52. package/build/aarch64-unknown-linux-static/extras/fib.so +0 -0
  53. package/build/aarch64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  54. package/build/aarch64-unknown-linux-static/extras/point.so +0 -0
  55. package/build/aarch64-unknown-linux-static/extras/run-test262 +0 -0
  56. package/build/aarch64-unknown-linux-static/extras/sample-program/sum +0 -0
  57. package/build/aarch64-unknown-linux-static/extras/stack-limit-test +0 -0
  58. package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
  59. package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
  60. package/build/dts/quickjs-libbytecode.d.ts +5 -1
  61. package/build/dts/quickjs-libc.d.ts +1 -4
  62. package/build/dts/quickjs-libcontext.d.ts +3 -3
  63. package/build/dts/{quickjs-libmodule.d.ts → quickjs-libengine.d.ts} +24 -5
  64. package/build/dts/quickjs-modulesys.d.ts +19 -33
  65. package/build/x86_64-apple-darwin/bin/file-to-bytecode.js +7 -2
  66. package/build/x86_64-apple-darwin/bin/qjs +0 -0
  67. package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
  68. package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  69. package/build/x86_64-apple-darwin/bin/qjsc +0 -0
  70. package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
  71. package/build/x86_64-apple-darwin/extras/fib.so +0 -0
  72. package/build/x86_64-apple-darwin/extras/is-stdin-a-tty +0 -0
  73. package/build/x86_64-apple-darwin/extras/log-argv +0 -0
  74. package/build/x86_64-apple-darwin/extras/point.so +0 -0
  75. package/build/x86_64-apple-darwin/extras/run-test262 +0 -0
  76. package/build/x86_64-apple-darwin/extras/sample-program/sum +0 -0
  77. package/build/x86_64-apple-darwin/extras/stack-limit-test +0 -0
  78. package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
  79. package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
  80. package/build/x86_64-pc-windows-static/bin/file-to-bytecode.js +7 -2
  81. package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
  82. package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
  83. package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
  84. package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
  85. package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
  86. package/build/x86_64-pc-windows-static/extras/is-stdin-a-tty.exe +0 -0
  87. package/build/x86_64-pc-windows-static/extras/log-argv.exe +0 -0
  88. package/build/x86_64-pc-windows-static/extras/run-test262.exe +0 -0
  89. package/build/x86_64-pc-windows-static/extras/sample-program/sum.exe +0 -0
  90. package/build/x86_64-pc-windows-static/extras/stack-limit-test.exe +0 -0
  91. package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
  92. package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
  93. package/build/x86_64-unknown-linux-gnu/bin/file-to-bytecode.js +7 -2
  94. package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
  95. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  96. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  97. package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
  98. package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
  99. package/build/x86_64-unknown-linux-gnu/extras/fib.so +0 -0
  100. package/build/x86_64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  101. package/build/x86_64-unknown-linux-gnu/extras/log-argv +0 -0
  102. package/build/x86_64-unknown-linux-gnu/extras/point.so +0 -0
  103. package/build/x86_64-unknown-linux-gnu/extras/run-test262 +0 -0
  104. package/build/x86_64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  105. package/build/x86_64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  106. package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  107. package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  108. package/build/x86_64-unknown-linux-musl/bin/file-to-bytecode.js +7 -2
  109. package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
  110. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  111. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  112. package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
  113. package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
  114. package/build/x86_64-unknown-linux-musl/extras/fib.so +0 -0
  115. package/build/x86_64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  116. package/build/x86_64-unknown-linux-musl/extras/point.so +0 -0
  117. package/build/x86_64-unknown-linux-musl/extras/run-test262 +0 -0
  118. package/build/x86_64-unknown-linux-musl/extras/sample-program/sum +0 -0
  119. package/build/x86_64-unknown-linux-musl/extras/stack-limit-test +0 -0
  120. package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  121. package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  122. package/build/x86_64-unknown-linux-static/bin/file-to-bytecode.js +7 -2
  123. package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
  124. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
  125. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  126. package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
  127. package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
  128. package/build/x86_64-unknown-linux-static/extras/fib.so +0 -0
  129. package/build/x86_64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  130. package/build/x86_64-unknown-linux-static/extras/point.so +0 -0
  131. package/build/x86_64-unknown-linux-static/extras/run-test262 +0 -0
  132. package/build/x86_64-unknown-linux-static/extras/sample-program/sum +0 -0
  133. package/build/x86_64-unknown-linux-static/extras/stack-limit-test +0 -0
  134. package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
  135. package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
  136. 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
 
@@ -113,6 +114,10 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
113
114
  - Helper function for loading a file from disk into char a buffer
114
115
  - Helper functions for printing JS errors to stderr
115
116
 
117
+ ### New module: "quickjs:engine"
118
+
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
+
116
121
  ### Changes to the module loader
117
122
 
118
123
  - `.js` extensions can now be omitted from import specifiers; they're optional.
@@ -123,24 +128,22 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
123
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`.
124
129
  - Adds `import.meta.resolve`
125
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`.
126
- - Module and eval helpers have been moved from "quickjs:std" to the new module "quickjs:module".
127
- - Makes the module loader's resolution and loading behavior configurable, and allows users to define additional builtin modules
128
- - The module "quickjs:module" exports an object called `Module`.
129
- - You can specify additional implicit import specifier extensions by adding to the `Module.searchExtensions` array.
130
- - You can transform any file prior to evaluating it as a module by adding a function to the `Module.compilers` object. Useful for compile-to-ts languages like TypeScript, Coffeescript, etc.
131
- - You can define custom builtin modules using the `Module.define` function.
132
- - You can override module name normalization (aka module resolution) by replacing the `Module.resolve` function.
133
- - Note that you must handle `Module.searchExtensions` yourself in your replacement implementation.
134
- - You can override the method used to load modules by replacing the `Module.read` function.
135
- - Note that you must handle `Module.compilers` yourself in your replacement implementation.
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.
136
140
  - Makes `import.meta.main` configurable
137
- - The module "quickjs:module" exports two functions named `setMainModule` and `isMainModule`.
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:module", or `require`.
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`.
139
143
  - You can use `isMainModule` to check if a given module would be the main module without loading it.
140
- - Adds a mechanism for identifying module namespace objects
141
- - The module "quickjs:module" exports an object called `Module`.
142
- - `something instanceof Module` will be true when `something` is a module namespace object.
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.
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.
144
147
  - Synchronous import function added (`importModule`), which provides the same module record object you would get via dynamic (async) import.
145
148
  - JS api for using the engine's configured module name normalization function was added (`resolveModule`).
146
149
 
@@ -150,7 +153,7 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
150
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).
151
154
  - Line endings have been made consistent and trailing whitespace has been removed
152
155
  - The tests are authored in a new format which leverages jest snapshot testing.
153
- - Module-loading code in `quickjs-libc` was moved into `quickjs-modulesys` and `quickjs-libmodule`.
156
+ - Some parts of `quickjs-libc` were moved into `quickjs-modulesys` and `quickjs-libengine`.
154
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`.
155
158
 
156
159
  ### More target OSes/runtimes
@@ -185,7 +188,7 @@ QuickJS itself has no external dependencies outside this repo except pthreads, a
185
188
 
186
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.
187
190
 
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.12.1, but it should work with most versions of both of those.
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.
189
192
 
190
193
  ### Compilation Instructions
191
194
 
@@ -198,7 +201,7 @@ To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
198
201
 
199
202
  Or, to compile binaries for just your own unix system:
200
203
 
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.12.1, but it should work with most versions of both of those.
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.
202
205
  - Clone the repo and cd to its folder
203
206
  - Run `meta/build.sh`
204
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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -6,7 +6,11 @@ declare module "quickjs:bytecode" {
6
6
  */
7
7
  export function fromFile(
8
8
  path: string,
9
- options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
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(): null | [number, number];
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` and `Module`. Defaults to `true`. */
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:module" module. Defaults to `true`. */
159
- "quickjs:module"?: boolean;
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:module" {
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 use these properties to add support for importing new filetypes.
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
- * This object can also be used to identify whether an object is a module
78
- * namespace record.
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 const Module: Module;
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 use these properties to add support for importing new filetypes.
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 Module {
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
- * Module.compilers[".txt"] = (filename, content) => {
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
- * `Module.searchExtensions` yourself in your replacement implementation.
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 `Module.compilers` yourself
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 Module.searchExtensions}, and use one of those if present. This
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 `Module.searchExtensions` is the default
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 `Module.searchExtensions`, then the engine
130
- * will use those, too. It will search in the same order as the strings appear
131
- * in the `Module.searchExtensions` array.
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 import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
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 Module.resolve} to resolve the name. If you
174
- * want this to return URL strings, change `Module.resolve` and `Module.read`
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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
@@ -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
- const [_quickjsRun, _thisScript, inputFile, outputFile] = scriptArgs;
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
- const bytecode = Bytecode.fromFile(inputFile);
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
  }
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.6.0",
4
+ "version": "0.7.0",
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.2.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",