ChakraCore Documentation

repository·master·Indexed 27 days ago

https://github.com/chakra-core/chakracore

A high-performance JavaScript engine with a C API designed for embedding into C or C++ compatible projects, particularly for embedded use cases. It provides a pure JavaScript engine without browser or Node.js external APIs. The documentation covers building on Windows, macOS, and Linux, installation via vcpkg, and usage of the 'ch' host application and JSRT APIs. Additionally, it includes details on the WebAssembly Binary Toolkit (WABT) tools such as wat2wasm, wasm2wat, and wasm-interp.

Tokens
9.4K
Snippets
13
Records
63
Agent score
92%

What's inside ChakraCore

  1. Overview of WABT (WebAssembly Binary Toolkit)

    master

    WABT is a suite of tools designed for manipulating WebAssembly files with high fidelity and compliance to the specification. Key tools include:

    • wat2wasm: Translates WebAssembly text format (.wat) to WebAssembly binary format (.wasm).
    • wasm2wat: The inverse of wat2wasm; translates binary format back to text format.
    • wasm-objdump: Prints information about a .wasm binary (similar to objdump).
    • wasm-interp: A stack-based interpreter that decodes and runs WebAssembly binary files.
    • wat-desugar: Parses .wat text (s-expressions, flat, or mixed) and prints the
  2. Build WABT on macOS and Linux

    master

    Building requires CMake.

    Using Make

    Running make builds a default debug version using the Clang compiler, placing results in out/clang/Debug/.

    Note for macOS: You must use CMake version 3.10 or higher.

    Available build targets can be customized using the pattern make [compiler]-[build_type]-[configuration].

    Compilers:

    • gcc
    • clang
    • gcc-i686
    • gcc-fuzz

    Build Types:

    • debug
    • release

    Configurations:

    • asan (Address Sanitizer)
    • msan (Memory Sanitizer)
    • lsan (Leak Sanitizer)
    • ubsan (Undefined Behavior Sanitizer)
    • no-re2c
    • no-tests

    Example targets:

    • make clang-debug
    • make gcc-i686-release
    • make clang-debug-lsan
    $ make
  3. Build ChakraCore on Windows

    master

    To build ChakraCore on Windows (Windows 7 SP1+ or Windows Server 2008 R2+), you need Visual Studio 2015 or 2017 with C++ support installed.

    1. Clone the repository:
      git clone https://github.com/Microsoft/ChakraCore.git
    2. Open Build\Chakra.Core.sln in Visual Studio.
    3. Build the Solution.
    git clone https://github.com/Microsoft/ChakraCore.git
  4. Embed ChakraCore in your application

    master

    ChakraCore is intended to be embedded in your own C/C++ applications via its C API.

    Important Note on APIs: ChakraCore is a pure JavaScript engine and does not include external APIs typically found in a web browser or Node.js. For example, DOM APIs like document.write() are not provided. When embedding, you must implement your own input and output APIs. For basic terminal output in the ch host, you can use print().

  5. Build WABT on Windows

    master

    Building on Windows requires CMake and either Visual Studio (2015 or newer) or MinGW.

    To build using CMake from the command line:

    1. Create a build directory.
    2. Run cmake with the desired configuration, install prefix, and generator.
    3. Run cmake --build to compile and install.

    Example for a Visual Studio 2015 debug build:

    > mkdir build
    > cd build
    > cmake .. -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=..\bin -G "Visual Studio 14 2015"
    > cmake --build .. --config DEBUG --target install
  6. Build and run the ChakraCore Hello-world Sample

    master

    To build and run the ChakraCore Hello-world sample for Shared Library on Linux or macOS, use the make command. The sample demonstrates initializing the JavaScript runtime, creating an execution context, running scripts, and handling values using the JavaScript Runtime (JSRT) APIs.

    Linux (amd64):

    make
    ./sample.o

    macOS (OSX):

    make PLATFORM=darwin
    ./sample.o
    make
    ./sample.o
  7. Use the 'ch' CLI tool

    master

    The ch command-line tool is used to execute JavaScript source files using the ChakraCore engine. It supports various modes including standard execution, background parsing, and Time Travel Debugging (TTD) in specific build configurations.

    Basic Usage:

    ch [flags] <source file>

    Note: Many advanced flags (the [flaglist]) are only available in Debug or Test builds. In Release builds, these flags are not supported.