Code Monkey home page Code Monkey logo

sjs's Introduction

sjs

Overview

Skookum JS, or sjs for short, is a JavaScript runtime focused on providing comprehensive POSIX APIs.

The motivation for this project comes from answering the question "how would a JavaScript runtime look like if there were no browsers?".

Features

  • Small footprint
  • Ecmascript ES5/ES5.1 compliant
  • Some post-ES5 features
  • Built-in Unicode support
  • Tail call support
  • CommonJS-based module loading system
  • Support for native modules written in C
  • Rich standard library
  • Binary name 25% shorter than Node

See the full list here.

Documentation

Check it out here.

Documentation Status

Building

Skookum JS currently supports Linux and macOS. See compilation instructions here.

Build Status

License

Check the LICENSE file.

Author

Saúl Ibarra Corretgé (@saghul)

Contributing

Please see CONTRIBUTING.

Acknowledgements

sjs would not have been possible without some other projects existing. Some served as a source of inspiration, some as a source of actual code, and the author would like to thank them all.

  • Duktape: The engine that powers sjs. This project would not have been possible without Duktape. :hearteyes:
  • Nodejs: World's most well known JavaScript runtime, definitely an inspiration.
  • libuv: A lot of the cross-platform code was borrowed from here.
  • Dukluv: Another JavaScript runtime combining Duktape with libuv.
  • CPython: Python's canonical interpreter was an inspiration, specially for the standard library components.

sjs's People

Contributors

joegen avatar saghul avatar tarkin000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sjs's Issues

modules: add atexit module

We will need a way to cleanly exit the interpreter instead of just doing exit. Probably use an exception SJSExit, VMExit or SystemExit to signal this, then capture it, run atexit handlers and call exit(code).

vm: separate JavaScript code compilation from execution

Right now we run them one after the other, but the original source code is no longer needed after we compile it to JavaScript, so we can free it.

This means that we also do more work before we actually run the code, so it might not be beneficial.

Consider switching to xoroshiro128+ for RNG

I recently switched from Mersenne Twister (MT19937) to xoroshiro128+ for random number generation in minisphere. It's about 4 times as fast as MT, generates 64-bit unsigned integers, is higher quality (i.e. passes more randomness tests), and is in the public domain. It's the successor to the xorshift128+ algorithm currently used by SpiderMonkey and V8:

The implementation I wrote for minisphere allows creating multiple generator instances as well as saving and restoring the state of the generator. Since the state is only 128-bit it can be represented as a single 32-character hex string that you can write to a file and read back later. MT19937 has nearly 2.5KB of state making it a bit unwieldy.

Here's my implementation if you want to look at it:

modules: add random module

Passwd module

A wrapper around these:

int getpwnam_r(const char *name, struct passwd *pwd,
            char *buf, size_t buflen, struct passwd **result);

int getpwuid_r(uid_t uid, struct passwd *pwd,
            char *buf, size_t buflen, struct passwd **result);

Also:

os.getuid / geteuid: http://man7.org/linux/man-pages/man2/getuid.2.html
os.setuid: http://man7.org/linux/man-pages/man2/setuid.2.html
os.setgid http://man7.org/linux/man-pages/man2/setgid.2.html

Then use these to add support for uid / gid in process.spawn.

Avoid opening /dev/urandom on every call to os.urandom

This only applies to systems which actually use /dev/urandom.

The idea is to open the fd once, store it in sjs_vm_t and keep it around. Every time we need to read from it do a fstat and check the inode still matches. (This trick is what CPython does)

modules: add fs module

The initial version should contain:

  • File object for reading / writing and so on
  • unlink
  • stat
  • scandir

vm: skip shebang when running a file

Since the shebang always needs to be the first line, we can probably get away with it by replacing the first two characters (assuming they are #!) with //. This way we don't alter the line count.

Add some examples

  • read name and print hello name
  • echo server (non-blocking)
  • mini-netcat
  • C module
  • JS module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.