@suchipi/quickjs 0.1.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 (117) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +145 -0
  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/dts/inspect.d.ts +123 -0
  9. package/build/aarch64-apple-darwin/dts/quickjs-libbytecode.d.ts +24 -0
  10. package/build/aarch64-apple-darwin/dts/quickjs-libc.d.ts +1309 -0
  11. package/build/aarch64-apple-darwin/dts/quickjs-libcontext.d.ts +179 -0
  12. package/build/aarch64-apple-darwin/dts/quickjs.d.ts +859 -0
  13. package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
  14. package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
  15. package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
  16. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  17. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  18. package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
  19. package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
  20. package/build/aarch64-unknown-linux-gnu/dts/inspect.d.ts +123 -0
  21. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libbytecode.d.ts +24 -0
  22. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libc.d.ts +1309 -0
  23. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libcontext.d.ts +179 -0
  24. package/build/aarch64-unknown-linux-gnu/dts/quickjs.d.ts +859 -0
  25. package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  26. package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  27. package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
  28. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  29. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  30. package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
  31. package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
  32. package/build/aarch64-unknown-linux-musl/dts/inspect.d.ts +123 -0
  33. package/build/aarch64-unknown-linux-musl/dts/quickjs-libbytecode.d.ts +24 -0
  34. package/build/aarch64-unknown-linux-musl/dts/quickjs-libc.d.ts +1309 -0
  35. package/build/aarch64-unknown-linux-musl/dts/quickjs-libcontext.d.ts +179 -0
  36. package/build/aarch64-unknown-linux-musl/dts/quickjs.d.ts +859 -0
  37. package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  38. package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  39. package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
  40. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
  41. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  42. package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
  43. package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
  44. package/build/aarch64-unknown-linux-static/dts/inspect.d.ts +123 -0
  45. package/build/aarch64-unknown-linux-static/dts/quickjs-libbytecode.d.ts +24 -0
  46. package/build/aarch64-unknown-linux-static/dts/quickjs-libc.d.ts +1309 -0
  47. package/build/aarch64-unknown-linux-static/dts/quickjs-libcontext.d.ts +179 -0
  48. package/build/aarch64-unknown-linux-static/dts/quickjs.d.ts +859 -0
  49. package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
  50. package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
  51. package/build/x86_64-apple-darwin/bin/qjs +0 -0
  52. package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
  53. package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  54. package/build/x86_64-apple-darwin/bin/qjsc +0 -0
  55. package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
  56. package/build/x86_64-apple-darwin/dts/inspect.d.ts +123 -0
  57. package/build/x86_64-apple-darwin/dts/quickjs-libbytecode.d.ts +24 -0
  58. package/build/x86_64-apple-darwin/dts/quickjs-libc.d.ts +1309 -0
  59. package/build/x86_64-apple-darwin/dts/quickjs-libcontext.d.ts +179 -0
  60. package/build/x86_64-apple-darwin/dts/quickjs.d.ts +859 -0
  61. package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
  62. package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
  63. package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
  64. package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
  65. package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
  66. package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
  67. package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
  68. package/build/x86_64-pc-windows-static/dts/inspect.d.ts +123 -0
  69. package/build/x86_64-pc-windows-static/dts/quickjs-libbytecode.d.ts +24 -0
  70. package/build/x86_64-pc-windows-static/dts/quickjs-libc.d.ts +1309 -0
  71. package/build/x86_64-pc-windows-static/dts/quickjs-libcontext.d.ts +179 -0
  72. package/build/x86_64-pc-windows-static/dts/quickjs.d.ts +859 -0
  73. package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
  74. package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
  75. package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
  76. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  77. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  78. package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
  79. package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
  80. package/build/x86_64-unknown-linux-gnu/dts/inspect.d.ts +123 -0
  81. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libbytecode.d.ts +24 -0
  82. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libc.d.ts +1309 -0
  83. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libcontext.d.ts +179 -0
  84. package/build/x86_64-unknown-linux-gnu/dts/quickjs.d.ts +859 -0
  85. package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  86. package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  87. package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
  88. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  89. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  90. package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
  91. package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
  92. package/build/x86_64-unknown-linux-musl/dts/inspect.d.ts +123 -0
  93. package/build/x86_64-unknown-linux-musl/dts/quickjs-libbytecode.d.ts +24 -0
  94. package/build/x86_64-unknown-linux-musl/dts/quickjs-libc.d.ts +1309 -0
  95. package/build/x86_64-unknown-linux-musl/dts/quickjs-libcontext.d.ts +179 -0
  96. package/build/x86_64-unknown-linux-musl/dts/quickjs.d.ts +859 -0
  97. package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  98. package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  99. package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
  100. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
  101. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  102. package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
  103. package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
  104. package/build/x86_64-unknown-linux-static/dts/inspect.d.ts +123 -0
  105. package/build/x86_64-unknown-linux-static/dts/quickjs-libbytecode.d.ts +24 -0
  106. package/build/x86_64-unknown-linux-static/dts/quickjs-libc.d.ts +1309 -0
  107. package/build/x86_64-unknown-linux-static/dts/quickjs-libcontext.d.ts +179 -0
  108. package/build/x86_64-unknown-linux-static/dts/quickjs.d.ts +859 -0
  109. package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
  110. package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
  111. package/npm/cli/qjs.js +4 -0
  112. package/npm/cli/qjsc.js +4 -0
  113. package/npm/cli/quickjs-run.js +4 -0
  114. package/npm/cli/run-binary.js +17 -0
  115. package/npm/index.js +68 -0
  116. package/package.json +35 -0
  117. package/tsconfig.json +19 -0
