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.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/THIRD_PARTY_LICENSES/README.md +71 -254
  4. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  5. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  6. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  7. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  8. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  9. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  11. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  12. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  13. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  14. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  15. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  16. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  17. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  18. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  19. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  21. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  22. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  24. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  30. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  32. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  34. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  36. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  38. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  40. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  42. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  43. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  45. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  47. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  49. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  51. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  53. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  55. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  56. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  57. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  58. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  59. data/UPSTREAM.md +7 -5
  60. data/ext/cfsolve/Cargo.lock +534 -1727
  61. data/ext/cfsolve/Cargo.toml +4 -0
  62. data/ext/cfsolve/src/main.rs +1 -1
  63. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  64. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  65. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  66. data/lib/cfsolve/version.rb +2 -2
  67. data/vendor/cfsolve/Cargo.lock +561 -1729
  68. data/vendor/cfsolve/Cargo.toml +26 -8
  69. data/vendor/cfsolve/README.md +4 -0
  70. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  71. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  72. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  73. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  74. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  75. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  76. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  77. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  78. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  79. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  80. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  81. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  82. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  83. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  84. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  85. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  86. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  87. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  88. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  89. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  90. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  91. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  92. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  93. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  94. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  95. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  96. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  97. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  98. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  99. data/vendor/cfsolve/src/challenge.rs +1 -0
  100. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  101. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  102. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  103. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  104. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  105. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  106. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  107. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  108. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  109. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  110. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  111. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  112. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  113. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  114. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  115. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  116. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  117. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  118. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  119. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  120. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  121. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  122. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  123. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  124. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  125. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  126. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  127. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  128. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  129. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  130. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  131. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  132. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  133. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  134. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  135. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  136. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
  137. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  138. data/vendor/cfsolve/src/error.rs +40 -5
  139. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  140. data/vendor/cfsolve/src/http/client.rs +7 -10
  141. data/vendor/cfsolve/src/http/requests.rs +2 -2
  142. data/vendor/cfsolve/src/js/ast.rs +479 -263
  143. data/vendor/cfsolve/src/lib.rs +1 -0
  144. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  145. data/vendor/cfsolve/src/listing/query.rs +1 -47
  146. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  147. data/vendor/cfsolve/src/profiling.rs +49 -0
  148. data/vendor/cfsolve/src/script.rs +35 -24
  149. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  150. data/vendor/cfsolve/src/session/channel.rs +2 -2
  151. data/vendor/cfsolve/src/session/initial.rs +5 -5
  152. data/vendor/cfsolve/src/session/sink.rs +26 -1
  153. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  154. data/vendor/cfsolve/src/session.rs +1 -1
  155. data/vendor/cfsolve/src/solver.rs +3 -1
  156. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  157. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  158. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  159. data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
  160. data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
  161. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  162. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  163. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  164. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  165. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  166. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  167. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  168. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  169. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  170. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  171. data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
  172. data/vendor/cfsolve/src/stage2.rs +2 -0
  173. data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
  174. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  175. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  176. data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
  177. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  178. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  179. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  180. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  181. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  182. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  183. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  184. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  185. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  186. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
  187. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  188. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  189. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  190. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  191. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  192. data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
  193. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  194. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  195. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  196. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  197. data/vendor/cfsolve/src/vm/machine.rs +56 -49
  198. data/vendor/cfsolve/src/vm/output.rs +13 -5
  199. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  200. data/vendor/cfsolve/src/vm/session.rs +185 -120
  201. data/vendor/cfsolve/src/vm/value.rs +22 -19
  202. data/vendor/cfsolve/src/vm.rs +2 -1
  203. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  204. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  205. metadata +94 -178
  206. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  207. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  208. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  209. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  210. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  211. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  212. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  213. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  214. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  215. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  216. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  217. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  218. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  219. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  220. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  221. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  222. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  223. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  224. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  225. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  226. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  227. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  228. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  229. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  230. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  231. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  232. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  233. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  234. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  235. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  237. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  238. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  239. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  240. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  241. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  242. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  243. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  244. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  245. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  246. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  247. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  248. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  249. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  250. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  251. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  252. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  253. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  255. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  256. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  257. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  258. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  259. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  260. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  261. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  262. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  263. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  264. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  265. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  266. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  268. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  269. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  270. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  271. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  272. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  273. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  274. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  277. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  278. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  279. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  280. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  281. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  282. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  283. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  284. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  286. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  288. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  290. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  292. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  293. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  294. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  295. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  296. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  297. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  298. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  299. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  300. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  301. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  302. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  303. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  305. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  329. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  330. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  331. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  332. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  333. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  334. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  335. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  336. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  337. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  338. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  339. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  340. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  341. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  342. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  343. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  344. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  345. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  346. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  347. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  348. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  349. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  350. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  351. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  352. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  353. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  354. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  355. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  356. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  357. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  358. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  359. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  360. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  361. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  362. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  363. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  364. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  365. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  366. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  367. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  368. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -2,93 +2,125 @@
2
2
  //! helper functions, state fields, and program runner. [`super::session`] evaluates what this
3
3
  //! module finds.
4
4
 
5
+ use std::ptr;
6
+
5
7
  use anyhow::{Context, Result, bail, ensure};
