@suchipi/quickjs 0.5.0 → 0.6.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 (106) hide show
  1. package/README.md +56 -35
  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 +14 -0
  47. package/build/dts/quickjs-libmodule.d.ts +9 -0
  48. package/build/dts/quickjs-modulesys.d.ts +10 -12
  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
  106. 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 the following changes:
3
+ Fork of the fantastic QuickJS engine by Fabrice Bellard, with many changes.
4
4
 
5
- ## Changes to `quickjs`:
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
- ## Changes to `quickjs-libc`:
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,8 +57,6 @@ 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)).
@@ -51,15 +64,17 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
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).
53
66
 
54
- ## Changes to the `qjs` repl:
67
+ ### Changes to the `qjs` binary:
55
68
 
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
69
  - Blocking the main thread is allowed
70
+ - `-m` (module mode) now affects eval strings passed to `-e`
71
+ - Changes to the repl:
72
+ - Ctrl+W deletes words backwards from the cursor position
73
+ - The last error is accessible via the `_error` global
74
+ - If a thrown error has additional properties added onto it, those are printed along with the thrown error
75
+ - The new `inspect` global is used to print results
61
76
 
62
- ## New binary: `qjsbootstrap`:
77
+ ### New binary: `qjsbootstrap`:
63
78
 
64
79
  Appending some JS code to the end of this binary changes it into a binary that executes that JS code:
65
80
 
@@ -74,23 +89,23 @@ You can use this to create distributable binaries that run JS code without needi
74
89
 
75
90
  > 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
91
 
77
- ## New binary: `quickjs-run`:
92
+ ### New binary: `quickjs-run`:
78
93
 
79
94
  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
95
 
81
- ## New module: "quickjs:bytecode"
96
+ ### New module: "quickjs:bytecode"
82
97
 
83
98
  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
99
 
85
- ## New module: "quickjs:context"
100
+ ### New module: "quickjs:context"
86
101
 
87
102
  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
103
 
89
- ## New module: "quickjs:pointer"
104
+ ### New module: "quickjs:pointer"
90
105
 
91
106
  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
107
 
93
- ## New library: `quickjs-utils`
108
+ ### New library: `quickjs-utils`
94
109
 
95
110
  Helper structs, functions, and macros that make it easier to work with QuickJS in C code.
96
111
 
@@ -98,22 +113,19 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
98
113
  - Helper function for loading a file from disk into char a buffer
99
114
  - Helper functions for printing JS errors to stderr
100
115
 
101
- ## New library: `quickjs-modulesys`
116
+ ### Changes to the module loader
102
117
 
103
- - Module-loading code in `quickjs-libc` was moved into `quickjs-modulesys`, with the following changes:
104
- - `.js` extensions can now be omitted from import specifiers; they're optional.
105
- - If your import specifier points to a folder, it will attempt to load `index.js` from that folder.
118
+ - `.js` extensions can now be omitted from import specifiers; they're optional.
119
+ - If your import specifier points to a folder, it will attempt to load `index.js` from that folder.
106
120
  - Adds the global `require`, a CommonJS-like synchronous module loading function.
107
121
  - The `require` function is not fully CommonJS-compliant; for instance, `require.main` is not present. `require.resolve` is, though.
108
122
  - Adds `import.meta.require`
109
123
  - 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
124
  - Adds `import.meta.resolve`
111
125
  - 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.
115
- - Adds the global object `Module`.
116
- - `instanceof Module` can be used to identify module namespace objects.
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`.
117
129
  - You can specify additional implicit import specifier extensions by adding to the `Module.searchExtensions` array.
118
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.
119
131
  - You can define custom builtin modules using the `Module.define` function.
@@ -121,32 +133,41 @@ Helper structs, functions, and macros that make it easier to work with QuickJS i
121
133
  - Note that you must handle `Module.searchExtensions` yourself in your replacement implementation.
122
134
  - You can override the method used to load modules by replacing the `Module.read` function.
123
135
  - 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
136
+ - 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`.
139
+ - 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
+ - Synchronous import function added (`importModule`), which provides the same module record object you would get via dynamic (async) import.
145
+ - JS api for using the engine's configured module name normalization function was added (`resolveModule`).
146
+
147
+ ### Changes to project organization
129
148
 
130
149
  - Stuff is reorganized into separate folders under `src`.
131
150
  - 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
151
  - Line endings have been made consistent and trailing whitespace has been removed
