Configuration

JerryScript provides a large number of configuration options which can be used to enable or disable specific features, allowing users to fine tune the engine to best suit their needs. A configuration option’s value can be changed either by providing specific C preprocessor definitions, by adding CMake defininitions, or by using the arguments of the tools/build.py script. This document lists the available configuration options, shows the configuration name for C, CMake, and python, and provides a brief description that explains the effect of the options.

All-in-one build

Enables the All-in-one build process, which aggregates the contents of each source file, and uses this combined file to compile the JerryScript library. This process can provide comparable results to link time optimization, and can be useful when LTO is not available otherwise.

Options
C:<none>
CMake:-DENABLE_ALL_IN_ONE=ON/OFF
Python:—all-in-one=ON/OFF

Jerry debugger

Enables debugger support in the engine, which can be used to debug running JavaScript code. For more information on using the debugger see Debugger. The debugger is disabled by default.

Options
C:-DJERRY_DEBUGGER=0/1
CMake:-DJERRY_DEBUGGER=ON/OFF
Python:—jerry-debugger=ON/OFF

Line information

By default, all source code information is discarded after parsing is complete. This option can be used to augment the created bytecode to provide line information during runtime, that can be used by the debugger to identify the currently executed source context. See Debugger.

Options
C:-DJERRY_LINE_INFO=0/1
CMake:-DJERRY_LINE_INFO=ON/OFF
Python:—line-info=ON/OFF

Profiles

This option can be used to enable/disable available JavaScript language features by providing profile files. Profile files contain a list of C definitions that configure each individual feature. The path value for CMake and Python arguments should be a file path to the profile file, or one of es2015-subset, es5.1, or minimal, which are the pre-defined profiles. To see how a profile file should be created, or what configuration options are available in C, see the profile README.

Options
C:<see description>
CMake:-DJERRY_PROFILE=”path”
Python:—profile=”path”

External context

Enables external context support in the engine. By default, JerryScript uses a statically allocated context to store the current state of the engine internals. When this option is enabled, an externally allocated memory region can be provided through the port API to the engine, to be used as the context.

Options
C:-DJERRY_EXTERNAL_CONTEXT=0/1
CMake:-DJERRY_EXTERNAL_CONTEXT=ON/OFF
Python:—external-context=ON/OFF

Snapshot execution

This option can be used to enable snapshot execution in the engine. This option is disabled by default.

Options
C:-DJERRY_SNAPSHOT_EXEC=0/1
CMake:-DJERRY_SNAPSHOT_EXEC=ON/OFF
Python:—snapshot-exec=ON/OFF

Snapshot saving

This option can be used to enable snapshot saving in the engine. This option is disabled by default.

Options
C:-DJERRY_SNAPSHOT_SAVE=0/1
CMake:-DJERRY_SNAPSHOT_SAVE=ON/OFF
Python:—snapshot-save=ON/OFF

Jerry parser

This option can be used to enable or disable the parser. When the parser is disabled all features that depend on source parsing are unavailable (eg. jerry_parse, eval, Function constructor). This option can be useful in combination with the snapshot feature. The parser is enabled by default.

Options
C:-DJERRY_PARSER=0/1
CMake:-DJERRY_PARSER=ON/OFF
Python:—js-parser=ON/OFF

Dump bytecode

This option can be used to display created bytecode in a human readable format. See Internals for more details. This option is disabled by default.

Options
C:-DJERRY_PARSER_DUMP_BYTE_CODE=0/1
CMake:-DJERRY_PARSER_DUMP_BYTE_CODE=ON/OFF
Python:—show-opcodes=ON/OFF

Dump RegExp bytecode

This option can be used to display created RegExp bytecode in a human readable format. The RegExp bytecode is different from the bytecode used by the virtual machine. This option is disabled by default.

Options
C:-DJERRY_REGEXP_DUMP_BYTE_CODE=0/1
CMake:-DJERRY_REGEXP_DUMP_BYTE_CODE=ON/OFF
Python:—show-regexp-opcodes=ON/OFF

Strict RegExp

This option can be used to enable strict RegExp mode. The standard RegExp syntax is a lot stricter than what is common in current JavaScript implementations. When enabled, this flag disables all of the non-standard, quality-of-life RegExp features, that are implemented to provide compatibility with other commonly used engines. This option is disabled by default.

Options
C:-DJERRY_REGEXP_STRICT_MODE=0/1
CMake:-DJERRY_REGEXP_STRICT_MODE=ON/OFF
Python:—regexp-strict-mode=ON/OFF

Error messages

Enables error messages for thrown Error objects. By default, error messages are omitted to reduce memory usage. Enabling this feature provides detailed error messages where available, like line information for Syntax errors, variable names for Reference errors, Type/Range error messages for built-in routines, etc.

Options
C:-DJERRY_ERROR_MESSAGES=0/1
CMake:—DJERRY_ERROR_MESSAGES=ON/OFF
Python:—error-messages=ON/OFF

Logging

This option can be used to enable log messages during runtime. When enabled the engine will use the jerry_port_log port API function to print relevant log messages. This feature is disabled by default.

Options
C:-DJERRY_LOGGING=0/1
CMake:-DJERRY_LOGGING=ON/OFF
Python:—logging=ON/OFF

