### Install lit with setup.py and run tests Source: https://github.com/discord/hermes/blob/main/external/llvh/utils/lit/README.txt Install lit via setuptools and then run lit's tests using the installed 'lit' command. ```shell python utils/lit/setup.py install lit --path /path/to/your/llvm/build/bin utils/lit/tests ``` -------------------------------- ### CallInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Calls a function with arguments. The example shows the instruction syntax with callee, this, and arguments. ```llvm %0 = CallInst %callee, %this, %arg0, %arg1, %arg2, ... ``` -------------------------------- ### ConstructInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Constructs a new object with a constructor. The example shows the instruction syntax with constructor, undefined, and arguments. ```llvm %0 = ConstructInst %constructor, #undefined, %arg0, %arg1, %arg2, ... ``` -------------------------------- ### Install with yarn Source: https://github.com/discord/hermes/blob/main/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/README.md Install the plugin as a dev dependency using yarn. ```sh yarn add babel-plugin-syntax-hermes-parser --dev ``` -------------------------------- ### Install dependencies on Ubuntu Source: https://github.com/discord/hermes/blob/main/doc/BuildingAndRunning.md Install required packages for building Hermes on Ubuntu using apt. ```bash apt install cmake git ninja-build libicu-dev python3 zip libreadline-dev ``` -------------------------------- ### Install with npm Source: https://github.com/discord/hermes/blob/main/tools/hermes-parser/js/babel-plugin-syntax-hermes-parser/README.md Install the plugin as a dev dependency using npm. ```sh npm install --save-dev babel-plugin-syntax-hermes-parser ``` -------------------------------- ### Install iOS pods with BUILD_FROM_SOURCE Source: https://github.com/discord/hermes/blob/main/doc/ReactNativeIntegration.md Run this command to install pods with BUILD_FROM_SOURCE=true, enabling a build from source for the custom Hermes. ```bash BUILD_FROM_SOURCE=true bundle exec pod install ``` -------------------------------- ### CreateArgumentsInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Allocates the JavaScript `arguments` array-like object on the heap. The example shows the instruction with no arguments. ```hermes-ir %0 = CreateArgumentsInst ``` -------------------------------- ### Run test262 suite with example paths Source: https://github.com/discord/hermes/blob/main/doc/BuildingAndRunning.md Example command to run test262 with a specific Hermes build and test262 clone. ```bash hermes/utils/testsuite/run_testsuite.py -b ~/hermes_build ~/test262/test ``` -------------------------------- ### CreateScopeInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Creates a new function top-level scope. The example shows the instruction syntax with a descriptor %desc. ```llvm %0 = CreateScopeInst %desc ``` -------------------------------- ### Install npm packages Source: https://github.com/discord/hermes/blob/main/tools/hcdp/README.md Run this command in the hcdp directory to install the required npm packages before running the tool. ```bash npm install ``` -------------------------------- ### AllocObjectInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Allocates a new JavaScript object on the heap. The example shows the instruction with a size hint and an optional parent argument. ```hermes-ir %0 = AllocObjectInst %sizeHint : LiteralNumber, %parent : EmptySentinel or null or Value ``` -------------------------------- ### CreateRegExpInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Constructs a RegExp object from a regexp literal. The example shows the instruction with pattern and flags string literals. ```hermes-ir %0 = CreateRegExpInst "pattern", "flags" ``` -------------------------------- ### UnreachableInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Example usage of the UnreachableInst instruction: %0 = UnreachableInst. This instruction crashes the VM if executed in debug builds. ```text %0 = UnreachableInst ``` -------------------------------- ### Install and activate Emscripten SDK Source: https://github.com/discord/hermes/blob/main/doc/Emscripten.md Installs and activates the latest Emscripten SDK using emsdk, then sources the environment script to set up the build environment. ```bash emsdk install latest emsdk activate latest source ./emsdk_env.sh ``` -------------------------------- ### BinaryOperatorInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Performs a binary operation on two operands. The example shows the instruction syntax with operands %x and %y. ```llvm %0 = BinaryOperatorInst %x, %y ``` -------------------------------- ### AllocArrayInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Allocates a new JavaScript array on the heap. The example shows the instruction with a size hint and initial element values. ```hermes-ir %0 = AllocArrayInst %sizeHint, %value0, %value1, ... ``` -------------------------------- ### SwitchInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Transfers control to one of different places based on the input value. The example shows the instruction with an input, default block, and value-destination pairs. ```hermes-ir %0 = SwitchInst %input, %default, [%val0, %block0], [%val1, %block1] .. ``` -------------------------------- ### CallBuiltinInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Calls a builtin function with undefined for this. The example shows the instruction syntax with builtin number, undefined, and arguments. ```llvm %0 = CallBuiltinInst %builtinNumber, %undefined, %arg0, %arg1, %arg2, ... ``` -------------------------------- ### DirectEvalInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Implements a direct call to eval(arg). The example shows the instruction syntax with a value operand %value1. ```llvm %0 = DirectEvalInst %value1 ``` -------------------------------- ### Start fuzzing with Fuzzilli Source: https://github.com/discord/hermes/blob/main/tools/fuzzers/fuzzilli/README.md Starts fuzzing Hermes with Fuzzilli using the hermes profile. Requires FUZZILLI_LOCATION and BINARY_LOCATION environment variables. ```shell cd $FUZZILLI_LOCATION swift run FuzzilliCli --profile=hermes $BINARY_LOCATION ``` -------------------------------- ### CompareBranchInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Performs a binary comparison and conditional branch. The example shows the instruction syntax with operands %x, %y and branch targets %BB1 (True) and %BB2 (False). ```llvm %0 = CompareBranch %x, %y, %BB1, %BB2 ``` -------------------------------- ### CreateFunction Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Constructs a new function closure from its code representation. The example shows the instruction syntax with a function operand %function. ```llvm %0 = CreateFunction %function, ``` -------------------------------- ### CreateInnerScopeInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Creates a new inner scope with a given parent. The example shows the instruction syntax with parent scope %parent and descriptor %desc. ```llvm %0 = CreateInnerScopeInst %parent, %desc ``` -------------------------------- ### Example metadata.json file Source: https://github.com/discord/hermes/blob/main/doc/Modules.md Example metadata.json file showing the required segments object and optional resolutionTable. The segments object maps segment IDs to arrays of file paths; segment "0" is the main segment loaded on startup. The resolutionTable maps relative file names to objects that resolve require() strings to actual file paths. ```json { "segments": { "0": [ "./cjs-subdir-main.js", "cjs-subdir-2.js", "bar/cjs-subdir-bar.js", "foo/cjs-subdir-foo.js" ] }, "resolutionTable": { "./cjs-subdir-main.js": { "foo": "./foo/cjs-subdir-foo.js" }, "./foo/cjs-subdir-foo.js": { "bar": "./bar/cjs-subdir-bar.js" } } } ``` -------------------------------- ### BranchInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Jumps to a different basic block. Terminates a basic block and does not read or write from memory. ```hermes-ir %0 = BranchInst %BB1 ``` -------------------------------- ### GetBuiltinClosureInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Returns a closure of a builtin function. The argument %builtinNumber specifies the builtin to return the closure of. Reads from memory. ```text %0 = GetBuiltinClosureInst %builtinNumber ``` -------------------------------- ### CatchInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Catches an exception and returns it. This instruction has no arguments and can only appear at the beginning of a basic block. It is generated for each catch and finally block. ```hermes-ir %0 = CatchInst ``` -------------------------------- ### Install dependencies on macOS via Homebrew Source: https://github.com/discord/hermes/blob/main/doc/BuildingAndRunning.md Install required packages for building Hermes on macOS using Homebrew. ```bash brew install cmake git ninja ``` -------------------------------- ### Install dependencies on Arch Linux Source: https://github.com/discord/hermes/blob/main/doc/BuildingAndRunning.md Install required packages for building Hermes on Arch Linux using pacman. ```bash pacman -S cmake git ninja icu python zip readline ``` -------------------------------- ### IteratorClose example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Example usage of the IteratorClose instruction: %0 = IteratorClose %iterator %ignoreInnerException. This instruction closes an iterator if it exists. ```text %0 = IteratorClose %iterator %ignoreInnerException ``` -------------------------------- ### CallIntrinsicInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Calls an unsafe compiler intrinsic. The example shows the instruction syntax with intrinsic index, undefined, and arguments. ```llvm %0 = CallIntrinsicInst %intrinsicsIndex, %undefined, %arg0, %arg1, %arg2, ... ``` -------------------------------- ### TryStartInst Example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Marks the beginning of try blocks. Takes two arguments: the try body block and the catch target block. This is a nop used for tracking. ```hermes-ir %0 = TryStartInst %catchTargetBlock, %tryBodyBlock ``` -------------------------------- ### Run hcdp.js with binary and script paths Source: https://github.com/discord/hermes/blob/main/tools/hcdp/README.md Execute the hcdp.js script, passing the path to the hcdp binary and the script to be debugged. The example uses ~/hcdp and ~/loop.js. ```bash node ./hcdp.js ~/hcdp ~/loop.js ``` -------------------------------- ### ThrowIfHasRestrictedGlobalPropertyInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Raises an exception if the given name is a restricted global property. The example shows the instruction with a single string argument. ```hermes-ir ThrowIfHasRestrictedGlobalPropertyInst %name : string ``` -------------------------------- ### Configure lit.site.cfg with output mapping Source: https://github.com/discord/hermes/blob/main/external/llvh/utils/lit/CMakeLists.txt Generates lit.site.cfg from the template in the source tests directory, mapping the output to the build directory. The configured file is not placed correctly until tests are run because it must be copied into a copy of the tests folder. ```cmake configure_lit_site_cfg( "${CMAKE_CURRENT_SOURCE_DIR}/tests/lit.site.cfg.in" "${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg" OUTPUT_MAPPING "${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg" ) ``` -------------------------------- ### Install @react-native/hermes-inspector-msggen with yarn Source: https://github.com/discord/hermes/blob/main/API/hermes/cdp/tools/hermes-inspector-msggen/README.md Install the package and its development dependencies using yarn. The note suggests that npm 3+ and npx can be used instead. ```bash yarn add --dev @babel/cli @babel/core @babel/preset-env @babel/preset-flow jest @react-native/hermes-inspector-msggen ``` -------------------------------- ### IteratorNext example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Example usage of the IteratorNext instruction: %0 = IteratorNext %iterator %sourceOrNext. This instruction destructures the next value from a given iterator. ```text %0 = IteratorNext %iterator %sourceOrNext ``` -------------------------------- ### Run llvm-lit wrapper script Source: https://github.com/discord/hermes/blob/main/external/llvh/utils/lit/README.txt Run the llvm-lit wrapper script on lit's tests to verify it works. ```shell /path/to/your/llvm/build/bin/llvm-lit utils/lit/tests ``` -------------------------------- ### TryStoreGlobalPropertyInst example Source: https://github.com/discord/hermes/blob/main/doc/IR.md Attempts to store a value into an existing field of the global object and throws if it doesn't exist. %value is the value to be stored, %object is the global object, %property must be a string literal. May read and write memory or throw. ```text %4 = TryStoreGlobalPropertyInst %value, %object, %property ```