@swf2es/player-hosts 0.0.0-stage → 0.1.1

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 (405) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +759 -0
  3. package/README.md +43 -2
  4. package/dist/indexeddb.d.ts +27 -0
  5. package/dist/indexeddb.d.ts.map +1 -0
  6. package/dist/indexeddb.js +170 -0
  7. package/dist/indexeddb.js.map +1 -0
  8. package/dist/node-worker.d.ts +2 -0
  9. package/dist/node-worker.d.ts.map +1 -0
  10. package/dist/node-worker.js +12 -0
  11. package/dist/node-worker.js.map +1 -0
  12. package/dist/node.d.ts +8 -0
  13. package/dist/node.d.ts.map +1 -0
  14. package/dist/node.js +43 -0
  15. package/dist/node.js.map +1 -0
  16. package/dist/precompiled.d.ts +31 -0
  17. package/dist/precompiled.d.ts.map +1 -0
  18. package/dist/precompiled.js +125 -0
  19. package/dist/precompiled.js.map +1 -0
  20. package/dist/stage3d.d.ts +13 -0
  21. package/dist/stage3d.d.ts.map +1 -0
  22. package/dist/stage3d.js +61 -0
  23. package/dist/stage3d.js.map +1 -0
  24. package/dist/thread/codegen/codegen.js +308 -0
  25. package/dist/thread/codegen/index.js +405 -0
  26. package/dist/thread/format/abc-names.js +126 -0
  27. package/dist/thread/format/actions.js +222 -0
  28. package/dist/thread/format/air-descriptor.js +63 -0
  29. package/dist/thread/format/api-versions.js +22 -0
  30. package/dist/thread/format/bitmap.js +199 -0
  31. package/dist/thread/format/button.js +60 -0
  32. package/dist/thread/format/compression.js +200 -0
  33. package/dist/thread/format/display.js +305 -0
  34. package/dist/thread/format/filters.js +136 -0
  35. package/dist/thread/format/font.js +168 -0
  36. package/dist/thread/format/index.js +26 -0
  37. package/dist/thread/format/pbj.js +484 -0
  38. package/dist/thread/format/shape.js +411 -0
  39. package/dist/thread/format/sound.js +91 -0
  40. package/dist/thread/format/swf.js +163 -0
  41. package/dist/thread/format/tags.js +58 -0
  42. package/dist/thread/format/text.js +135 -0
  43. package/dist/thread/format/zip.js +91 -0
  44. package/dist/thread/native/audio/binary.js +3 -0
  45. package/dist/thread/native/audio/index.js +72 -0
  46. package/dist/thread/native/base64.js +9 -0
  47. package/dist/thread/native/compress/binary.js +3 -0
  48. package/dist/thread/native/compress/index.js +145 -0
  49. package/dist/thread/native/instance.js +49 -0
  50. package/dist/thread/native/mp3/binary.js +3 -0
  51. package/dist/thread/native/mp3/index.js +48 -0
  52. package/dist/thread/native/render/binary.js +3 -0
  53. package/dist/thread/native/render/bitmap-kernel.js +591 -0
  54. package/dist/thread/native/render/draw-kernel.js +204 -0
  55. package/dist/thread/native/render/dxt-encoder.js +94 -0
  56. package/dist/thread/native/render/index.js +10 -0
  57. package/dist/thread/native/render/lines.js +122 -0
  58. package/dist/thread/native/render/module.js +26 -0
  59. package/dist/thread/native/render/pixel-ops.js +235 -0
  60. package/dist/thread/native/render/tessellator.js +250 -0
  61. package/dist/thread/player/avm1/amf.js +507 -0
  62. package/dist/thread/player/avm1/avm1.js +1304 -0
  63. package/dist/thread/player/avm1/bindings.js +214 -0
  64. package/dist/thread/player/avm1/classes.js +75 -0
  65. package/dist/thread/player/avm1/clips.js +229 -0
  66. package/dist/thread/player/avm1/compile.js +140 -0
  67. package/dist/thread/player/avm1/external.js +79 -0
  68. package/dist/thread/player/avm1/focus.js +278 -0
  69. package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
  70. package/dist/thread/player/avm1/globals/Button.js +31 -0
  71. package/dist/thread/player/avm1/globals/Color.js +115 -0
  72. package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
  73. package/dist/thread/player/avm1/globals/FileReference.js +217 -0
  74. package/dist/thread/player/avm1/globals/Key.js +60 -0
  75. package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
  76. package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
  77. package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
  78. package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
  79. package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
  80. package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
  81. package/dist/thread/player/avm1/globals/Selection.js +62 -0
  82. package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
  83. package/dist/thread/player/avm1/globals/Sound.js +238 -0
  84. package/dist/thread/player/avm1/globals/Stage.js +12 -0
  85. package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
  86. package/dist/thread/player/avm1/globals/TextField.js +396 -0
  87. package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
  88. package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
  89. package/dist/thread/player/avm1/globals/XML.js +396 -0
  90. package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
  91. package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
  92. package/dist/thread/player/avm1/globals/drawing.js +202 -0
  93. package/dist/thread/player/avm1/globals/filters.js +635 -0
  94. package/dist/thread/player/avm1/globals/geom.js +600 -0
  95. package/dist/thread/player/avm1/input.js +483 -0
  96. package/dist/thread/player/avm1/keyboard.js +113 -0
  97. package/dist/thread/player/avm1/loads.js +352 -0
  98. package/dist/thread/player/avm1/net.js +219 -0
  99. package/dist/thread/player/avm1/paths.js +104 -0
  100. package/dist/thread/player/avm1/pointer.js +512 -0
  101. package/dist/thread/player/avm1/queue.js +303 -0
  102. package/dist/thread/player/avm1/sound.js +106 -0
  103. package/dist/thread/player/avm1/swf.js +141 -0
  104. package/dist/thread/player/avm1/timers.js +113 -0
  105. package/dist/thread/player/bitmap/bitmap.js +627 -0
  106. package/dist/thread/player/bitmap/draw.js +68 -0
  107. package/dist/thread/player/bitmap/dxt.js +11 -0
  108. package/dist/thread/player/bitmap/filters.js +656 -0
  109. package/dist/thread/player/bitmap/images.js +240 -0
  110. package/dist/thread/player/bitmap/kernel.js +65 -0
  111. package/dist/thread/player/bitmap/ops.js +1239 -0
  112. package/dist/thread/player/bitmap/pixel-bender.js +911 -0
  113. package/dist/thread/player/bitmap/png.js +139 -0
  114. package/dist/thread/player/bitmap/turbulence.js +89 -0
  115. package/dist/thread/player/clock.js +182 -0
  116. package/dist/thread/player/display/bitmapobject.js +25 -0
  117. package/dist/thread/player/display/bounds.js +520 -0
  118. package/dist/thread/player/display/buttonobject.js +305 -0
  119. package/dist/thread/player/display/color.js +40 -0
  120. package/dist/thread/player/display/container.js +150 -0
  121. package/dist/thread/player/display/display.js +14 -0
  122. package/dist/thread/player/display/displayobject.js +664 -0
  123. package/dist/thread/player/display/drawing.js +613 -0
  124. package/dist/thread/player/display/filters.js +285 -0
  125. package/dist/thread/player/display/geometry.js +189 -0
  126. package/dist/thread/player/display/gradients.js +117 -0
  127. package/dist/thread/player/display/graphicsdata.js +592 -0
  128. package/dist/thread/player/display/instantiate.js +71 -0
  129. package/dist/thread/player/display/matrix3d.js +373 -0
  130. package/dist/thread/player/display/morph.js +226 -0
  131. package/dist/thread/player/display/movieclip.js +680 -0
  132. package/dist/thread/player/display/perspective.js +193 -0
  133. package/dist/thread/player/display/scale9.js +236 -0
  134. package/dist/thread/player/display/shapeobject.js +131 -0
  135. package/dist/thread/player/display/shapes.js +407 -0
  136. package/dist/thread/player/display/textobjects.js +222 -0
  137. package/dist/thread/player/display/timeline.js +471 -0
  138. package/dist/thread/player/display/value-lists.js +40 -0
  139. package/dist/thread/player/display/videoobject.js +6 -0
  140. package/dist/thread/player/display/walk.js +127 -0
  141. package/dist/thread/player/files.js +334 -0
  142. package/dist/thread/player/hosts.js +207 -0
  143. package/dist/thread/player/input/avm1.js +82 -0
  144. package/dist/thread/player/input/context-menu.js +63 -0
  145. package/dist/thread/player/input/keyboard.js +458 -0
  146. package/dist/thread/player/input/pointer.js +863 -0
  147. package/dist/thread/player/input/text-editor.js +319 -0
  148. package/dist/thread/player/input/touch.js +209 -0
  149. package/dist/thread/player/localconnection.js +90 -0
  150. package/dist/thread/player/media/audio.js +376 -0
  151. package/dist/thread/player/media/dynamic-sound.js +90 -0
  152. package/dist/thread/player/media/extract.js +135 -0
  153. package/dist/thread/player/media/mp3.js +152 -0
  154. package/dist/thread/player/media/sounds.js +507 -0
  155. package/dist/thread/player/media/streaming-audio.js +133 -0
  156. package/dist/thread/player/player.js +616 -0
  157. package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
  158. package/dist/thread/player/playerglobal/air-library.js +8 -0
  159. package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
  160. package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
  161. package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
  162. package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
  163. package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
  164. package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
  165. package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
  166. package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
  167. package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
  168. package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
  169. package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
  170. package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
  171. package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
  172. package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
  173. package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
  174. package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
  175. package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
  176. package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
  177. package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
  178. package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
  179. package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
  180. package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
  181. package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
  182. package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
  183. package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
  184. package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
  185. package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
  186. package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
  187. package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
  188. package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
  189. package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
  190. package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
  191. package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
  192. package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
  193. package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
  194. package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
  195. package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
  196. package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
  197. package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
  198. package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
  199. package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
  200. package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
  201. package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
  202. package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
  203. package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
  204. package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
  205. package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
  206. package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
  207. package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
  208. package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
  209. package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
  210. package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
  211. package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
  212. package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
  213. package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
  214. package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
  215. package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
  216. package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
  217. package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
  218. package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
  219. package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
  220. package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
  221. package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
  222. package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
  223. package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
  224. package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
  225. package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
  226. package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
  227. package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
  228. package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
  229. package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
  230. package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
  231. package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
  232. package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
  233. package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
  234. package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
  235. package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
  236. package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
  237. package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
  238. package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
  239. package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
  240. package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
  241. package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
  242. package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
  243. package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
  244. package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
  245. package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
  246. package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
  247. package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
  248. package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
  249. package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
  250. package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
  251. package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
  252. package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
  253. package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
  254. package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
  255. package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
  256. package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
  257. package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
  258. package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
  259. package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
  260. package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
  261. package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
  262. package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
  263. package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
  264. package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
  265. package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
  266. package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
  267. package/dist/thread/player/playerglobal/index.js +224 -0
  268. package/dist/thread/player/playerglobal/libraries.js +10 -0
  269. package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
  270. package/dist/thread/player/playerglobal/toplevel.js +122 -0
  271. package/dist/thread/player/scripting/clipboard.js +146 -0
  272. package/dist/thread/player/scripting/code.js +900 -0
  273. package/dist/thread/player/scripting/evaluate.js +144 -0
  274. package/dist/thread/player/scripting/events.js +172 -0
  275. package/dist/thread/player/scripting/handover.js +182 -0
  276. package/dist/thread/player/scripting/lazy.js +38 -0
  277. package/dist/thread/player/scripting/lifecycle.js +272 -0
  278. package/dist/thread/player/scripting/loads.js +860 -0
  279. package/dist/thread/player/scripting/sha256.js +95 -0
  280. package/dist/thread/player/scripting/symbols.js +348 -0
  281. package/dist/thread/player/scripting/timers.js +434 -0
  282. package/dist/thread/player/scripting/workers.js +923 -0
  283. package/dist/thread/player/scripting.js +1018 -0
  284. package/dist/thread/player/stage.js +4 -0
  285. package/dist/thread/player/text/csm.js +113 -0
  286. package/dist/thread/player/text/css.js +167 -0
  287. package/dist/thread/player/text/fonts.js +97 -0
  288. package/dist/thread/player/text/layout.js +393 -0
  289. package/dist/thread/player/text/static.js +109 -0
  290. package/dist/thread/player/text/text.js +431 -0
  291. package/dist/thread/player/workers/thread.js +159 -0
  292. package/dist/thread/player/workers/wire.js +198 -0
  293. package/dist/thread/player-hosts/web-worker.js +19 -0
  294. package/dist/thread/runtime/avm1/activation.js +89 -0
  295. package/dist/thread/runtime/avm1/case.js +249 -0
  296. package/dist/thread/runtime/avm1/clips.js +334 -0
  297. package/dist/thread/runtime/avm1/control.js +280 -0
  298. package/dist/thread/runtime/avm1/errors.js +50 -0
  299. package/dist/thread/runtime/avm1/functions.js +249 -0
  300. package/dist/thread/runtime/avm1/globals/array.js +549 -0
  301. package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
  302. package/dist/thread/runtime/avm1/globals/date.js +436 -0
  303. package/dist/thread/runtime/avm1/globals/global.js +344 -0
  304. package/dist/thread/runtime/avm1/globals/math.js +139 -0
  305. package/dist/thread/runtime/avm1/globals/number.js +93 -0
  306. package/dist/thread/runtime/avm1/globals/string.js +201 -0
  307. package/dist/thread/runtime/avm1/globals/timers.js +129 -0
  308. package/dist/thread/runtime/avm1/host.js +5 -0
  309. package/dist/thread/runtime/avm1/index.js +14 -0
  310. package/dist/thread/runtime/avm1/inheritance.js +132 -0
  311. package/dist/thread/runtime/avm1/numbers.js +298 -0
  312. package/dist/thread/runtime/avm1/objects.js +896 -0
  313. package/dist/thread/runtime/avm1/operators.js +170 -0
  314. package/dist/thread/runtime/avm1/realm.js +529 -0
  315. package/dist/thread/runtime/avm1/runtime.js +882 -0
  316. package/dist/thread/runtime/avm1/scope.js +385 -0
  317. package/dist/thread/runtime/avm1/urls.js +180 -0
  318. package/dist/thread/runtime/avm1/values.js +97 -0
  319. package/dist/thread/runtime/avm2/amf-classes.js +66 -0
  320. package/dist/thread/runtime/avm2/amf.js +801 -0
  321. package/dist/thread/runtime/avm2/array-conversion.js +100 -0
  322. package/dist/thread/runtime/avm2/builtin-library.js +21 -0
  323. package/dist/thread/runtime/avm2/cache-fill.js +86 -0
  324. package/dist/thread/runtime/avm2/classes.js +211 -0
  325. package/dist/thread/runtime/avm2/definitions.js +69 -0
  326. package/dist/thread/runtime/avm2/descriptors.js +5 -0
  327. package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
  328. package/dist/thread/runtime/avm2/domain-memory.js +75 -0
  329. package/dist/thread/runtime/avm2/domain.js +280 -0
  330. package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
  331. package/dist/thread/runtime/avm2/enumeration.js +393 -0
  332. package/dist/thread/runtime/avm2/errors.js +45 -0
  333. package/dist/thread/runtime/avm2/float-library.js +66 -0
  334. package/dist/thread/runtime/avm2/float.js +26 -0
  335. package/dist/thread/runtime/avm2/hooks.js +19 -0
  336. package/dist/thread/runtime/avm2/index.js +38 -0
  337. package/dist/thread/runtime/avm2/messages.js +177 -0
  338. package/dist/thread/runtime/avm2/method-factories.js +95 -0
  339. package/dist/thread/runtime/avm2/modules.js +105 -0
  340. package/dist/thread/runtime/avm2/names.js +248 -0
  341. package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
  342. package/dist/thread/runtime/avm2/natives/array.js +390 -0
  343. package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
  344. package/dist/thread/runtime/avm2/natives/case.js +88 -0
  345. package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
  346. package/dist/thread/runtime/avm2/natives/date.js +581 -0
  347. package/dist/thread/runtime/avm2/natives/define.js +130 -0
  348. package/dist/thread/runtime/avm2/natives/describe.js +351 -0
  349. package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
  350. package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
  351. package/dist/thread/runtime/avm2/natives/float.js +96 -0
  352. package/dist/thread/runtime/avm2/natives/index.js +64 -0
  353. package/dist/thread/runtime/avm2/natives/json.js +514 -0
  354. package/dist/thread/runtime/avm2/natives/number.js +162 -0
  355. package/dist/thread/runtime/avm2/natives/object.js +237 -0
  356. package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
  357. package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
  358. package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
  359. package/dist/thread/runtime/avm2/natives/shell.js +557 -0
  360. package/dist/thread/runtime/avm2/natives/sort.js +377 -0
  361. package/dist/thread/runtime/avm2/natives/string.js +132 -0
  362. package/dist/thread/runtime/avm2/natives/sync.js +821 -0
  363. package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
  364. package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
  365. package/dist/thread/runtime/avm2/natives/vector.js +406 -0
  366. package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
  367. package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
  368. package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
  369. package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
  370. package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
  371. package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
  372. package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
  373. package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
  374. package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
  375. package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
  376. package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
  377. package/dist/thread/runtime/avm2/number-strings.js +110 -0
  378. package/dist/thread/runtime/avm2/numbers.js +558 -0
  379. package/dist/thread/runtime/avm2/options.js +16 -0
  380. package/dist/thread/runtime/avm2/player-messages.js +550 -0
  381. package/dist/thread/runtime/avm2/property-cache.js +135 -0
  382. package/dist/thread/runtime/avm2/runtime.js +2644 -0
  383. package/dist/thread/runtime/avm2/traits.js +509 -0
  384. package/dist/thread/runtime/index.js +7 -0
  385. package/dist/web-worker.d.ts +2 -0
  386. package/dist/web-worker.d.ts.map +1 -0
  387. package/dist/web-worker.js +20 -0
  388. package/dist/web-worker.js.map +1 -0
  389. package/dist/websocket.d.ts +4 -0
  390. package/dist/websocket.d.ts.map +1 -0
  391. package/dist/websocket.js +27 -0
  392. package/dist/websocket.js.map +1 -0
  393. package/dist/workers.d.ts +35 -0
  394. package/dist/workers.d.ts.map +1 -0
  395. package/dist/workers.js +171 -0
  396. package/dist/workers.js.map +1 -0
  397. package/package.json +62 -3
  398. package/src/indexeddb.ts +227 -0
  399. package/src/node-worker.ts +13 -0
  400. package/src/node.ts +49 -0
  401. package/src/precompiled.ts +166 -0
  402. package/src/stage3d.ts +76 -0
  403. package/src/web-worker.ts +24 -0
  404. package/src/websocket.ts +32 -0
  405. package/src/workers.ts +255 -0
