33

I need an extremely tiny implementation of (maybe a subset of?) Javascript. Code size and memory usage are extremely important (speed isn't in the question, it can run as slow as it likes). It must be written in C (not C++), and that too, ANSI C (GCC extensions are okay). If it runs on a VM would be best, because I will have to write a compiler for it. Any suggestions?

EDIT: Both of the responses I have seem good, except:

SpiderMonkey concentrates a lot on making it faster, I don't care if its fast at all.
Quad-Wheel sounds good, except the activity on it, and code comments are few (I will be porting this to another architecture if that helps).

So, any other responses would be great. Or, I could roll out my own simplified version of JS (but that doesn't sound fun at all)

6
  • 1
    It might help if we know what your use case is. An embedded controller, perhaps? Commented Mar 21, 2011 at 23:02
  • Must you use Javascript? For example, there are a wide variety of implementations of Scheme (or even Forth) that are small and perhaps well suited for your application. Commented Mar 21, 2011 at 23:24
  • 1
    If you don't have to use Javascript, try Lua.
    – lhf
    Commented Mar 22, 2011 at 0:51
  • There already exists eLua. I would like to create my own :) Scheme sounds good, and, it would be very easy to write an interpreter for. Commented Mar 22, 2011 at 1:59
  • It is not clear why this is tagged embedded.
    – Clifford
    Commented Mar 22, 2011 at 18:55

11 Answers 11

23

Duktape is written in C, with a focus on portability and compact footprint: http://duktape.org/

2
  • 2
    Compared to some of the alternatives, Duktape's documentation is excellent. I'm moving from muJS to Duktape for that very reason.
    – CyberFonic
    Commented Dec 5, 2014 at 22:05
  • 1
    What is the RAM footprint of Ducktape? I can't find any documentation on that. I know that Espurino can start in as little as 8K
    – JockM
    Commented Mar 14, 2018 at 22:14
14

I just discovered this ruby: https://github.com/gfwilliams/tiny-js

I've been looking quite some time for this, since spidermonkey/v8 usually is pretty big and comes with several dependancies. Tiny-js is a portable 'run make and your done'-linux c-class. Perfectly for if you are only looking for simple bindings and prefer javascript/c-syntax over lua/other awesome scriptinglanguages.

4
  • +1 and accept. This is pretty awesome. Sorry for the response being a year and a half late. Commented Feb 12, 2013 at 0:23
  • 2
    tiny-js is in C++ not C as you expected.
    – rahulg
    Commented Feb 12, 2013 at 9:27
  • It seems that tiny-js is effectively unmaintained. No commits since July 2013. Commented Sep 24, 2014 at 5:20
  • 1
    It would appear that Duktape (@Samuli Kärkkäinen, below) is a more up to the moment alternative. Since it implementants ECMA standards it better conforms to the principles of "object based" implementations.
    – CyberFonic
    Commented Dec 5, 2014 at 22:08
4

An ANSI-C engine for ECMA-262: http://code.google.com/p/quad-wheel/

Mozilla SpiderMonkey is written in C as well, but probably to complex and large for you?

2

SpiderMonkey is Mozilla's C implementation of JavaScript.

http://www.mozilla.org/js/spidermonkey/

2

muJS from Artifex Software might be another option for embedded JS/ES implementation.

1

You should look at Jsi, which was just released. It is very small, is a subset of javascript, and is in C (derived from quadwheel).

2
  • 9
    Could you provide a pointer to "jsi"? I can't find "Jsi" anywhere, or anything that points from quadwheel (quad-wheel?) to Jsi.
    – Pekka
    Commented May 8, 2014 at 1:38
  • @Pekka Perhaps github.com/pcmacdon/jsish
    – tekknolagi
    Commented Aug 16, 2022 at 9:25
0

I think the jsi he's talking about is this: http://pdqi.com/cgi-bin/cgiwrap/pdqi/jsi.cgi/doc/tip/jsi/www/usingjsi.wiki

(Don't blame it is not... hehe)

0

http://jsish.org will redirect you to the host site.

1
  • 1
    Welcome to Stack Overflow! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Commented Jun 13, 2016 at 19:56
0

https://github.com/cesanta/v7 is designed for embedded systems. Has very small footprint.

0

Have you looked at JerryScript?

0

If you are completely expect a full Node.js runtime at embeddable, ShadowNode might be a good for you.

https://github.com/Rokid/ShadowNode

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.