Convert Figma logo to code with AI

jerryscript-project logojerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.

6,913
669
6,913
198

Top Related Projects

1,850

Embedded JavaScript engine for C/C++

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

The Espruino JavaScript interpreter - Official Repo

Chez Scheme

Quick Overview

JerryScript is a lightweight JavaScript engine designed for resource-constrained devices, such as microcontrollers. It implements a subset of the ECMAScript 5.1 standard and can run on devices with as little as 64 KB of RAM and 200 KB of flash memory.

Pros

  • Extremely small footprint, suitable for IoT and embedded devices
  • Cross-platform compatibility, runs on various architectures
  • Modular design allows for easy customization and integration
  • Active development and community support

Cons

  • Limited JavaScript feature set compared to full-fledged engines
  • Performance may be slower than larger JavaScript engines
  • Not suitable for complex web applications or heavy computations
  • Learning curve for embedded developers unfamiliar with JavaScript

Code Examples

  1. Hello World example:
#include "jerryscript.h"

int main (void)
{
  const jerry_char_t script[] = "print('Hello, World!');";
  
  jerry_init (JERRY_INIT_EMPTY);
  jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
  jerry_cleanup ();
  
  return 0;
}
  1. Creating and using JavaScript objects:
#include "jerryscript.h"

int main (void)
{
  jerry_init (JERRY_INIT_EMPTY);
  
  jerry_value_t object = jerry_create_object ();
  jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "myProperty");
  jerry_value_t prop_value = jerry_create_number (42);
  
  jerry_set_property (object, prop_name, prop_value);
  
  jerry_release_value (prop_name);
  jerry_release_value (prop_value);
  jerry_release_value (object);
  
  jerry_cleanup ();
  
  return 0;
}
  1. Calling JavaScript functions from C:
#include "jerryscript.h"

int main (void)
{
  jerry_init (JERRY_INIT_EMPTY);
  
  const jerry_char_t script[] = "function add(a, b) { return a + b; }";
  jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
  
  jerry_value_t global = jerry_get_global_object ();
  jerry_value_t func_name = jerry_create_string ((const jerry_char_t *) "add");
  jerry_value_t func = jerry_get_property (global, func_name);
  
  jerry_value_t args[2];
  args[0] = jerry_create_number (5);
  args[1] = jerry_create_number (3);
  
  jerry_value_t result = jerry_call_function (func, jerry_create_undefined (), args, 2);
  
  double num = jerry_get_number_value (result);
  printf("Result: %f\n", num);
  
  jerry_release_value (result);
  jerry_release_value (args[1]);
  jerry_release_value (args[0]);
  jerry_release_value (func);
  jerry_release_value (func_name);
  jerry_release_value (global);
  
  jerry_cleanup ();
  
  return 0;
}

Getting Started

  1. Clone the JerryScript repository:

    git clone https://github.com/jerryscript-project/jerryscript.git
    
  2. Build JerryScript:

    cd jerryscript
    python tools/build.py
    
  3. Run the shell example:

    build/bin/jerry
    
  4. To use JerryScript in your project, include the necessary headers and link against the built library. Refer to the documentation for detailed integration instructions.

Competitor Comparisons

1,850

Embedded JavaScript engine for C/C++

Pros of mjs

  • Smaller footprint and lower memory usage
  • Simpler codebase, easier to understand and modify
  • Better suited for resource-constrained embedded systems

Cons of mjs

  • Less feature-rich compared to JerryScript
  • Smaller community and fewer resources available
  • Limited compatibility with existing JavaScript libraries

Code Comparison

mjs:

void mjs_init(struct mjs *mjs) {
  memset(mjs, 0, sizeof(*mjs));
  mjs->stack.len = 0;
  mjs->stack.size = 8;
  mjs->stack.buf = calloc(1, mjs->stack.size);
}

JerryScript:

jerry_init_t init_flags = JERRY_INIT_EMPTY;
jerry_context_t *context_p = jerry_create_context(init_flags, NULL);
jerry_value_t global_obj_val = jerry_get_global_object();
jerry_release_value(global_obj_val);

Both projects aim to provide JavaScript engines for embedded systems, but mjs focuses on simplicity and minimal resource usage, while JerryScript offers a more comprehensive implementation with broader compatibility. mjs is better suited for extremely resource-constrained environments, while JerryScript provides a more feature-rich experience at the cost of increased complexity and resource requirements.

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of MicroPython

  • More comprehensive standard library, closer to CPython
  • Supports a wider range of microcontrollers and embedded systems
  • Active community with frequent updates and contributions

Cons of MicroPython

  • Larger memory footprint compared to JerryScript
  • Slower execution speed for certain operations
  • Less focus on JavaScript compatibility

