Understand the ECMA component responsibilities
masterThe ECMA component of the JerryScript engine manages the following core concepts:
- Data representation
- Runtime representation
- Garbage collection (GC)
repository·master·Indexed 27 days ago
https://github.com/jerryscript-project/jerryscriptAn ultra-lightweight JavaScript engine designed for resource-constrained IoT devices and microcontrollers, optimized for low memory consumption (less than 64 KB RAM). The documentation covers building the engine via Python scripts or CMake, configuring features using profile files, and deploying to hardware targets including ESP32 (via esp-idf), ESP8266 (via ESP8266 RTOS SDK), and Particle Photon. It also details available debugging tools such as the console debugger client and Chrome webtool.
The ECMA component of the JerryScript engine manages the following core concepts:
JerryScript operates using two primary components: the Parser and the Virtual Machine (VM).
Key subcomponents of the Parser include the Lexer (tokenization), Scanner (pre-scanning for ambiguous tokens like /), Expression Parser, and Statement Parser.
JerryScript provides several tools for debugging JavaScript execution in IoT environments:
jerry_client.py) for console-based debugging.The Virtual Machine is an interpreter that executes byte-code instructions sequentially.
Key implementation details:
vm_run located in ./jerry-core/vm/vm.c.vm_loop, is non-recursive. This design choice prevents function calls from burdening the system stack, as the VM returns rather than calling itself recursively.The following APIs allow for interacting with ArrayBuffer and SharedArrayBuffer objects.
Requirements:
JERRY_BUILTIN_TYPEDARRAY build option.JERRY_FEATURE_TYPEDARRAY feature enum.JerryScript can be deployed on Espressif hardware using the following SDKs:
Both targets follow the ESP-IDF build system style and directory structure. For specific implementation details and setup instructions, refer to the target-specific documentation in the repository:
esp8266-rtos-sdk/README.mdesp-idf/README.mdWhen writing code for JerryScript, use a verbose function declaration format to reduce maintenance costs and improve readability.
Key requirements for a compliant function declaration:
@return description./**< description */ inline for each argument.} /* function_name */)./**
* Short overview about the purpose of this function.
*
* A more detailed explanation if needed.
*
* Note:
* Extra notes if needed.
*
* @return short description about the value
* returned by the function
*/
return_value_type_t
function_name (argument1, /**< description of argument1 */
argument2, /**< description of argument2 */
...
argument_n, /**< description of argument n */
{
/* Function body. */
} /* function_name */When performing property operations like jerry_object_get or jerry_object_set, you must manage the references for both the retrieved/set value and the result of the operation itself.
jerry_object_get: Returns a new live reference to the property value. If the operation fails, it returns a live reference to an error object. Both must be freed.jerry_object_set:new_prop_value) must be released.result) is a new live reference (representing a primitive or an error) and must also be released. jerry_value_t new_prop_value = jerry_number (2.718);
jerry_value_t result = jerry_object_set (..., new_prop_value);
/* The new_prop_value can be passed to other JerryScript API
* functions before the jerry_value_free () call. */
jerry_value_free (new_prop_value);
/* The reference stored in the 'result' variable is live whether
* the operation is successful or not, and must also be freed. */
if (jerry_value_is_exception (result))
{
/* Errors can be handled here. */
}
jerry_value_free (result);A comment is required after #else and #endif directives. The comment should include the condition but omit the defined keyword.
Example:
#ifdef JERRY_A
#else /* !JERRY_A */
#endif /* JERRY_A */To use the JerryScript library, you must clone and build it for your target environment. The following steps demonstrate building with the default configuration and installing it to a local directory on a Linux system.
After installation, the library headers and libraries will be located in the example_install/{include,lib} directories. To use pkg-config to manage includes and libraries, you must export the PKG_CONFIG_PATH pointing to the installation's lib/pkgconfig directory.
$ mkdir jerry
$ cd jerry
$ git clone https://github.com/jerryscript-project/jerryscript.git
$ jerryscript/tools/build.py --builddir=$(pwd)/example_build --cmake-param="-DCMAKE_INSTALL_PREFIX=$(pwd)/example_install/"
$ make -C $(pwd)/example_build install
# Set up pkg-config
$ export PKG_CONFIG_PATH=$(pwd)/example_install/lib/pkgconfig/
# Verify pkg-config works
$ pkg-config --cflags --libs libjerry-core libjerry-port libjerry-ext libjerry-mathtools/build.py Python script. This allows you to enable or disable specific features to fine-tune the engine for your needs.After configuring NuttX and preparing your files, build the NuttX image and flash it to the STM32F4-Discovery board using ST-Link.
# Build NuttX
make -C nuttx
# Flash the device
make -C stlink release
sudo stlink/build/Release/st-flash write nuttx/nuttx.bin 0x8000000