@@ -0,0 +1,405 @@
1
+ /**
2
+ * Compiles ABC and AVM1 bytecode to ES modules.
3
+ *
4
+ * The compiler itself is AssemblyScript (assembly/), built to codegen.wasm.
5
+ * This wrapper instantiates it and gives its exports their types. The same wasm runs as the browser JIT
6
+ * (a module per ABC as its SWF loads) and as the ahead-of-time compiler,
7
+ * so both produce identical output. See docs/architecture/overview.md.
8
+ */
9
+ import { AIR_API_VERSION, API_VERSION, checkApiVersion } from "../format/index.js";
10
+ import { instantiate } from "./codegen.js";
11
+ /** Bumped whenever generated code or the runtime ABI it calls changes. */
12
+ export const COMPILER_VERSION = "0.0.0";
13
+ // The API versions the player and the swf2es command reset the compiler
14
+ // with, which module cache keys name: Flash Player's, and AIR's, whose
15
+ // series has the names Flash Player's leaves out. format's, which the
16
+ // runtime takes too.
17
+ export { AIR_API_VERSION, API_VERSION };
18
+ /** The text whose SHA-256 is a LibraryDigest's, for ABC `index`, any added after the first `count`. */
19
+ export function libraryLog(codegen, index, count) {
20
+ return codegen.context(index, 0, count)?.log ?? "";
21
+ }
22
+ /**
23
+ * The text of ABC `index`'s module cache key, whose UTF-8's SHA-256 is the
24
+ * key: what the module depends on, the compiler's identity, the API
25
+ * version, every ABC its domain sees, by hash and whether it is a library,
26
+ * those added after it included, its own place among them, and the
27
+ * compiler's log about them (see Codegen.context), the libraries' part by
28
+ * its digest once taken. The player's module cache and the swf2es command
29
+ * both key by it, so that the command's modules are the cache's. Null
30
+ * where there is no context.
31
+ */
32
+ export function moduleKey(codegen, index, abcs, libraries) {
33
+ const context = codegen.context(index, libraries?.count ?? 0);
34
+ if (!context) {
35
+ return null;
36
+ }
37
+ return JSON.stringify({
38
+ compiler: codegen.identity,
39
+ api: codegen.apiVersion,
40
+ abcs: context.abcs.map((i) => `${abcs.builtins[i] ? "builtin " : ""}${abcs.hashes[i]}`),
41
+ own: context.own,
42
+ libraries,
43
+ log: context.log,
44
+ });
45
+ }
46
+ /**
47
+ * The text of the module cache key of a SWF's AVM1 module, whose UTF-8's
48
+ * SHA-256 is the key: the compiler's identity, the SWF's version, which
49
+ * picks the operations its code calls, and `hash`, the SHA-256 of the
50
+ * SWF's decompressed bytes, which hold its blocks. An AVM1 module links to
51
+ * nothing, so nothing else goes in.
52
+ */
53
+ export function actionsKey(codegen, hash, version) {
54
+ return JSON.stringify({ compiler: codegen.identity, avm1: version, swf: hash });
55
+ }
56
+ /**
57
+ * Instantiate the compiler from a compiled codegen.wasm module. Loading the
58
+ * bytes is left to the caller (fetch in browsers, fs in node), which keeps
59
+ * this package free of I/O. The file ships as `@swf2es/codegen/codegen.wasm`.
60
+ */
61
+ export async function createCodegen(module) {
62
+ const wasm = await instantiate(module, { env: {} });
63
+ const version = wasm.compilerVersion();
64
+ if (version !== COMPILER_VERSION) {
65
+ throw new Error(`codegen.wasm is version ${version} but the wrapper expects ${COMPILER_VERSION}`);
66
+ }
67
+ // Of the same version, but built before its modules were handed out in
68
+ // place: its *Bytes exports return copies, which this wrapper cannot read.
69
+ // Asked of the module, as the bindings define every export they know of.
70
+ if (!WebAssembly.Module.exports(module).some((e) => e.name === "outputLength")) {
71
+ throw new Error("codegen.wasm has no outputLength export, which the wrapper expects: it is older than the wrapper");
72
+ }
73
+ // codegen.wasm uses AssemblyScript's minimal runtime, which collects
74
+ // garbage only when asked. Nothing runs in wasm between calls, so that is
75
+ // when: every COLLECT_EVERY calls, and after a call that grew memory.
76
+ // Memory never shrinks, so collecting only on growth would let each
77
+ // cycle's garbage grow it a little further.
78
+ let size = wasm.memory.buffer.byteLength;
79
+ let calls = 0;
80
+ let methodBytes = 0;
81
+ // Whether the domain has an ABC to compile: asking before is a mistake worth a message, not a trap.
82
+ let added = 0;
83
+ const last = (what) => {
84
+ if (added === 0) {
85
+ throw new Error(`${what}: no ABC has been added to the domain`);
86
+ }
87
+ };
88
+ // An ABC by its position among those added, -1 for the last.
89
+ const indexOf = (index) => {
90
+ if (index >= 0 && (!Number.isInteger(index) || index >= added)) {
91
+ throw new Error(`ABC ${index}: only ${added} have been added to the domain`);
92
+ }
93
+ return index < 0 ? -1 : index;
94
+ };
95
+ // ABC `index`'s module, its source map and entries kept for `keep`. A
96
+ // module is never empty: the ABC was of a dropped application domain.
97
+ const moduleOf = (hashes, index, keep, lazy = false) => {
98
+ // Only the hashes the module names: joining every ABC's for each
99
+ // compile took megabytes of codegen's memory a few thousand loads on.
100
+ const at = indexOf(index);
101
+ const own = at < 0 ? added - 1 : at;
102
+ const linked = collected(wasm.domainLinked(at));
103
+ const named = [hashes[own] ?? ""];
104
+ for (const i of linked ? linked.split(",") : []) {
105
+ named.push(hashes[Number(i)] ?? "");
106
+ }
107
+ // Its bytes decoded here: lifted as a string, a module of megabytes took
108
+ // longer than compiling it. The emitter writes only well-formed UTF-8,
109
+ // which decodes alike either way.
110
+ const address = lazy
111
+ ? wasm.domainLazyModuleBytes(named.join("\n"), at)
112
+ : wasm.domainModuleBytes(named.join("\n"), at, keep, true);
113
+ const module = collected(handed(address, wasm.outputLength()), lazy);
114
+ if (module === "") {
115
+ throw new Error(`ABC ${index}: its application domain was dropped`);
116
+ }
117
+ return module;
118
+ };
119
+ const ranges = (actions) => [
120
+ Int32Array.from(actions.blocks, (b) => b.offset),
121
+ Int32Array.from(actions.blocks, (b) => b.length),
122
+ ];
123
+ // The SWFs whose blocks or units compileActionBlocks and compileActionUnit
124
+ // compile, which wasm holds by a handle each: the few used last, so that
125
+ // blocks and units of SWFs that alternate do not copy them in again, each
126
+ // let go as its bytes are collected.
127
+ const holding = new WeakMap();
128
+ const holds = [];
129
+ let handles = 0;
130
+ let copies = 0;
131
+ const release = (handle) => {
132
+ const at = holds.indexOf(handle);
133
+ if (at >= 0) {
134
+ holds.splice(at, 1);
135
+ wasm.actionsRelease(handle);
136
+ }
137
+ };
138
+ const collectedSwfs = new FinalizationRegistry(release);
139
+ const hold = (bytes, actions) => {
140
+ const known = holding.get(bytes);
141
+ if (known !== undefined && known.actions === actions && holds.includes(known.handle)) {
142
+ holds.splice(holds.indexOf(known.handle), 1);
143
+ holds.push(known.handle);
144
+ return known.handle;
145
+ }
146
+ if (known !== undefined) {
147
+ release(known.handle);
148
+ collectedSwfs.unregister(known);
149
+ }
150
+ const handle = ++handles;
151
+ const [offsets, lengths] = ranges(actions);
152
+ wasm.actionsHold(handle, bytes, offsets, lengths);
153
+ copies++;
154
+ const record = { handle, actions };
155
+ holding.set(bytes, record);
156
+ collectedSwfs.register(bytes, handle, record);
157
+ holds.push(handle);
158
+ while (holds.length > HELD_SWFS) {
159
+ release(holds[0]);
160
+ }
161
+ return handle;
162
+ };
163
+ const actionsModule = (bytes, actions, keep) => {
164
+ const [offsets, lengths] = ranges(actions);
165
+ const address = wasm.actionsModuleBytes(bytes, offsets, lengths, actions.version, keep);
166
+ return collected(handed(address, wasm.outputLength()));
167
+ };
168
+ // UTF-8 a call handed out in codegen's memory, not copied (see handOut in
169
+ // assembly/output.ts), decoded before anything else calls in: the next
170
+ // call may grow memory or move them, and a collection may free them.
171
+ const handed = (address, length) => length === 0 ? "" : utf8.decode(new Uint8Array(wasm.memory.buffer, address, length));
172
+ const stamps = WebAssembly.Module.customSections(module, "swf2es.build");
173
+ const identity = stamps.length ? String.fromCharCode(...new Uint8Array(stamps[0])) : null;
174
+ let epoch = 0;
175
+ let apiVersion = API_VERSION;
176
+ const collected = (result, reclaim = false) => {
177
+ const grown = wasm.memory.buffer.byteLength;
178
+ if (reclaim || grown > size || ++calls >= COLLECT_EVERY) {
179
+ wasm.__collect();
180
+ size = grown;
181
+ calls = 0;
182
+ methodBytes = 0;
183
+ }
184
+ return result;
185
+ };
186
+ return {
187
+ identity,
188
+ abcVersion(abc) {
189
+ const packed = collected(wasm.abcVersion(abc));
190
+ return packed < 0 ? null : { major: packed >>> 16, minor: packed & 0xffff };
191
+ },
192
+ get epoch() {
193
+ return epoch;
194
+ },
195
+ reset(version = API_VERSION) {
196
+ checkApiVersion(version);
197
+ added = 0;
198
+ epoch++;
199
+ apiVersion = version;
200
+ collected(wasm.domainReset(version));
201
+ },
202
+ get apiVersion() {
203
+ return apiVersion;
204
+ },
205
+ add(abc, builtin = false, appDomain = 0) {
206
+ const error = collected(wasm.domainAdd(abc, builtin, appDomain));
207
+ if (error < 0) {
208
+ throw new Error(`application domain ${appDomain}: never made, or dropped`);
209
+ }
210
+ if (error === 0) {
211
+ added++;
212
+ }
213
+ return error;
214
+ },
215
+ childDomain(parent) {
216
+ const domain = collected(wasm.domainChild(parent));
217
+ if (domain < 0) {
218
+ throw new Error(`application domain ${parent}: never made, or dropped`);
219
+ }
220
+ return domain;
221
+ },
222
+ dropDomain(appDomain, of = epoch) {
223
+ if (of === epoch) {
224
+ collected(wasm.domainDrop(appDomain));
225
+ }
226
+ },
227
+ evictDomain(appDomain) {
228
+ collected(wasm.domainEvict(appDomain));
229
+ },
230
+ usage() {
231
+ const [live, dead, memory] = collected(wasm.domainUsage()).split(" ").map(Number);
232
+ return { live, dead, memory };
233
+ },
234
+ compact() {
235
+ // A rebuild makes new tables while the old are live: what earlier
236
+ // calls left is collected first, and the old tables once it is done,
237
+ // before the next call's allocations would grow memory past them.
238
+ if (!collected(wasm.domainWantsCompact())) {
239
+ return false;
240
+ }
241
+ wasm.__collect();
242
+ calls = 0;
243
+ if (!wasm.domainCompact()) {
244
+ return false;
245
+ }
246
+ wasm.__collect();
247
+ size = wasm.memory.buffer.byteLength;
248
+ calls = 0;
249
+ return true;
250
+ },
251
+ isLive(appDomain) {
252
+ return collected(wasm.domainState(appDomain)) === 0;
253
+ },
254
+ reviveDomain(appDomain, abcs) {
255
+ // Its ABCs' bytes are copied into the compiler only if a rebuild let go of them.
256
+ let revived = collected(wasm.domainRevive(appDomain));
257
+ if (revived < 0) {
258
+ for (const [index, bytes] of abcs) {
259
+ const error = collected(wasm.domainRestore(index, bytes));
260
+ if (error !== 0) {
261
+ throw new Error(`ABC ${index}: not of an evicted domain, or rejected (${error})`);
262
+ }
263
+ }
264
+ revived = collected(wasm.domainRevive(appDomain));
265
+ }
266
+ if (revived < 0) {
267
+ throw new Error(`application domain ${appDomain}: not evicted, its parent not live, or an ABC of it not given`);
268
+ }
269
+ if (revived > 0) {
270
+ wasm.__collect();
271
+ size = wasm.memory.buffer.byteLength;
272
+ calls = 0;
273
+ }
274
+ },
275
+ found(d) {
276
+ collected(wasm.domainFound(d.domain, d.nsKind, d.uri, d.name, d.abc, d.asType));
277
+ },
278
+ compile(hashes = [], index = -1) {
279
+ last("compile");
280
+ // Each part a call of its own, collected after it: the module's garbage
281
+ // is gone before its entries are written.
282
+ const module = moduleOf(hashes, index, true);
283
+ const sourceMap = collected(wasm.domainSourceMap());
284
+ const entries = parseEntries(collected(wasm.domainModuleEntries()));
285
+ return { module, sourceMap, entries };
286
+ },
287
+ compileModule(hashes = [], index = -1) {
288
+ last("compileModule");
289
+ return moduleOf(hashes, index, false);
290
+ },
291
+ compileLazyModule(hashes = [], index = -1) {
292
+ last("compileLazyModule");
293
+ return moduleOf(hashes, index, false, true);
294
+ },
295
+ context(index = -1, after = 0, upTo = -1) {
296
+ if (added === 0) {
297
+ return null;
298
+ }
299
+ const text = collected(wasm.domainContext(indexOf(index), after, upTo));
300
+ if (text === "") {
301
+ return null;
302
+ }
303
+ const first = text.indexOf("\n");
304
+ const second = text.indexOf("\n", first + 1);
305
+ const abcs = text.slice(0, first);
306
+ return {
307
+ abcs: abcs ? abcs.split(",").map(Number) : [],
308
+ own: Number(text.slice(first + 1, second < 0 ? text.length : second)),
309
+ log: second < 0 ? "" : text.slice(second + 1),
310
+ };
311
+ },
312
+ revision() {
313
+ return `${epoch} ${wasm.domainRevision()}`;
314
+ },
315
+ compileModuleLogged(hashes = [], index = -1) {
316
+ last("compileModuleLogged");
317
+ const mark = wasm.domainLogMark();
318
+ const module = moduleOf(hashes, index, false);
319
+ const log = collected(wasm.domainLogSince(mark, indexOf(index)));
320
+ return { module, log: log === "!" ? null : log };
321
+ },
322
+ replay(log, index = -1) {
323
+ last("replay");
324
+ return collected(wasm.domainReplay(log, indexOf(index)));
325
+ },
326
+ compileMethods(bodies, index = -1) {
327
+ last("compileMethods");
328
+ const indices = bodies.filter((b) => Number.isInteger(b) && b >= 0);
329
+ if (indices.length === 0) {
330
+ return new Map();
331
+ }
332
+ const address = wasm.domainEmitEachBytes(indices.join(","), true, indexOf(index));
333
+ const length = wasm.outputLength();
334
+ methodBytes += length;
335
+ const text = handed(address, length);
336
+ return parseEntries(collected(text, methodBytes >= COLLECT_METHOD_BYTES));
337
+ },
338
+ compileActions(bytes, actions) {
339
+ const module = actionsModule(bytes, actions, true);
340
+ const entries = parseEntries(collected(wasm.actionsModuleEntries()));
341
+ const units = new Map();
342
+ for (const item of collected(wasm.actionsModuleUnits()).split("\u0002")) {
343
+ const [key, numbers, limits, code] = item.split("\u0001");
344
+ if (code !== undefined) {
345
+ const [at, end, bound, five] = numbers.split(",").map(Number);
346
+ const [high, reach] = limits.split(",").map(Number);
347
+ units.set(key, { code, high, reach, unit: { at, end, bound, five: five !== 0 } });
348
+ }
349
+ }
350
+ return { module, entries: actions.blocks.map((_, k) => entries.get(k) ?? ""), units };
351
+ },
352
+ compileActionsModule(bytes, actions) {
353
+ return actionsModule(bytes, actions, false);
354
+ },
355
+ compileActionBlocks(bytes, actions, blocks) {
356
+ const indices = blocks.filter((b) => Number.isInteger(b) && b >= 0);
357
+ if (indices.length === 0) {
358
+ return new Map();
359
+ }
360
+ // The SWF held, as for units: a block needs it whole, and copying it
361
+ // in for each block cost a copy of the SWF in codegen's memory
362
+ // beside the one held for units, and the time to copy it.
363
+ const handle = hold(bytes, actions);
364
+ const address = wasm.actionsHeldEmitEachBytes(handle, actions.version, indices.join(","));
365
+ const text = handed(address, wasm.outputLength());
366
+ // A block's analysis can go before the next block runs.
367
+ return parseEntries(collected(text, true));
368
+ },
369
+ compileActionUnit(bytes, actions, { at, end, bound, five }) {
370
+ const handle = hold(bytes, actions);
371
+ const address = wasm.actionsHeldUnitBytes(handle, actions.version, at, end, bound, five);
372
+ const code = handed(address, wasm.outputLength());
373
+ const [high, reach] = wasm.actionsUnitLimits();
374
+ return collected({ code, high, reach });
375
+ },
376
+ releaseActions(bytes) {
377
+ const known = holding.get(bytes);
378
+ if (known !== undefined) {
379
+ release(known.handle);
380
+ holding.delete(bytes);
381
+ collectedSwfs.unregister(known);
382
+ }
383
+ },
384
+ heldActions() {
385
+ return { held: collected(wasm.actionsHeldCount()), copies };
386
+ },
387
+ };
388
+ }
389
+ /** Entries as the wasm writes them: for each, the body's index, U+0001, its entry, U+0002. */
390
+ function parseEntries(text) {
391
+ const entries = new Map();
392
+ for (const item of text.split("\u0002")) {
393
+ const at = item.indexOf("\u0001");
394
+ if (at > 0) {
395
+ entries.set(Number(item.slice(0, at)), item.slice(at + 1));
396
+ }
397
+ }
398
+ return entries;
399
+ }
400
+ const COLLECT_EVERY = 64;
401
+ /** How many SWFs whose blocks or units are compiled codegen holds a copy of at most. */
402
+ const HELD_SWFS = 4;
403
+ // Large method entries should not accumulate sixty-four calls of garbage.
404
+ const COLLECT_METHOD_BYTES = 256 * 1024;
405
+ const utf8 = new TextDecoder();
@@ -0,0 +1,126 @@
1
+ // The names an ABC refers to, read from its constant pool alone: each
2
+ // qualified name, "package::Name" as avmplus writes a definition's (a
3
+ // top-level one bare), from the pool's QNames in a package's namespace,
4
+ // and from each Multiname, once for every package namespace in its set,
5
+ // as a lookup that names the class unqualified finds it in one of them.
6
+ // What it may name is enough to tell which libraries a SWF expects, as the
7
+ // web element tells an AIR application's SWF from one for the browser.
8
+ import { utf8 } from "./display.js";
9
+ const CONSTANT_Namespace = 0x08;
10
+ const CONSTANT_PackageNamespace = 0x16;
11
+ const CONSTANT_QName = 0x07;
12
+ const CONSTANT_QNameA = 0x0d;
13
+ const CONSTANT_RTQName = 0x0f;
14
+ const CONSTANT_RTQNameA = 0x10;
15
+ const CONSTANT_RTQNameL = 0x11;
16
+ const CONSTANT_RTQNameLA = 0x12;
17
+ const CONSTANT_Multiname = 0x09;
18
+ const CONSTANT_MultinameA = 0x0e;
19
+ const CONSTANT_MultinameL = 0x1b;
20
+ const CONSTANT_MultinameLA = 0x1c;
21
+ const CONSTANT_TypeName = 0x1d;
22
+ /** The qualified names `abc` may refer to; what it cannot read stops the reading, keeping what came before. */
23
+ export function abcReferences(abc) {
24
+ const names = new Set();
25
+ let at = 4;
26
+ const u30 = () => {
27
+ let value = 0;
28
+ for (let shift = 0; shift < 35; shift += 7) {
29
+ if (at >= abc.length) {
30
+ throw new RangeError("ABC cut short");
31
+ }
32
+ const b = abc[at++];
33
+ value += (b & 0x7f) * 2 ** shift;
34
+ if ((b & 0x80) === 0) {
35
+ break;
36
+ }
37
+ }
38
+ return value;
39
+ };
40
+ const skipU30s = (count) => {
41
+ for (let i = 1; i < count; i++) {
42
+ u30();
43
+ }
44
+ };
45
+ try {
46
+ skipU30s(u30()); // ints
47
+ skipU30s(u30()); // uints
48
+ const doubles = u30();
49
+ at += Math.max(0, doubles - 1) * 8;
50
+ // From 47.16 AIR's ABCs have a pool of 4-byte floats next (codegen's parse.ts).
51
+ const minor = abc[0] | (abc[1] << 8);
52
+ const major = abc[2] | (abc[3] << 8);
53
+ if (major === 47 && minor >= 16) {
54
+ const floats = u30();
55
+ at += Math.max(0, floats - 1) * 4;
56
+ }
57
+ const strings = [""];
58
+ for (let i = 1, n = u30(); i < n; i++) {
59
+ const length = u30();
60
+ strings.push(utf8(abc.subarray(at, at + length)));
61
+ at += length;
62
+ }
63
+ // A package's namespace by its URI; null for any other kind.
64
+ const namespaces = [null];
65
+ for (let i = 1, n = u30(); i < n; i++) {
66
+ const kind = abc[at++];
67
+ const name = strings[u30()] ?? "";
68
+ namespaces.push(kind === CONSTANT_PackageNamespace || kind === CONSTANT_Namespace ? name : null);
69
+ }
70
+ const sets = [[]];
71
+ for (let i = 1, n = u30(); i < n; i++) {
72
+ const set = [];
73
+ for (let j = 0, count = u30(); j < count; j++) {
74
+ set.push(u30());
75
+ }
76
+ sets.push(set);
77
+ }
78
+ const add = (ns, name) => {
79
+ if (ns !== null && ns !== undefined && name) {
80
+ names.add(ns === "" ? name : `${ns}::${name}`);
81
+ }
82
+ };
83
+ for (let i = 1, n = u30(); i < n; i++) {
84
+ const kind = abc[at++];
85
+ switch (kind) {
86
+ case CONSTANT_QName:
87
+ case CONSTANT_QNameA: {
88
+ const ns = u30();
89
+ add(namespaces[ns], strings[u30()]);
90
+ break;
91
+ }
92
+ case CONSTANT_RTQName:
93
+ case CONSTANT_RTQNameA:
94
+ u30();
95
+ break;
96
+ case CONSTANT_RTQNameL:
97
+ case CONSTANT_RTQNameLA:
98
+ break;
99
+ case CONSTANT_Multiname:
100
+ case CONSTANT_MultinameA: {
101
+ const name = strings[u30()];
102
+ for (const ns of sets[u30()] ?? []) {
103
+ add(namespaces[ns], name);
104
+ }
105
+ break;
106
+ }
107
+ case CONSTANT_MultinameL:
108
+ case CONSTANT_MultinameLA:
109
+ u30();
110
+ break;
111
+ case CONSTANT_TypeName: {
112
+ u30();
113
+ skipU30s(u30() + 1);
114
+ break;
115
+ }
116
+ default:
117
+ // A kind no ABC has: what follows cannot be read.
118
+ return names;
119
+ }
120
+ }
121
+ }
122
+ catch {
123
+ // Cut short: what was read is what it names.
124
+ }
125
+ return names;
126
+ }