Duktape is an embeddable JavaScript engine
duktape.org
duktape.org
It's not actually smaller; Duktape is about 4MB source files while QuickJS is about 2.7 MB. But Duktape has a nice C API similar to Lua. And QuickJS requires a recent C compiler whereas Duktape is happy with C89.
For any C library this is HEAVILY dependent on the compiler, compilation, and linking options used.
I’ve spent quite some time recently wrangling Unicode tables, so a quick note: unless you consciously go for performance over size (e.g. the Windows SBCS code pages use a 65536-entry lookup table for encoding, each), Unicode property tables are not that large.
With general category, a basic[1] set of properties, and canonical normalization, you can get away with about 30K for the whole lot without much of a problem, and probably less than that if you use a sorted inversion list instead of a trie for binary properties (both Plan 9 / libutf and Duktape do this IIRC, while QuickJS does something trickier I haven’t grokked yet, but it’s obviously not trying to be a speed demon there either).
Compatibility decompositions are more problematic (so. many. ideographs), I’m still at 20K for those, and I expect default casing and case folding will cost about that much as well. Maybe you also want some other properties (breaks? bidi class? script?). So let’s say 60K at best, 90K at worst, total.
Overall, a considerable but not catastrophic contribution to Duktape’s 330K (as quoted in your link) and even less of a problem for QuickJS’s 620K. And that is for tables that you can run against—if you’re willing to sacrifice runtime memory consumption for disk / wire size, you can do substantially better[2].
(These were rough estimates from experience. The actual figure for QuickJS turns out to be 37K, so I was a bit too pessimistic; I can’t compile Duktape right now, but it’s probably smaller given it can’t even normalize[3].)
Character names, collation, or locales / tailoring would multiply the size severalfold, but I think none of the small engines here do any of that (although an engine that wanted ECMA-402 internationalization would need all of it and more).
[1] https://www.unicode.org/reports/tr18/#RL1.2
[2] https://devlog.hexops.com/2021/unicode-data-file-compression...
Like Lua in games etc.
(Genuine question; I'm not an iOS developer.)
It's scary to think that Poettering's Linux desktop is built around SpiderMonkey serving as the gatekeeper between users and root.
Fortunately Debian's conservatism has kept them on policykit, which avoids this nonsense.
I maintain a library for using QuickJS, a JS interpreter with more modern language support, from NodeJS or the web called QuickJS-Emscripten: https://github.com/justjake/quickjs-emscripten
This was inspired by seeing Duktape WASM build on HN (https://github.com/maple3142/duktape-eval) and Figma's blogposts about building a Javascript plugin runtime:
- How Figma built the Figma plugin system: Describes the LowLevelJavascriptVm interface (https://www.figma.com/blog/how-we-built-the-figma-plugin-sys...)
- An update on plugin security: Figma switches to QuickJS (https://www.figma.com/blog/an-update-on-plugin-security/)
How to build a plugin system on the web and also sleep well at night - https://www.figma.com/blog/how-we-built-the-figma-plugin-sys...
An update on plugin security - https://www.figma.com/blog/an-update-on-plugin-security/
It will be useful to have variants of loadFile and some other functions that currently deal only with UTF-8 strings:
[1] UTF-8
[2] ISO-8859-1
[3] ArrayBuffer
Currently, only urlGet has a variant using ArrayBuffer, although it would be useful to allow that for loadFile too, to avoid having to open and measure and close the file to do it by yourself.
Additionally, urlGet lacks some of the options of curl (such as whether or not to follow redirects).
Typed arrays may also be necessary for command-line arguments and environment variables and file names in some cases, where they might not be valid UTF-8 (it is not guaranteed that they will be; this depends on the file system in use, though, since some are always Unicode; however, some allow mismatched surrogates so this must also be permitted). (Node.js allows this for file names, but it seems not for command-line arguments and environment variables.) Additionally, the locale might or might not be Unicode, but even if it is, that does not necessarily mean that the other things are. Assuming that everything is UTF-8 is an invalid assumption (it might not even be text in any encoding at all; it might even be null-terminated binary data), and programs that deal with Unicode often incorrectly ignore the locale.