133
152
  - 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`.
154
+ - 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
155
 
135
- ## More target OSes/runtimes
156
+ ### More target OSes/runtimes
136
157
 
137
158
  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
159
 
139
160
  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
161
 
141
- ## Library Archives
162
+ ### Library Archives
142
163
 
143
164
  We create `.a` files containing all of quickjs as part of the build.
144
165
 
145
- ## Other changes
166
+ ### Other changes
146
167
 
147
168
  There are also probably some other miscellaneous changes I forgot to write down in the README.
148
169
 
149
- # Compiling
170
+ ## Compiling
150
171
 
151
172
  The repo has stuff set up to compile quickjs binaries for:
152
173
 
@@ -166,7 +187,7 @@ Linux, macOS, iOS, and Windows binaries can be compiled using Docker. Or, you ca
166
187
 
167
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.
168
189
 
169
- ## Compilation Instructions
190
+ ### Compilation Instructions
170
191
 
171
192
  To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
172
193
 
Binary file
Binary file
@@ -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
  *
@@ -69,4 +69,13 @@ 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
+ * 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.
76
+ *
77
+ * This object can also be used to identify whether an object is a module
78
+ * namespace record.
79
+ */
80
+ export const Module: Module;
72
81
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * A global which lets you configure the module loader (import/export/require).
2
+ * An object which lets you configure the module loader (import/export/require).
3
3
  * You can use these properties to add support for importing new filetypes.
4
4
  *
5
- * This global can also be used to identify whether an object is a module
5
+ * This object can also be used to identify whether an object is a module
6
6
  * namespace record.
7
7
  */
8
- interface ModuleGlobal {
8
+ interface Module {
9
9
  /**
10
10
  * Returns true if `target` is a module namespace object.
11
11
  */
@@ -24,7 +24,7 @@ interface ModuleGlobal {
24
24
  * See the doc comment on {@link require} for more information.
25
25
  *
26
26
  * NOTE: If you add a new extension to this array, you will likely also want
27
- * to add to {@link Module.compilers}.
27
+ * to add to {@link compilers}.
28
28
  */
29
29
  searchExtensions: Array<string>;
30
30
 
@@ -65,7 +65,7 @@ interface ModuleGlobal {
65
65
  * And `names` will be a string containing the contents of names.txt.
66
66
  *
67
67
  * NOTE: When adding to this object, you may also wish to add to
68
- * {@link Module.searchExtensions}.
68
+ * {@link searchExtensions}.
69
69
  */
70
70
  compilers: {
71
71
  [extensionWithDot: string]: (filename: string, content: string) => string;
@@ -78,7 +78,8 @@ interface ModuleGlobal {
78
78
  define(name: string, obj: { [key: string]: any }): void;
79
79
 
80
80
  /**
81
- * Resolves a require/import request from `fromFile` into a canonicalized path.
81
+ * Resolves a require/import request from `fromFile` into a canonicalized
82
+ * path.
82
83
  *
83
84
  * To change native module resolution behavior, replace this function with
84
85
  * your own implementation. Note that you must handle
@@ -96,9 +97,6 @@ interface ModuleGlobal {
96
97
  read(modulePath: string): string;
97
98
  }
98
99
 
99
- // global added by QJMS_AddModuleGlobal
100
- declare var Module: ModuleGlobal;
101
-
102
100
  interface RequireFunction {
103
101
  /**
104
102
  * Synchronously import a module.
@@ -125,8 +123,8 @@ interface RequireFunction {
125
123
  * ```
126
124
  *
127
125
  * then the engine will look for `somewhere.js`. If that doesn't exist, the
128
- * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
129
- * will be thrown.
126
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an
127
+ * error will be thrown.
130
128
  *
131
129
  * If you add more extensions to `Module.searchExtensions`, then the engine
132
130
  * will use those, too. It will search in the same order as the strings appear
@@ -140,7 +138,7 @@ interface RequireFunction {
140
138
  resolve: (source: string) => string;
141
139
  }
142
140
 
143
- // global added by QJMS_AddRequireGlobal
141
+ // global added by QJMS_InitContext
144
142
  declare var require: RequireFunction;
145
143
 
146
144
  // gets set per-module by QJMS_SetModuleImportMeta
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.5.0",
4
+ "version": "0.6.0",
5
5
  "main": "./npm/index.js",
6
6
  "bin": {
7
7
  "qjs": "npm/cli/qjs.js",
package/.gitmodules DELETED
@@ -1,6 +0,0 @@
1
- [submodule "src/run-test262/test262"]
2
- path = src/run-test262/test262
3
- url = https://github.com/tc39/test262.git
4
- [submodule "src/run-test262/test262o"]
5
- path = src/run-test262/test262o
6
- url = https://github.com/tc39/test262.git