cfsolve 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +7 -5
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -0
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +69 -31
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +180 -148
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +5 -5
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
- data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
- data/vendor/cfsolve/src/stage2.rs +2 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +56 -49
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/session.rs +185 -120
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +2 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +94 -178
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
//! Compiles JavaScript into plans
|
|
1
|
+
//! Compiles JavaScript into plans, which [`super::compile`] turns into closures. Slot plans store function locals
|
|
2
2
|
//! in numbered slots, except locals that nested functions mention, which stay in the call's
|
|
3
|
-
//! scope for those functions to capture. Scoped plans resolve
|
|
3
|
+
//! scope for those functions to capture. Scoped plans resolve every binding through scopes.
|
|
4
4
|
//! Unsupported syntax becomes a node that stops evaluation if reached.
|
|
5
5
|
|
|
6
6
|
#[cfg(test)]
|
|
@@ -9,59 +9,94 @@ use std::cell::RefCell;
|
|
|
9
9
|
use std::ptr;
|
|
10
10
|
use std::rc::Rc;
|
|
11
11
|
|
|
12
|
-
use
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
VarDeclKind, VarDeclOrExpr, VarDeclarator, WhileStmt,
|
|
12
|
+
use oxc::ast::ast::{
|
|
13
|
+
Argument, ArrayExpressionElement, ArrowFunctionBody, ArrowFunctionExpression,
|
|
14
|
+
BindingIdentifier, BindingPattern, CatchClause, Class, Expression as Expr, ForStatementInit,
|
|
15
|
+
FormalParameters, Function, IdentifierReference, MemberExpression, ObjectPropertyKind,
|
|
16
|
+
PropertyKey, PropertyKind, SimpleAssignmentTarget, Statement as Stmt, VariableDeclaration,
|
|
17
|
+
VariableDeclarationKind, VariableDeclarator,
|
|
19
18
|
};
|
|
20
|
-
use
|
|
19
|
+
use oxc::ast_visit::{Visit, walk};
|
|
20
|
+
use oxc::semantic::{ScopeFlags, SymbolId};
|
|
21
|
+
use oxc::syntax::operator::{BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator};
|
|
21
22
|
|
|
22
23
|
use super::compile::{self, Code};
|
|
23
24
|
use super::semantics;
|
|
24
|
-
use crate::
|
|
25
|
+
use crate::js::ast::{Binding, Script};
|
|
25
26
|
use crate::vm::value::Value;
|
|
27
|
+
use crate::vm::{HashMap, HashSet, extract};
|
|
28
|
+
|
|
29
|
+
/// What a call runs: parameters, then a body. A script function's body is its statements; the
|
|
30
|
+
/// dispatch decoder's is assembled from the dispatch loop (see [`crate::vm::dispatch`]).
|
|
31
|
+
#[derive(Clone, Copy)]
|
|
32
|
+
pub(crate) struct Routine<'ast> {
|
|
33
|
+
pub(crate) parameters: &'ast FormalParameters<'ast>,
|
|
34
|
+
/// Declarations run first without their initializers, so they only declare their names.
|
|
35
|
+
pub(crate) declarations: &'ast [&'ast VariableDeclaration<'ast>],
|
|
36
|
+
pub(crate) statements: &'ast [Stmt<'ast>],
|
|
37
|
+
/// What the routine returns after its statements, if they do not return.
|
|
38
|
+
pub(crate) returns: Option<&'ast Expr<'ast>>,
|
|
39
|
+
/// Identifies the routine's plans: the address of the function body or decoder.
|
|
40
|
+
pub(crate) address: usize,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
impl<'ast> Routine<'ast> {
|
|
44
|
+
/// The routine of a function with a body.
|
|
45
|
+
pub(crate) fn function(function: &'ast Function<'ast>) -> Option<Self> {
|
|
46
|
+
let body = function.body.as_deref()?;
|
|
47
|
+
Some(Self {
|
|
48
|
+
parameters: &function.params,
|
|
49
|
+
declarations: &[],
|
|
50
|
+
statements: &body.statements,
|
|
51
|
+
returns: None,
|
|
52
|
+
address: ptr::from_ref(body).addr(),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
26
56
|
|
|
27
57
|
/// Caches plans by source-node address. The session's definition keeps those nodes alive longer
|
|
28
58
|
/// than the cache.
|
|
29
59
|
#[derive(Default)]
|
|
30
60
|
pub(crate) struct Plans<'ast> {
|
|
31
|
-
/// `None` marks
|
|
61
|
+
/// `None` marks routines that need a scoped plan.
|
|
32
62
|
pub(super) slot_plans: RefCell<HashMap<usize, Option<Rc<FunctionPlan<'ast>>>>>,
|
|
33
|
-
scoped_plans: RefCell<HashMap<usize, Rc<[
|
|
63
|
+
scoped_plans: RefCell<HashMap<usize, Rc<[Code<'ast>]>>>,
|
|
34
64
|
/// Forces scoped plans for comparison tests.
|
|
35
65
|
#[cfg(test)]
|
|
36
66
|
pub(super) disabled: Cell<bool>,
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
impl<'ast> Plans<'ast> {
|
|
40
|
-
pub(super) fn slots(
|
|
70
|
+
pub(super) fn slots(
|
|
71
|
+
&self,
|
|
72
|
+
script: Script<'ast>,
|
|
73
|
+
routine: Routine<'ast>,
|
|
74
|
+
) -> Option<Rc<FunctionPlan<'ast>>> {
|
|
41
75
|
#[cfg(test)]
|
|
42
76
|
if self.disabled.get() {
|
|
43
77
|
return None;
|
|
44
78
|
}
|
|
45
|
-
let
|
|
46
|
-
if let Some(plan) = self.slot_plans.borrow().get(&address) {
|
|
79
|
+
if let Some(plan) = self.slot_plans.borrow().get(&routine.address) {
|
|
47
80
|
return plan.clone();
|
|
48
81
|
}
|
|
49
|
-
let plan = FunctionPlan::compile(
|
|
50
|
-
self.slot_plans
|
|
82
|
+
let plan = FunctionPlan::compile(script, routine).map(Rc::new);
|
|
83
|
+
self.slot_plans
|
|
84
|
+
.borrow_mut()
|
|
85
|
+
.insert(routine.address, plan.clone());
|
|
51
86
|
plan
|
|
52
87
|
}
|
|
53
88
|
|
|
54
|
-
/// Returns the scoped plan of
|
|
55
|
-
|
|
89
|
+
/// Returns the scoped plan of the routine or arrow at `address`, compiling `plan` on first
|
|
90
|
+
/// use.
|
|
91
|
+
pub(super) fn scoped(
|
|
56
92
|
&self,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) -> Rc<[
|
|
60
|
-
let address = ptr::from_ref(code).addr();
|
|
93
|
+
address: usize,
|
|
94
|
+
plan: impl FnOnce() -> Vec<Statement<'ast>>,
|
|
95
|
+
) -> Rc<[Code<'ast>]> {
|
|
61
96
|
if let Some(plan) = self.scoped_plans.borrow().get(&address) {
|
|
62
97
|
return plan.clone();
|
|
63
98
|
}
|
|
64
|
-
let plan: Rc<[
|
|
99
|
+
let plan: Rc<[Code<'ast>]> = compile::statements(&plan()).into();
|
|
65
100
|
self.scoped_plans.borrow_mut().insert(address, plan.clone());
|
|
66
101
|
plan
|
|
67
102
|
}
|
|
@@ -82,131 +117,222 @@ impl<'ast> FunctionPlan<'ast> {
|
|
|
82
117
|
/// Attempts to compile a slot plan. Returns `None` to request a scoped plan for unsupported
|
|
83
118
|
/// syntax, parenthesized callees, computed object keys, logical assignments, parameter
|
|
84
119
|
/// patterns, variables named `arguments`, or arrows reading `arguments`.
|
|
85
|
-
pub(super) fn compile(
|
|
86
|
-
let body = function.body.as_ref()?;
|
|
120
|
+
pub(super) fn compile(script: Script<'ast>, routine: Routine<'ast>) -> Option<Self> {
|
|
87
121
|
let mut compiler = PlanCompiler {
|
|
88
|
-
captured: captured(
|
|
89
|
-
..PlanCompiler::
|
|
122
|
+
captured: captured(script, routine),
|
|
123
|
+
..PlanCompiler::new(script)
|
|
90
124
|
};
|
|
91
|
-
let
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if name == "arguments" {
|
|
125
|
+
let parameters = extract::parameters(routine.parameters)?;
|
|
126
|
+
let mut names = Vec::with_capacity(parameters.len());
|
|
127
|
+
for parameter in parameters {
|
|
128
|
+
if parameter.name == "arguments" {
|
|
95
129
|
return None;
|
|
96
130
|
}
|
|
97
|
-
|
|
98
|
-
|
|
131
|
+
let binding = Binding::Symbol(parameter.symbol_id());
|
|
132
|
+
compiler.local(binding);
|
|
133
|
+
names.push(compiler.name(binding));
|
|
134
|
+
}
|
|
135
|
+
for declaration in routine.declarations {
|
|
136
|
+
for declarator in &declaration.declarations {
|
|
137
|
+
compiler.declared(declarator);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for statement in routine.statements {
|
|
141
|
+
compiler.visit_statement(statement);
|
|
99
142
|
}
|
|
100
|
-
body.
|
|
101
|
-
let body = compiler.body(&body.stmts);
|
|
143
|
+
let body = compiler.routine(routine);
|
|
102
144
|
if compiler.rejected {
|
|
103
145
|
return None;
|
|
104
146
|
}
|
|
105
147
|
Some(Self {
|
|
106
|
-
parameters,
|
|
107
|
-
arguments: compiler.locals.get(&
|
|
148
|
+
parameters: names,
|
|
149
|
+
arguments: compiler.locals.get(&Binding::Global("arguments")).copied(),
|
|
108
150
|
locals: compiler.locals.len(),
|
|
109
151
|
code: compile::statements(&body),
|
|
110
152
|
})
|
|
111
153
|
}
|
|
112
154
|
}
|
|
113
155
|
|
|
114
|
-
pub(super) fn
|
|
115
|
-
|
|
156
|
+
pub(super) fn scoped_statement<'ast>(
|
|
157
|
+
script: Script<'ast>,
|
|
158
|
+
statement: &'ast Stmt<'ast>,
|
|
159
|
+
) -> Statement<'ast> {
|
|
160
|
+
PlanCompiler::new(script).statement(statement, None)
|
|
116
161
|
}
|
|
117
162
|
|
|
118
|
-
/// Scoped execution plan for a
|
|
119
|
-
/// of the call.
|
|
120
|
-
pub(super) fn
|
|
121
|
-
|
|
163
|
+
/// Scoped execution plan for a routine's body. Function declarations bind their names at the
|
|
164
|
+
/// start of the call.
|
|
165
|
+
pub(super) fn scoped_routine<'ast>(
|
|
166
|
+
script: Script<'ast>,
|
|
167
|
+
routine: Routine<'ast>,
|
|
168
|
+
) -> Vec<Statement<'ast>> {
|
|
169
|
+
PlanCompiler::new(script).routine(routine)
|
|
122
170
|
}
|
|
123
171
|
|
|
124
|
-
pub(super) fn scoped_expression
|
|
125
|
-
|
|
172
|
+
pub(super) fn scoped_expression<'ast>(
|
|
173
|
+
script: Script<'ast>,
|
|
174
|
+
expression: &'ast Expr<'ast>,
|
|
175
|
+
) -> Expression<'ast> {
|
|
176
|
+
PlanCompiler::new(script).expression(expression)
|
|
126
177
|
}
|
|
127
178
|
|
|
128
|
-
pub(super) fn scoped_arrow
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
179
|
+
pub(super) fn scoped_arrow<'ast>(
|
|
180
|
+
script: Script<'ast>,
|
|
181
|
+
arrow: &'ast ArrowFunctionExpression<'ast>,
|
|
182
|
+
) -> Vec<Statement<'ast>> {
|
|
183
|
+
let mut compiler = PlanCompiler::new(script);
|
|
184
|
+
match &arrow.body {
|
|
185
|
+
ArrowFunctionBody::FunctionBody(body) => compiler.body(&body.statements),
|
|
186
|
+
body => {
|
|
187
|
+
let body = body
|
|
188
|
+
.as_expression()
|
|
189
|
+
.expect("an arrow body is a block or an expression");
|
|
190
|
+
vec![Statement::Return(Some(compiler.expression(body)))]
|
|
191
|
+
}
|
|
132
192
|
}
|
|
133
193
|
}
|
|
134
194
|
|
|
135
|
-
|
|
136
|
-
|
|
195
|
+
struct PlanCompiler<'a> {
|
|
196
|
+
script: Script<'a>,
|
|
137
197
|
/// Slots of a slot plan's locals; empty for scoped plans.
|
|
138
|
-
locals: HashMap<
|
|
139
|
-
///
|
|
140
|
-
captured: HashSet<
|
|
198
|
+
locals: HashMap<Binding<'a>, usize>,
|
|
199
|
+
/// Bindings nested functions mention. These locals stay in the call's scope.
|
|
200
|
+
captured: HashSet<SymbolId>,
|
|
141
201
|
/// Whether compilation needs a scoped plan. Ignored when compiling scoped plans.
|
|
142
202
|
rejected: bool,
|
|
143
203
|
}
|
|
144
204
|
|
|
145
|
-
impl Visit for PlanCompiler {
|
|
146
|
-
fn
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
declaration.visit_children_with(self);
|
|
205
|
+
impl<'a> Visit<'a> for PlanCompiler<'a> {
|
|
206
|
+
fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
|
|
207
|
+
self.declared(declarator);
|
|
208
|
+
walk::walk_variable_declarator(self, declarator);
|
|
151
209
|
}
|
|
152
210
|
|
|
153
|
-
fn
|
|
154
|
-
if name
|
|
155
|
-
self.local(
|
|
211
|
+
fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
|
|
212
|
+
if reference.name == "arguments" {
|
|
213
|
+
self.local(self.script.binding(reference));
|
|
156
214
|
}
|
|
157
215
|
}
|
|
158
216
|
|
|
159
|
-
/// Treat a nested function declaration as a local binding in the enclosing function.
|
|
160
|
-
|
|
161
|
-
|
|
217
|
+
/// Treat a nested function declaration as a local binding in the enclosing function. A
|
|
218
|
+
/// nested function's own locals remain separate.
|
|
219
|
+
fn visit_function(&mut self, function: &Function<'a>, _: ScopeFlags) {
|
|
220
|
+
if function.is_declaration()
|
|
221
|
+
&& let Some(name) = &function.id
|
|
222
|
+
{
|
|
223
|
+
self.local(Binding::Symbol(name.symbol_id()));
|
|
224
|
+
}
|
|
162
225
|
}
|
|
163
226
|
|
|
164
227
|
/// Treat a `catch` parameter as a function local in the execution plan.
|
|
165
|
-
fn visit_catch_clause(&mut self, clause: &CatchClause) {
|
|
166
|
-
if let Some(
|
|
167
|
-
|
|
228
|
+
fn visit_catch_clause(&mut self, clause: &CatchClause<'a>) {
|
|
229
|
+
if let Some(parameter) = &clause.param
|
|
230
|
+
&& let BindingPattern::BindingIdentifier(name) = ¶meter.pattern
|
|
231
|
+
{
|
|
232
|
+
self.local(Binding::Symbol(name.symbol_id()));
|
|
168
233
|
}
|
|
169
|
-
|
|
234
|
+
walk::walk_catch_clause(self, clause);
|
|
170
235
|
}
|
|
171
236
|
|
|
172
|
-
|
|
173
|
-
fn
|
|
174
|
-
fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
|
|
175
|
-
fn visit_class(&mut self, _: &Class) {}
|
|
237
|
+
fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
|
|
238
|
+
fn visit_class(&mut self, _: &Class<'a>) {}
|
|
176
239
|
}
|
|
177
240
|
|
|
178
|
-
///
|
|
179
|
-
|
|
180
|
-
|
|
241
|
+
/// The symbols of a routine's own bindings that functions, arrows, and classes nested in it
|
|
242
|
+
/// reference. A function's `arguments` has no symbol; arrows reading it are rejected.
|
|
243
|
+
fn captured<'a>(script: Script<'a>, routine: Routine<'a>) -> HashSet<SymbolId> {
|
|
244
|
+
#[derive(Default)]
|
|
245
|
+
struct Bindings(HashSet<SymbolId>);
|
|
246
|
+
|
|
247
|
+
impl<'a> Visit<'a> for Bindings {
|
|
248
|
+
fn visit_binding_identifier(&mut self, name: &BindingIdentifier<'a>) {
|
|
249
|
+
self.0.insert(name.symbol_id());
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn visit_function(&mut self, function: &Function<'a>, _: ScopeFlags) {
|
|
253
|
+
if function.is_declaration()
|
|
254
|
+
&& let Some(name) = &function.id
|
|
255
|
+
{
|
|
256
|
+
self.0.insert(name.symbol_id());
|
|
257
|
+
}
|
|
258
|
+
}
|
|
181
259
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
260
|
+
fn visit_class(&mut self, class: &Class<'a>) {
|
|
261
|
+
if class.is_declaration()
|
|
262
|
+
&& let Some(name) = &class.id
|
|
263
|
+
{
|
|
264
|
+
self.0.insert(name.symbol_id());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
|
|
185
269
|
}
|
|
186
|
-
}
|
|
187
270
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
271
|
+
struct References<'s, 'a> {
|
|
272
|
+
script: Script<'a>,
|
|
273
|
+
bindings: &'s HashSet<SymbolId>,
|
|
274
|
+
captured: HashSet<SymbolId>,
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
impl<'a> Visit<'a> for References<'_, 'a> {
|
|
278
|
+
fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
|
|
279
|
+
if let Some(symbol) = self.script.symbol(reference)
|
|
280
|
+
&& self.bindings.contains(&symbol)
|
|
281
|
+
{
|
|
282
|
+
self.captured.insert(symbol);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
struct Nested<'s, 'a>(References<'s, 'a>);
|
|
288
|
+
|
|
289
|
+
impl<'a> Visit<'a> for Nested<'_, 'a> {
|
|
290
|
+
fn visit_function(&mut self, function: &Function<'a>, flags: ScopeFlags) {
|
|
291
|
+
self.0.visit_function(function, flags);
|
|
292
|
+
}
|
|
192
293
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
function.visit_with(&mut self.0);
|
|
294
|
+
fn visit_arrow_function_expression(&mut self, arrow: &ArrowFunctionExpression<'a>) {
|
|
295
|
+
self.0.visit_arrow_function_expression(arrow);
|
|
196
296
|
}
|
|
197
|
-
|
|
198
|
-
|
|
297
|
+
|
|
298
|
+
fn visit_class(&mut self, class: &Class<'a>) {
|
|
299
|
+
self.0.visit_class(class);
|
|
199
300
|
}
|
|
200
|
-
|
|
201
|
-
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let mut bindings = Bindings::default();
|
|
304
|
+
bindings.visit_formal_parameters(routine.parameters);
|
|
305
|
+
for declaration in routine.declarations {
|
|
306
|
+
for declarator in &declaration.declarations {
|
|
307
|
+
bindings.visit_binding_pattern(&declarator.id);
|
|
202
308
|
}
|
|
203
309
|
}
|
|
310
|
+
for statement in routine.statements {
|
|
311
|
+
bindings.visit_statement(statement);
|
|
312
|
+
}
|
|
313
|
+
let mut nested = Nested(References {
|
|
314
|
+
script,
|
|
315
|
+
bindings: &bindings.0,
|
|
316
|
+
captured: HashSet::default(),
|
|
317
|
+
});
|
|
318
|
+
for statement in routine.statements {
|
|
319
|
+
nested.visit_statement(statement);
|
|
320
|
+
}
|
|
321
|
+
nested.0.captured
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/// Whether a visited node mentions `arguments`, to reject arrows that read the enclosing one.
|
|
325
|
+
#[derive(Default)]
|
|
326
|
+
struct MentionsArguments(bool);
|
|
327
|
+
|
|
328
|
+
impl<'a> Visit<'a> for MentionsArguments {
|
|
329
|
+
fn visit_identifier_reference(&mut self, name: &IdentifierReference<'a>) {
|
|
330
|
+
self.0 |= name.name == "arguments";
|
|
331
|
+
}
|
|
204
332
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
names.remove(&atom!("arguments"));
|
|
209
|
-
names
|
|
333
|
+
fn visit_binding_identifier(&mut self, name: &BindingIdentifier<'a>) {
|
|
334
|
+
self.0 |= name.name == "arguments";
|
|
335
|
+
}
|
|
210
336
|
}
|
|
211
337
|
|
|
212
338
|
pub(super) struct Case<'ast> {
|
|
@@ -241,11 +367,11 @@ pub(super) enum Statement<'ast> {
|
|
|
241
367
|
body: Box<Statement<'ast>>,
|
|
242
368
|
/// Whether the body runs once before the test, as in `do ... while`.
|
|
243
369
|
body_first: bool,
|
|
244
|
-
label: Option<&'ast
|
|
370
|
+
label: Option<&'ast str>,
|
|
245
371
|
},
|
|
246
|
-
Break(Option<&'ast
|
|
247
|
-
Continue(Option<&'ast
|
|
248
|
-
Label(&'ast
|
|
372
|
+
Break(Option<&'ast str>),
|
|
373
|
+
Continue(Option<&'ast str>),
|
|
374
|
+
Label(&'ast str, Box<Statement<'ast>>),
|
|
249
375
|
/// A `try` statement with its catch parameter, catch body, and finally body.
|
|
250
376
|
Try {
|
|
251
377
|
block: Vec<Statement<'ast>>,
|
|
@@ -258,7 +384,7 @@ pub(super) enum Statement<'ast> {
|
|
|
258
384
|
|
|
259
385
|
pub(super) enum Expression<'ast> {
|
|
260
386
|
Logical {
|
|
261
|
-
operator:
|
|
387
|
+
operator: LogicalOperator,
|
|
262
388
|
left: Box<Expression<'ast>>,
|
|
263
389
|
right: Box<Expression<'ast>>,
|
|
264
390
|
/// Whether the right side is [`pure`].
|
|
@@ -271,20 +397,22 @@ pub(super) enum Expression<'ast> {
|
|
|
271
397
|
Member(Box<Expression<'ast>>, Property<'ast>),
|
|
272
398
|
Call(Box<Expression<'ast>>, Vec<Expression<'ast>>),
|
|
273
399
|
New(Box<Expression<'ast>>, Vec<Expression<'ast>>),
|
|
274
|
-
Binary(
|
|
400
|
+
Binary(BinaryOperator, Box<Expression<'ast>>, Box<Expression<'ast>>),
|
|
275
401
|
/// An arithmetic or bitwise operator, with its operation on numbers (see
|
|
276
402
|
/// [`semantics::numeric`]).
|
|
277
403
|
Arithmetic {
|
|
278
|
-
operator:
|
|
404
|
+
operator: BinaryOperator,
|
|
279
405
|
operation: fn(f64, f64) -> f64,
|
|
280
406
|
left: Box<Expression<'ast>>,
|
|
281
407
|
right: Box<Expression<'ast>>,
|
|
282
408
|
},
|
|
283
|
-
Unary(
|
|
284
|
-
Assign(Target<'ast>, Option<
|
|
409
|
+
Unary(UnaryOperator, Box<Expression<'ast>>),
|
|
410
|
+
Assign(Target<'ast>, Option<BinaryOperator>, Box<Expression<'ast>>),
|
|
411
|
+
/// `&&=`, `||=` or `??=`, which stops evaluation once its target is located.
|
|
412
|
+
LogicalAssign(Target<'ast>),
|
|
285
413
|
Update {
|
|
286
414
|
target: Target<'ast>,
|
|
287
|
-
operator:
|
|
415
|
+
operator: UpdateOperator,
|
|
288
416
|
prefix: bool,
|
|
289
417
|
},
|
|
290
418
|
Conditional(
|
|
@@ -294,8 +422,8 @@ pub(super) enum Expression<'ast> {
|
|
|
294
422
|
),
|
|
295
423
|
Array(Vec<Option<Expression<'ast>>>),
|
|
296
424
|
Object(Vec<(Property<'ast>, Expression<'ast>)>),
|
|
297
|
-
Function(Option<&'ast
|
|
298
|
-
Arrow(&'ast
|
|
425
|
+
Function(Option<&'ast str>, &'ast Function<'ast>),
|
|
426
|
+
Arrow(&'ast ArrowFunctionExpression<'ast>),
|
|
299
427
|
/// Syntax the interpreter does not follow, described for diagnostics.
|
|
300
428
|
Unsupported(&'static str),
|
|
301
429
|
}
|
|
@@ -310,97 +438,157 @@ pub(super) enum Target<'ast> {
|
|
|
310
438
|
Member(Box<Expression<'ast>>, Property<'ast>),
|
|
311
439
|
}
|
|
312
440
|
|
|
313
|
-
/// A
|
|
441
|
+
/// A binding a plan reads or writes: a local, by its slot, or a binding resolved through
|
|
442
|
+
/// scopes.
|
|
314
443
|
#[derive(Clone, Copy)]
|
|
315
444
|
pub(super) enum Name<'ast> {
|
|
316
|
-
Local(usize,
|
|
317
|
-
|
|
445
|
+
Local(usize, Binding<'ast>),
|
|
446
|
+
Scoped(Binding<'ast>),
|
|
318
447
|
}
|
|
319
448
|
|
|
320
449
|
impl<'ast> Name<'ast> {
|
|
321
|
-
pub(super) fn
|
|
450
|
+
pub(super) fn binding(self) -> Binding<'ast> {
|
|
322
451
|
match self {
|
|
323
|
-
Self::Local(_,
|
|
452
|
+
Self::Local(_, binding) | Self::Scoped(binding) => binding,
|
|
324
453
|
}
|
|
325
454
|
}
|
|
326
455
|
}
|
|
327
456
|
|
|
328
|
-
impl PlanCompiler {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
457
|
+
impl<'a> PlanCompiler<'a> {
|
|
458
|
+
fn new(script: Script<'a>) -> Self {
|
|
459
|
+
Self {
|
|
460
|
+
script,
|
|
461
|
+
locals: HashMap::default(),
|
|
462
|
+
captured: HashSet::default(),
|
|
463
|
+
rejected: false,
|
|
334
464
|
}
|
|
335
465
|
}
|
|
336
466
|
|
|
467
|
+
/// Gives local `binding` a slot unless a nested function mentions it.
|
|
468
|
+
fn local(&mut self, binding: Binding<'a>) {
|
|
469
|
+
if let Binding::Symbol(symbol) = binding
|
|
470
|
+
&& self.captured.contains(&symbol)
|
|
471
|
+
{
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
let next = self.locals.len();
|
|
475
|
+
self.locals.entry(binding).or_insert(next);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/// Gives the variable `declarator` declares a slot.
|
|
479
|
+
fn declared(&mut self, declarator: &VariableDeclarator<'a>) {
|
|
480
|
+
if let BindingPattern::BindingIdentifier(name) = &declarator.id {
|
|
481
|
+
self.local(Binding::Symbol(name.symbol_id()));
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/// Plans a routine: its function declarations, then its declarations without initializers,
|
|
486
|
+
/// its statements, and what it returns.
|
|
487
|
+
fn routine(&mut self, routine: Routine<'a>) -> Vec<Statement<'a>> {
|
|
488
|
+
let mut plan = self.hoisted(routine.statements);
|
|
489
|
+
for declaration in routine.declarations {
|
|
490
|
+
plan.push(self.variables(declaration, false));
|
|
491
|
+
}
|
|
492
|
+
plan.extend(self.statements(routine.statements));
|
|
493
|
+
if let Some(returned) = routine.returns {
|
|
494
|
+
plan.push(Statement::Return(Some(self.expression(returned))));
|
|
495
|
+
}
|
|
496
|
+
plan
|
|
497
|
+
}
|
|
498
|
+
|
|
337
499
|
/// Plans a function body or block, binding its function declarations before executing
|
|
338
500
|
/// statements, as JavaScript hoists them to the start of the body or block. Declarations
|
|
339
|
-
/// beside the VM class are planned as statements and
|
|
340
|
-
fn body
|
|
501
|
+
/// beside the VM class are planned as statements and resolve through the session.
|
|
502
|
+
fn body(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
|
|
503
|
+
let mut plan = self.hoisted(statements);
|
|
504
|
+
plan.extend(self.statements(statements));
|
|
505
|
+
plan
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/// Declarations binding the functions `statements` declare.
|
|
509
|
+
fn hoisted(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
|
|
341
510
|
let mut plan = Vec::with_capacity(statements.len());
|
|
342
511
|
for statement in statements {
|
|
343
|
-
if let Stmt::
|
|
344
|
-
let name = &
|
|
512
|
+
if let Stmt::FunctionDeclaration(function) = statement
|
|
513
|
+
&& let Some(name) = &function.id
|
|
514
|
+
{
|
|
345
515
|
plan.push(Statement::Declare(vec![Declaration {
|
|
346
|
-
name: self.name(name),
|
|
347
|
-
init: Some(Expression::Function(Some(name),
|
|
516
|
+
name: self.name(Binding::Symbol(name.symbol_id())),
|
|
517
|
+
init: Some(Expression::Function(Some(name.name.as_str()), function)),
|
|
348
518
|
keeps: false,
|
|
349
519
|
}]));
|
|
350
520
|
}
|
|
351
521
|
}
|
|
352
|
-
plan.extend(self.statements(statements));
|
|
353
522
|
plan
|
|
354
523
|
}
|
|
355
524
|
|
|
356
|
-
fn statements
|
|
525
|
+
fn statements(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
|
|
357
526
|
statements
|
|
358
527
|
.iter()
|
|
359
528
|
.map(|statement| self.statement(statement, None))
|
|
360
529
|
.collect()
|
|
361
530
|
}
|
|
362
531
|
|
|
363
|
-
fn statement
|
|
532
|
+
fn statement(&mut self, statement: &'a Stmt<'a>, label: Option<&'a str>) -> Statement<'a> {
|
|
364
533
|
match statement {
|
|
365
|
-
Stmt::
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
Stmt::
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
534
|
+
Stmt::ExpressionStatement(expression) => {
|
|
535
|
+
Statement::Expression(self.expression(&expression.expression))
|
|
536
|
+
}
|
|
537
|
+
Stmt::VariableDeclaration(declaration) if !declaration.kind.is_using() => {
|
|
538
|
+
self.variables(declaration, true)
|
|
539
|
+
}
|
|
540
|
+
// Declarations do not bind their names; the names resolve through scopes.
|
|
541
|
+
Stmt::FunctionDeclaration(_) | Stmt::ClassDeclaration(_) | Stmt::EmptyStatement(_) => {
|
|
542
|
+
Statement::Empty
|
|
543
|
+
}
|
|
544
|
+
Stmt::BlockStatement(block) => Statement::Block(self.body(&block.body)),
|
|
545
|
+
Stmt::IfStatement(branch) => Statement::If(
|
|
372
546
|
self.expression(&branch.test),
|
|
373
|
-
Box::new(self.statement(&branch.
|
|
547
|
+
Box::new(self.statement(&branch.consequent, None)),
|
|
374
548
|
branch
|
|
375
|
-
.
|
|
549
|
+
.alternate
|
|
376
550
|
.as_ref()
|
|
377
|
-
.map(|
|
|
551
|
+
.map(|alternate| Box::new(self.statement(alternate, None))),
|
|
378
552
|
),
|
|
379
|
-
Stmt::
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
553
|
+
Stmt::ReturnStatement(returned) => Statement::Return(
|
|
554
|
+
returned
|
|
555
|
+
.argument
|
|
556
|
+
.as_ref()
|
|
557
|
+
.map(|argument| self.expression(argument)),
|
|
558
|
+
),
|
|
559
|
+
Stmt::ThrowStatement(thrown) => Statement::Throw(self.expression(&thrown.argument)),
|
|
560
|
+
Stmt::SwitchStatement(switch) => {
|
|
384
561
|
let discriminant = self.expression(&switch.discriminant);
|
|
385
562
|
let cases = switch.cases.iter().map(|case| Case {
|
|
386
563
|
test: case.test.as_ref().map(|test| self.expression(test)),
|
|
387
|
-
body: self.statements(&case.
|
|
564
|
+
body: self.statements(&case.consequent),
|
|
388
565
|
});
|
|
389
566
|
Statement::Switch(discriminant, cases.collect())
|
|
390
567
|
}
|
|
391
|
-
Stmt::
|
|
392
|
-
|
|
393
|
-
Statement::Continue(branch.label.as_ref().map(|label| &label.sym))
|
|
568
|
+
Stmt::BreakStatement(branch) => {
|
|
569
|
+
Statement::Break(branch.label.as_ref().map(|label| label.name.as_str()))
|
|
394
570
|
}
|
|
395
|
-
Stmt::
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
)
|
|
399
|
-
|
|
571
|
+
Stmt::ContinueStatement(branch) => {
|
|
572
|
+
Statement::Continue(branch.label.as_ref().map(|label| label.name.as_str()))
|
|
573
|
+
}
|
|
574
|
+
Stmt::LabeledStatement(labeled) => {
|
|
575
|
+
let name = labeled.label.name.as_str();
|
|
576
|
+
Statement::Label(name, Box::new(self.statement(&labeled.body, Some(name))))
|
|
577
|
+
}
|
|
578
|
+
Stmt::ForStatement(looping) => Statement::Loop {
|
|
400
579
|
init: looping.init.as_ref().map(|init| {
|
|
401
580
|
Box::new(match init {
|
|
402
|
-
|
|
403
|
-
|
|
581
|
+
ForStatementInit::VariableDeclaration(declaration)
|
|
582
|
+
if !declaration.kind.is_using() =>
|
|
583
|
+
{
|
|
584
|
+
self.variables(declaration, true)
|
|
585
|
+
}
|
|
586
|
+
ForStatementInit::VariableDeclaration(_) => {
|
|
587
|
+
Statement::Expression(self.unsupported("a declaration"))
|
|
588
|
+
}
|
|
589
|
+
init => Statement::Expression(
|
|
590
|
+
self.expression(init.as_expression().expect("an expression")),
|
|
591
|
+
),
|
|
404
592
|
})
|
|
405
593
|
}),
|
|
406
594
|
test: looping.test.as_ref().map(|test| self.expression(test)),
|
|
@@ -412,46 +600,64 @@ impl PlanCompiler {
|
|
|
412
600
|
body_first: false,
|
|
413
601
|
label,
|
|
414
602
|
},
|
|
415
|
-
Stmt::
|
|
416
|
-
| Stmt::DoWhile(DoWhileStmt { test, body, .. }) => Statement::Loop {
|
|
603
|
+
Stmt::WhileStatement(looping) => Statement::Loop {
|
|
417
604
|
init: None,
|
|
418
|
-
test: Some(self.expression(test)),
|
|
605
|
+
test: Some(self.expression(&looping.test)),
|
|
419
606
|
update: None,
|
|
420
|
-
body: Box::new(self.statement(body, None)),
|
|
421
|
-
body_first:
|
|
607
|
+
body: Box::new(self.statement(&looping.body, None)),
|
|
608
|
+
body_first: false,
|
|
422
609
|
label,
|
|
423
610
|
},
|
|
424
|
-
Stmt::
|
|
425
|
-
|
|
611
|
+
Stmt::DoWhileStatement(looping) => Statement::Loop {
|
|
612
|
+
init: None,
|
|
613
|
+
test: Some(self.expression(&looping.test)),
|
|
614
|
+
update: None,
|
|
615
|
+
body: Box::new(self.statement(&looping.body, None)),
|
|
616
|
+
body_first: true,
|
|
617
|
+
label,
|
|
618
|
+
},
|
|
619
|
+
Stmt::TryStatement(attempt) => {
|
|
620
|
+
let handler = attempt.handler.as_deref();
|
|
426
621
|
let parameter = match handler.and_then(|handler| handler.param.as_ref()) {
|
|
427
622
|
None => None,
|
|
428
|
-
Some(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
623
|
+
Some(parameter) => match ¶meter.pattern {
|
|
624
|
+
BindingPattern::BindingIdentifier(name) => {
|
|
625
|
+
Some(self.name(Binding::Symbol(name.symbol_id())))
|
|
626
|
+
}
|
|
627
|
+
_ => {
|
|
628
|
+
return Statement::Expression(
|
|
629
|
+
self.unsupported("a destructuring catch"),
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
},
|
|
432
633
|
};
|
|
433
634
|
Statement::Try {
|
|
434
|
-
block: self.body(&attempt.block.
|
|
635
|
+
block: self.body(&attempt.block.body),
|
|
435
636
|
parameter,
|
|
436
|
-
handler: handler.map(|handler| self.body(&handler.body.
|
|
437
|
-
finalizer: attempt
|
|
438
|
-
.finalizer
|
|
439
|
-
.as_ref()
|
|
440
|
-
.map(|body| self.body(&body.stmts)),
|
|
637
|
+
handler: handler.map(|handler| self.body(&handler.body.body)),
|
|
638
|
+
finalizer: attempt.finalizer.as_ref().map(|body| self.body(&body.body)),
|
|
441
639
|
}
|
|
442
640
|
}
|
|
443
|
-
Stmt::
|
|
641
|
+
Stmt::ForInStatement(_) | Stmt::ForOfStatement(_) => {
|
|
444
642
|
Statement::Expression(self.unsupported("a for-in or for-of loop"))
|
|
445
643
|
}
|
|
446
|
-
Stmt::
|
|
447
|
-
Stmt::
|
|
644
|
+
Stmt::WithStatement(_) => Statement::Expression(self.unsupported("a with statement")),
|
|
645
|
+
Stmt::DebuggerStatement(_) => {
|
|
646
|
+
Statement::Expression(self.unsupported("a debugger statement"))
|
|
647
|
+
}
|
|
648
|
+
_ => Statement::Expression(self.unsupported("a declaration")),
|
|
448
649
|
}
|
|
449
650
|
}
|
|
450
651
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
652
|
+
/// Plans a variable declaration, with its initializers if `initialized`.
|
|
653
|
+
fn variables(
|
|
654
|
+
&mut self,
|
|
655
|
+
declaration: &'a VariableDeclaration<'a>,
|
|
656
|
+
initialized: bool,
|
|
657
|
+
) -> Statement<'a> {
|
|
658
|
+
let mut declarations = Vec::with_capacity(declaration.declarations.len());
|
|
659
|
+
for declarator in &declaration.declarations {
|
|
660
|
+
let BindingPattern::BindingIdentifier(name) = &declarator.id else {
|
|
455
661
|
// The declarators before it run first.
|
|
456
662
|
let stop = self.unsupported("a destructuring declaration");
|
|
457
663
|
return Statement::Block(vec![
|
|
@@ -459,256 +665,290 @@ impl PlanCompiler {
|
|
|
459
665
|
Statement::Expression(stop),
|
|
460
666
|
]);
|
|
461
667
|
};
|
|
462
|
-
self.rejected |= name.
|
|
668
|
+
self.rejected |= name.name == "arguments";
|
|
669
|
+
let init = declarator.init.as_ref().filter(|_| initialized);
|
|
463
670
|
declarations.push(Declaration {
|
|
464
|
-
name: self.name(
|
|
465
|
-
init:
|
|
466
|
-
keeps: declaration.kind ==
|
|
671
|
+
name: self.name(Binding::Symbol(name.symbol_id())),
|
|
672
|
+
init: init.map(|init| self.expression(init)),
|
|
673
|
+
keeps: declaration.kind == VariableDeclarationKind::Var && init.is_none(),
|
|
467
674
|
});
|
|
468
675
|
}
|
|
469
676
|
Statement::Declare(declarations)
|
|
470
677
|
}
|
|
471
678
|
|
|
472
|
-
fn
|
|
473
|
-
match
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
MemberProp::PrivateName(_) => self.unsupported_key("a private name"),
|
|
679
|
+
fn name(&self, binding: Binding<'a>) -> Name<'a> {
|
|
680
|
+
match self.locals.get(&binding) {
|
|
681
|
+
Some(&slot) => Name::Local(slot, binding),
|
|
682
|
+
None => Name::Scoped(binding),
|
|
477
683
|
}
|
|
478
684
|
}
|
|
479
685
|
|
|
480
|
-
fn
|
|
481
|
-
|
|
482
|
-
Some(&slot) => Name::Local(slot, name),
|
|
483
|
-
None => Name::Global(name),
|
|
484
|
-
}
|
|
686
|
+
fn reference(&self, reference: &IdentifierReference<'a>) -> Name<'a> {
|
|
687
|
+
self.name(self.script.binding(reference))
|
|
485
688
|
}
|
|
486
689
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
690
|
+
/// Plans the object and property of `member`, or returns `None` for a `super` property.
|
|
691
|
+
fn member(
|
|
692
|
+
&mut self,
|
|
693
|
+
member: &'a MemberExpression<'a>,
|
|
694
|
+
) -> Option<(Expression<'a>, Property<'a>)> {
|
|
695
|
+
if matches!(member.object(), Expr::Super(_)) {
|
|
696
|
+
return None;
|
|
697
|
+
}
|
|
698
|
+
let object = self.expression(member.object());
|
|
699
|
+
let property = match member {
|
|
700
|
+
MemberExpression::StaticMemberExpression(member) => {
|
|
701
|
+
Property::Name(member.property.name.as_str())
|
|
702
|
+
}
|
|
703
|
+
MemberExpression::ComputedMemberExpression(member) => {
|
|
704
|
+
Property::Computed(Box::new(self.expression(&member.expression)))
|
|
705
|
+
}
|
|
706
|
+
MemberExpression::PrivateFieldExpression(_) => self.unsupported_key("a private name"),
|
|
707
|
+
};
|
|
708
|
+
Some((object, property))
|
|
492
709
|
}
|
|
493
710
|
|
|
494
|
-
fn arguments
|
|
711
|
+
fn arguments(&mut self, arguments: &'a [Argument<'a>]) -> Vec<Expression<'a>> {
|
|
495
712
|
arguments
|
|
496
713
|
.iter()
|
|
497
|
-
.map(|argument| match argument.
|
|
498
|
-
|
|
499
|
-
|
|
714
|
+
.map(|argument| match argument.as_expression() {
|
|
715
|
+
Some(argument) => self.expression(argument),
|
|
716
|
+
None => self.unsupported("a spread argument"),
|
|
500
717
|
})
|
|
501
718
|
.collect()
|
|
502
719
|
}
|
|
503
720
|
|
|
504
721
|
/// Compiles a `key: value` property. Unsupported property forms stop evaluation before the
|
|
505
722
|
/// value.
|
|
506
|
-
fn object_property
|
|
723
|
+
fn object_property(
|
|
507
724
|
&mut self,
|
|
508
|
-
property: &'a
|
|
725
|
+
property: &'a ObjectPropertyKind<'a>,
|
|
509
726
|
) -> (Property<'a>, Expression<'a>) {
|
|
510
727
|
let property = match property {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
728
|
+
ObjectPropertyKind::ObjectProperty(property)
|
|
729
|
+
if property.kind == PropertyKind::Init
|
|
730
|
+
&& !property.method
|
|
731
|
+
&& !property.shorthand =>
|
|
732
|
+
{
|
|
733
|
+
property
|
|
734
|
+
}
|
|
735
|
+
ObjectPropertyKind::ObjectProperty(_) => {
|
|
736
|
+
return self.unsupported_property("an object method or shorthand");
|
|
737
|
+
}
|
|
738
|
+
ObjectPropertyKind::SpreadProperty(_) => {
|
|
739
|
+
return self.unsupported_property("a spread property");
|
|
740
|
+
}
|
|
516
741
|
};
|
|
517
742
|
let key = match &property.key {
|
|
518
|
-
|
|
743
|
+
key if property.computed => {
|
|
744
|
+
self.rejected = true;
|
|
745
|
+
let key = key
|
|
746
|
+
.as_expression()
|
|
747
|
+
.expect("a computed key is an expression");
|
|
748
|
+
Property::Computed(Box::new(self.expression(key)))
|
|
749
|
+
}
|
|
750
|
+
PropertyKey::StaticIdentifier(name) => Property::Name(name.name.as_str()),
|
|
519
751
|
// Property keys require text; lone-surrogate strings have no text representation.
|
|
520
|
-
|
|
752
|
+
PropertyKey::StringLiteral(name) => match name.value.as_str() {
|
|
521
753
|
Some(name) => Property::Name(name),
|
|
522
754
|
None => self.unsupported_key("an object key with a lone surrogate"),
|
|
523
755
|
},
|
|
524
|
-
|
|
756
|
+
PropertyKey::NumericLiteral(number) => {
|
|
525
757
|
Property::Computed(Box::new(Expression::Constant(Value::Number(number.value))))
|
|
526
758
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
Property::Computed(Box::new(self.expression(&key.expr)))
|
|
530
|
-
}
|
|
531
|
-
PropName::BigInt(_) => self.unsupported_key("a bigint key"),
|
|
759
|
+
PropertyKey::BigIntLiteral(_) => self.unsupported_key("a bigint key"),
|
|
760
|
+
_ => self.unsupported_key("a private name"),
|
|
532
761
|
};
|
|
533
762
|
(key, self.expression(&property.value))
|
|
534
763
|
}
|
|
535
764
|
|
|
536
765
|
/// Compiles unsupported syntax as a node that stops evaluation. Slot-plan compilation
|
|
537
766
|
/// rejects it.
|
|
538
|
-
fn unsupported
|
|
767
|
+
fn unsupported(&mut self, reason: &'static str) -> Expression<'a> {
|
|
539
768
|
self.rejected = true;
|
|
540
769
|
Expression::Unsupported(reason)
|
|
541
770
|
}
|
|
542
771
|
|
|
543
|
-
fn unsupported_key
|
|
772
|
+
fn unsupported_key(&mut self, reason: &'static str) -> Property<'a> {
|
|
544
773
|
Property::Computed(Box::new(self.unsupported(reason)))
|
|
545
774
|
}
|
|
546
775
|
|
|
547
776
|
/// A property that stops at its key; its value is never reached.
|
|
548
|
-
fn unsupported_property
|
|
777
|
+
fn unsupported_property(&mut self, reason: &'static str) -> (Property<'a>, Expression<'a>) {
|
|
549
778
|
(
|
|
550
779
|
self.unsupported_key(reason),
|
|
551
780
|
Expression::Unsupported(reason),
|
|
552
781
|
)
|
|
553
782
|
}
|
|
554
783
|
|
|
555
|
-
|
|
784
|
+
/// Plans a name or member target, or returns `None` for other targets.
|
|
785
|
+
fn target(&mut self, target: &'a SimpleAssignmentTarget<'a>) -> Option<Target<'a>> {
|
|
786
|
+
match target {
|
|
787
|
+
SimpleAssignmentTarget::AssignmentTargetIdentifier(name) => {
|
|
788
|
+
Some(Target::Name(self.reference(name)))
|
|
789
|
+
}
|
|
790
|
+
target => {
|
|
791
|
+
let (object, property) = self.member(target.as_member_expression()?)?;
|
|
792
|
+
Some(Target::Member(Box::new(object), property))
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
fn expression(&mut self, expression: &'a Expr<'a>) -> Expression<'a> {
|
|
556
798
|
match expression {
|
|
557
|
-
Expr::
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
.and_then(|quasi| quasi.cooked.as_ref())
|
|
570
|
-
{
|
|
799
|
+
Expr::NumericLiteral(number) => Expression::Constant(Value::Number(number.value)),
|
|
800
|
+
// Literals may hold lone surrogates, which only code units keep.
|
|
801
|
+
Expr::StringLiteral(text) => {
|
|
802
|
+
Expression::Constant(Value::String(text.value.encode_utf16().collect()))
|
|
803
|
+
}
|
|
804
|
+
Expr::BooleanLiteral(value) => Expression::Constant(Value::Bool(value.value)),
|
|
805
|
+
Expr::NullLiteral(_) => Expression::Constant(Value::Null),
|
|
806
|
+
Expr::RegExpLiteral(_) | Expr::BigIntLiteral(_) => {
|
|
807
|
+
self.unsupported("a regular expression or bigint literal")
|
|
808
|
+
}
|
|
809
|
+
Expr::TemplateLiteral(template) if template.expressions.is_empty() => {
|
|
810
|
+
match template.quasis.first().and_then(|quasi| quasi.value.cooked) {
|
|
571
811
|
Some(cooked) => {
|
|
572
|
-
Expression::Constant(Value::String(cooked.
|
|
812
|
+
Expression::Constant(Value::String(cooked.encode_utf16().collect()))
|
|
573
813
|
}
|
|
574
814
|
None => self.unsupported("a raw template"),
|
|
575
815
|
}
|
|
576
816
|
}
|
|
577
|
-
Expr::
|
|
578
|
-
Expr::
|
|
579
|
-
Expr::
|
|
580
|
-
Expr::
|
|
817
|
+
Expr::Identifier(name) => Expression::Name(self.reference(name)),
|
|
818
|
+
Expr::ThisExpression(_) => Expression::This,
|
|
819
|
+
Expr::ParenthesizedExpression(paren) => self.expression(&paren.expression),
|
|
820
|
+
Expr::SequenceExpression(sequence) => Expression::Sequence(
|
|
581
821
|
sequence
|
|
582
|
-
.
|
|
822
|
+
.expressions
|
|
583
823
|
.iter()
|
|
584
824
|
.map(|expression| self.expression(expression))
|
|
585
825
|
.collect(),
|
|
586
826
|
),
|
|
587
|
-
Expr::
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
827
|
+
Expr::StaticMemberExpression(_)
|
|
828
|
+
| Expr::ComputedMemberExpression(_)
|
|
829
|
+
| Expr::PrivateFieldExpression(_) => {
|
|
830
|
+
let member = expression
|
|
831
|
+
.as_member_expression()
|
|
832
|
+
.expect("a member expression");
|
|
833
|
+
match self.member(member) {
|
|
834
|
+
Some((object, property)) => Expression::Member(Box::new(object), property),
|
|
835
|
+
None => self.unsupported("a super property expression"),
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
Expr::CallExpression(call) => {
|
|
839
|
+
let callee = &call.callee;
|
|
840
|
+
if matches!(callee, Expr::Super(_)) {
|
|
593
841
|
return self.unsupported("a super or import call");
|
|
594
|
-
}
|
|
595
|
-
self.rejected |= matches!(
|
|
842
|
+
}
|
|
843
|
+
self.rejected |= matches!(callee, Expr::ParenthesizedExpression(_));
|
|
596
844
|
// The interpreter calls parenthesized members without a receiver, like
|
|
597
845
|
// `(0, o.f)()`. JavaScript normally preserves the receiver in `(o.f)()`.
|
|
598
|
-
let callee = match (
|
|
599
|
-
(Expr::
|
|
846
|
+
let callee = match (callee, self.expression(callee)) {
|
|
847
|
+
(Expr::ParenthesizedExpression(_), member @ Expression::Member(..)) => {
|
|
600
848
|
Expression::Sequence(vec![member])
|
|
601
849
|
}
|
|
602
850
|
(_, callee) => callee,
|
|
603
851
|
};
|
|
604
|
-
Expression::Call(Box::new(callee), self.arguments(&call.
|
|
852
|
+
Expression::Call(Box::new(callee), self.arguments(&call.arguments))
|
|
605
853
|
}
|
|
606
|
-
Expr::
|
|
854
|
+
Expr::ImportExpression(_) => self.unsupported("a super or import call"),
|
|
855
|
+
Expr::NewExpression(construction) => Expression::New(
|
|
607
856
|
Box::new(self.expression(&construction.callee)),
|
|
608
|
-
|
|
609
|
-
Some(arguments) => self.arguments(arguments),
|
|
610
|
-
None => Vec::new(),
|
|
611
|
-
},
|
|
857
|
+
self.arguments(&construction.arguments),
|
|
612
858
|
),
|
|
613
|
-
Expr::
|
|
859
|
+
Expr::LogicalExpression(logical) => Expression::Logical {
|
|
860
|
+
operator: logical.operator,
|
|
861
|
+
left: Box::new(self.expression(&logical.left)),
|
|
862
|
+
right: Box::new(self.expression(&logical.right)),
|
|
863
|
+
pure: pure(&logical.right),
|
|
864
|
+
},
|
|
865
|
+
Expr::BinaryExpression(binary) => {
|
|
614
866
|
let left = Box::new(self.expression(&binary.left));
|
|
615
867
|
let right = Box::new(self.expression(&binary.right));
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
| BinaryOp::NullishCoalescing) => Expression::Logical {
|
|
868
|
+
let operator = binary.operator;
|
|
869
|
+
match semantics::numeric(operator) {
|
|
870
|
+
Some(operation) => Expression::Arithmetic {
|
|
620
871
|
operator,
|
|
872
|
+
operation,
|
|
621
873
|
left,
|
|
622
874
|
right,
|
|
623
|
-
pure: pure(&binary.right),
|
|
624
|
-
},
|
|
625
|
-
operator => match semantics::numeric(operator) {
|
|
626
|
-
Some(operation) => Expression::Arithmetic {
|
|
627
|
-
operator,
|
|
628
|
-
operation,
|
|
629
|
-
left,
|
|
630
|
-
right,
|
|
631
|
-
},
|
|
632
|
-
None => Expression::Binary(operator, left, right),
|
|
633
875
|
},
|
|
876
|
+
None => Expression::Binary(operator, left, right),
|
|
634
877
|
}
|
|
635
878
|
}
|
|
636
|
-
Expr::
|
|
637
|
-
|
|
638
|
-
Expression::Unary(unary.op, Box::new(self.expression(&unary.arg)))
|
|
879
|
+
Expr::UnaryExpression(unary) if unary.operator == UnaryOperator::Delete => {
|
|
880
|
+
self.unsupported("delete")
|
|
639
881
|
}
|
|
640
|
-
Expr::
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
_ => return self.unsupported("a destructuring assignment"),
|
|
882
|
+
Expr::UnaryExpression(unary) => {
|
|
883
|
+
Expression::Unary(unary.operator, Box::new(self.expression(&unary.argument)))
|
|
884
|
+
}
|
|
885
|
+
Expr::AssignmentExpression(assignment) => {
|
|
886
|
+
let target = assignment.left.as_simple_assignment_target();
|
|
887
|
+
let Some(target) = target.and_then(|target| self.target(target)) else {
|
|
888
|
+
return self.unsupported("a destructuring assignment");
|
|
649
889
|
};
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
);
|
|
655
|
-
let right = Box::new(self.expression(&
|
|
890
|
+
if assignment.operator.is_logical() {
|
|
891
|
+
self.rejected = true;
|
|
892
|
+
return Expression::LogicalAssign(target);
|
|
893
|
+
}
|
|
894
|
+
let operator = assignment.operator.to_binary_operator();
|
|
895
|
+
let right = Box::new(self.expression(&assignment.right));
|
|
656
896
|
Expression::Assign(target, operator, right)
|
|
657
897
|
}
|
|
658
|
-
Expr::
|
|
659
|
-
target
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
898
|
+
Expr::UpdateExpression(update) => match self.target(&update.argument) {
|
|
899
|
+
Some(target) => Expression::Update {
|
|
900
|
+
target,
|
|
901
|
+
operator: update.operator,
|
|
902
|
+
prefix: update.prefix,
|
|
663
903
|
},
|
|
664
|
-
|
|
665
|
-
prefix: update.prefix,
|
|
904
|
+
None => self.unsupported("an increment of an expression"),
|
|
666
905
|
},
|
|
667
|
-
Expr::
|
|
906
|
+
Expr::ConditionalExpression(conditional) => Expression::Conditional(
|
|
668
907
|
Box::new(self.expression(&conditional.test)),
|
|
669
|
-
Box::new(self.expression(&conditional.
|
|
670
|
-
Box::new(self.expression(&conditional.
|
|
908
|
+
Box::new(self.expression(&conditional.consequent)),
|
|
909
|
+
Box::new(self.expression(&conditional.alternate)),
|
|
671
910
|
),
|
|
672
|
-
Expr::
|
|
911
|
+
Expr::ArrayExpression(array) => Expression::Array(
|
|
673
912
|
array
|
|
674
|
-
.
|
|
913
|
+
.elements
|
|
675
914
|
.iter()
|
|
676
915
|
.map(|element| match element {
|
|
677
|
-
|
|
678
|
-
|
|
916
|
+
ArrayExpressionElement::Elision(_) => None,
|
|
917
|
+
ArrayExpressionElement::SpreadElement(_) => {
|
|
918
|
+
Some(self.unsupported("a spread element"))
|
|
919
|
+
}
|
|
920
|
+
element => {
|
|
921
|
+
Some(self.expression(element.as_expression().expect("an element")))
|
|
679
922
|
}
|
|
680
|
-
Some(_) => Some(self.unsupported("a spread element")),
|
|
681
|
-
None => None,
|
|
682
923
|
})
|
|
683
924
|
.collect(),
|
|
684
925
|
),
|
|
685
|
-
Expr::
|
|
926
|
+
Expr::ObjectExpression(object) => Expression::Object(
|
|
686
927
|
object
|
|
687
|
-
.
|
|
928
|
+
.properties
|
|
688
929
|
.iter()
|
|
689
930
|
.map(|property| self.object_property(property))
|
|
690
931
|
.collect(),
|
|
691
932
|
),
|
|
692
|
-
Expr::
|
|
693
|
-
let name = function.
|
|
694
|
-
Expression::Function(name,
|
|
933
|
+
Expr::FunctionExpression(function) => {
|
|
934
|
+
let name = function.id.as_ref().map(|name| name.name.as_str());
|
|
935
|
+
Expression::Function(name, function)
|
|
695
936
|
}
|
|
696
937
|
// Arrows inherit `arguments`, which slot plans keep out of scopes.
|
|
697
|
-
Expr::
|
|
698
|
-
let mut
|
|
699
|
-
|
|
700
|
-
self.rejected |=
|
|
938
|
+
Expr::ArrowFunctionExpression(arrow) => {
|
|
939
|
+
let mut mentions = MentionsArguments::default();
|
|
940
|
+
mentions.visit_arrow_function_expression(arrow);
|
|
941
|
+
self.rejected |= mentions.0;
|
|
701
942
|
Expression::Arrow(arrow)
|
|
702
943
|
}
|
|
703
944
|
expression => self.unsupported(match expression {
|
|
704
|
-
Expr::
|
|
705
|
-
Expr::
|
|
706
|
-
Expr::
|
|
707
|
-
Expr::
|
|
708
|
-
Expr::
|
|
709
|
-
Expr::
|
|
710
|
-
Expr::
|
|
711
|
-
Expr::SuperProp(_) => "a super property expression",
|
|
945
|
+
Expr::TemplateLiteral(_) => "a template expression",
|
|
946
|
+
Expr::TaggedTemplateExpression(_) => "a tagged template expression",
|
|
947
|
+
Expr::ChainExpression(_) => "an optional chain expression",
|
|
948
|
+
Expr::AwaitExpression(_) => "an await expression",
|
|
949
|
+
Expr::YieldExpression(_) => "a yield expression",
|
|
950
|
+
Expr::ClassExpression(_) => "a class expression",
|
|
951
|
+
Expr::ImportMeta(_) | Expr::NewTarget(_) => "a meta property expression",
|
|
712
952
|
_ => "an unsupported expression",
|
|
713
953
|
}),
|
|
714
954
|
}
|
|
@@ -717,21 +957,29 @@ impl PlanCompiler {
|
|
|
717
957
|
|
|
718
958
|
/// Checks whether `expr` only produces a value or throws. Rejects calls, writes, and
|
|
719
959
|
/// register-dependent branches.
|
|
720
|
-
fn pure(expr: &Expr) -> bool {
|
|
960
|
+
fn pure(expr: &Expr<'_>) -> bool {
|
|
721
961
|
match expr {
|
|
722
|
-
Expr::
|
|
723
|
-
Expr::
|
|
724
|
-
Expr::
|
|
725
|
-
Expr::
|
|
726
|
-
Expr::
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
962
|
+
Expr::NumericLiteral(_)
|
|
963
|
+
| Expr::StringLiteral(_)
|
|
964
|
+
| Expr::BooleanLiteral(_)
|
|
965
|
+
| Expr::NullLiteral(_)
|
|
966
|
+
| Expr::BigIntLiteral(_)
|
|
967
|
+
| Expr::RegExpLiteral(_)
|
|
968
|
+
| Expr::Identifier(_)
|
|
969
|
+
| Expr::ThisExpression(_)
|
|
970
|
+
| Expr::FunctionExpression(_)
|
|
971
|
+
| Expr::ArrowFunctionExpression(_) => true,
|
|
972
|
+
Expr::TemplateLiteral(template) => template.expressions.is_empty(),
|
|
973
|
+
Expr::ParenthesizedExpression(paren) => pure(&paren.expression),
|
|
974
|
+
Expr::SequenceExpression(sequence) => sequence.expressions.iter().all(pure),
|
|
975
|
+
Expr::StaticMemberExpression(member) => pure(&member.object),
|
|
976
|
+
Expr::PrivateFieldExpression(member) => pure(&member.object),
|
|
977
|
+
Expr::ComputedMemberExpression(member) => pure(&member.object) && pure(&member.expression),
|
|
978
|
+
Expr::UnaryExpression(unary) => {
|
|
979
|
+
unary.operator != UnaryOperator::Delete && pure(&unary.argument)
|
|
732
980
|
}
|
|
733
|
-
Expr::
|
|
734
|
-
Expr::
|
|
981
|
+
Expr::BinaryExpression(binary) => pure(&binary.left) && pure(&binary.right),
|
|
982
|
+
Expr::LogicalExpression(logical) => pure(&logical.left) && pure(&logical.right),
|
|
735
983
|
_ => false,
|
|
736
984
|
}
|
|
737
985
|
}
|