@suchipi/quickjs 0.2.1 → 0.3.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +66 -41
  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/is-stdin-a-tty +0 -0
  9. package/build/aarch64-apple-darwin/extras/run-test262 +0 -0
  10. package/build/aarch64-apple-darwin/extras/sample-program/sum +0 -0
  11. package/build/aarch64-apple-darwin/extras/stack-limit-test +0 -0
  12. package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
  13. package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
  14. package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
  15. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  16. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  17. package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
  18. package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
  19. package/build/aarch64-unknown-linux-gnu/extras/fib.so +0 -0
  20. package/build/aarch64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  21. package/build/aarch64-unknown-linux-gnu/extras/log-argv +0 -0
  22. package/build/aarch64-unknown-linux-gnu/extras/point.so +0 -0
  23. package/build/aarch64-unknown-linux-gnu/extras/run-test262 +0 -0
  24. package/build/aarch64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  25. package/build/aarch64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  26. package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  27. package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  28. package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
  29. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  30. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  31. package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
  32. package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
  33. package/build/aarch64-unknown-linux-musl/extras/fib.so +0 -0
  34. package/build/aarch64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  35. package/build/aarch64-unknown-linux-musl/extras/log-argv +0 -0
  36. package/build/aarch64-unknown-linux-musl/extras/point.so +0 -0
  37. package/build/aarch64-unknown-linux-musl/extras/run-test262 +0 -0
  38. package/build/aarch64-unknown-linux-musl/extras/sample-program/sum +0 -0
  39. package/build/aarch64-unknown-linux-musl/extras/stack-limit-test +0 -0
  40. package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  41. package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  42. package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
  43. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
  44. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  45. package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
  46. package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
  47. package/build/aarch64-unknown-linux-static/extras/fib.so +0 -0
  48. package/build/aarch64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  49. package/build/aarch64-unknown-linux-static/extras/log-argv +0 -0
  50. package/build/aarch64-unknown-linux-static/extras/point.so +0 -0
  51. package/build/aarch64-unknown-linux-static/extras/run-test262 +0 -0
  52. package/build/aarch64-unknown-linux-static/extras/sample-program/sum +0 -0
  53. package/build/aarch64-unknown-linux-static/extras/stack-limit-test +0 -0
  54. package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
  55. package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
  56. package/build/dts/quickjs-libc.d.ts +0 -157
  57. package/build/dts/quickjs-libcontext.d.ts +0 -1
  58. package/build/dts/quickjs.d.ts +12 -0
  59. package/build/x86_64-apple-darwin/bin/qjs +0 -0
  60. package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
  61. package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  62. package/build/x86_64-apple-darwin/bin/qjsc +0 -0
  63. package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
  64. package/build/x86_64-apple-darwin/extras/is-stdin-a-tty +0 -0
  65. package/build/x86_64-apple-darwin/extras/run-test262 +0 -0
  66. package/build/x86_64-apple-darwin/extras/sample-program/sum +0 -0
  67. package/build/x86_64-apple-darwin/extras/stack-limit-test +0 -0
  68. package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
  69. package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
  70. package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
  71. package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
  72. package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
  73. package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
  74. package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
  75. package/build/x86_64-pc-windows-static/extras/is-stdin-a-tty.exe +0 -0
  76. package/build/x86_64-pc-windows-static/extras/log-argv.exe +0 -0
  77. package/build/x86_64-pc-windows-static/extras/run-test262.exe +0 -0
  78. package/build/x86_64-pc-windows-static/extras/sample-program/sum.exe +0 -0
  79. package/build/x86_64-pc-windows-static/extras/stack-limit-test.exe +0 -0
  80. package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
  81. package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
  82. package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
  83. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  84. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  85. package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
  86. package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
  87. package/build/x86_64-unknown-linux-gnu/extras/is-stdin-a-tty +0 -0
  88. package/build/x86_64-unknown-linux-gnu/extras/run-test262 +0 -0
  89. package/build/x86_64-unknown-linux-gnu/extras/sample-program/sum +0 -0
  90. package/build/x86_64-unknown-linux-gnu/extras/stack-limit-test +0 -0
  91. package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  92. package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  93. package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
  94. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  95. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  96. package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
  97. package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
  98. package/build/x86_64-unknown-linux-musl/extras/fib.so +0 -0
  99. package/build/x86_64-unknown-linux-musl/extras/is-stdin-a-tty +0 -0
  100. package/build/x86_64-unknown-linux-musl/extras/log-argv +0 -0
  101. package/build/x86_64-unknown-linux-musl/extras/point.so +0 -0
  102. package/build/x86_64-unknown-linux-musl/extras/run-test262 +0 -0
  103. package/build/x86_64-unknown-linux-musl/extras/sample-program/sum +0 -0
  104. package/build/x86_64-unknown-linux-musl/extras/stack-limit-test +0 -0
  105. package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  106. package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  107. package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
  108. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
  109. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  110. package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
  111. package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
  112. package/build/x86_64-unknown-linux-static/extras/fib.so +0 -0
  113. package/build/x86_64-unknown-linux-static/extras/is-stdin-a-tty +0 -0
  114. package/build/x86_64-unknown-linux-static/extras/log-argv +0 -0
  115. package/build/x86_64-unknown-linux-static/extras/point.so +0 -0
  116. package/build/x86_64-unknown-linux-static/extras/run-test262 +0 -0
  117. package/build/x86_64-unknown-linux-static/extras/sample-program/sum +0 -0
  118. package/build/x86_64-unknown-linux-static/extras/stack-limit-test +0 -0
  119. package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
  120. package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
  121. package/package.json +1 -1
  122. package/tsconfig.json +1 -1
