swf2js 0.1.2 → 0.4.0

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 (416) hide show
  1. package/README.md +81 -14
  2. package/package.json +11 -7
  3. package/studio/actionscript-roundtrip.test.js +54 -0
  4. package/studio/actionscript-scripts.test.js +169 -0
  5. package/studio/animated-image.test.js +137 -0
  6. package/studio/arithmetic.test.js +16 -0
  7. package/studio/as3-import.test.js +110 -0
  8. package/studio/audio-info.test.js +44 -0
  9. package/studio/components.test.js +152 -0
  10. package/studio/document-editing.test.js +92 -0
  11. package/studio/examples/01-space-mission.json +1628 -0
  12. package/studio/examples/02-clockwork-vault.json +1079 -0
  13. package/studio/examples/03-neon-synth.json +1364 -0
  14. package/studio/examples/04-kinetic-poster.json +923 -0
  15. package/studio/examples/05-signal-relay.json +1131 -0
  16. package/studio/examples/06-calculator.json +564 -0
  17. package/studio/frame-editing.test.js +129 -0
  18. package/studio/frame-events.test.js +117 -0
  19. package/studio/groups.test.js +88 -0
  20. package/studio/index.html +962 -0
  21. package/studio/interaction-triggers.test.js +37 -0
  22. package/studio/linked-actions.test.js +48 -0
  23. package/studio/lottie.test.js +208 -0
  24. package/studio/masks.test.js +43 -0
  25. package/studio/media-assets.test.js +62 -0
  26. package/studio/paint-tools.test.js +60 -0
  27. package/studio/playback.test.js +17 -0
  28. package/studio/project-io.test.js +405 -0
  29. package/studio/project-preview.test.js +475 -0
  30. package/studio/scene-transition.test.js +32 -0
  31. package/studio/server/archive-companions.js +27 -0
  32. package/studio/server/as3-library.js +91 -0
  33. package/studio/server/assets.js +162 -0
  34. package/studio/server/audio-info.js +82 -0
  35. package/studio/server/font-files.js +332 -0
  36. package/studio/server/http.js +135 -0
  37. package/studio/server/linked-actions.js +93 -0
  38. package/studio/server/png-decode.js +1 -0
  39. package/studio/server/project-movie.js +1164 -0
  40. package/studio/server/project-preview.js +152 -0
  41. package/studio/server/projects.js +370 -0
  42. package/studio/server/report.js +29 -0
  43. package/studio/server/routes.js +93 -0
  44. package/studio/server/swf-authoring.js +90 -0
  45. package/studio/server/swf-control-runtime.as +513 -0
  46. package/studio/server/swf-controls.js +119 -0
  47. package/studio/server/swf-export.js +293 -0
  48. package/studio/server/swf-import.js +1675 -0
  49. package/studio/server/swf-morphs.js +64 -0
  50. package/studio/server/swf-routes.js +42 -0
  51. package/studio/server/swf-streams.js +80 -0
  52. package/studio/server/swf-transition-runtime.as +52 -0
  53. package/studio/server/tween-recovery.js +106 -0
  54. package/studio/server-api.test.js +283 -0
  55. package/studio/server.js +320 -0
  56. package/studio/src/animated-image.js +423 -0
  57. package/studio/src/appearance-inspector.js +63 -0
  58. package/studio/src/arithmetic.js +50 -0
  59. package/studio/src/authored-controls.js +42 -0
  60. package/studio/src/busy.js +41 -0
  61. package/studio/src/canvas.js +430 -0
  62. package/studio/src/clipper-browser.js +2 -0
  63. package/studio/src/color-transform.js +38 -0
  64. package/studio/src/component-inspector.js +126 -0
  65. package/studio/src/components.js +268 -0
  66. package/studio/src/display-frame.js +262 -0
  67. package/studio/src/document-editing.js +69 -0
  68. package/studio/src/event-editor.js +150 -0
  69. package/studio/src/frame-editing.js +150 -0
  70. package/studio/src/frame-events.js +128 -0
  71. package/studio/src/frame-image.js +28 -0
  72. package/studio/src/groups.js +125 -0
  73. package/studio/src/handler-editor.js +122 -0
  74. package/studio/src/history.js +83 -0
  75. package/studio/src/imported-paths.js +99 -0
  76. package/studio/src/index.js +3582 -0
  77. package/studio/src/interaction-triggers.js +42 -0
  78. package/studio/src/json-patch.js +77 -0
  79. package/studio/src/layer-icons.js +25 -0
  80. package/studio/src/lottie-export.js +948 -0
  81. package/studio/src/lottie-import.js +1138 -0
  82. package/studio/src/masks.js +69 -0
  83. package/studio/src/media-assets.js +188 -0
  84. package/studio/src/media-library.js +193 -0
  85. package/studio/src/model.js +431 -0
  86. package/studio/src/numeric-fields.js +46 -0
  87. package/studio/src/object-list.js +57 -0
  88. package/studio/src/paint-tools.js +76 -0
  89. package/studio/src/placement-effects.js +74 -0
  90. package/studio/src/playback.js +10 -0
  91. package/studio/src/preview-audio.js +64 -0
  92. package/studio/src/preview-interactions.js +106 -0
  93. package/studio/src/preview-recorder.js +335 -0
  94. package/studio/src/preview-surface.js +338 -0
  95. package/studio/src/project-io.js +905 -0
  96. package/studio/src/project-session.js +375 -0
  97. package/studio/src/projects-dialog.js +319 -0
  98. package/studio/src/scene-transition.js +129 -0
  99. package/studio/src/script-editor.js +175 -0
  100. package/studio/src/script-references.js +74 -0
  101. package/studio/src/scripted-controls.js +146 -0
  102. package/studio/src/scripts.js +185 -0
  103. package/studio/src/stage-guides.js +101 -0
  104. package/studio/src/svg-animation.js +416 -0
  105. package/studio/src/svg-context.js +522 -0
  106. package/studio/src/svg-frame.js +413 -0
  107. package/studio/src/svg-import.js +1208 -0
  108. package/studio/src/swf-recording.js +104 -0
  109. package/studio/src/symbol-library.js +39 -0
  110. package/studio/src/symbols.js +62 -0
  111. package/studio/src/text-fields.js +58 -0
  112. package/studio/src/theme.js +43 -0
  113. package/studio/src/timeline.js +321 -0
  114. package/studio/src/vector-cut.js +103 -0
  115. package/studio/src/vector-geometry.js +254 -0
  116. package/studio/src/vector-style.js +146 -0
  117. package/studio/src/video-encode.js +84 -0
  118. package/studio/src/video-export.js +331 -0
  119. package/studio/src/video-mux.js +339 -0
  120. package/studio/src/video-playback.js +281 -0
  121. package/studio/src/workspace.js +344 -0
  122. package/studio/stroke-style.test.js +119 -0
  123. package/studio/styles.css +1547 -0
  124. package/studio/svg-export.test.js +162 -0
  125. package/studio/svg-import.test.js +318 -0
  126. package/studio/swf-authoring.test.js +140 -0
  127. package/studio/swf-export.test.js +324 -0
  128. package/studio/swf-import.test.js +489 -0
  129. package/studio/symbols.test.js +68 -0
  130. package/studio/tests/accessibility-interactions.mjs +138 -0
  131. package/studio/tests/appearance-interactions.mjs +103 -0
  132. package/studio/tests/control-interactions.mjs +60 -0
  133. package/studio/tests/event-interactions.mjs +117 -0
  134. package/studio/tests/external-resources.mjs +174 -0
  135. package/studio/tests/frame-image.mjs +71 -0
  136. package/studio/tests/html-export.mjs +68 -0
  137. package/studio/tests/import-files.mjs +131 -0
  138. package/studio/tests/lottie.mjs +125 -0
  139. package/studio/tests/mask-interactions.mjs +148 -0
  140. package/studio/tests/media-interactions.mjs +109 -0
  141. package/studio/tests/paint-interactions.mjs +64 -0
  142. package/studio/tests/project-interactions.mjs +244 -0
  143. package/studio/tests/script-interactions.mjs +178 -0
  144. package/studio/tests/scripted-control-interactions.mjs +107 -0
  145. package/studio/tests/svg-export.mjs +149 -0
  146. package/studio/tests/text-field-interactions.mjs +64 -0
  147. package/studio/tests/theme-interactions.mjs +53 -0
  148. package/studio/tests/timeline-browser.mjs +507 -0
  149. package/studio/tests/transition-interactions.mjs +94 -0
  150. package/studio/tests/trigger-interactions.mjs +93 -0
  151. package/studio/tests/video-export.mjs +243 -0
  152. package/studio/tests/workspace-interactions.mjs +226 -0
  153. package/studio/tween-recovery.test.js +31 -0
  154. package/studio/vector-style.test.js +56 -0
  155. package/studio/video-export.test.js +326 -0
  156. package/studiospec/actionscript.md +88 -0
  157. package/studiospec/architecture.md +378 -0
  158. package/studiospec/controls.md +100 -0
  159. package/studiospec/file-support.md +268 -0
  160. package/studiospec/lottie.md +69 -0
  161. package/studiospec/requirements.md +135 -0
  162. package/studiospec/stroke-style.md +95 -0
  163. package/studiospec/svg-export.md +83 -0
  164. package/studiospec/svg-import.md +139 -0
  165. package/studiospec/swooflib-integration.md +115 -0
  166. package/studiospec/tasks.md +573 -0
  167. package/studiospec/video-export.md +127 -0
  168. package/swf2js/__tests__/actionscript.test.js +1609 -0
  169. package/swf2js/__tests__/adpcm-audio.test.js +43 -0
  170. package/swf2js/__tests__/as2-compiler.test.js +153 -0
  171. package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
  172. package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
  173. package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
  174. package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
  175. package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
  176. package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
  177. package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
  178. package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
  179. package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
  180. package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
  181. package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
  182. package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
  183. package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
  184. package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
  185. package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
  186. package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
  187. package/swf2js/__tests__/avm1-key-events.test.js +52 -0
  188. package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
  189. package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
  190. package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
  191. package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
  192. package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
  193. package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
  194. package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
  195. package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
  196. package/swf2js/__tests__/avm1-super.test.js +70 -0
  197. package/swf2js/__tests__/avm1-target-path.test.js +325 -0
  198. package/swf2js/__tests__/avm1-try.test.js +229 -0
  199. package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
  200. package/swf2js/__tests__/avm2-applytype.test.js +180 -0
  201. package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
  202. package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
  203. package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
  204. package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
  205. package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
  206. package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
  207. package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
  208. package/swf2js/__tests__/avm2-e4x.test.js +326 -0
  209. package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
  210. package/swf2js/__tests__/avm2-findprop.test.js +110 -0
  211. package/swf2js/__tests__/avm2-getlex.test.js +166 -0
  212. package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
  213. package/swf2js/__tests__/avm2-interface.test.js +95 -0
  214. package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
  215. package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
  216. package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
  217. package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
  218. package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
  219. package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
  220. package/swf2js/__tests__/avm2-protected.test.js +214 -0
  221. package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
  222. package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
  223. package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
  224. package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
  225. package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
  226. package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
  227. package/swf2js/__tests__/bevel-filter.test.js +116 -0
  228. package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
  229. package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
  230. package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
  231. package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
  232. package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
  233. package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
  234. package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
  235. package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
  236. package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
  237. package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
  238. package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
  239. package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
  240. package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
  241. package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
  242. package/swf2js/__tests__/blur-filter.test.js +48 -0
  243. package/swf2js/__tests__/bundle-emitter.test.js +394 -0
  244. package/swf2js/__tests__/button-actions.test.js +370 -0
  245. package/swf2js/__tests__/button-color-transform.test.js +48 -0
  246. package/swf2js/__tests__/button-decoder.test.js +106 -0
  247. package/swf2js/__tests__/button-hit-test.test.js +825 -0
  248. package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
  249. package/swf2js/__tests__/button-sound.test.js +105 -0
  250. package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
  251. package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
  252. package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
  253. package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
  254. package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
  255. package/swf2js/__tests__/companion-swf.test.js +638 -0
  256. package/swf2js/__tests__/context-menu.test.js +149 -0
  257. package/swf2js/__tests__/convolution-filter.test.js +74 -0
  258. package/swf2js/__tests__/definefont4.test.js +280 -0
  259. package/swf2js/__tests__/display-displacement.test.js +161 -0
  260. package/swf2js/__tests__/display-list.test.js +80 -0
  261. package/swf2js/__tests__/display-mask-render.test.js +656 -0
  262. package/swf2js/__tests__/displayobject-stage.test.js +320 -0
  263. package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
  264. package/swf2js/__tests__/embedded-swf.test.js +202 -0
  265. package/swf2js/__tests__/embedded-textfield.test.js +107 -0
  266. package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
  267. package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
  268. package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
  269. package/swf2js/__tests__/event-priority-order.test.js +125 -0
  270. package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
  271. package/swf2js/__tests__/event-will-trigger.test.js +43 -0
  272. package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
  273. package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
  274. package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
  275. package/swf2js/__tests__/font-encoder.test.js +95 -0
  276. package/swf2js/__tests__/font-outline-text.test.js +659 -0
  277. package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
  278. package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
  279. package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
  280. package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
  281. package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
  282. package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
  283. package/swf2js/__tests__/input-events.test.js +714 -0
  284. package/swf2js/__tests__/integration/corpus.test.js +41 -0
  285. package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
  286. package/swf2js/__tests__/loader-info.test.js +81 -0
  287. package/swf2js/__tests__/local-connection.test.js +122 -0
  288. package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
  289. package/swf2js/__tests__/morph-topology.test.js +267 -0
  290. package/swf2js/__tests__/movie-data-codec.test.js +128 -0
  291. package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
  292. package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
  293. package/swf2js/__tests__/path-stream.test.js +81 -0
  294. package/swf2js/__tests__/place-object-filters.test.js +88 -0
  295. package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
  296. package/swf2js/__tests__/place-object3-image.test.js +85 -0
  297. package/swf2js/__tests__/player-version.test.js +46 -0
  298. package/swf2js/__tests__/root-textfield.test.js +287 -0
  299. package/swf2js/__tests__/scaling-grid.test.js +183 -0
  300. package/swf2js/__tests__/shape-decoder.test.js +361 -0
  301. package/swf2js/__tests__/shape-line-style2.test.js +138 -0
  302. package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
  303. package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
  304. package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
  305. package/swf2js/__tests__/socket-offline.test.js +67 -0
  306. package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
  307. package/swf2js/__tests__/sound-envelope.test.js +110 -0
  308. package/swf2js/__tests__/sound-extract.test.js +168 -0
  309. package/swf2js/__tests__/sound-id3.test.js +283 -0
  310. package/swf2js/__tests__/sound-load.test.js +259 -0
  311. package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
  312. package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
  313. package/swf2js/__tests__/sound-transform.test.js +104 -0
  314. package/swf2js/__tests__/speex-audio.test.js +77 -0
  315. package/swf2js/__tests__/stage-noscale.test.js +45 -0
  316. package/swf2js/__tests__/swf-encoder.test.js +134 -0
  317. package/swf2js/__tests__/swflib-assemble.test.js +20 -0
  318. package/swf2js/__tests__/textfield-html-text.test.js +368 -0
  319. package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
  320. package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
  321. package/swf2js/__tests__/textfield-scroll.test.js +79 -0
  322. package/swf2js/__tests__/textfield-selection.test.js +383 -0
  323. package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
  324. package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
  325. package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
  326. package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
  327. package/{src → swf2js}/cli.js +43 -11
  328. package/swf2js/compiler/as2-classes.js +156 -0
  329. package/swf2js/compiler/as2-parser.js +598 -0
  330. package/swf2js/compiler/avm1-codegen.js +897 -0
  331. package/swf2js/compiler/index.js +28 -0
  332. package/{src → swf2js}/decoder/button-decoder.js +3 -1
  333. package/swf2js/decoder/png.js +114 -0
  334. package/{src → swf2js}/decoder/shape-decoder.js +20 -10
  335. package/{src → swf2js}/decoder/tag-decoder.js +5 -3
  336. package/{src → swf2js}/decoder/tag-types.js +4 -0
  337. package/swf2js/decompiler/avm1-decompiler.js +1138 -0
  338. package/{src → swf2js}/emitter/asset-encoder.js +66 -113
  339. package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
  340. package/swf2js/emitter/external-resources.js +39 -0
  341. package/swf2js/emitter/movie-data-codec.js +91 -0
  342. package/swf2js/encoder/bit-writer.js +182 -0
  343. package/swf2js/encoder/shape-encoder.js +310 -0
  344. package/swf2js/encoder/swf-builder.js +639 -0
  345. package/swf2js/encoder/swf-writer.js +55 -0
  346. package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
  347. package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
  348. package/{src → swf2js}/runtime/index.js +1 -1
  349. package/{src → swf2js}/runtime/movie-runtime.js +28 -2
  350. package/{src → swf2js}/transpiler/actionscript.js +82 -19
  351. package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
  352. package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
  353. package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
  354. package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
  355. package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
  356. package/swooflib/README.md +569 -0
  357. package/swooflib/adpcm.js +147 -0
  358. package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
  359. package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
  360. package/swooflib/control-definitions.js +42 -0
  361. package/swooflib/control-widget.js +763 -0
  362. package/swooflib/controls.js +300 -0
  363. package/{src/runtime/swflib → swooflib}/display.js +16 -10
  364. package/{src/runtime/swflib → swooflib}/events.js +11 -0
  365. package/{src/runtime/swflib → swooflib}/flash.js +6 -5
  366. package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
  367. package/{src/runtime/swflib → swooflib}/input.js +12 -14
  368. package/{src/runtime/swflib → swooflib}/loader.js +52 -22
  369. package/swooflib/movie-network.js +86 -0
  370. package/swooflib/path-stream.js +169 -0
  371. package/{src/runtime/swflib → swooflib}/render.js +3 -13
  372. package/{src/runtime/swflib → swooflib}/sound.js +25 -2
  373. package/{src/runtime/swflib → swooflib}/stage.js +3 -3
  374. package/swooflib/stream-time.js +21 -0
  375. package/{src/runtime/swflib → swooflib}/system.js +88 -37
  376. package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
  377. package/{src/runtime/swflib → swooflib}/text.js +8 -0
  378. package/swooflib/xml-node.js +53 -0
  379. package/src/emitter/timeline-data-codec.js +0 -58
  380. /package/{src → swf2js}/decoder/symbol-table.js +0 -0
  381. /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
  382. /package/{src → swf2js}/emitter/font-encoder.js +0 -0
  383. /package/{src → swf2js}/model/swf-document.js +0 -0
  384. /package/{src → swf2js}/model/transpile-result.js +0 -0
  385. /package/{src → swf2js}/parser/bit-reader.js +0 -0
  386. /package/{src → swf2js}/parser/decompressor.js +0 -0
  387. /package/{src → swf2js}/parser/swf-parser.js +0 -0
  388. /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
  389. /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
  390. /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
  391. /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
  392. /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
  393. /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
  394. /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
  395. /package/{src → swf2js}/util/diagnostics.js +0 -0
  396. /package/{src → swf2js}/util/logger.js +0 -0
  397. /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
  398. /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
  399. /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
  400. /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
  401. /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
  402. /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
  403. /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
  404. /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
  405. /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
  406. /package/{src/runtime/swflib → swooflib}/host.js +0 -0
  407. /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
  408. /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
  409. /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
  410. /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
  411. /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
  412. /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
  413. /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
  414. /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
  415. /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
  416. /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
