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.
- package/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { transpileAvm2, AVM2_RUNTIME_STUB } from '../transpiler/avm2/avm2-transpiler.js';
|
|
3
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
4
|
+
|
|
5
|
+
function buildCustomNamespaceAbc(builtin = false) {
|
|
6
|
+
const bytes = [];
|
|
7
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
8
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
9
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
10
|
+
const body = (methodIndex, code) => {
|
|
11
|
+
u30(methodIndex); u30(2); u30(builtin && methodIndex === 1 ? 2 : 1); u30(0); u30(1); u30(code.length);
|
|
12
|
+
for (const b of code) bytes.push(b);
|
|
13
|
+
u30(0); u30(0);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
u16(16); u16(46);
|
|
17
|
+
u30(0); u30(0); u30(0);
|
|
18
|
+
u30(9); str(''); str('App'); str('Object'); str(builtin ? 'test' : 'value'); str('readCustom');
|
|
19
|
+
str(builtin ? 'http://adobe.com/AS3/2006/builtin' : 'privateNS'); str('public'); str('secret');
|
|
20
|
+
u30(3); bytes.push(0x16); u30(1); bytes.push(0x08); u30(6);
|
|
21
|
+
u30(0);
|
|
22
|
+
u30(6);
|
|
23
|
+
bytes.push(0x07); u30(1); u30(2); // App
|
|
24
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
25
|
+
bytes.push(0x07); u30(1); u30(4); // public value
|
|
26
|
+
bytes.push(0x07); u30(2); u30(4); // privateNS::value
|
|
27
|
+
bytes.push(0x07); u30(1); u30(5); // readCustom
|
|
28
|
+
u30(3);
|
|
29
|
+
for (let i = 0; i < 3; i++) {
|
|
30
|
+
const hasArg = builtin && i === 1;
|
|
31
|
+
u30(hasArg ? 1 : 0); u30(0); if (hasArg) u30(0); u30(0); bytes.push(0);
|
|
32
|
+
}
|
|
33
|
+
u30(0); // metadata
|
|
34
|
+
u30(1); // classes
|
|
35
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(3); // instance header, 3 traits
|
|
36
|
+
u30(3); bytes.push(0); u30(1); u30(0); u30(0); // public slot value id 1
|
|
37
|
+
u30(4); bytes.push(0); u30(2); u30(0); u30(0); // custom slot value id 2
|
|
38
|
+
u30(5); bytes.push(1); u30(1); u30(1); // readCustom method 1
|
|
39
|
+
u30(2); u30(0); // cinit 2, no class traits
|
|
40
|
+
u30(0); // scripts
|
|
41
|
+
u30(3); // method bodies
|
|
42
|
+
body(0, [0xd0, 0x2c, 7, 0x61, 3, 0xd0, 0x2c, 8, 0x61, 4, 0x47]); // value="public"; custom value="secret"
|
|
43
|
+
body(1, builtin
|
|
44
|
+
? [0xd1, 0x2c, 7, 0x46, 4, 1, 0x48] // return arg.AS3::test("public")
|
|
45
|
+
: [0x60, 4, 0x48]); // return privateNS::value through getlex
|
|
46
|
+
body(2, [0x47]);
|
|
47
|
+
return new Uint8Array(bytes);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('AVM2 custom namespace properties', () => {
|
|
51
|
+
it('keeps custom namespace traits distinct from public same-named traits', () => {
|
|
52
|
+
const diagnostics = new DiagnosticsCollector();
|
|
53
|
+
const js = transpileAvm2(buildCustomNamespaceAbc(), diagnostics);
|
|
54
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
55
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
56
|
+
expect(js).toMatch(/__avm2ns_8_uri_[0-9a-f]+_value/);
|
|
57
|
+
|
|
58
|
+
const App = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn App;`)();
|
|
59
|
+
const value = new App();
|
|
60
|
+
expect(value.value).toBe('public');
|
|
61
|
+
expect(value.readCustom()).toBe('secret');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('calls native JavaScript methods for names in the AS3 builtin namespace', () => {
|
|
65
|
+
const diagnostics = new DiagnosticsCollector();
|
|
66
|
+
const js = transpileAvm2(buildCustomNamespaceAbc(true), diagnostics);
|
|
67
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
68
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
69
|
+
const key = /__avm2ns_8_uri_[0-9a-f]+_test/.exec(js)?.[0];
|
|
70
|
+
expect(key).toBeTruthy();
|
|
71
|
+
|
|
72
|
+
const App = new Function(`${AVM2_RUNTIME_STUB}\n${js}\nreturn App;`)();
|
|
73
|
+
const instance = new App();
|
|
74
|
+
expect(instance.readCustom(/^public$/)).toBe(true);
|
|
75
|
+
expect(instance.readCustom(/^private$/)).toBe(false);
|
|
76
|
+
expect(instance.readCustom({ [key]: () => 'explicit', test: () => 'fallback' })).toBe('explicit');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('keeps private namespace identities distinct across ABC blocks', () => {
|
|
80
|
+
const diagnostics = new DiagnosticsCollector();
|
|
81
|
+
const abcOne = transpileAvm2(buildPrivateNamespaceAbc('PrivateOwner', false), diagnostics);
|
|
82
|
+
const abcTwo = transpileAvm2(buildPrivateNamespaceAbc('PrivateReader', true), diagnostics);
|
|
83
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
84
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
85
|
+
const firstKey = /(__avm2ns_5_abc_[0-9a-f]+_[0-9]+_ns_2_secret)/.exec(abcOne)?.[1];
|
|
86
|
+
const secondKey = /(__avm2ns_5_abc_[0-9a-f]+_[0-9]+_ns_2_secret)/.exec(abcTwo)?.[1];
|
|
87
|
+
expect(firstKey).toBeTruthy();
|
|
88
|
+
expect(secondKey).toBeTruthy();
|
|
89
|
+
expect(firstKey).not.toBe(secondKey);
|
|
90
|
+
|
|
91
|
+
const classes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${abcOne}\n${abcTwo}\n_runAvm2Initializers();\nreturn { PrivateOwner, PrivateReader };`)();
|
|
92
|
+
const owner = new classes.PrivateOwner();
|
|
93
|
+
const reader = new classes.PrivateReader();
|
|
94
|
+
expect(owner.readPrivate()).toBe('owned');
|
|
95
|
+
expect(reader.readPrivate(owner)).toBeUndefined();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
function buildPrivateNamespaceAbc(className, reader) {
|
|
100
|
+
const bytes = [];
|
|
101
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
102
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
103
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
104
|
+
const body = (methodIndex, code, localCount = 1) => {
|
|
105
|
+
u30(methodIndex); u30(2); u30(localCount); u30(0); u30(1); u30(code.length);
|
|
106
|
+
for (const b of code) bytes.push(b);
|
|
107
|
+
u30(0); u30(0);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
u16(16); u16(46);
|
|
111
|
+
u30(0); u30(0); u30(0);
|
|
112
|
+
u30(8); str(''); str(className); str('Object'); str('secret'); str('privateNS'); str('readPrivate'); str('owned');
|
|
113
|
+
u30(3); bytes.push(0x16); u30(1); bytes.push(0x05); u30(5);
|
|
114
|
+
u30(0);
|
|
115
|
+
u30(5);
|
|
116
|
+
bytes.push(0x07); u30(1); u30(2); // class
|
|
117
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
118
|
+
bytes.push(0x07); u30(2); u30(4); // privateNS::secret
|
|
119
|
+
bytes.push(0x07); u30(1); u30(6); // public method
|
|
120
|
+
u30(3);
|
|
121
|
+
for (let m = 0; m < 3; m++) {
|
|
122
|
+
const hasArg = reader && m === 1;
|
|
123
|
+
u30(hasArg ? 1 : 0); u30(0);
|
|
124
|
+
if (hasArg) u30(0);
|
|
125
|
+
u30(0); bytes.push(0);
|
|
126
|
+
}
|
|
127
|
+
u30(0); // metadata
|
|
128
|
+
u30(1); // one class
|
|
129
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(reader ? 1 : 2); // instance traits
|
|
130
|
+
if (!reader) { u30(3); bytes.push(0); u30(1); u30(0); u30(0); } // private slot
|
|
131
|
+
u30(4); bytes.push(1); u30(1); u30(1); // read method
|
|
132
|
+
u30(2); u30(0); // cinit, no static traits
|
|
133
|
+
u30(0); // scripts
|
|
134
|
+
u30(3); // method bodies
|
|
135
|
+
body(0, reader ? [0x47] : [0xd0, 0x2c, 7, 0x61, 3, 0x47]);
|
|
136
|
+
body(1, reader ? [0xd1, 0x66, 3, 0x48] : [0xd0, 0x66, 3, 0x48], reader ? 2 : 1);
|
|
137
|
+
body(2, [0x47]);
|
|
138
|
+
return new Uint8Array(bytes);
|
|
139
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { AVM2_RUNTIME_STUB } from '../runtime/avm2-runtime.js';
|
|
4
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
5
|
+
import { AbcReader } from '../transpiler/avm2/abc-reader.js';
|
|
6
|
+
import { transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
7
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
8
|
+
|
|
9
|
+
function reflectionFixture() {
|
|
10
|
+
const bytes = [16, 0, 46, 0, 0, 0, 0];
|
|
11
|
+
const strings = ['Fixture', 'Object', 'String', 'field', 'Inject', 'name', 'other', 'a&"b', 'second', 'hidden'];
|
|
12
|
+
const push = (...values) => bytes.push(...values);
|
|
13
|
+
push(strings.length + 1);
|
|
14
|
+
for (const string of strings) push(string.length, ...new TextEncoder().encode(string));
|
|
15
|
+
push(3, 0x16, 0, 0x05, 0, 0); // public and private namespaces, no namespace sets
|
|
16
|
+
push(6);
|
|
17
|
+
for (let i = 1; i <= 4; i++) push(0x07, 1, i);
|
|
18
|
+
push(0x07, 2, 10);
|
|
19
|
+
push(2); // two methods
|
|
20
|
+
push(2, 0, 3, 3, 0, 0x08, 1, 0, 0x0c); // String, optional String = null
|
|
21
|
+
push(0, 0, 0, 0); // static initializer
|
|
22
|
+
push(1, 5, 2, 6, 7, 8, 9); // Inject with two keys, then two values
|
|
23
|
+
push(1, 1, 2, 1, 0, 0, 2); // one sealed class
|
|
24
|
+
push(4, 0x40, 1, 3, 0, 1, 0); // [Inject] public field:String
|
|
25
|
+
push(5, 0, 2, 3, 0); // private hidden:String
|
|
26
|
+
push(1, 0, 0, 2); // static initializer, no static traits or scripts, two bodies
|
|
27
|
+
push(0, 1, 3, 0, 1, 1, 0x47, 0, 0);
|
|
28
|
+
push(1, 1, 1, 0, 1, 1, 0x47, 0, 0);
|
|
29
|
+
return Uint8Array.from(bytes);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it('reflects public ABC traits, parameter optionality, inheritance and ordered annotations', () => {
|
|
33
|
+
const diagnostics = new DiagnosticsCollector();
|
|
34
|
+
const js = transpileAvm2(reflectionFixture(), diagnostics);
|
|
35
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
36
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
37
|
+
const result = runInNewContext(`${SWFLIB_SOURCE}
|
|
38
|
+
${AVM2_RUNTIME_STUB}
|
|
39
|
+
${js}
|
|
40
|
+
class Marker {}
|
|
41
|
+
_registerAvm2Class(Marker, [], 0, 'Marker', { namespace: 'test' });
|
|
42
|
+
_registerAvm2Interfaces(Marker, [], []);
|
|
43
|
+
_registerAvm2Interfaces(Fixture, ['test.Marker'], null);
|
|
44
|
+
_runAvm2Initializers();
|
|
45
|
+
const describe = swoof.utils.describeType;
|
|
46
|
+
[describe(Fixture).toXMLString(), describe(Object.create(Fixture.prototype)).toXMLString()];
|
|
47
|
+
`);
|
|
48
|
+
expect(result[0]).toContain('<factory type="Fixture"><extendsClass type="Object"/><implementsInterface type="test::Marker"/>');
|
|
49
|
+
expect(result[0]).toContain('<constructor><parameter index="1" type="String" optional="false"/><parameter index="2" type="String" optional="true"/></constructor>');
|
|
50
|
+
expect(result[0]).toContain('<variable name="field" type="String"><metadata name="Inject"><arg key="name" value="a&"b"/><arg key="other" value="second"/></metadata></variable>');
|
|
51
|
+
expect(result[0]).not.toContain('hidden');
|
|
52
|
+
expect(result[1]).toContain('<type name="Fixture" base="Object" isDynamic="false" isFinal="false" isStatic="false">');
|
|
53
|
+
expect(result[1]).not.toContain('<factory');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('calls the native IEventDispatcher trait on a Sprite and recognizes its interface type', () => {
|
|
57
|
+
const result = runInNewContext(`${SWFLIB_SOURCE}
|
|
58
|
+
${AVM2_RUNTIME_STUB}
|
|
59
|
+
const sprite = new swoof.display.Sprite();
|
|
60
|
+
const ns = new (_getlex('Namespace'))('flash.events:IEventDispatcher');
|
|
61
|
+
let received = 0;
|
|
62
|
+
_avm2CallLateProperty(sprite, [ns, 'addEventListener'], ['ready', () => received++]);
|
|
63
|
+
_avm2CallLateProperty(sprite, [ns, 'dispatchEvent'], [new Event('ready')]);
|
|
64
|
+
const dispatcher = swoof.events.IEventDispatcher;
|
|
65
|
+
[received, _isType(sprite, dispatcher), _avm2Call(dispatcher, null, [sprite]) === sprite];
|
|
66
|
+
`);
|
|
67
|
+
expect(result).toEqual([1, true, true]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('decodes ABC signed and unsigned variable-length constant pools without early sign extension', () => {
|
|
71
|
+
const reader = new AbcReader(Uint8Array.of(
|
|
72
|
+
4, 0x78, 0x80, 0x01, 0xff, 0xff, 0xff, 0xff, 0x0f,
|
|
73
|
+
3, 0x92, 0x01, 0xff, 0xff, 0xff, 0xff, 0x0f,
|
|
74
|
+
0, 0, 0, 0, 0,
|
|
75
|
+
));
|
|
76
|
+
const pool = reader.readConstantPool();
|
|
77
|
+
expect(pool.ints).toEqual([0, 120, 128, -1]);
|
|
78
|
+
expect(pool.uints).toEqual([0, 146, 4294967295]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('coerces native package classes when called as functions', () => {
|
|
82
|
+
const result = runInNewContext(`${SWFLIB_SOURCE}
|
|
83
|
+
${AVM2_RUNTIME_STUB}
|
|
84
|
+
const TextField = swoof.text.TextField;
|
|
85
|
+
const field = new TextField();
|
|
86
|
+
const storage = swoof.net.SharedObject.getLocal('example');
|
|
87
|
+
[
|
|
88
|
+
_avm2Call(TextField, null, [field]) === field,
|
|
89
|
+
_avm2Call(TextField, null, [null]) === null,
|
|
90
|
+
_avm2Call(_getlex('Class'), null, [swoof.net.SharedObject]) === storage.constructor,
|
|
91
|
+
storage instanceof swoof.events.EventDispatcher,
|
|
92
|
+
_getlex('flash.utils.Proxy') !== globalThis.Proxy,
|
|
93
|
+
];
|
|
94
|
+
`);
|
|
95
|
+
expect(result).toEqual([true, true, true, true, true]);
|
|
96
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
4
|
+
import { transpileAvm2, AVM2_RUNTIME_STUB } from '../transpiler/avm2/avm2-transpiler.js';
|
|
5
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
6
|
+
|
|
7
|
+
function makeDictionaryFixture() {
|
|
8
|
+
const methods = [
|
|
9
|
+
['storeAndRead', 2, [0xd1, 0xd2, 0x24, 42, 0x61, 1, 0xd1, 0xd2, 0x66, 1, 0x48]],
|
|
10
|
+
['contains', 2, [0xd2, 0xd1, 0xb4, 0x48]],
|
|
11
|
+
['remove', 2, [0xd1, 0xd2, 0x6a, 1, 0x48]],
|
|
12
|
+
['firstName', 1, [0x24, 0, 0xd6, 0x32, 1, 2, 0x29, 0xd1, 0xd2, 0x1e, 0x48]],
|
|
13
|
+
['firstValue', 1, [0xd1, 0xd1, 0x24, 0, 0x1f, 0x23, 0x48]],
|
|
14
|
+
];
|
|
15
|
+
const names = ['DictionaryOps', 'Object', ...methods.map(([name]) => name)];
|
|
16
|
+
const bytes = [16, 0, 46, 0, 0, 0, 0, names.length + 1];
|
|
17
|
+
for (const name of names) bytes.push(name.length, ...new TextEncoder().encode(name));
|
|
18
|
+
bytes.push(2, 0x16, 0, 2, 1, 1); // public namespace and namespace set
|
|
19
|
+
bytes.push(names.length + 2, 0x1b, 1); // MultinameL #1
|
|
20
|
+
for (let i = 1; i <= names.length; i++) bytes.push(0x07, 1, i);
|
|
21
|
+
bytes.push(methods.length + 2, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
22
|
+
for (const [, count] of methods) bytes.push(count, 0, ...Array(count).fill(0), 0, 0);
|
|
23
|
+
bytes.push(0, 1, 2, 3, 0, 0, 0, methods.length); // one instance extending Object
|
|
24
|
+
for (const [index] of methods.entries()) bytes.push(index + 4, 1, 0, index + 2);
|
|
25
|
+
bytes.push(1, 0, 0, methods.length + 2); // class init, no traits, no scripts
|
|
26
|
+
const bodies = [[0x47], [0x47], ...methods.map(([, , code]) => code)];
|
|
27
|
+
for (const [index, code] of bodies.entries()) bytes.push(index, 3, 3, 0, 0, code.length, ...code, 0, 0);
|
|
28
|
+
return Uint8Array.from(bytes);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
it.each([false, true])('preserves Dictionary key identity and visits live entries with AVM2 opcodes (weakKeys=%s)', (weakKeys) => {
|
|
32
|
+
const diagnostics = new DiagnosticsCollector();
|
|
33
|
+
const compiled = transpileAvm2(makeDictionaryFixture(), diagnostics);
|
|
34
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
35
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
36
|
+
const { Dictionary, DictionaryOps } = new Function(`${SWFLIB_SOURCE}
|
|
37
|
+
${AVM2_RUNTIME_STUB}
|
|
38
|
+
${compiled}
|
|
39
|
+
return { Dictionary: __swoof_swflib.builtins.Dictionary, DictionaryOps };
|
|
40
|
+
`)();
|
|
41
|
+
const ops = new DictionaryOps();
|
|
42
|
+
const dictionary = new Dictionary(weakKeys);
|
|
43
|
+
const removed = {};
|
|
44
|
+
const kept = {};
|
|
45
|
+
expect(ops.storeAndRead(dictionary, removed)).toBe(42);
|
|
46
|
+
expect(ops.storeAndRead(dictionary, kept)).toBe(42);
|
|
47
|
+
expect(ops.contains(dictionary, kept)).toBe(true);
|
|
48
|
+
expect(ops.contains(dictionary, {})).toBe(false);
|
|
49
|
+
expect(ops.remove(dictionary, removed)).toBe(true);
|
|
50
|
+
expect(ops.remove(dictionary, removed)).toBe(true);
|
|
51
|
+
expect(ops.contains(dictionary, removed)).toBe(false);
|
|
52
|
+
expect(ops.firstName(dictionary)).toBe(kept);
|
|
53
|
+
expect(ops.firstValue(dictionary)).toBe(42);
|
|
54
|
+
dictionary.set(1, 'number');
|
|
55
|
+
dictionary.set('1', 'string');
|
|
56
|
+
dictionary.set(null, 'null');
|
|
57
|
+
dictionary.set(undefined, 'undefined');
|
|
58
|
+
expect(dictionary._getEntries()).toEqual([[kept, 42], [1, 'number'], ['1', 'string'], [null, 'null'], [undefined, 'undefined']]);
|
|
59
|
+
dictionary.clear();
|
|
60
|
+
expect(dictionary._getEntries()).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('allows collection of an enumerated weak key even when its value references it', () => {
|
|
64
|
+
const runtimeUrl = new URL('../runtime/index.js', import.meta.url).href;
|
|
65
|
+
const script = `
|
|
66
|
+
import assert from 'node:assert/strict';
|
|
67
|
+
import { setImmediate } from 'node:timers/promises';
|
|
68
|
+
import { SWFLIB_SOURCE } from ${JSON.stringify(runtimeUrl)};
|
|
69
|
+
const { Dictionary, ByteArray } = new Function(SWFLIB_SOURCE + '\\nreturn __swoof_swflib.builtins;')();
|
|
70
|
+
const weak = new Dictionary(true);
|
|
71
|
+
const strong = new Dictionary();
|
|
72
|
+
function addKey(dictionary, key) {
|
|
73
|
+
dictionary.set(key, { key });
|
|
74
|
+
assert.equal(dictionary._swoofNextIndex(0), 1);
|
|
75
|
+
assert.equal(dictionary._swoofNextName(1), key);
|
|
76
|
+
return new WeakRef(key);
|
|
77
|
+
}
|
|
78
|
+
const weakKey = addKey(weak, {});
|
|
79
|
+
const strongKey = addKey(strong, {});
|
|
80
|
+
weak.set(2, 'primitive');
|
|
81
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
82
|
+
await setImmediate();
|
|
83
|
+
global.gc();
|
|
84
|
+
if (weakKey.deref() === undefined) break;
|
|
85
|
+
}
|
|
86
|
+
assert.equal(weakKey.deref(), undefined);
|
|
87
|
+
assert.ok(strongKey.deref());
|
|
88
|
+
assert.deepEqual(weak._getEntries(), [[2, 'primitive']]);
|
|
89
|
+
const bytes = new ByteArray();
|
|
90
|
+
bytes.writeObject(weak);
|
|
91
|
+
bytes.position = 0;
|
|
92
|
+
assert.deepEqual(bytes.readObject()._getEntries(), [[2, 'primitive']]);
|
|
93
|
+
`;
|
|
94
|
+
const result = spawnSync(process.execPath, ['--expose-gc', '--input-type=module', '-e', script], { encoding: 'utf8', timeout: 10000 });
|
|
95
|
+
expect(result.status, result.error?.message || result.stderr).toBe(0);
|
|
96
|
+
});
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { transpileAvm2, AVM2_RUNTIME_STUB } from '../transpiler/avm2/avm2-transpiler.js';
|
|
3
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
4
|
+
import { AVM2_RUNTIME_BOOTSTRAP } from '../runtime/avm2-runtime.js';
|
|
5
|
+
import { createEmbeddedMovieRuntime } from '../runtime/embedded-movie-runtime.js';
|
|
6
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
7
|
+
|
|
8
|
+
function buildMinimalAbc(codeBytes, constructorParams = 0) {
|
|
9
|
+
const bytes = [];
|
|
10
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
11
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
12
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
13
|
+
u16(16); u16(46);
|
|
14
|
+
u30(0); u30(0); u30(0);
|
|
15
|
+
u30(5); str(''); str('TestClass'); str('Sprite'); str('foo');
|
|
16
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
17
|
+
u30(0);
|
|
18
|
+
u30(4); bytes.push(0x07); u30(1); u30(2); bytes.push(0x07); u30(1); u30(3); bytes.push(0x07); u30(1); u30(4);
|
|
19
|
+
u30(3);
|
|
20
|
+
for (let m = 0; m < 3; m++) {
|
|
21
|
+
const count = m === 0 ? constructorParams : 0;
|
|
22
|
+
u30(count); u30(0);
|
|
23
|
+
for (let p = 0; p < count; p++) u30(0);
|
|
24
|
+
u30(0); bytes.push(0);
|
|
25
|
+
}
|
|
26
|
+
u30(0);
|
|
27
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1); u30(3); bytes.push(0); u30(1); u30(0); u30(0);
|
|
28
|
+
u30(1); u30(0);
|
|
29
|
+
u30(1); u30(2); u30(0);
|
|
30
|
+
u30(1); u30(0); u30(4); u30(2); u30(1); u30(3); u30(codeBytes.length);
|
|
31
|
+
for (const b of codeBytes) bytes.push(b);
|
|
32
|
+
u30(0); u30(0);
|
|
33
|
+
return new Uint8Array(bytes);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function buildCallStaticAbc(ctorCode) {
|
|
37
|
+
const bytes = [];
|
|
38
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
39
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
40
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
41
|
+
const body = (methodIndex, code, localCount) => {
|
|
42
|
+
u30(methodIndex); u30(4); u30(localCount); u30(1); u30(3); u30(code.length);
|
|
43
|
+
for (const b of code) bytes.push(b);
|
|
44
|
+
u30(0); u30(0);
|
|
45
|
+
};
|
|
46
|
+
u16(16); u16(46);
|
|
47
|
+
u30(0); u30(0); u30(0);
|
|
48
|
+
u30(5); str(''); str('TestClass'); str('Sprite'); str('foo');
|
|
49
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
50
|
+
u30(0);
|
|
51
|
+
u30(4); bytes.push(0x07); u30(1); u30(2); bytes.push(0x07); u30(1); u30(3); bytes.push(0x07); u30(1); u30(4);
|
|
52
|
+
u30(4);
|
|
53
|
+
for (let m = 0; m < 3; m++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
54
|
+
u30(1); u30(0); u30(0); u30(0); bytes.push(0);
|
|
55
|
+
u30(0);
|
|
56
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1);
|
|
57
|
+
u30(3); bytes.push(0x01); u30(1); u30(3);
|
|
58
|
+
u30(1); u30(0);
|
|
59
|
+
u30(1); u30(2); u30(0);
|
|
60
|
+
u30(2);
|
|
61
|
+
body(0, ctorCode, 2);
|
|
62
|
+
body(3, [0xd1, 0x48], 2); // getlocal1; returnvalue
|
|
63
|
+
u30(0); u30(0);
|
|
64
|
+
return new Uint8Array(bytes);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function transpile(code) {
|
|
68
|
+
const diagnostics = new DiagnosticsCollector();
|
|
69
|
+
const js = transpileAvm2(buildMinimalAbc(code), diagnostics);
|
|
70
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
71
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
72
|
+
return js;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function runtime() {
|
|
76
|
+
return new Function('__swoof_swflib', `${AVM2_RUNTIME_STUB}\nreturn { setMemory: _setDomainMemory, read: _memRead, write: _memWrite, signExtend: _signExtend };`)();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function compiledConstructor(code) {
|
|
80
|
+
const js = transpile(code);
|
|
81
|
+
return new Function('__swoof_swflib', `class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn { TestClass, setMemory: _setDomainMemory };`)();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('AVM2 domain memory', () => {
|
|
85
|
+
it('loads and stores integer values in little-endian byte order', () => {
|
|
86
|
+
const { setMemory, read, write } = runtime();
|
|
87
|
+
const bytes = new Uint8Array(16);
|
|
88
|
+
setMemory(bytes);
|
|
89
|
+
|
|
90
|
+
write(0x3a, 1, 0xab);
|
|
91
|
+
write(0x3b, 2, 0x1234);
|
|
92
|
+
write(0x3c, 4, 0x89abcdef);
|
|
93
|
+
expect([...bytes.slice(0, 8)]).toEqual([0, 0xab, 0x34, 0x12, 0xef, 0xcd, 0xab, 0x89]);
|
|
94
|
+
expect(read(0x35, 1)).toBe(0xab);
|
|
95
|
+
expect(read(0x36, 2)).toBe(0x1234);
|
|
96
|
+
expect(read(0x37, 4)).toBe(-1985229329);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('loads and stores float32 and float64 values', () => {
|
|
100
|
+
const { setMemory, read, write } = runtime();
|
|
101
|
+
setMemory(new ArrayBuffer(16));
|
|
102
|
+
write(0x3d, 0, 1.25);
|
|
103
|
+
write(0x3e, 4, -Math.PI);
|
|
104
|
+
expect(read(0x38, 0)).toBe(1.25);
|
|
105
|
+
expect(read(0x39, 4)).toBe(-Math.PI);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('accepts a ByteArray-like domain memory view', () => {
|
|
109
|
+
const { setMemory, write, read } = runtime();
|
|
110
|
+
const bytes = new Uint8Array(8);
|
|
111
|
+
setMemory({ _getU8: () => bytes });
|
|
112
|
+
write(0x3c, 0, 0x10203040);
|
|
113
|
+
expect(read(0x37, 0)).toBe(0x10203040);
|
|
114
|
+
expect([...bytes.slice(0, 4)]).toEqual([0x40, 0x30, 0x20, 0x10]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('connects ApplicationDomain.currentDomain.domainMemory to AVM2 operations', () => {
|
|
118
|
+
const avm2Class = transpile([0x47]);
|
|
119
|
+
const env = new Function(`class Sprite {}\n${SWFLIB_SOURCE}\n${AVM2_RUNTIME_STUB}\n${avm2Class}\nreturn {
|
|
120
|
+
ApplicationDomain: __swoof_swflib.builtins.ApplicationDomain,
|
|
121
|
+
ByteArray: __swoof_swflib.builtins.ByteArray,
|
|
122
|
+
TestClass,
|
|
123
|
+
read: _memRead,
|
|
124
|
+
};`)();
|
|
125
|
+
const memory = new env.ByteArray();
|
|
126
|
+
memory.length = env.ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
|
|
127
|
+
memory[1] = 0x7a;
|
|
128
|
+
env.ApplicationDomain.currentDomain.domainMemory = memory;
|
|
129
|
+
expect(env.ApplicationDomain.currentDomain.domainMemory).toBe(memory);
|
|
130
|
+
expect(env.read(0x35, 1)).toBe(0x7a);
|
|
131
|
+
expect(env.ApplicationDomain.currentDomain.getDefinition('TestClass')).toBe(env.TestClass);
|
|
132
|
+
expect(env.ApplicationDomain.currentDomain.hasDefinition('TestClass')).toBe(true);
|
|
133
|
+
expect(env.ApplicationDomain.currentDomain.hasDefinition('MissingClass')).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('uses the defining application domain for compiled opcodes in a parent and two loaded siblings', async () => {
|
|
137
|
+
const hostGlobal = Object.create(globalThis);
|
|
138
|
+
hostGlobal.document = { createElement: () => ({ getContext: () => null }) };
|
|
139
|
+
const hostRuntime = new Function('globalThis', `${SWFLIB_SOURCE}\nreturn globalThis.__swoof_swflib;`)(hostGlobal);
|
|
140
|
+
const { ApplicationDomain, ByteArray, Event, Loader, LoaderContext, MovieClip, Sprite } = hostRuntime.builtins;
|
|
141
|
+
const parentDomain = ApplicationDomain.currentDomain;
|
|
142
|
+
const firstDomain = new ApplicationDomain(parentDomain);
|
|
143
|
+
const secondDomain = new ApplicationDomain(parentDomain);
|
|
144
|
+
const diagnostics = new DiagnosticsCollector();
|
|
145
|
+
const js = transpileAvm2(buildMinimalAbc([
|
|
146
|
+
0xd0, 0x24, 2, 0x36, 0x61, 3, // this.foo = li16(2)
|
|
147
|
+
0xd1, 0x24, 2, 0x3b, 0x47, // si16(value, 2)
|
|
148
|
+
], 1), diagnostics);
|
|
149
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
150
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
151
|
+
const compileMovie = new Function('globalThis', '__swoof_swflib', 'Sprite',
|
|
152
|
+
`${AVM2_RUNTIME_BOOTSTRAP}\n${js}\nreturn TestClass;`);
|
|
153
|
+
const ParentProbe = compileMovie(hostGlobal, hostRuntime, Sprite);
|
|
154
|
+
const movieBytes = Uint8Array.of(0x46, 0x57, 0x53, 10, 8, 0, 0, 0);
|
|
155
|
+
hostRuntime.registerEmbeddedSwf(movieBytes, environment => createEmbeddedMovieRuntime(
|
|
156
|
+
hostRuntime, hostGlobal, environment, { assets: [], stageW: 1, stageH: 1 }, () => Promise.resolve(), () => null,
|
|
157
|
+
movie => {
|
|
158
|
+
const content = new MovieClip();
|
|
159
|
+
content.Probe = compileMovie(movie.global, movie.runtime, Sprite);
|
|
160
|
+
return content;
|
|
161
|
+
}
|
|
162
|
+
));
|
|
163
|
+
async function load(domain) {
|
|
164
|
+
const loader = new Loader();
|
|
165
|
+
const info = loader.contentLoaderInfo;
|
|
166
|
+
const loaded = new Promise((resolve, reject) => {
|
|
167
|
+
info.addEventListener(Event.COMPLETE, resolve);
|
|
168
|
+
info.addEventListener('ioError', event => reject(new Error(event.text)));
|
|
169
|
+
});
|
|
170
|
+
loader.loadBytes(movieBytes, new LoaderContext(false, domain));
|
|
171
|
+
await loaded;
|
|
172
|
+
expect(info.applicationDomain).toBe(domain);
|
|
173
|
+
return loader.content.Probe;
|
|
174
|
+
}
|
|
175
|
+
const [FirstProbe, SecondProbe] = await Promise.all([load(firstDomain), load(secondDomain)]);
|
|
176
|
+
expect(new ParentProbe(7).foo).toBe(0);
|
|
177
|
+
expect(new FirstProbe(11).foo).toBe(0);
|
|
178
|
+
expect(new SecondProbe(13).foo).toBe(0);
|
|
179
|
+
expect(new ParentProbe(7).foo).toBe(7);
|
|
180
|
+
|
|
181
|
+
const memories = [parentDomain, firstDomain, secondDomain].map(domain => {
|
|
182
|
+
const memory = new ByteArray();
|
|
183
|
+
memory.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
|
|
184
|
+
memory.position = 19;
|
|
185
|
+
domain.domainMemory = memory;
|
|
186
|
+
return memory;
|
|
187
|
+
});
|
|
188
|
+
expect(new ParentProbe(0x1234).foo).toBe(0);
|
|
189
|
+
expect(new FirstProbe(0xabcd).foo).toBe(0);
|
|
190
|
+
expect(new SecondProbe(0x4567).foo).toBe(0);
|
|
191
|
+
expect(new ParentProbe(0x1234).foo).toBe(0x1234);
|
|
192
|
+
expect(new FirstProbe(0xabcd).foo).toBe(0xabcd);
|
|
193
|
+
expect(new SecondProbe(0x4567).foo).toBe(0x4567);
|
|
194
|
+
expect(memories.map(memory => [memory[2], memory[3], memory.position])).toEqual([
|
|
195
|
+
[0x34, 0x12, 19], [0xcd, 0xab, 19], [0x67, 0x45, 19],
|
|
196
|
+
]);
|
|
197
|
+
firstDomain.domainMemory = null;
|
|
198
|
+
expect(new FirstProbe(11).foo).toBe(11);
|
|
199
|
+
expect(new ParentProbe(0x1234).foo).toBe(0x1234);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('validates selected buffers and refreshes bounds when a shared provider grows or shrinks', () => {
|
|
203
|
+
const env = new Function(`${SWFLIB_SOURCE}\n${AVM2_RUNTIME_STUB}\nreturn {
|
|
204
|
+
ApplicationDomain, ByteArray, read: _memRead, write: _memWrite
|
|
205
|
+
};`)();
|
|
206
|
+
const { ApplicationDomain, ByteArray, read, write } = env;
|
|
207
|
+
const domain = ApplicationDomain.currentDomain;
|
|
208
|
+
const child = new ApplicationDomain(domain);
|
|
209
|
+
const memory = new ByteArray();
|
|
210
|
+
const min = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
|
|
211
|
+
expect(domain.domainMemory).toBeNull();
|
|
212
|
+
memory.length = min;
|
|
213
|
+
domain.domainMemory = child.domainMemory = memory;
|
|
214
|
+
expect(() => { domain.domainMemory = new ByteArray(); }).toThrow(/at least 1024/);
|
|
215
|
+
expect(() => { domain.domainMemory = new Uint8Array(min); }).toThrow(TypeError);
|
|
216
|
+
expect(domain.domainMemory).toBe(memory);
|
|
217
|
+
expect(() => write(0x3b, min - 1, 0xbeef)).toThrow(RangeError);
|
|
218
|
+
expect(() => { memory.length = min - 1; }).toThrow(RangeError);
|
|
219
|
+
memory.length = 2 * min; // Force a different backing buffer.
|
|
220
|
+
write(0x3b, min - 1, 0xbeef);
|
|
221
|
+
expect(read(0x36, min - 1)).toBe(0xbeef);
|
|
222
|
+
expect(memory[min]).toBe(0xbe);
|
|
223
|
+
memory.length = min; // The backing capacity remains larger than the logical length.
|
|
224
|
+
expect(() => read(0x36, min - 1)).toThrow(RangeError);
|
|
225
|
+
domain.domainMemory = null;
|
|
226
|
+
expect(() => memory.clear()).toThrow(RangeError);
|
|
227
|
+
child.domainMemory = null;
|
|
228
|
+
memory.clear();
|
|
229
|
+
expect(memory.length).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('sign-extends 1, 8, and 16-bit values to signed 32-bit integers', () => {
|
|
233
|
+
const { signExtend } = runtime();
|
|
234
|
+
expect(signExtend(1, 1)).toBe(-1);
|
|
235
|
+
expect(signExtend(0xfe, 8)).toBe(-2);
|
|
236
|
+
expect(signExtend(0x80ff, 16)).toBe(-32513);
|
|
237
|
+
expect(signExtend(0x7f, 8)).toBe(127);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('throws RangeError for negative and out-of-range accesses', () => {
|
|
241
|
+
const { setMemory, read, write } = runtime();
|
|
242
|
+
setMemory(new ArrayBuffer(4));
|
|
243
|
+
expect(() => read(0x35, -1)).toThrow(RangeError);
|
|
244
|
+
expect(() => read(0x36, 3)).toThrow(RangeError);
|
|
245
|
+
expect(() => write(0x3c, 1, 2)).toThrow(RangeError);
|
|
246
|
+
write(0x3a, 0, 9);
|
|
247
|
+
expect(read(0x35, NaN)).toBe(9);
|
|
248
|
+
expect(read(0x35, 0x100000000)).toBe(9);
|
|
249
|
+
setMemory(new ArrayBuffer(0));
|
|
250
|
+
expect(() => read(0x35, 0)).toThrow(RangeError);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('transpiles memory opcodes through shared helpers and applies sign extension', () => {
|
|
254
|
+
// pushbyte 4; li16; sxi16; returnvalue
|
|
255
|
+
const load = transpile([0x24, 4, 0x36, 0x52, 0x48]);
|
|
256
|
+
expect(load).toContain('_memRead(54, 4)');
|
|
257
|
+
expect(load).toContain('_signExtend(_memRead(54, 4), 16)');
|
|
258
|
+
|
|
259
|
+
// pushbyte 0x7f; pushbyte 2; si8; returnvoid
|
|
260
|
+
const store = transpile([0x24, 0x7f, 0x24, 2, 0x3a, 0x47]);
|
|
261
|
+
expect(store).toContain('_memWrite(58, 2, 127)');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('executes compiled store opcodes and enforces bounds in compiled loads', () => {
|
|
265
|
+
// pushbyte 0x34; pushbyte 3; si8; returnvoid
|
|
266
|
+
const store = compiledConstructor([0x24, 0x34, 0x24, 3, 0x3a, 0x47]);
|
|
267
|
+
const bytes = new Uint8Array(8);
|
|
268
|
+
store.setMemory(bytes);
|
|
269
|
+
new store.TestClass();
|
|
270
|
+
expect(bytes[3]).toBe(0x34);
|
|
271
|
+
|
|
272
|
+
// pushbyte 7; li16; returnvalue
|
|
273
|
+
const load = compiledConstructor([0x24, 7, 0x36, 0x48]);
|
|
274
|
+
load.setMemory(new ArrayBuffer(8));
|
|
275
|
+
expect(() => new load.TestClass()).toThrow(RangeError);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('dispatches callstatic to the exact ABC method with the supplied receiver and arguments', () => {
|
|
279
|
+
// getlocal0; pushbyte 42; callstatic method 3 with one argument; pop; returnvoid
|
|
280
|
+
const code = [0xd0, 0x24, 42, 0x44, 3, 1, 0x29, 0x47];
|
|
281
|
+
const diagnostics = new DiagnosticsCollector();
|
|
282
|
+
const js = transpileAvm2(buildCallStaticAbc(code), diagnostics);
|
|
283
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
284
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
285
|
+
const tableName = /var (_avm2MethodTable_[0-9a-f]+_[0-9]+) =/.exec(js)?.[1];
|
|
286
|
+
expect(tableName).toBeTruthy();
|
|
287
|
+
expect(js).toContain(`_callStatic(${tableName}, 3, this, [42])`);
|
|
288
|
+
expect(js).toContain(`_registerAvm2Methods(TestClass, ${tableName}, [[3,"foo"]]);`);
|
|
289
|
+
expect(js).not.toContain('function (_receiver, _args)');
|
|
290
|
+
const env = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn {
|
|
291
|
+
TestClass, table: ${tableName}, callStatic: _callStatic,
|
|
292
|
+
};`)();
|
|
293
|
+
const receiver = new env.TestClass();
|
|
294
|
+
expect(env.callStatic(env.table, 3, receiver, [37])).toBe(37);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('resolves inherited static methods and getter replacements at invocation time', () => {
|
|
298
|
+
const { entry, callStatic } = new Function(`
|
|
299
|
+
${AVM2_RUNTIME_STUB}
|
|
300
|
+
return { entry: _avm2MethodEntry, callStatic: _callStatic };
|
|
301
|
+
`)();
|
|
302
|
+
class Parent {
|
|
303
|
+
static method(amount) { return this.value + amount; }
|
|
304
|
+
}
|
|
305
|
+
class Child extends Parent {}
|
|
306
|
+
const receiver = { value: 4 };
|
|
307
|
+
const table = { 2: entry(Child, 'method') };
|
|
308
|
+
|
|
309
|
+
expect(callStatic(table, 2, receiver, [3])).toBe(7);
|
|
310
|
+
let accessedBy;
|
|
311
|
+
Object.defineProperty(Parent, 'method', {
|
|
312
|
+
get() {
|
|
313
|
+
accessedBy = this;
|
|
314
|
+
return function (amount) { return this.value * amount; };
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
expect(accessedBy).toBeUndefined();
|
|
318
|
+
expect(callStatic(table, 2, receiver, [3])).toBe(12);
|
|
319
|
+
expect(accessedBy).toBe(Child);
|
|
320
|
+
Object.defineProperty(Parent, 'method', { value: null });
|
|
321
|
+
expect(callStatic(table, 2, receiver, [3])).toBeUndefined();
|
|
322
|
+
expect(callStatic({ 2: (bound, args) => [bound, args[0]] }, 2, receiver, [3])).toEqual([receiver, 3]);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('uses an independent 100,000-block budget per method invocation', () => {
|
|
326
|
+
const createBudget = new Function(`${AVM2_RUNTIME_STUB}\nreturn _createAvm2ExecutionBudget;`)();
|
|
327
|
+
const check = createBudget();
|
|
328
|
+
for (let i = 0; i < 100000; i++) check();
|
|
329
|
+
expect(check).toThrow('AVM2 execution limit exceeded');
|
|
330
|
+
expect(createBudget()).not.toThrow();
|
|
331
|
+
});
|
|
332
|
+
});
|