Code Comparison

MicroPython:

import machine
import time

led = machine.Pin(2, machine.Pin.OUT)
while True:
    led.toggle()
    time.sleep(1)

JerryScript:

var led = Pin(2, Pin.OUT);
setInterval(function() {
  led.toggle();
}, 1000);

Both examples demonstrate LED blinking, but MicroPython uses Python syntax and built-in modules, while JerryScript uses JavaScript with a hypothetical Pin API. MicroPython's approach is more familiar to Python developers, while JerryScript caters to those preferring JavaScript for embedded development.

JerryScript focuses on providing a lightweight JavaScript engine for resource-constrained devices, while MicroPython aims to bring a more complete Python implementation to microcontrollers. The choice between them depends on factors such as target hardware, preferred language, and specific project requirements.

The Espruino JavaScript interpreter - Official Repo

Pros of Espruino

  • Designed specifically for microcontrollers, offering better optimization for low-resource environments
  • Includes a Web IDE for easy development and flashing of devices
  • Provides a comprehensive set of built-in modules for hardware interaction

Cons of Espruino

  • Less flexible for general-purpose JavaScript applications
  • Smaller community and ecosystem compared to JerryScript
  • More focused on specific hardware platforms, potentially limiting portability

Code Comparison

Espruino:

var led = LED1;
setInterval(function() {
  led.toggle();
}, 500);

JerryScript:

var pin = 13;
setInterval(function() {
  digitalWrite(pin, !digitalRead(pin));
}, 500);

Both examples demonstrate LED blinking, but Espruino's API is more abstracted and tailored for its specific hardware, while JerryScript uses a more generic approach that might require additional setup or libraries depending on the platform.

Espruino is optimized for quick prototyping and ease of use on supported microcontrollers, whereas JerryScript offers more flexibility and can be integrated into a wider range of projects and platforms. The choice between them depends on the specific requirements of your project and the target hardware.

Chez Scheme

Pros of ChezScheme

  • Highly optimized Scheme implementation with a focus on performance
  • Supports both interpreted and compiled execution modes
  • Extensive standard library and documentation

Cons of ChezScheme

  • Larger footprint and resource requirements compared to JerryScript
  • Less suitable for embedded or resource-constrained environments
  • Steeper learning curve for developers new to Scheme

Code Comparison

ChezScheme:

(define (factorial n)
  (if (= n 0)
      1
      (* n (factorial (- n 1)))))

JerryScript:

function factorial(n) {
  return n === 0 ? 1 : n * factorial(n - 1);
}

Summary

ChezScheme is a powerful Scheme implementation designed for performance and flexibility, while JerryScript is a lightweight JavaScript engine for resource-constrained devices. ChezScheme offers more advanced features and a comprehensive standard library, making it suitable for complex applications. JerryScript, on the other hand, excels in embedded systems and IoT devices due to its small footprint and low memory requirements.

The code comparison demonstrates the syntactical differences between Scheme and JavaScript, with ChezScheme using a more functional style and JerryScript following JavaScript conventions. Both implementations achieve the same result, but ChezScheme's syntax may be less familiar to developers accustomed to C-style languages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

JerryScript: JavaScript engine for the Internet of Things

License GitHub Actions Status AppVeyor Build Status FOSSA Status IRC Channel

JerryScript is a lightweight JavaScript engine for resource-constrained devices such as microcontrollers. It can run on devices with less than 64 KB of RAM and less than 200 KB of flash memory.

Key characteristics of JerryScript:

  • Full ECMAScript 5.1 standard compliance
  • 160K binary size when compiled for ARM Thumb-2
  • Heavily optimized for low memory consumption
  • Written in C99 for maximum portability
  • Snapshot support for precompiling JavaScript source code to byte code
  • Mature C API, easy to embed in applications

Additional information can be found on our project page and Wiki.

Memory usage and Binary footprint are measured at here with real target daily.

The latest results on Raspberry Pi 2:

Remote Testrunner

IRC channel: #jerryscript on freenode Mailing list: jerryscript-dev@groups.io, you can subscribe here and access the mailing list archive here.

Quick Start

Getting the sources

git clone https://github.com/jerryscript-project/jerryscript.git
cd jerryscript

Building JerryScript

python tools/build.py

For additional information see Getting Started.

Documentation

Contributing

The project can only accept contributions which are licensed under the Apache License 2.0 and are signed according to the JerryScript Developer's Certificate of Origin. For further information please see our Contribution Guidelines.

License

JerryScript is open source software under the Apache License 2.0. Complete license and copyright information can be found in the source code.

FOSSA Status

Copyright JS Foundation and other contributors, http://js.foundation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.