@@ -0,0 +1,764 @@
1
+ import { runInNewContext } from 'node:vm';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { AVM1_RUNTIME_STUB, transpileAvm1 } from '../transpiler/avm1/avm1-transpiler.js';
4
+ import { OP } from '../transpiler/avm1/avm1-opcodes.js';
5
+ import { DiagnosticsCollector } from '../util/diagnostics.js';
6
+ import { transpileActionScript } from '../transpiler/actionscript.js';
7
+ import { AVM1_RUNTIME_FACTORY_SOURCE } from '../runtime/index.js';
8
+ import { generateTimelineEngine, timelineHelpersSource } from '../transpiler/timeline/timeline-codegen.js';
9
+ import { TAG } from '../decoder/tag-types.js';
10
+
11
+ const bytesOf = value => [...new TextEncoder().encode(value), 0];
12
+ const action = (op, data) => [op, data.length & 255, data.length >> 8, ...data];
13
+ const push = (...values) => action(OP.Push, values.flatMap(value =>
14
+ typeof value === 'string' ? [0, ...bytesOf(value)] : [7, value & 255, (value >>> 8) & 255, (value >>> 16) & 255, value >>> 24]));
15
+ const read = name => [...push(name), OP.GetVariable];
16
+
17
+ function compile(actions, setup = '', environment = {}, options = {}) {
18
+ const diagnostics = new DiagnosticsCollector();
19
+ const js = transpileAvm1(Uint8Array.of(...actions, OP.End), diagnostics, options);
20
+ expect(diagnostics.all()).toEqual([]);
21
+ const logs = [];
22
+ const { root, script } = runInNewContext(`
23
+ ${AVM1_RUNTIME_STUB}
24
+ ${setup}
25
+ ({ root, script: function () { ${js} } });
26
+ `, {
27
+ console: { log(value) { logs.push(value); } },
28
+ ...environment,
29
+ });
30
+ return { root, run: () => { logs.length = 0; script.call(root); return [...logs]; } };
31
+ }
32
+
33
+ describe('AVM1 loading and host actions', () => {
34
+ it('plays the defining timeline when a callback is invoked on a plain object', () => {
35
+ const body = [OP.Play, ...read('this'), OP.Return];
36
+ const define = action(OP.DefineFunction, [...bytesOf('completed'), 0, 0, body.length, 0]);
37
+ const movie = compile([...define, ...body], '', { SWF_VERSION: 8 });
38
+ let played = 0;
39
+ movie.root.play = () => { played++; };
40
+ movie.run();
41
+ const listener = { completed: movie.root.completed };
42
+ expect(listener.completed()).toBe(listener);
43
+ expect(played).toBe(1);
44
+ });
45
+
46
+ it('calls movie-owned AVM1 timers with method receivers and callback arguments', () => {
47
+ const scheduled = new Map();
48
+ let nextId = 0;
49
+ const schedule = repeat => (callback, delay) => {
50
+ const id = ++nextId;
51
+ scheduled.set(id, { callback, delay, repeat });
52
+ return id;
53
+ };
54
+ const clear = id => scheduled.delete(id);
55
+ const movie = compile([
56
+ ...push('intervalId', 7, 100, 'poll'), ...read('watch'),
57
+ ...push(4, 'setInterval'), OP.CallFunction, OP.SetVariable,
58
+ ...push('timeoutId', 3, 20), ...read('done'),
59
+ ...push(3, 'setTimeout'), OP.CallFunction, OP.SetVariable,
60
+ ], `
61
+ root.watch = { value: 0, poll: function (step) { this.value += step; } };
62
+ root.done = function (value) { root.result = value; };
63
+ root.cancel = function () { globals.clearInterval(root.intervalId); globals.clearTimeout(root.timeoutId); };
64
+ `, {
65
+ __swoof_swflib: { packages: { utils: {
66
+ setInterval: schedule(true), clearInterval: clear,
67
+ setTimeout: schedule(false), clearTimeout: clear,
68
+ } } },
69
+ });
70
+ movie.run();
71
+ const { root } = movie;
72
+ const interval = scheduled.get(root.intervalId);
73
+ const timeout = scheduled.get(root.timeoutId);
74
+ expect(interval).toMatchObject({ delay: 100, repeat: true });
75
+ expect(timeout).toMatchObject({ delay: 20, repeat: false });
76
+ interval.callback();
77
+ root.watch.poll = function (step) { this.value += step * 2; };
78
+ interval.callback();
79
+ timeout.callback();
80
+ expect(root.watch.value).toBe(21);
81
+ expect(root.result).toBe(3);
82
+ root.cancel();
83
+ expect(scheduled.size).toBe(0);
84
+ });
85
+
86
+ it('clears a movie-owned timer from its unbound function callback', () => {
87
+ const body = [...read('timerId'), ...push(1, 'clearInterval'), OP.CallFunction, OP.Pop];
88
+ const define = action(OP.DefineFunction, [...bytesOf('finishPreload'), 0, 0, body.length, 0]);
89
+ const diagnostics = new DiagnosticsCollector();
90
+ const js = transpileAvm1(Uint8Array.of(...define, ...body, OP.End), diagnostics);
91
+ expect(diagnostics.all()).toEqual([]);
92
+ const callbacks = [];
93
+ const managedClears = [], hostClears = [];
94
+ runInNewContext(`
95
+ ${AVM1_RUNTIME_STUB}
96
+ (function () {
97
+ 'use strict';
98
+ ${js}
99
+ }).call(root);
100
+ root.timerId = globals.setInterval(root.finishPreload, 50);
101
+ `, {
102
+ clearInterval(id) { hostClears.push(id); },
103
+ __swoof_swflib: { packages: { utils: {
104
+ setInterval(callback) { callbacks.push(callback); return 17; },
105
+ clearInterval(id) { managedClears.push(id); },
106
+ } } },
107
+ });
108
+
109
+ expect(callbacks).toHaveLength(1);
110
+ callbacks[0]();
111
+ expect(managedClears).toEqual([17]);
112
+ expect(hostClears).toEqual([]);
113
+ });
114
+
115
+ it('resolves member names and function captures from the pool on the executed branch', () => {
116
+ const pool = name => action(OP.ConstantPool, [1, 0, ...bytesOf(name)]);
117
+ const pooledName = action(OP.Push, [8, 0]);
118
+ const replacement = pool('secondary');
119
+ const body = [...read('this'), ...pooledName, OP.GetMember, OP.Return];
120
+ const define = action(OP.DefineFunction, [...bytesOf('readSelected'), 0, 0, body.length, 0]);
121
+ const movie = compile([
122
+ ...pool('primary'), ...read('skipReplacement'),
123
+ ...action(OP.If, [replacement.length, 0]), ...replacement,
124
+ ...read('this'), ...pooledName, ...push(42), OP.SetMember,
125
+ ...define, ...body,
126
+ ...pool('other'), ...push(0, 'readSelected'), OP.CallFunction, OP.Trace,
127
+ ]);
128
+ movie.root.skipReplacement = true;
129
+ expect(movie.run()).toEqual([42]);
130
+ expect(movie.root.primary).toBe(42);
131
+ expect(movie.root.secondary).toBeUndefined();
132
+ delete movie.root.primary;
133
+ movie.root.skipReplacement = false;
134
+ expect(movie.run()).toEqual([42]);
135
+ expect(movie.root.primary).toBeUndefined();
136
+ expect(movie.root.secondary).toBe(42);
137
+ });
138
+
139
+ it('keeps constants already pushed when a later pool replaces their entries', () => {
140
+ const movie = compile([
141
+ ...action(OP.ConstantPool, [1, 0, ...bytesOf('first')]),
142
+ ...action(OP.Push, [8, 0]),
143
+ ...action(OP.ConstantPool, [1, 0, ...bytesOf('second')]),
144
+ OP.Trace, ...action(OP.Push, [8, 0]), OP.Trace,
145
+ ]);
146
+ expect(movie.run()).toEqual(['first', 'second']);
147
+ });
148
+
149
+ it('gives AVM1 package lookups the library classes and keeps MovieClip', () => {
150
+ function Font() {}
151
+ function MovieClip() {}
152
+ function BitmapData() {}
153
+ const movie = compile([
154
+ ...push('font'), ...read('flash'), ...push('text'), OP.GetMember, ...push('Font'), OP.GetMember, OP.SetVariable,
155
+ ...push('clip', 'MovieClip'), OP.GetVariable, OP.SetVariable,
156
+ ], '', { __swoof_swflib: { packages: { text: { Font }, display: { MovieClip, BitmapData } } } });
157
+ movie.run();
158
+ expect(movie.root.font).toBe(Font);
159
+ expect(typeof movie.root.clip).toBe('function');
160
+ expect(movie.root.clip).not.toBe(MovieClip);
161
+ });
162
+
163
+ it('constructs the AVM1 flash.display.BitmapData through the movie package', () => {
164
+ function BitmapData(width, height) { this.width = width; this.height = height; }
165
+ const movie = compile([
166
+ ...push('bitmap', 12, 8, 2), ...read('flash'),
167
+ ...push('display'), OP.GetMember, ...push('BitmapData'), OP.NewMethod, OP.SetVariable,
168
+ ], '', { __swoof_swflib: { packages: { display: { BitmapData } } } });
169
+ movie.run();
170
+ expect(movie.root.bitmap).toBeInstanceOf(BitmapData);
171
+ expect(movie.root.bitmap).toMatchObject({ width: 8, height: 12 });
172
+ });
173
+
174
+ it('loads an HTTP image through MovieClipLoader and exposes ordered events and byte counts', async () => {
175
+ let stream;
176
+ const requests = [], images = [], blobs = [], revoked = [];
177
+ const movie = compile([
178
+ ...push('loader', 0, 'MovieClipLoader'), OP.NewObject, OP.SetVariable,
179
+ ], `
180
+ root.banner = root.createEmptyMovieClip('banner', 3);
181
+ root.events = [];
182
+ `, {
183
+ Blob, AbortController,
184
+ Image: class { constructor() { this.naturalWidth = 4; this.naturalHeight = 5; images.push(this); } },
185
+ URL: {
186
+ createObjectURL(blob) { blobs.push(blob); return 'blob:banner'; },
187
+ revokeObjectURL(url) { revoked.push(url); },
188
+ },
189
+ fetch(url) {
190
+ requests.push(url);
191
+ return Promise.resolve(new Response(new ReadableStream({ start(controller) { stream = controller; } }), {
192
+ headers: { 'Content-Type': 'image/png', 'Content-Length': '4' },
193
+ }));
194
+ },
195
+ });
196
+ movie.run();
197
+ const { loader, banner, events } = movie.root;
198
+ const listener = {
199
+ onLoadStart(clip) { events.push(['start', this === listener, clip === banner]); },
200
+ onLoadProgress(clip, loaded, total) { events.push(['progress', loaded, total, clip.getBytesLoaded()]); },
201
+ onLoadComplete(clip, status) { events.push(['complete', status, clip._width]); },
202
+ onLoadInit(clip) { events.push(['init', clip._width, clip._height]); },
203
+ };
204
+ expect(loader.addListener(listener)).toBe(true);
205
+ expect(loader.addListener(listener)).toBe(false);
206
+ expect(loader.loadClip('https://example.test/banner.png', '/banner')).toBe(true);
207
+ const flush = () => new Promise(resolve => setImmediate(resolve));
208
+ await flush();
209
+ stream.enqueue(Uint8Array.of(1, 2));
210
+ await flush();
211
+ expect(loader.getProgress(banner)).toEqual({ bytesLoaded: 2, bytesTotal: 4 });
212
+ stream.enqueue(Uint8Array.of(3, 4));
213
+ stream.close();
214
+ await flush();
215
+ expect(blobs.map(blob => blob.size)).toEqual([4]);
216
+ expect(images[0].src).toBe('blob:banner');
217
+ images[0].onload();
218
+ expect(events).toEqual([
219
+ ['start', true, true], ['progress', 2, 4, 2], ['progress', 4, 4, 4],
220
+ ['complete', 200, 0], ['init', 4, 5],
221
+ ]);
222
+ expect(revoked).toEqual(['blob:banner']);
223
+ expect(requests).toEqual(['https://example.test/banner.png']);
224
+ expect(loader.removeListener(listener)).toBe(true);
225
+ expect(loader.unloadClip('/banner')).toBe(true);
226
+ expect(loader.getProgress(banner)).toEqual({ bytesLoaded: 0, bytesTotal: 0 });
227
+ });
228
+
229
+ it('reports a missing HTTP asset once and suppresses callbacks for a canceled local image', async () => {
230
+ const requests = [], images = [], events = [];
231
+ const movie = compile([], `
232
+ root.loader = new globals.MovieClipLoader();
233
+ root.banner = root.createEmptyMovieClip('banner', 3);
234
+ `, {
235
+ Image: class { constructor() { images.push(this); } },
236
+ URL,
237
+ fetch(url) { requests.push(url); return Promise.resolve(new Response('missing', { status: 404 })); },
238
+ });
239
+ const { loader, banner } = movie.root;
240
+ loader.addListener({
241
+ onLoadStart() { events.push('start'); },
242
+ onLoadInit() { events.push('init'); },
243
+ onLoadError(clip, code, status) { events.push([clip === banner, code, status]); },
244
+ });
245
+ expect(loader.loadClip('https://example.test/banner.png', banner)).toBe(true);
246
+ await new Promise(resolve => setImmediate(resolve));
247
+ expect(events).toEqual([[true, 'URLNotFound', 404]]);
248
+ expect(requests).toHaveLength(1);
249
+ expect(loader.loadClip('https://example.test/stinger.swf?cache=2', banner)).toBe(true);
250
+ await new Promise(resolve => setImmediate(resolve));
251
+ expect(events).toEqual([[true, 'URLNotFound', 404], [true, 'URLNotFound', 0]]);
252
+ expect(requests).toHaveLength(1);
253
+ expect(loader.loadClip('art/local.png', banner)).toBe(true);
254
+ expect(images[0].src).toBe('art/local.png');
255
+ const callback = images[0].onload;
256
+ expect(loader.unloadClip(banner)).toBe(true);
257
+ callback();
258
+ expect(events).toHaveLength(2);
259
+ expect(loader.loadClip('art/another.png', 2)).toBe(true);
260
+ expect(loader.unloadClip('_level2')).toBe(true);
261
+ });
262
+
263
+ it('uses AVM1 LoadVars for typed reads, form requests and callbacks', async () => {
264
+ const requests = [];
265
+ const movie = compile([...push('sender', 0, 'LoadVars'), OP.NewObject, OP.SetVariable], `
266
+ root.target = new globals.LoadVars();
267
+ root.events = [];
268
+ root.target.onHTTPStatus = code => root.events.push(['status', code]);
269
+ root.target.onLoad = function (success) { root.events.push(['load', success, this.loaded]); };
270
+ `, {
271
+ URLSearchParams, TextDecoder, AbortController,
272
+ fetch(url, options) {
273
+ requests.push({ url, options });
274
+ return Promise.resolve(new Response('player=Alex+Smith&count=4'));
275
+ },
276
+ });
277
+ movie.run();
278
+ const { sender, target, events } = movie.root;
279
+ sender.key = 'a+b';
280
+ sender.contentType = 'application/custom';
281
+ sender.addRequestHeader(['X-Game', 'swoof']);
282
+ expect(sender.sendAndLoad('/data', target)).toBe(true);
283
+ await new Promise(resolve => setImmediate(resolve));
284
+ expect(requests).toMatchObject([{ url: '/data', options: { method: 'POST', body: 'key=a%2Bb',
285
+ headers: { 'Content-Type': 'application/custom', 'X-Game': 'swoof' } } }]);
286
+ expect(events).toEqual([['status', 200], ['load', true, true]]);
287
+ expect(target).toMatchObject({ player: 'Alex Smith', count: '4' });
288
+ expect(target.getBytesLoaded()).toBe(25);
289
+ expect(target.getBytesTotal()).toBe(25);
290
+ expect(String(sender)).toBe('key=a%2Bb');
291
+ });
292
+
293
+ it('reports LoadVars streaming bytes and sends the raw response to an override', async () => {
294
+ let stream;
295
+ const movie = compile([], `
296
+ root.vars = new globals.LoadVars();
297
+ root.events = [];
298
+ root.vars.onHTTPStatus = code => root.events.push(['status', code]);
299
+ root.vars.onData = body => root.events.push(['data', body]);
300
+ root.vars.onLoad = success => root.events.push(['load', success]);
301
+ `, {
302
+ URLSearchParams, TextDecoder,
303
+ fetch() {
304
+ return Promise.resolve(new Response(new ReadableStream({ start(controller) { stream = controller; } }), {
305
+ headers: { 'Content-Length': '8' },
306
+ }));
307
+ },
308
+ });
309
+ const { vars, events } = movie.root;
310
+ const flush = () => new Promise(resolve => setImmediate(resolve));
311
+ const bytes = new TextEncoder().encode('name=猫');
312
+ expect(vars.loaded).toBeUndefined();
313
+ expect(vars.load('data.txt')).toBe(true);
314
+ await flush();
315
+ stream.enqueue(bytes.slice(0, 6));
316
+ await flush();
317
+ expect(vars.getBytesLoaded()).toBe(6);
318
+ expect(vars.getBytesTotal()).toBe(8);
319
+ expect(events).toEqual([['status', 200]]);
320
+ stream.enqueue(bytes.slice(6));
321
+ stream.close();
322
+ await flush();
323
+ expect(vars.getBytesLoaded()).toBe(8);
324
+ expect(events).toEqual([['status', 200], ['data', 'name=猫']]);
325
+ expect(vars.name).toBeUndefined();
326
+ });
327
+
328
+ it('constructs emitted AVM1 XML and traverses nodes independently from AVM2 XML', () => {
329
+ const nested = { nodeName: 'entry', nodeType: 1, attributes: [{ name: 'kind', value: 'a&b' }],
330
+ childNodes: [{ nodeType: 3, nodeValue: 'A<B' }] };
331
+ const tree = { nodeName: 'swoof-avm1-xml', childNodes: [
332
+ { nodeType: 3, nodeValue: ' ' }, nested,
333
+ { nodeType: 1, nodeName: 'next', attributes: [], childNodes: [] },
334
+ ] };
335
+ class DOMParser {
336
+ parseFromString(source) {
337
+ expect(source).toBe('<swoof-avm1-xml> <entry kind="a&amp;b">A&lt;B</entry><next/></swoof-avm1-xml>');
338
+ return { documentElement: tree, getElementsByTagNameNS: () => [] };
339
+ }
340
+ }
341
+ const source = '<?xml version="1.0"?> <entry kind="a&amp;b">A&lt;B</entry><next/>';
342
+ const movie = compile([...push('doc', source, 1, 'XML'), OP.NewObject, OP.SetVariable], '', { DOMParser });
343
+ movie.run();
344
+ const xml = movie.root.doc;
345
+ expect(xml.firstChild.nodeValue).toBe(' ');
346
+ const entry = xml.firstChild.nextSibling;
347
+ expect(entry.firstChild.nodeValue).toBe('A<B');
348
+ expect(entry.attributes.kind).toBe('a&b');
349
+ expect(entry.parentNode).toBe(xml);
350
+ expect(xml.lastChild.previousSibling).toBe(entry);
351
+ xml.ignoreWhite = true;
352
+ xml.parseXML(source);
353
+ expect(entry.parentNode).toBeNull();
354
+ expect(xml.firstChild.nodeName).toBe('entry');
355
+ xml.lastChild.appendChild(xml.createTextNode('<ok>'));
356
+ expect(String(xml)).toBe('<?xml version="1.0"?><entry kind="a&amp;b">A&lt;B</entry><next>&lt;ok&gt;</next>');
357
+ });
358
+
359
+ it('reports XML load status before completion and ignores stale requests', async () => {
360
+ const requests = [];
361
+ class DOMParser {
362
+ parseFromString(body) {
363
+ return { documentElement: { nodeName: 'swoof-avm1-xml', childNodes: [
364
+ { nodeType: 1, nodeName: 'body', attributes: [], childNodes: [{ nodeType: 4, nodeValue: 'content' }] },
365
+ ] }, getElementsByTagNameNS: namespace => !body.includes('valid') && namespace === 'http://www.w3.org/1999/xhtml' ? [{}] : [] };
366
+ }
367
+ }
368
+ const movie = compile([], `
369
+ root.xml = new globals.XML();
370
+ root.events = [];
371
+ root.xml.onHTTPStatus = function (status) { root.events.push(['status', status]); };
372
+ root.xml.onLoad = function (success) { root.events.push(['load', success, this.status, this.loaded]); };
373
+ `, {
374
+ DOMParser, AbortController,
375
+ fetch(url, options) {
376
+ return new Promise(resolve => requests.push({ url, signal: options.signal, resolve }));
377
+ },
378
+ });
379
+ const flush = () => new Promise(resolve => setImmediate(resolve));
380
+ const { xml, events } = movie.root;
381
+ expect(xml.load(undefined)).toBe(false);
382
+ expect(xml.load('prior.xml')).toBe(true);
383
+ await flush();
384
+ expect(xml.load('promo.xml')).toBe(true);
385
+ await flush();
386
+ expect(requests.map(request => request.url)).toEqual(['prior.xml', 'promo.xml']);
387
+ expect(requests[0].signal.aborted).toBe(true);
388
+ requests[0].resolve({ ok: true, status: 200, text: () => 'stale' });
389
+ requests[1].resolve({ ok: true, status: 200, text: () => '<valid/>' });
390
+ await flush();
391
+ expect(events.splice(0)).toEqual([['status', 200], ['load', true, 0, true]]);
392
+ expect(xml.firstChild.firstChild.nodeValue).toBe('content');
393
+
394
+ xml.load('missing.xml');
395
+ await flush();
396
+ requests[2].resolve({ ok: false, status: 404 });
397
+ await flush();
398
+ expect(events.splice(0)).toEqual([['status', 404], ['load', false, 0, false]]);
399
+ xml.load('bad.xml');
400
+ await flush();
401
+ requests[3].resolve({ ok: true, status: 200, text: () => '<broken>' });
402
+ await flush();
403
+ expect(events.splice(0)).toEqual([['status', 200], ['load', true, -6, true]]);
404
+ xml.onData = body => events.push(['data', body]);
405
+ xml.load('raw.xml');
406
+ await flush();
407
+ requests[4].resolve({ ok: true, status: 200, text: () => '<valid/>' });
408
+ await flush();
409
+ expect(events).toEqual([['status', 200], ['data', '<valid/>']]);
410
+ expect(xml.loaded).toBe(false);
411
+ });
412
+
413
+ it('uses an empty constant-pool property target for the current clip', () => {
414
+ const movie = compile([
415
+ ...action(OP.ConstantPool, [1, 0, 0]),
416
+ ...push('_x'),
417
+ ...action(OP.Push, [8, 0]), ...push(0), OP.GetProperty,
418
+ ...push(5), OP.Add2, OP.SetVariable,
419
+ ], 'root.x = 35;');
420
+ movie.run();
421
+ expect(movie.root.x).toBe(40);
422
+ });
423
+
424
+ it.each([false, true])('uses the defining timeline for indexed callback properties (SetTarget = %s)', usesSetTarget => {
425
+ const readProperty = (target, index) => [...push(target, index), OP.GetProperty, OP.Trace];
426
+ const body = [
427
+ ...readProperty('', 20),
428
+ ...readProperty('aim', 0),
429
+ ...(usesSetTarget ? [
430
+ ...action(OP.SetTarget, bytesOf('aim')),
431
+ ...readProperty('', 20),
432
+ ] : []),
433
+ ...push('', 0, 33), OP.SetProperty,
434
+ ...read('this'), OP.Return,
435
+ ];
436
+ const define = action(OP.DefineFunction, [...bytesOf('update'), 0, 0, body.length, 0]);
437
+ const movie = compile([...define, ...body, ...push(0, 'listener'), OP.CallFunction], `
438
+ avm1MouseX = 78;
439
+ root.aim = root.createEmptyMovieClip('aim', 1);
440
+ root.aim.x = 12;
441
+ root.listener = function () {
442
+ var receiver = { x: 9, update: root.update };
443
+ root.sameReceiver = receiver.update() === receiver;
444
+ root.receiverX = receiver.x;
445
+ };
446
+ `, { SWF_VERSION: 8 });
447
+ expect(movie.run()).toEqual(usesSetTarget ? [78, 12, 66] : [78, 12]);
448
+ expect([movie.root.x, movie.root.aim.x]).toEqual(usesSetTarget ? [0, 33] : [33, 12]);
449
+ expect(movie.root.sameReceiver).toBe(true);
450
+ expect(movie.root.receiverX).toBe(9);
451
+ });
452
+
453
+ it('routes immediate URLs and GET form operands to the browser and keeps FSCommand on the host bridge', () => {
454
+ const opened = [], commands = [];
455
+ const movie = compile([
456
+ ...action(OP.GetURL, [...bytesOf('instructions.html'), ...bytesOf('')]),
457
+ ...push('submit?game=1#result', '_blank'), ...action(OP.GetURL2, [1]),
458
+ ...push('javascript:alert(1)', '_self'), ...action(OP.GetURL2, [0]),
459
+ ...action(OP.GetURL, [...bytesOf('FSCommand:score'), ...bytesOf('42')]),
460
+ ], "root.player = 'A B';", {
461
+ URLSearchParams,
462
+ window: { open(url, target) { opened.push([url, target]); } },
463
+ __swoof_swflib: { fsCommand(command, args) { commands.push([command, args]); } },
464
+ });
465
+ movie.run();
466
+ expect(opened).toEqual([['instructions.html', '_self'], ['submit?game=1&player=A+B#result', '_blank']]);
467
+ expect(commands).toEqual([['score', '42']]);
468
+ });
469
+
470
+ it('submits named clip variables by POST and parses the response before its onData event', async () => {
471
+ const requests = [];
472
+ const movie = compile([
473
+ ...push('profile.txt', '/profile'), ...action(OP.GetURL2, [0xc2]),
474
+ ], `
475
+ root.requestName = 'Joe Á';
476
+ var profile = root.createEmptyMovieClip('profile', 3);
477
+ profile.onData = function () { this.report = this.title + ':' + this.status; };
478
+ `, {
479
+ URLSearchParams,
480
+ async fetch(url, options) {
481
+ requests.push([url, options]);
482
+ return { ok: true, text: async () => 'title=Name+%E2%9C%93&status=a%3Db&__proto__=text' };
483
+ },
484
+ });
485
+ movie.run();
486
+ await new Promise(resolve => setImmediate(resolve));
487
+ expect(requests).toEqual([['profile.txt', {
488
+ method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'requestName=Joe+%C3%81',
489
+ }]]);
490
+ expect(movie.root.profile.report).toBe('Name ✓:a=b');
491
+ expect(Object.hasOwn(movie.root.profile, '__proto__')).toBe(false);
492
+ });
493
+
494
+ it('waits for the policy check before loading AVM1 variables', async () => {
495
+ const requests = [];
496
+ let finishPolicy;
497
+ const pending = new Promise(resolve => { finishPolicy = resolve; });
498
+ const movie = compile([
499
+ ...push('https://example.test/profile', '/profile'), ...action(OP.GetURL2, [0xc0]),
500
+ ], `root.createEmptyMovieClip('profile', 3);`, {
501
+ System: {
502
+ capabilities: { version: 'MAC 32,0,0,465' },
503
+ security: { _checkPolicyFiles(url) { requests.push('policy:' + url); return pending; } },
504
+ },
505
+ URLSearchParams,
506
+ async fetch(url) { requests.push(url); return { ok: true, text: async () => 'ready=yes' }; },
507
+ });
508
+ movie.run();
509
+ expect(requests).toEqual(['policy:https://example.test/profile']);
510
+ finishPolicy([false]);
511
+ await new Promise(resolve => setImmediate(resolve));
512
+ expect(requests).toEqual(['policy:https://example.test/profile', 'https://example.test/profile']);
513
+ expect(movie.root.profile.ready).toBe('yes');
514
+ });
515
+
516
+ it('loads a relative image into a transformed clip, paints it and ignores canceled image results', () => {
517
+ const images = [], draws = [];
518
+ class Image {
519
+ constructor() { images.push(this); }
520
+ naturalWidth = 16;
521
+ naturalHeight = 9;
522
+ }
523
+ const ctx = {
524
+ save() {}, restore() {}, fillRect() {},
525
+ setTransform(...matrix) { this.matrix = matrix.map(value => value || 0); },
526
+ drawImage(image) { draws.push([image.src, this.matrix]); },
527
+ };
528
+ const engine = generateTimelineEngine({ frames: [{ places: [] }], characters: {} }, { frameCount: 1 });
529
+ const movie = compile([
530
+ ...push('art/splash.png', '/container/banner'), ...action(OP.GetURL2, [0x40]),
531
+ ], `
532
+ var STAGE_WIDTH = 120, STAGE_HEIGHT = 100, FRAME_RATE = 24, BACKGROUND = '#000';
533
+ var loaded = {};
534
+ ${engine}
535
+ root.render = function () { timeline.render(); };
536
+ var container = root.createEmptyMovieClip('container', 3);
537
+ container.x = 20;
538
+ var banner = container.createEmptyMovieClip('banner', 4);
539
+ banner.x = 4; banner.y = 7;
540
+ `, { Image, ctx });
541
+ movie.run();
542
+ expect(images[0].src).toBe('art/splash.png');
543
+ images[0].onload();
544
+ movie.root.render();
545
+ expect(draws).toEqual([['art/splash.png', [1, 0, 0, 1, 24, 7]]]);
546
+ const banner = movie.root.container.banner;
547
+ expect([banner._width, banner._height]).toEqual([16, 9]);
548
+ expect(banner.hitTest(25, 8, true)).toBe(true);
549
+ banner.loadMovie('older.png');
550
+ const lateLoad = images[1].onload;
551
+ banner.unloadMovie();
552
+ lateLoad();
553
+ movie.root.render();
554
+ expect(draws).toHaveLength(1);
555
+ expect(banner.hitTest(25, 8, true)).toBe(false);
556
+ });
557
+
558
+ it.each([false, true])('calls authored frame actions without entering the frame (shared runtime %s)', shared => {
559
+ const call = operand => [...push(operand), ...action(OP.CallFrame, [])];
560
+ const bytecode = (...ops) => Uint8Array.of(...ops, OP.End);
561
+ const trace = value => bytecode(...push(value), OP.Trace);
562
+ const diagnostics = new DiagnosticsCollector();
563
+ const generated = transpileActionScript([
564
+ { type: 'DoAction', bytecode: bytecode(...call(2), ...call('2'), ...call('/child:work'), ...call('/child:start'), ...call('missing'), ...push('after'), OP.Trace) },
565
+ { type: 'ShowFrame' },
566
+ { type: 'PlaceObject2', name: 'late', characterId: 7, clipActions: [{ eventFlags: 1, bytecode: trace('late onLoad') }] },
567
+ { type: 'DoAction', bytecode: trace('root frame 2') },
568
+ { type: 'ShowFrame' },
569
+ { type: 'DoAction', bytecode: trace('root label 2') },
570
+ { type: 'Sprite', characterId: 7, tags: [
571
+ { code: TAG.ShowFrame },
572
+ { code: TAG.DoAction, data: bytecode(...read('_name'), OP.Trace) },
573
+ ] },
574
+ ], diagnostics, { sharedAvm1Runtime: shared });
575
+ expect(diagnostics.all()).toEqual([]);
576
+ const observed = [];
577
+ const result = runInNewContext(`
578
+ var __swoof_swflib = {
579
+ createAvm1Runtime: ${AVM1_RUNTIME_FACTORY_SOURCE},
580
+ timelineHelpers: ${timelineHelpersSource()},
581
+ };
582
+ var __swoof_root, EXPORT_ASSETS = [];
583
+ var FRAME_SCRIPTS = [], SPRITE_FRAME_SCRIPTS = {}, displayList = {}, spritePlay = {};
584
+ var ensureSpritePlay, runSpriteFrameScripts, FRAMES = [{}, {}, { label: 'run', labels: ['2', 'run'] }];
585
+ var CHARACTERS = { 7: { type: 'sprite', frames: [{}, { label: 'work', labels: ['start', 'work'] }] } };
586
+ ${generated.fullJs}
587
+ var child = _ensureNamedClip('child', 7);
588
+ FRAME_SCRIPTS[0][0].call(root);
589
+ [root.currentFrame, child.currentFrame, 'late' in root];
590
+ `, { console: { log(value) { observed.push(value); } } });
591
+ expect(observed).toEqual(['root frame 2', 'root label 2', 'child', 'child', 'after']);
592
+ expect(result).toEqual([1, 1, false]);
593
+ });
594
+
595
+ it('skips whole records under SetTarget, including the body of a skipped function', () => {
596
+ const body = [...push('function body'), OP.Trace, OP.End];
597
+ const definition = action(OP.DefineFunction, [...bytesOf('extra'), 0, 0, body.length, 0]);
598
+ const movie = compile([
599
+ ...action(OP.SetTarget, bytesOf('clip')),
600
+ ...push('lower operand'),
601
+ ...action(OP.WaitForFrame, [4, 0, 3]),
602
+ ...definition, ...body, ...push('loaded branch'), OP.Trace,
603
+ OP.Trace,
604
+ ], `root.framesLoaded = 10;
605
+ var clip = root.createEmptyMovieClip('clip', 1);
606
+ clip.totalFrames = 7; clip.framesLoaded = 2;`);
607
+ expect(movie.run()).toEqual(['lower operand']);
608
+ expect('extra' in movie.root).toBe(false);
609
+ movie.root.clip.framesLoaded = 4;
610
+ expect(movie.run()).toEqual(['loaded branch', 'lower operand']);
611
+ expect(typeof movie.root.extra).toBe('function');
612
+ });
613
+
614
+ it('consumes the stack frame and applies the Flash stack-form boundary', () => {
615
+ const movie = compile([
616
+ ...push('lower operand'), ...read('requestedFrame'),
617
+ ...action(OP.WaitForFrame2, [2]),
618
+ ...push('loaded branch'), OP.Trace,
619
+ OP.Trace,
620
+ ], 'root.totalFrames = 8; root.framesLoaded = 3;');
621
+ for (const frame of [5, 16002]) {
622
+ movie.root.requestedFrame = frame;
623
+ expect(movie.run()).toEqual(['lower operand']);
624
+ }
625
+ for (const frame of [4, '4', 'label']) {
626
+ movie.root.requestedFrame = frame;
627
+ expect(movie.run()).toEqual(['loaded branch', 'lower operand']);
628
+ }
629
+ });
630
+
631
+ it.each([5, 6, 7])('uses decimal WaitForFrame2 operands in SWF %i', version => {
632
+ const movie = compile([
633
+ ...read('requestedFrame'), ...action(OP.WaitForFrame2, [2]),
634
+ ...push('loaded'), OP.Trace,
635
+ ], 'root.totalFrames = 8; root.framesLoaded = 3;', { SWF_VERSION: version });
636
+ for (const frame of ['5', '+5.', '50e-1', '005', { toString: () => '5' }, 4294967301, -2147483648]) {
637
+ movie.root.requestedFrame = frame;
638
+ expect(movie.run()).toEqual([]);
639
+ }
640
+ for (const frame of ['0x5', '0b101', '0o5', ' 5', '5 ', '5\n', 5.5, '5.5', Infinity, NaN, 'child:5']) {
641
+ movie.root.requestedFrame = frame;
642
+ expect(movie.run()).toEqual(['loaded']);
643
+ }
644
+ });
645
+
646
+ it('applies independent immediate and stack frame limits', () => {
647
+ const movie = compile([
648
+ ...action(OP.WaitForFrame, [0x80, 0x3e, 2]), ...push('immediate limit'), OP.Trace,
649
+ ...action(OP.WaitForFrame, [0x81, 0x3e, 2]), ...push('immediate past limit'), OP.Trace,
650
+ ...push(16001), ...action(OP.WaitForFrame2, [2]), ...push('stack limit'), OP.Trace,
651
+ ...push(16002), ...action(OP.WaitForFrame2, [2]), ...push('stack past limit'), OP.Trace,
652
+ ], 'root.totalFrames = 20000; root.framesLoaded = 16000;');
653
+ expect(movie.run()).toEqual(['immediate limit', 'stack limit']);
654
+ });
655
+
656
+ it.each([5, 6, 7])('normalizes RandomNumber bounds in SWF %i', version => {
657
+ let draws = 0;
658
+ const math = Object.create(Math);
659
+ math.random = () => { draws++; return 0.9; };
660
+ const movie = compile([...read('maximum'), OP.RandomNumber, OP.Trace], '',
661
+ { SWF_VERSION: version, Math: math }, { useRuntimeNumbers: true });
662
+ for (const value of [undefined, NaN, -Infinity, -10, 0, 0.9, '4suffix']) {
663
+ movie.root.maximum = value;
664
+ expect(movie.run()).toEqual([0]);
665
+ }
666
+ expect(draws).toBe(0);
667
+ for (const [value, upperBound] of [[1.9, 1], ['5.9', 5], [Infinity, 0x7fffffff], [2 ** 40, 0x7fffffff]]) {
668
+ movie.root.maximum = value;
669
+ expect(movie.run()).toEqual([Math.floor(0.9 * upperBound)]);
670
+ }
671
+ movie.root.maximum = '010';
672
+ expect(movie.run()).toEqual([version === 5 ? 9 : 7]);
673
+ expect(draws).toBe(5);
674
+ });
675
+
676
+ it.each([5, 7])('uses SWF %i number conversion for native Math.round calls', version => {
677
+ const callRound = [...read('input'), ...push(1), ...read('Math'), ...push('round'), OP.CallMethod, OP.Trace];
678
+ const movie = compile([
679
+ ...callRound,
680
+ ...read('input'), ...push(1), ...read('mathName'), OP.GetVariable,
681
+ ...read('methodName'), OP.CallMethod, OP.Trace,
682
+ ...push('roundFn'), ...read('Math'), ...push('round'), OP.GetMember, OP.SetVariable,
683
+ ...read('input'), ...push(1, 'roundFn'), OP.CallFunction, OP.Trace,
684
+ ...read('Math'), ...push('round'), ...read('overrideRound'), OP.SetMember,
685
+ ...callRound,
686
+ ], `
687
+ root.mathName = 'Math';
688
+ root.methodName = 'round';
689
+ root.overrideRound = function (value) {
690
+ return value === undefined && this === globals.Math ? 'override' : 'coerced';
691
+ };
692
+ root.hostRound = value => Math.round(value);
693
+ `, { SWF_VERSION: version }, { nameSpellings: version < 7 ? new Map() : null });
694
+ const expected = version === 5 ? 0 : NaN;
695
+ expect(movie.run()).toEqual([expected, expected, expected, 'override']);
696
+ expect(movie.root.hostRound(undefined)).toBeNaN();
697
+ });
698
+
699
+ it.each([5, 7])('resolves the native isNaN guard in SWF %i', version => {
700
+ const movie = compile([
701
+ ...read('invalid'), ...push(1, 'isNaN'), OP.CallFunction, OP.Trace,
702
+ ...read('missing'), ...push(1, 'isNaN'), OP.CallFunction, OP.Trace,
703
+ ...push('check'), ...read('isNaN'), OP.SetVariable,
704
+ ...push(34, 1, 'check'), OP.CallFunction, OP.Trace,
705
+ ...push('isNaN'), ...read('override'), OP.SetVariable,
706
+ ...push(34, 1, 'isNaN'), OP.CallFunction, OP.Trace,
707
+ ], `
708
+ root.invalid = NaN;
709
+ root.override = function (value) { return this === root && value === 34 ? 'override' : false; };
710
+ `, { SWF_VERSION: version }, { nameSpellings: version < 7 ? new Map() : null });
711
+ expect(movie.run()).toEqual([true, version === 7, false, 'override']);
712
+ });
713
+
714
+ it('shares the stage quality across clips and restores best after a toggle', () => {
715
+ const stage = { quality: 'best' };
716
+ const movie = compile([OP.ToggleQuality, ...read('_quality'), OP.Trace, ...read('_highquality'), OP.Trace],
717
+ "root.createEmptyMovieClip('clip', 1);", { __swoof_swflib: { stage } });
718
+ expect(movie.run()).toEqual(['LOW', 0]);
719
+ expect(stage.quality).toBe('low');
720
+ expect(movie.root.clip._quality).toBe('LOW');
721
+ expect(movie.run()).toEqual(['BEST', 2]);
722
+ movie.root.clip._quality = 'MEDIUM';
723
+ expect(stage.quality).toBe('medium');
724
+ movie.root.clip._highquality = 1;
725
+ expect(stage.quality).toBe('high');
726
+ });
727
+
728
+ it('registers interfaces and follows inherited interfaces in instanceof and cast', () => {
729
+ const movie = compile([
730
+ ...read('IBase'), ...push(1), ...read('IChild'), OP.Implements,
731
+ ...read('IChild'), ...read('interfaceCount'), ...read('Base'), OP.Implements,
732
+ ...read('object'), ...read('IBase'), OP.InstanceOf, OP.Trace,
733
+ ...read('IChild'), ...read('object'), OP.Cast, OP.Trace,
734
+ ...read('Unrelated'), ...read('object'), OP.Cast, OP.Trace,
735
+ ], `
736
+ root.IBase = function () {};
737
+ root.IChild = function () {};
738
+ root.Unrelated = function () {};
739
+ root.Base = function () {};
740
+ root.interfaceCount = 1;
741
+ function Derived() {}
742
+ Derived.prototype = Object.create(root.Base.prototype);
743
+ root.object = new Derived();
744
+ `);
745
+ expect(movie.run()).toEqual([true, movie.root.object, null]);
746
+ });
747
+
748
+ it('passes Flash Lite host arguments in order and enqueues the returned value on the operand stack', () => {
749
+ const calls = [];
750
+ const fsCommand2 = (command, args) => {
751
+ calls.push([command, ...args]);
752
+ return command === 'HostEcho' ? args.join(':') : undefined;
753
+ };
754
+ const movie = compile([
755
+ ...push('lower operand', 'second', 'first', 'HostEcho'), ...read('argumentCount'),
756
+ OP.FSCommand2, OP.Trace, OP.Trace,
757
+ ...push('languageCode', 'GetLanguage', 2), OP.FSCommand2, OP.Trace,
758
+ ...read('languageCode'), OP.Trace,
759
+ ...push('Unknown', 1), OP.FSCommand2, OP.Trace,
760
+ ], 'root.argumentCount = 3;', { __swoof_swflib: { fsCommand2 }, navigator: { language: 'en-US' } });
761
+ expect(movie.run()).toEqual(['first:second', 'lower operand', 0, 'en-US', -1]);
762
+ expect(calls).toEqual([['HostEcho', 'first', 'second'], ['GetLanguage', 'languageCode'], ['Unknown']]);
763
+ });
764
+ });