├── .gitignore ├── LICENSE ├── README.md ├── docs └── opcodes_table.html ├── hbc_decompiler.py ├── hbc_disassembler.py ├── hbc_file_parser.py ├── setup.py ├── src ├── decompilation │ ├── defs.py │ ├── hbc_decompiler.py │ ├── pass1_set_metadata.py │ ├── pass2_transform_code.py │ ├── pass3_parse_forin_loops.py │ └── pass4_name_closure_vars.py ├── disassembly │ └── hbc_disassembler.py └── parsers │ ├── debug_info_parser.py │ ├── hbc_bytecode_parser.py │ ├── hbc_file_parser.py │ ├── hbc_opcodes │ ├── def_classes.py │ ├── hbc51.py │ ├── hbc58.py │ ├── hbc59.py │ ├── hbc61.py │ ├── hbc62.py │ ├── hbc68.py │ ├── hbc69.py │ ├── hbc70.py │ ├── hbc72.py │ ├── hbc73.py │ ├── hbc76.py │ ├── hbc80.py │ ├── hbc81.py │ ├── hbc82.py │ ├── hbc83.py │ ├── hbc84.py │ ├── hbc85.py │ ├── hbc86.py │ ├── hbc87.py │ ├── hbc89.py │ ├── hbc90.py │ ├── hbc92.py │ └── hbc95.py │ ├── pretty_print.py │ ├── regexp_bytecode_parser.py │ └── serialized_literal_parser.py ├── tests ├── assets │ └── index.android.bundle ├── build.sh ├── sample.hbc ├── sample.hermes_dec_hasm ├── sample.hermes_dec_hdec ├── sample.hermes_dec_header ├── sample.hermes_objdump_hasm ├── sample.hermes_pretty_hasm ├── sample.hermes_raw_hasm └── sample.js └── utils ├── git_tags.sh ├── hermes_bytecode_structs_parser.py ├── hermes_bytecode_structs_table_gen.py ├── original_function_builtins_c_src ├── Builtins-hbc61.def ├── Builtins-hbc68.def ├── Builtins-hbc69.def ├── Builtins-hbc70.def ├── Builtins-hbc72.def ├── Builtins-hbc73.def ├── Builtins-hbc80.def ├── Builtins-hbc81.def ├── Builtins-hbc82.def ├── Builtins-hbc86.def ├── Builtins-hbc87.def ├── Builtins-hbc90.def ├── Builtins-hbc92.def ├── Builtins-hbc95.def ├── Builtins-v0.0.1.def ├── Builtins-v0.0.3.def ├── Builtins-v0.1.0.def ├── Builtins-v0.11.0.def ├── Builtins-v0.12.0.def ├── Builtins-v0.2.1.def ├── Builtins-v0.7.0.def ├── Builtins-v0.8.0.def ├── Builtins-v0.9.0.def └── get_source_codes.sh ├── original_hermes_bytecode_c_src ├── BytecodeList-hbc61.def ├── BytecodeList-hbc68.def ├── BytecodeList-hbc69.def ├── BytecodeList-hbc70.def ├── BytecodeList-hbc72.def ├── BytecodeList-hbc73.def ├── BytecodeList-hbc80.def ├── BytecodeList-hbc81.def ├── BytecodeList-hbc82.def ├── BytecodeList-hbc86.def ├── BytecodeList-hbc87.def ├── BytecodeList-hbc90.def ├── BytecodeList-hbc92.def ├── BytecodeList-hbc95.def ├── BytecodeList-v0.0.1.def ├── BytecodeList-v0.0.3.def ├── BytecodeList-v0.1.0.def ├── BytecodeList-v0.11.0.def ├── BytecodeList-v0.12.0.def ├── BytecodeList-v0.2.1.def ├── BytecodeList-v0.7.0.def ├── BytecodeList-v0.8.0.def ├── BytecodeList-v0.9.0.def ├── BytecodeVersion-hbc61.h ├── BytecodeVersion-hbc68.h ├── BytecodeVersion-hbc69.h ├── BytecodeVersion-hbc70.h ├── BytecodeVersion-hbc72.h ├── BytecodeVersion-hbc73.h ├── BytecodeVersion-hbc80.h ├── BytecodeVersion-hbc81.h ├── BytecodeVersion-hbc82.h ├── BytecodeVersion-hbc86.h ├── BytecodeVersion-hbc87.h ├── BytecodeVersion-hbc90.h ├── BytecodeVersion-hbc92.h ├── BytecodeVersion-hbc95.h ├── BytecodeVersion-v0.0.1.h ├── BytecodeVersion-v0.0.3.h ├── BytecodeVersion-v0.1.0.h ├── BytecodeVersion-v0.11.0.h ├── BytecodeVersion-v0.12.0.h ├── BytecodeVersion-v0.2.1.h ├── BytecodeVersion-v0.7.0.h ├── BytecodeVersion-v0.8.0.h ├── BytecodeVersion-v0.9.0.h └── get_source_codes.sh ├── original_regex_bytecode_c_src ├── RegexBytecode-v0.0.1.h ├── RegexBytecode-v0.0.2.h ├── RegexBytecode-v0.0.3.h ├── RegexBytecode-v0.1.0.h ├── RegexBytecode-v0.1.1.h ├── RegexBytecode-v0.10.0.h ├── RegexBytecode-v0.11.0.h ├── RegexBytecode-v0.12.0.h ├── RegexBytecode-v0.2.1.h ├── RegexBytecode-v0.3.0.h ├── RegexBytecode-v0.4.0.h ├── RegexBytecode-v0.4.1.h ├── RegexBytecode-v0.4.3.h ├── RegexBytecode-v0.4.4.h ├── RegexBytecode-v0.5.0.h ├── RegexBytecode-v0.5.1.h ├── RegexBytecode-v0.5.3.h ├── RegexBytecode-v0.6.0.h ├── RegexBytecode-v0.7.0.h ├── RegexBytecode-v0.7.1.h ├── RegexBytecode-v0.7.2.h ├── RegexBytecode-v0.8.0.h ├── RegexBytecode-v0.8.1.h ├── RegexBytecode-v0.9.0.h └── get_source_codes.sh ├── regen_hbc_opcodes.sh └── regex_bytecode_structs_parser.py /.gitignore: -------------------------------------------------------------------------------- 1 | # The following is related to Python or miscellaneous 2 | *.pyc 3 | dist/ 4 | __pycache__/ 5 | config.py 6 | build/ 7 | notes/ 8 | tests/*real* 9 | tests/assets/*di* 10 | *.egg-info 11 | .~lock.* 12 | *.glade# 13 | *~ 14 | *.swp 15 | .vscode 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `hermes-dec` is a reverse-engineering tool which can be used for disassembling and decompiling React Native files compiled into the Hermes VM bytecode (HBC) format. 2 | 3 | For a wider presentation of its purpose, please see our [presentation blog post](https://labs.p1sec.com/?p=2070). 4 | 5 | ## Background 6 | 7 | The Hermes VM for React Native was announced by Facebook on the [12 July 2019](https://engineering.fb.com/2019/07/12/android/hermes/). The initial release of Hermes was version 0.1.0 ([bytecode version 59](https://github.com/facebook/hermes/blob/v0.1.0/include/hermes/BCGen/HBC/BytecodeFileFormat.h#L32)), Github tags 0.0.1 to 0.0.3 correspond to pre-public release. 8 | 9 | However, Hermes is the default compilation target for React Native on Android only since [React Native 0.70](https://reactnative.dev/blog/2022/09/05/version-070#hermes-as-default-engine) (released on 5 September 2022), as explained [here](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default). 10 | 11 | Before that, and since React Native 0.60.2, the Hermes VM was an [opt-in feature](https://reactnative.dev/docs/hermes#enabling-hermes). Hermes for iOS is supported since [version 0.64 of React Native](https://reactnative.dev/blog/2021/03/12/version-0.64) (released on the 12 March 2021). 12 | 13 | **React Native is used by a wide variety of significant mobile applications**, as exposed on the [React Native showcase page](https://reactnative.dev/showcase). 14 | 15 | A variety of technical documentation regarding the Hermes VM, which is published as [an open-source](https://github.com/facebook/hermes/) project under the BSD license, including [various design documents in the Markdown format](https://github.com/facebook/hermes/tree/main/doc), which can be read on Github as well as on [Facebook's website for React documentation](https://hermesengine.dev/docs/vm/). 16 | 17 | In Android applications released under the .APK format, the Hermes bytecode (HBC) file is usually located at: 18 | 19 | ``` 20 | $ file assets/index.android.bundle 21 | assets/index.android.bundle: Hermes JavaScript bytecode, version 84 22 | ``` 23 | 24 | On non-Hermes based setups of React Native, this file usually contains minified/Webpacked JavaScript code. 25 | 26 | ## Installation 27 | 28 | The application itself only relies on the Python 3.x standard library for now. 29 | 30 | You can install the tool through the following commands on Ubuntu 22.04: 31 | 32 | ``` 33 | sudo apt install -y python3-pip 34 | sudo pip3 install --upgrade git+https://github.com/P1sec/hermes-dec 35 | ``` 36 | 37 | Certain internal development utilities may however require to install `libclang` for Python: 38 | 39 | ``` 40 | sudo apt install python3-clang-12 41 | ``` 42 | 43 | ## Usage 44 | 45 | If you didn't install the tool system-wide using the command above, you can also download the source using this command and find the same utilities at the root: 46 | 47 | ``` 48 | $ git clone git@github.com:P1sec/hermes-dec.git 49 | $ cd hermes-dec/ 50 | ``` 51 | 52 | For an Android application, you should extract the Hermes bundle file from the .APK file through using your favorite unzipping tool (an .APK file is a renamed .ZIP archive): 53 | 54 | ``` 55 | $ 7z x my_application.apk 56 | $ cd my_application 57 | ``` 58 | 59 | And check the type of the `assets/index.android.bundle` React Native bundle file which, in the case of a React Native-based application, should be either a plain-text minified JavaScript bundle file or an Hermes bytecode file: 60 | 61 | ``` 62 | $ file assets/index.android.bundle 63 | assets/index.android.bundle: Hermes JavaScript bytecode, version 84 64 | ``` 65 | 66 | If the concerned file is indeed an Hermes JavaScript bytecode file, you may then decode most of its file headers using the following utility (which output may not be stable over time): 67 | 68 | ``` 69 | hbc-file-parser assets/index.android.bundle 70 | ``` 71 | 72 | You may then disassemble the contents of the React Native bytecode file to the `/tmp/my_output_file.hasm` output file using the following command (leave out the second parameter in order to send the disassembled content to the standard output): 73 | 74 | ``` 75 | hbc-disassembler assets/index.android.bundle /tmp/my_output_file.hasm 76 | ``` 77 | 78 | And perform the decompilation to pseudo-code (which is not valid JavaScript yet as it does not retranscribe loop/conditional structures) using the following command: 79 | 80 | ``` 81 | hbc-decompiler assets/index.android.bundle /tmp/my_output_file.js 82 | ``` 83 | 84 | ## Extra documentation 85 | 86 | You can find auto-generated documentation for the Hermes VM opcodes [here](https://p1sec.github.io/hermes-dec/opcodes_table.html). 87 | 88 | This is an useful tool to understand the generated assembly code. 89 | -------------------------------------------------------------------------------- /hbc_decompiler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | 4 | from src.decompilation.hbc_decompiler import main 5 | 6 | main() 7 | -------------------------------------------------------------------------------- /hbc_disassembler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | 4 | from src.disassembly.hbc_disassembler import main 5 | 6 | main() 7 | -------------------------------------------------------------------------------- /hbc_file_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | 4 | from src.parsers.hbc_file_parser import main 5 | 6 | main() 7 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | 4 | from setuptools import setup 5 | 6 | setup(name = 'hermes-dec', 7 | version = '0.0.1', 8 | description = 'A tool for reverse engineering React Native bytecode files, including disassembly and decompilation facilities', 9 | author = 'P1 Security - Marin Moulinier', 10 | author_email = '', 11 | entry_points = { 12 | 'console_scripts': [ 13 | 'hbc-decompiler = hermes_dec.decompilation.hbc_decompiler:main', 14 | 'hbc-disassembler = hermes_dec.disassembly.hbc_disassembler:main', 15 | 'hbc-file-parser = hermes_dec.parsers.hbc_file_parser:main' 16 | ] 17 | }, 18 | url = 'https://github.com/P1sec/hermes-dec', 19 | install_requires = [], 20 | packages = [ 21 | 'hermes_dec.parsers', 22 | 'hermes_dec.parsers.hbc_opcodes', 23 | 'hermes_dec.decompilation', 24 | 'hermes_dec.disassembly' 25 | ], 26 | package_dir = { 27 | 'hermes_dec.parsers': 'src/parsers', 28 | 'hermes_dec.disassembly': 'src/disassembly', 29 | 'hermes_dec.decompilation': 'src/decompilation' 30 | } 31 | ) 32 | -------------------------------------------------------------------------------- /src/decompilation/hbc_decompiler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from os.path import realpath, dirname 4 | from argparse import ArgumentParser 5 | import sys 6 | 7 | SCRIPT_DIR = dirname(realpath(__file__)) 8 | ROOT_DIR = realpath(SCRIPT_DIR + '/..') 9 | PARSERS_DIR = realpath(ROOT_DIR + '/parsers') 10 | 11 | sys.path.insert(0, SCRIPT_DIR) 12 | sys.path.insert(0, PARSERS_DIR) 13 | 14 | from hbc_file_parser import HBCReader 15 | from pass1_set_metadata import pass1_set_metadata 16 | from pass2_transform_code import pass2_transform_code 17 | from pass3_parse_forin_loops import pass3_parse_forin_loops 18 | from pass4_name_closure_vars import pass4_name_closure_vars 19 | from defs import HermesDecompiler, FunctionTableIndex, DecompiledFunctionBody 20 | 21 | """ 22 | Entry points for the Hermes HBC Decompiler 23 | """ 24 | 25 | # Decompile a function and its nested closures to the standard 26 | # output, given a parsed Hermes bytecode file and a function ID: 27 | 28 | def decompile_function(state : HermesDecompiler, function_id : int, **kwargs): 29 | 30 | dehydrated = DecompiledFunctionBody() 31 | 32 | dehydrated.function_id = function_id 33 | dehydrated.function_object = state.hbc_reader.function_headers[function_id] 34 | dehydrated.is_global = function_id == state.hbc_reader.header.globalCodeIndex 35 | 36 | # Used within FunctionTableIndex.closure_decompile to 37 | # provide extra context about the current function: 38 | for key, value in kwargs.items(): 39 | setattr(dehydrated, key, value) 40 | 41 | if dehydrated.function_object.hasExceptionHandler: 42 | dehydrated.exc_handlers = state.hbc_reader.function_id_to_exc_handlers[function_id] 43 | 44 | pass1_set_metadata(state, dehydrated) 45 | 46 | pass2_transform_code(state, dehydrated) 47 | 48 | pass3_parse_forin_loops(state, dehydrated) 49 | 50 | pass4_name_closure_vars(state, dehydrated) 51 | 52 | dehydrated.output_code(state) 53 | 54 | 55 | def do_decompilation(state : HermesDecompiler, file_handle): 56 | 57 | hbc_reader = HBCReader() 58 | state.hbc_reader = hbc_reader 59 | 60 | state.hbc_reader.read_whole_file(file_handle) 61 | 62 | state.calldirect_function_ids = set() 63 | 64 | global_function_index = state.hbc_reader.header.globalCodeIndex 65 | 66 | state.indent_level = 0 67 | decompile_function(state, global_function_index) 68 | print() 69 | 70 | for function_id in sorted(state.calldirect_function_ids): 71 | decompile_function(state, function_id) 72 | print() 73 | 74 | def main(): 75 | 76 | args = ArgumentParser() 77 | 78 | args.add_argument('input_file') 79 | args.add_argument('output_file', nargs = '?') 80 | 81 | args = args.parse_args() 82 | 83 | state = HermesDecompiler() 84 | state.input_file = args.input_file 85 | state.output_file = args.output_file 86 | 87 | with open(state.input_file, 'rb') as file_handle: 88 | if state.output_file: 89 | stdout = sys.stdout 90 | with open(state.output_file, 'w', encoding='utf-8') as sys.stdout: 91 | do_decompilation(state, file_handle) 92 | sys.stdout = stdout 93 | 94 | print() 95 | print('[+] Decompiled output wrote to "%s"' % state.output_file) 96 | print() 97 | else: 98 | sys.stdout.reconfigure(encoding='utf-8') 99 | do_decompilation(state, file_handle) 100 | 101 | if __name__ == '__main__': 102 | 103 | main() 104 | -------------------------------------------------------------------------------- /src/decompilation/pass1_set_metadata.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Tuple, Dict, Set, Sequence, Union, Optional, Any 4 | from os.path import dirname, realpath 5 | from collections import defaultdict 6 | 7 | from defs import HermesDecompiler, BasicBlock, DecompiledFunctionBody 8 | from hbc_bytecode_parser import parse_hbc_bytecode 9 | 10 | 11 | def pass1_set_metadata(state : HermesDecompiler, function_body : DecompiledFunctionBody): 12 | 13 | function_body.function_name = state.hbc_reader.strings[function_body.function_object.functionName] 14 | function_body.nested_frames = [] 15 | function_body.ret_anchors = {} 16 | function_body.throw_anchors = {} 17 | function_body.jump_anchors = {} 18 | function_body.jump_targets = set() 19 | 20 | # Record the addresses for the try_*, catch_* addresses within code 21 | 22 | function_body.try_starts = defaultdict(list) 23 | function_body.try_ends = defaultdict(list) 24 | function_body.catch_targets = defaultdict(list) 25 | if function_body.function_object.hasExceptionHandler: 26 | for handler_count, handler in enumerate(function_body.exc_handlers): 27 | function_body.try_starts[handler.start].append('try_start_%d' % handler_count) 28 | function_body.try_ends[handler.end].append('try_end%d' % handler_count) 29 | function_body.catch_targets[handler.target].append('catch_target%d' % handler_count) 30 | 31 | # As well as Jump, Switch, Yield 32 | 33 | for instruction in parse_hbc_bytecode(function_body.function_object, state.hbc_reader): 34 | 35 | if (instruction.inst.name[0] == 'J' or 36 | instruction.inst.name.startswith('SaveGenerator')): 37 | 38 | function_body.jump_anchors[instruction.next_pos] = instruction 39 | function_body.jump_targets.add(instruction.original_pos + instruction.arg1) 40 | 41 | elif instruction.inst.name == 'SwitchImm': 42 | 43 | function_body.jump_anchors[instruction.next_pos] = instruction 44 | function_body.jump_targets.add(instruction.original_pos + instruction.arg3) 45 | for jump_target in instruction.switch_jump_table: 46 | function_body.jump_targets.add(jump_target) 47 | 48 | elif instruction.inst.name == 'Ret': 49 | 50 | function_body.ret_anchors[instruction.next_pos] = instruction 51 | 52 | elif instruction.inst.name == 'Throw': 53 | 54 | function_body.throw_anchors[instruction.next_pos] = instruction 55 | 56 | """ 57 | Make basic blocks out of assembly 58 | """ 59 | 60 | error_handlers = (state.hbc_reader.function_id_to_exc_handlers[function_body.function_id] 61 | if function_body.function_object.hasExceptionHandler else []) 62 | 63 | basic_block_boundaries = ({0} | 64 | function_body.try_starts.keys() | function_body.try_ends.keys() | function_body.catch_targets.keys() | 65 | function_body.jump_anchors.keys() | function_body.ret_anchors.keys() | function_body.throw_anchors.keys() | 66 | function_body.jump_targets) 67 | 68 | basic_blocks = function_body.basic_blocks = [] 69 | 70 | start_to_basic_block : Dict[int, BasicBlock] = {} 71 | end_to_basic_block : Dict[int, BasicBlock] = {} 72 | 73 | # Create the basic blocks that will constitute the control 74 | # flow graph for the current function 75 | 76 | basic_block_start = 0 77 | may_have_fallen_through : bool = False 78 | for basic_block_end in sorted(basic_block_boundaries)[1:]: 79 | 80 | basic_block = BasicBlock() 81 | basic_block.start_address = basic_block_start 82 | basic_block.end_address = basic_block_end 83 | 84 | start_to_basic_block[basic_block_start] = basic_block 85 | end_to_basic_block[basic_block_end] = basic_block 86 | 87 | basic_block.child_nodes = [] 88 | basic_block.parent_nodes = [] 89 | basic_block.error_handling_child_nodes = [] 90 | basic_block.error_handling_parent_nodes = [] 91 | 92 | if may_have_fallen_through: 93 | basic_block.parent_nodes.append(basic_blocks[-1]) 94 | basic_blocks[-1].child_nodes.append(basic_block) 95 | 96 | may_have_fallen_through = True 97 | if basic_block_end in function_body.ret_anchors: 98 | may_have_fallen_through = False 99 | basic_block.anchor_instruction = function_body.ret_anchors[basic_block_end] 100 | basic_block.is_unconditional_return_end = True 101 | elif basic_block_end in function_body.throw_anchors: 102 | may_have_fallen_through = False 103 | basic_block.anchor_instruction = function_body.throw_anchors[basic_block_end] 104 | basic_block.is_unconditional_throw_anchor = True 105 | elif basic_block_end in function_body.jump_anchors: 106 | op = function_body.jump_anchors[basic_block_end] 107 | basic_block.anchor_instruction = op 108 | op_name = op.inst.name 109 | if op_name in ('Jmp', 'JmpLong'): 110 | may_have_fallen_through = False 111 | basic_block.jump_targets_for_anchor = [op.original_pos + op.arg1] 112 | basic_block.is_unconditional_jump_anchor = True 113 | elif op_name == 'SwitchImm': 114 | may_have_fallen_through = False 115 | basic_block.jump_targets_for_anchor = sorted({op.original_pos + op.arg3, *op.switch_jump_table}) 116 | basic_block.if_switch_action_anchor = True 117 | elif op_name in ('SaveGenerator', 'SaveGeneratorLong'): 118 | may_have_fallen_through = True 119 | basic_block.jump_targets_for_anchor = [op.original_pos + op.arg1] 120 | basic_block.is_yield_action_anchor = True 121 | elif op_name[0] == 'J': 122 | may_have_fallen_through = True 123 | basic_block.jump_targets_for_anchor = [op.original_pos + op.arg1] 124 | basic_block.is_conditional_jump_anchor = True 125 | else: 126 | raise ValueError 127 | 128 | basic_blocks.append(basic_block) 129 | 130 | basic_block_start = basic_block_end 131 | 132 | for basic_block in basic_blocks: 133 | if basic_block.jump_targets_for_anchor: 134 | 135 | # Link graphes between these in case of 136 | # jump/switch/yield instructions 137 | 138 | for jump_target in basic_block.jump_targets_for_anchor: 139 | jump_target_block = start_to_basic_block[jump_target] 140 | if jump_target_block not in basic_block.child_nodes: 141 | basic_block.child_nodes.append(jump_target_block) 142 | if basic_block not in jump_target_block.parent_nodes: 143 | jump_target_block.parent_nodes.append(basic_block) 144 | 145 | # Link graphes between these when error 146 | # handling is present 147 | 148 | for error_handler in error_handlers: 149 | if ((basic_block.start_address <= error_handler.start < basic_block.end_address) or 150 | (basic_block.start_address < error_handler.end <= basic_block.end_address)): 151 | 152 | error_handler_block = start_to_basic_block[error_handler.target] 153 | 154 | if error_handler_block not in basic_block.error_handling_child_nodes: 155 | basic_block.error_handling_child_nodes.append(error_handler_block) 156 | if basic_block not in error_handler_block.error_handling_parent_nodes: 157 | error_handler_block.error_handling_parent_nodes.append(basic_block) 158 | 159 | # WIP... 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /src/decompilation/pass3_parse_forin_loops.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Tuple, Dict, Set, Sequence, Union, Optional, Any 4 | from os.path import dirname, realpath 5 | from dataclasses import dataclass 6 | 7 | from defs import HermesDecompiler, DecompiledFunctionBody, NestedFrame, Environment, TokenString, ForInLoopInit, ForInLoopNextIter, RawToken, ReturnDirective, ThrowDirective, JumpNotCondition, JumpCondition, AssignmentToken, BasicBlock, LeftParenthesisToken, RightHandRegToken, RightParenthesisToken, LeftHandRegToken, NewEnvironmentToken, StoreToEnvironment, GetEnvironmentToken, LoadFromEnvironmentToken, FunctionTableIndex 8 | 9 | def pass3_parse_forin_loops(state : HermesDecompiler, function_body : DecompiledFunctionBody): 10 | 11 | JNC = JumpNotCondition # Forward jumps 12 | JC = JumpCondition # Backwards jumps 13 | 14 | RD = ReturnDirective 15 | TD = ThrowDirective 16 | 17 | AT = AssignmentToken 18 | 19 | TS = TokenString 20 | RT = RawToken 21 | LHRT = LeftHandRegToken 22 | RHRT = RightHandRegToken 23 | 24 | FILI = ForInLoopInit 25 | FILNI = ForInLoopNextIter 26 | 27 | LPT = LeftParenthesisToken 28 | RPT = RightParenthesisToken 29 | 30 | # Implementation for recreating "for..in" structures (see the .odt notes) 31 | 32 | lines = function_body.statements 33 | 34 | for index, line in enumerate(lines): 35 | # Seek for a GetPNameList instruction 36 | has_fili = line.tokens and isinstance(line.tokens[0], FILI) 37 | 38 | if has_fili: 39 | 40 | # Seek for a GetNextPName instruction further it 41 | other_index = next((other_index 42 | for other_index in range(index, len(lines)) 43 | if isinstance(lines[other_index].tokens[0], FILNI)), None) 44 | assert other_index 45 | 46 | # The beginning point of the loop's inner basic block 47 | # will be: 48 | begin_address = lines[index + 2].assembly[0].original_pos 49 | 50 | if (isinstance(lines[index + 1].tokens[0], JC) and 51 | isinstance(lines[other_index + 1].tokens[0], JC)): 52 | 53 | # There is a nested loop and we're going to an 54 | # instruction located backwards in the HBC after 55 | # the end of the current for..in loop (hence the JC 56 | # rather than JNC token in our intermediate 57 | # representation), manage to find the end of the 58 | # current basic block through iterating over code 59 | 60 | continue # Commented yet: Show not to always work 61 | 62 | """ 63 | for further_index in range(other_index + 2, len(lines)): 64 | 65 | if (isinstance(lines[further_index].tokens[0], JC) and 66 | lines[further_index].tokens[0].target_address == begin_address and 67 | lines[further_index].tokens[1] == RT('true')): 68 | 69 | # We've found an unconditional backwards jump towards 70 | # the beginning of the loop, close the current basic 71 | # block 72 | break 73 | 74 | if (isinstance(lines[further_index].tokens[0], RD) or 75 | isinstance(lines[further_index].tokens[0], TD)): 76 | 77 | # We've found either a "return" or a "throw" 78 | # instruction, likely located after a conditional 79 | # jump towards the beginning of the current basic 80 | # block, close the current basic block 81 | break 82 | 83 | end_address = lines[further_index + 1].assembly[0].original_pos 84 | """ 85 | 86 | else: 87 | 88 | # There is no nested loop and we're having the end 89 | # address of the current loop located directly in 90 | # the first conditional jump located after the 91 | # respective GetPNameList and GetNextPName 92 | # instructions within the original HBC 93 | 94 | end_address = lines[other_index + 1].tokens[0].target_address 95 | 96 | assert isinstance(lines[index + 1].tokens[0], JNC) 97 | assert isinstance(lines[other_index + 1].tokens[0], JNC) 98 | 99 | boundary_1 = lines[index + 1].tokens[0].target_address 100 | boundary_2 = lines[other_index + 1].tokens[0].target_address 101 | 102 | min_boundary = min(boundary_1, boundary_2) 103 | max_boundary = max(boundary_1, boundary_2) 104 | if min_boundary != max_boundary: 105 | weird_case = False 106 | for further_index in range(other_index + 2, len(lines)): 107 | if min_boundary <= lines[further_index].assembly[0].original_pos < max_boundary: 108 | weird_case = True 109 | # lines[further_index].tokens.insert(0, RT('// NOTE: Orphan basic block present beween two condition branches automatically created upon For..in loop: ')) 110 | break 111 | if weird_case: 112 | continue 113 | 114 | function_body.nested_frames.append( 115 | NestedFrame( 116 | begin_address, 117 | end_address 118 | ) 119 | ) 120 | 121 | line.tokens = [RT('for'), LPT(), LHRT(lines[other_index].tokens[0].next_value_register), 122 | RT(' in '), RHRT(line.tokens[0].obj_register), RPT()] 123 | lines[index + 1].tokens = [] 124 | lines[other_index].tokens = [] 125 | lines[other_index + 1].tokens = [] 126 | 127 | continue 128 | -------------------------------------------------------------------------------- /src/decompilation/pass4_name_closure_vars.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Tuple, Dict, Set, Sequence, Union, Optional, Any 4 | from sys import stderr 5 | 6 | from defs import HermesDecompiler, DecompiledFunctionBody, Environment, TokenString, ForInLoopInit, ForInLoopNextIter, RawToken, ReturnDirective, ThrowDirective, JumpNotCondition, JumpCondition, AssignmentToken, BasicBlock, LeftParenthesisToken, RightHandRegToken, RightParenthesisToken, LeftHandRegToken, NewInnerEnvironmentToken, NewEnvironmentToken, StoreToEnvironment, GetEnvironmentToken, LoadFromEnvironmentToken, FunctionTableIndex 7 | 8 | # Implementation for the "NameNonLocalClosureVariables" algorithm (see the .odt notes) 9 | 10 | """ 11 | NOTES about the original Hermes `lib/VM/Interpreter.cpp` file 12 | handling instructions such as `GetEnvironment`, `CreateEnvironment`, 13 | `StoreToEnvironment`, `LoadFromEnvironment`: 14 | - "FRAME.getCalleeClosureUnsafe()->getEnvironment(runtime)" 15 | ^ This seems to fetch the operand 2 of Call* calls 16 | containing a closure reference for the current function 17 | - "curEnv->getParentEnvironment(runtime)" 18 | ^ This fetches the environement that was to the current 19 | function's passed-environment at the point of creating 20 | `curEnv` (through indirecting a linked list), or likely 21 | the caller's environment 22 | """ 23 | 24 | def pass4_name_closure_vars(state : HermesDecompiler, function_body : DecompiledFunctionBody): 25 | 26 | AT = AssignmentToken 27 | 28 | TS = TokenString 29 | RT = RawToken 30 | LHRT = LeftHandRegToken 31 | RHRT = RightHandRegToken 32 | 33 | function_body.local_items : Dict[int, Environment] = {} 34 | 35 | parent_environment = function_body.parent_environment 36 | 37 | lines = function_body.statements 38 | for index, line in enumerate(lines): 39 | for token in line.tokens: 40 | 41 | if isinstance(token, NewEnvironmentToken): 42 | 43 | function_body.local_items[token.register] = Environment(parent_environment, (parent_environment.nesting_quantity + 1) if parent_environment else 0, {}) 44 | line.tokens = [] # Silence this instruction in the produced decompiled code 45 | 46 | elif isinstance(token, NewInnerEnvironmentToken): 47 | 48 | outer_environment = function_body.local_items[token.parent_register] 49 | function_body.local_items[token.dest_register] = Environment(outer_environment, (outer_environment.nesting_quantity + 1), {}) 50 | 51 | elif isinstance(token, GetEnvironmentToken): 52 | 53 | environment = parent_environment 54 | for nesting in range(token.nesting_level): 55 | environment = environment.parent_environment 56 | 57 | function_body.local_items[token.register] = environment 58 | line.tokens = [] # Silence this instruction in the produced decompiled code 59 | 60 | elif isinstance(token, FunctionTableIndex): 61 | 62 | if token.environment_id is not None: 63 | token.parent_environment = function_body.local_items[token.environment_id] 64 | 65 | elif isinstance(token, StoreToEnvironment): 66 | varname = '_closure%d_slot%d' % (function_body.local_items[token.env_register].nesting_quantity, 67 | token.slot_index) 68 | 69 | if token.slot_index not in function_body.local_items[token.env_register].slot_index_to_varname: 70 | function_body.local_items[token.env_register].slot_index_to_varname[token.slot_index] = varname 71 | line.tokens = [RT('var ' + varname), AT(), RHRT(token.value_register)] 72 | 73 | else: # This a closure-referenced variable reassignment 74 | line.tokens = [RT(varname), AT(), RHRT(token.value_register)] 75 | 76 | elif isinstance(token, LoadFromEnvironmentToken): 77 | var_name = '_closure%d_slot%d' % (function_body.local_items[token.register].nesting_quantity, 78 | token.slot_index) 79 | 80 | line.tokens[2] = RT(var_name) 81 | -------------------------------------------------------------------------------- /src/disassembly/hbc_disassembler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Dict, Set, Optional, Any, Sequence 4 | from os.path import dirname, realpath 5 | from argparse import ArgumentParser 6 | from json import dumps 7 | import sys 8 | 9 | DISASSEMBLY_DIR = dirname(realpath(__file__)) 10 | ROOT_DIR = realpath(DISASSEMBLY_DIR + '/..') 11 | PARSERS_DIR = realpath(ROOT_DIR + '/parsers') 12 | sys.path.insert(0, PARSERS_DIR) 13 | 14 | from hbc_bytecode_parser import parse_hbc_bytecode 15 | from hbc_file_parser import HBCReader, StringKind 16 | 17 | 18 | def do_disassemble(input_file : str): 19 | 20 | 21 | with open(input_file, 'rb') as file_descriptor: 22 | 23 | hbc_reader = HBCReader() 24 | 25 | hbc_reader.read_whole_file(file_descriptor) 26 | 27 | """ 28 | output_json_data : Dict[int, dict] = {} 29 | 30 | identifier_count = 0 31 | for string_count, (string_kind, string) in enumerate(zip(hbc_reader.string_kinds, hbc_reader.strings)): 32 | 33 | obj = hbc_reader.small_string_table[string_count] 34 | 35 | output_json_data[string_count] = { 36 | 'type': { 37 | StringKind.String: 'string', 38 | StringKind.Identifier: 'identifier', 39 | StringKind.Predefined: 'predefined' 40 | }[string_kind], 41 | 'value': string, 42 | 'is_utf16': bool(obj.isUTF16) 43 | } 44 | 45 | print('{') 46 | print(',\n'.join( 47 | ' %d: %s' % (key, dumps(value)) 48 | for key, value in sorted(output_json_data.items()) 49 | )) 50 | print('}') 51 | """ 52 | # WIP ..² 53 | 54 | # TODO : Print the JSON data generated above, one line per entry I guess? 55 | 56 | for function_count, function_header in enumerate(hbc_reader.function_headers): 57 | # pretty_print_structure(function_header) 58 | exception_info = '' 59 | if function_header.hasExceptionHandler: 60 | exception_data = hbc_reader.function_id_to_exc_handlers[function_count] 61 | exception_info = '\n [Exception handlers:' 62 | for exception_item in exception_data: 63 | exception_info += ' [start=' + hex(exception_item.start) + ', ' 64 | exception_info += 'end=' + hex(exception_item.end) + ', ' 65 | exception_info += 'target=' + hex(exception_item.target) + ']' 66 | exception_info += ' ]' 67 | 68 | debug_info = '' 69 | if function_header.hasDebugInfo: 70 | debug_data = hbc_reader.function_id_to_debug_offsets[function_count] 71 | debug_info = '\n [Debug offsets: ' 72 | debug_info += 'source_locs=' + hex(debug_data.source_locations) + ', ' 73 | debug_info += 'scope_desc_data=' + hex(debug_data.scope_desc_data) + ']' 74 | 75 | print('=> [Function #%d "%s" of %d bytes]: %d params, frame size=%d, env size=%d, read index sz=%d, write index sz=%d, strict=%r, exc handler=%r, debug info=%r @ offset 0x%08x%s%s' % ( 76 | 77 | function_count, 78 | hbc_reader.strings[function_header.functionName], 79 | function_header.bytecodeSizeInBytes, 80 | function_header.paramCount, 81 | function_header.frameSize, 82 | function_header.environmentSize, 83 | function_header.highestReadCacheIndex, 84 | function_header.highestWriteCacheIndex, 85 | function_header.strictMode, 86 | function_header.hasExceptionHandler, 87 | function_header.hasDebugInfo, 88 | 89 | function_header.offset, 90 | exception_info, 91 | debug_info)) 92 | 93 | print() 94 | print('Bytecode listing:') 95 | print() 96 | for instruction in parse_hbc_bytecode(function_header, hbc_reader): 97 | print('==>', repr(instruction)) 98 | print() 99 | print() 100 | print('=' * 15) 101 | print() 102 | 103 | # Safety checks: 104 | assert function_header.unused == 0 and function_header.paramCount < 100 105 | 106 | 107 | def main(): 108 | 109 | # TODO : Make an actual CLI with extra options here .. 110 | 111 | args = ArgumentParser() 112 | 113 | args.add_argument('input_file') 114 | args.add_argument('output_file', nargs = '?') # , default = '/dev/stdout' 115 | 116 | args = args.parse_args() 117 | 118 | if args.output_file: 119 | stdout = sys.stdout 120 | with open(args.output_file, 'w', encoding='utf-8') as sys.stdout: 121 | do_disassemble(args.input_file) 122 | sys.stdout = stdout 123 | 124 | print() 125 | print('[+] Disassembly output wrote to "%s"' % args.output_file) 126 | print() 127 | 128 | else: 129 | sys.stdout.reconfigure(encoding='utf-8') 130 | do_disassemble(args.input_file) 131 | 132 | if __name__ == '__main__': 133 | 134 | main() 135 | -------------------------------------------------------------------------------- /src/parsers/debug_info_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Dict, Set, Sequence, Union, Optional, Any 4 | from io import BytesIO 5 | 6 | def read_varint(buf : BytesIO) -> Optional[int]: # From "decodeSLEB128" in the LLVH source code 7 | 8 | result = 0 9 | shift = 0 10 | byte = None 11 | 12 | while True: 13 | read = buf.read(1) 14 | if not read: 15 | break 16 | byte = read[0] 17 | result |= (byte & 0x7f) << shift 18 | shift += 7 19 | if not byte & 0x80: 20 | break 21 | 22 | if byte is None: 23 | return None 24 | 25 | # Sign-extend and convert if the result is negative 26 | if byte & 0x40: 27 | result = int.from_bytes( 28 | (((-1 << shift) | result) & 0xffffffff_ffffffff).to_bytes(8, 'little', signed = False), 29 | 'little', signed = True) 30 | 31 | return result 32 | 33 | def print_debug_info(buf : BytesIO, version : int): 34 | 35 | while True: 36 | function_index = read_varint(buf) 37 | if function_index is None: 38 | break 39 | current_line = read_varint(buf) 40 | current_column = read_varint(buf) 41 | 42 | print() 43 | print('Function index:', function_index) 44 | print('Start line:', current_line) 45 | print('Start column:', current_column) 46 | 47 | current_address = 0 48 | current_statement = 0 49 | 50 | while True: 51 | address_delta = read_varint(buf) 52 | if address_delta in (-1, None): 53 | break 54 | line_delta = read_varint(buf) 55 | column_delta = read_varint(buf) 56 | if version >= 94: 57 | scope_address = read_varint(buf) 58 | env_register = read_varint(buf) 59 | statement_delta = 0 60 | if line_delta & 1: 61 | statement_delta = read_varint(buf) 62 | line_delta >>= 1 63 | 64 | current_address += address_delta 65 | current_line += line_delta 66 | current_column += column_delta 67 | current_statement += statement_delta 68 | 69 | if version >= 94: 70 | print(' Address %d: Line %d - Column %d - Statement %d - Scope address %d - Env register %d' % ( 71 | current_address, current_line, 72 | current_column, current_statement, 73 | scope_address, env_register)) 74 | else: 75 | print(' Address %d: Line %d - Column %d - Statement %d' % ( 76 | current_address, current_line, 77 | current_column, current_statement)) 78 | 79 | # print(' Address delta:', address_delta) 80 | # print(' Line delta:', line_delta) 81 | # print(' Column delta:', column_delta) 82 | # print(' Statement delta:', statement_delta) 83 | 84 | print() 85 | 86 | # WIP .. 87 | -------------------------------------------------------------------------------- /src/parsers/hbc_bytecode_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Dict, Set, Sequence, Union, Optional, Iterator, Any 4 | from logging import warning 5 | from io import BytesIO 6 | 7 | # Imports relative to the current directory: 8 | from hbc_opcodes import hbc51, hbc58, hbc59, hbc61, hbc62, hbc68, hbc69, hbc70, hbc72, hbc73, hbc76, hbc80, hbc81, hbc82, hbc83, hbc84, hbc85, hbc86, hbc87, hbc89, hbc90, hbc92, hbc95 9 | from serialized_literal_parser import unpack_slp_array, SLPArray, SLPValue, TagType 10 | from hbc_opcodes.def_classes import OperandMeaning, Instruction 11 | 12 | class ParsedInstruction: 13 | inst : Instruction 14 | arg1 : object 15 | arg2 : object 16 | arg3 : object 17 | arg4 : object 18 | arg5 : object 19 | arg6 : object 20 | switch_jump_table : Optional[List[int]] 21 | original_pos : int 22 | next_pos : int 23 | hbc_reader : 'HBCReader' 24 | 25 | def __repr__(self): 26 | operands = [ 27 | '%s: %s' % ( 28 | 29 | (self.inst.operands[index].operand_meaning.name 30 | if self.inst.operands[index].operand_meaning 31 | else self.inst.operands[index].operand_type.name), 32 | getattr(self, 'arg%d' % (index + 1)) 33 | ) 34 | for index in range(len(self.inst.operands)) 35 | ] 36 | 37 | comment = '' 38 | for operand_index, operand in enumerate(self.inst.operands): 39 | if operand.operand_meaning: 40 | operand_value = getattr(self, 'arg%d' % (operand_index + 1)) 41 | if operand.operand_meaning == OperandMeaning.string_id: 42 | comment += ' # String: %r (%s)' % ( 43 | self.hbc_reader.strings[operand_value], 44 | self.hbc_reader.string_kinds[operand_value].name 45 | ) 46 | elif operand.operand_meaning == OperandMeaning.bigint_id: 47 | comment += ' # BigInt: %s' % ( 48 | self.hbc_reader.bigint_values[operand_value] 49 | ) 50 | elif operand.operand_meaning == OperandMeaning.function_id: 51 | function_header = self.hbc_reader.function_headers[operand_value] 52 | comment += ' # Function: [#%d %s of %d bytes]: %d params @ offset 0x%08x' % ( 53 | operand_value, 54 | self.hbc_reader.strings[function_header.functionName], 55 | function_header.bytecodeSizeInBytes, 56 | function_header.paramCount, 57 | function_header.offset) 58 | elif operand.operand_type.name in ('Addr8', 'Addr32'): 59 | operand_value = getattr(self, 'arg%d' % (operand_index + 1)) 60 | comment += ' # Address: %08x' % (self.original_pos + operand_value) 61 | if self.inst.name in ('NewArrayWithBuffer', 'NewArrayWithBufferLong'): 62 | comment += ' # Array: [%s]' % ', '.join(unpack_slp_array( 63 | self.hbc_reader.arrays[self.arg4:], self.arg3).to_strings(self.hbc_reader.strings)) 64 | elif self.inst.name in ('NewObjectWithBuffer', 'NewObjectWithBufferLong'): 65 | comment += ' # Object: {%s}' % ', '.join('%s: %s' % (key, value) 66 | for key, value in zip( 67 | unpack_slp_array( 68 | self.hbc_reader.object_keys[self.arg4:], self.arg3).to_strings(self.hbc_reader.strings), 69 | unpack_slp_array( 70 | self.hbc_reader.object_values[self.arg5:], self.arg3).to_strings(self.hbc_reader.strings) 71 | ) 72 | ) 73 | elif self.inst.name in ('CallBuiltin', 'CallBuiltinLong', 'GetBuiltinClosure'): 74 | builtin_number = self.arg2 75 | builtin_functions = get_builtin_functions(self.hbc_reader.parser_module) 76 | comment += ' # Built-in function: [#%d %s]' % (builtin_number, builtin_functions[builtin_number]) 77 | elif self.inst.name == 'SwitchImm': 78 | comment += ' # Jump table: [%s]' % ', '.join('%08x' % value for value in 79 | self.switch_jump_table) 80 | 81 | return f'{"%08x" % self.original_pos}: <{self.inst.name}>: <{", ".join(operands)}>{comment}' 82 | 83 | def get_parser(bytecode_version : int) -> 'module': 84 | parser_module_tbl = { 85 | 51: hbc51, 86 | 58: hbc58, 87 | 59: hbc59, 88 | 61: hbc61, 89 | 62: hbc62, 90 | 68: hbc68, 91 | 69: hbc69, 92 | 70: hbc70, 93 | # Before version 72/0.4.0, the bytecode format used predefined 94 | # string identifiers (which were removed in commit 63fb517) 95 | # These are not supported in the current code setup 96 | 72: hbc72, 97 | 73: hbc73, 98 | 76: hbc76, 99 | 80: hbc80, 100 | 81: hbc81, 101 | 82: hbc82, 102 | 83: hbc83, 103 | 84: hbc84, 104 | 85: hbc85, 105 | 86: hbc86, 106 | 87: hbc87, 107 | 89: hbc89, 108 | 90: hbc90, 109 | 92: hbc92, 110 | # The changes introduced in Hermes bytecode version 92 111 | # were reverted to the state of version 91 after a few 112 | # days from their introduction in the Git tree, into a 113 | # new version 93, and reintroduced in version 94. 114 | 93: hbc90, 115 | 94: hbc92, 116 | 95: hbc95 117 | } 118 | 119 | if bytecode_version < 72: 120 | warning('This file uses an ancient Hermes bytecode format, which ' + 121 | 'is not supported.') 122 | 123 | elif bytecode_version > 96: 124 | warning(('Bytecode version %d corresponds to a development or ' + 125 | 'recent version of the Hermes bytecode and is not ' + 126 | 'formally supported by the current tool.') % bytecode_version) 127 | 128 | for min_version in reversed(sorted(parser_module_tbl)): 129 | if bytecode_version >= min_version: 130 | parser_module = parser_module_tbl[min_version] 131 | break 132 | 133 | return parser_module 134 | 135 | def get_builtin_functions(parser_module : 'module') -> List[str]: 136 | 137 | return parser_module._builtin_function_names 138 | 139 | # Read and parse the actual bytecode (+ switch tables) for 140 | # a given function header 141 | 142 | def parse_hbc_bytecode(function_header : object, hbc_reader : 'HBCReader') -> Iterator[Instruction]: 143 | 144 | hbc_reader.file_buffer.seek(function_header.offset) 145 | 146 | buf = BytesIO(hbc_reader.file_buffer.read(function_header.bytecodeSizeInBytes)) 147 | 148 | while True: 149 | original_pos = buf.tell() 150 | 151 | opcode = buf.read(1) 152 | if not opcode: 153 | break 154 | opcode = opcode[0] 155 | 156 | inst = hbc_reader.parser_module._opcode_to_instruction.get(opcode) 157 | if not inst: 158 | raise NotImplementedError('Opcode "0x%02x" is currently not implemented within hermes-dec.' % opcode) 159 | 160 | structure = inst.structure() 161 | buf.readinto(structure) 162 | 163 | result = ParsedInstruction() 164 | result.inst = inst 165 | result.original_pos = original_pos 166 | result.next_pos = original_pos + inst.binary_size 167 | result.hbc_reader = hbc_reader 168 | 169 | for operand in ('arg1', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6'): 170 | if hasattr(structure, operand): 171 | setattr(result, operand, getattr(structure, operand)) 172 | 173 | if inst.name == 'SwitchImm': 174 | result.switch_jump_table = [] 175 | hbc_reader.file_buffer.seek(function_header.offset + original_pos + structure.arg2) 176 | hbc_reader.align_over_padding() 177 | 178 | for jump_table_entry in range(structure.arg4, structure.arg5 + 1): 179 | result.switch_jump_table.append(int.from_bytes( 180 | hbc_reader.file_buffer.read(4), 'little') + original_pos) 181 | 182 | yield result 183 | -------------------------------------------------------------------------------- /src/parsers/hbc_opcodes/def_classes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from ctypes import LittleEndianStructure, _SimpleCData, sizeof, c_double, c_int8, c_int32, c_uint8, c_uint16, c_uint32 4 | from typing import List, Dict, Sequence, Set, Tuple, Optional, Union, Any 5 | from dataclasses import dataclass 6 | from enum import Enum 7 | 8 | class OperandType: 9 | name : str 10 | c_type : _SimpleCData 11 | 12 | def __init__(self, name : str, c_type : str): 13 | 14 | self.name = name 15 | self.c_type = { 16 | 'int8_t': c_int8, 17 | 'int32_t': c_int32, 18 | 'uint8_t': c_uint8, 19 | 'uint16_t': c_uint16, 20 | 'uint32_t': c_uint32, 21 | 'double': c_double 22 | }[c_type] 23 | 24 | class OperandMeaning(Enum): 25 | bigint_id = 1 26 | function_id = 2 27 | string_id = 3 28 | 29 | @dataclass 30 | class Operand: 31 | operand_type : OperandType 32 | operand_meaning : Optional[OperandMeaning] 33 | 34 | class Instruction: 35 | name : str 36 | opcode : int 37 | operands : List[Operand] 38 | structure : LittleEndianStructure 39 | binary_size : int 40 | has_ret_target : bool 41 | 42 | def __init__(self, name : str, opcode : int, args : List[OperandType], module_ref : 'module'): 43 | 44 | self.name = name 45 | self.opcode = opcode 46 | self.operands = [Operand(arg, None) for arg in args] 47 | self.has_ret_target = False 48 | 49 | module_ref['_instructions'].append(self) 50 | 51 | self.structure = type(name, (LittleEndianStructure, ), dict( 52 | _pack_ = True, 53 | _fields_ = [ 54 | ('arg%d' % (pos + 1), operand.c_type) 55 | for pos, operand in enumerate(args) 56 | ] 57 | )) 58 | 59 | self.binary_size = 1 + sizeof(self.structure) 60 | -------------------------------------------------------------------------------- /src/parsers/pretty_print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | 4 | from collections import OrderedDict 5 | 6 | 7 | """ 8 | Turn a parsed C structure in a dict of human-readable key-value 9 | pairs, for displayal in ASCII tables 10 | 11 | :param ctypes_structure: A parsed ctypes structures to consume. 12 | 13 | :returns An OrderedDict of strings/strings. 14 | """ 15 | 16 | def structure_to_key_values_strings(ctypes_structure): 17 | 18 | key_values = OrderedDict() 19 | 20 | if not getattr(ctypes_structure, '_fields_', None): 21 | return key_values 22 | 23 | for key, ctype in (field[:2] for field in ctypes_structure._fields_): 24 | 25 | value = getattr(ctypes_structure, key) 26 | 27 | # Turn "key_name" into "Key name" 28 | 29 | pretty_key = key[0].upper() + key[1:] 30 | pretty_key = pretty_key.replace('_', ' ') 31 | 32 | # Stringify the value 33 | 34 | if type(value) == bytes: # Strings 35 | 36 | key_values[pretty_key] = value.decode('ascii') 37 | 38 | elif type(value) == int: # Integer 39 | 40 | # key_values[pretty_key] = '0x%08x' % value if value else 'N/A' 41 | key_values[pretty_key] = str(value) if value < (1 << 15) else hex(value) 42 | 43 | else: 44 | 45 | key_values[pretty_key] = bytes(value).hex() 46 | 47 | return key_values 48 | 49 | 50 | """ 51 | Return an ASCII table from a parsed C structure, with field names as 52 | column 1 and values as column 2. 53 | """ 54 | 55 | def pretty_print_structure(ctypes_structure): 56 | 57 | key_values = structure_to_key_values_strings(ctypes_structure) 58 | 59 | pretty_print_table(list(key_values.items())) 60 | 61 | 62 | """ 63 | Return an ascii table from a list (rows) of list (columns) of strings (cells) 64 | """ 65 | 66 | def pretty_print_table(rows): 67 | 68 | # Calculate columns length 69 | 70 | if not rows: 71 | return 72 | 73 | number_of_columns = len(rows[0]) 74 | 75 | column_to_max_length = [ 76 | 77 | max(len(row[column]) for row in rows) 78 | 79 | for column in range(number_of_columns) 80 | ] 81 | 82 | # Do a nice table 83 | 84 | print() 85 | 86 | print('+-%s-+' % '---'.join('-' * max_len for max_len in column_to_max_length)) 87 | 88 | for row in rows: 89 | 90 | print('| %s |' % ' | '.join( 91 | 92 | row[column].ljust(column_to_max_length[column]) 93 | 94 | for column in range(number_of_columns)) 95 | ) 96 | 97 | print('+-%s-+' % '---'.join('-' * max_len for max_len in column_to_max_length)) 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/parsers/serialized_literal_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from typing import List, Union, Any, Sequence, Dict, Set, Optional 4 | from dataclasses import dataclass 5 | from enum import IntEnum, IntFlag 6 | from struct import unpack 7 | from io import BytesIO 8 | 9 | """ 10 | The SerializedLiteral format is used to store structured 11 | arrays of string references and literals within the Hermes 12 | array buffer, object key buffer, object value buffer 13 | arrays. 14 | 15 | It is parsed here: 16 | 17 | https://github.com/facebook/hermes/blob/v0.12.0/lib/BCGen/HBC/BytecodeDisassembler.cpp#L285 18 | 19 | OS << "Object Key Buffer:\n"; 20 | while ((size_t)keyInd < objKeyBuffer.size()) { 21 | std::pair keyTag = 22 | checkBufferTag(objKeyBuffer.data() + keyInd); 23 | keyInd += (keyTag.first > 0x0f ? 2 : 1); 24 | for (int i = 0; i < keyTag.first; i++) { 25 | OS << SLPToString(keyTag.second, objKeyBuffer.data(), &keyInd) << "\n"; 26 | } 27 | } 28 | 29 | 30 | Strings are referred to as indexes of the global string, 31 | which are stored over either 8, 16 or 32 bits each: 32 | 33 | int ind = 34 | isKeyBuffer ? BMGen_.getIdentifierID(str) : BMGen_.getStringID(str); 35 | 36 | The binary form of this format is TLV-oriented, see: 37 | 38 | https://github.com/facebook/hermes/blob/v0.12.0/include/hermes/BCGen/HBC/SerializedLiteralGenerator.h 39 | https://github.com/facebook/hermes/blob/v0.12.0/lib/BCGen/HBC/SerializedLiteralParserBase.cpp 40 | https://github.com/facebook/hermes/blob/v0.12.0/lib/BCGen/HBC/SerializedLiteralGenerator.cpp 41 | https://github.com/facebook/hermes/blob/v0.12.0/include/hermes/BCGen/HBC/SerializedLiteralParserBase.h 42 | https://github.com/facebook/hermes/blob/v0.12.0/lib/VM/SerializedLiteralParser.cpp 43 | https://github.com/facebook/hermes/blob/v0.12.0/include/hermes/VM/SerializedLiteralParser.h 44 | """ 45 | 46 | class TagType(IntEnum): 47 | NullTag = 0 48 | TrueTag = 1 49 | FalseTag = 2 50 | NumberTag = 3 51 | LongStringTag = 4 52 | ShortStringTag = 5 53 | ByteStringTag = 6 54 | IntegerTag = 7 55 | 56 | 57 | @dataclass 58 | class SLPValue: 59 | tag_type : TagType 60 | 61 | value : object 62 | 63 | @dataclass 64 | class SLPArray: 65 | items : List[SLPValue] 66 | 67 | def to_strings(self, string_table : List[str]) -> List[str]: 68 | 69 | stringified_items : List[str] = [] 70 | for item in self.items: 71 | if item.tag_type == TagType.NullTag: 72 | string = 'null' 73 | elif item.tag_type == TagType.TrueTag: 74 | string = 'true' 75 | elif item.tag_type == TagType.FalseTag: 76 | string = 'false' 77 | elif item.tag_type == TagType.NumberTag: 78 | string = str(item.value) 79 | elif item.tag_type in (TagType.LongStringTag, 80 | TagType.ShortStringTag, TagType.ByteStringTag): 81 | string = repr(string_table[item.value]) 82 | elif item.tag_type == TagType.IntegerTag: 83 | string = str(item.value) 84 | else: 85 | raise ValueError 86 | 87 | stringified_items.append(string) 88 | 89 | return stringified_items 90 | 91 | 92 | def unpack_slp_array(data : bytes, num_items : int) -> SLPArray: 93 | data = BytesIO(data) 94 | 95 | items = [] 96 | 97 | while len(items) < num_items: 98 | values = [] 99 | 100 | next_tag = data.read(1) 101 | if not next_tag: 102 | break 103 | tag_type = TagType((next_tag[0] >> 4) & 0b111) 104 | if next_tag[0] >> 7 == 1: # Extended length flag? 105 | length = ((next_tag[0] & 0b1111) << 8) | data.read(1)[0] 106 | else: 107 | length = next_tag[0] & 0b1111 108 | 109 | for item in range(length): 110 | 111 | if tag_type == TagType.NullTag: 112 | values.append(None) 113 | elif tag_type == TagType.TrueTag: 114 | values.append(True) 115 | elif tag_type == TagType.FalseTag: 116 | values.append(False) 117 | elif tag_type == TagType.NumberTag: 118 | values.append(unpack(' sample.hermes_raw_hasm 9 | echo disassemble | ~/hermes/build/bin/hbcdump -pretty-disassemble sample.hbc > sample.hermes_pretty_hasm 10 | echo disassemble | ~/hermes/build/bin/hbcdump -objdump-disassemble sample.hbc > sample.hermes_objdump_hasm 11 | 12 | ../hbc_file_parser.py sample.hbc > sample.hermes_dec_header 13 | ../hbc_disassembler.py sample.hbc sample.hermes_dec_hasm 14 | ../hbc_decompiler.py sample.hbc sample.hermes_dec_hdec 15 | 16 | # Currently not functional: PYTHONPATH=/home/marin/atypikoo_apk/hbctool/ python3 ~/atypikoo_apk/hbctool/hbctool/__init__.py disasm sample.hbc sample.hbctool_py_hasm 17 | -------------------------------------------------------------------------------- /tests/sample.hbc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P1sec/hermes-dec/7c9d95841e2afae03b9812c64f826ef9ae7ebae7/tests/sample.hbc -------------------------------------------------------------------------------- /tests/sample.hermes_dec_hdec: -------------------------------------------------------------------------------- 1 | testx = undefined; 2 | gen = undefined; 3 | ze = undefined; 4 | r2 = async function(a0) { // Original name: testx, environment: r1 5 | r4 = undefined; 6 | r0 = undefined; 7 | r0 = arguments; 8 | r3 = r0; 9 | r2 = spawnAsync; 10 | r1 = function* (a0) { // Original name: ?anon_0_testx, environment: r0 11 | r0 = function* (a0) { // Original name: ?anon_0_?anon_0_testx, environment: r0 12 | _fun3: for(var _fun3_ip = 0; ; ) switch(_fun3_ip) { 13 | case 0: 14 | StartGenerator(); 15 | ResumeGenerator(result_out_reg=0, return_bool_out_reg=1); 16 | if(r1) { _fun3_ip = 121; continue _fun3 } 17 | case 7: 18 | r4 = global; 19 | r2 = r4.testx; 20 | r3 = r4.test2; 21 | r5 = 42; 22 | r1 = 'D+D +D\u202f+D +\nD+ÉD '; 23 | r1 = r5 + r1; 24 | r1 = r1 + r3; 25 | r3 = undefined; 26 | r1 = r2.bind(r3)(r1); 27 | SaveGenerator(address=46); 28 | case 44: 29 | return r1; 30 | case 46: 31 | ResumeGenerator(result_out_reg=1, return_bool_out_reg=2); 32 | if(r2) { _fun3_ip = 118; continue _fun3 } 33 | case 52: 34 | r2 = r4.gen; 35 | r2 = r2.bind(r3)(); 36 | SaveGenerator(address=65); 37 | case 63: 38 | return r2; 39 | case 65: 40 | ResumeGenerator(result_out_reg=2, return_bool_out_reg=5); 41 | if(r5) { _fun3_ip = 115; continue _fun3 } 42 | case 71: 43 | r7 = r4.console; 44 | r6 = r7.log; 45 | r5 = a0; 46 | r5 = r6.bind(r7)(r5); 47 | r6 = r4.console; 48 | r5 = r6.log; 49 | r4 = r4.xy; 50 | r4 = r5.bind(r6)(r4); 51 | return r3; 52 | case 115: 53 | return r2; 54 | case 118: 55 | return r1; 56 | case 121: 57 | return r0; 58 | } 59 | }; 60 | return r0; 61 | }; 62 | r0 = this; 63 | r0 = r2.bind(r4)(r1, r0, r3); 64 | return r0; 65 | }; 66 | r0 = global; 67 | r0['testx'] = r2; 68 | r2 = function* () { // Original name: gen, environment: r1 69 | r0 = function* () { // Original name: ?anon_0_gen, environment: r0 70 | _fun5: for(var _fun5_ip = 0; ; ) switch(_fun5_ip) { 71 | case 0: 72 | StartGenerator(); 73 | r2 = undefined; 74 | r3 = undefined; 75 | ResumeGenerator(result_out_reg=0, return_bool_out_reg=1); 76 | if(r1) { _fun5_ip = 176; continue _fun5 } 77 | case 14: 78 | r1 = 42; 79 | SaveGenerator(address=21); 80 | case 19: 81 | return r1; 82 | case 21: 83 | ResumeGenerator(result_out_reg=1, return_bool_out_reg=4); 84 | if(r4) { _fun5_ip = 173; continue _fun5 } 85 | case 30: // try_start_0 // try_start_1 86 | r4 = global; 87 | r4 = r4.gen; 88 | r5 = r4.bind(r2)(); 89 | r4 = r5.next; 90 | r4 = r4.bind(r5)(); 91 | case 50: // try_end0 92 | _fun5_ip = 71; continue _fun5; 93 | case 52: // catch_target0 94 | CatchBlockStart(arg_register=4); 95 | r4 = global; 96 | r5 = r4.print; 97 | r4 = 'Hello! Exception handling'; 98 | r4 = r5.bind(r2)(r4); 99 | case 71: // try_end1 100 | _fun5_ip = 170; continue _fun5; 101 | case 73: // catch_target1 102 | CatchBlockStart(arg_register=3); 103 | case 75: // try_start_2 104 | r5 = 432; 105 | r4 = 'dçdàçD°D+D'; 106 | r5 = r5 * r4; 107 | r4 = 478; 108 | r4 = r5 + r4; 109 | if(!r4) { _fun5_ip = 149; continue _fun5 } 110 | case 102: 111 | r4 = global; 112 | r6 = r4.console; 113 | r5 = r6.log; 114 | r7 = r3; 115 | r3 = 'Bon-jour : '; 116 | r4 = r3 + r7; 117 | r3 = 340000; 118 | r7 = r7 * r3; 119 | r3 = 6; 120 | r3 = r7 + r3; 121 | r3 = r5.bind(r6)(r4, r3); 122 | case 149: // try_end2 123 | _fun5_ip = 170; continue _fun5; 124 | case 151: // catch_target2 125 | CatchBlockStart(arg_register=3); 126 | r3 = global; 127 | r4 = r3.alert; 128 | r3 = 'AAAAAAAA'; 129 | r3 = r4.bind(r2)(r3); 130 | case 170: 131 | return r2; 132 | case 173: 133 | return r1; 134 | case 176: 135 | return r0; 136 | } 137 | }; 138 | return r0; 139 | }; 140 | r0['gen'] = r2; 141 | r1 = function() { // Original name: ze, environment: r1 142 | _fun6: for(var _fun6_ip = 0; ; ) switch(_fun6_ip) { 143 | case 0: 144 | r0 = undefined; 145 | r1 = global; 146 | r4 = r1.Math; 147 | r2 = r4.random; 148 | r2 = r2.bind(r4)(); 149 | if(r2) { _fun6_ip = 30; continue _fun6 } 150 | case 24: 151 | var _closure1_slot0 = r0; 152 | _fun6_ip = 52; continue _fun6; 153 | case 30: 154 | r2 = function() { // Original name: zb, environment: r3 155 | _fun7: for(var _fun7_ip = 0; ; ) switch(_fun7_ip) { 156 | case 0: 157 | r0 = global; 158 | r1 = r0.Date; 159 | r0 = r1.now; 160 | r0 = r0.bind(r1)(); 161 | if(!r0) { _fun7_ip = 33; continue _fun7 } 162 | case 20: 163 | r1 = _closure1_slot0; 164 | r0 = undefined; 165 | r0 = r1.bind(r0)(); 166 | case 33: 167 | r0 = undefined; 168 | return r0; 169 | } 170 | }; 171 | _closure1_slot0 = r2; 172 | r2 = r2.bind(r0)(); 173 | r1 = r1.ze; 174 | r1 = r1.bind(r0)(); 175 | case 52: 176 | return r0; 177 | } 178 | }; 179 | r0['ze'] = r1; 180 | r2 = r0.window; 181 | r1 = r0.ze; 182 | r2['onload'] = r1; 183 | r1 = r0.ze; 184 | r4 = undefined; 185 | r1 = r1.bind(r4)(); 186 | r1 = /dkooDD JPOD D09D\n\\ @ .\r\n\t@ \x00 D+D /gmi; 187 | r0['test2'] = r1; 188 | r3 = r0.console; 189 | r2 = r3.log; 190 | r6 = r0.test2; 191 | r5 = r6.exec; 192 | r1 = 'bonjour'; 193 | r1 = r5.bind(r6)(r1); 194 | r1 = r2.bind(r3)(r1); 195 | r5 = r0.console; 196 | r3 = r5.log; 197 | r1 = r0.gen; 198 | r2 = r1.bind(r4)(); 199 | r1 = r2.next; 200 | r2 = r1.bind(r2)(); 201 | r1 = 'a'; 202 | r1 = r3.bind(r5)(r1, r2); 203 | r3 = r0.console; 204 | r2 = r3.log; 205 | r1 = r0.testx; 206 | r5 = 7.3; 207 | r0 = 'le'; 208 | r0 = r5 + r0; 209 | r1 = r1.bind(r4)(r0); 210 | r0 = r1.next; 211 | r1 = r0.bind(r1)(); 212 | r0 = 'b'; 213 | r0 = r2.bind(r3)(r0, r1); 214 | return r0; 215 | 216 | -------------------------------------------------------------------------------- /tests/sample.js: -------------------------------------------------------------------------------- 1 | /* bigInt = -4057069294949984n 2 | console.log(bigInt) 3 | 4 | bigInt2 = -409090990090999999999999999999999939n 5 | print(bigInt2) */ 6 | 7 | async function testx(y) { 8 | await testx(42 + 'D+D +D\u202f+D +\nD+ÉD ' + test2); 9 | 10 | await gen() 11 | 12 | console.log(y) 13 | console.log(xy) 14 | } 15 | 16 | function* gen() { 17 | yield 42 18 | try { 19 | try { 20 | gen().next() 21 | } 22 | catch(e) { 23 | print('Hello! Exception handling') 24 | } 25 | } 26 | catch(e) { 27 | try { 28 | if(432 * 'dçdàçD°D+D' + 478) { 29 | console.log('Bon-jour : ' + e, e * 34e4 + 6); 30 | } 31 | } 32 | catch(b) { 33 | alert('AAAAAAAA') 34 | } 35 | } 36 | } 37 | 38 | // Recursive functions tests: 39 | function ze() { 40 | 41 | if(Math.random()) { 42 | var zb = function() { 43 | if(Date.now()) { 44 | zb(); 45 | } 46 | } 47 | 48 | zb() || ze() 49 | } 50 | } 51 | 52 | window.onload = ze; 53 | ze(); 54 | 55 | test2 = /dkooDD JPOD D09D\n\\ @ .\r\n\t@ \x00 D+D /gmi 56 | console.log(test2.exec('bonjour')) 57 | 58 | console.log('a', gen().next()) 59 | console.log('b', testx(3+4.3+'le').next()) 60 | -------------------------------------------------------------------------------- /utils/git_tags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This file is to be included by the code download scripts 4 | # present in the current subdirectories. 5 | 6 | # It contains Git tag identifiers and commit hashes for the 7 | # single Hermes bytecode versions which are supported by 8 | # the current tool. 9 | 10 | GIT_TAGS=( 11 | 'v0.0.1' # Bytecode version 51 12 | # 'v0.0.2' # Bytecode version 51 13 | 'v0.0.3' # Bytecode version 58 14 | 'v0.1.0' # Bytecode version 59 15 | # 'v0.1.1' # Bytecode version 60 - Bumped Jul 17, 2019 - No codegen change 16 | 'ee7a2db' # Bytecode version 61 - Aug 3, 2019 17 | 'v0.2.1' # Bytecode version 62 - Bumped Aug 29, 2019 18 | # '8eb5923' # Bytecode version 63 - Sep 19, 2019 19 | # '2d326de' # Bytecode version 64 - Oct 4, 2019 20 | # '28436fb' # Bytecode version 65 - Oct 4, 2019 21 | # '892bf2c' # Bytecode version 66 - Oct 4, 2019 22 | # 'f9e263d' # Bytecode version 67 - Oct 11, 2019 23 | '883eb4d' # Bytecode version 68 - Oct 15, 2019 24 | '5a402ac' # Bytecode version 69 - Oct 15, 2019 25 | '51969f2' # Bytecode version 70 - Oct 15, 2019 26 | # 'v0.3.0' # Bytecode version 71 - Bumped Oct 25, 2019, stable release Nov 11, 2019 - No codegen change 27 | 'd1637f2' # Bytecode version 72 - Nov 26, 2019 28 | 'ecded4d' # Bytecode version 73 - Dec 19, 2019 29 | # 'v0.4.0' # Bytecode version 74 - Bumped Jan 6, 2020 (there was a reverted version 75) - No codegen change 30 | # 'v0.4.1' # Bytecode version 74 31 | # 'v0.4.3' # Bytecode version 74 32 | # 'v0.4.4' # Bytecode version 74 33 | # 'v0.5.0' # Bytecode version 74 34 | # 'v0.5.1' # Bytecode version 74 35 | # 'v0.5.3' # Bytecode version 74 36 | # 'v0.6.0' # Bytecode version 74 37 | # '6871396' # Bytecode version 75 - Aug 3, 2020 - No gencode change 38 | 'v0.7.0' # Bytecode version 76 - Bumped Aug 19, 2020 39 | # 'v0.7.1' # Bytecode version 76 - Bumped Aug 19, 2020 40 | # 'v0.7.2' # Bytecode version 76 - Bumped Aug 19, 2020, stable release Dec 9, 2020 41 | # '701b9dd' # Bytecode version 77 - Oct 7, 2020 - No gencode change 42 | # 'c57fde2' # Bytecode version 78 - Oct 8, 2020 - No gencode change 43 | # '05b2972' # Bytecode version 79 - Dec 29, 2020 - No gencode change 44 | 'e70045d' # Bytecode version 80 - Jan 13, 2021 45 | '40aa0f7' # Bytecode version 81 - Jan 14, 2021 46 | '65de349' # Bytecode version 82 - Jan 26, 2021 47 | 'v0.8.0' # Bytecode version 83 - Bumped Mar 16, 2021, stable release Apr 29, 2021 48 | # 'v0.8.1' # Bytecode version 84 - Bumped Jul 10, 2021, stable release Jul 12, 2021 49 | # WebAssembly instrinsincs are added in bytecode versions 85 and 86, but the 50 | # bytecode version number is then unbumped as these have been disabled by default. 51 | 'v0.9.0' # Bytecode version 84 - Unbumped from 86 Jul 27, 2021, stable release Sep 2, 2021 52 | # 'v0.10.0' # Bytecode version 84 - Unbumped from 86 Jul 27, 2021, stable release Nov 14, 2021 53 | 'v0.11.0' # Bytecode version 85 - Bumped Mar 22, 2022, stable release Jan 27, 2022 54 | 'b823515' # Bytecode version 86 - Jun 28, 2022 55 | '41752c6' # Bytecode version 87 - Jul 9, 2022 56 | # '2a55135' # Bytecode version 88 - Jul 9, 2022 - No gencode change 57 | 'v0.12.0' # Bytecode version 89 - Bumped Jul 14, 2022, stable release Aug 24, 2022 58 | '0763eee' # Bytecode version 90 - Oct 7, 2022 59 | # '4985960' # Bytecode version 91 - Dec 18, 2022 - No gencode change 60 | 'b544ff4' # Bytecode version 92 contains a change that was reverted from the main source 61 | # tree after three days (Feb 14-17, 2023). 62 | # Bytecode version 93 is similar to bytecode version 91. 63 | # '1c71748' # Bytecode version 94 reintroduces the change from version 92 - Mar 8, 2023 64 | 'f6b56d3' # Bytecode version 95 - Mar 29, 2023 65 | # '2afc7b0' # Bytecode version 96 - Aug 29, 2023 - No gencode change, only the regex engine 66 | ) 67 | 68 | declare -A TAG_TO_VERSION=( 69 | [ee7a2db]='hbc61' 70 | [8eb5923]='hbc63' 71 | [2d326de]='hbc64' 72 | [28436fb]='hbc65' 73 | [892bf2c]='hbc66' 74 | [f9e263d]='hbc67' 75 | [883eb4d]='hbc68' 76 | [5a402ac]='hbc69' 77 | [51969f2]='hbc70' 78 | [d1637f2]='hbc72' 79 | [ecded4d]='hbc73' 80 | [6871396]='hbc75' 81 | [701b9dd]='hbc77' 82 | [c57fde2]='hbc78' 83 | [05b2972]='hbc79' 84 | [e70045d]='hbc80' 85 | [40aa0f7]='hbc81' 86 | [65de349]='hbc82' 87 | [b74eb2d]='hbc85' 88 | [b823515]='hbc86' 89 | [41752c6]='hbc87' 90 | [2a55135]='hbc88' 91 | [0763eee]='hbc90' 92 | [4985960]='hbc91' 93 | [b544ff4]='hbc92' 94 | [1c71748]='hbc94' 95 | [f6b56d3]='hbc95' 96 | ) 97 | -------------------------------------------------------------------------------- /utils/hermes_bytecode_structs_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from re import search, match, findall, sub, finditer, MULTILINE, DOTALL 4 | from typing import List, Dict, Set, Sequence, Union, Optional, Any 5 | from os.path import dirname, realpath 6 | from dataclasses import dataclass 7 | from os import listdir 8 | 9 | UTILS_DIR = dirname(realpath(__file__)) 10 | ROOT_DIR = realpath(UTILS_DIR + '/..') 11 | SRC_DIR = realpath(ROOT_DIR + '/src') 12 | PARSERS_DIR = realpath(SRC_DIR + '/parsers') 13 | 14 | git_tags = sorted( 15 | file_name.split('-')[1].split('.def')[0] 16 | for file_name in listdir(UTILS_DIR + '/original_function_builtins_c_src/') 17 | if file_name.endswith('.def') 18 | ) 19 | 20 | for git_tag in git_tags: 21 | 22 | INPUT_FILE_NAME = UTILS_DIR + '/original_hermes_bytecode_c_src/BytecodeList-%s.def' % git_tag 23 | 24 | INPUT_BUILTINS_FILE_NAMES = UTILS_DIR + '/original_function_builtins_c_src/Builtins-%s.def' % git_tag 25 | 26 | INPUT_VERSION_FILE_NAME = UTILS_DIR + '/original_hermes_bytecode_c_src/BytecodeVersion-%s.h' % git_tag 27 | 28 | with open(INPUT_VERSION_FILE_NAME) as fd: 29 | version_file_contents = fd.read() 30 | bytecode_version : int = int(search(r'BYTECODE_VERSION = (\d+)', version_file_contents).group(1)) 31 | 32 | builtin_function_names : List[str] = [] 33 | with open(INPUT_BUILTINS_FILE_NAMES) as fd: 34 | for line in fd: 35 | if line.split('(')[0] in ('BUILTIN_METHOD', 36 | 'PRIVATE_BUILTIN', 'JS_BUILTIN'): 37 | operands = line.split('(')[1].split(')')[0].split(', ') 38 | builtin_function_names.append('.'.join(operands)) 39 | 40 | OUTPUT_FILE_NAME = PARSERS_DIR + '/hbc_opcodes/hbc%d.py' % bytecode_version 41 | 42 | out_source = '''#!/usr/bin/python3 43 | #-*- encoding: Utf-8 -*- 44 | """ 45 | Note: The contents of the current file have been automatically 46 | generated by the "utils/hermes_bytecode_structs_parser.py" 47 | script 48 | 49 | Please do not edit it manually. 👍 50 | """ 51 | 52 | from typing import List, Set, Dict, Union, Optional, Sequence, Any 53 | 54 | # Imports from the current diretory 55 | from .def_classes import * 56 | 57 | _instructions : List[Instruction] = [] 58 | 59 | 60 | ''' 61 | 62 | opcode_count = 0 63 | 64 | with open(INPUT_FILE_NAME) as fd: 65 | 66 | input_source = fd.read() 67 | 68 | # Backport OPERAND_FUNCTION_ID declarations added with 69 | # version 0.12.0 (https://github.com/facebook/hermes/commit/c20d7d8) 70 | # in order to improve disassembly output readability if needed. 71 | 72 | if 'OPERAND_FUNCTION_ID(CallDirect, 3)' not in input_source: 73 | input_source += ''' 74 | OPERAND_FUNCTION_ID(CallDirect, 3) 75 | OPERAND_FUNCTION_ID(CreateClosure, 3) 76 | OPERAND_FUNCTION_ID(CreateClosureLongIndex, 3) 77 | ''' 78 | 79 | if 'CreateGeneratorClosure' in input_source: 80 | input_source += ''' 81 | OPERAND_FUNCTION_ID(CreateGeneratorClosure, 3) 82 | OPERAND_FUNCTION_ID(CreateGeneratorClosureLongIndex, 3) 83 | ''' 84 | 85 | if 'CreateGenerator' in input_source: 86 | input_source += ''' 87 | OPERAND_FUNCTION_ID(CreateGenerator, 3) 88 | OPERAND_FUNCTION_ID(CreateGeneratorLongIndex, 3) 89 | ''' 90 | 91 | if 'CreateAsyncClosure' in input_source: 92 | input_source += ''' 93 | OPERAND_FUNCTION_ID(CreateAsyncClosure, 3) 94 | OPERAND_FUNCTION_ID(CreateAsyncClosureLongIndex, 3) 95 | ''' 96 | 97 | lines = input_source.splitlines() 98 | 99 | for line in lines: 100 | 101 | line = match('^((?:DEFINE|OPERAND)[^(]+?)\((.+?)\)', line) 102 | 103 | if line: 104 | directive, args = line.groups() 105 | args = args.split(', ') 106 | 107 | # print('=>', directive, args) 108 | 109 | if directive.startswith('DEFINE_OPERAND_TYPE'): 110 | out_source = out_source[:-1] # No endline before that for readibility 111 | out_source += f'{args[0]} = OperandType(\'{args[0]}\', \'{args[1]}\')\n\n' 112 | elif directive.startswith('DEFINE_OPCODE'): 113 | out_source += f'{args[0]} = Instruction(\'{args[0]}\', {opcode_count}, [{", ".join(args[1:])}], globals())\n\n' 114 | opcode_count += 1 115 | elif directive.startswith('DEFINE_JUMP'): 116 | args += { 117 | 'DEFINE_JUMP_1': ['Addr8'], 118 | 'DEFINE_JUMP_2': ['Addr8', 'Reg8'], 119 | 'DEFINE_JUMP_3': ['Addr8', 'Reg8', 'Reg8'] 120 | }[directive] 121 | out_source += f'{args[0]} = Instruction(\'{args[0]}\', {opcode_count}, [{", ".join(args[1:])}], globals())\n' 122 | out_source += f'{args[0]}Long = Instruction(\'{args[0]}Long\', {opcode_count + 1}, [{", ".join(["Addr32"] + args[2:])}], globals())\n\n' 123 | opcode_count += 2 124 | elif directive.startswith('DEFINE_RET_TARGET'): 125 | out_source = out_source.strip() 126 | out_source += f'\n{args[0]}.has_ret_target = True\n\n' 127 | elif directive.startswith('OPERAND_'): 128 | operand_meaning = { 129 | 'OPERAND_BIGINT_ID': 'OperandMeaning.bigint_id', 130 | 'OPERAND_FUNCTION_ID': 'OperandMeaning.function_id', 131 | 'OPERAND_STRING_ID': 'OperandMeaning.string_id' 132 | }[directive] 133 | # out_source = out_source.strip() 134 | out_source += f'{args[0]}.operands[{(int(args[1]) - 1)}].operand_meaning = {operand_meaning}\n\n' 135 | 136 | out_source += '''_opcode_to_instruction : Dict[int, Instruction] = {v.opcode: v for v in _instructions} 137 | _name_to_instruction : Dict[str, Instruction] = {v.name: v for v in _instructions} 138 | 139 | ''' 140 | 141 | out_source += '''_builtin_function_names : List[str] = [ 142 | %s 143 | ] 144 | 145 | ''' % ',\n '.join(repr(string) 146 | for string in builtin_function_names) 147 | 148 | with open(OUTPUT_FILE_NAME, 'w', encoding='utf-8') as fd: 149 | fd.write(out_source) 150 | 151 | 152 | print() 153 | print('[+] Wrote File => %s' % OUTPUT_FILE_NAME) 154 | 155 | print() 156 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc61.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 44 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 45 | BUILTIN_METHOD(HermesInternal, exportAll) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | #undef BUILTIN_OBJECT 98 | #undef BUILTIN_METHOD 99 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc68.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, throwTypeError) 44 | BUILTIN_METHOD(HermesInternal, generatorSetDelegated) 45 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 46 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 47 | BUILTIN_METHOD(HermesInternal, exportAll) 48 | BUILTIN_METHOD(HermesInternal, exponentiationOperator) 49 | 50 | BUILTIN_OBJECT(JSON) 51 | BUILTIN_METHOD(JSON, parse) 52 | BUILTIN_METHOD(JSON, stringify) 53 | 54 | BUILTIN_OBJECT(Math) 55 | BUILTIN_METHOD(Math, abs) 56 | BUILTIN_METHOD(Math, acos) 57 | BUILTIN_METHOD(Math, asin) 58 | BUILTIN_METHOD(Math, atan) 59 | BUILTIN_METHOD(Math, atan2) 60 | BUILTIN_METHOD(Math, ceil) 61 | BUILTIN_METHOD(Math, cos) 62 | BUILTIN_METHOD(Math, exp) 63 | BUILTIN_METHOD(Math, floor) 64 | BUILTIN_METHOD(Math, hypot) 65 | BUILTIN_METHOD(Math, imul) 66 | BUILTIN_METHOD(Math, log) 67 | BUILTIN_METHOD(Math, max) 68 | BUILTIN_METHOD(Math, min) 69 | BUILTIN_METHOD(Math, pow) 70 | BUILTIN_METHOD(Math, random) 71 | BUILTIN_METHOD(Math, round) 72 | BUILTIN_METHOD(Math, sin) 73 | BUILTIN_METHOD(Math, sqrt) 74 | BUILTIN_METHOD(Math, tan) 75 | BUILTIN_METHOD(Math, trunc) 76 | 77 | // BUILTIN_OBJECT(Number) 78 | // BUILTIN_METHOD(Number, isNaN) 79 | 80 | BUILTIN_OBJECT(Object) 81 | BUILTIN_METHOD(Object, create) 82 | BUILTIN_METHOD(Object, defineProperties) 83 | BUILTIN_METHOD(Object, defineProperty) 84 | // BUILTIN_METHOD(Object, entries) 85 | BUILTIN_METHOD(Object, freeze) 86 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 87 | BUILTIN_METHOD(Object, getOwnPropertyNames) 88 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 89 | BUILTIN_METHOD(Object, getPrototypeOf) 90 | BUILTIN_METHOD(Object, isExtensible) 91 | BUILTIN_METHOD(Object, isFrozen) 92 | BUILTIN_METHOD(Object, keys) 93 | BUILTIN_METHOD(Object, seal) 94 | // BUILTIN_METHOD(Object, setPrototypeOf) 95 | // BUILTIN_METHOD(Object, values) 96 | 97 | BUILTIN_OBJECT(String) 98 | BUILTIN_METHOD(String, fromCharCode) 99 | 100 | #undef BUILTIN_OBJECT 101 | #undef BUILTIN_METHOD 102 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc69.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, throwTypeError) 44 | BUILTIN_METHOD(HermesInternal, generatorSetDelegated) 45 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 46 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 47 | BUILTIN_METHOD(HermesInternal, arraySpread) 48 | BUILTIN_METHOD(HermesInternal, exportAll) 49 | BUILTIN_METHOD(HermesInternal, exponentiationOperator) 50 | 51 | BUILTIN_OBJECT(JSON) 52 | BUILTIN_METHOD(JSON, parse) 53 | BUILTIN_METHOD(JSON, stringify) 54 | 55 | BUILTIN_OBJECT(Math) 56 | BUILTIN_METHOD(Math, abs) 57 | BUILTIN_METHOD(Math, acos) 58 | BUILTIN_METHOD(Math, asin) 59 | BUILTIN_METHOD(Math, atan) 60 | BUILTIN_METHOD(Math, atan2) 61 | BUILTIN_METHOD(Math, ceil) 62 | BUILTIN_METHOD(Math, cos) 63 | BUILTIN_METHOD(Math, exp) 64 | BUILTIN_METHOD(Math, floor) 65 | BUILTIN_METHOD(Math, hypot) 66 | BUILTIN_METHOD(Math, imul) 67 | BUILTIN_METHOD(Math, log) 68 | BUILTIN_METHOD(Math, max) 69 | BUILTIN_METHOD(Math, min) 70 | BUILTIN_METHOD(Math, pow) 71 | BUILTIN_METHOD(Math, random) 72 | BUILTIN_METHOD(Math, round) 73 | BUILTIN_METHOD(Math, sin) 74 | BUILTIN_METHOD(Math, sqrt) 75 | BUILTIN_METHOD(Math, tan) 76 | BUILTIN_METHOD(Math, trunc) 77 | 78 | // BUILTIN_OBJECT(Number) 79 | // BUILTIN_METHOD(Number, isNaN) 80 | 81 | BUILTIN_OBJECT(Object) 82 | BUILTIN_METHOD(Object, create) 83 | BUILTIN_METHOD(Object, defineProperties) 84 | BUILTIN_METHOD(Object, defineProperty) 85 | // BUILTIN_METHOD(Object, entries) 86 | BUILTIN_METHOD(Object, freeze) 87 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 88 | BUILTIN_METHOD(Object, getOwnPropertyNames) 89 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 90 | BUILTIN_METHOD(Object, getPrototypeOf) 91 | BUILTIN_METHOD(Object, isExtensible) 92 | BUILTIN_METHOD(Object, isFrozen) 93 | BUILTIN_METHOD(Object, keys) 94 | BUILTIN_METHOD(Object, seal) 95 | // BUILTIN_METHOD(Object, setPrototypeOf) 96 | // BUILTIN_METHOD(Object, values) 97 | 98 | BUILTIN_OBJECT(String) 99 | BUILTIN_METHOD(String, fromCharCode) 100 | 101 | #undef BUILTIN_OBJECT 102 | #undef BUILTIN_METHOD 103 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc70.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, throwTypeError) 44 | BUILTIN_METHOD(HermesInternal, generatorSetDelegated) 45 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 46 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 47 | BUILTIN_METHOD(HermesInternal, arraySpread) 48 | BUILTIN_METHOD(HermesInternal, apply) 49 | BUILTIN_METHOD(HermesInternal, exportAll) 50 | BUILTIN_METHOD(HermesInternal, exponentiationOperator) 51 | 52 | BUILTIN_OBJECT(JSON) 53 | BUILTIN_METHOD(JSON, parse) 54 | BUILTIN_METHOD(JSON, stringify) 55 | 56 | BUILTIN_OBJECT(Math) 57 | BUILTIN_METHOD(Math, abs) 58 | BUILTIN_METHOD(Math, acos) 59 | BUILTIN_METHOD(Math, asin) 60 | BUILTIN_METHOD(Math, atan) 61 | BUILTIN_METHOD(Math, atan2) 62 | BUILTIN_METHOD(Math, ceil) 63 | BUILTIN_METHOD(Math, cos) 64 | BUILTIN_METHOD(Math, exp) 65 | BUILTIN_METHOD(Math, floor) 66 | BUILTIN_METHOD(Math, hypot) 67 | BUILTIN_METHOD(Math, imul) 68 | BUILTIN_METHOD(Math, log) 69 | BUILTIN_METHOD(Math, max) 70 | BUILTIN_METHOD(Math, min) 71 | BUILTIN_METHOD(Math, pow) 72 | BUILTIN_METHOD(Math, random) 73 | BUILTIN_METHOD(Math, round) 74 | BUILTIN_METHOD(Math, sin) 75 | BUILTIN_METHOD(Math, sqrt) 76 | BUILTIN_METHOD(Math, tan) 77 | BUILTIN_METHOD(Math, trunc) 78 | 79 | // BUILTIN_OBJECT(Number) 80 | // BUILTIN_METHOD(Number, isNaN) 81 | 82 | BUILTIN_OBJECT(Object) 83 | BUILTIN_METHOD(Object, create) 84 | BUILTIN_METHOD(Object, defineProperties) 85 | BUILTIN_METHOD(Object, defineProperty) 86 | // BUILTIN_METHOD(Object, entries) 87 | BUILTIN_METHOD(Object, freeze) 88 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 89 | BUILTIN_METHOD(Object, getOwnPropertyNames) 90 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 91 | BUILTIN_METHOD(Object, getPrototypeOf) 92 | BUILTIN_METHOD(Object, isExtensible) 93 | BUILTIN_METHOD(Object, isFrozen) 94 | BUILTIN_METHOD(Object, keys) 95 | BUILTIN_METHOD(Object, seal) 96 | // BUILTIN_METHOD(Object, setPrototypeOf) 97 | // BUILTIN_METHOD(Object, values) 98 | 99 | BUILTIN_OBJECT(String) 100 | BUILTIN_METHOD(String, fromCharCode) 101 | 102 | #undef BUILTIN_OBJECT 103 | #undef BUILTIN_METHOD 104 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc72.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define global objects and methods which the compiler can assume have not 11 | /// been overwritten and can be treated as builtins. 12 | /// 13 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 15 | /// YOU MODIFY THIS FILE. 16 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | ///===----------------------------------------------------------------------=== 18 | 19 | #ifndef BUILTIN_OBJECT 20 | #define BUILTIN_OBJECT(object) 21 | #endif 22 | #ifndef BUILTIN_METHOD 23 | #define BUILTIN_METHOD(object, name) 24 | #endif 25 | #ifndef PRIVATE_BUILTIN 26 | #define PRIVATE_BUILTIN(name) 27 | #endif 28 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 29 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 30 | #endif 31 | 32 | BUILTIN_OBJECT(Array) 33 | // BUILTIN_METHOD(Array, from) 34 | BUILTIN_METHOD(Array, isArray) 35 | 36 | BUILTIN_OBJECT(ArrayBuffer) 37 | BUILTIN_METHOD(ArrayBuffer, isView) 38 | 39 | BUILTIN_OBJECT(Date) 40 | BUILTIN_METHOD(Date, UTC) 41 | BUILTIN_METHOD(Date, now) 42 | BUILTIN_METHOD(Date, parse) 43 | 44 | // BUILTIN_OBJECT(HermesInternal) 45 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | PRIVATE_BUILTIN(silentSetPrototypeOf) 98 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 99 | PRIVATE_BUILTIN(requireFast) 100 | PRIVATE_BUILTIN(getTemplateObject) 101 | PRIVATE_BUILTIN(ensureObject) 102 | PRIVATE_BUILTIN(throwTypeError) 103 | PRIVATE_BUILTIN(generatorSetDelegated) 104 | PRIVATE_BUILTIN(copyDataProperties) 105 | PRIVATE_BUILTIN(copyRestArgs) 106 | PRIVATE_BUILTIN(arraySpread) 107 | PRIVATE_BUILTIN(apply) 108 | PRIVATE_BUILTIN(exportAll) 109 | PRIVATE_BUILTIN(exponentiationOperator) 110 | 111 | #undef BUILTIN_OBJECT 112 | #undef BUILTIN_METHOD 113 | #undef PRIVATE_BUILTIN 114 | #undef MARK_FIRST_PRIVATE_BUILTIN 115 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc73.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define global objects and methods which the compiler can assume have not 11 | /// been overwritten and can be treated as builtins. 12 | /// 13 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 15 | /// YOU MODIFY THIS FILE. 16 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | ///===----------------------------------------------------------------------=== 18 | 19 | #ifndef BUILTIN_OBJECT 20 | #define BUILTIN_OBJECT(object) 21 | #endif 22 | #ifndef BUILTIN_METHOD 23 | #define BUILTIN_METHOD(object, name) 24 | #endif 25 | #ifndef PRIVATE_BUILTIN 26 | #define PRIVATE_BUILTIN(name) 27 | #endif 28 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 29 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 30 | #endif 31 | 32 | BUILTIN_OBJECT(Array) 33 | // BUILTIN_METHOD(Array, from) 34 | BUILTIN_METHOD(Array, isArray) 35 | 36 | BUILTIN_OBJECT(ArrayBuffer) 37 | BUILTIN_METHOD(ArrayBuffer, isView) 38 | 39 | BUILTIN_OBJECT(Date) 40 | BUILTIN_METHOD(Date, UTC) 41 | BUILTIN_METHOD(Date, now) 42 | BUILTIN_METHOD(Date, parse) 43 | 44 | // BUILTIN_OBJECT(HermesInternal) 45 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | PRIVATE_BUILTIN(silentSetPrototypeOf) 98 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 99 | PRIVATE_BUILTIN(requireFast) 100 | PRIVATE_BUILTIN(getTemplateObject) 101 | PRIVATE_BUILTIN(ensureObject) 102 | PRIVATE_BUILTIN(throwTypeError) 103 | PRIVATE_BUILTIN(generatorSetDelegated) 104 | PRIVATE_BUILTIN(copyDataProperties) 105 | PRIVATE_BUILTIN(copyRestArgs) 106 | PRIVATE_BUILTIN(arraySpread) 107 | PRIVATE_BUILTIN(apply) 108 | PRIVATE_BUILTIN(exportAll) 109 | PRIVATE_BUILTIN(exponentiationOperator) 110 | 111 | #undef BUILTIN_OBJECT 112 | #undef BUILTIN_METHOD 113 | #undef PRIVATE_BUILTIN 114 | #undef MARK_FIRST_PRIVATE_BUILTIN 115 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc80.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define global objects and methods which the compiler can assume have not 11 | /// been overwritten and can be treated as builtins. 12 | /// 13 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 15 | /// YOU MODIFY THIS FILE. 16 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | ///===----------------------------------------------------------------------=== 18 | 19 | #ifndef BUILTIN_OBJECT 20 | #define BUILTIN_OBJECT(object) 21 | #endif 22 | #ifndef BUILTIN_METHOD 23 | #define BUILTIN_METHOD(object, name) 24 | #endif 25 | #ifndef PRIVATE_BUILTIN 26 | #define PRIVATE_BUILTIN(name) 27 | #endif 28 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 29 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 30 | #endif 31 | 32 | BUILTIN_OBJECT(Array) 33 | // BUILTIN_METHOD(Array, from) 34 | BUILTIN_METHOD(Array, isArray) 35 | 36 | BUILTIN_OBJECT(ArrayBuffer) 37 | BUILTIN_METHOD(ArrayBuffer, isView) 38 | 39 | BUILTIN_OBJECT(Date) 40 | BUILTIN_METHOD(Date, UTC) 41 | BUILTIN_METHOD(Date, now) 42 | BUILTIN_METHOD(Date, parse) 43 | 44 | // BUILTIN_OBJECT(HermesInternal) 45 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | PRIVATE_BUILTIN(silentSetPrototypeOf) 98 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 99 | PRIVATE_BUILTIN(requireFast) 100 | PRIVATE_BUILTIN(getTemplateObject) 101 | PRIVATE_BUILTIN(ensureObject) 102 | PRIVATE_BUILTIN(getMethod) 103 | PRIVATE_BUILTIN(throwTypeError) 104 | PRIVATE_BUILTIN(generatorSetDelegated) 105 | PRIVATE_BUILTIN(copyDataProperties) 106 | PRIVATE_BUILTIN(copyRestArgs) 107 | PRIVATE_BUILTIN(arraySpread) 108 | PRIVATE_BUILTIN(apply) 109 | PRIVATE_BUILTIN(exportAll) 110 | PRIVATE_BUILTIN(exponentiationOperator) 111 | 112 | #undef BUILTIN_OBJECT 113 | #undef BUILTIN_METHOD 114 | #undef PRIVATE_BUILTIN 115 | #undef MARK_FIRST_PRIVATE_BUILTIN 116 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc81.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define global objects and methods which the compiler can assume have not 11 | /// been overwritten and can be treated as builtins. 12 | /// 13 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 15 | /// YOU MODIFY THIS FILE. 16 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | ///===----------------------------------------------------------------------=== 18 | 19 | #ifndef BUILTIN_OBJECT 20 | #define BUILTIN_OBJECT(object) 21 | #endif 22 | #ifndef BUILTIN_METHOD 23 | #define BUILTIN_METHOD(object, name) 24 | #endif 25 | #ifndef PRIVATE_BUILTIN 26 | #define PRIVATE_BUILTIN(name) 27 | #endif 28 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 29 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 30 | #endif 31 | 32 | BUILTIN_OBJECT(Array) 33 | // BUILTIN_METHOD(Array, from) 34 | BUILTIN_METHOD(Array, isArray) 35 | 36 | BUILTIN_OBJECT(ArrayBuffer) 37 | BUILTIN_METHOD(ArrayBuffer, isView) 38 | 39 | BUILTIN_OBJECT(Date) 40 | BUILTIN_METHOD(Date, UTC) 41 | BUILTIN_METHOD(Date, now) 42 | BUILTIN_METHOD(Date, parse) 43 | 44 | // BUILTIN_OBJECT(HermesInternal) 45 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | PRIVATE_BUILTIN(silentSetPrototypeOf) 98 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 99 | PRIVATE_BUILTIN(requireFast) 100 | PRIVATE_BUILTIN(getTemplateObject) 101 | PRIVATE_BUILTIN(ensureObject) 102 | PRIVATE_BUILTIN(getMethod) 103 | PRIVATE_BUILTIN(throwTypeError) 104 | PRIVATE_BUILTIN(generatorSetDelegated) 105 | PRIVATE_BUILTIN(copyDataProperties) 106 | PRIVATE_BUILTIN(copyRestArgs) 107 | PRIVATE_BUILTIN(arraySpread) 108 | PRIVATE_BUILTIN(apply) 109 | PRIVATE_BUILTIN(exportAll) 110 | PRIVATE_BUILTIN(exponentiationOperator) 111 | 112 | #undef BUILTIN_OBJECT 113 | #undef BUILTIN_METHOD 114 | #undef PRIVATE_BUILTIN 115 | #undef MARK_FIRST_PRIVATE_BUILTIN 116 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc82.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(ArrayBuffer) 66 | BUILTIN_METHOD(ArrayBuffer, isView) 67 | 68 | BUILTIN_OBJECT(Date) 69 | BUILTIN_METHOD(Date, UTC) 70 | BUILTIN_METHOD(Date, now) 71 | BUILTIN_METHOD(Date, parse) 72 | 73 | // BUILTIN_OBJECT(HermesInternal) 74 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 75 | 76 | BUILTIN_OBJECT(JSON) 77 | BUILTIN_METHOD(JSON, parse) 78 | BUILTIN_METHOD(JSON, stringify) 79 | 80 | BUILTIN_OBJECT(Math) 81 | BUILTIN_METHOD(Math, abs) 82 | BUILTIN_METHOD(Math, acos) 83 | BUILTIN_METHOD(Math, asin) 84 | BUILTIN_METHOD(Math, atan) 85 | BUILTIN_METHOD(Math, atan2) 86 | BUILTIN_METHOD(Math, ceil) 87 | BUILTIN_METHOD(Math, cos) 88 | BUILTIN_METHOD(Math, exp) 89 | BUILTIN_METHOD(Math, floor) 90 | BUILTIN_METHOD(Math, hypot) 91 | BUILTIN_METHOD(Math, imul) 92 | BUILTIN_METHOD(Math, log) 93 | BUILTIN_METHOD(Math, max) 94 | BUILTIN_METHOD(Math, min) 95 | BUILTIN_METHOD(Math, pow) 96 | BUILTIN_METHOD(Math, random) 97 | BUILTIN_METHOD(Math, round) 98 | BUILTIN_METHOD(Math, sin) 99 | BUILTIN_METHOD(Math, sqrt) 100 | BUILTIN_METHOD(Math, tan) 101 | BUILTIN_METHOD(Math, trunc) 102 | 103 | // BUILTIN_OBJECT(Number) 104 | // BUILTIN_METHOD(Number, isNaN) 105 | 106 | BUILTIN_OBJECT(Object) 107 | BUILTIN_METHOD(Object, create) 108 | BUILTIN_METHOD(Object, defineProperties) 109 | BUILTIN_METHOD(Object, defineProperty) 110 | // BUILTIN_METHOD(Object, entries) 111 | BUILTIN_METHOD(Object, freeze) 112 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 113 | BUILTIN_METHOD(Object, getOwnPropertyNames) 114 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 115 | BUILTIN_METHOD(Object, getPrototypeOf) 116 | BUILTIN_METHOD(Object, isExtensible) 117 | BUILTIN_METHOD(Object, isFrozen) 118 | BUILTIN_METHOD(Object, keys) 119 | BUILTIN_METHOD(Object, seal) 120 | // BUILTIN_METHOD(Object, setPrototypeOf) 121 | // BUILTIN_METHOD(Object, values) 122 | 123 | BUILTIN_OBJECT(String) 124 | BUILTIN_METHOD(String, fromCharCode) 125 | 126 | PRIVATE_BUILTIN(silentSetPrototypeOf) 127 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 128 | PRIVATE_BUILTIN(requireFast) 129 | PRIVATE_BUILTIN(getTemplateObject) 130 | PRIVATE_BUILTIN(ensureObject) 131 | PRIVATE_BUILTIN(getMethod) 132 | PRIVATE_BUILTIN(throwTypeError) 133 | PRIVATE_BUILTIN(generatorSetDelegated) 134 | PRIVATE_BUILTIN(copyDataProperties) 135 | PRIVATE_BUILTIN(copyRestArgs) 136 | PRIVATE_BUILTIN(arraySpread) 137 | PRIVATE_BUILTIN(apply) 138 | PRIVATE_BUILTIN(exportAll) 139 | PRIVATE_BUILTIN(exponentiationOperator) 140 | 141 | JS_BUILTIN(spawnAsync) 142 | MARK_FIRST_JS_BUILTIN(spawnAsync) 143 | 144 | #undef BUILTIN_OBJECT 145 | #undef BUILTIN_METHOD 146 | #undef PRIVATE_BUILTIN 147 | #undef MARK_FIRST_PRIVATE_BUILTIN 148 | #undef JS_BUILTIN 149 | #undef MARK_FIRST_JS_BUILTIN 150 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc86.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(Date) 66 | BUILTIN_METHOD(Date, UTC) 67 | BUILTIN_METHOD(Date, now) 68 | BUILTIN_METHOD(Date, parse) 69 | 70 | // BUILTIN_OBJECT(HermesInternal) 71 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 72 | 73 | BUILTIN_OBJECT(JSON) 74 | BUILTIN_METHOD(JSON, parse) 75 | BUILTIN_METHOD(JSON, stringify) 76 | 77 | BUILTIN_OBJECT(Math) 78 | BUILTIN_METHOD(Math, abs) 79 | BUILTIN_METHOD(Math, acos) 80 | BUILTIN_METHOD(Math, asin) 81 | BUILTIN_METHOD(Math, atan) 82 | BUILTIN_METHOD(Math, atan2) 83 | BUILTIN_METHOD(Math, ceil) 84 | BUILTIN_METHOD(Math, cos) 85 | BUILTIN_METHOD(Math, exp) 86 | BUILTIN_METHOD(Math, floor) 87 | BUILTIN_METHOD(Math, hypot) 88 | BUILTIN_METHOD(Math, imul) 89 | BUILTIN_METHOD(Math, log) 90 | BUILTIN_METHOD(Math, max) 91 | BUILTIN_METHOD(Math, min) 92 | BUILTIN_METHOD(Math, pow) 93 | BUILTIN_METHOD(Math, random) 94 | BUILTIN_METHOD(Math, round) 95 | BUILTIN_METHOD(Math, sin) 96 | BUILTIN_METHOD(Math, sqrt) 97 | BUILTIN_METHOD(Math, tan) 98 | BUILTIN_METHOD(Math, trunc) 99 | 100 | // BUILTIN_OBJECT(Number) 101 | // BUILTIN_METHOD(Number, isNaN) 102 | 103 | BUILTIN_OBJECT(Object) 104 | BUILTIN_METHOD(Object, create) 105 | BUILTIN_METHOD(Object, defineProperties) 106 | BUILTIN_METHOD(Object, defineProperty) 107 | // BUILTIN_METHOD(Object, entries) 108 | BUILTIN_METHOD(Object, freeze) 109 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 110 | BUILTIN_METHOD(Object, getOwnPropertyNames) 111 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 112 | BUILTIN_METHOD(Object, getPrototypeOf) 113 | BUILTIN_METHOD(Object, isExtensible) 114 | BUILTIN_METHOD(Object, isFrozen) 115 | BUILTIN_METHOD(Object, keys) 116 | BUILTIN_METHOD(Object, seal) 117 | // BUILTIN_METHOD(Object, setPrototypeOf) 118 | // BUILTIN_METHOD(Object, values) 119 | 120 | BUILTIN_OBJECT(String) 121 | BUILTIN_METHOD(String, fromCharCode) 122 | 123 | PRIVATE_BUILTIN(silentSetPrototypeOf) 124 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 125 | PRIVATE_BUILTIN(requireFast) 126 | PRIVATE_BUILTIN(getTemplateObject) 127 | PRIVATE_BUILTIN(ensureObject) 128 | PRIVATE_BUILTIN(getMethod) 129 | PRIVATE_BUILTIN(throwTypeError) 130 | PRIVATE_BUILTIN(generatorSetDelegated) 131 | PRIVATE_BUILTIN(copyDataProperties) 132 | PRIVATE_BUILTIN(copyRestArgs) 133 | PRIVATE_BUILTIN(arraySpread) 134 | PRIVATE_BUILTIN(apply) 135 | PRIVATE_BUILTIN(exportAll) 136 | PRIVATE_BUILTIN(exponentiationOperator) 137 | 138 | JS_BUILTIN(spawnAsync) 139 | MARK_FIRST_JS_BUILTIN(spawnAsync) 140 | 141 | #undef BUILTIN_OBJECT 142 | #undef BUILTIN_METHOD 143 | #undef PRIVATE_BUILTIN 144 | #undef MARK_FIRST_PRIVATE_BUILTIN 145 | #undef JS_BUILTIN 146 | #undef MARK_FIRST_JS_BUILTIN 147 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc87.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(Date) 66 | BUILTIN_METHOD(Date, UTC) 67 | BUILTIN_METHOD(Date, now) 68 | BUILTIN_METHOD(Date, parse) 69 | 70 | // BUILTIN_OBJECT(HermesInternal) 71 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 72 | 73 | BUILTIN_OBJECT(JSON) 74 | BUILTIN_METHOD(JSON, parse) 75 | BUILTIN_METHOD(JSON, stringify) 76 | 77 | BUILTIN_OBJECT(Math) 78 | BUILTIN_METHOD(Math, abs) 79 | BUILTIN_METHOD(Math, acos) 80 | BUILTIN_METHOD(Math, asin) 81 | BUILTIN_METHOD(Math, atan) 82 | BUILTIN_METHOD(Math, atan2) 83 | BUILTIN_METHOD(Math, ceil) 84 | BUILTIN_METHOD(Math, cos) 85 | BUILTIN_METHOD(Math, exp) 86 | BUILTIN_METHOD(Math, floor) 87 | BUILTIN_METHOD(Math, hypot) 88 | BUILTIN_METHOD(Math, imul) 89 | BUILTIN_METHOD(Math, log) 90 | BUILTIN_METHOD(Math, max) 91 | BUILTIN_METHOD(Math, min) 92 | BUILTIN_METHOD(Math, pow) 93 | BUILTIN_METHOD(Math, random) 94 | BUILTIN_METHOD(Math, round) 95 | BUILTIN_METHOD(Math, sin) 96 | BUILTIN_METHOD(Math, sqrt) 97 | BUILTIN_METHOD(Math, tan) 98 | BUILTIN_METHOD(Math, trunc) 99 | 100 | // BUILTIN_OBJECT(Number) 101 | // BUILTIN_METHOD(Number, isNaN) 102 | 103 | BUILTIN_OBJECT(Object) 104 | BUILTIN_METHOD(Object, create) 105 | BUILTIN_METHOD(Object, defineProperties) 106 | BUILTIN_METHOD(Object, defineProperty) 107 | // BUILTIN_METHOD(Object, entries) 108 | BUILTIN_METHOD(Object, freeze) 109 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 110 | BUILTIN_METHOD(Object, getOwnPropertyNames) 111 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 112 | BUILTIN_METHOD(Object, getPrototypeOf) 113 | BUILTIN_METHOD(Object, isExtensible) 114 | BUILTIN_METHOD(Object, isFrozen) 115 | BUILTIN_METHOD(Object, keys) 116 | BUILTIN_METHOD(Object, seal) 117 | // BUILTIN_METHOD(Object, setPrototypeOf) 118 | // BUILTIN_METHOD(Object, values) 119 | 120 | BUILTIN_OBJECT(String) 121 | BUILTIN_METHOD(String, fromCharCode) 122 | 123 | PRIVATE_BUILTIN(silentSetPrototypeOf) 124 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 125 | PRIVATE_BUILTIN(requireFast) 126 | PRIVATE_BUILTIN(getTemplateObject) 127 | PRIVATE_BUILTIN(ensureObject) 128 | PRIVATE_BUILTIN(getMethod) 129 | PRIVATE_BUILTIN(throwTypeError) 130 | PRIVATE_BUILTIN(generatorSetDelegated) 131 | PRIVATE_BUILTIN(copyDataProperties) 132 | PRIVATE_BUILTIN(copyRestArgs) 133 | PRIVATE_BUILTIN(arraySpread) 134 | PRIVATE_BUILTIN(apply) 135 | PRIVATE_BUILTIN(exportAll) 136 | PRIVATE_BUILTIN(exponentiationOperator) 137 | 138 | JS_BUILTIN(spawnAsync) 139 | MARK_FIRST_JS_BUILTIN(spawnAsync) 140 | 141 | #undef BUILTIN_OBJECT 142 | #undef BUILTIN_METHOD 143 | #undef PRIVATE_BUILTIN 144 | #undef MARK_FIRST_PRIVATE_BUILTIN 145 | #undef JS_BUILTIN 146 | #undef MARK_FIRST_JS_BUILTIN 147 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc90.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_METHOD(Date, UTC) 66 | BUILTIN_METHOD(Date, parse) 67 | 68 | // BUILTIN_OBJECT(HermesInternal) 69 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 70 | 71 | BUILTIN_OBJECT(JSON) 72 | BUILTIN_METHOD(JSON, parse) 73 | BUILTIN_METHOD(JSON, stringify) 74 | 75 | BUILTIN_OBJECT(Math) 76 | BUILTIN_METHOD(Math, abs) 77 | BUILTIN_METHOD(Math, acos) 78 | BUILTIN_METHOD(Math, asin) 79 | BUILTIN_METHOD(Math, atan) 80 | BUILTIN_METHOD(Math, atan2) 81 | BUILTIN_METHOD(Math, ceil) 82 | BUILTIN_METHOD(Math, cos) 83 | BUILTIN_METHOD(Math, exp) 84 | BUILTIN_METHOD(Math, floor) 85 | BUILTIN_METHOD(Math, hypot) 86 | BUILTIN_METHOD(Math, imul) 87 | BUILTIN_METHOD(Math, log) 88 | BUILTIN_METHOD(Math, max) 89 | BUILTIN_METHOD(Math, min) 90 | BUILTIN_METHOD(Math, pow) 91 | BUILTIN_METHOD(Math, round) 92 | BUILTIN_METHOD(Math, sin) 93 | BUILTIN_METHOD(Math, sqrt) 94 | BUILTIN_METHOD(Math, tan) 95 | BUILTIN_METHOD(Math, trunc) 96 | 97 | // BUILTIN_OBJECT(Number) 98 | // BUILTIN_METHOD(Number, isNaN) 99 | 100 | BUILTIN_OBJECT(Object) 101 | BUILTIN_METHOD(Object, create) 102 | BUILTIN_METHOD(Object, defineProperties) 103 | BUILTIN_METHOD(Object, defineProperty) 104 | // BUILTIN_METHOD(Object, entries) 105 | BUILTIN_METHOD(Object, freeze) 106 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 107 | BUILTIN_METHOD(Object, getOwnPropertyNames) 108 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 109 | BUILTIN_METHOD(Object, getPrototypeOf) 110 | BUILTIN_METHOD(Object, isExtensible) 111 | BUILTIN_METHOD(Object, isFrozen) 112 | BUILTIN_METHOD(Object, keys) 113 | BUILTIN_METHOD(Object, seal) 114 | // BUILTIN_METHOD(Object, setPrototypeOf) 115 | // BUILTIN_METHOD(Object, values) 116 | 117 | BUILTIN_OBJECT(String) 118 | BUILTIN_METHOD(String, fromCharCode) 119 | 120 | PRIVATE_BUILTIN(silentSetPrototypeOf) 121 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 122 | PRIVATE_BUILTIN(requireFast) 123 | PRIVATE_BUILTIN(getTemplateObject) 124 | PRIVATE_BUILTIN(ensureObject) 125 | PRIVATE_BUILTIN(getMethod) 126 | PRIVATE_BUILTIN(throwTypeError) 127 | PRIVATE_BUILTIN(generatorSetDelegated) 128 | PRIVATE_BUILTIN(copyDataProperties) 129 | PRIVATE_BUILTIN(copyRestArgs) 130 | PRIVATE_BUILTIN(arraySpread) 131 | PRIVATE_BUILTIN(apply) 132 | PRIVATE_BUILTIN(exportAll) 133 | PRIVATE_BUILTIN(exponentiationOperator) 134 | PRIVATE_BUILTIN(initRegexNamedGroups) 135 | 136 | JS_BUILTIN(spawnAsync) 137 | MARK_FIRST_JS_BUILTIN(spawnAsync) 138 | 139 | #undef BUILTIN_OBJECT 140 | #undef BUILTIN_METHOD 141 | #undef PRIVATE_BUILTIN 142 | #undef MARK_FIRST_PRIVATE_BUILTIN 143 | #undef JS_BUILTIN 144 | #undef MARK_FIRST_JS_BUILTIN 145 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc92.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_METHOD(Date, UTC) 66 | BUILTIN_METHOD(Date, parse) 67 | 68 | // BUILTIN_OBJECT(HermesInternal) 69 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 70 | 71 | BUILTIN_OBJECT(JSON) 72 | BUILTIN_METHOD(JSON, parse) 73 | BUILTIN_METHOD(JSON, stringify) 74 | 75 | BUILTIN_OBJECT(Math) 76 | BUILTIN_METHOD(Math, abs) 77 | BUILTIN_METHOD(Math, acos) 78 | BUILTIN_METHOD(Math, asin) 79 | BUILTIN_METHOD(Math, atan) 80 | BUILTIN_METHOD(Math, atan2) 81 | BUILTIN_METHOD(Math, ceil) 82 | BUILTIN_METHOD(Math, cos) 83 | BUILTIN_METHOD(Math, exp) 84 | BUILTIN_METHOD(Math, floor) 85 | BUILTIN_METHOD(Math, hypot) 86 | BUILTIN_METHOD(Math, imul) 87 | BUILTIN_METHOD(Math, log) 88 | BUILTIN_METHOD(Math, max) 89 | BUILTIN_METHOD(Math, min) 90 | BUILTIN_METHOD(Math, pow) 91 | BUILTIN_METHOD(Math, round) 92 | BUILTIN_METHOD(Math, sin) 93 | BUILTIN_METHOD(Math, sqrt) 94 | BUILTIN_METHOD(Math, tan) 95 | BUILTIN_METHOD(Math, trunc) 96 | 97 | // BUILTIN_OBJECT(Number) 98 | // BUILTIN_METHOD(Number, isNaN) 99 | 100 | BUILTIN_OBJECT(Object) 101 | BUILTIN_METHOD(Object, create) 102 | BUILTIN_METHOD(Object, defineProperties) 103 | BUILTIN_METHOD(Object, defineProperty) 104 | // BUILTIN_METHOD(Object, entries) 105 | BUILTIN_METHOD(Object, freeze) 106 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 107 | BUILTIN_METHOD(Object, getOwnPropertyNames) 108 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 109 | BUILTIN_METHOD(Object, getPrototypeOf) 110 | BUILTIN_METHOD(Object, isExtensible) 111 | BUILTIN_METHOD(Object, isFrozen) 112 | BUILTIN_METHOD(Object, keys) 113 | BUILTIN_METHOD(Object, seal) 114 | // BUILTIN_METHOD(Object, setPrototypeOf) 115 | // BUILTIN_METHOD(Object, values) 116 | 117 | BUILTIN_OBJECT(String) 118 | BUILTIN_METHOD(String, fromCharCode) 119 | 120 | PRIVATE_BUILTIN(silentSetPrototypeOf) 121 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 122 | PRIVATE_BUILTIN(requireFast) 123 | PRIVATE_BUILTIN(getTemplateObject) 124 | PRIVATE_BUILTIN(ensureObject) 125 | PRIVATE_BUILTIN(getMethod) 126 | PRIVATE_BUILTIN(throwTypeError) 127 | PRIVATE_BUILTIN(generatorSetDelegated) 128 | PRIVATE_BUILTIN(copyDataProperties) 129 | PRIVATE_BUILTIN(copyRestArgs) 130 | PRIVATE_BUILTIN(arraySpread) 131 | PRIVATE_BUILTIN(apply) 132 | PRIVATE_BUILTIN(exportAll) 133 | PRIVATE_BUILTIN(exponentiationOperator) 134 | PRIVATE_BUILTIN(initRegexNamedGroups) 135 | PRIVATE_BUILTIN(getOriginalNativeErrorConstructor) 136 | 137 | JS_BUILTIN(spawnAsync) 138 | MARK_FIRST_JS_BUILTIN(spawnAsync) 139 | 140 | #undef BUILTIN_OBJECT 141 | #undef BUILTIN_METHOD 142 | #undef PRIVATE_BUILTIN 143 | #undef MARK_FIRST_PRIVATE_BUILTIN 144 | #undef JS_BUILTIN 145 | #undef MARK_FIRST_JS_BUILTIN 146 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-hbc95.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_METHOD(Date, UTC) 66 | BUILTIN_METHOD(Date, parse) 67 | 68 | // BUILTIN_OBJECT(HermesInternal) 69 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 70 | 71 | BUILTIN_OBJECT(JSON) 72 | BUILTIN_METHOD(JSON, parse) 73 | BUILTIN_METHOD(JSON, stringify) 74 | 75 | BUILTIN_OBJECT(Math) 76 | BUILTIN_METHOD(Math, abs) 77 | BUILTIN_METHOD(Math, acos) 78 | BUILTIN_METHOD(Math, asin) 79 | BUILTIN_METHOD(Math, atan) 80 | BUILTIN_METHOD(Math, atan2) 81 | BUILTIN_METHOD(Math, ceil) 82 | BUILTIN_METHOD(Math, cos) 83 | BUILTIN_METHOD(Math, exp) 84 | BUILTIN_METHOD(Math, floor) 85 | BUILTIN_METHOD(Math, hypot) 86 | BUILTIN_METHOD(Math, imul) 87 | BUILTIN_METHOD(Math, log) 88 | BUILTIN_METHOD(Math, max) 89 | BUILTIN_METHOD(Math, min) 90 | BUILTIN_METHOD(Math, pow) 91 | BUILTIN_METHOD(Math, round) 92 | BUILTIN_METHOD(Math, sin) 93 | BUILTIN_METHOD(Math, sqrt) 94 | BUILTIN_METHOD(Math, tan) 95 | BUILTIN_METHOD(Math, trunc) 96 | 97 | // BUILTIN_OBJECT(Number) 98 | // BUILTIN_METHOD(Number, isNaN) 99 | 100 | BUILTIN_OBJECT(Object) 101 | BUILTIN_METHOD(Object, create) 102 | BUILTIN_METHOD(Object, defineProperties) 103 | BUILTIN_METHOD(Object, defineProperty) 104 | // BUILTIN_METHOD(Object, entries) 105 | BUILTIN_METHOD(Object, freeze) 106 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 107 | BUILTIN_METHOD(Object, getOwnPropertyNames) 108 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 109 | BUILTIN_METHOD(Object, getPrototypeOf) 110 | BUILTIN_METHOD(Object, isExtensible) 111 | BUILTIN_METHOD(Object, isFrozen) 112 | BUILTIN_METHOD(Object, keys) 113 | BUILTIN_METHOD(Object, seal) 114 | // BUILTIN_METHOD(Object, setPrototypeOf) 115 | // BUILTIN_METHOD(Object, values) 116 | 117 | BUILTIN_OBJECT(String) 118 | BUILTIN_METHOD(String, fromCharCode) 119 | 120 | PRIVATE_BUILTIN(silentSetPrototypeOf) 121 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 122 | PRIVATE_BUILTIN(requireFast) 123 | PRIVATE_BUILTIN(getTemplateObject) 124 | PRIVATE_BUILTIN(ensureObject) 125 | PRIVATE_BUILTIN(getMethod) 126 | PRIVATE_BUILTIN(throwTypeError) 127 | PRIVATE_BUILTIN(generatorSetDelegated) 128 | PRIVATE_BUILTIN(copyDataProperties) 129 | PRIVATE_BUILTIN(copyRestArgs) 130 | PRIVATE_BUILTIN(arraySpread) 131 | PRIVATE_BUILTIN(apply) 132 | PRIVATE_BUILTIN(exportAll) 133 | PRIVATE_BUILTIN(exponentiationOperator) 134 | PRIVATE_BUILTIN(initRegexNamedGroups) 135 | PRIVATE_BUILTIN(getOriginalNativeErrorConstructor) 136 | 137 | JS_BUILTIN(spawnAsync) 138 | MARK_FIRST_JS_BUILTIN(spawnAsync) 139 | 140 | #undef BUILTIN_OBJECT 141 | #undef BUILTIN_METHOD 142 | #undef PRIVATE_BUILTIN 143 | #undef MARK_FIRST_PRIVATE_BUILTIN 144 | #undef JS_BUILTIN 145 | #undef MARK_FIRST_JS_BUILTIN 146 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.0.1.def: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, require) 42 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 43 | BUILTIN_METHOD(HermesInternal, ensureObject) 44 | 45 | BUILTIN_OBJECT(JSON) 46 | BUILTIN_METHOD(JSON, parse) 47 | BUILTIN_METHOD(JSON, stringify) 48 | 49 | BUILTIN_OBJECT(Math) 50 | BUILTIN_METHOD(Math, abs) 51 | BUILTIN_METHOD(Math, acos) 52 | BUILTIN_METHOD(Math, asin) 53 | BUILTIN_METHOD(Math, atan) 54 | BUILTIN_METHOD(Math, atan2) 55 | BUILTIN_METHOD(Math, ceil) 56 | BUILTIN_METHOD(Math, cos) 57 | BUILTIN_METHOD(Math, exp) 58 | BUILTIN_METHOD(Math, floor) 59 | BUILTIN_METHOD(Math, hypot) 60 | BUILTIN_METHOD(Math, imul) 61 | BUILTIN_METHOD(Math, log) 62 | BUILTIN_METHOD(Math, max) 63 | BUILTIN_METHOD(Math, min) 64 | BUILTIN_METHOD(Math, pow) 65 | BUILTIN_METHOD(Math, random) 66 | BUILTIN_METHOD(Math, round) 67 | BUILTIN_METHOD(Math, sin) 68 | BUILTIN_METHOD(Math, sqrt) 69 | BUILTIN_METHOD(Math, tan) 70 | BUILTIN_METHOD(Math, trunc) 71 | 72 | // BUILTIN_OBJECT(Number) 73 | // BUILTIN_METHOD(Number, isNaN) 74 | 75 | BUILTIN_OBJECT(Object) 76 | BUILTIN_METHOD(Object, create) 77 | BUILTIN_METHOD(Object, defineProperties) 78 | BUILTIN_METHOD(Object, defineProperty) 79 | // BUILTIN_METHOD(Object, entries) 80 | BUILTIN_METHOD(Object, freeze) 81 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 82 | BUILTIN_METHOD(Object, getOwnPropertyNames) 83 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 84 | BUILTIN_METHOD(Object, getPrototypeOf) 85 | BUILTIN_METHOD(Object, isExtensible) 86 | BUILTIN_METHOD(Object, isFrozen) 87 | BUILTIN_METHOD(Object, keys) 88 | BUILTIN_METHOD(Object, seal) 89 | // BUILTIN_METHOD(Object, setPrototypeOf) 90 | // BUILTIN_METHOD(Object, values) 91 | 92 | BUILTIN_OBJECT(String) 93 | BUILTIN_METHOD(String, fromCharCode) 94 | 95 | #undef BUILTIN_OBJECT 96 | #undef BUILTIN_METHOD 97 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.0.3.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 44 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 45 | BUILTIN_METHOD(HermesInternal, exportAll) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | #undef BUILTIN_OBJECT 98 | #undef BUILTIN_METHOD 99 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.1.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 44 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 45 | BUILTIN_METHOD(HermesInternal, exportAll) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | #undef BUILTIN_OBJECT 98 | #undef BUILTIN_METHOD 99 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.11.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(ArrayBuffer) 66 | BUILTIN_METHOD(ArrayBuffer, isView) 67 | 68 | BUILTIN_OBJECT(Date) 69 | BUILTIN_METHOD(Date, UTC) 70 | BUILTIN_METHOD(Date, now) 71 | BUILTIN_METHOD(Date, parse) 72 | 73 | // BUILTIN_OBJECT(HermesInternal) 74 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 75 | 76 | BUILTIN_OBJECT(JSON) 77 | BUILTIN_METHOD(JSON, parse) 78 | BUILTIN_METHOD(JSON, stringify) 79 | 80 | BUILTIN_OBJECT(Math) 81 | BUILTIN_METHOD(Math, abs) 82 | BUILTIN_METHOD(Math, acos) 83 | BUILTIN_METHOD(Math, asin) 84 | BUILTIN_METHOD(Math, atan) 85 | BUILTIN_METHOD(Math, atan2) 86 | BUILTIN_METHOD(Math, ceil) 87 | BUILTIN_METHOD(Math, cos) 88 | BUILTIN_METHOD(Math, exp) 89 | BUILTIN_METHOD(Math, floor) 90 | BUILTIN_METHOD(Math, hypot) 91 | BUILTIN_METHOD(Math, imul) 92 | BUILTIN_METHOD(Math, log) 93 | BUILTIN_METHOD(Math, max) 94 | BUILTIN_METHOD(Math, min) 95 | BUILTIN_METHOD(Math, pow) 96 | BUILTIN_METHOD(Math, random) 97 | BUILTIN_METHOD(Math, round) 98 | BUILTIN_METHOD(Math, sin) 99 | BUILTIN_METHOD(Math, sqrt) 100 | BUILTIN_METHOD(Math, tan) 101 | BUILTIN_METHOD(Math, trunc) 102 | 103 | // BUILTIN_OBJECT(Number) 104 | // BUILTIN_METHOD(Number, isNaN) 105 | 106 | BUILTIN_OBJECT(Object) 107 | BUILTIN_METHOD(Object, create) 108 | BUILTIN_METHOD(Object, defineProperties) 109 | BUILTIN_METHOD(Object, defineProperty) 110 | // BUILTIN_METHOD(Object, entries) 111 | BUILTIN_METHOD(Object, freeze) 112 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 113 | BUILTIN_METHOD(Object, getOwnPropertyNames) 114 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 115 | BUILTIN_METHOD(Object, getPrototypeOf) 116 | BUILTIN_METHOD(Object, isExtensible) 117 | BUILTIN_METHOD(Object, isFrozen) 118 | BUILTIN_METHOD(Object, keys) 119 | BUILTIN_METHOD(Object, seal) 120 | // BUILTIN_METHOD(Object, setPrototypeOf) 121 | // BUILTIN_METHOD(Object, values) 122 | 123 | BUILTIN_OBJECT(String) 124 | BUILTIN_METHOD(String, fromCharCode) 125 | 126 | PRIVATE_BUILTIN(silentSetPrototypeOf) 127 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 128 | PRIVATE_BUILTIN(requireFast) 129 | PRIVATE_BUILTIN(getTemplateObject) 130 | PRIVATE_BUILTIN(ensureObject) 131 | PRIVATE_BUILTIN(getMethod) 132 | PRIVATE_BUILTIN(throwTypeError) 133 | PRIVATE_BUILTIN(generatorSetDelegated) 134 | PRIVATE_BUILTIN(copyDataProperties) 135 | PRIVATE_BUILTIN(copyRestArgs) 136 | PRIVATE_BUILTIN(arraySpread) 137 | PRIVATE_BUILTIN(apply) 138 | PRIVATE_BUILTIN(exportAll) 139 | PRIVATE_BUILTIN(exponentiationOperator) 140 | 141 | JS_BUILTIN(spawnAsync) 142 | MARK_FIRST_JS_BUILTIN(spawnAsync) 143 | 144 | #undef BUILTIN_OBJECT 145 | #undef BUILTIN_METHOD 146 | #undef PRIVATE_BUILTIN 147 | #undef MARK_FIRST_PRIVATE_BUILTIN 148 | #undef JS_BUILTIN 149 | #undef MARK_FIRST_JS_BUILTIN 150 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.12.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_METHOD(Date, UTC) 66 | BUILTIN_METHOD(Date, parse) 67 | 68 | // BUILTIN_OBJECT(HermesInternal) 69 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 70 | 71 | BUILTIN_OBJECT(JSON) 72 | BUILTIN_METHOD(JSON, parse) 73 | BUILTIN_METHOD(JSON, stringify) 74 | 75 | BUILTIN_OBJECT(Math) 76 | BUILTIN_METHOD(Math, abs) 77 | BUILTIN_METHOD(Math, acos) 78 | BUILTIN_METHOD(Math, asin) 79 | BUILTIN_METHOD(Math, atan) 80 | BUILTIN_METHOD(Math, atan2) 81 | BUILTIN_METHOD(Math, ceil) 82 | BUILTIN_METHOD(Math, cos) 83 | BUILTIN_METHOD(Math, exp) 84 | BUILTIN_METHOD(Math, floor) 85 | BUILTIN_METHOD(Math, hypot) 86 | BUILTIN_METHOD(Math, imul) 87 | BUILTIN_METHOD(Math, log) 88 | BUILTIN_METHOD(Math, max) 89 | BUILTIN_METHOD(Math, min) 90 | BUILTIN_METHOD(Math, pow) 91 | BUILTIN_METHOD(Math, round) 92 | BUILTIN_METHOD(Math, sin) 93 | BUILTIN_METHOD(Math, sqrt) 94 | BUILTIN_METHOD(Math, tan) 95 | BUILTIN_METHOD(Math, trunc) 96 | 97 | // BUILTIN_OBJECT(Number) 98 | // BUILTIN_METHOD(Number, isNaN) 99 | 100 | BUILTIN_OBJECT(Object) 101 | BUILTIN_METHOD(Object, create) 102 | BUILTIN_METHOD(Object, defineProperties) 103 | BUILTIN_METHOD(Object, defineProperty) 104 | // BUILTIN_METHOD(Object, entries) 105 | BUILTIN_METHOD(Object, freeze) 106 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 107 | BUILTIN_METHOD(Object, getOwnPropertyNames) 108 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 109 | BUILTIN_METHOD(Object, getPrototypeOf) 110 | BUILTIN_METHOD(Object, isExtensible) 111 | BUILTIN_METHOD(Object, isFrozen) 112 | BUILTIN_METHOD(Object, keys) 113 | BUILTIN_METHOD(Object, seal) 114 | // BUILTIN_METHOD(Object, setPrototypeOf) 115 | // BUILTIN_METHOD(Object, values) 116 | 117 | BUILTIN_OBJECT(String) 118 | BUILTIN_METHOD(String, fromCharCode) 119 | 120 | PRIVATE_BUILTIN(silentSetPrototypeOf) 121 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 122 | PRIVATE_BUILTIN(requireFast) 123 | PRIVATE_BUILTIN(getTemplateObject) 124 | PRIVATE_BUILTIN(ensureObject) 125 | PRIVATE_BUILTIN(getMethod) 126 | PRIVATE_BUILTIN(throwTypeError) 127 | PRIVATE_BUILTIN(generatorSetDelegated) 128 | PRIVATE_BUILTIN(copyDataProperties) 129 | PRIVATE_BUILTIN(copyRestArgs) 130 | PRIVATE_BUILTIN(arraySpread) 131 | PRIVATE_BUILTIN(apply) 132 | PRIVATE_BUILTIN(exportAll) 133 | PRIVATE_BUILTIN(exponentiationOperator) 134 | 135 | JS_BUILTIN(spawnAsync) 136 | MARK_FIRST_JS_BUILTIN(spawnAsync) 137 | 138 | #undef BUILTIN_OBJECT 139 | #undef BUILTIN_METHOD 140 | #undef PRIVATE_BUILTIN 141 | #undef MARK_FIRST_PRIVATE_BUILTIN 142 | #undef JS_BUILTIN 143 | #undef MARK_FIRST_JS_BUILTIN 144 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.2.1.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | ///===----------------------------------------------------------------------=== 8 | /// \file 9 | /// Define global objects and methods which the compiler can assume have not 10 | /// been overwritten and can be treated as builtins. 11 | /// 12 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 13 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 14 | /// YOU MODIFY THIS FILE. 15 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 16 | ///===----------------------------------------------------------------------=== 17 | 18 | #ifndef BUILTIN_OBJECT 19 | #define BUILTIN_OBJECT(object) 20 | #endif 21 | #ifndef BUILTIN_METHOD 22 | #define BUILTIN_METHOD(object, name) 23 | #endif 24 | 25 | BUILTIN_OBJECT(Array) 26 | // BUILTIN_METHOD(Array, from) 27 | BUILTIN_METHOD(Array, isArray) 28 | 29 | BUILTIN_OBJECT(ArrayBuffer) 30 | BUILTIN_METHOD(ArrayBuffer, isView) 31 | 32 | BUILTIN_OBJECT(Date) 33 | BUILTIN_METHOD(Date, UTC) 34 | BUILTIN_METHOD(Date, now) 35 | BUILTIN_METHOD(Date, parse) 36 | 37 | BUILTIN_OBJECT(HermesInternal) 38 | BUILTIN_METHOD(HermesInternal, getEpilogues) 39 | BUILTIN_METHOD(HermesInternal, silentSetPrototypeOf) 40 | BUILTIN_METHOD(HermesInternal, requireFast) 41 | BUILTIN_METHOD(HermesInternal, getTemplateObject) 42 | BUILTIN_METHOD(HermesInternal, ensureObject) 43 | BUILTIN_METHOD(HermesInternal, copyDataProperties) 44 | BUILTIN_METHOD(HermesInternal, copyRestArgs) 45 | BUILTIN_METHOD(HermesInternal, exportAll) 46 | BUILTIN_METHOD(HermesInternal, exponentiationOperator) 47 | 48 | BUILTIN_OBJECT(JSON) 49 | BUILTIN_METHOD(JSON, parse) 50 | BUILTIN_METHOD(JSON, stringify) 51 | 52 | BUILTIN_OBJECT(Math) 53 | BUILTIN_METHOD(Math, abs) 54 | BUILTIN_METHOD(Math, acos) 55 | BUILTIN_METHOD(Math, asin) 56 | BUILTIN_METHOD(Math, atan) 57 | BUILTIN_METHOD(Math, atan2) 58 | BUILTIN_METHOD(Math, ceil) 59 | BUILTIN_METHOD(Math, cos) 60 | BUILTIN_METHOD(Math, exp) 61 | BUILTIN_METHOD(Math, floor) 62 | BUILTIN_METHOD(Math, hypot) 63 | BUILTIN_METHOD(Math, imul) 64 | BUILTIN_METHOD(Math, log) 65 | BUILTIN_METHOD(Math, max) 66 | BUILTIN_METHOD(Math, min) 67 | BUILTIN_METHOD(Math, pow) 68 | BUILTIN_METHOD(Math, random) 69 | BUILTIN_METHOD(Math, round) 70 | BUILTIN_METHOD(Math, sin) 71 | BUILTIN_METHOD(Math, sqrt) 72 | BUILTIN_METHOD(Math, tan) 73 | BUILTIN_METHOD(Math, trunc) 74 | 75 | // BUILTIN_OBJECT(Number) 76 | // BUILTIN_METHOD(Number, isNaN) 77 | 78 | BUILTIN_OBJECT(Object) 79 | BUILTIN_METHOD(Object, create) 80 | BUILTIN_METHOD(Object, defineProperties) 81 | BUILTIN_METHOD(Object, defineProperty) 82 | // BUILTIN_METHOD(Object, entries) 83 | BUILTIN_METHOD(Object, freeze) 84 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 85 | BUILTIN_METHOD(Object, getOwnPropertyNames) 86 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 87 | BUILTIN_METHOD(Object, getPrototypeOf) 88 | BUILTIN_METHOD(Object, isExtensible) 89 | BUILTIN_METHOD(Object, isFrozen) 90 | BUILTIN_METHOD(Object, keys) 91 | BUILTIN_METHOD(Object, seal) 92 | // BUILTIN_METHOD(Object, setPrototypeOf) 93 | // BUILTIN_METHOD(Object, values) 94 | 95 | BUILTIN_OBJECT(String) 96 | BUILTIN_METHOD(String, fromCharCode) 97 | 98 | #undef BUILTIN_OBJECT 99 | #undef BUILTIN_METHOD 100 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.7.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define global objects and methods which the compiler can assume have not 11 | /// been overwritten and can be treated as builtins. 12 | /// 13 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 15 | /// YOU MODIFY THIS FILE. 16 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 | ///===----------------------------------------------------------------------=== 18 | 19 | #ifndef BUILTIN_OBJECT 20 | #define BUILTIN_OBJECT(object) 21 | #endif 22 | #ifndef BUILTIN_METHOD 23 | #define BUILTIN_METHOD(object, name) 24 | #endif 25 | #ifndef PRIVATE_BUILTIN 26 | #define PRIVATE_BUILTIN(name) 27 | #endif 28 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 29 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 30 | #endif 31 | 32 | BUILTIN_OBJECT(Array) 33 | // BUILTIN_METHOD(Array, from) 34 | BUILTIN_METHOD(Array, isArray) 35 | 36 | BUILTIN_OBJECT(ArrayBuffer) 37 | BUILTIN_METHOD(ArrayBuffer, isView) 38 | 39 | BUILTIN_OBJECT(Date) 40 | BUILTIN_METHOD(Date, UTC) 41 | BUILTIN_METHOD(Date, now) 42 | BUILTIN_METHOD(Date, parse) 43 | 44 | // BUILTIN_OBJECT(HermesInternal) 45 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 46 | 47 | BUILTIN_OBJECT(JSON) 48 | BUILTIN_METHOD(JSON, parse) 49 | BUILTIN_METHOD(JSON, stringify) 50 | 51 | BUILTIN_OBJECT(Math) 52 | BUILTIN_METHOD(Math, abs) 53 | BUILTIN_METHOD(Math, acos) 54 | BUILTIN_METHOD(Math, asin) 55 | BUILTIN_METHOD(Math, atan) 56 | BUILTIN_METHOD(Math, atan2) 57 | BUILTIN_METHOD(Math, ceil) 58 | BUILTIN_METHOD(Math, cos) 59 | BUILTIN_METHOD(Math, exp) 60 | BUILTIN_METHOD(Math, floor) 61 | BUILTIN_METHOD(Math, hypot) 62 | BUILTIN_METHOD(Math, imul) 63 | BUILTIN_METHOD(Math, log) 64 | BUILTIN_METHOD(Math, max) 65 | BUILTIN_METHOD(Math, min) 66 | BUILTIN_METHOD(Math, pow) 67 | BUILTIN_METHOD(Math, random) 68 | BUILTIN_METHOD(Math, round) 69 | BUILTIN_METHOD(Math, sin) 70 | BUILTIN_METHOD(Math, sqrt) 71 | BUILTIN_METHOD(Math, tan) 72 | BUILTIN_METHOD(Math, trunc) 73 | 74 | // BUILTIN_OBJECT(Number) 75 | // BUILTIN_METHOD(Number, isNaN) 76 | 77 | BUILTIN_OBJECT(Object) 78 | BUILTIN_METHOD(Object, create) 79 | BUILTIN_METHOD(Object, defineProperties) 80 | BUILTIN_METHOD(Object, defineProperty) 81 | // BUILTIN_METHOD(Object, entries) 82 | BUILTIN_METHOD(Object, freeze) 83 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 84 | BUILTIN_METHOD(Object, getOwnPropertyNames) 85 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 86 | BUILTIN_METHOD(Object, getPrototypeOf) 87 | BUILTIN_METHOD(Object, isExtensible) 88 | BUILTIN_METHOD(Object, isFrozen) 89 | BUILTIN_METHOD(Object, keys) 90 | BUILTIN_METHOD(Object, seal) 91 | // BUILTIN_METHOD(Object, setPrototypeOf) 92 | // BUILTIN_METHOD(Object, values) 93 | 94 | BUILTIN_OBJECT(String) 95 | BUILTIN_METHOD(String, fromCharCode) 96 | 97 | PRIVATE_BUILTIN(silentSetPrototypeOf) 98 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 99 | PRIVATE_BUILTIN(requireFast) 100 | PRIVATE_BUILTIN(getTemplateObject) 101 | PRIVATE_BUILTIN(ensureObject) 102 | PRIVATE_BUILTIN(getMethod) 103 | PRIVATE_BUILTIN(throwTypeError) 104 | PRIVATE_BUILTIN(generatorSetDelegated) 105 | PRIVATE_BUILTIN(copyDataProperties) 106 | PRIVATE_BUILTIN(copyRestArgs) 107 | PRIVATE_BUILTIN(arraySpread) 108 | PRIVATE_BUILTIN(apply) 109 | PRIVATE_BUILTIN(exportAll) 110 | PRIVATE_BUILTIN(exponentiationOperator) 111 | 112 | #undef BUILTIN_OBJECT 113 | #undef BUILTIN_METHOD 114 | #undef PRIVATE_BUILTIN 115 | #undef MARK_FIRST_PRIVATE_BUILTIN 116 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.8.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(ArrayBuffer) 66 | BUILTIN_METHOD(ArrayBuffer, isView) 67 | 68 | BUILTIN_OBJECT(Date) 69 | BUILTIN_METHOD(Date, UTC) 70 | BUILTIN_METHOD(Date, now) 71 | BUILTIN_METHOD(Date, parse) 72 | 73 | // BUILTIN_OBJECT(HermesInternal) 74 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 75 | 76 | BUILTIN_OBJECT(JSON) 77 | BUILTIN_METHOD(JSON, parse) 78 | BUILTIN_METHOD(JSON, stringify) 79 | 80 | BUILTIN_OBJECT(Math) 81 | BUILTIN_METHOD(Math, abs) 82 | BUILTIN_METHOD(Math, acos) 83 | BUILTIN_METHOD(Math, asin) 84 | BUILTIN_METHOD(Math, atan) 85 | BUILTIN_METHOD(Math, atan2) 86 | BUILTIN_METHOD(Math, ceil) 87 | BUILTIN_METHOD(Math, cos) 88 | BUILTIN_METHOD(Math, exp) 89 | BUILTIN_METHOD(Math, floor) 90 | BUILTIN_METHOD(Math, hypot) 91 | BUILTIN_METHOD(Math, imul) 92 | BUILTIN_METHOD(Math, log) 93 | BUILTIN_METHOD(Math, max) 94 | BUILTIN_METHOD(Math, min) 95 | BUILTIN_METHOD(Math, pow) 96 | BUILTIN_METHOD(Math, random) 97 | BUILTIN_METHOD(Math, round) 98 | BUILTIN_METHOD(Math, sin) 99 | BUILTIN_METHOD(Math, sqrt) 100 | BUILTIN_METHOD(Math, tan) 101 | BUILTIN_METHOD(Math, trunc) 102 | 103 | // BUILTIN_OBJECT(Number) 104 | // BUILTIN_METHOD(Number, isNaN) 105 | 106 | BUILTIN_OBJECT(Object) 107 | BUILTIN_METHOD(Object, create) 108 | BUILTIN_METHOD(Object, defineProperties) 109 | BUILTIN_METHOD(Object, defineProperty) 110 | // BUILTIN_METHOD(Object, entries) 111 | BUILTIN_METHOD(Object, freeze) 112 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 113 | BUILTIN_METHOD(Object, getOwnPropertyNames) 114 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 115 | BUILTIN_METHOD(Object, getPrototypeOf) 116 | BUILTIN_METHOD(Object, isExtensible) 117 | BUILTIN_METHOD(Object, isFrozen) 118 | BUILTIN_METHOD(Object, keys) 119 | BUILTIN_METHOD(Object, seal) 120 | // BUILTIN_METHOD(Object, setPrototypeOf) 121 | // BUILTIN_METHOD(Object, values) 122 | 123 | BUILTIN_OBJECT(String) 124 | BUILTIN_METHOD(String, fromCharCode) 125 | 126 | PRIVATE_BUILTIN(silentSetPrototypeOf) 127 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 128 | PRIVATE_BUILTIN(requireFast) 129 | PRIVATE_BUILTIN(getTemplateObject) 130 | PRIVATE_BUILTIN(ensureObject) 131 | PRIVATE_BUILTIN(getMethod) 132 | PRIVATE_BUILTIN(throwTypeError) 133 | PRIVATE_BUILTIN(generatorSetDelegated) 134 | PRIVATE_BUILTIN(copyDataProperties) 135 | PRIVATE_BUILTIN(copyRestArgs) 136 | PRIVATE_BUILTIN(arraySpread) 137 | PRIVATE_BUILTIN(apply) 138 | PRIVATE_BUILTIN(exportAll) 139 | PRIVATE_BUILTIN(exponentiationOperator) 140 | 141 | JS_BUILTIN(spawnAsync) 142 | MARK_FIRST_JS_BUILTIN(spawnAsync) 143 | 144 | #undef BUILTIN_OBJECT 145 | #undef BUILTIN_METHOD 146 | #undef PRIVATE_BUILTIN 147 | #undef MARK_FIRST_PRIVATE_BUILTIN 148 | #undef JS_BUILTIN 149 | #undef MARK_FIRST_JS_BUILTIN 150 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/Builtins-v0.9.0.def: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | ///===----------------------------------------------------------------------=== 9 | /// \file 10 | /// Define Hermes builtin functions. 11 | /// 12 | /// All builtin functions in Hermes are registered in a vector of `Callable *` 13 | /// in the runtime with an index as its builtin method id. 14 | /// 15 | /// There are 3 kinds of builtins in Hermes: 16 | /// 1. (Public Native) Builtins: those are global objects and methods of JSLib 17 | /// implemented natively which the compiler can assume have not been 18 | /// overwritten and can be treated as builtins under the "static builtin" 19 | /// optimizations (`-fstatic-builtins` flag). 20 | /// 21 | /// 2. Private (Native) Builtins: those are native functions meant to be only 22 | /// called internally by the compiler to help with implementing JS features 23 | /// without introducing extra opcodes. They are notationally written as 24 | /// `HermesBuiltin_name`. 25 | /// 26 | /// 3. (Private) JS Builtins: those are JS functions returned from the result of 27 | /// executing internal bytecode. They are also there to help with implementing 28 | /// JS features. 29 | /// 30 | /// At this moment, 31 | /// Native builtins are invoked via `CallBuiltin` instruction. 32 | /// JS builtins are invoked via `GetBuiltinClosure` followed by a `Call`. 33 | /// 34 | /// We might separate them in the future. 35 | /// 36 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 37 | /// IMPORTANT: DO NOT FORGET TO INCREASE THE BYTECODE FILE FORMAT VERSION IF 38 | /// YOU MODIFY THIS FILE. 39 | /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40 | ///===----------------------------------------------------------------------=== 41 | 42 | #ifndef BUILTIN_OBJECT 43 | #define BUILTIN_OBJECT(object) 44 | #endif 45 | #ifndef BUILTIN_METHOD 46 | #define BUILTIN_METHOD(object, name) 47 | #endif 48 | #ifndef PRIVATE_BUILTIN 49 | #define PRIVATE_BUILTIN(name) 50 | #endif 51 | #ifndef MARK_FIRST_PRIVATE_BUILTIN 52 | #define MARK_FIRST_PRIVATE_BUILTIN(name) 53 | #endif 54 | #ifndef JS_BUILTIN 55 | #define JS_BUILTIN(name) 56 | #endif 57 | #ifndef MARK_FIRST_JS_BUILTIN 58 | #define MARK_FIRST_JS_BUILTIN(name) 59 | #endif 60 | 61 | BUILTIN_OBJECT(Array) 62 | // BUILTIN_METHOD(Array, from) 63 | BUILTIN_METHOD(Array, isArray) 64 | 65 | BUILTIN_OBJECT(ArrayBuffer) 66 | BUILTIN_METHOD(ArrayBuffer, isView) 67 | 68 | BUILTIN_OBJECT(Date) 69 | BUILTIN_METHOD(Date, UTC) 70 | BUILTIN_METHOD(Date, now) 71 | BUILTIN_METHOD(Date, parse) 72 | 73 | // BUILTIN_OBJECT(HermesInternal) 74 | // BUILTIN_METHOD(HermesInternal, getEpilogues) 75 | 76 | BUILTIN_OBJECT(JSON) 77 | BUILTIN_METHOD(JSON, parse) 78 | BUILTIN_METHOD(JSON, stringify) 79 | 80 | BUILTIN_OBJECT(Math) 81 | BUILTIN_METHOD(Math, abs) 82 | BUILTIN_METHOD(Math, acos) 83 | BUILTIN_METHOD(Math, asin) 84 | BUILTIN_METHOD(Math, atan) 85 | BUILTIN_METHOD(Math, atan2) 86 | BUILTIN_METHOD(Math, ceil) 87 | BUILTIN_METHOD(Math, cos) 88 | BUILTIN_METHOD(Math, exp) 89 | BUILTIN_METHOD(Math, floor) 90 | BUILTIN_METHOD(Math, hypot) 91 | BUILTIN_METHOD(Math, imul) 92 | BUILTIN_METHOD(Math, log) 93 | BUILTIN_METHOD(Math, max) 94 | BUILTIN_METHOD(Math, min) 95 | BUILTIN_METHOD(Math, pow) 96 | BUILTIN_METHOD(Math, random) 97 | BUILTIN_METHOD(Math, round) 98 | BUILTIN_METHOD(Math, sin) 99 | BUILTIN_METHOD(Math, sqrt) 100 | BUILTIN_METHOD(Math, tan) 101 | BUILTIN_METHOD(Math, trunc) 102 | 103 | // BUILTIN_OBJECT(Number) 104 | // BUILTIN_METHOD(Number, isNaN) 105 | 106 | BUILTIN_OBJECT(Object) 107 | BUILTIN_METHOD(Object, create) 108 | BUILTIN_METHOD(Object, defineProperties) 109 | BUILTIN_METHOD(Object, defineProperty) 110 | // BUILTIN_METHOD(Object, entries) 111 | BUILTIN_METHOD(Object, freeze) 112 | BUILTIN_METHOD(Object, getOwnPropertyDescriptor) 113 | BUILTIN_METHOD(Object, getOwnPropertyNames) 114 | // BUILTIN_METHOD(Object, getOwnPropertySymbols) 115 | BUILTIN_METHOD(Object, getPrototypeOf) 116 | BUILTIN_METHOD(Object, isExtensible) 117 | BUILTIN_METHOD(Object, isFrozen) 118 | BUILTIN_METHOD(Object, keys) 119 | BUILTIN_METHOD(Object, seal) 120 | // BUILTIN_METHOD(Object, setPrototypeOf) 121 | // BUILTIN_METHOD(Object, values) 122 | 123 | BUILTIN_OBJECT(String) 124 | BUILTIN_METHOD(String, fromCharCode) 125 | 126 | PRIVATE_BUILTIN(silentSetPrototypeOf) 127 | MARK_FIRST_PRIVATE_BUILTIN(silentSetPrototypeOf) 128 | PRIVATE_BUILTIN(requireFast) 129 | PRIVATE_BUILTIN(getTemplateObject) 130 | PRIVATE_BUILTIN(ensureObject) 131 | PRIVATE_BUILTIN(getMethod) 132 | PRIVATE_BUILTIN(throwTypeError) 133 | PRIVATE_BUILTIN(generatorSetDelegated) 134 | PRIVATE_BUILTIN(copyDataProperties) 135 | PRIVATE_BUILTIN(copyRestArgs) 136 | PRIVATE_BUILTIN(arraySpread) 137 | PRIVATE_BUILTIN(apply) 138 | PRIVATE_BUILTIN(exportAll) 139 | PRIVATE_BUILTIN(exponentiationOperator) 140 | 141 | JS_BUILTIN(spawnAsync) 142 | MARK_FIRST_JS_BUILTIN(spawnAsync) 143 | 144 | #undef BUILTIN_OBJECT 145 | #undef BUILTIN_METHOD 146 | #undef PRIVATE_BUILTIN 147 | #undef MARK_FIRST_PRIVATE_BUILTIN 148 | #undef JS_BUILTIN 149 | #undef MARK_FIRST_JS_BUILTIN 150 | -------------------------------------------------------------------------------- /utils/original_function_builtins_c_src/get_source_codes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script fetches various bits of Hermes source code 4 | # to the current directory, for exploratory use. 5 | 6 | # Exit on non-success 7 | set -e 8 | 9 | # How to list Hermes Git source tags: 10 | # git -C ~/hermes fetch; git -C ~/hermes tag -l 'v*' | grep -v rc | sort -V | tr '\n' ' '; echo 11 | # ("sort -V" means versioning-like sort) 12 | 13 | cd "$(dirname "$0")" 14 | source ../git_tags.sh 15 | 16 | verlte() { 17 | [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] 18 | } 19 | 20 | for git_tag in ${GIT_TAGS[@]}; do 21 | hbc_version=${TAG_TO_VERSION[${git_tag}]} 22 | 23 | echo "Downloading files for ${git_tag}..." 24 | if [ -z ${hbc_version} ]; then 25 | if verlte "${git_tag}" "v0.3.0"; then 26 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/Inst/Builtins.def" -O "Builtins-${git_tag}.def" 27 | else 28 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/FrontEndDefs/Builtins.def" -O "Builtins-${git_tag}.def" 29 | fi 30 | else 31 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/FrontEndDefs/Builtins.def" -O "Builtins-${hbc_version}.def" || wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/Inst/Builtins.def" -O "Builtins-${hbc_version}.def" 32 | fi 33 | done 34 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-hbc86.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Jun 27, 2022 23 | const static uint32_t BYTECODE_VERSION = 86; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-hbc87.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Jun 29, 2022 23 | const static uint32_t BYTECODE_VERSION = 87; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-hbc90.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Sep 19, 2022 23 | const static uint32_t BYTECODE_VERSION = 90; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-hbc92.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Feb 7, 2023 23 | const static uint32_t BYTECODE_VERSION = 92; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-hbc95.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Mar 22, 2023 23 | const static uint32_t BYTECODE_VERSION = 95; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-v0.11.0.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Jul 06, 2021 23 | const static uint32_t BYTECODE_VERSION = 84; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-v0.12.0.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Jul 6, 2022 23 | const static uint32_t BYTECODE_VERSION = 89; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/BytecodeVersion-v0.9.0.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #ifndef HERMES_BCGEN_HBC_BYTECODEVERSION_H 9 | #define HERMES_BCGEN_HBC_BYTECODEVERSION_H 10 | 11 | #include 12 | 13 | /* 14 | * This file should *only* contain the version number constant definition, 15 | * to enable tooling to determine whether the version has been updated. 16 | */ 17 | 18 | namespace hermes { 19 | namespace hbc { 20 | 21 | // Bytecode version generated by this version of the compiler. 22 | // Updated: Jul 06, 2021 23 | const static uint32_t BYTECODE_VERSION = 84; 24 | 25 | } // namespace hbc 26 | } // namespace hermes 27 | 28 | #endif // HERMES_BCGEN_HBC_BYTECODEVERSION_H 29 | -------------------------------------------------------------------------------- /utils/original_hermes_bytecode_c_src/get_source_codes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script fetches various bits of Hermes source code 4 | # to the current directory, for exploratory use. 5 | 6 | # Exit on non-success 7 | set -e 8 | 9 | # How to list Hermes Git source tags: 10 | # git -C ~/hermes fetch; git -C ~/hermes tag -l 'v*' | grep -v rc | sort -V | tr '\n' ' '; echo 11 | # ("sort -V" means versioning-like sort) 12 | 13 | cd "$(dirname "$0")" 14 | source ../git_tags.sh 15 | 16 | verlte() { 17 | [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] 18 | } 19 | 20 | for git_tag in ${GIT_TAGS[@]}; do 21 | hbc_version=${TAG_TO_VERSION[${git_tag}]} 22 | 23 | echo "Downloading files for ${git_tag}..." 24 | if [ -z ${hbc_version} ]; then 25 | if verlte "${git_tag}" "v0.8.0"; then 26 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeFileFormat.h" -O "BytecodeVersion-${git_tag}.h" 27 | else 28 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeVersion.h" -O "BytecodeVersion-${git_tag}.h" 29 | fi 30 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeList.def" -O "BytecodeList-${git_tag}.def" 31 | else 32 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeVersion.h" -O "BytecodeVersion-${hbc_version}.h" || wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeFileFormat.h" -O "BytecodeVersion-${hbc_version}.h" 33 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/BCGen/HBC/BytecodeList.def" -O "BytecodeList-${hbc_version}.def" 34 | fi 35 | done 36 | -------------------------------------------------------------------------------- /utils/original_regex_bytecode_c_src/RegexBytecode-v0.0.1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | #ifndef HERMES_REGEX_REGEXBYTECODE_H 8 | #define HERMES_REGEX_REGEXBYTECODE_H 9 | 10 | #include "llvm/ADT/DenseMap.h" 11 | #include "llvm/Support/Casting.h" 12 | 13 | #include 14 | #include 15 | 16 | namespace hermes { 17 | namespace regex { 18 | 19 | /// Define the enum class of regex opcodes. 20 | #define REOP(code) code, 21 | enum class Opcode : uint8_t { 22 | #include "hermes/Regex/RegexOpcodes.def" 23 | }; 24 | 25 | /// Type representing a jump location, as a 32 bit value. 26 | using JumpTarget32 = uint32_t; 27 | 28 | /// Type representing a set of MatchConstraint flags as a bitmask. 29 | using MatchConstraintSet = uint8_t; 30 | 31 | /// The list of Instructions corresponding to our Opcodes. 32 | /// Our instructions are packed with byte alignment, beacuse they need ton be 33 | /// serializable directly. 34 | LLVM_PACKED_START 35 | 36 | /// Base instruction type. All instructions derive from this. Note that Insn and 37 | /// its subclasses support LLVM RTTI (isa, cast, dyn_cast, etc). 38 | struct Insn { 39 | Opcode opcode; 40 | }; 41 | 42 | struct GoalInsn : public Insn {}; 43 | struct LeftAnchorInsn : public Insn {}; 44 | struct RightAnchorInsn : public Insn {}; 45 | struct MatchAnyButNewlineInsn : public Insn {}; 46 | struct MatchChar8Insn : public Insn { 47 | char c; 48 | }; 49 | struct MatchChar16Insn : public Insn { 50 | char16_t c; 51 | }; 52 | 53 | // Instructions for case-insensitive matching. c is already case-folded. 54 | struct MatchCharICase8Insn : public Insn { 55 | char c; 56 | }; 57 | struct MatchCharICase16Insn : public Insn { 58 | char16_t c; 59 | }; 60 | struct AlternationInsn : public Insn { 61 | /// The primary branch is the Insn following the alternation, while the 62 | /// secondary branch is at the secondaryBranch jump target. Both branches have 63 | /// constraints which determine whether they are viable. 64 | JumpTarget32 secondaryBranch; 65 | MatchConstraintSet primaryConstraints; 66 | MatchConstraintSet secondaryConstraints; 67 | }; 68 | struct Jump32Insn : public Insn { 69 | JumpTarget32 target; 70 | }; 71 | 72 | /// A BracketRange represents an inclusive range of characters in a bracket, 73 | /// such as /[a-z]/. Singletons like /[a]/ are represented as the range a-a. 74 | struct BracketRange16 { 75 | char16_t start; 76 | char16_t end; 77 | }; 78 | struct BackRefInsn : public Insn { 79 | uint16_t mexp; 80 | }; 81 | 82 | /// BracketInsn is a variable-width instruction. Each BracketInsn is followed by 83 | /// a sequence of BracketRange16 in the bytecode stream. 84 | struct BracketInsn : public Insn { 85 | /// Number of BracketRange16s following this instruction. 86 | uint32_t rangeCount; 87 | /// Whether the bracket is negated (leading ^). 88 | uint8_t negate : 1; 89 | 90 | /// A bitmask containing the three positive character classes \d \s \w, and a 91 | /// negative companion for their inverts \D \S \W. See CharacterClass::Type 92 | /// for the flag values. 93 | uint8_t positiveCharClasses : 3; 94 | uint8_t negativeCharClasses : 3; 95 | 96 | /// \return the width of this instruction plus its bracket ranges. 97 | uint32_t totalWidth() const { 98 | return sizeof(*this) + rangeCount * sizeof(BracketRange16); 99 | } 100 | }; 101 | 102 | // See BytecodeFileFormatTest for details about bit field layouts 103 | static_assert( 104 | sizeof(BracketInsn) == 6, 105 | "BracketInsn should take up 6 byte total"); 106 | 107 | struct WordBoundaryInsn : public Insn { 108 | /// Whether the boundary is inverted (\B instead of \b). 109 | bool invert; 110 | }; 111 | 112 | /// Begin/EndMarkedSubexpression stores the index of the marked subexpression. 113 | /// Note that the first marked subexpression has index 1 (0 is reserved for 114 | /// the entire match). 115 | struct BeginMarkedSubexpressionInsn : public Insn { 116 | uint16_t mexp; 117 | }; 118 | struct EndMarkedSubexpressionInsn : public Insn { 119 | uint16_t mexp; 120 | }; 121 | 122 | /// A LookaheadInsn is immediately followed by bytecode for its contained 123 | /// expression. It has a jump target to its continuation. 124 | struct LookaheadInsn : public Insn { 125 | /// Whether we are inverted: (?!...) instead of (?=...). 126 | bool invert; 127 | /// Constraints on what can match the contained expression. 128 | MatchConstraintSet constraints; 129 | // The subexpression marked regions we want to be able to backtrack. 130 | uint16_t mexpBegin; 131 | uint16_t mexpEnd; 132 | /// Jump target if the lookahead matches. 133 | JumpTarget32 continuation; 134 | }; 135 | 136 | /// An instruction for entering a loop. This supports all loop constructs 137 | /// available in regexp, and includes optional nongreedy support, min/max 138 | /// counts, and enclosed capture groups. The body of the loop is the Insn 139 | /// following the BeginLoopInsn, while the not-taken target is stored following 140 | /// the loop body. 141 | struct BeginLoopInsn : public Insn { 142 | /// The LoopID is used to index into the state to count iterations and track 143 | /// the entry position. 144 | uint32_t loopId; 145 | 146 | /// Minimum and maximum iterations. 147 | /// For an unbounded loop (including Kleene star), max is UINT32_MAX 148 | uint32_t min; 149 | uint32_t max; 150 | 151 | /// Range of marked subexpressions enclosed by the loop, as [begin, end). 152 | uint32_t mexpBegin; 153 | uint32_t mexpEnd; 154 | 155 | /// Whether the loop is greedy (i.e. * instead of *?) 156 | bool greedy; 157 | 158 | /// Set of constraints on what can match the loop body. 159 | MatchConstraintSet loopeeConstraints; 160 | 161 | /// The not-taken target for the loop. 162 | JumpTarget32 notTakenTarget; 163 | }; 164 | 165 | /// An instruction that closes a loop, appearing after the loop body. 166 | /// The target is always a BeginLoopInsn. 167 | struct EndLoopInsn : public Insn { 168 | JumpTarget32 target; 169 | }; 170 | 171 | /// An instruction for entering a simple loop. This supports only loops that: 172 | /// - have no minimum or maximum, 173 | /// - do not contain any capture groups, 174 | /// - are greedy, and 175 | /// - have a body that cannot match the empty string. 176 | struct BeginSimpleLoopInsn : public Insn { 177 | /// We don't need a loop ID like BeginLoopInsn because we don't need to 178 | /// track the iteration count or the entry position. 179 | 180 | /// Set of constraints on what can match the loop body. 181 | MatchConstraintSet loopeeConstraints; 182 | 183 | /// The not-taken target for the loop. 184 | JumpTarget32 notTakenTarget; 185 | }; 186 | 187 | /// An instruction that closes a simple loop, appearing after the loop body. 188 | /// The target is always a BeginSimpleLoopInsn. 189 | struct EndSimpleLoopInsn : public Insn { 190 | JumpTarget32 target; 191 | }; 192 | 193 | /// An instruction for entering a loop whose body always matches one character 194 | /// and does not contain any capture groups. 195 | struct Width1LoopInsn : public Insn { 196 | /// The LoopID is used to index into the state to count iterations and track 197 | /// the entry position. 198 | uint32_t loopId; 199 | 200 | /// Minimum and maximum iterations. 201 | /// For an unbounded loop (including Kleene star), max is UINT32_MAX 202 | uint32_t min; 203 | uint32_t max; 204 | 205 | /// Whether the loop is greedy (i.e. * instead of *?) 206 | bool greedy; 207 | 208 | /// The not-taken target for the loop. 209 | JumpTarget32 notTakenTarget; 210 | }; 211 | 212 | /// A header that appears at the beginning of a bytecode stream. 213 | struct RegexBytecodeHeader { 214 | /// Number of capture groups. 215 | uint16_t markedCount; 216 | 217 | /// Number of loops. 218 | uint16_t loopCount; 219 | 220 | /// Syntax flags used to construct the regex. 221 | uint8_t syntaxFlags; 222 | 223 | /// Constraints on what strings can match this regex. 224 | MatchConstraintSet constraints; 225 | }; 226 | 227 | LLVM_PACKED_END; 228 | 229 | /// OpcodeFor::value is the opcode for the Instruction. 230 | template 231 | struct OpcodeFor {}; 232 | 233 | #define REOP(Code) \ 234 | template <> \ 235 | struct OpcodeFor { \ 236 | static constexpr Opcode value = Opcode::Code; \ 237 | }; 238 | #include "hermes/Regex/RegexOpcodes.def" 239 | 240 | /// A class representing a regex compiled to a bytecode stream. 241 | class RegexBytecodeStream { 242 | /// The stream of instructions encoded as bytes. 243 | std::vector bytes_; 244 | 245 | /// Whether our bytecode has been acquired. 246 | bool acquired_ = false; 247 | 248 | /// Private type acting as a reallocation-safe pointer to an instruction. 249 | /// This stores a pointer to the vector and an offset, rather than a pointer 250 | /// into the vector contents. 251 | template 252 | class InstructionWrapper { 253 | std::vector *const bytes_; 254 | const uint32_t offset_; 255 | 256 | public: 257 | Instruction *operator->() { 258 | Insn *base = reinterpret_cast(&bytes_->at(offset_)); 259 | return llvm::cast(base); 260 | } 261 | 262 | InstructionWrapper(std::vector *bytes, uint32_t offset) 263 | : bytes_(bytes), offset_(offset) {} 264 | }; 265 | 266 | public: 267 | /// Emit an instruction. 268 | /// \return a dereferenceable "pointer" to the instruction in the bytecode 269 | /// stream. 270 | template 271 | InstructionWrapper emit() { 272 | size_t startSize = bytes_.size(); 273 | bytes_.resize(startSize + sizeof(Instruction), 0); 274 | Insn *insn = reinterpret_cast(&bytes_[startSize]); 275 | insn->opcode = OpcodeFor::value; 276 | return InstructionWrapper(&bytes_, startSize); 277 | } 278 | 279 | /// Emit a BracketRange16. 280 | void emitBracketRange(BracketRange16 range) { 281 | const uint8_t *rangeBytes = reinterpret_cast(&range); 282 | bytes_.insert(bytes_.end(), rangeBytes, rangeBytes + sizeof(range)); 283 | } 284 | 285 | /// \return the current offset in the stream, which is where the next 286 | /// instruction will be emitted. Note the header is omitted. 287 | uint32_t currentOffset() const { 288 | return bytes_.size() - sizeof(RegexBytecodeHeader); 289 | } 290 | 291 | /// \return the bytecode, transferring ownership of it to the caller. 292 | std::vector acquireBytecode() { 293 | assert(!acquired_ && "Bytecode already acquired"); 294 | acquired_ = true; 295 | return std::move(bytes_); 296 | } 297 | 298 | /// Construct a RegexBytecodeStream starting with a header. 299 | RegexBytecodeStream(const RegexBytecodeHeader &header) { 300 | const uint8_t *headerBytes = reinterpret_cast(&header); 301 | bytes_.insert(bytes_.end(), headerBytes, headerBytes + sizeof header); 302 | } 303 | }; 304 | 305 | } // namespace regex 306 | } // namespace hermes 307 | 308 | namespace llvm { 309 | /// LLVM RTTI implementation for regex instructions. Rather than defining 310 | /// classof() for each instruction struct, which would require a lot of 311 | /// error-prone boilerplate, we take the Casting.h header's suggestion of 312 | /// specializing isa_impl for the case where From is just Insn and To is one of 313 | /// its subclasses. 314 | template 315 | struct isa_impl< 316 | To, 317 | From, 318 | typename std::enable_if< 319 | std::is_same::value && 320 | std::is_base_of::value>::type> { 321 | static inline bool doit(const From &val) { 322 | return val.opcode == hermes::regex::OpcodeFor::value; 323 | } 324 | }; 325 | } // namespace llvm 326 | #endif // HERMES_REGEX_REGEXBYTECODE_H 327 | -------------------------------------------------------------------------------- /utils/original_regex_bytecode_c_src/RegexBytecode-v0.0.2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | #ifndef HERMES_REGEX_REGEXBYTECODE_H 8 | #define HERMES_REGEX_REGEXBYTECODE_H 9 | 10 | #include "llvm/ADT/DenseMap.h" 11 | #include "llvm/Support/Casting.h" 12 | 13 | #include 14 | #include 15 | 16 | namespace hermes { 17 | namespace regex { 18 | 19 | /// Define the enum class of regex opcodes. 20 | #define REOP(code) code, 21 | enum class Opcode : uint8_t { 22 | #include "hermes/Regex/RegexOpcodes.def" 23 | }; 24 | 25 | /// Type representing a jump location, as a 32 bit value. 26 | using JumpTarget32 = uint32_t; 27 | 28 | /// Type representing a set of MatchConstraint flags as a bitmask. 29 | using MatchConstraintSet = uint8_t; 30 | 31 | /// The list of Instructions corresponding to our Opcodes. 32 | /// Our instructions are packed with byte alignment, beacuse they need ton be 33 | /// serializable directly. 34 | LLVM_PACKED_START 35 | 36 | /// Base instruction type. All instructions derive from this. Note that Insn and 37 | /// its subclasses support LLVM RTTI (isa, cast, dyn_cast, etc). 38 | struct Insn { 39 | Opcode opcode; 40 | }; 41 | 42 | struct GoalInsn : public Insn {}; 43 | struct LeftAnchorInsn : public Insn {}; 44 | struct RightAnchorInsn : public Insn {}; 45 | struct MatchAnyButNewlineInsn : public Insn {}; 46 | struct MatchChar8Insn : public Insn { 47 | char c; 48 | }; 49 | struct MatchChar16Insn : public Insn { 50 | char16_t c; 51 | }; 52 | 53 | // Instructions for case-insensitive matching. c is already case-folded. 54 | struct MatchCharICase8Insn : public Insn { 55 | char c; 56 | }; 57 | struct MatchCharICase16Insn : public Insn { 58 | char16_t c; 59 | }; 60 | struct AlternationInsn : public Insn { 61 | /// The primary branch is the Insn following the alternation, while the 62 | /// secondary branch is at the secondaryBranch jump target. Both branches have 63 | /// constraints which determine whether they are viable. 64 | JumpTarget32 secondaryBranch; 65 | MatchConstraintSet primaryConstraints; 66 | MatchConstraintSet secondaryConstraints; 67 | }; 68 | struct Jump32Insn : public Insn { 69 | JumpTarget32 target; 70 | }; 71 | 72 | /// A BracketRange represents an inclusive range of characters in a bracket, 73 | /// such as /[a-z]/. Singletons like /[a]/ are represented as the range a-a. 74 | struct BracketRange16 { 75 | char16_t start; 76 | char16_t end; 77 | }; 78 | struct BackRefInsn : public Insn { 79 | uint16_t mexp; 80 | }; 81 | 82 | /// BracketInsn is a variable-width instruction. Each BracketInsn is followed by 83 | /// a sequence of BracketRange16 in the bytecode stream. 84 | struct BracketInsn : public Insn { 85 | /// Number of BracketRange16s following this instruction. 86 | uint32_t rangeCount; 87 | /// Whether the bracket is negated (leading ^). 88 | uint8_t negate : 1; 89 | 90 | /// A bitmask containing the three positive character classes \d \s \w, and a 91 | /// negative companion for their inverts \D \S \W. See CharacterClass::Type 92 | /// for the flag values. 93 | uint8_t positiveCharClasses : 3; 94 | uint8_t negativeCharClasses : 3; 95 | 96 | /// \return the width of this instruction plus its bracket ranges. 97 | uint32_t totalWidth() const { 98 | return sizeof(*this) + rangeCount * sizeof(BracketRange16); 99 | } 100 | }; 101 | 102 | // See BytecodeFileFormatTest for details about bit field layouts 103 | static_assert( 104 | sizeof(BracketInsn) == 6, 105 | "BracketInsn should take up 6 byte total"); 106 | 107 | struct WordBoundaryInsn : public Insn { 108 | /// Whether the boundary is inverted (\B instead of \b). 109 | bool invert; 110 | }; 111 | 112 | /// Begin/EndMarkedSubexpression stores the index of the marked subexpression. 113 | /// Note that the first marked subexpression has index 1 (0 is reserved for 114 | /// the entire match). 115 | struct BeginMarkedSubexpressionInsn : public Insn { 116 | uint16_t mexp; 117 | }; 118 | struct EndMarkedSubexpressionInsn : public Insn { 119 | uint16_t mexp; 120 | }; 121 | 122 | /// A LookaheadInsn is immediately followed by bytecode for its contained 123 | /// expression. It has a jump target to its continuation. 124 | struct LookaheadInsn : public Insn { 125 | /// Whether we are inverted: (?!...) instead of (?=...). 126 | bool invert; 127 | /// Constraints on what can match the contained expression. 128 | MatchConstraintSet constraints; 129 | // The subexpression marked regions we want to be able to backtrack. 130 | uint16_t mexpBegin; 131 | uint16_t mexpEnd; 132 | /// Jump target if the lookahead matches. 133 | JumpTarget32 continuation; 134 | }; 135 | 136 | /// An instruction for entering a loop. This supports all loop constructs 137 | /// available in regexp, and includes optional nongreedy support, min/max 138 | /// counts, and enclosed capture groups. The body of the loop is the Insn 139 | /// following the BeginLoopInsn, while the not-taken target is stored following 140 | /// the loop body. 141 | struct BeginLoopInsn : public Insn { 142 | /// The LoopID is used to index into the state to count iterations and track 143 | /// the entry position. 144 | uint32_t loopId; 145 | 146 | /// Minimum and maximum iterations. 147 | /// For an unbounded loop (including Kleene star), max is UINT32_MAX 148 | uint32_t min; 149 | uint32_t max; 150 | 151 | /// Range of marked subexpressions enclosed by the loop, as [begin, end). 152 | uint32_t mexpBegin; 153 | uint32_t mexpEnd; 154 | 155 | /// Whether the loop is greedy (i.e. * instead of *?) 156 | bool greedy; 157 | 158 | /// Set of constraints on what can match the loop body. 159 | MatchConstraintSet loopeeConstraints; 160 | 161 | /// The not-taken target for the loop. 162 | JumpTarget32 notTakenTarget; 163 | }; 164 | 165 | /// An instruction that closes a loop, appearing after the loop body. 166 | /// The target is always a BeginLoopInsn. 167 | struct EndLoopInsn : public Insn { 168 | JumpTarget32 target; 169 | }; 170 | 171 | /// An instruction for entering a simple loop. This supports only loops that: 172 | /// - have no minimum or maximum, 173 | /// - do not contain any capture groups, 174 | /// - are greedy, and 175 | /// - have a body that cannot match the empty string. 176 | struct BeginSimpleLoopInsn : public Insn { 177 | /// We don't need a loop ID like BeginLoopInsn because we don't need to 178 | /// track the iteration count or the entry position. 179 | 180 | /// Set of constraints on what can match the loop body. 181 | MatchConstraintSet loopeeConstraints; 182 | 183 | /// The not-taken target for the loop. 184 | JumpTarget32 notTakenTarget; 185 | }; 186 | 187 | /// An instruction that closes a simple loop, appearing after the loop body. 188 | /// The target is always a BeginSimpleLoopInsn. 189 | struct EndSimpleLoopInsn : public Insn { 190 | JumpTarget32 target; 191 | }; 192 | 193 | /// An instruction for entering a loop whose body always matches one character 194 | /// and does not contain any capture groups. 195 | struct Width1LoopInsn : public Insn { 196 | /// The LoopID is used to index into the state to count iterations and track 197 | /// the entry position. 198 | uint32_t loopId; 199 | 200 | /// Minimum and maximum iterations. 201 | /// For an unbounded loop (including Kleene star), max is UINT32_MAX 202 | uint32_t min; 203 | uint32_t max; 204 | 205 | /// Whether the loop is greedy (i.e. * instead of *?) 206 | bool greedy; 207 | 208 | /// The not-taken target for the loop. 209 | JumpTarget32 notTakenTarget; 210 | }; 211 | 212 | /// A header that appears at the beginning of a bytecode stream. 213 | struct RegexBytecodeHeader { 214 | /// Number of capture groups. 215 | uint16_t markedCount; 216 | 217 | /// Number of loops. 218 | uint16_t loopCount; 219 | 220 | /// Syntax flags used to construct the regex. 221 | uint8_t syntaxFlags; 222 | 223 | /// Constraints on what strings can match this regex. 224 | MatchConstraintSet constraints; 225 | }; 226 | 227 | LLVM_PACKED_END; 228 | 229 | /// OpcodeFor::value is the opcode for the Instruction. 230 | template 231 | struct OpcodeFor {}; 232 | 233 | #define REOP(Code) \ 234 | template <> \ 235 | struct OpcodeFor { \ 236 | static constexpr Opcode value = Opcode::Code; \ 237 | }; 238 | #include "hermes/Regex/RegexOpcodes.def" 239 | 240 | /// A class representing a regex compiled to a bytecode stream. 241 | class RegexBytecodeStream { 242 | /// The stream of instructions encoded as bytes. 243 | std::vector bytes_; 244 | 245 | /// Whether our bytecode has been acquired. 246 | bool acquired_ = false; 247 | 248 | /// Private type acting as a reallocation-safe pointer to an instruction. 249 | /// This stores a pointer to the vector and an offset, rather than a pointer 250 | /// into the vector contents. 251 | template 252 | class InstructionWrapper { 253 | std::vector *const bytes_; 254 | const uint32_t offset_; 255 | 256 | public: 257 | Instruction *operator->() { 258 | Insn *base = reinterpret_cast(&bytes_->at(offset_)); 259 | return llvm::cast(base); 260 | } 261 | 262 | InstructionWrapper(std::vector *bytes, uint32_t offset) 263 | : bytes_(bytes), offset_(offset) {} 264 | }; 265 | 266 | public: 267 | /// Emit an instruction. 268 | /// \return a dereferenceable "pointer" to the instruction in the bytecode 269 | /// stream. 270 | template 271 | InstructionWrapper emit() { 272 | size_t startSize = bytes_.size(); 273 | bytes_.resize(startSize + sizeof(Instruction), 0); 274 | Insn *insn = reinterpret_cast(&bytes_[startSize]); 275 | insn->opcode = OpcodeFor::value; 276 | return InstructionWrapper(&bytes_, startSize); 277 | } 278 | 279 | /// Emit a BracketRange16. 280 | void emitBracketRange(BracketRange16 range) { 281 | const uint8_t *rangeBytes = reinterpret_cast(&range); 282 | bytes_.insert(bytes_.end(), rangeBytes, rangeBytes + sizeof(range)); 283 | } 284 | 285 | /// \return the current offset in the stream, which is where the next 286 | /// instruction will be emitted. Note the header is omitted. 287 | uint32_t currentOffset() const { 288 | return bytes_.size() - sizeof(RegexBytecodeHeader); 289 | } 290 | 291 | /// \return the bytecode, transferring ownership of it to the caller. 292 | std::vector acquireBytecode() { 293 | assert(!acquired_ && "Bytecode already acquired"); 294 | acquired_ = true; 295 | return std::move(bytes_); 296 | } 297 | 298 | /// Construct a RegexBytecodeStream starting with a header. 299 | RegexBytecodeStream(const RegexBytecodeHeader &header) { 300 | const uint8_t *headerBytes = reinterpret_cast(&header); 301 | bytes_.insert(bytes_.end(), headerBytes, headerBytes + sizeof header); 302 | } 303 | }; 304 | 305 | } // namespace regex 306 | } // namespace hermes 307 | 308 | namespace llvm { 309 | /// LLVM RTTI implementation for regex instructions. Rather than defining 310 | /// classof() for each instruction struct, which would require a lot of 311 | /// error-prone boilerplate, we take the Casting.h header's suggestion of 312 | /// specializing isa_impl for the case where From is just Insn and To is one of 313 | /// its subclasses. 314 | template 315 | struct isa_impl< 316 | To, 317 | From, 318 | typename std::enable_if< 319 | std::is_same::value && 320 | std::is_base_of::value>::type> { 321 | static inline bool doit(const From &val) { 322 | return val.opcode == hermes::regex::OpcodeFor::value; 323 | } 324 | }; 325 | } // namespace llvm 326 | #endif // HERMES_REGEX_REGEXBYTECODE_H 327 | -------------------------------------------------------------------------------- /utils/original_regex_bytecode_c_src/get_source_codes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script fetches various bits of Hermes source code 4 | # to the current directory, for exploratory use. 5 | 6 | # Exit on non-success 7 | set -e 8 | 9 | # How to list Hermes Git source tags: 10 | # git -C ~/hermes fetch; git -C ~/hermes tag -l 'v*' | grep -v rc | sort -V | tr '\n' ' '; echo 11 | # ("sort -V" means versioning-like sort) 12 | 13 | cd "$(dirname "$0")" 14 | source ../git_tags.sh 15 | 16 | for git_tag in ${GIT_TAGS[@]}; do 17 | hbc_version=${TAG_TO_VERSION[${git_tag}]} 18 | if [ -z ${hbc_version} ]; then 19 | hbc_version=${git_tag} 20 | fi 21 | 22 | echo "Downloading files for ${git_tag}..." 23 | wget "https://raw.githubusercontent.com/facebook/hermes/${git_tag}/include/hermes/Regex/RegexBytecode.h" -O "RegexBytecode-${hbc_version}.h" 24 | done 25 | -------------------------------------------------------------------------------- /utils/regen_hbc_opcodes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit on non-success, print commands 4 | set -ex 5 | 6 | cd "$(dirname "$0")" 7 | 8 | rm -f original_function_builtins_c_src/*.def 9 | rm -f original_hermes_bytecode_c_src/*.def 10 | rm -f original_hermes_bytecode_c_src/*.h 11 | 12 | ./original_hermes_bytecode_c_src/get_source_codes.sh 13 | ./original_function_builtins_c_src/get_source_codes.sh 14 | # ./original_regex_bytecode_c_src/get_source_codes.sh 15 | 16 | ./hermes_bytecode_structs_parser.py 17 | 18 | -------------------------------------------------------------------------------- /utils/regex_bytecode_structs_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | #-*- encoding: Utf-8 -*- 3 | from re import search, match, findall, sub, finditer, MULTILINE, DOTALL 4 | from typing import List, Dict, Set, Sequence, Union, Optional, Any 5 | from dataclasses import dataclass 6 | 7 | from clang.cindex import Index, CursorKind 8 | 9 | """ 10 | This file contains transitory libclang-based code 11 | that is used for generating structures which have 12 | been used as a base for the "../parsers/regexp_bytecode_parser.py" 13 | file, based on the original source code contained within 14 | the "../original_regex_bytecode_c_src" directory, which 15 | has been downloaded by the "get_source_codes.sh" script 16 | contained within the same directory. 17 | 18 | It is a scratchpad. 19 | """ 20 | 21 | 22 | @dataclass 23 | class OpcodeStructureField: 24 | field_name : str 25 | field_type : str 26 | real_type : Optional[str] 27 | bit_len : Optional[int] 28 | 29 | @dataclass 30 | class OpcodeStructure: 31 | struct_name : str 32 | fields : List[OpcodeStructureField] 33 | 34 | opcode_name_to_structure : Dict[str, OpcodeStructure] = {} 35 | 36 | 37 | def find_typerefs(node, indent = 0, struct : Optional[OpcodeStructure] = None, field : Optional[OpcodeStructureField] = None, visiting_baseclass : bool = False): 38 | """ Find all references to the type named 'typename' 39 | """ 40 | # help(node.type) 41 | # exit() 42 | # help(node.type.get_declaration()) 43 | # exit() 44 | """ 45 | print('%sFound `%s` (%s) [line=%s, col=%s] %s' % ( 46 | ' ' * (indent * 2), 47 | node.spelling, node.kind, node.location.line, node.location.column, (node.type.spelling, node.type.get_canonical().spelling, node.type.get_declaration().underlying_typedef_type.spelling if node.type.get_declaration().kind.is_declaration() else None))) # (node.storage_class, node.type, node.type.spelling, node.translation_unit, node.referenced, node.raw_comment))) 48 | """ 49 | 50 | if node.kind == CursorKind.CXX_BASE_SPECIFIER: 51 | visiting_baseclass = True 52 | elif node.kind == CursorKind.STRUCT_DECL and ((node.spelling.endswith('Insn') and node.spelling != 'Insn') or 'BracketRange' in node.spelling): 53 | struct = OpcodeStructure(node.spelling, []) 54 | opcode_name_to_structure[node.spelling] = struct 55 | elif struct and node.kind == CursorKind.FIELD_DECL: 56 | # help(node) 57 | # exit() 58 | field = OpcodeStructureField(node.spelling, node.type.spelling, None, None) 59 | if node.is_bitfield(): 60 | field.bit_len = node.get_bitfield_width() 61 | if node.type.get_declaration().kind.is_declaration(): 62 | underlying_type = node.type.get_declaration().underlying_typedef_type.spelling 63 | if underlying_type and underlying_type != node.spelling and '__' not in underlying_type: 64 | field.field_type, field.real_type = underlying_type, field.field_type 65 | struct.fields.append(field) 66 | elif struct and visiting_baseclass and node.kind == CursorKind.TYPE_REF and node.spelling != 'struct hermes::regex::Insn': 67 | for otherchild in node.type.get_declaration().get_children(): 68 | find_typerefs(otherchild, indent + 1, struct, field, False) 69 | # Recurse for children of this node 70 | for child in node.get_children(): 71 | find_typerefs(child, indent + 1, struct, field, visiting_baseclass) 72 | 73 | # INPUT_FILE_NAME = '/home/marin/hermes/include/hermes/Regex/RegexBytecode.h' 74 | INPUT_FILE_NAME = '/home/marin/hermes-dec/parsers/original_regex_bytecode_c_src/RegexBytecode-v0.12.0.h' 75 | # INPUT_FILE_NAME = '/home/marin/hermes-dec/parsers/original_regex_bytecode_c_src/RegexBytecode-v0.0.1.h' 76 | 77 | index = Index.create() 78 | tu = index.parse(INPUT_FILE_NAME, args = ['-x', 'c++']) 79 | print('Translation unit:', tu.spelling) 80 | find_typerefs(tu.cursor) 81 | 82 | print() 83 | print('=' * 12) 84 | print() 85 | print('=== Decoded structures: ===') 86 | print() 87 | 88 | """ 89 | for opcode_name, structure in opcode_name_to_structure.items(): 90 | print('[Struct "%s"]' % opcode_name) 91 | for field in structure.fields: 92 | if field.real_type: 93 | print(' %s %s # %s' % (field.field_type, field.field_name, field.real_type)) 94 | else: 95 | print(' %s %s' % (field.field_type, field.field_name)) 96 | print() 97 | """ 98 | 99 | print() 100 | for opcode_name, structure in opcode_name_to_structure.items(): 101 | print('class %s(LittleEndianStructure):' % opcode_name) 102 | print(' _pack_ = True') 103 | if structure.fields: 104 | print(' _fields_ = [') 105 | for field_index, field in enumerate(structure.fields): 106 | readable_type = { 107 | 'bool': 'c_bool', 108 | 'char': 'c_char', 109 | 'char16_t': 'c_wchar', 110 | 'uint8_t': 'c_uint8', 111 | 'uint16_t': 'c_uint16', 112 | 'uint32_t': 'c_uint32' 113 | }[field.field_type] 114 | 115 | if field.bit_len: 116 | readable_type += ', %d' % field.bit_len 117 | 118 | if field.real_type: 119 | print(" ('%s', %s)%s # %s" % (field.field_name, readable_type, ',' if field_index + 1 < len(structure.fields) else '', field.real_type)) 120 | else: 121 | print(" ('%s', %s)%s" % (field.field_name, readable_type, ',' if field_index + 1 < len(structure.fields) else '')) 122 | print(' ]') 123 | print() 124 | 125 | parsed_inst_names = sorted(set(opcode_name.replace('Insn', '') for opcode_name in opcode_name_to_structure.keys()) - {'BracketRange32'}) 126 | 127 | """ 128 | orig_inst_names = sorted({'Goal', 'LeftAnchor', 'RightAnchor', 'MatchAny', 'U16MatchAny', 'MatchAnyButNewline', 'U16MatchAnyButNewline', 'MatchChar8', 'MatchChar16', 'U16MatchChar32', 'MatchNChar8', 'MatchNCharICase8', 'MatchCharICase8', 'MatchCharICase16', 'U16MatchCharICase32', 'Alternation', 'Jump32', 'Bracket', 'U16Bracket', 'BeginMarkedSubexpression', 'EndMarkedSubexpression', 'BackRef', 'WordBoundary', 'Lookaround', 'BeginLoop', 'EndLoop', 'BeginSimpleLoop', 'EndSimpleLoop', 'Width1Loop'}) 129 | 130 | print() 131 | print('=>') 132 | print('=> Parsed structures for (len %s):' % len(parsed_inst_names), parsed_inst_names) 133 | print('=> Should match structures (len %s):' % len(orig_inst_names), orig_inst_names) 134 | print() 135 | 136 | assert parsed_inst_names == orig_inst_names 137 | """ 138 | 139 | print('=') 140 | print() 141 | 142 | print('~') 143 | --------------------------------------------------------------------------------