package/LICENSE CHANGED
@@ -2,7 +2,7 @@ QuickJS Javascript Engine
2
2
 
3
3
  Copyright (c) 2017-2021 Fabrice Bellard
4
4
  Copyright (c) 2017-2021 Charlie Gordon
5
- Copyright (c) 2022-2022 Lily Skye
5
+ Copyright (c) 2022-2023 Lily Skye
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -5,11 +5,12 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
5
5
  ## Changes to `quickjs`:
6
6
 
7
7
  - A TypeScript `.d.ts` file is provided for all QuickJS-specific APIs (operator overloading APIs, BigInt extensions, BigFloat, BigDecimal, etc).
8
- - `Object.toPrimitive` is now available (static method that invokes ToPrimitive on the given value, using the optionally-provided hint).
9
- - `Object.isPrimitive` is now available (static method that returns a boolean indicating whether the given value is a primitive).
10
- - `Symbol.typeofValue` can be used to override the result of using the `typeof` operator on an object. However, you can only use it to return a different one of the builtin values `typeof` would normally return: `"object"`, `"boolean"`, `"number"`, etc.
8
+ - Non-standard `Object.toPrimitive` added (static method that invokes ToPrimitive on the given value, using the optionally-provided hint).
9
+ - Non-standard `Object.isPrimitive` added (static method that returns a boolean indicating whether the given value is a primitive).
10
+ - Non-standard `Symbol.typeofValue` has been added which can be used to override the result of using the `typeof` operator on an object. However, you can only use it to return a different one of the builtin values `typeof` would normally return: `"object"`, `"boolean"`, `"number"`, etc.
11
11
  - Added support for Error constructor "cause" option (from ES2022).
12
12
  - Added support for relative indexing method `.at()` (from ES2022).
