cfsolve 0.1.1 → 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 +18 -0
- data/README.md +10 -9
- 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 +10 -8
- 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 +2570 -1894
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
- 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 -35
- data/vendor/cfsolve/examples/build_profile.rs +17 -15
- data/vendor/cfsolve/examples/capture_session.rs +37 -0
- data/vendor/cfsolve/examples/check_answers.rs +66 -0
- data/vendor/cfsolve/examples/compare_session.rs +189 -0
- 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 +6 -3
- 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 +2570 -1894
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
- data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
- data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
- 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/profile.rs +7 -18
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/recorded.rs +42 -7
- 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 +132 -0
- data/vendor/cfsolve/src/challenge/installed.rs +127 -269
- 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 +175 -35
- 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 +236 -122
- 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 +201 -205
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
- 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 +361 -322
- 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 -32
- data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
- 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 +9 -1
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -254
- data/vendor/cfsolve/src/js/objects.rs +9 -2
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -92
- data/vendor/cfsolve/src/listing/query.rs +26 -291
- data/vendor/cfsolve/src/listing.rs +0 -1
- 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 +19 -10
- data/vendor/cfsolve/src/session/probes.rs +160 -125
- 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/timing.rs +58 -53
- data/vendor/cfsolve/src/session/widget.rs +5 -6
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
- data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
- data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
- data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
- data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
- 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/native.rs +2 -1
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
- data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
- data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
- data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
- data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
- data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/records.rs +4 -13
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +98 -100
- data/vendor/cfsolve/src/stage2/registry.rs +41 -34
- data/vendor/cfsolve/src/stage2/replay.rs +182 -254
- data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +152 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
- data/vendor/cfsolve/src/stage2.rs +4 -1
- data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
- 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 +67 -68
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
- data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
- data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
- data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
- data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
- 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 +605 -330
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
- 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 +16 -3
- data/vendor/cfsolve/src/vm/machine.rs +58 -47
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
- data/vendor/cfsolve/src/vm/session.rs +197 -110
- data/vendor/cfsolve/src/vm/value.rs +35 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
- metadata +106 -183
- 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/vendor/cfsolve/src/listing/normalize.rs +0 -264
- data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
- data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
- data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
- data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
- /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,7 @@
|
|
|
1
|
-
//! Compiles JavaScript into plans
|
|
2
|
-
//! in numbered slots
|
|
3
|
-
//!
|
|
1
|
+
//! Compiles JavaScript into plans, which [`super::compile`] turns into closures. Slot plans store function locals
|
|
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 every binding through scopes.
|
|
4
|
+
//! Unsupported syntax becomes a node that stops evaluation if reached.
|
|
4
5
|
|
|
5
6
|
#[cfg(test)]
|
|
6
7
|
use std::cell::Cell;
|
|
@@ -8,169 +9,329 @@ use std::cell::RefCell;
|
|
|
8
9
|
use std::ptr;
|
|
9
10
|
use std::rc::Rc;
|
|
10
11
|
|
|
11
|
-
use
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,
|
|
17
18
|
};
|
|
18
|
-
use
|
|
19
|
+
use oxc::ast_visit::{Visit, walk};
|
|
20
|
+
use oxc::semantic::{ScopeFlags, SymbolId};
|
|
21
|
+
use oxc::syntax::operator::{BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator};
|
|
19
22
|
|
|
23
|
+
use super::compile::{self, Code};
|
|
20
24
|
use super::semantics;
|
|
21
|
-
use crate::
|
|
25
|
+
use crate::js::ast::{Binding, Script};
|
|
22
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
|
+
}
|
|
23
56
|
|
|
24
57
|
/// Caches plans by source-node address. The session's definition keeps those nodes alive longer
|
|
25
58
|
/// than the cache.
|
|
26
59
|
#[derive(Default)]
|
|
27
60
|
pub(crate) struct Plans<'ast> {
|
|
28
|
-
/// `None` marks
|
|
61
|
+
/// `None` marks routines that need a scoped plan.
|
|
29
62
|
pub(super) slot_plans: RefCell<HashMap<usize, Option<Rc<FunctionPlan<'ast>>>>>,
|
|
30
|
-
scoped_plans: RefCell<HashMap<usize, Rc<[
|
|
63
|
+
scoped_plans: RefCell<HashMap<usize, Rc<[Code<'ast>]>>>,
|
|
31
64
|
/// Forces scoped plans for comparison tests.
|
|
32
65
|
#[cfg(test)]
|
|
33
66
|
pub(super) disabled: Cell<bool>,
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
impl<'ast> Plans<'ast> {
|
|
37
|
-
pub(super) fn slots(
|
|
70
|
+
pub(super) fn slots(
|
|
71
|
+
&self,
|
|
72
|
+
script: Script<'ast>,
|
|
73
|
+
routine: Routine<'ast>,
|
|
74
|
+
) -> Option<Rc<FunctionPlan<'ast>>> {
|
|
38
75
|
#[cfg(test)]
|
|
39
76
|
if self.disabled.get() {
|
|
40
77
|
return None;
|
|
41
78
|
}
|
|
42
|
-
let
|
|
43
|
-
if let Some(plan) = self.slot_plans.borrow().get(&address) {
|
|
79
|
+
if let Some(plan) = self.slot_plans.borrow().get(&routine.address) {
|
|
44
80
|
return plan.clone();
|
|
45
81
|
}
|
|
46
|
-
let plan = FunctionPlan::compile(
|
|
47
|
-
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());
|
|
48
86
|
plan
|
|
49
87
|
}
|
|
50
88
|
|
|
51
|
-
/// Returns the scoped plan of
|
|
52
|
-
|
|
89
|
+
/// Returns the scoped plan of the routine or arrow at `address`, compiling `plan` on first
|
|
90
|
+
/// use.
|
|
91
|
+
pub(super) fn scoped(
|
|
53
92
|
&self,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
) -> Rc<[
|
|
57
|
-
let address = ptr::from_ref(code).addr();
|
|
93
|
+
address: usize,
|
|
94
|
+
plan: impl FnOnce() -> Vec<Statement<'ast>>,
|
|
95
|
+
) -> Rc<[Code<'ast>]> {
|
|
58
96
|
if let Some(plan) = self.scoped_plans.borrow().get(&address) {
|
|
59
97
|
return plan.clone();
|
|
60
98
|
}
|
|
61
|
-
let plan: Rc<[
|
|
99
|
+
let plan: Rc<[Code<'ast>]> = compile::statements(&plan()).into();
|
|
62
100
|
self.scoped_plans.borrow_mut().insert(address, plan.clone());
|
|
63
101
|
plan
|
|
64
102
|
}
|
|
65
103
|
}
|
|
66
104
|
|
|
67
105
|
pub(super) struct FunctionPlan<'ast> {
|
|
68
|
-
|
|
106
|
+
/// Where each parameter is bound: a slot, or the call's scope if a nested function
|
|
107
|
+
/// mentions it.
|
|
108
|
+
pub(super) parameters: Vec<Name<'ast>>,
|
|
69
109
|
/// The slot of `arguments`, if the body reads it.
|
|
70
110
|
pub(super) arguments: Option<usize>,
|
|
71
111
|
pub(super) locals: usize,
|
|
72
|
-
|
|
112
|
+
/// The body, compiled into closures.
|
|
113
|
+
pub(super) code: Vec<Code<'ast>>,
|
|
73
114
|
}
|
|
74
115
|
|
|
75
116
|
impl<'ast> FunctionPlan<'ast> {
|
|
76
117
|
/// Attempts to compile a slot plan. Returns `None` to request a scoped plan for unsupported
|
|
77
118
|
/// syntax, parenthesized callees, computed object keys, logical assignments, parameter
|
|
78
|
-
/// patterns, variables named `arguments`, or
|
|
79
|
-
pub(super) fn compile(
|
|
80
|
-
let mut compiler = PlanCompiler
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
119
|
+
/// patterns, variables named `arguments`, or arrows reading `arguments`.
|
|
120
|
+
pub(super) fn compile(script: Script<'ast>, routine: Routine<'ast>) -> Option<Self> {
|
|
121
|
+
let mut compiler = PlanCompiler {
|
|
122
|
+
captured: captured(script, routine),
|
|
123
|
+
..PlanCompiler::new(script)
|
|
124
|
+
};
|
|
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" {
|
|
85
129
|
return None;
|
|
86
130
|
}
|
|
87
|
-
|
|
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
|
+
}
|
|
88
139
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
140
|
+
for statement in routine.statements {
|
|
141
|
+
compiler.visit_statement(statement);
|
|
142
|
+
}
|
|
143
|
+
let body = compiler.routine(routine);
|
|
92
144
|
if compiler.rejected {
|
|
93
145
|
return None;
|
|
94
146
|
}
|
|
95
147
|
Some(Self {
|
|
96
|
-
parameters,
|
|
97
|
-
arguments: compiler.locals.get(&
|
|
148
|
+
parameters: names,
|
|
149
|
+
arguments: compiler.locals.get(&Binding::Global("arguments")).copied(),
|
|
98
150
|
locals: compiler.locals.len(),
|
|
99
|
-
body,
|
|
151
|
+
code: compile::statements(&body),
|
|
100
152
|
})
|
|
101
153
|
}
|
|
102
154
|
}
|
|
103
155
|
|
|
104
|
-
pub(super) fn
|
|
105
|
-
|
|
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)
|
|
106
161
|
}
|
|
107
162
|
|
|
108
|
-
/// Scoped execution plan for a
|
|
109
|
-
/// of the call.
|
|
110
|
-
pub(super) fn
|
|
111
|
-
|
|
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)
|
|
112
170
|
}
|
|
113
171
|
|
|
114
|
-
pub(super) fn scoped_expression
|
|
115
|
-
|
|
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)
|
|
116
177
|
}
|
|
117
178
|
|
|
118
|
-
pub(super) fn scoped_arrow
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
}
|
|
122
192
|
}
|
|
123
193
|
}
|
|
124
194
|
|
|
125
|
-
|
|
126
|
-
|
|
195
|
+
struct PlanCompiler<'a> {
|
|
196
|
+
script: Script<'a>,
|
|
127
197
|
/// Slots of a slot plan's locals; empty for scoped plans.
|
|
128
|
-
locals: HashMap<
|
|
198
|
+
locals: HashMap<Binding<'a>, usize>,
|
|
199
|
+
/// Bindings nested functions mention. These locals stay in the call's scope.
|
|
200
|
+
captured: HashSet<SymbolId>,
|
|
129
201
|
/// Whether compilation needs a scoped plan. Ignored when compiling scoped plans.
|
|
130
202
|
rejected: bool,
|
|
131
203
|
}
|
|
132
204
|
|
|
133
|
-
impl Visit for PlanCompiler {
|
|
134
|
-
fn
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
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);
|
|
139
209
|
}
|
|
140
210
|
|
|
141
|
-
fn
|
|
142
|
-
if name
|
|
143
|
-
self.
|
|
211
|
+
fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
|
|
212
|
+
if reference.name == "arguments" {
|
|
213
|
+
self.local(self.script.binding(reference));
|
|
144
214
|
}
|
|
145
215
|
}
|
|
146
216
|
|
|
147
|
-
/// Treat a nested function declaration as a local binding in the enclosing function.
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
}
|
|
150
225
|
}
|
|
151
226
|
|
|
152
227
|
/// Treat a `catch` parameter as a function local in the execution plan.
|
|
153
|
-
fn visit_catch_clause(&mut self, clause: &CatchClause) {
|
|
154
|
-
if let Some(
|
|
155
|
-
|
|
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()));
|
|
156
233
|
}
|
|
157
|
-
|
|
234
|
+
walk::walk_catch_clause(self, clause);
|
|
158
235
|
}
|
|
159
236
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
fn visit_function(&mut self, _: &Function) {}
|
|
163
|
-
fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
|
|
164
|
-
fn visit_class(&mut self, _: &Class) {}
|
|
237
|
+
fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
|
|
238
|
+
fn visit_class(&mut self, _: &Class<'a>) {}
|
|
165
239
|
}
|
|
166
240
|
|
|
167
|
-
///
|
|
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
|
+
}
|
|
259
|
+
|
|
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>) {}
|
|
269
|
+
}
|
|
270
|
+
|
|
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
|
+
}
|
|
293
|
+
|
|
294
|
+
fn visit_arrow_function_expression(&mut self, arrow: &ArrowFunctionExpression<'a>) {
|
|
295
|
+
self.0.visit_arrow_function_expression(arrow);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
fn visit_class(&mut self, class: &Class<'a>) {
|
|
299
|
+
self.0.visit_class(class);
|
|
300
|
+
}
|
|
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);
|
|
308
|
+
}
|
|
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.
|
|
168
325
|
#[derive(Default)]
|
|
169
|
-
struct
|
|
326
|
+
struct MentionsArguments(bool);
|
|
170
327
|
|
|
171
|
-
impl Visit for
|
|
172
|
-
fn
|
|
173
|
-
self.0.
|
|
328
|
+
impl<'a> Visit<'a> for MentionsArguments {
|
|
329
|
+
fn visit_identifier_reference(&mut self, name: &IdentifierReference<'a>) {
|
|
330
|
+
self.0 |= name.name == "arguments";
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
fn visit_binding_identifier(&mut self, name: &BindingIdentifier<'a>) {
|
|
334
|
+
self.0 |= name.name == "arguments";
|
|
174
335
|
}
|
|
175
336
|
}
|
|
176
337
|
|
|
@@ -206,11 +367,11 @@ pub(super) enum Statement<'ast> {
|
|
|
206
367
|
body: Box<Statement<'ast>>,
|
|
207
368
|
/// Whether the body runs once before the test, as in `do ... while`.
|
|
208
369
|
body_first: bool,
|
|
209
|
-
label: Option<&'ast
|
|
370
|
+
label: Option<&'ast str>,
|
|
210
371
|
},
|
|
211
|
-
Break(Option<&'ast
|
|
212
|
-
Continue(Option<&'ast
|
|
213
|
-
Label(&'ast
|
|
372
|
+
Break(Option<&'ast str>),
|
|
373
|
+
Continue(Option<&'ast str>),
|
|
374
|
+
Label(&'ast str, Box<Statement<'ast>>),
|
|
214
375
|
/// A `try` statement with its catch parameter, catch body, and finally body.
|
|
215
376
|
Try {
|
|
216
377
|
block: Vec<Statement<'ast>>,
|
|
@@ -223,7 +384,7 @@ pub(super) enum Statement<'ast> {
|
|
|
223
384
|
|
|
224
385
|
pub(super) enum Expression<'ast> {
|
|
225
386
|
Logical {
|
|
226
|
-
operator:
|
|
387
|
+
operator: LogicalOperator,
|
|
227
388
|
left: Box<Expression<'ast>>,
|
|
228
389
|
right: Box<Expression<'ast>>,
|
|
229
390
|
/// Whether the right side is [`pure`].
|
|
@@ -236,20 +397,22 @@ pub(super) enum Expression<'ast> {
|
|
|
236
397
|
Member(Box<Expression<'ast>>, Property<'ast>),
|
|
237
398
|
Call(Box<Expression<'ast>>, Vec<Expression<'ast>>),
|
|
238
399
|
New(Box<Expression<'ast>>, Vec<Expression<'ast>>),
|
|
239
|
-
Binary(
|
|
400
|
+
Binary(BinaryOperator, Box<Expression<'ast>>, Box<Expression<'ast>>),
|
|
240
401
|
/// An arithmetic or bitwise operator, with its operation on numbers (see
|
|
241
402
|
/// [`semantics::numeric`]).
|
|
242
403
|
Arithmetic {
|
|
243
|
-
operator:
|
|
404
|
+
operator: BinaryOperator,
|
|
244
405
|
operation: fn(f64, f64) -> f64,
|
|
245
406
|
left: Box<Expression<'ast>>,
|
|
246
407
|
right: Box<Expression<'ast>>,
|
|
247
408
|
},
|
|
248
|
-
Unary(
|
|
249
|
-
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>),
|
|
250
413
|
Update {
|
|
251
414
|
target: Target<'ast>,
|
|
252
|
-
operator:
|
|
415
|
+
operator: UpdateOperator,
|
|
253
416
|
prefix: bool,
|
|
254
417
|
},
|
|
255
418
|
Conditional(
|
|
@@ -259,8 +422,8 @@ pub(super) enum Expression<'ast> {
|
|
|
259
422
|
),
|
|
260
423
|
Array(Vec<Option<Expression<'ast>>>),
|
|
261
424
|
Object(Vec<(Property<'ast>, Expression<'ast>)>),
|
|
262
|
-
Function(Option<&'ast
|
|
263
|
-
Arrow(&'ast
|
|
425
|
+
Function(Option<&'ast str>, &'ast Function<'ast>),
|
|
426
|
+
Arrow(&'ast ArrowFunctionExpression<'ast>),
|
|
264
427
|
/// Syntax the interpreter does not follow, described for diagnostics.
|
|
265
428
|
Unsupported(&'static str),
|
|
266
429
|
}
|
|
@@ -275,107 +438,157 @@ pub(super) enum Target<'ast> {
|
|
|
275
438
|
Member(Box<Expression<'ast>>, Property<'ast>),
|
|
276
439
|
}
|
|
277
440
|
|
|
278
|
-
/// A
|
|
441
|
+
/// A binding a plan reads or writes: a local, by its slot, or a binding resolved through
|
|
442
|
+
/// scopes.
|
|
279
443
|
#[derive(Clone, Copy)]
|
|
280
444
|
pub(super) enum Name<'ast> {
|
|
281
|
-
Local(usize,
|
|
282
|
-
|
|
445
|
+
Local(usize, Binding<'ast>),
|
|
446
|
+
Scoped(Binding<'ast>),
|
|
283
447
|
}
|
|
284
448
|
|
|
285
449
|
impl<'ast> Name<'ast> {
|
|
286
|
-
pub(super) fn
|
|
450
|
+
pub(super) fn binding(self) -> Binding<'ast> {
|
|
287
451
|
match self {
|
|
288
|
-
Self::Local(_,
|
|
452
|
+
Self::Local(_, binding) | Self::Scoped(binding) => binding,
|
|
289
453
|
}
|
|
290
454
|
}
|
|
291
455
|
}
|
|
292
456
|
|
|
293
|
-
impl PlanCompiler {
|
|
294
|
-
fn
|
|
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,
|
|
464
|
+
}
|
|
465
|
+
}
|
|
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
|
+
}
|
|
295
474
|
let next = self.locals.len();
|
|
296
|
-
|
|
475
|
+
self.locals.entry(binding).or_insert(next);
|
|
297
476
|
}
|
|
298
477
|
|
|
299
|
-
///
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
nested.visit_with(&mut names);
|
|
305
|
-
names
|
|
306
|
-
.0
|
|
307
|
-
.iter()
|
|
308
|
-
.all(|name| !self.locals.contains_key(name) && !(arrow && name == "arguments"))
|
|
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
|
+
}
|
|
309
483
|
}
|
|
310
484
|
|
|
311
|
-
/// Plans a function
|
|
312
|
-
///
|
|
313
|
-
fn
|
|
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
|
+
|
|
499
|
+
/// Plans a function body or block, binding its function declarations before executing
|
|
500
|
+
/// statements, as JavaScript hoists them to the start of the body or block. Declarations
|
|
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>> {
|
|
314
510
|
let mut plan = Vec::with_capacity(statements.len());
|
|
315
511
|
for statement in statements {
|
|
316
|
-
if let Stmt::
|
|
317
|
-
let name = &
|
|
318
|
-
|
|
512
|
+
if let Stmt::FunctionDeclaration(function) = statement
|
|
513
|
+
&& let Some(name) = &function.id
|
|
514
|
+
{
|
|
319
515
|
plan.push(Statement::Declare(vec![Declaration {
|
|
320
|
-
name: self.name(name),
|
|
321
|
-
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)),
|
|
322
518
|
keeps: false,
|
|
323
519
|
}]));
|
|
324
520
|
}
|
|
325
521
|
}
|
|
326
|
-
plan.extend(self.statements(statements));
|
|
327
522
|
plan
|
|
328
523
|
}
|
|
329
524
|
|
|
330
|
-
fn statements
|
|
525
|
+
fn statements(&mut self, statements: &'a [Stmt<'a>]) -> Vec<Statement<'a>> {
|
|
331
526
|
statements
|
|
332
527
|
.iter()
|
|
333
528
|
.map(|statement| self.statement(statement, None))
|
|
334
529
|
.collect()
|
|
335
530
|
}
|
|
336
531
|
|
|
337
|
-
fn statement
|
|
532
|
+
fn statement(&mut self, statement: &'a Stmt<'a>, label: Option<&'a str>) -> Statement<'a> {
|
|
338
533
|
match statement {
|
|
339
|
-
Stmt::
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
Stmt::
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
Stmt::
|
|
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(
|
|
347
546
|
self.expression(&branch.test),
|
|
348
|
-
Box::new(self.statement(&branch.
|
|
547
|
+
Box::new(self.statement(&branch.consequent, None)),
|
|
349
548
|
branch
|
|
350
|
-
.
|
|
549
|
+
.alternate
|
|
351
550
|
.as_ref()
|
|
352
|
-
.map(|
|
|
551
|
+
.map(|alternate| Box::new(self.statement(alternate, None))),
|
|
353
552
|
),
|
|
354
|
-
Stmt::
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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) => {
|
|
359
561
|
let discriminant = self.expression(&switch.discriminant);
|
|
360
562
|
let cases = switch.cases.iter().map(|case| Case {
|
|
361
563
|
test: case.test.as_ref().map(|test| self.expression(test)),
|
|
362
|
-
body: self.statements(&case.
|
|
564
|
+
body: self.statements(&case.consequent),
|
|
363
565
|
});
|
|
364
566
|
Statement::Switch(discriminant, cases.collect())
|
|
365
567
|
}
|
|
366
|
-
Stmt::
|
|
367
|
-
|
|
368
|
-
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()))
|
|
369
570
|
}
|
|
370
|
-
Stmt::
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
)
|
|
374
|
-
|
|
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 {
|
|
375
579
|
init: looping.init.as_ref().map(|init| {
|
|
376
580
|
Box::new(match init {
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
),
|
|
379
592
|
})
|
|
380
593
|
}),
|
|
381
594
|
test: looping.test.as_ref().map(|test| self.expression(test)),
|
|
@@ -387,46 +600,64 @@ impl PlanCompiler {
|
|
|
387
600
|
body_first: false,
|
|
388
601
|
label,
|
|
389
602
|
},
|
|
390
|
-
Stmt::
|
|
391
|
-
|
|
603
|
+
Stmt::WhileStatement(looping) => Statement::Loop {
|
|
604
|
+
init: None,
|
|
605
|
+
test: Some(self.expression(&looping.test)),
|
|
606
|
+
update: None,
|
|
607
|
+
body: Box::new(self.statement(&looping.body, None)),
|
|
608
|
+
body_first: false,
|
|
609
|
+
label,
|
|
610
|
+
},
|
|
611
|
+
Stmt::DoWhileStatement(looping) => Statement::Loop {
|
|
392
612
|
init: None,
|
|
393
|
-
test: Some(self.expression(test)),
|
|
613
|
+
test: Some(self.expression(&looping.test)),
|
|
394
614
|
update: None,
|
|
395
|
-
body: Box::new(self.statement(body, None)),
|
|
396
|
-
body_first:
|
|
615
|
+
body: Box::new(self.statement(&looping.body, None)),
|
|
616
|
+
body_first: true,
|
|
397
617
|
label,
|
|
398
618
|
},
|
|
399
|
-
Stmt::
|
|
400
|
-
let handler = attempt.handler.
|
|
619
|
+
Stmt::TryStatement(attempt) => {
|
|
620
|
+
let handler = attempt.handler.as_deref();
|
|
401
621
|
let parameter = match handler.and_then(|handler| handler.param.as_ref()) {
|
|
402
622
|
None => None,
|
|
403
|
-
Some(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
+
},
|
|
407
633
|
};
|
|
408
634
|
Statement::Try {
|
|
409
|
-
block: self.
|
|
635
|
+
block: self.body(&attempt.block.body),
|
|
410
636
|
parameter,
|
|
411
|
-
handler: handler.map(|handler| self.
|
|
412
|
-
finalizer: attempt
|
|
413
|
-
.finalizer
|
|
414
|
-
.as_ref()
|
|
415
|
-
.map(|body| self.statements(&body.stmts)),
|
|
637
|
+
handler: handler.map(|handler| self.body(&handler.body.body)),
|
|
638
|
+
finalizer: attempt.finalizer.as_ref().map(|body| self.body(&body.body)),
|
|
416
639
|
}
|
|
417
640
|
}
|
|
418
|
-
Stmt::
|
|
641
|
+
Stmt::ForInStatement(_) | Stmt::ForOfStatement(_) => {
|
|
419
642
|
Statement::Expression(self.unsupported("a for-in or for-of loop"))
|
|
420
643
|
}
|
|
421
|
-
Stmt::
|
|
422
|
-
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")),
|
|
423
649
|
}
|
|
424
650
|
}
|
|
425
651
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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 {
|
|
430
661
|
// The declarators before it run first.
|
|
431
662
|
let stop = self.unsupported("a destructuring declaration");
|
|
432
663
|
return Statement::Block(vec![
|
|
@@ -434,254 +665,290 @@ impl PlanCompiler {
|
|
|
434
665
|
Statement::Expression(stop),
|
|
435
666
|
]);
|
|
436
667
|
};
|
|
437
|
-
self.rejected |= name.
|
|
668
|
+
self.rejected |= name.name == "arguments";
|
|
669
|
+
let init = declarator.init.as_ref().filter(|_| initialized);
|
|
438
670
|
declarations.push(Declaration {
|
|
439
|
-
name: self.name(
|
|
440
|
-
init:
|
|
441
|
-
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(),
|
|
442
674
|
});
|
|
443
675
|
}
|
|
444
676
|
Statement::Declare(declarations)
|
|
445
677
|
}
|
|
446
678
|
|
|
447
|
-
fn
|
|
448
|
-
match
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
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),
|
|
452
683
|
}
|
|
453
684
|
}
|
|
454
685
|
|
|
455
|
-
fn
|
|
456
|
-
|
|
457
|
-
Some(&slot) => Name::Local(slot, name),
|
|
458
|
-
None => Name::Global(name),
|
|
459
|
-
}
|
|
686
|
+
fn reference(&self, reference: &IdentifierReference<'a>) -> Name<'a> {
|
|
687
|
+
self.name(self.script.binding(reference))
|
|
460
688
|
}
|
|
461
689
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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))
|
|
467
709
|
}
|
|
468
710
|
|
|
469
|
-
fn arguments
|
|
711
|
+
fn arguments(&mut self, arguments: &'a [Argument<'a>]) -> Vec<Expression<'a>> {
|
|
470
712
|
arguments
|
|
471
713
|
.iter()
|
|
472
|
-
.map(|argument| match argument.
|
|
473
|
-
|
|
474
|
-
|
|
714
|
+
.map(|argument| match argument.as_expression() {
|
|
715
|
+
Some(argument) => self.expression(argument),
|
|
716
|
+
None => self.unsupported("a spread argument"),
|
|
475
717
|
})
|
|
476
718
|
.collect()
|
|
477
719
|
}
|
|
478
720
|
|
|
479
721
|
/// Compiles a `key: value` property. Unsupported property forms stop evaluation before the
|
|
480
722
|
/// value.
|
|
481
|
-
fn object_property
|
|
723
|
+
fn object_property(
|
|
482
724
|
&mut self,
|
|
483
|
-
property: &'a
|
|
725
|
+
property: &'a ObjectPropertyKind<'a>,
|
|
484
726
|
) -> (Property<'a>, Expression<'a>) {
|
|
485
727
|
let property = match property {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
+
}
|
|
491
741
|
};
|
|
492
742
|
let key = match &property.key {
|
|
493
|
-
|
|
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()),
|
|
494
751
|
// Property keys require text; lone-surrogate strings have no text representation.
|
|
495
|
-
|
|
752
|
+
PropertyKey::StringLiteral(name) => match name.value.as_str() {
|
|
496
753
|
Some(name) => Property::Name(name),
|
|
497
754
|
None => self.unsupported_key("an object key with a lone surrogate"),
|
|
498
755
|
},
|
|
499
|
-
|
|
756
|
+
PropertyKey::NumericLiteral(number) => {
|
|
500
757
|
Property::Computed(Box::new(Expression::Constant(Value::Number(number.value))))
|
|
501
758
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
Property::Computed(Box::new(self.expression(&key.expr)))
|
|
505
|
-
}
|
|
506
|
-
PropName::BigInt(_) => self.unsupported_key("a bigint key"),
|
|
759
|
+
PropertyKey::BigIntLiteral(_) => self.unsupported_key("a bigint key"),
|
|
760
|
+
_ => self.unsupported_key("a private name"),
|
|
507
761
|
};
|
|
508
762
|
(key, self.expression(&property.value))
|
|
509
763
|
}
|
|
510
764
|
|
|
511
765
|
/// Compiles unsupported syntax as a node that stops evaluation. Slot-plan compilation
|
|
512
766
|
/// rejects it.
|
|
513
|
-
fn unsupported
|
|
767
|
+
fn unsupported(&mut self, reason: &'static str) -> Expression<'a> {
|
|
514
768
|
self.rejected = true;
|
|
515
769
|
Expression::Unsupported(reason)
|
|
516
770
|
}
|
|
517
771
|
|
|
518
|
-
fn unsupported_key
|
|
772
|
+
fn unsupported_key(&mut self, reason: &'static str) -> Property<'a> {
|
|
519
773
|
Property::Computed(Box::new(self.unsupported(reason)))
|
|
520
774
|
}
|
|
521
775
|
|
|
522
776
|
/// A property that stops at its key; its value is never reached.
|
|
523
|
-
fn unsupported_property
|
|
777
|
+
fn unsupported_property(&mut self, reason: &'static str) -> (Property<'a>, Expression<'a>) {
|
|
524
778
|
(
|
|
525
779
|
self.unsupported_key(reason),
|
|
526
780
|
Expression::Unsupported(reason),
|
|
527
781
|
)
|
|
528
782
|
}
|
|
529
783
|
|
|
530
|
-
|
|
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> {
|
|
531
798
|
match expression {
|
|
532
|
-
Expr::
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
.and_then(|quasi| quasi.cooked.as_ref())
|
|
545
|
-
{
|
|
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) {
|
|
546
811
|
Some(cooked) => {
|
|
547
|
-
Expression::Constant(Value::String(cooked.
|
|
812
|
+
Expression::Constant(Value::String(cooked.encode_utf16().collect()))
|
|
548
813
|
}
|
|
549
814
|
None => self.unsupported("a raw template"),
|
|
550
815
|
}
|
|
551
816
|
}
|
|
552
|
-
Expr::
|
|
553
|
-
Expr::
|
|
554
|
-
Expr::
|
|
555
|
-
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(
|
|
556
821
|
sequence
|
|
557
|
-
.
|
|
822
|
+
.expressions
|
|
558
823
|
.iter()
|
|
559
824
|
.map(|expression| self.expression(expression))
|
|
560
825
|
.collect(),
|
|
561
826
|
),
|
|
562
|
-
Expr::
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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(_)) {
|
|
568
841
|
return self.unsupported("a super or import call");
|
|
569
|
-
}
|
|
570
|
-
self.rejected |= matches!(
|
|
842
|
+
}
|
|
843
|
+
self.rejected |= matches!(callee, Expr::ParenthesizedExpression(_));
|
|
571
844
|
// The interpreter calls parenthesized members without a receiver, like
|
|
572
845
|
// `(0, o.f)()`. JavaScript normally preserves the receiver in `(o.f)()`.
|
|
573
|
-
let callee = match (
|
|
574
|
-
(Expr::
|
|
846
|
+
let callee = match (callee, self.expression(callee)) {
|
|
847
|
+
(Expr::ParenthesizedExpression(_), member @ Expression::Member(..)) => {
|
|
575
848
|
Expression::Sequence(vec![member])
|
|
576
849
|
}
|
|
577
850
|
(_, callee) => callee,
|
|
578
851
|
};
|
|
579
|
-
Expression::Call(Box::new(callee), self.arguments(&call.
|
|
852
|
+
Expression::Call(Box::new(callee), self.arguments(&call.arguments))
|
|
580
853
|
}
|
|
581
|
-
Expr::
|
|
854
|
+
Expr::ImportExpression(_) => self.unsupported("a super or import call"),
|
|
855
|
+
Expr::NewExpression(construction) => Expression::New(
|
|
582
856
|
Box::new(self.expression(&construction.callee)),
|
|
583
|
-
|
|
584
|
-
Some(arguments) => self.arguments(arguments),
|
|
585
|
-
None => Vec::new(),
|
|
586
|
-
},
|
|
857
|
+
self.arguments(&construction.arguments),
|
|
587
858
|
),
|
|
588
|
-
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) => {
|
|
589
866
|
let left = Box::new(self.expression(&binary.left));
|
|
590
867
|
let right = Box::new(self.expression(&binary.right));
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
| BinaryOp::NullishCoalescing) => Expression::Logical {
|
|
868
|
+
let operator = binary.operator;
|
|
869
|
+
match semantics::numeric(operator) {
|
|
870
|
+
Some(operation) => Expression::Arithmetic {
|
|
595
871
|
operator,
|
|
872
|
+
operation,
|
|
596
873
|
left,
|
|
597
874
|
right,
|
|
598
|
-
pure: pure(&binary.right),
|
|
599
|
-
},
|
|
600
|
-
operator => match semantics::numeric(operator) {
|
|
601
|
-
Some(operation) => Expression::Arithmetic {
|
|
602
|
-
operator,
|
|
603
|
-
operation,
|
|
604
|
-
left,
|
|
605
|
-
right,
|
|
606
|
-
},
|
|
607
|
-
None => Expression::Binary(operator, left, right),
|
|
608
875
|
},
|
|
876
|
+
None => Expression::Binary(operator, left, right),
|
|
609
877
|
}
|
|
610
878
|
}
|
|
611
|
-
Expr::
|
|
612
|
-
|
|
613
|
-
Expression::Unary(unary.op, Box::new(self.expression(&unary.arg)))
|
|
879
|
+
Expr::UnaryExpression(unary) if unary.operator == UnaryOperator::Delete => {
|
|
880
|
+
self.unsupported("delete")
|
|
614
881
|
}
|
|
615
|
-
Expr::
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
_ => 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");
|
|
624
889
|
};
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
);
|
|
630
|
-
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));
|
|
631
896
|
Expression::Assign(target, operator, right)
|
|
632
897
|
}
|
|
633
|
-
Expr::
|
|
634
|
-
target
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
898
|
+
Expr::UpdateExpression(update) => match self.target(&update.argument) {
|
|
899
|
+
Some(target) => Expression::Update {
|
|
900
|
+
target,
|
|
901
|
+
operator: update.operator,
|
|
902
|
+
prefix: update.prefix,
|
|
638
903
|
},
|
|
639
|
-
|
|
640
|
-
prefix: update.prefix,
|
|
904
|
+
None => self.unsupported("an increment of an expression"),
|
|
641
905
|
},
|
|
642
|
-
Expr::
|
|
906
|
+
Expr::ConditionalExpression(conditional) => Expression::Conditional(
|
|
643
907
|
Box::new(self.expression(&conditional.test)),
|
|
644
|
-
Box::new(self.expression(&conditional.
|
|
645
|
-
Box::new(self.expression(&conditional.
|
|
908
|
+
Box::new(self.expression(&conditional.consequent)),
|
|
909
|
+
Box::new(self.expression(&conditional.alternate)),
|
|
646
910
|
),
|
|
647
|
-
Expr::
|
|
911
|
+
Expr::ArrayExpression(array) => Expression::Array(
|
|
648
912
|
array
|
|
649
|
-
.
|
|
913
|
+
.elements
|
|
650
914
|
.iter()
|
|
651
915
|
.map(|element| match element {
|
|
652
|
-
|
|
653
|
-
|
|
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")))
|
|
654
922
|
}
|
|
655
|
-
Some(_) => Some(self.unsupported("a spread element")),
|
|
656
|
-
None => None,
|
|
657
923
|
})
|
|
658
924
|
.collect(),
|
|
659
925
|
),
|
|
660
|
-
Expr::
|
|
926
|
+
Expr::ObjectExpression(object) => Expression::Object(
|
|
661
927
|
object
|
|
662
|
-
.
|
|
928
|
+
.properties
|
|
663
929
|
.iter()
|
|
664
930
|
.map(|property| self.object_property(property))
|
|
665
931
|
.collect(),
|
|
666
932
|
),
|
|
667
|
-
Expr::
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
Expression::Function(name, &function.function)
|
|
933
|
+
Expr::FunctionExpression(function) => {
|
|
934
|
+
let name = function.id.as_ref().map(|name| name.name.as_str());
|
|
935
|
+
Expression::Function(name, function)
|
|
671
936
|
}
|
|
672
|
-
|
|
673
|
-
|
|
937
|
+
// Arrows inherit `arguments`, which slot plans keep out of scopes.
|
|
938
|
+
Expr::ArrowFunctionExpression(arrow) => {
|
|
939
|
+
let mut mentions = MentionsArguments::default();
|
|
940
|
+
mentions.visit_arrow_function_expression(arrow);
|
|
941
|
+
self.rejected |= mentions.0;
|
|
674
942
|
Expression::Arrow(arrow)
|
|
675
943
|
}
|
|
676
944
|
expression => self.unsupported(match expression {
|
|
677
|
-
Expr::
|
|
678
|
-
Expr::
|
|
679
|
-
Expr::
|
|
680
|
-
Expr::
|
|
681
|
-
Expr::
|
|
682
|
-
Expr::
|
|
683
|
-
Expr::
|
|
684
|
-
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",
|
|
685
952
|
_ => "an unsupported expression",
|
|
686
953
|
}),
|
|
687
954
|
}
|
|
@@ -690,21 +957,29 @@ impl PlanCompiler {
|
|
|
690
957
|
|
|
691
958
|
/// Checks whether `expr` only produces a value or throws. Rejects calls, writes, and
|
|
692
959
|
/// register-dependent branches.
|
|
693
|
-
fn pure(expr: &Expr) -> bool {
|
|
960
|
+
fn pure(expr: &Expr<'_>) -> bool {
|
|
694
961
|
match expr {
|
|
695
|
-
Expr::
|
|
696
|
-
Expr::
|
|
697
|
-
Expr::
|
|
698
|
-
Expr::
|
|
699
|
-
Expr::
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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)
|
|
705
980
|
}
|
|
706
|
-
Expr::
|
|
707
|
-
Expr::
|
|
981
|
+
Expr::BinaryExpression(binary) => pure(&binary.left) && pure(&binary.right),
|
|
982
|
+
Expr::LogicalExpression(logical) => pure(&logical.left) && pure(&logical.right),
|
|
708
983
|
_ => false,
|
|
709
984
|
}
|
|
710
985
|
}
|