Embedded JavaScript engine for C/C++

Related tags

Scripting v7
Overview

V7: Embedded JavaScript engine

NOTE: this project is deprecated in favor of https://github.com/cesanta/mjs

License

V7 is the smallest JavaScript engine written in C. V7 features are:

  • Cross-platform: works on anything, starting from Arduino to MS Windows
  • Small size. Compiled static size is in 40k - 120k range, RAM footprint on initialization is about 800 bytes with freeze feature, 15k without freeze feature
  • Simple and intuitive C/C++ API. It is easy to export existing C/C++ functions into JavaScript environment
  • Standard: V7 implements JavaScript 5.1
  • Usable out-of-the-box: V7 provides an auxiliary library with Hardware (SPI, UART, etc), File, Crypto, Network API
  • Source code is both ISO C and ISO C++ compliant
  • Very easy to integrate: simply copy two files: v7.h and v7.c into your project

V7 makes it possible to program Internet of Things (IoT) embedded devices in JavaScript. V7 is a part of the full stack Mongoose OS Platform.

Examples & Documentation

Contributions

To submit contributions, sign Cesanta CLA and send GitHub pull request. You retain the copyright on your contributions.

Licensing

V7 is released under commercial and GNU GPL v.2 open source licenses.

Commercial Projects: Once your project becomes commercialised GPLv2 licensing dictates that you need to either open your source fully or purchase a commercial license. Cesanta offer full, royalty-free commercial licenses without any GPL restrictions. If your needs require a custom license, we’d be happy to work on a solution with you. [Contact us for pricing.] (https://www.cesanta.com/contact)

Prototyping: While your project is still in prototyping stage and not for sale, you can use V7’s open source code without license restrictions.

Issues
  • V7 ScriptBASIC integration on Windows 7 32 bit

    V7 ScriptBASIC integration on Windows 7 32 bit

    I compiled my V7 extension module for Script BASIC under Windows 7 32 bit OS using TDM-GCC32 and I can't seem to return a pointer to a requested JavaScript variable even thought the return code says success.

    Is there any docs on compiling for Windows?

    opened by ScriptBasic 41
  • v7 tagged pointers vs Obj-C tagged pointers

    v7 tagged pointers vs Obj-C tagged pointers

    On 64 bits platforms, Obj-C uses tagged pointers to store numbers for instance - see https://www.mikeash.com/pyblog/friday-qa-2012-07-27-lets-build-tagged-pointers.html.

    v7 also uses tag pointers.

    If using v7_create_foreign() to wrap an Obj-C object that happens to be a tagged pointer, could there be any issue? Did you guys test this case?

    opened by swisspol 15
  • Implement low level Socket interface

    Implement low level Socket interface

    Sorry for PR size. In order to replace exceptions with retvals I had to make a little refactoring and as result PR contains a lot of small changes.

    Review on Reviewable

    opened by alashkin 14
  • Can't call js function from C

    Can't call js function from C

    Hey,

    I'm trying to call a function from my JavaScript file in my C code.

    I used the code from the example to get started https://github.com/cesanta/v7/blob/master/examples/call_js_from_c/call_js_from_c.c

    However, I don't get it working and it always shows that error print.

    My code:

    static void OnUpdate(struct v7 *v7) {
    	v7_val_t func, result, args;
    
    	/* Lookup JavaScript function `sum()` */
    	func = v7_get(v7, v7_get_global(v7), "Update", 6);
    
    	/* Create arguments array with two numbers */
    	args = v7_mk_null();
    
    	/* Call JavaScript function. Pass `undefined` as `this` */
    	if (v7_apply(v7, func, V7_UNDEFINED, args, &result) == V7_OK) {
    		printf("Result: %g\n", v7_get_double(v7, result));
    	}
    	else {
    		v7_print_error(stderr, v7, "Error while calling sum", result);
    	}
    }
    
    ...
    
    while(1)
    {
     OnUpdate(state);
    }
    
    

    My js file:

    function Update() {
     print("mooo!");
    }
    

    Hope somebody can help me here :)

    opened by Memorix101 13
  • Warn when trying to parse a large script

    Warn when trying to parse a large script

    Refs https://github.com/cesanta/v7/issues/494

    It would be nice to warn a user about large script because I had to spend time trying to figure out what was happening :(

    I put the code here because I saw another warning. Ideally this check should be done in ast_modify_skip, but there is a performance trade off to do so.

    I'm not sure if I should make another v7_err value (maybe V7_AST_TOO_LARGE), which seems more sensible approach.

    Review on Reviewable

    opened by edvakf 12
  • `v7_to_json` does not allocate a larger buffer if needed because `to_str` reports only number of bytes written, no number of bytes needed

    `v7_to_json` does not allocate a larger buffer if needed because `to_str` reports only number of bytes written, no number of bytes needed

    v7 -e "eval('print(111111111111111111111111); print(2222222222222222222222);')" 1.11111111111111109247e+023 2.22222222222222216397e+021 null

    v7 -e "eval('print(111111111111111111111111); print(2222222222222222222222); print(333333333333333333333333333);')" Exec error [eval('print(111111111111111111111111); print(2222222222222222222222); print(333333333333333333333333333);')]: {"message":"parse error at at line 1 col 99: [ print(111111111111111111"} undefined

    p2 
    opened by vrz 12
  • Is it possible to install a callback on object for unresolved properties?

    Is it possible to install a callback on object for unresolved properties?

    (sorry more of question than an issue, but I didn't see a v7 tag in Stack Overflow)

    Unless I missed it, it's not possible to do something like this so that a C function would get called back on a JS object whenever JavaScript attempts to access a non-existing property. Such a functionality would allow for more elegant bindings with other languages:

    Before:

    var foo = CreateNativeObject("some_class", "some_constructor", arg1, arg2...);
    CallNativeObjectMethod(foo, "some_method", arg1, arg2...);
    

    After:

    var bar = GetNativeClass("some_class");
    var foo = bar.some_constructor(arg1, arg2...) <--- unresolved property callback fires to return JS function wrapping C function
    foo.some_method(arg1, arg2...) <--- unresolved property callback fires to return JS function wrapping C function
    
    opened by swisspol 11
  • Sockets: init, ctor, close() and bind()

    Sockets: init, ctor, close() and bind()

    Hi, @mmikulicic In order to keep reasonable size of PR I've created this one with socket basics. It contain only initialization, ctor, close and bind (bind - as first fucntion)

    Please, make review for me. Pay attention on:

    1. Usage of v7_create_foreign
    2. Creation of "namespaces" constants (Type.SOCK_STREAM) - lines 182-204

    Thank you.

    Review on Reviewable

    opened by alashkin 11
  • /x*/ regexp should match an empty substring

    /x*/ regexp should match an empty substring

    With node:

    console.log("should match empty string at index 0".match(/x*/))
    
    [ '', index: 0, input: 'should match empty string at index 0' ]
    

    With v7:

    print("should match empty string at index 0".match(/x*/))
    

    yields

    null
    
    bug 
    opened by mkmik 11
  • v7_next_prop - No property attributes being returned

    v7_next_prop - No property attributes being returned

    I'm unable to return any property attributes with the v7_next_prop() function. Always returns a zero.

    BTW: The Docs for this function are wrong and had to refer to the v7.h file for the correct use.

    void v7_destruct_prop_iter_ctx(struct v7 *v7, struct prop_iter_ctx *ctx);
    
    /*
     * Iterate over the `obj`'s properties.
     *
     * Usage example (here we assume we have some `v7_val_t obj`):
     *
     *     struct prop_iter_ctx ctx;
     *     v7_val_t name, val;
     *     v7_prop_attr_t attrs;
     *
     *     v7_init_prop_iter_ctx(v7, obj, &ctx);
     *     while (v7_next_prop(v7, &ctx, &name, &val, &attrs)) {
     *       ...
     *     }
     *     v7_destruct_prop_iter_ctx(v7, &ctx);
     */
    int v7_next_prop(struct v7 *v7, struct prop_iter_ctx *ctx, v7_val_t *name,
                     v7_val_t *value, v7_prop_attr_t *attrs);
    
    opened by ScriptBasic 10
  • build problems on windows

    build problems on windows

    make.exe v7

    "grep" не является внутренней или внешней командой, исполняемой программой или пакетным файлом. "GENERATING src/features_full.h" "perl" не является внутренней или внешней командой, исполняемой программой или пакетным файлом. make.exe: *** [src/features_full.h] Error 1

    opened by vrz 10
  •  JSON.parse error

    JSON.parse error

    var strJSon='{"sex":"\u00e7\u0094\u00b7"}'; print(strJSon); var obj = JSON.parse(strJSon); print(JSON.stringify(obj));

    {"sex":"\u00e7\u0094\u00b7"} {"sex":"\u00c3\u00a7\u00c2\u0094\u00c2\u00b7"}

    opened by wangwolue 0
  • Linker errors: Undefined symbols for architecture x86_64

    Linker errors: Undefined symbols for architecture x86_64

    I am unable to compile the v7 binary provided in the makefile and i am observing linker errors.

    Undefined symbols for architecture x86_64: "_mg_mk_str", referenced from: _mg_next_comma_list_entry in v7-fb9d22.o _mg_next_comma_list_entry_n in v7-fb9d22.o "_mg_mk_str_n", referenced from: _mg_next_comma_list_entry_n in v7-fb9d22.o "_mg_strchr", referenced from: _mg_next_comma_list_entry_n in v7-fb9d22.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [v7] Error 1

    opened by syedkhalid 0
  • Developer Centre down?

    Developer Centre down?

    https://docs.cesanta.com/v7/dev

    This link seems to be broken. It'd be nice to have that fixed, as I don't seem to find any other way of finding out how I could implement require or even import.

    Thanks!

    opened by IngwiePhoenix 0
  • v7_array_length issue

    v7_array_length issue

    include <stdio.h> #include "v7.h"

    int main(void) { struct v7* v7 = v7_create(); v7_val_t a = v7_mk_array(v7);

    v7_array_push(v7, a, v7_mk_number(v7, 0));
    v7_array_push(v7, a, v7_mk_number(v7, 1));
    v7_array_push(v7, a, v7_mk_number(v7, 2));
    printf("%d\n", v7_array_length(v7, a));
    
    v7_array_del(v7, a, 0);
    printf("%d\n", v7_array_length(v7, a));
    
    v7_destroy(v7);
    return 0;
    

    }

    the output is: 3 3 if I change v7_array_del(v7, a, 0); to v7_array_del(v7, a, 2); the output is: 3 2

    it seems that only the last entry can be deleted

    opened by biyuexiug 1
  • Trouble passing

    Trouble passing "true", "false" and "null"

    Some values can't be passed directly to a function.

    I was trying to pass true as the first argument to a function, but it got turned into undefined. From what I've seen this happens with false and null as well.

    Check the below example and its output (from running ./v7 file.js), written in the comments:

    'use strict'
    
    function fn(a, b) { print("a: " + a + ", b: " + b) }
    
    fn(3, 2) // a: 3, b: 2 
    fn(true) // a: undefined, b: undefined 
    fn(true, true) // a: true, b: undefined 
    fn(true, "foo") // a: true, b: foo 
    

    If instead you put the true value in a variable and pass it through that variable, everything works well.

    print('-- from a variable')
    var trueVar = true
    
    fn(trueVar) // a: true, b: undefined 
    fn(trueVar, trueVar) // a: true, b: true 
    fn(trueVar, "foo") // a: true, b: foo 
    

    Everything works if true is generated from any expression as well.

    I compiled the latest master (as of today) of v7 with the following command:

    gcc -O0 -DV7_EXE -DV7_ENABLE_STACK_TRACKING -DV7_ENABLE_FILE v7.c -lm

    But even when keeping only -DV7_EXE I can still reproduce this issue.

    opened by fabiosantoscode 3
Releases(3.0)
  • 3.0(May 19, 2016)

    • Error reporting improved significantly:
      • Added complete stack traces, with filenames and line numbers
      • When non-callable value is called, v7 gives some context instead of plain "value is not a function"
    • All build flags are documented
    • C API changed:
      • Getting C entities from JS values (v7_val_t):
      • v7_to_number() -> v7_get_double()
      • v7_to_boolean() -> v7_get_bool()
      • v7_to_cstring() -> v7_get_cstring()
      • v7_get_string_data() -> v7_get_string()
      • v7_to_foreign() -> v7_get_ptr()
      • These functions now take the v7 argument:
        • v7_mk_number()
        • v7_get_double()
        • v7_mk_boolean()
        • v7_get_bool()
        • v7_mk_foreign()
        • v7_get_ptr()
      • Added v7_get_int()
      • v7_mk_undefined() is deprecated, use the macro V7_UNDEFINED instead
      • v7_mk_null() is deprecated, use the macro V7_NULL instead
    • Added MSP432 CCS projects for v7 examples
    • Implemented v7 user data and destructors
    • Implemented Object.isFrozen() and Object.isSealed()
    • Bug fixes and refactoring
    Source code(tar.gz)
    Source code(zip)
  • 2.0(Mar 8, 2016)

    • Parser's stack usage does not grow as expression nesting grows, it allows v7 to run in stack-constrained environment;
    • Interpreter is reimplemented completely: instead of AST-based VM runtime with long jumps, the bytecode is generated and then evaluated. Again, it allowed to get rid of deep stack usage and make the whole runtime more straightforward;
    • Freezing: the ability to take a snapshot of v7's RAM usage, and then put that snapshot in flash instead. This way, the whole standard library can reside in flash, therefore saving several kilobytes of RAM, which is very expensive on embedded devices;
    • The ability to run from unmanaged (typically, mmap-ed) memory. This way, scripts can be precompiled, put in flash, and run straight from there. Again, it saves RAM;
    • API is cleaned up;
    • Lots of bugfixes and stability improvements.
    Source code(tar.gz)
    Source code(zip)
  • 1.0(Apr 27, 2015)

    • Implemented hand-written tokenizer and parser
    • Implemented AST-based VM runtime
    • Implemented mark-and-sweep garbage collector
    • Published examples
    • Published documentation with API reference
    • Standard Library is partially implemented. Unimplemented API:
      • global: decodeURI(), decodeURIComponent()
      • Object: seal(), freeze(), isSealed(), isFrozen()
      • Function: bind()
      • Array: concat(), unshift(), forEach(), reduceRight()
      • JSON: replacer argument in stringify() is ignored
    • Auxiliary library is not implemented yet
    Source code(tar.gz)
    Source code(zip)
Owner
Cesanta Software
Embedded Communication
Cesanta Software
ChakraCore is an open source Javascript engine with a C API.

ChakraCore ChakraCore is a Javascript engine with a C API you can use to add support for Javascript to any C or C compatible project. It can be compil

null 8.7k Jun 20, 2022
:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:

Quick start | Requirements | Features | User guide | Contributing | License nbind is a set of headers that make your C++11 library accessible from Jav

charto 1.9k Jun 20, 2022
Structy is an irresponsibly dumb and simple struct serialization/deserialization library for C, Python, and vanilla JavaScript.

Structy Structy is an irresponsibly dumb and simple struct serialization/deserialization library for C, Python, and vanilla JavaScript. You can think

Stargirl Flowers 47 Jun 19, 2022
Embedded Scripting Language Designed for C++

Master Status: Develop Status: ChaiScript http://www.chaiscript.com (c) 2009-2012 Jonathan Turner (c) 2009-2017 Jason Turner Release under the BSD lic

ChaiScript 2.5k Jun 28, 2022
Embedded JavaScript engine for C/C++

mJS: Restricted JavaScript engine Overview mJS is designed for microcontrollers with limited resources. Main design goals are: small footprint and sim

Cesanta Software 1.6k Jun 24, 2022
The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript

The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript

null 2.7k Jun 19, 2022
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 8.5k Jun 29, 2022
A place to collaborate on code for the Embedded.fm book club. Currently reading "STM32 ARM Programming for Embedded Systems".

Welcome to the Book Club Code site! This is a place for the Embedded.fm book club to collaborate and learn together. Repo Structure Guide Top-level fo

Peter Griffin 10 Jan 13, 2022
Embedded Flutter runtime targeting Embedded Linux with Wayland

ivi-homescreen IVI Homescreen for Wayland Strongly Typed (C++) Lightweight Clang 11 Release Stripped = 151k GCC 9.3 Release Stripped = 168k Source run

null 148 Jun 17, 2022
Lab2: using a physical embedded systems to interact with virtual embedded systems.

Lab2: dotDevice EmSys Autumn 2021 In this lab you will use your TinyPico to interact with a virtual embedded system. Current Virtual Lab URL: [http://

Shane Fleming 1 Oct 20, 2021
Duktape - embeddable Javascript engine with a focus on portability and compact footprint

Duktape ⚠️ Master branch is undergoing incompatible changes for Duktape 3.x. To track Duktape 2.x, follow the v2-maintenance branch. Introduction Dukt

Sami Vaarala 5.3k Jun 23, 2022
ChakraCore is an open source Javascript engine with a C API.

ChakraCore ChakraCore is a Javascript engine with a C API you can use to add support for Javascript to any C or C compatible project. It can be compil

null 8.7k Jun 20, 2022
Elk is a tiny embeddable JavaScript engine that implements a small but usable subset of ES6

Elk is a tiny embeddable JavaScript engine that implements a small but usable subset of ES6. It is designed for microcontroller development. Instead of writing firmware code in C/C++, Elk allows to develop in JavaScript. Another use case is providing customers with a secure, protected scripting environment for product customisation.

Cesanta Software 1.4k Jun 27, 2022
Android Bindings for QuickJS, A fine little javascript engine.

quickjs-android quickjs-android 是 QuickJS JavaScript 引擎的 Android 接口框架,整体基于面向对象设计,提供了自动GC功能,使用简单。armeabi-v7a 的大小仅 350KB,是 Google V8 不错的替代品,启动速度比 V8 快,内

Wiki 91 Jun 9, 2022
Header-only ECMAScript (JavaScript) compatible regular expression engine

SRELL (std::regex-like library) is a regular expression template library for C++ and has native support for UTF-8, UTF-16, and UTF-32. This is up-to-d

Dmitry Atamanov 4 Mar 11, 2022
JerryScript: JavaScript engine for the Internet of Things

JerryScript: JavaScript engine for the Internet of Things JerryScript is a lightweight JavaScript engine for resource-constrained devices such as micr

Arm Mbed 6 Sep 18, 2019
ESE is an embedded / ISAM-based database engine, that provides rudimentary table and indexed access.

Extensible-Storage-Engine A Non-SQL Database Engine The Extensible Storage Engine (ESE) is one of those rare codebases having proven to have a more th

Microsoft 780 Jun 13, 2022
A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support.

Libonnx A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support. Getting Started The library's

xboot.org 400 Jun 27, 2022
DeepSpeech is an open source embedded (offline, on-device) speech-to-text engine which can run in real time on devices ranging from a Raspberry Pi 4 to high power GPU servers.

Project DeepSpeech DeepSpeech is an open-source Speech-To-Text engine, using a model trained by machine learning techniques based on Baidu's Deep Spee

Mozilla 19.8k Jun 28, 2022
A very fast lightweight embedded database engine with a built-in query language.

upscaledb 2.2.1 Fr 10. Mär 21:33:03 CET 2017 (C) Christoph Rupp, [email protected]; http://www.upscaledb.com This is t

Christoph Rupp 531 Jun 20, 2022
An Embedded NoSQL, Transactional Database Engine

UnQLite - Transactional Embedded Database Engine

PixLab | Symisc Systems 1.7k Jun 23, 2022
Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more

Apache MXNet (incubating) for Deep Learning Apache MXNet is a deep learning framework designed for both efficiency and flexibility. It allows you to m

The Apache Software Foundation 20k Jun 23, 2022
C++ promise/A+ library in Javascript style.

C++ promise/A+ library in Javascript style. C++ promise/A+ library in Javascript style. What is promise-cpp ? Examples Examples list Compiler required

null 469 Jun 23, 2022
🎵 Music notation engraving library for MEI with MusicXML and Humdrum support and various toolkits (JavaScript, Python)

Verovio is a fast, portable and lightweight library for engraving Music Encoding Initiative (MEI) digital scores into SVG images. Verovio also contain

RISM Switzerland 484 Jun 23, 2022
Comprehensive RPC framework with support for C++, C#, Java, JavaScript, Python and more.

Ice - Comprehensive RPC Framework Ice helps you network your software with minimal effort. By taking care of all interactions with low-level network p

ZeroC Ice 1.8k Jun 19, 2022
:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:

Quick start | Requirements | Features | User guide | Contributing | License nbind is a set of headers that make your C++11 library accessible from Jav

charto 1.9k Jun 20, 2022
Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift

Fast Binary Encoding (FBE) Fast Binary Encoding allows to describe any domain models, business objects, complex data structures, client/server request

Ivan Shynkarenka 567 Jun 16, 2022
CommonMark spec, with reference implementations in C and JavaScript

CommonMark CommonMark is a rationalized version of Markdown syntax, with a spec and BSD-licensed reference implementations in C and JavaScript. Try it

CommonMark 4.6k Jun 21, 2022
Structy is an irresponsibly dumb and simple struct serialization/deserialization library for C, Python, and vanilla JavaScript.

Structy Structy is an irresponsibly dumb and simple struct serialization/deserialization library for C, Python, and vanilla JavaScript. You can think

Stargirl Flowers 47 Jun 19, 2022