6
- use swc_core::atoms::Atom;
7
- use swc_core::common::Span;
8
- use swc_core::ecma::ast::{
9
- AssignExpr, AssignOp, AssignTarget, BlockStmt, CallExpr, Class, ClassMember, Decl, Expr,
10
- ExprOrSpread, Function, Lit, ReturnStmt, Script, SimpleAssignTarget, Stmt, SwitchStmt,
8
+ use oxc::ast::AstKind;
9
+ use oxc::ast::ast::{
10
+ Argument as CallArgument, AssignmentExpression, AssignmentTarget, BindingIdentifier,
11
+ BindingPattern, CallExpression, Class, ClassElement, Expression, FormalParameters, Function,
12
+ FunctionBody, MemberExpression, MethodDefinitionKind, Statement, SwitchStatement,
11
13
  };
12
- use swc_core::ecma::visit::{Visit, VisitWith};
14
+ use oxc::ast_visit::{Visit, walk};
15
+ use oxc::semantic::{ScopeFlags, SymbolId};
16
+ use oxc::span::GetSpan;
17
+ use oxc::syntax::operator::AssignmentOperator;
13
18
 
14
19
  use super::output::Position;
15
20
  use super::{HashMap, convert};
16
- use crate::js::ast;
17
-
18
- /// Finds a class with a `run` method and the innermost function body declaring it.
19
- #[derive(Default)]
20
- pub(super) struct Finder {
21
- pub found: Option<(BlockStmt, Class)>,
22
- }
23
-
24
- impl Visit for Finder {
25
- fn visit_function(&mut self, function: &Function) {
26
- if let Some(body) = &function.body
27
- && let Some(class) = machine_class(body)
28
- {
29
- self.found = Some((body.clone(), class.clone()));
30
- }
31
- function.visit_children_with(self);
32
- }
21
+ use crate::candidates;
22
+ use crate::js::ast::{self, Binding, Script};
23
+
24
+ /// Finds a class with a `run` method and the innermost function body declaring it: the last such
25
+ /// body in source order.
26
+ pub(super) fn find<'a>(script: Script<'a>) -> Option<(&'a FunctionBody<'a>, &'a Class<'a>)> {
27
+ script
28
+ .functions()
29
+ .filter_map(|function| {
30
+ let body = function.body.as_deref()?;
31
+ Some((body, machine_class(body)?))
32
+ })
33
+ .last()
33
34
  }
34
35
 
35
36
  /// Collects the statements that run before the VM's scope is entered, both at script level and
36
- /// in each enclosing function.
37
- pub(super) fn prelude(script: &Script, body: &BlockStmt) -> Vec<Stmt> {
38
- use swc_core::common::Spanned;
39
-
40
- /// The outermost function body inside a statement that encloses `target`.
41
- struct Enclosing {
42
- target: Span,
43
- body: Option<BlockStmt>,
44
- }
45
-
46
- impl Visit for Enclosing {
47
- fn visit_function(&mut self, function: &Function) {
48
- match &function.body {
49
- Some(body) if body.span.contains(self.target) => self.body = Some(body.clone()),
50
- _ => function.visit_children_with(self),
51
- }
52
- }
53
- }
54
-
37
+ /// in each enclosing function: at each level, the statements before the one containing `body`.
38
+ pub(super) fn prelude<'a>(
39
+ script: Script<'a>,
40
+ body: &'a FunctionBody<'a>,
41
+ ) -> Vec<&'a Statement<'a>> {
42
+ let mut enclosing: Vec<&'a [Statement<'a>]> = script
43
+ .nodes
44
+ .ancestor_kinds(body.node_id.get())
45
+ .filter_map(|kind| match kind {
46
+ AstKind::Function(function) => function.body.as_deref(),
47
+ _ => None,
48
+ })
49
+ .filter(|enclosing| !ptr::eq(*enclosing, body))
50
+ .map(|enclosing| &enclosing.statements[..])
51
+ .collect();
52
+ enclosing.push(&script.program.body);
55
53
  let mut prelude = Vec::new();
56
- let mut statements = script.body.clone();
57
- while let Some(index) = statements
58
- .iter()
59
- .position(|statement| statement.span().contains(body.span))
60
- {
61
- let mut enclosing = Enclosing {
62
- target: body.span,
63
- body: None,
54
+ for statements in enclosing.into_iter().rev() {
55
+ let Some(index) = statements
56
+ .iter()
57
+ .position(|statement| statement.span().contains_inclusive(body.span))
58
+ else {
59
+ break;
64
60
  };
65
- statements[index].visit_with(&mut enclosing);
66
- statements.truncate(index);
67
- prelude.append(&mut statements);
68
- match enclosing.body {
69
- Some(enclosing) if enclosing.span != body.span => statements = enclosing.stmts,
70
- _ => break,
71
- }
61
+ prelude.extend(&statements[..index]);
72
62
  }
73
63
  prelude
74
64
  }
75
65
 
76
66
  /// Functions declared beside the class: handlers and their helpers.
77
- pub(super) fn functions(statements: &[Stmt]) -> HashMap<Atom, &Function> {
67
+ pub(super) fn functions<'a>(
68
+ statements: &'a [Statement<'a>],
69
+ ) -> HashMap<SymbolId, &'a Function<'a>> {
78
70
  statements
79
71
  .iter()
80
- .filter_map(|statement| {
81
- let function = statement.as_decl()?.as_fn_decl()?;
82
- Some((function.ident.sym.clone(), &*function.function))
72
+ .filter_map(|statement| match statement {
73
+ Statement::FunctionDeclaration(function) => {
74
+ Some((function.id.as_ref()?.symbol_id(), &**function))
75
+ }
76
+ _ => None,
83
77
  })
84
78
  .collect()
85
79
  }
86
80
 
87
- pub(super) fn constructor(class: &Class) -> Result<&BlockStmt> {
81
+ /// Every parameter, if each is a plain identifier: no pattern, default, or rest.
82
+ pub(super) fn parameters<'a>(
83
+ parameters: &'a FormalParameters<'a>,
84
+ ) -> Option<Vec<&'a BindingIdentifier<'a>>> {
85
+ if parameters.rest.is_some() {
86
+ return None;
87
+ }
88
+ (0..parameters.items.len())
89
+ .map(|index| parameter(parameters, index))
90
+ .collect()
91
+ }
92
+
93
+ /// The parameter at `index`, if it is a plain identifier.
94
+ pub(super) fn parameter<'a>(
95
+ parameters: &'a FormalParameters<'a>,
96
+ index: usize,
97
+ ) -> Option<&'a BindingIdentifier<'a>> {
98
+ let parameter = parameters.items.get(index)?;
99
+ match &parameter.pattern {
100
+ BindingPattern::BindingIdentifier(name) if parameter.initializer.is_none() => Some(name),
101
+ _ => None,
102
+ }
103
+ }
104
+
105
+ /// The number of parameters, including a rest parameter.
106
+ pub(super) fn parameter_count(parameters: &FormalParameters<'_>) -> usize {
107
+ parameters.items.len() + usize::from(parameters.rest.is_some())
108
+ }
109
+
110
+ /// The constructor's statements.
111
+ pub(super) fn constructor<'a>(class: &'a Class<'a>) -> Result<&'a [Statement<'a>]> {
88
112
  class
113
+ .body
89
114
  .body
90
115
  .iter()
91
- .find_map(|member| member.as_constructor()?.body.as_ref())
116
+ .find_map(|element| match element {
117
+ ClassElement::MethodDefinition(method)
118
+ if method.kind == MethodDefinitionKind::Constructor =>
119
+ {
120
+ Some(&method.value.body.as_deref()?.statements[..])
121
+ }
122
+ _ => None,
123
+ })
92
124
  .context("the VM class has no constructor")
93
125
  }
94
126
 
@@ -120,7 +152,7 @@ pub(super) struct RunMethod<'ast> {
120
152
  /// Dispatch function declared beside the class and called by `run` with the machine. Some builds
121
153
  /// move both loops out of `run`; both dispatch the same handlers.
122
154
  pub(crate) struct DispatchLoop<'ast> {
123
- pub function: &'ast Function,
155
+ pub function: &'ast Function<'ast>,
124
156
  /// Argument values passed by `run`, in parameter order.
125
157
  pub arguments: Vec<Argument>,
126
158
  }
@@ -136,65 +168,72 @@ pub(crate) enum Argument {
136
168
 
137
169
  impl DispatchLoop<'_> {
138
170
  /// The parameter receiving the machine.
139
- fn machine(&self) -> Option<&Atom> {
171
+ fn machine(&self) -> Option<SymbolId> {
140
172
  let position = self
141
173
  .arguments
142
174
  .iter()
143
175
  .position(|argument| *argument == Argument::Machine)?;
144
- Some(&self.function.params.get(position)?.pat.as_ident()?.sym)
176
+ Some(parameter(&self.function.params, position)?.symbol_id())
145
177
  }
146
178
  }
147
179
 
180
+ /// The locals of `run` and what they hold.
181
+ struct Locals<'a> {
182
+ script: Script<'a>,
183
+ sources: HashMap<Binding<'a>, Source>,
184
+ }
185
+
148
186
  /// Tracks assignments in `run`, including copies of register fields and indices, program counter
149
187
  /// and key setup, storing the third argument in the cells register, reading the program register,
150
188
  /// and calling dispatch loops. An unsupported assignment clears the known value of its local.
151
189
  pub(super) fn run_method<'a>(
152
- functions: &HashMap<Atom, &'a Function>,
153
- run: &Function,
190
+ script: Script<'a>,
191
+ functions: &HashMap<SymbolId, &'a Function<'a>>,
192
+ run: &'a Function<'a>,
154
193
  ) -> Result<RunMethod<'a>> {