13
+ - `String.cooked` added (no-op template tag, like the proposed [String.cooked](https://github.com/tc39/proposal-string-cooked)).
13
14
  - Added function `JS_EvalThis_Privileged`, which allows C code to run eval in Contexts that have eval disabled. With this, you can disable eval in a context for security purposes, but can still execute trusted code within it.
14
15
  - Additional functions are exposed that allow importing modules synchronously or asynchronously:
15
16
  - `JS_DynamicImportAsync`
@@ -29,26 +30,8 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
29
30
  - 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.
30
31
  - In places where APIs in `std` or `os` would return null on failure, now an error will be thrown instead.
31
32
  - Error messages from `std` and `os` include information in the message such as the path to the file that couldn't be loaded. This info is also available as properties on the Error object.
32
- - `.js` extensions can now be omitted from import specifiers; they're optional.
33
- - If your import specifier points to a folder, it will attempt to load `index.js` from that folder.
34
-
35
- ## Additions to `quickjs-libc`:
36
-
37
- - A TypeScript `.d.ts` file is provided for all APIs (globals as well as stuff from `std`/`os`).
38
- - Synchronous import functions added (`require`, or the more flexible `std.importModule`).
39
- - Both of these functions provide the same module record object you would get via dynamic (async) import.
40
- - The `require` function is not fully CommonJS-compliant; for instance, `require.main` is not present.
41
- - Module resolution functions added (`require.resolve`, or `std.resolveModule`).
33
+ - A TypeScript `.d.ts` file is now provided for all APIs (globals as well as stuff from `std`/`os`).
42
34
  - A builtin global function `inspect` is added, which pretty-prints any JS value as a string.
43
- - A builtin global object `Module` is added.
44
- - `instanceof Module` can be used to identify module namespace objects.
45
- - You can specify additional implicit import specifier extensions by adding to the `Module.searchExtensions` array.
46
- - 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.
47
- - You can define custom builtin modules using the `Module.define` function.
48
- - You can override module name normalization (aka module resolution) by replacing the `Module.resolve` function.
49
- - Note that you must handle `Module.searchExtensions` yourself in your replacement implementation.
50
- - You can override the method used to load modules by replacing the `Module.read` function.
51
- - Note that you must handle `Module.compilers` yourself in your replacement implementation.
52
35
  - `os.access` function added (wrapper for libc `access`).
53
36
  - `FILE.prototype.sync` method added (wrapper for `fsync`).
54
37
  - `FILE.prototype.setvbuf` method added (wrapper for `setvbuf`).
@@ -56,12 +39,16 @@ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following chan
56
39
  - `os.{WUNTRACED,WEXITSTATUS,WTERMSIG,WSTOPSIG,WIFEXITED,WIFSIGNALED,WIFSTOPPED,WIFCONTINUED}` added, for working with `os.waitpid`.
57
40
  - `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.
58
41
  - `"b"` mode flag is now allowed in `std.fdopen`.
59
- - `std.strftime` is now available (wrapper for libc `strftime`).
60
- - `setTimeout` and `clearTimeout` are now available as globals.
61
- - `setInterval` and `clearInterval` are now available as globals.
62
- - `String.cooked` is now available (no-op template tag, like the proposed [String.cooked](https://github.com/tc39/proposal-string-cooked)).
63
- - `String.dedent` is now available (template tag function, like the proposed [String.dedent](https://github.com/tc39/proposal-string-dedent)).
42
+ - `std.strftime` added (wrapper for libc `strftime`).
64
43
  - Added `std.getuid`, `std.geteuid`, `std.getgid`, and `std.getegid` (wrappers for the libc functions of the same names).
44
+ - 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
+ - `setTimeout` and `clearTimeout` are now available as globals (previously they were only available as exports).
48
+ - `setInterval` and `clearInterval` are added, available as globals.
49
+ - `String.dedent` added (template tag function, like the proposed [String.dedent](https://github.com/tc39/proposal-string-dedent)).
50
+ - Several C-side helper functions were moved out of quickjs-libc and into quickjs-utils.
51
+ - Most module-related code (setting import.meta, etc) was moved into quickjs-modulesys.
65
52
 
66
53
  ## Changes to the `qjs` repl:
67
54
 
@@ -104,20 +91,52 @@ A barebones Module that exports a JS class which can be used to represent an opa
104
91
 
105
92
  ## New library: `quickjs-utils`
106
93
 
107
- Helper structs, functions, and macros that make it easier to work with QuickJS objects in C code.
94
+ Helper structs, functions, and macros that make it easier to work with QuickJS in C code.
95
+
96
+ - APIs for looping over every property in a JSValue
97
+ - Helper function for loading a file from disk into char a buffer
98
+ - Helper functions for printing JS errors to stderr
99
+
100
+ ## New library: `quickjs-modulesys`
101
+
102
+ - Module-loading code in `quickjs-libc` was moved into `quickjs-modulesys`, with the following changes:
103
+ - `.js` extensions can now be omitted from import specifiers; they're optional.
104
+ - If your import specifier points to a folder, it will attempt to load `index.js` from that folder.
105
+ - Adds the global `require`, a CommonJS-like synchronous module loading function.
106
+ - The `require` function is not fully CommonJS-compliant; for instance, `require.main` is not present. `require.resolve` is, though.
107
+ - Adds `import.meta.require`
108
+ - 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
+ - Adds `import.meta.resolve`
110
+ - 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`.
111
+ - Adds the global object `Module`.
112
+ - `instanceof Module` can be used to identify module namespace objects.
113
+ - You can specify additional implicit import specifier extensions by adding to the `Module.searchExtensions` array.
114
+ - 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.
115
+ - You can define custom builtin modules using the `Module.define` function.
116
+ - You can override module name normalization (aka module resolution) by replacing the `Module.resolve` function.
117
+ - Note that you must handle `Module.searchExtensions` yourself in your replacement implementation.
118
+ - You can override the method used to load modules by replacing the `Module.read` function.
119
+ - Note that you must handle `Module.compilers` yourself in your replacement implementation.
120
+ - The `eval_*` functions that were duplicated in each of the programs (`eval_buf`, `eval_file`, and `eval_binary`) were moved here
121
+ - 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
122
+ - 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.
108
123
 
109
124
  ## Changes to project organization
110
125
 
111
126
  - Stuff is reorganized into separate folders under `src`.
112
127
  - 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).
113
- - macOS binaries are now cross-compiled from Linux
114
- - we now compile ARM macOS binaries as well
115
- - These should work on both M1/M2/etc macbooks as well as on jailbroken iPhones/iPads
116
- - we compile aarch64 (arm 64) binaries for linux, too
117
- - these are statically linked, so should work on a raspi/etc, in theory. maybe android, too
118
128
  - Line endings have been made consistent and trailing whitespace has been removed
119
- - FreeBSD support added (but there's no cross-compilation set up, so you'll have to compile it yourself from a FreeBSD machine).
120
- - I'm in the process of converting the tests to a new format (which gets run by jest). But I haven't touched most of the old tests yet.
129
+ - The tests are authored in a new format which leverages jest snapshot testing.
130
+
131
+ ## More target OSes/runtimes
132
+
133
+ We now include support for more platforms, and cross-compilation scripts to build most of those platforms from any platform where Docker is available.
134
+
135
+ 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.
136
+
137
+ ## Library Archives
138
+
139
+ We create `.a` files containing all of quickjs as part of the build.
121
140
 
122
141
  ## Other changes
123
142
 
@@ -125,9 +144,19 @@ There are also probably some other miscellaneous changes I forgot to write down
125
144
 
126
145
  # Compiling
127
146
 
128
- The repo has stuff set up to compile quickjs binaries for Linux, macOS, iOS, FreeBSD, or Windows.
147
+ The repo has stuff set up to compile quickjs binaries for:
129
148
 
130
- QuickJS itself has no external dependencies outside this repo except pthreads, and all of the code is C99. As such, it shouldn't be too difficult to get it compiling on other Unix-like OSes. OS-specific configuration is done by way of config files found in the `meta/ninja/env` folder.
149
+ - Linux (amd64 and aarch64)
150
+ - glibc
151
+ - musl
152
+ - statically-linked
153
+ - macOS/iOS (x86_64 and arm64)
154
+ - Windows (x86_64)
155
+ - FreeBSD (cross-compilation not supported; you need to compile from a FreeBSD host)
156
+ - Cosmopolitan Libc (cross-platform `*.com` binaries). You need the cosmo toolchain installed for this one to work.
157
+ - any arbitrary unix-like OS, if you set env vars for CC, CFLAGS, etc.
158
+
159
+ QuickJS itself has no external dependencies outside this repo except pthreads, and all of the code is C99. As such, it shouldn't be too difficult to get it compiling on other Unix-like OSes.
131
160
 
132
161
  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.
133
162
 
@@ -150,7 +179,3 @@ Or, to compile binaries for just your own unix system:
150
179
  - Build artifacts will be placed in the `build` folder. You're probably most interested in stuff in the `build/bin` and `build/lib` folders.
151
180
 
152
181
  If you are targeting an unsupported OS or would like to use a different compiler, set the environment variables `HOST` and `TARGET` both to "other", and then set the environment variables `CC`, `AR`, `CFLAGS`, and `LDFLAGS` as you see fit. There are some other variables you can set as well; see `meta/ninja/envs/target/other.ninja.js` and `meta/ninja/envs/host/other.ninja.js` for a list.
153
-
154
- ## Notes
155
-
156
- The old tests for std and os aren't working right now; I really haven't touched them yet, so they're still expecting the old function signatures (returning errno, etc).
Binary file
Binary file
@@ -1149,153 +1149,6 @@ declare interface InspectFunction {
1149
1149
  */
1150
1150
  declare var inspect: InspectFunction;
1151
1151
 
1152
- /**
1153
- * A global which lets you configure the module loader (import/export/require).
1154
- * You can use these properties to add support for importing new filetypes.
1155
- *
1156
- * This global can also be used to identify whether an object is a module
1157
- * namespace record.
1158
- */
1159
- interface ModuleGlobal {
1160
- /**
1161
- * Returns true if `target` is a module namespace object.
1162
- */
1163
- [Symbol.hasInstance](target: any): target is {
1164
- [key: string | number | symbol]: any;
1165
- };
1166
-
1167
- /**
1168
- * A list of filetype extensions that may be omitted from an import specifier
1169
- * string.
1170
- *
1171
- * Defaults to `[".js"]`. You can add more strings to this array to
1172
- * make the engine search for additional files when resolving a
1173
- * require/import.
1174
- *
1175
- * See the doc comment on {@link require} for more information.
1176
- *
1177
- * NOTE: If you add a new extension to this array, you will likely also want
1178
- * to add to {@link Module.compilers}.
1179
- */
1180
- searchExtensions: Array<string>;
1181
-
1182
- /**
1183
- * User-defined functions which will handle getting the JavaScript code
1184
- * associated with a module.
1185
- *
1186
- * The key for each property in this object should be a file extension
1187
- * string with a leading dot, eg `".jsx"`. The value for each property should
1188
- * be a function which receives (1) the filepath to a module, and (2) that
1189
- * file's content as a UTF-8 string, and the function should return a string
1190
- * containing JavaScript code that corresponds to that module. In most cases,
1191
- * these functions will compile the contents of the file from one format into JavaScript.
1192
- *
1193
- * The function does not have to use the second 'content' argument it
1194
- * receives (ie. when loading binary files).
1195
- *
1196
- * By adding to this object, you can make it possible to import non-js
1197
- * filetypes; compile-to-JS languages like JSX, TypeScript, and CoffeeScript
1198
- * can be compiled at import time, and asset files like .txt files or .png
1199
- * files can be converted into an appropriate data structure at import time.
1200
- *
1201
- * As an example, to make it possible to import .txt files, you might do:
1202
- * ```js
1203
- * import * as std from "std";
1204
- *
1205
- * Module.compilers[".txt"] = (filename, content) => {
1206
- * return `export default ${JSON.stringify(content)}`;
1207
- * }
1208
- * ```
1209
- * (leveraging `JSON.stringify`'s ability to escape quotes).
1210
- *
1211
- * Then, later in your code, you can do:
1212
- * ```js
1213
- * import names from "./names.txt";
1214
- * ```
1215
- *
1216
- * And `names` will be a string containing the contents of names.txt.
1217
- *
1218
- * NOTE: When adding to this object, you may also wish to add to
1219
- * {@link Module.searchExtensions}.
1220
- */
1221
- compilers: {
1222
- [extensionWithDot: string]: (filename: string, content: string) => string;
1223
- };
1224
-
1225
- /**
1226
- * Create a virtual built-in module whose exports consist of the own
1227
- * enumerable properties of `obj`.
1228
- */
1229
- define(name: string, obj: { [key: string]: any }): void;
1230
-
1231
- /**
1232
- * Resolves a require/import request from `fromFile` into a canonicalized path.
1233
- *
1234
- * To change native module resolution behavior, replace this function with
1235
- * your own implementation. Note that you must handle
1236
- * `Module.searchExtensions` yourself in your replacement implementation.
1237
- */
1238
- resolve(name: string, fromFile: string): string;
1239
-
1240
- /**
1241
- * Reads the contents of the given resolved module name into a string.
1242
- *
1243
- * To change native module loading behavior, replace this function with your
1244
- * own implementation. Note that you must handle `Module.compilers` yourself
1245
- * in your replacement implementation.
1246
- */
1247
- read(modulePath: string): string;
1248
- }
1249
-
1250
- declare var Module: ModuleGlobal;
1251
-
1252
- interface RequireFunction {
1253
- /**
1254
- * Synchronously import a module.
1255
- *
1256
- * `source` will be resolved relative to the calling file.
1257
- *
1258
- * If `source` does not have a file extension, and a file without an extension
1259
- * cannot be found, the engine will check for files with the extensions in
1260
- * {@link Module.searchExtensions}, and use one of those if present. This
1261
- * behavior also happens when using normal `import` statements.
1262
- *
1263
- * For example, if you write:
1264
- *
1265
- * ```js
1266
- * import something from "./somewhere";
1267
- * ```
1268
- *
1269
- * but there's no file named `somewhere` in the same directory as the file
1270
- * where that import appears, and `Module.searchExtensions` is the default
1271
- * value:
1272
- *
1273
- * ```js
1274
- * [".js"]
1275
- * ```
1276
- *
1277
- * then the engine will look for `somewhere.js`. If that doesn't exist, the
1278
- * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
1279
- * will be thrown.
1280
- *
1281
- * If you add more extensions to `Module.searchExtensions`, then the engine
1282
- * will use those, too. It will search in the same order as the strings appear
1283
- * in the `Module.searchExtensions` array.
1284
- */
1285
- (source: string): any;
1286
-
1287
- /**
1288
- * Resolves the normalized path to a modules, relative to the calling file.
1289
- */
1290
- resolve: (source: string) => string;
1291
- }
1292
-
1293
- declare var require: RequireFunction;
1294
-
1295
- interface ImportMeta {
1296
- require: RequireFunction;
1297
- }
1298
-
1299
1152
  declare var setTimeout: typeof import("quickjs:os").setTimeout;
1300
1153
  declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
1301
1154
 
@@ -1305,16 +1158,6 @@ declare function setInterval(func: (...args: any) => any, ms: number): Interval;
1305
1158
  declare function clearInterval(interval: Interval): void;
1306
1159
 
1307
1160
  interface StringConstructor {
1308
- /**
1309
- * A no-op template literal tag.
1310
- *
1311
- * https://github.com/tc39/proposal-string-cooked
1312
- */
1313
- cooked(
1314
- strings: readonly string[] | ArrayLike<string>,
1315
- ...substitutions: any[]
1316
- ): string;
1317
-
1318
1161
  /**
1319
1162
  * Remove leading minimum indentation from the string.
1320
1163
  * The first line of the string must be empty.
@@ -142,7 +142,6 @@ declare module "quickjs:context" {
142
142
  *
143
143
  * NOTE: The following globals, normally part of `js_std_add_helpers`, are NEVER added:
144
144
  *
145
- * - Module
146
145
  * - scriptArgs
147
146
  *
148
147
  * If you need them in the new context, copy them over from your context's globalThis onto the child context's globalThis.
@@ -19,6 +19,18 @@ interface ObjectConstructor {
19
19
  isPrimitive(input: any): boolean;
20
20
  }
21
21
 
22
+ interface StringConstructor {
23
+ /**
24
+ * A no-op template literal tag.
25
+ *
26
+ * https://github.com/tc39/proposal-string-cooked
27
+ */
28
+ cooked(
29
+ strings: readonly string[] | ArrayLike<string>,
30
+ ...substitutions: any[]
31
+ ): string;
32
+ }
33
+
22
34
  interface SymbolConstructor {
23
35
  /**
24
36
  * A method that changes the result of using the `typeof` operator on the
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.2.1",
4
+ "version": "0.3.0",
5
5
  "main": "./npm/index.js",
6
6
  "bin": {
7
7
  "qjs": "./npm/cli/qjs.js",
package/tsconfig.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "allowJs": true,
19
19
  "checkJs": true,
20
20
  "noEmit": true,
21
- "lib": ["ES2020"],
21
+ "lib": ["ES2021"],
22
22
  "module": "ES2020",
23
23
  "moduleResolution": "node",
24
24
  "strictNullChecks": true,