@suchipi/quickjs 0.4.2 → 0.5.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 (105) hide show
  1. package/README.md +4 -0
  2. package/build/aarch64-apple-darwin/bin/qjs +0 -0
  3. package/build/aarch64-apple-darwin/bin/qjsbootstrap +0 -0
  4. package/build/aarch64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  5. package/build/aarch64-apple-darwin/bin/qjsc +0 -0
  6. package/build/aarch64-apple-darwin/bin/quickjs-run +0 -0
  7. package/build/aarch64-apple-darwin/extras/is-stdin-a-tty +0 -0
  8. package/build/aarch64-apple-darwin/extras/run-test262 +0 -0
  9. package/build/aarch64-apple-darwin/extras/sample-program/sum +0 -0
  10. package/build/aarch64-apple-darwin/extras/stack-limit-test +0 -0
  11. package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
  12. package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
  13. package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
  14. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  15. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  16. package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
  17. package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
  18. package/build/aarch64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  19. package/build/aarch64-unknown-linux-gnu/extras/run-test262 +0 -0
  20. package/build/aarch64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  21. package/build/aarch64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  22. package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  23. package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  24. package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
  25. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  26. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  27. package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
  28. package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
  29. package/build/aarch64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  30. package/build/aarch64-unknown-linux-musl/extras/run-test262 +0 -0
  31. package/build/aarch64-unknown-linux-musl/extras/sample-program/sum +0 -0
  32. package/build/aarch64-unknown-linux-musl/extras/stack-limit-test +0 -0
  33. package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  34. package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  35. package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
  36. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
  37. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  38. package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
  39. package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
  40. package/build/aarch64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  41. package/build/aarch64-unknown-linux-static/extras/run-test262 +0 -0
  42. package/build/aarch64-unknown-linux-static/extras/sample-program/sum +0 -0
  43. package/build/aarch64-unknown-linux-static/extras/stack-limit-test +0 -0
  44. package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
  45. package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
  46. package/build/dts/quickjs-libc.d.ts +24 -45
  47. package/build/dts/quickjs-libcontext.d.ts +21 -22
  48. package/build/dts/quickjs-libmodule.d.ts +72 -0
  49. package/build/x86_64-apple-darwin/bin/qjs +0 -0
  50. package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
  51. package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  52. package/build/x86_64-apple-darwin/bin/qjsc +0 -0
  53. package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
  54. package/build/x86_64-apple-darwin/extras/is-stdin-a-tty +0 -0
  55. package/build/x86_64-apple-darwin/extras/run-test262 +0 -0
  56. package/build/x86_64-apple-darwin/extras/sample-program/sum +0 -0
  57. package/build/x86_64-apple-darwin/extras/stack-limit-test +0 -0
  58. package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
  59. package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
  60. package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
  61. package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
  62. package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
  63. package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
  64. package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
  65. package/build/x86_64-pc-windows-static/extras/is-stdin-a-tty.exe +0 -0
  66. package/build/x86_64-pc-windows-static/extras/log-argv.exe +0 -0
  67. package/build/x86_64-pc-windows-static/extras/run-test262.exe +0 -0
  68. package/build/x86_64-pc-windows-static/extras/sample-program/sum.exe +0 -0
  69. package/build/x86_64-pc-windows-static/extras/stack-limit-test.exe +0 -0
  70. package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
  71. package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
  72. package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
  73. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  74. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  75. package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
  76. package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
  77. package/build/x86_64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  78. package/build/x86_64-unknown-linux-gnu/extras/run-test262 +0 -0
  79. package/build/x86_64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  80. package/build/x86_64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  81. package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  82. package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  83. package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
  84. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  85. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  86. package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
  87. package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
  88. package/build/x86_64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  89. package/build/x86_64-unknown-linux-musl/extras/run-test262 +0 -0
  90. package/build/x86_64-unknown-linux-musl/extras/sample-program/sum +0 -0
  91. package/build/x86_64-unknown-linux-musl/extras/stack-limit-test +0 -0
  92. package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  93. package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  94. package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
  95. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
  96. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  97. package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
  98. package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
  99. package/build/x86_64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  100. package/build/x86_64-unknown-linux-static/extras/run-test262 +0 -0
  101. package/build/x86_64-unknown-linux-static/extras/sample-program/sum +0 -0
  102. package/build/x86_64-unknown-linux-static/extras/stack-limit-test +0 -0
  103. package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
  104. package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
  105. package/package.json +1 -1