155
- let body = run.body.as_ref().context("the run method has no body")?;
156
- let mut locals: HashMap<Atom, Source> = run
157
- .params
158
- .iter()
159
- .enumerate()
160
- .filter_map(|(index, parameter)| {
161
- Some((
162
- parameter.pat.as_ident()?.sym.clone(),
163
- Source::Parameter(index),
164
- ))
194
+ let body = run.body.as_deref().context("the run method has no body")?;
195
+ let sources = (0..run.params.items.len())
196
+ .filter_map(|index| {
197
+ let name = parameter(&run.params, index)?;
198
+ Some((Binding::Symbol(name.symbol_id()), Source::Parameter(index)))
165
199
  })
166
200
  .collect();
201
+ let mut locals = Locals { script, sources };
167
202
  let mut cells = None;
168
203
  let mut loaded = Vec::new();
169
- for statement in &body.stmts {
170
- let Stmt::Expr(statement) = statement else {
204
+ for statement in &body.statements {
205
+ let Statement::ExpressionStatement(statement) = statement else {
171
206
  continue;
172
207
  };
173
- let expressions: Vec<&Expr> = match &*statement.expr {
174
- Expr::Seq(sequence) => sequence.exprs.iter().map(|expr| &**expr).collect(),
175
- expr => vec![expr],
208
+ let expressions: Vec<&Expression<'a>> = match &statement.expression {
209
+ Expression::SequenceExpression(sequence) => sequence.expressions.iter().collect(),
210
+ expression => vec![expression],
176
211
  };
177
- for expr in expressions {
178
- if let Some((Source::Field(registers), arguments)) = method_call(&locals, expr, "write")
212
+ for expression in expressions {
213
+ if let Some((Source::Field(registers), arguments)) =
214
+ locals.method_call(expression, "write")
179
215
  && let [Some(Source::Field(index)), Some(Source::Parameter(2))] = &arguments[..]
180
216
  {
181
217
  cells = Some((registers, index.clone()));
182
218
  continue;
183
219
  }
184
- let Expr::Assign(assign) = expr else { continue };
185
- let AssignTarget::Simple(SimpleAssignTarget::Ident(name)) = &assign.left else {
220
+ let Expression::AssignmentExpression(assignment) = expression else {
221
+ continue;
222
+ };
223
+ let AssignmentTarget::AssignmentTargetIdentifier(name) = &assignment.left else {
186
224
  continue;
187
225
  };
188
- let value = match assign.op {
189
- AssignOp::Assign => source(&locals, &assign.right),
226
+ let value = match assignment.operator {
227
+ AssignmentOperator::Assign => locals.source(&assignment.right),
190
228
  _ => None,
191
229
  };
192
230
  if let Some(Source::Register { registers, index }) = &value {
193
231
  loaded.push((registers.clone(), index.clone()));
194
232
  }
233
+ let binding = script.binding(name);
195
234
  match value {
196
- Some(value) => locals.insert(name.sym.clone(), value),
197
- None => locals.remove(&name.sym),
235
+ Some(value) => locals.sources.insert(binding, value),
236
+ None => locals.sources.remove(&binding),
198
237
  };
199
238
  }
200
239
  }
@@ -211,19 +250,20 @@ pub(super) fn run_method<'a>(
211
250
  };
212
251
  let program = program.clone();
213
252
  let mut calls = DispatchCall {
253
+ script,
214
254
  functions,
215
255
  found: None,
216
256
  };
217
- body.visit_with(&mut calls);
257
+ calls.visit_function_body(body);
218
258
  let (function, call) = calls
219
259
  .found
220
260
  .context("the run method calls no dispatch loop with the machine")?;
221
261
  let arguments = call
222
- .args
262
+ .arguments
223
263
  .iter()
224
- .map(|argument| match &*argument.expr {
225
- Expr::This(_) => Argument::Machine,
226
- Expr::Ident(name) => match locals.get(&name.sym) {
264
+ .map(|argument| match ast::argument_expression(argument) {
265
+ Expression::ThisExpression(_) => Argument::Machine,
266
+ Expression::Identifier(name) => match locals.sources.get(&script.binding(name)) {
227
267
  Some(Source::Field(field)) if *field == registers => Argument::Registers,
228
268
  Some(Source::Register { index, .. }) if *index == program => Argument::Program,
229
269
  _ => Argument::Other,
@@ -244,122 +284,149 @@ pub(super) fn run_method<'a>(
244
284
 
245
285
  /// Finds the first call in `run` whose first argument is the machine and whose target contains a
246
286
  /// dispatch switch.
247
- struct DispatchCall<'functions, 'ast> {
248
- functions: &'functions HashMap<Atom, &'ast Function>,
249
- found: Option<(&'ast Function, CallExpr)>,
287
+ struct DispatchCall<'functions, 'a> {
288
+ script: Script<'a>,
289
+ functions: &'functions HashMap<SymbolId, &'a Function<'a>>,
290
+ found: Option<(&'a Function<'a>, &'a CallExpression<'a>)>,
250
291
  }
251
292
 
252
- impl Visit for DispatchCall<'_, '_> {
253
- fn visit_call_expr(&mut self, call: &CallExpr) {
293
+ impl<'a> Visit<'a> for DispatchCall<'_, 'a> {
294
+ fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
254
295
  if self.found.is_none()
255
- && call
256
- .args
257
- .first()
258
- .is_some_and(|argument| argument.expr.is_this())
259
- && let Some(callee) = call.callee.as_expr().and_then(|callee| callee.as_ident())
260
- && let Some(&function) = self.functions.get(&callee.sym)
296
+ && call.arguments.first().is_some_and(|first| {
297
+ matches!(
298
+ ast::argument_expression(first),
299
+ Expression::ThisExpression(_)
300
+ )
301
+ })
302
+ && let Expression::Identifier(callee) = &call.callee
303
+ && let Some(symbol) = self.script.symbol(callee)
304
+ && let Some(&function) = self.functions.get(&symbol)
261
305
  && first_switch_in(function).is_some()
262
306
  {
263
- self.found = Some((function, call.clone()));
307
+ self.found = Some((
308
+ function,
309
+ self.script.lend(call, AstKind::as_call_expression),
310
+ ));
264
311
  }
265
- call.visit_children_with(self);
312
+ walk::walk_call_expression(self, call);
266
313
  }
267
314
  }
268
315
 
269
- /// Resolves `<object>.<name>(<arguments>)`, including the values of the object and arguments.
270
- fn method_call(
271
- locals: &HashMap<Atom, Source>,
272
- expr: &Expr,
273
- name: &str,
274
- ) -> Option<(Source, Vec<Option<Source>>)> {
275
- let (object, arguments) = ast::method_call(expr, name)?;
276
- let arguments = arguments
277
- .iter()
278
- .map(|argument| source(locals, &argument.expr))
279
- .collect();
280
- Some((source(locals, object)?, arguments))
281
- }
316
+ impl<'a> Locals<'a> {
317
+ /// Resolves `<object>.<name>(<arguments>)`, including the values of the object and
318
+ /// arguments.
319
+ fn method_call(
320
+ &self,
321
+ expression: &Expression<'a>,
322
+ name: &str,
323
+ ) -> Option<(Source, Vec<Option<Source>>)> {
324
+ let (object, arguments) = ast::method_call(expression, name)?;
325
+ let arguments = arguments
326
+ .iter()
327
+ .map(|argument| self.source(ast::argument_expression(argument)))
328
+ .collect();
329
+ Some((self.source(object)?, arguments))
330
+ }
282
331
 
283
- fn source(locals: &HashMap<Atom, Source>, expr: &Expr) -> Option<Source> {
284
- match expr {
285
- Expr::Ident(name) => locals.get(&name.sym).cloned(),
286
- Expr::Paren(paren) => source(locals, &paren.expr),
287
- Expr::Member(member) if member.obj.is_this() => {
288
- Some(Source::Field(ast::member_str(&member.prop)?.to_owned()))
289
- }
290
- Expr::Call(_) => match method_call(locals, expr, "read")? {
291
- (Source::Field(registers), arguments) => match &arguments[..] {
292
- [Some(Source::Field(index))] => Some(Source::Register {
293
- registers,
294
- index: index.clone(),
295
- }),
332
+ fn source(&self, expression: &Expression<'a>) -> Option<Source> {
333
+ match expression {
334
+ Expression::Identifier(name) => self.sources.get(&self.script.binding(name)).cloned(),
335
+ Expression::ParenthesizedExpression(paren) => self.source(&paren.expression),
336
+ Expression::CallExpression(_) => match self.method_call(expression, "read")? {
337
+ (Source::Field(registers), arguments) => match &arguments[..] {
338
+ [Some(Source::Field(index))] => Some(Source::Register {
339
+ registers,
340
+ index: index.clone(),
341
+ }),
342
+ _ => None,
343
+ },
296
344
  _ => None,
297
345
  },
298
- _ => None,
299
- },
346
+ expression => Some(Source::Field(this_field(expression)?.to_owned())),
347
+ }
348
+ }
349
+ }
350
+
351
+ /// The field `this.<field>` reads.
352
+ pub(super) fn this_field<'a>(expression: &Expression<'a>) -> Option<&'a str> {
353
+ let member = expression.as_member_expression()?;
354
+ match member.object() {
355
+ Expression::ThisExpression(_) => ast::member_str(member),
300
356
  _ => None,
301
357
  }
302
358
  }
303
359
 
304
360
  /// Finds the string decryption function called by the register reader as
305
361
  /// `decrypt(this.<values>[index])`.
306
- pub(super) fn record_decoder(body: &BlockStmt) -> Option<Atom> {
362
+ pub(super) fn record_decoder<'a>(
363
+ script: Script<'a>,
364
+ body: &'a FunctionBody<'a>,
365
+ ) -> Option<SymbolId> {
307
366
  /// Matches `<decoder>(this.<values>[<index>])`.
308
- struct Decoders {
309
- index: Atom,
310
- found: Vec<Atom>,
367
+ struct Decoders<'a> {
368
+ script: Script<'a>,
369
+ index: SymbolId,
370
+ found: Vec<Binding<'a>>,
311
371
  }
312
372
 
313
- impl Visit for Decoders {
314
- fn visit_call_expr(&mut self, call: &CallExpr) {
315
- if let Some(callee) = call.callee.as_expr().and_then(|callee| callee.as_ident())
316
- && let [argument] = &call.args[..]
317
- && let Some(member) = argument.expr.as_member()
373
+ impl<'a> Visit<'a> for Decoders<'a> {
374
+ fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
375
+ if let Expression::Identifier(callee) = &call.callee
376
+ && let [argument] = &call.arguments[..]
377
+ && let Some(member) = ast::argument_expression(argument).as_member_expression()
318
378
  && member
319
- .obj
320
- .as_member()
321
- .is_some_and(|values| values.obj.is_this())
322
- && member
323
- .prop
324
- .as_computed()
325
- .and_then(|index| index.expr.as_ident())
326
- .is_some_and(|name| name.sym == self.index)
379
+ .object()
380
+ .as_member_expression()
381
+ .is_some_and(|values| matches!(values.object(), Expression::ThisExpression(_)))
382
+ && let MemberExpression::ComputedMemberExpression(member) = member
383
+ && self.script.refers_to(&member.expression, self.index)
327
384
  {
328
- self.found.push(callee.sym.clone());
385
+ self.found.push(self.script.binding(callee));
329
386
  }
330
- call.visit_children_with(self);
387
+ walk::walk_call_expression(self, call);
331
388
  }
332
389
  }
333
390
 
334
- let read = body.stmts.iter().find_map(|statement| match statement {
335
- Stmt::Decl(Decl::Class(declaration)) if method(&declaration.class, "write").is_some() => {
336
- method(&declaration.class, "read")
337
- }
338
- _ => None,
339
- })?;
391
+ let read = body
392
+ .statements
393
+ .iter()
394
+ .find_map(|statement| match statement {
395
+ Statement::ClassDeclaration(class) if method(class, "write").is_some() => {
396
+ method(class, "read")
397
+ }
398
+ _ => None,
399
+ })?;
340
400
  let mut decoders = Decoders {
341
- index: read.params.first()?.pat.as_ident()?.sym.clone(),
401
+ script,
402
+ index: parameter(&read.params, 0)?.symbol_id(),
342
403
  found: Vec::new(),
343
404
  };
344
- read.visit_with(&mut decoders);
345
- let [decoder]: [Atom; 1] = decoders.found.try_into().ok()?;
405
+ decoders.visit_function(read, ScopeFlags::Function);
406
+ let [Binding::Symbol(decoder)] = decoders.found[..] else {
407
+ return None;
408
+ };
346
409
  Some(decoder)
347
410
  }
348
411
 
349
412
  /// The first class declaration with a `run` method.
350
- fn machine_class(body: &BlockStmt) -> Option<&Class> {
351
- body.stmts.iter().find_map(|statement| match statement {
352
- Stmt::Decl(Decl::Class(declaration)) if method(&declaration.class, "run").is_some() => {
353
- Some(&*declaration.class)
354
- }
355
- _ => None,
356
- })
413
+ fn machine_class<'a>(body: &'a FunctionBody<'a>) -> Option<&'a Class<'a>> {
414
+ body.statements
415
+ .iter()
416
+ .find_map(|statement| match statement {
417
+ Statement::ClassDeclaration(class) if method(class, "run").is_some() => Some(&**class),
418
+ _ => None,
419
+ })
357
420
  }
358
421
 
359
- pub(super) fn method<'a>(class: &'a Class, name: &str) -> Option<&'a Function> {
360
- class.body.iter().find_map(|member| match member {
361
- ClassMember::Method(method) if ast::static_key_str(&method.key) == Some(name) => {
362
- Some(&*method.function)
422
+ /// The method, getter, or setter named `name`, excluding the constructor.
423
+ pub(super) fn method<'a>(class: &'a Class<'a>, name: &str) -> Option<&'a Function<'a>> {
424
+ class.body.body.iter().find_map(|element| match element {
425
+ ClassElement::MethodDefinition(method)
426
+ if method.kind != MethodDefinitionKind::Constructor
427
+ && ast::static_key_str(&method.key, method.computed) == Some(name) =>
428
+ {
429
+ Some(&*method.value)
363
430
  }
364
431
  _ => None,
365
432
  })
@@ -367,40 +434,46 @@ pub(super) fn method<'a>(class: &'a Class, name: &str) -> Option<&'a Function> {
367
434
 
368
435
  /// Extracts opcode and handler pairs from `case <opcode>: <handler>(<machine>); break;`.
369
436
  pub(super) fn handlers<'a>(
370
- functions: &HashMap<Atom, &'a Function>,
437
+ script: Script<'a>,
438
+ functions: &HashMap<SymbolId, &'a Function<'a>>,
371
439
  dispatch: &DispatchLoop<'a>,
372
- ) -> Result<HashMap<u8, &'a Function>> {
440
+ ) -> Result<HashMap<u8, &'a Function<'a>>> {
373
441
  let switch = first_switch_in(dispatch.function).context("the dispatch loop has no switch")?;
374
442
  let machine = dispatch.machine();
375
- let is_machine = |argument: &ExprOrSpread| {
376
- argument.spread.is_none()
377
- && argument
378
- .expr
379
- .as_ident()
380
- .is_some_and(|name| Some(&name.sym) == machine)
443
+ let is_machine = |argument: &CallArgument<'_>| {
444
+ argument.as_expression().is_some_and(|argument| {
445
+ machine.is_some_and(|machine| script.refers_to(argument, machine))
446
+ })
381
447
  };
382
448
  let mut handlers = HashMap::default();
383
449
  for case in &switch.cases {
384
450
  let Some(test) = &case.test else { continue };
385
- let Expr::Lit(Lit::Num(opcode)) = &**test else {
451
+ let Expression::NumericLiteral(opcode) = test else {
386
452
  bail!("a dispatch case is not a number");
387
453
  };
388
454
  let opcode = convert::byte(opcode.value).context("a dispatch case is not an opcode")?;
389
455
  let call = case
390
- .cons
456
+ .consequent
391
457
  .iter()
392
- .find_map(|statement| statement.as_expr()?.expr.as_call())
458
+ .find_map(|statement| match statement {
459
+ Statement::ExpressionStatement(statement) => match &statement.expression {
460
+ Expression::CallExpression(call) => Some(call),
461
+ _ => None,
462
+ },
463
+ _ => None,
464
+ })
393
465
  .with_context(|| format!("dispatch case {opcode} calls no handler"))?;
394
- let Some(name) = call.callee.as_expr().and_then(|callee| callee.as_ident()) else {
466
+ let Expression::Identifier(name) = &call.callee else {
395
467
  bail!("dispatch case {opcode} calls no named handler");
396
468
  };
397
- let function = functions
398
- .get(&name.sym)
399
- .with_context(|| format!("no handler function {}", name.sym))?;
469
+ let function = script
470
+ .symbol(name)
471
+ .and_then(|symbol| functions.get(&symbol))
472
+ .with_context(|| format!("no handler function {}", name.name))?;
400
473
  ensure!(
401
- matches!(&call.args[..], [argument] if is_machine(argument)),
474
+ matches!(&call.arguments[..], [argument] if is_machine(argument)),
402
475
  "dispatch case {opcode} does not pass {} only the machine",
403
- name.sym
476
+ name.name
404
477
  );
405
478
  let previous = handlers.insert(opcode, *function);
406
479
  ensure!(previous.is_none(), "opcode {opcode} has two dispatch cases");
@@ -409,30 +482,41 @@ pub(super) fn handlers<'a>(
409
482
  }
410
483
 
411
484
  /// Finds the first dispatch switch in the body of `function`.
412
- fn first_switch_in(function: &Function) -> Option<&SwitchStmt> {
413
- function.body.as_ref()?.stmts.iter().find_map(first_switch)
485
+ fn first_switch_in<'a>(function: &'a Function<'a>) -> Option<&'a SwitchStatement<'a>> {
486
+ function
487
+ .body
488
+ .as_deref()?
489
+ .statements
490
+ .iter()
491
+ .find_map(first_switch)
414
492
  }
415
493
 
416
494
  /// Finds the first dispatch `switch`; both dispatch loops use the same form.
417
- fn first_switch(statement: &Stmt) -> Option<&SwitchStmt> {
495
+ fn first_switch<'a>(statement: &'a Statement<'a>) -> Option<&'a SwitchStatement<'a>> {
418
496
  match statement {
419
- Stmt::Switch(switch) => Some(switch),
420
- Stmt::Block(block) => block.stmts.iter().find_map(first_switch),
421
- Stmt::While(looping) => first_switch(&looping.body),
422
- Stmt::If(branch) => {
423
- first_switch(&branch.cons).or_else(|| first_switch(branch.alt.as_deref()?))
497
+ Statement::SwitchStatement(switch) => Some(switch),
498
+ Statement::BlockStatement(block) => block.body.iter().find_map(first_switch),
499
+ Statement::WhileStatement(looping) => first_switch(&looping.body),
500
+ Statement::IfStatement(branch) => {
501
+ first_switch(&branch.consequent).or_else(|| first_switch(branch.alternate.as_ref()?))
424
502
  }
425
- Stmt::Try(attempt) => attempt.block.stmts.iter().find_map(first_switch),
503
+ Statement::TryStatement(attempt) => attempt.block.body.iter().find_map(first_switch),
426
504
  _ => None,
427
505
  }
428
506
  }
429
507
 
430
508
  /// Where the program runner starts a program (see [`Runner`]).
431
- pub(super) fn entry(body: &BlockStmt) -> Result<Position> {
509
+ pub(super) fn entry(body: &FunctionBody<'_>) -> Result<Position> {
432
510
  let runner = body
433
- .stmts
511
+ .statements
434
512
  .iter()
435
- .find_map(|statement| Runner::installed_by(statement.as_expr()?.expr.as_assign()?))
513
+ .find_map(|statement| match statement {
514
+ Statement::ExpressionStatement(statement) => match &statement.expression {
515
+ Expression::AssignmentExpression(assignment) => Runner::installed_by(assignment),
516
+ _ => None,
517
+ },
518
+ _ => None,
519
+ })
436
520
  .context("no program runner in the VM's scope")?;
437
521
  let pc = convert::position(runner.pc).context("the runner starts at no program position")?;
438
522
  let key = convert::byte(runner.key).context("the runner starts with no dispatch key")?;
@@ -451,29 +535,39 @@ struct Runner<'ast> {
451
535
  }
452
536
 
453
537
  impl<'ast> Runner<'ast> {
454
- fn installed_by(assign: &'ast AssignExpr) -> Option<Self> {
455
- let AssignTarget::Simple(SimpleAssignTarget::Member(target)) = &assign.left else {
538
+ fn installed_by(assignment: &AssignmentExpression<'ast>) -> Option<Self> {
539
+ let target = assignment.left.as_member_expression()?;
540
+ if matches!(target.object(), Expression::Super(_)) {
541
+ return None;
542
+ }
543
+ let Expression::FunctionExpression(function) = &assignment.right else {
456
544
  return None;
457
545
  };
458
- let body = assign.right.as_fn_expr()?.function.body.as_ref()?;
459
- let [
460
- Stmt::Return(ReturnStmt {
461
- arg: Some(call), ..
462
- }),
463
- ] = after_bare_declarations(&body.stmts)
546
+ let body = function.body.as_deref()?;
547
+ if !body.directives.is_empty() {
548
+ return None;
549
+ }
550
+ let [Statement::ReturnStatement(returned)] = after_bare_declarations(&body.statements)
464
551
  else {
465
552
  return None;
466
553
  };
467
- let (machine, [pc, key, ..]) = ast::method_call(call, "run")? else {
554
+ let (machine, [pc, key, ..]) = ast::method_call(returned.argument.as_ref()?, "run")? else {
468
555
  return None;
469
556
  };
470
- let (Expr::New(_), Expr::Lit(Lit::Num(pc)), Expr::Lit(Lit::Num(key))) =
471
- (machine, &*pc.expr, &*key.expr)
557
+ let (
558
+ Expression::NewExpression(_),
559
+ Expression::NumericLiteral(pc),
560
+ Expression::NumericLiteral(key),
561
+ ) = (
562
+ machine,
563
+ ast::argument_expression(pc),
564
+ ast::argument_expression(key),
565
+ )
472
566
  else {
473
567
  return None;
474
568
  };
475
569
  Some(Self {
476
- name: ast::member_str(&target.prop)?,
570
+ name: ast::member_str(target)?,
477
571
  pc: pc.value,
478
572
  key: key.value,
479
573
  })
@@ -481,42 +575,35 @@ impl<'ast> Runner<'ast> {
481
575
  }
482
576
 
483
577
  /// Returns the installed program runner's name if exactly one exists (see [`Runner`]).
484
- pub(crate) fn runner_name(script: &Script) -> Option<String> {
485
- #[derive(Default)]
486
- struct Names(Vec<String>);
487
-
488
- impl Visit for Names {
489
- fn visit_assign_expr(&mut self, assign: &AssignExpr) {
490
- if let Some(runner) = Runner::installed_by(assign) {
491
- self.0.push(runner.name.to_owned());
492
- }
493
- assign.visit_children_with(self);
494
- }
495
- }
496
-
497
- let mut names = Names::default();
498
- script.visit_with(&mut names);
499
- let [name]: [String; 1] = names.0.try_into().ok()?;
500
- Some(name)
578
+ pub(crate) fn runner_name(script: Script<'_>) -> Option<String> {
579
+ let runners = script.nodes.iter().filter_map(|node| match node.kind() {
580
+ AstKind::AssignmentExpression(assignment) => Runner::installed_by(assignment),
581
+ _ => None,
582
+ });
583
+ let runner = candidates::exactly_one(runners, "program runner").ok()?;
584
+ Some(runner.name.to_owned())
501
585
  }
502
586
 
503
587
  /// Whether `call` calls the runner `name` installs, as `name(...)` or `<global>.name(...)`.
504
- pub(crate) fn calls_runner(call: &CallExpr, name: &str) -> bool {
505
- match call.callee.as_expr().map(|callee| callee.unwrap_parens()) {
506
- Some(Expr::Ident(callee)) => callee.sym == name,
507
- Some(Expr::Member(member)) => ast::member_str(&member.prop) == Some(name),
508
- _ => false,
588
+ pub(crate) fn calls_runner(call: &CallExpression<'_>, name: &str) -> bool {
589
+ match call.callee.without_parentheses() {
590
+ Expression::Identifier(callee) => callee.name == name,
591
+ callee => callee.as_member_expression().is_some_and(|member| {
592
+ !matches!(member.object(), Expression::Super(_))
593
+ && ast::member_str(member) == Some(name)
594
+ }),
509
595
  }
510
596
  }
511
597
 
512
598
  /// Skips leading `var x;` declarations. Deobfuscation removes helper objects used to calculate
513
599
  /// `run` arguments but may leave their declarations.
514
- fn after_bare_declarations(statements: &[Stmt]) -> &[Stmt] {
600
+ fn after_bare_declarations<'b, 'a>(statements: &'b [Statement<'a>]) -> &'b [Statement<'a>] {
515
601
  let start = statements
516
602
  .iter()
517
603
  .position(|statement| {
518
- !matches!(statement, Stmt::Decl(Decl::Var(declaration))
519
- if declaration.decls.iter().all(|declarator| declarator.init.is_none()))
604
+ !matches!(statement, Statement::VariableDeclaration(declaration)
605
+ if !declaration.kind.is_using()
606
+ && declaration.declarations.iter().all(|declarator| declarator.init.is_none()))
520
607
  })
521
608
  .unwrap_or(statements.len());
522
609
  &statements[start..]
@@ -525,13 +612,15 @@ fn after_bare_declarations(statements: &[Stmt]) -> &[Stmt] {
525
612
  #[cfg(test)]
526
613
  mod tests {
527
614
  use super::*;
615
+ use crate::js::ast::ParsedScript;
528
616
 
529
617
  fn entry_of(source: &str) -> Result<Position> {
530
- let parsed = ast::parse_javascript("t", source).unwrap();
531
- let Some(Stmt::Decl(Decl::Fn(function))) = parsed.script.body.first() else {
618
+ let parsed = ParsedScript::parse("t", source).unwrap();
619
+ let script = parsed.script();
620
+ let Some(Statement::FunctionDeclaration(function)) = script.program.body.first() else {
532
621
  panic!("the test source declares no function");
533
622
  };
534
- entry(function.function.body.as_ref().unwrap())
623
+ entry(function.body.as_deref().unwrap())
535
624
  }
536
625
 
537
626
  #[test]
@@ -551,20 +640,28 @@ mod tests {
551
640
 
552
641
  #[test]
553
642
  fn names_the_runner_its_callers_call() {
554
- let parsed = ast::parse_javascript(
643
+ let parsed = ParsedScript::parse(
555
644
  "t",
556
645
  "O.vlJM8 = function(p) { return new M(p).run(0, 238, []); }; \
557
646
  O.other = function(p) { return M(p).run(0, 238, []); }; O.vlJM8('a'); vlJM8('b');",
558
647
  )
559
648
  .unwrap();
560
- let name = runner_name(&parsed.script).unwrap();
649
+ let script = parsed.script();
650
+ let name = runner_name(script).unwrap();
561
651
  assert_eq!(name, "vlJM8");
562
- let calls: Vec<&CallExpr> = parsed
563
- .script
652
+ let calls: Vec<&CallExpression<'_>> = script
653
+ .program
564
654
  .body
565
655
  .iter()
566
- .filter_map(|statement| statement.as_expr()?.expr.as_call())
656
+ .filter_map(|statement| match statement {
657
+ Statement::ExpressionStatement(statement) => match &statement.expression {
658
+ Expression::CallExpression(call) => Some(&**call),
659
+ _ => None,
660
+ },
661
+ _ => None,
662
+ })
567
663
  .collect();
664
+ assert_eq!(calls.len(), 2);
568
665
  assert!(calls.iter().all(|call| calls_runner(call, &name)));
569
666
  }
570
667
  }