package/LICENSE ADDED
@@ -0,0 +1,40 @@
1
+ QuickJS Javascript Engine
2
+
3
+ Copyright (c) 2017-2021 Fabrice Bellard
4
+ Copyright (c) 2017-2021 Charlie Gordon
5
+ Copyright (c) 2022-2022 Lily Skye
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+
25
+ QuickJS also includes npm:@suchipi/inspect@2.1.0, which has the following license:
26
+
27
+ Copyright (c) 2016-2022, John Gardner
28
+ Copyright (c) 2022 Lily Skye
29
+
30
+ Permission to use, copy, modify, and/or distribute this software for any
31
+ purpose with or without fee is hereby granted, provided that the above
32
+ copyright notice and this permission notice appear in all copies.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
35
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
36
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
37
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
39
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
40
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # suchipi/quickjs
2
+
3
+ Fork of the fantastic QuickJS engine by Fabrice Bellard, with the following changes:
4
+
5
+ ## Changes to `quickjs`:
6
+
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.
11
+ - Added support for Error constructor "cause" option (from ES2022).
12
+ - Added support for relative indexing method `.at()` (from ES2022).
13
+ - 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
+ - Additional functions are exposed that allow importing modules synchronously or asynchronously:
15
+ - `JS_DynamicImportAsync`
16
+ - `JS_DynamicImportSync`
17
+ - `JS_DynamicImportSync2` (additional arg for specifying basename that the import specifier is relative to)
18
+ - Additional error-related functions added:
19
+ - `JS_ThrowError`
20
+ - `JS_AddPropertyToException`
21
+ - Additional utility functions added:
22
+ - `JS_FreezeObjectValue` (performs Object.freeze)
23
+ - `JS_IsPrimitive`
24
+ - ModuleDefs now have an optional "user_data" property (pointer to void) which can be accessed during module initialization (via `JS_GetModuleUserData` and `JS_SetModuleUserData`)
25
+
26
+ ## Changes to `quickjs-libc`:
27
+
28
+ - `std` and `os` builtin modules are now namespaced under "quickjs:". In other words, you have to import them as "quickjs:std" and "quickjs:os".
29
+ - 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
+ - In places where APIs in `std` or `os` would return null on failure, now an error will be thrown instead.
31
+ - 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`).
42
+ - 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
+ - `os.access` function added (wrapper for libc `access`).
53
+ - `FILE.prototype.sync` method added (wrapper for `fsync`).
54
+ - `FILE.prototype.setvbuf` method added (wrapper for `setvbuf`).
55
+ - `std.isFILE` function added (returns whether the provided object is a `FILE` (via `js_std_file_class_id`)).
56
+ - `os.{WUNTRACED,WEXITSTATUS,WTERMSIG,WSTOPSIG,WIFEXITED,WIFSIGNALED,WIFSTOPPED,WIFCONTINUED}` added, for working with `os.waitpid`.
57
+ - `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
+ - `"b"` mode flag is now allowed in `std.fdopen`.
59
+ - `setTimeout` and `clearTimeout` are now available as globals.
60
+ - `setInterval` and `clearInterval` are now available as globals.
61
+ - `String.cooked` is now available (no-op template tag, like the proposed [String.cooked](https://github.com/tc39/proposal-string-cooked)).
62
+ - `String.dedent` is now available (template tag function, like the proposed [String.dedent](https://github.com/tc39/proposal-string-dedent)).
63
+
64
+ ## Changes to the `qjs` repl:
65
+
66
+ - The new `inspect` global is used to print results
67
+ - The last error is accessible via the `_error` global
68
+ - If a thrown error has additional properties added onto it, those are printed along with the thrown error
69
+ - Ctrl+W deletes words backwards from the cursor position
70
+
71
+ ## New binary: `qjsbootstrap`:
72
+
73
+ Appending some JS code to the end of this binary changes it into a binary that executes that JS code:
74
+
75
+ ```sh
76
+ $ cp qjsbootstrap my-program
77
+ $ echo 'console.log("hello!")' >> my-program
78
+ $ ./my-program
79
+ hello!
80
+ ```
81
+
82
+ You can use this to create distributable binaries that run JS code without needing to use qjsc or a C compiler. Instructions [here](https://github.com/suchipi/quickjs/tree/main/src/qjsbootstrap).
83
+
84
+ > 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.
85
+
86
+ ## New module: "quickjs:bytecode"
87
+
88
+ 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`.
89
+
90
+ ## New module: "quickjs:context"
91
+
92
+ 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.
93
+
94
+ ## New library: `quickjs-utils`
95
+
96
+ Helper structs, functions, and macros that make it easier to work with QuickJS objects in C code.
97
+
98
+ ## Changes to project organization
99
+
100
+ - Stuff is reorganized into separate folders under `src`.
101
+ - 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).
102
+ - macOS binaries are now cross-compiled from Linux
103
+ - we now compile ARM macOS binaries as well
104
+ - These should work on both M1/M2/etc macbooks as well as on jailbroken iPhones/iPads
105
+ - we compile aarch64 (arm 64) binaries for linux, too
106
+ - these are statically linked, so should work on a raspi/etc, in theory. maybe android, too
107
+ - Line endings have been made consistent and trailing whitespace has been removed
108
+ - FreeBSD support added (but there's no cross-compilation set up, so you'll have to compile it yourself from a FreeBSD machine).
109
+ - 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.
110
+
111
+ ## Other changes
112
+
113
+ There are also probably some other miscellaneous changes I forgot to write down in the README.
114
+
115
+ # Compiling
116
+
117
+ The repo has stuff set up to compile quickjs binaries for Linux, macOS, iOS, FreeBSD, or Windows.
118
+
119
+ 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.
120
+
121
+ 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.
122
+
123
+ 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.
124
+
125
+ ## Compilation Instructions
126
+
127
+ To compile binaries for Linux, macOS, iOS, and Windows (using Docker):
128
+
129
+ - Make sure you have docker installed.
130
+ - Clone the repo and cd to its folder
131
+ - Run `meta/docker/build-all.sh`
132
+ - Build artifacts will be placed in the `build` folder, organized by OS.
133
+
134
+ Or, to compile binaries for just your own unix system:
135
+
136
+ - 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.
137
+ - Clone the repo and cd to its folder
138
+ - Run `meta/build.sh`
139
+ - Build artifacts will be placed in the `build` folder. You're probably most interested in stuff in the `build/bin` and `build/lib` folders.
140
+
141
+ 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.
142
+
143
+ ## Notes
144
+
145
+ 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).
@@ -0,0 +1,123 @@
1
+ /** npm: @suchipi/print@2.3.0. License: ISC */
2
+
3
+ /*
4
+ Copyright (c) 2016-2022, John Gardner
5
+ Copyright (c) 2022 Lily Skye
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
+ */
19
+
20
+ /**
21
+ * Options for {@link inspect}.
22
+ */
23
+ declare interface InspectOptions {
24
+ /** Whether to display non-enumerable properties. Defaults to false. */
25
+ all?: boolean;
26
+
27
+ /** Whether to invoke getter functions. Defaults to false. */
28
+ followGetters?: boolean;
29
+
30
+ /** Whether to display the indexes of iterable entries. Defaults to false. */
31
+ indexes?: boolean;
32
+
33
+ /** Hide object details after 𝑁 recursions. Defaults to Infinity. */
34
+ maxDepth?: number;
35
+
36
+ /** If true, don't identify well-known symbols as `@@…`. Defaults to false. */
37
+ noAmp?: boolean;
38
+
39
+ /** If true, don't format byte-arrays as hexadecimal. Defaults to false. */
40
+ noHex?: boolean;
41
+
42
+ /** If true, don't display function source code. Defaults to false. */
43
+ noSource?: boolean;
44
+
45
+ /** Whether to show `__proto__` properties if possible. Defaults to false. */
46
+ proto?: boolean;
47
+
48
+ /** Whether to sort properties alphabetically. When false, properties are sorted by creation order. Defaults to false. */
49
+ sort?: boolean;
50
+
51
+ /** Options that control whether and how ANSI terminal escape sequences for colours should be added to the output. Defaults to false, meaning no colours. */
52
+ colours?: boolean | 256 | 8 | InspectColours;
53
+
54
+ /** Prefix string to use for indentation. Defaults to '\t'. */
55
+ indent?: string;
56
+ }
57
+
58
+ declare interface InspectColours {
59
+ off?: string | number;
60
+ red?: string | number;
61
+ grey?: string | number;
62
+ green?: string | number;
63
+ darkGreen?: string | number;
64
+ punct?: string | number;
65
+ keys?: string | number;
66
+ keyEscape?: string | number;
67
+ typeColour?: string | number;
68
+ primitive?: string | number;
69
+ escape?: string | number;
70
+ date?: string | number;
71
+ hexBorder?: string | number;
72
+ hexValue?: string | number;
73
+ hexOffset?: string | number;
74
+ reference?: string | number;
75
+ srcBorder?: string | number;
76
+ srcRowNum?: string | number;
77
+ srcRowText?: string | number;
78
+ nul?: string | number;
79
+ nulProt?: string | number;
80
+ undef?: string | number;
81
+ noExts?: string | number;
82
+ frozen?: string | number;
83
+ sealed?: string | number;
84
+ regex?: string | number;
85
+ string?: string | number;
86
+ symbol?: string | number;
87
+ symbolFade?: string | number;
88
+ braces?: string | number;
89
+ quotes?: string | number;
90
+ empty?: string | number;
91
+ dot?: string | number;
92
+ }
93
+
94
+ declare interface InspectFunction {
95
+ /**
96
+ * Generate a human-readable representation of a value.
97
+ *
98
+ * @param value - Value to inspect
99
+ * @param options - Additional settings for refining output
100
+ * @returns A string representation of `value`.
101
+ */
102
+ (value: any, options?: InspectOptions): string;
103
+
104
+ /**
105
+ * Generate a human-readable representation of a value.
106
+ *
107
+ * @param value - Value to inspect
108
+ * @param key - The value's corresponding member name
109
+ * @param options - Additional settings for refining output
110
+ * @returns A string representation of `value`.
111
+ */
112
+ (value: any, key?: string | symbol, options?: InspectOptions): string;
113
+ }
114
+
115
+ /**
116
+ * Generate a human-readable representation of a value.
117
+ *
118
+ * @param value - Value to inspect
119
+ * @param key - The value's corresponding member name
120
+ * @param options - Additional settings for refining output
121
+ * @returns A string representation of `value`.
122
+ */
123
+ declare var inspect: InspectFunction;
@@ -0,0 +1,24 @@
1
+ declare module "quickjs:bytecode" {
2
+ /**
3
+ * Convert the module or script in the specified file into bytecode.
4
+ *
5
+ * When converted back to a value, it will be a function.
6
+ */
7
+ export function fromFile(
8
+ path: string,
9
+ options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
10
+ ): ArrayBuffer;
11
+
12
+ /**
13
+ * Convert the provided value into bytecode. Doesn't work with all values.
14
+ */
15
+ export function fromValue(
16
+ value: any,
17
+ options?: { byteSwap?: boolean }
18
+ ): ArrayBuffer;
19
+
20
+ /**
21
+ * Convert the provided bytecode into a value.
22
+ */
23
+ export function toValue(bytecode: ArrayBuffer): any;
24
+ }