LCache

This option enables the LCache, allowing faster access to object properties. The LCache usases a statically allocated hash-map, which increases memory consumption. See Internals for further details. This option is enabled by default.

Options
C:-DJERRY_LCACHE=0/1
CMake:<none>
Python:<none>

Property hashmaps

This option enables the creation of hashmaps for object properties, which allows faster property access, at the cost of increased memory consumption. See Internals for further details. This option is enabled by default.

Options
C:-DJERRY_PROPRETY_HASHMAP=0/1
CMake:<none>
Python:<none>

Memory statistics

This option can be used to provide memory usage statistics either upon engine termination, or during runtime using the jerry_get_memory_stats jerry API function. The feature can create a significant performance overhead, and should only be used for measurement purposes. This option is disabled by default.

Options
C:-DJERRY_MEM_STATS=0/1
CMake:-DJERRY_MEM_STATS=ON/OFF
Python:—mem-stats=ON/OFF

Heap size

This option can be used to adjust the size of the internal heap, represented in kilobytes. The provided value should be an integer. Values larger than 512 require 32-bit compressed pointers to be enabled. The default value is 512.

Options
C:-DJERRY_GLOBAL_HEAP_SIZE=(int)
CMake:—DJERRY_GLOBAL_HEAP_SIZE=(int)
Python:—mem-heap=(int)

Garbage collection limit

This option can be used to adjust the maximum allowed heap usage increase until triggering the next garbage collection, in bytes. When the total allocated memory size reaches the current gc limit, garbage collection will be triggered to try and reduce clutter from unreachable objects. If the total allocated memory can’t be reduced below the current limit, then the limit will be increased by the amount specified via this option. Similarly, when the total allocated memory goes well below the current gc limit, the limit is reduced by this amount. The default value is 1/32 of the total heap size, but not greater than 8192 bytes. A value of 0 will use the default value.

Options
C:-DJERRY_GC_LIMIT=(int)
CMake:-DJERRY_GC_LIMIT=(int)
Python:—gc-limit=(int)

Stack limit

This option can be used to cap the stack usage of the engine, and prevent stack overflows due to recursion. The provided value should be an integer, which represents the allowed stack usage in kilobytes. The default value is 0 (unlimited).

Options
C:-DJERRY_STACK_LIMIT=(int)
CMake:-DJERRY_STACK_LIMIT=(int)
Python:—stack-limit=(int)

32-bit compressed pointers

Enables 32-bit pointers instead of the default 16-bit compressed pointers. This allows the engine to use a much larger heap, but also comes with slightly increased memory usage, as objects can’t be packed as tightly. This option must be enabled when using the system allocator.

Options
C:-DJERRY_CPOINTER_32_BIT=0/1
CMake:-DJERRY_CPOINTER_32_BIT=ON/OFF
Python:—cpointer-32bit=ON/OFF

System allocator

This option enables the use of malloc/free instead of the internal JerryScript allocator. This feature requires 32-bit compressed pointers, and is unsupported on 64-bit architectures. This option is disabled by default.

Options
C:-DJERRY_SYSTEM_ALLOCATOR=0/1
CMake:-DJERRY_SYSTEM_ALLOCATOR=ON/OFF
Python:—system-allocator=ON/OFF

Valgrind support

This option enables valgrind support for the internal allocator. When enabled, valgrind will be able to properly identify allocated memory regions, and report leaks or out-of-bounds memory accesses. This option is disabled by default.

Options
C:-DJERRY_VALGRIND=0/1
CMake:-DJERRY_VALGRIND=ON/OFF
Python:—valgrind=ON/OFF

Memory stress test

This option can be used to stress test memory management, by running garbage collection before every allocation attempt. This option is disabled by default.

Options
C:-DJERRY_MEM_GC_BEFORE_EACH_ALLOC=0/1
CMake:-DJERRY_MEM_GC_BEFORE_EACH_ALLOC=ON/OFF
Python:—mem-stress-test=ON/OFF

Single source build mode

There is a special mode to use/“build” JerryScript. That is generating a single C file which can be included into projects quickly. To achive this the following command can be executed to create a set of files into the gen_src directory (Note that the command is executed in the jerryscript root directory but can be adapted to run outside of the project root dir):

  1. $ python tools/srcgenerator.py --output-dir gen_src --jerry-core --jerry-port-default --jerry-libm

The command creates the following files in the gen_src dir:

  • jerryscript.c
  • jerryscript.h
  • jerryscript-config.h
  • jerryscript-port-default.c
  • jerryscript-port-default.h
  • jerryscript-libm.c
  • math.h

Important: the jerryscript-config.h contains the configurations mentioned above and should be adapted to the required use-case. See the file contents for more details and for the default configuration. (Note: This config file is created from the the jerry-core/config.h file.)

These files can be directly compiled with an application using the JerryScript API. For example with the following command:

  1. $ gcc -Wall -o demo_app demo_app.c gen_src/jerryscript.c gen_src/jerryscript-port-default.c jerryscript-libm.c -Igen_src/

Please note that the headers must be available on the include path.

In addition there is a -DENABLE_ALL_IN_ONE_SOURCE=ON CMake option to use this kind of sources during the build.