LinuxCommandLibrary

d8

Compile Java bytecode to DEX format

TLDR

Start a REPL (interactive shell)

$ d8
copy

Run a JavaScript file
$ d8 [path/to/file.js]
copy

Evaluate a JavaScript expression
$ d8 -e "[code]
copy

SYNOPSIS

d8 [options] [script-file] [-- [arguments...]]

PARAMETERS

--help
    Displays a comprehensive list of command-line options and their descriptions.

--version
    Prints the version of the V8 engine used by the d8 shell.

--shell
    Forces d8 to run in interactive mode, even if a script file is provided. This allows for entering commands after script execution.

--print-ast
    Prints the Abstract Syntax Tree (AST) generated by the V8 engine for the parsed JavaScript code.

--allow-natives-syntax
    Enables the use of special JavaScript syntax (e.g., %DebugPrint()) that exposes V8's internal native functions, typically used for debugging and engine introspection.

--expose-gc
    Exposes the garbage collection function (gc()) to JavaScript code, allowing manual invocation of the garbage collector for testing memory management.

--harmony-*
    Enables experimental ECMAScript (JavaScript) features that are under development. For example, --harmony-private-methods.

--prof
    Enables profiling and generates a v8.log file that can be analyzed with tools like d8's own profiling script or external profilers.

--js-flags="<flags>"
    Passes specific V8 engine flags directly to the JavaScript runtime. This allows fine-grained control over various internal V8 behaviors.

--
    A separator that indicates that all subsequent arguments are to be treated as arguments to the JavaScript script file, rather than d8 options.

DESCRIPTION

d8 is the standalone command-line shell for Google's V8 JavaScript engine. It provides a lightweight environment to execute JavaScript code outside of a web browser, making it an invaluable tool for V8 engine developers, JavaScript library authors, and anyone interested in benchmarking or experimenting with JavaScript performance characteristics. Unlike Node.js, d8 focuses purely on the V8 engine itself, offering direct access to many internal V8 functionalities and experimental ECMAScript features that are not yet stable or exposed in other runtime environments. It is commonly used for testing the engine's compilation, optimization, and garbage collection mechanisms, as well as for rapid prototyping and debugging of JavaScript code.

CAVEATS

d8 is primarily a development and testing tool for the V8 engine, not a general-purpose JavaScript runtime like Node.js. It typically lacks many features expected in a full runtime, such as file system access, network capabilities, or module systems. Its command-line options are numerous and can change frequently with V8 engine updates, often without backward compatibility guarantees. It is usually found in development environments and is not part of standard Linux distributions by default.

INTERACTIVE MODE

When d8 is invoked without a script file, or with the --shell option, it enters an interactive read-eval-print loop (REPL). In this mode, users can type JavaScript code directly, which is immediately executed, making it useful for quick tests and explorations of JavaScript syntax and V8 features.

SCRIPT EXECUTION

To execute a JavaScript file, simply provide its path as an argument to d8: d8 my_script.js. Arguments can be passed to the script using the -- separator: d8 my_script.js -- arg1 arg2. Inside my_script.js, these arguments can be accessed via the global arguments object, which is an array of strings.

HISTORY

The d8 shell emerged as a crucial component of Google's V8 JavaScript engine project, which was first released in 2008 as the JavaScript engine for the Google Chrome web browser. From its inception, V8 was designed for high performance, compiling JavaScript to native machine code. d8 was developed as an essential accompanying tool, providing a direct interface to test, benchmark, and debug the V8 engine's functionalities independently of a browser environment. It has continuously evolved alongside the V8 engine and the ECMAScript standard, incorporating new features and optimizations as they are developed.

SEE ALSO

node(1), chromium(1), js(1)

Copied to clipboard