7 ms·
XS7 – A compact JavaScript engine for embedded applications
- marktangotango 9y agoCan I create a secure sandbox? Users only have access to functions and objects i whitelist, I can set max allowed heap, limit stack, and limit number of opcodes (or whatever) executed?
- mrtksn 9y agoIs there a way to do that with anything else out there?
- lprader 9y agoYes, absolutely. XS just provides the basic built-in JavaScript objects (Date, RegExp, String, Number, etc.). Everything else is up to you (meaning the person who creates the virtual machine). And memory allocation can be static or dynamic, so you can control how much memory is available. In case you're interested, here's the doc that describes the C interface to the runtime of the XS JavaScript engine: https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/xs/XS%20in%20C.md https://github.com/Moddable-OpenSource/moddable/blob/public/...
- marktangotango 9y agoI didn’t see anything in that doc about limiting instructions executed, or throwing an error if some limit is reached. Did you mean to say that capability is included? Can you share a specific reference?
- phoddie 9y agoWe don't have a document that answers your question directly but the capabilities are all there. We're happy to help you get started - post an issue on our repository on GitHub. The "XS in C" describes the API you'll use from your C/C++ code to interact with XS (created a VM, implement native functions callable from JavaScript, etc). Most of the limits can be set using the manifest, which defines the virtual machine build. For example, to limit the memory used by a script or the modules available to a script (e.g. what classes and functions it can call), use the manifest's "creation" object which indicates the maximum number of bytes the VM can allocate. Here's the base manifest all our examples include, which define the VM size in the creation as 32 KB - https://github.com/Moddable-OpenSource/moddable/blob/public/examples/manifest_base.json https://github.com/Moddable-OpenSource/moddable/blob/public/.... The manifest also lists all the modules that are built into the virtual machine. These are the only modules a script can use (unless you add a module that can load other modules!). For example, manifest_net.json (https://github.com/Moddable-OpenSource/moddable/blob/public/examples/manifest_net.json https://github.com/Moddable-OpenSource/moddable/blob/public/...) includes a bunch of modules related to networking (socket, sntp, wifi).
- CharlesW 9y agoXS6's ECMAScript 6 compatibility: 95%[1] [1] https://kangax.github.io/compat-table/es6/#xs6 https://kangax.github.io/compat-table/es6/#xs6
- phoddie 9y agoBetter than that, XS today achieves over 99% compatibility on test262, the official JavaScript language test suite, for ECMAScript 2017 (the latest versin of the JavaScript language). That's over 50,000 tests. Details on the test results in our GitHub repository @ https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/xs/XS%20Conformance.md#results https://github.com/Moddable-OpenSource/moddable/blob/public/...
- CharlesW 9y agoCool, congratulations!
- positivecomment 9y agoThis is very cool. I hope one day someone creates a basic DOM for this with good CSS support and then we'd have the mini-electron. I hope that a very limited subset of the features of a browser (no downloads, tabs, networking, security contexts and everything else which would be irrelevant for desktop apps) can be implemented with few orders of magnitude less lines of code.
- rstat1 9y agoI'd hardly consider networking support to be irrelevant to a desktop app.
- positivecomment 9y agoI meant in the context of the GUI, then all data would be exchanged through the native bindings.
- lprader 9y agoYeah, that would be interesting. Right now the Moddable SDK comes with the Piu application framework, which has cascading styles, inspired by CSS. You can read all about that here: https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/piu/piu.md https://github.com/Moddable-OpenSource/moddable/blob/public/...
- dmitrygr 9y ago> security contexts and everything else which would be irrelevant for desktop apps I hope that was dark sarcasm, or that you do not write software. Security is never irrelevant! Never!
- scrollaway 9y agoThere's a lot of web browser security features which are only relevant when the code is untrusted, when assets are fetched over http/https instead of bundled locally, etc. GP is likely overestimating how much "bloat" could actually be dropped but your comment is uninformed.
- yazr 9y agothis + light-weight OSS browser = mini-electron ?! Any technical barriers to this ?
- mort96 9y agoWell, implementing all of HTML and CSS and the DOM in something light-weight might be difficult.
- Can_Not 9y agoPerhaps something like bindings for QT or GTK would be preferred.
- carussell 9y agoGTK already has JS bindings. If you're running Gnome, then substantial parts of what you're seeing and interacting with on your desktop is JS. The Gnome folks tried anointing JS as the de jure development language across the Gnome project (i.e., for apps, too) a few years back, but there was a minor backlash. Unfortunately, Electron came along within the next year or so has since snagged most of the mindshare that was up for grabs after they backpeddled a bit. You can write JS apps, but it's not a prominent park of the environment outside of Gnome Shell and extensions, AFAIK. The documentation is pretty lacking. GJS is SpiderMonkey under the hood—the same JS engine used in Firefox. It would be interesting to see if XS were an improvement for Gnome. Web browsers are subject to constraints that aren't necessarily a relevant factor for static packages downloaded from your distro vendor. For example, it looks like XS/Kinoma/Moddable supports AOT compilation, which could be a win. Metrics here look like they focus on RAM and not on speed of computation. On the softer side, GTK folks do favor C, and the explicit endorsement of (L)GPLv3 is worth brownie points in that circle. (SpiderMonkey is written in C++, and MPL2 is compatible with (L)GPL, but its copyleft is weaker and allows more permissive use.) In any case, this project is really neat. I only wish I'd heard about it back in 2015.
- Can_Not 9y ago
- moltensyntax 9y agoTessel (https://tessel.io/ https://tessel.io/) also runs JavaScript on embedded. It cleverly used Lua as an intermediate language.
- CharlesW 9y agoThat makes it sound they're running Lua on embedded. In that case, is the JS-to-Lua transpiling done on-device as well?
- drzaiusx11 9y agohow does this compare to espruino (which can run on 64kB RAM)? http://www.espruino.com/ http://www.espruino.com/
- lprader 9y agoA few things: - XS7 can run in as little as 32K RAM :) - Espruino follows the ES5 standard (released in 2009), whereas XS7 follows the ECMAScript 2017 standard. - The Espruino debugger is more like gdb, the XS7 debugger has a GUI. We have a couple of posts on our website with more information about XS7: http://blog.moddable.tech/blog/moddable-tech-presentation-to-tc-39/ http://blog.moddable.tech/blog/moddable-tech-presentation-to... http://www.moddable.com/XS7-TC-39 http://www.moddable.com/XS7-TC-39
- ricardobeat 9y agoAny benchmarks available? Would love to know how it compares to Duktape (http://duktape.org/ http://duktape.org/).
- lprader 9y agoWe can run our helloworld sample (https://github.com/Moddable-OpenSource/moddable/tree/public/examples/helloworld https://github.com/Moddable-OpenSource/moddable/tree/public/...) with the xsbug debugger attached in 6000 bytes of RAM on the ESP8266. 5456 bytes for the stack and heaps, 256 for the dynamic symbol table, and 288 for the alias array. With the 26KB RAM Duktape needs for "Hello world" we can run apps like the Sensor hub described in this blog post (run on a Thunderboard that only has 32KB of RAM total): http://blog.moddable.tech/blog/moddable-tech-presentation-to-tc-39/ http://blog.moddable.tech/blog/moddable-tech-presentation-to...
- svaarala 9y agoBy default Duktape maintains the built-in objects purely in RAM, but for low footprint targets the built-in objects (and also custom user objects) can be made pure ROM objects which reduces memory usage quite a bit; the lowest startup RAM usage is around 1,5kB, see https://github.com/svaarala/duktape/blob/master/doc/low-memory.rst https://github.com/svaarala/duktape/blob/master/doc/low-memo....
- gravypod 9y agoI though many of the options in duktape could be turned off to reduce the memory footprint.
- nerpderp83 9y agoJavaScriptCore is already running on WASM, https://github.com/mbbill/JSC.js https://github.com/mbbill/JSC.js so all you need is a WASM execution context and you get a great ECMAScript engine.
- abritinthebay 9y agoAre there any micro-controller style boards that run this (for example - something espruino-like)? Would be very interesting to play with in that context.
- carussell 9y agoLooks like this thing is derived from the work by Kinoma[1], who has/had a $25 micro with networking. The link to their retailer is dead, though. 1. http://kinoma.com/buy/ http://kinoma.com/buy/
- abritinthebay 9y agoYeah, but Kinoma is basically dead and all their products discontinued. It looks like there's nothing out-of-the-box but they do recommend ESP8266 based boards[1] on their site. Which is interesting as I thought that was just a wifi chip... edit - It does look like they're producing their own board[2] as a demo/hacking platform which is pretty great! 1. https://www.amazon.com/HiLetgo-Internet-Development-Wireless-Micropython/dp/B010O1G1ES/ref=sr_1_1_sspa https://www.amazon.com/HiLetgo-Internet-Development-Wireless... 2. http://www.moddable.com/moddable-zero.php http://www.moddable.com/moddable-zero.php
- phoddie 9y agoAny NodeMCU compatible ESP8266 board should work. Moddable Zero starts with a NodeMCU board and adds a color touch screen for $20 (and they are handmade to order in California). http://www.moddable.com/moddable-zero.php http://www.moddable.com/moddable-zero.php
- abritinthebay 9y agoI saw that just before you posted. Ordered one! Excited to try it out.
- megous 9y agoIs there some documentation on how to run code from a string in C. I guess I can setup a getter for a buffer and then call fxParseScript? Is that all?
- megous 9y agoAh, I found some nice example in fx_agent_start_aux() function. :)
- phoddie 9y agoFWIW - we usually don't parse scripts on the MCU because that takes time and memory. Instead, we compile on the development machine using xsc and link using xsl. This leaves more memory free for scripts to use for data, and allows scripts to start running almost instantly.
- megous 9y agoI understand, though I meant to use xs engine separately on bigger platforms, where this is not an issue.
- olouv 9y agoIs there a tutorial somewhere to get started with an ESP32? Is it a supported platform?
- phoddie 9y agoInstructions for building XS for ESP32 are in our GitHub repository. There are separate sections for building on macOS, Windows, and Linux. https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/Moddable%20SDK%20–%20Getting%20Started.md#esp32-setup https://github.com/Moddable-OpenSource/moddable/blob/public/...
- ithkuil 9y agoSimilar projects https://github.com/cesanta/v7 https://github.com/cesanta/v7 And https://github.com/cesanta/mjs https://github.com/cesanta/mjs