package/README.md CHANGED
@@ -49,6 +49,7 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
49
49
  - `String.dedent` added (template tag function, like the proposed [String.dedent](https://github.com/tc39/proposal-string-dedent)).
50
50
  - Several C-side helper functions were moved out of quickjs-libc and into quickjs-utils.
51
51
  - Most module-related code (setting import.meta, etc) was moved into quickjs-modulesys.
52
+ - 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).
52
53
 
53
54
  ## Changes to the `qjs` repl:
54
55
 
@@ -108,6 +109,9 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
108
109
  - 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`.
109
110
  - Adds `import.meta.resolve`
110
111
  - 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`.
112
+ - Makes `import.meta.main` configurable
113
+ - You can use `std.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()`, `std.importModule`, or `require`.
114
+ - You can use `std.isMainModule` to check if a given module would be the main module without loading it.
111
115
  - Adds the global object `Module`.
112
116
  - `instanceof Module` can be used to identify module namespace objects.
113
117
  - You can specify additional implicit import specifier extensions by adding to the `Module.searchExtensions` array.
Binary file
Binary file
@@ -129,54 +129,42 @@ declare interface FILE {
129
129
 
130
130
  declare module "quickjs:std" {
131
131
  /**
132
- * Exit the process with the provided status code.
132
+ * Set the exit code that the process should exit with in the future, if it
133
+ * exits normally.
133
134
  *
134
- * @param statusCode The exit code; 0 for success, nonzero for failure.
135
- */
136
- export function exit(statusCode: number): void;
137
-
138
- /**
139
- * Evaluate the string `code` as a script (global eval).
135
+ * Can only be called from the main thread.
140
136
  *
141
- * @param code - The code to evaluate.
142
- * @param options - An optional object containing the following optional properties:
143
- * @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
144
- * @property filename - String (default = "<evalScript>"). The filename to associate with the code being executed.
145
- * @returns The result of the evaluation.
146
- */
147
- export function evalScript(
148
- code: string,
149
- options?: { backtraceBarrier?: boolean; filename?: string }
150
- ): any;
151
-
152
- /**
153
- * Evaluate the file `filename` as a script (global eval).
137
+ * This exit code will only be used if the process exits "normally", ie, when
138
+ * there are no more pending JS tasks/listeners. If an unhandled exception is
139
+ * thrown, the process will always exit with status `1`, regardless of the
140
+ * status code passed to `setExitCode`. If someone calls {@link exit} and
141
+ * passes in a status code, that status code will take precedence over the
142
+ * status code passed to `setExitCode`.
154
143
  *
155
- * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
156
- * @returns The result of the evaluation.
144
+ * @param statusCode The future exit code; 0 for success, nonzero for failure.
157
145
  */
158
- export function loadScript(filename: string): any;
146
+ export function setExitCode(statusCode: number): void;
159
147
 
160
148
  /**
161
- * Evaluate the file `filename` as a module. Effectively a synchronous dynamic `import()`.
149
+ * Return the exit code that was previously set by {@link setExitCode}, or 0 if
150
+ * it hasn't yet been set.
162
151
  *
163
- * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
164
- * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
165
- * @returns The result of the evaluation (module namespace object).
152
+ * Can only be called from the main thread.
166
153
  */
167
- export function importModule(
168
- filename: string,
169
- basename?: string
170
- ): { [key: string]: any };
154
+ export function getExitCode(): number;
171
155
 
172
156
  /**
173
- * Return the resolved path to a module.
157
+ * Exit the process with the provided status code.
158
+ *
159
+ * Can only be called from the main thread.
160
+ *
161
+ * If `statusCode` is not provided, a value previously passed into
162
+ * {@link setExitCode} will be used. If no value was previously passed into
163
+ * setExitCode, `0` will be used.
174
164
  *
175
- * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
176
- * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
177
- * @returns The resolved module path.
165
+ * @param statusCode The exit code; 0 for success, nonzero for failure.
178
166
  */
179
- export function resolveModule(filename: string, basename?: string): string;
167
+ export function exit(statusCode?: number): never;
180
168
 
181
169
  /**
182
170
  * Load the file `filename` and return it as a string assuming UTF-8 encoding.
@@ -185,15 +173,6 @@ declare module "quickjs:std" {
185
173
  */
186
174
  export function loadFile(filename: string): string;
187
175
 
188
- /**
189
- * Read the script of module filename from an active stack frame, then return it as a string.
190
- *
191
- * If there isn't a valid filename for the specified stack frame, an error will be thrown.
192
- *
193
- * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
194
- */
195
- export function getFileNameFromStack(stackLevels?: number): string;
196
-
197
176
  /**
198
177
  * Return a boolean indicating whether the provided value is a FILE object.
199
178
  *
@@ -44,6 +44,10 @@ declare module "quickjs:context" {
44
44
  * - Symbol
45
45
  * - eval (but it doesn't work unless the `eval` option is enabled)
46
46
  * - globalThis
47
+ *
48
+ * Note that new contexts don't have a `scriptArgs` global. If you need one
49
+ * to be present in the new context, you can add one onto the Context's
50
+ * `globalThis` property.
47
51
  */
48
52
  constructor(options?: {
49
53
  /** Enables `Date`. Defaults to `true` */
@@ -55,6 +59,9 @@ declare module "quickjs:context" {
55
59
  /** Enables `String.prototype.normalize`. Defaults to `true`. */
56
60
  stringNormalize?: boolean;
57
61
 
62
+ /** Enables `String.dedent`. Defaults to `true`. */
63
+ stringDedent?: boolean;
64
+
58
65
  /** Enables `RegExp`. Defaults to `true`. */
59
66
  regExp?: boolean;
60
67
 
@@ -121,32 +128,22 @@ declare module "quickjs:context" {
121
128
  */
122
129
  operators?: boolean;
123
130
 
124
- /** Enables "use math". Defaults to `true`. */
131
+ /** Enables `"use math"`. Defaults to `true`. */
125
132
  useMath?: boolean;
126
133
 
134
+ /** Enables `inspect`. Defaults to `true`. */
135
+ inspect?: boolean;
136
+ /** Enables `console`. Defaults to `true`. */
137
+ console?: boolean;
138
+ /** Enables `print`. Defaults to `true`. */
139
+ print?: boolean;
140
+ /** Enables `require` and `Module`. Defaults to `true`. */
141
+ moduleGlobals?: boolean;
127
142
  /**
128
- * Enables:
129
- *
130
- * - inspect
131
- * - console
132
- * - print
133
- * - require (and require.resolve)
134
- * - setTimeout
135
- * - clearTimeout
136
- * - setInterval
137
- * - clearInterval
138
- * - String.cooked
139
- * - String.dedent
140
- *
141
- * Defaults to `true`.
142
- *
143
- * NOTE: The following globals, normally part of `js_std_add_helpers`, are NEVER added:
144
- *
145
- * - scriptArgs
146
- *
147
- * If you need them in the new context, copy them over from your context's globalThis onto the child context's globalThis.
143
+ * Enables `setTimeout`, `clearTimeout`, `setInterval`, and
144
+ * `clearInterval`. Defaults to `true`.
148
145
  */
149
- stdHelpers?: boolean;
146
+ timers?: boolean;
150
147
 
151
148
  /** Enable builtin modules. */
152
149
  modules?: {
@@ -158,6 +155,8 @@ declare module "quickjs:context" {
158
155
  "quickjs:bytecode"?: boolean;
159
156
  /** Enables the "quickjs:context" module. Defaults to `true`. */
160
157
  "quickjs:context"?: boolean;
158
+ /** Enables the "quickjs:module" module. Defaults to `true`. */
159
+ "quickjs:module"?: boolean;
161
160
  };
162
161
  });
163
162
 
@@ -0,0 +1,72 @@
1
+ declare module "quickjs:module" {
2
+ /**
3
+ * Return whether the provided resolved module path is set as the main module.
4
+ *
5
+ * In other words, return what the value of `import.meta.main` would be within
6
+ * the module.
7
+ *
8
+ * The main module can be set via {@link setMainModule}.
9
+ */
10
+ export function isMainModule(resolvedFilepath: string): boolean;
11
+
12
+ /**
13
+ * Set the main module to the module with the provided resolved path.
14
+ *
15
+ * This will affect the value of `import.meta.main` for modules loaded in the
16
+ * future, but it will NOT retroactively change the value of
17
+ * `import.meta.main` in existing already-loaded modules.
18
+ */
19
+ export function setMainModule(resolvedFilepath: string): void;
20
+
21
+ /**
22
+ * Evaluate the string `code` as a script (global eval).
23
+ *
24
+ * @param code - The code to evaluate.
25
+ * @param options - An optional object containing the following optional properties:
26
+ * @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
27
+ * @property filename - String (default = "<evalScript>"). The filename to associate with the code being executed.
28
+ * @returns The result of the evaluation.
29
+ */
30
+ export function evalScript(
31
+ code: string,
32
+ options?: { backtraceBarrier?: boolean; filename?: string }
33
+ ): any;
34
+
35
+ /**
36
+ * Evaluate the file `filename` as a script (global eval).
37
+ *
38
+ * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
39
+ * @returns The result of the evaluation.
40
+ */
41
+ export function runScript(filename: string): any;
42
+
43
+ /**
44
+ * Evaluate the file `filename` as a module. Effectively a synchronous dynamic `import()`.
45
+ *
46
+ * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
47
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
48
+ * @returns The result of the evaluation (module namespace object).
49
+ */
50
+ export function importModule(
51
+ filename: string,
52
+ basename?: string
53
+ ): { [key: string]: any };
54
+
55
+ /**
56
+ * Return the resolved path to a module.
57
+ *
58
+ * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
59
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
60
+ * @returns The resolved module path.
61
+ */
62
+ export function resolveModule(filename: string, basename?: string): string;
63
+
64
+ /**
65
+ * Read the script of module filename from an active stack frame, then return it as a string.
66
+ *
67
+ * If there isn't a valid filename for the specified stack frame, an error will be thrown.
68
+ *
69
+ * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
70
+ */
71
+ export function getFileNameFromStack(stackLevels?: number): string;
72
+ }
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.2",
4
+ "version": "0.5.0",
5
5
  "main": "./npm/index.js",
6
6
  "bin": {
7
7
  "qjs": "npm/cli/qjs.js",