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,116 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { createContext, runInContext } from 'node:vm';
|
|
5
|
+
import { expect, it } from 'vitest';
|
|
6
|
+
import { decode } from '../decoder/tag-decoder.js';
|
|
7
|
+
import { emit } from '../emitter/bundle-emitter.js';
|
|
8
|
+
import { parse } from '../parser/swf-parser.js';
|
|
9
|
+
import { transpileActionScript } from '../transpiler/actionscript.js';
|
|
10
|
+
|
|
11
|
+
function createCanvas() {
|
|
12
|
+
const listeners = {};
|
|
13
|
+
const canvas = {
|
|
14
|
+
width: 640, height: 400, style: {}, listeners,
|
|
15
|
+
addEventListener(type, fn) { (listeners[type] ??= []).push(fn); },
|
|
16
|
+
getBoundingClientRect() { return { left: 0, top: 0, width: 640, height: 400 }; },
|
|
17
|
+
};
|
|
18
|
+
const context = new Proxy({
|
|
19
|
+
canvas,
|
|
20
|
+
measureText: text => ({ width: text.length * 6 }),
|
|
21
|
+
getTransform: () => ({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }),
|
|
22
|
+
getImageData: () => ({ data: Uint8ClampedArray.of(255, 255, 255, 255) }),
|
|
23
|
+
createLinearGradient: () => ({ addColorStop() {} }),
|
|
24
|
+
createRadialGradient: () => ({ addColorStop() {} }),
|
|
25
|
+
}, { get: (target, key) => target[key] ?? (() => {}) });
|
|
26
|
+
canvas.getContext = () => context;
|
|
27
|
+
return canvas;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
it('starts QWOP from empty Stage space and advances physics with keyboard input', async () => {
|
|
31
|
+
const fixture = 'archive/flasharchive/QWOP.swf';
|
|
32
|
+
const { doc, diagnostics } = await parse(new Uint8Array(readFileSync(fixture)));
|
|
33
|
+
const { tags, symbolTable } = decode(doc, diagnostics);
|
|
34
|
+
const actionScript = transpileActionScript(tags, diagnostics, { swfVersion: doc.header.version });
|
|
35
|
+
const output = mkdtempSync(join(tmpdir(), 'swoof-qwop-'));
|
|
36
|
+
try {
|
|
37
|
+
const bundle = emit({ header: doc.header, tags, symbolTable, actionScript }, fixture, output,
|
|
38
|
+
diagnostics, { externalTimelineData: true });
|
|
39
|
+
const warnings = [], windowListeners = {};
|
|
40
|
+
const stage = createCanvas();
|
|
41
|
+
const sandbox = {
|
|
42
|
+
atob, TextDecoder, TextEncoder, setTimeout, clearTimeout,
|
|
43
|
+
console: { log() {}, warn(...args) { warnings.push(args); } },
|
|
44
|
+
requestAnimationFrame: () => 1, PointerEvent: function () {},
|
|
45
|
+
addEventListener(type, fn) { (windowListeners[type] ??= []).push(fn); },
|
|
46
|
+
document: {
|
|
47
|
+
readyState: 'complete',
|
|
48
|
+
getElementById: id => id === 'stage' ? stage : null,
|
|
49
|
+
createElement: createCanvas,
|
|
50
|
+
},
|
|
51
|
+
Image: class {
|
|
52
|
+
naturalWidth = 64;
|
|
53
|
+
naturalHeight = 64;
|
|
54
|
+
set src(value) { this.onload?.(); }
|
|
55
|
+
},
|
|
56
|
+
Audio: class { addEventListener() {} play() { return Promise.resolve(); } pause() {} },
|
|
57
|
+
Path2D: class { moveTo() {} lineTo() {} quadraticCurveTo() {} closePath() {} },
|
|
58
|
+
};
|
|
59
|
+
sandbox.window = sandbox;
|
|
60
|
+
const realm = createContext(sandbox);
|
|
61
|
+
for (const path of [bundle.swflibPath, bundle.movieDataPath, bundle.jsPath]) {
|
|
62
|
+
runInContext(readFileSync(path, 'utf8'), realm, { filename: path });
|
|
63
|
+
}
|
|
64
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
65
|
+
|
|
66
|
+
const { main, timeline } = sandbox.__swoof;
|
|
67
|
+
expect(main?.constructor.name).toBe('Athletics');
|
|
68
|
+
expect(main.view).toBe(main.getChildByName('view1'));
|
|
69
|
+
expect(main.Intro_mc.parent).toBe(main.stage);
|
|
70
|
+
const world = main.view.world;
|
|
71
|
+
expect(world.paused).toBe(true);
|
|
72
|
+
expect(world.rtjoint.joint).toBeTruthy();
|
|
73
|
+
const runner = world.cbody;
|
|
74
|
+
expect(runner.b2body.m_mass).toBeGreaterThan(0);
|
|
75
|
+
expect([runner.x, runner.y, runner.rotation].every(Number.isFinite)).toBe(true);
|
|
76
|
+
|
|
77
|
+
timeline.tick();
|
|
78
|
+
timeline.tick();
|
|
79
|
+
const point = { x: 522, y: 2 };
|
|
80
|
+
expect(timeline.pickAuthoredPointer(point.x, point.y, false)).toBeFalsy();
|
|
81
|
+
expect(sandbox.__swoof_swflib.canvasProgrammaticPointerAt(point.x, point.y)).toBeFalsy();
|
|
82
|
+
const clickTargets = [];
|
|
83
|
+
main.stage.addEventListener('click', event => clickTargets.push(event.target));
|
|
84
|
+
for (const [type, buttons] of [['pointerdown', 1], ['pointerup', 0]]) {
|
|
85
|
+
const event = { clientX: point.x, clientY: point.y, button: 0, buttons, pointerId: 1,
|
|
86
|
+
pointerType: 'mouse', isPrimary: true, target: stage, preventDefault() {} };
|
|
87
|
+
for (const fn of stage.listeners[type] ?? []) fn(event);
|
|
88
|
+
for (const fn of windowListeners[type] ?? []) fn(event);
|
|
89
|
+
}
|
|
90
|
+
expect(main.GotFocus).toBe(true);
|
|
91
|
+
expect(clickTargets).toEqual([main.stage]);
|
|
92
|
+
expect(main.Intro_mc.parent).toBeNull();
|
|
93
|
+
expect(world.paused).toBe(false);
|
|
94
|
+
|
|
95
|
+
const keys = [['q', 81], ['w', 87], ['o', 79], ['p', 80]];
|
|
96
|
+
for (const [key, keyCode] of keys) {
|
|
97
|
+
for (const fn of windowListeners.keydown ?? []) {
|
|
98
|
+
fn({ key, keyCode, target: stage, preventDefault() {} });
|
|
99
|
+
}
|
|
100
|
+
expect(main[key.toUpperCase() + 'DOWN']).toBe(true);
|
|
101
|
+
for (const fn of windowListeners.keyup ?? []) {
|
|
102
|
+
fn({ key, keyCode, target: stage, preventDefault() {} });
|
|
103
|
+
}
|
|
104
|
+
expect(main[key.toUpperCase() + 'DOWN']).toBe(false);
|
|
105
|
+
}
|
|
106
|
+
for (const fn of windowListeners.keydown ?? []) fn({ key: 'q', keyCode: 81, target: stage, preventDefault() {} });
|
|
107
|
+
const y = runner.y;
|
|
108
|
+
for (let i = 0; i < 6; i++) timeline.tick();
|
|
109
|
+
expect(Number.isFinite(runner.y)).toBe(true);
|
|
110
|
+
expect(Math.abs(runner.y - y)).toBeGreaterThan(1);
|
|
111
|
+
expect(main.scoreval.text).toMatch(/^-?\d+(?:\.\d+)? metres$/);
|
|
112
|
+
expect(warnings).toEqual([]);
|
|
113
|
+
} finally {
|
|
114
|
+
rmSync(output, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
}, 15000);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { AVM2_RUNTIME_STUB, transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
4
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
5
|
+
|
|
6
|
+
function compileClass(className) {
|
|
7
|
+
const bytes = [16, 0, 46, 0];
|
|
8
|
+
const u30 = value => {
|
|
9
|
+
while (value >= 128) {
|
|
10
|
+
bytes.push((value & 127) | 128);
|
|
11
|
+
value >>>= 7;
|
|
12
|
+
}
|
|
13
|
+
bytes.push(value);
|
|
14
|
+
};
|
|
15
|
+
const methods = [
|
|
16
|
+
['qualifiedRead', 0, [0xd0, 0x31, 2, 0x66, 5, 0x48]],
|
|
17
|
+
['lateRead', 2, [0xd0, 0xd1, 0xd2, 0x66, 6, 0x48]],
|
|
18
|
+
['setRead', 1, [0xd0, 0xd1, 0x66, 7, 0x48]],
|
|
19
|
+
['lateWrite', 3, [0xd0, 0xd1, 0xd2, 0xd3, 0x61, 6, 0x47]],
|
|
20
|
+
['lateDelete', 2, [0xd0, 0xd1, 0xd2, 0x6a, 6, 0x48]],
|
|
21
|
+
['lateCall', 3, [0xd0, 0xd1, 0xd2, 0xd3, 0x46, 6, 1, 0x48]],
|
|
22
|
+
['lateConstruct', 2, [0xd0, 0xd1, 0xd2, 0x4a, 6, 0, 0x48]],
|
|
23
|
+
['privateRead', 0, [0xd0, 0x31, 3, 0x66, 5, 0x48]],
|
|
24
|
+
['privateNamespace', 0, [0x31, 3, 0x48]],
|
|
25
|
+
['findLate', 2, [0xd0, 0x30, 0xd1, 0xd2, 0x5d, 6, 0x48]],
|
|
26
|
+
['constantNamespace', 0, [0xd0, 0x66, 8, 0x48]],
|
|
27
|
+
['looseEquals', 2, [0xd1, 0xd2, 0xab, 0x48]],
|
|
28
|
+
['strictEquals', 2, [0xd1, 0xd2, 0xac, 0x48]],
|
|
29
|
+
['packageNamespace', 0, [0x31, 5, 0x48]],
|
|
30
|
+
['internalNamespace', 0, [0x31, 6, 0x48]],
|
|
31
|
+
['equalBranch', 2, [0xd1, 0xd2, 0x13, 2, 0, 0, 0x27, 0x48, 0x26, 0x48]],
|
|
32
|
+
['unequalBranch', 2, [0xd1, 0xd2, 0x14, 2, 0, 0, 0x27, 0x48, 0x26, 0x48]],
|
|
33
|
+
];
|
|
34
|
+
const scriptTrait = methods.length + 10;
|
|
35
|
+
methods.push(['scriptNamespace', 0, [0x60, scriptTrait, 0x48]]);
|
|
36
|
+
const strings = [className, 'Object', 'urn:runtime', 'value', 'ns', ...methods.map(([name]) => name), 'nsDefinitions', 'declared'];
|
|
37
|
+
u30(0); u30(0); u30(0);
|
|
38
|
+
u30(strings.length + 1);
|
|
39
|
+
for (const string of strings) {
|
|
40
|
+
const encoded = new TextEncoder().encode(string);
|
|
41
|
+
u30(encoded.length); bytes.push(...encoded);
|
|
42
|
+
}
|
|
43
|
+
u30(7);
|
|
44
|
+
bytes.push(0x16); u30(0); // public namespace
|
|
45
|
+
bytes.push(0x08); u30(3); // custom URI
|
|
46
|
+
bytes.push(0x05); u30(3); // private namespace with the same URI
|
|
47
|
+
bytes.push(0x16); u30(6 + methods.length); // package for the script trait
|
|
48
|
+
bytes.push(0x16); u30(3); // package namespace with the custom URI
|
|
49
|
+
bytes.push(0x17); u30(3); // internal namespace with the custom URI
|
|
50
|
+
u30(2); u30(2); u30(2); u30(1); // ordered custom and public set
|
|
51
|
+
const qname = (ns, name) => { bytes.push(7); u30(ns); u30(name); };
|
|
52
|
+
u30(10 + methods.length);
|
|
53
|
+
qname(1, 1); qname(1, 2); qname(2, 4); qname(3, 4);
|
|
54
|
+
bytes.push(0x0f); u30(4); // RTQName value
|
|
55
|
+
bytes.push(0x11); // RTQNameL
|
|
56
|
+
bytes.push(0x1b); u30(1); // MultinameL
|
|
57
|
+
qname(1, 5); // ns
|
|
58
|
+
methods.forEach((_, index) => qname(1, index + 6));
|
|
59
|
+
qname(4, 7 + methods.length); // nsDefinitions.declared
|
|
60
|
+
u30(methods.length + 2);
|
|
61
|
+
for (const [, params] of [[null, 0], [null, 0], ...methods]) {
|
|
62
|
+
u30(params); u30(0);
|
|
63
|
+
for (let i = 0; i < params; i++) u30(0);
|
|
64
|
+
u30(0); bytes.push(0);
|
|
65
|
+
}
|
|
66
|
+
u30(0); // metadata
|
|
67
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); // class, iinit
|
|
68
|
+
u30(methods.length + 3);
|
|
69
|
+
u30(3); bytes.push(0); u30(1); u30(0); u30(0); // custom value slot
|
|
70
|
+
u30(4); bytes.push(0); u30(2); u30(0); u30(0); // private value slot
|
|
71
|
+
u30(8); bytes.push(6); u30(3); u30(0); u30(2); bytes.push(0x08); // namespace const default
|
|
72
|
+
methods.forEach((_, index) => { u30(index + 9); bytes.push(1); u30(0); u30(index + 2); });
|
|
73
|
+
u30(1); u30(0); // cinit, static traits
|
|
74
|
+
const declaresNamespace = className === 'First';
|
|
75
|
+
u30(Number(declaresNamespace)); // scripts
|
|
76
|
+
if (declaresNamespace) {
|
|
77
|
+
u30(1); u30(1); // init and trait count
|
|
78
|
+
u30(scriptTrait); bytes.push(6); u30(0); u30(0); u30(2); bytes.push(0x08); // const with an automatic slot ID
|
|
79
|
+
}
|
|
80
|
+
u30(methods.length + 1);
|
|
81
|
+
const body = (index, params, code) => {
|
|
82
|
+
u30(index); u30(6); u30(1 + params); u30(0); u30(1); u30(code.length);
|
|
83
|
+
bytes.push(...code); u30(0); u30(0);
|
|
84
|
+
};
|
|
85
|
+
body(0, 0, [0xd0, 0x24, 21, 0x61, 4, 0x47]);
|
|
86
|
+
methods.forEach(([, params, code], index) => body(index + 2, params, code));
|
|
87
|
+
const diagnostics = new DiagnosticsCollector();
|
|
88
|
+
const js = transpileAvm2(Uint8Array.from(bytes), diagnostics);
|
|
89
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
90
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
91
|
+
return js;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
it('uses computed namespaces and ordered late names across emitted property operations', () => {
|
|
95
|
+
const { First, Second, Namespace, QName } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
96
|
+
${compileClass('First')}
|
|
97
|
+
${compileClass('Second')}
|
|
98
|
+
({ First, Second, Namespace: _getlex('Namespace'), QName: _getlex('QName') });
|
|
99
|
+
`);
|
|
100
|
+
const first = new First();
|
|
101
|
+
const second = new Second();
|
|
102
|
+
const ns = new Namespace('display', 'urn:runtime');
|
|
103
|
+
const publicNs = Namespace();
|
|
104
|
+
expect(ns.uri).toBe('urn:runtime');
|
|
105
|
+
expect(ns.prefix).toBe('display');
|
|
106
|
+
expect(String(ns)).toBe('urn:runtime');
|
|
107
|
+
expect(first.constantNamespace()).toBeInstanceOf(Namespace);
|
|
108
|
+
expect(first.constantNamespace().uri).toBe('urn:runtime');
|
|
109
|
+
expect(first.scriptNamespace()).toBe(first.constantNamespace());
|
|
110
|
+
expect(second.scriptNamespace()).toBe(first.constantNamespace());
|
|
111
|
+
|
|
112
|
+
first.value = 'public';
|
|
113
|
+
first.lateWrite(ns, 'value', 42);
|
|
114
|
+
expect(first.qualifiedRead()).toBe(42);
|
|
115
|
+
expect(first.lateRead(ns, 'value')).toBe(42);
|
|
116
|
+
expect(first.setRead('value')).toBe(42);
|
|
117
|
+
expect(first.setRead(new QName(publicNs, 'value'))).toBe('public');
|
|
118
|
+
expect(first.lateRead(ns, new QName(publicNs, 'value'))).toBe('public');
|
|
119
|
+
expect(first.lateRead(publicNs, 'value')).toBe('public');
|
|
120
|
+
expect(first.findLate(ns, 'value')).toBe(first);
|
|
121
|
+
expect(first.lateDelete(ns, 'value')).toBe(true);
|
|
122
|
+
expect(first.setRead('value')).toBe('public');
|
|
123
|
+
|
|
124
|
+
first.lateWrite(ns, 'run', function (arg) { return this.value + arg; });
|
|
125
|
+
first.lateWrite(ns, 'Ctor', class Example {});
|
|
126
|
+
expect(first.lateCall(ns, 'run', 7)).toBe('public7');
|
|
127
|
+
expect(first.lateConstruct(ns, 'Ctor').constructor.name).toBe('Example');
|
|
128
|
+
expect(first.privateRead()).toBe(21);
|
|
129
|
+
expect(second.privateRead()).toBe(21);
|
|
130
|
+
expect(second.lateRead(first.privateNamespace(), 'value')).toBeUndefined();
|
|
131
|
+
expect(() => first.lateRead('urn:runtime', 'value')).toThrow(/must be a Namespace/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('compares Namespace values by URI for loose equality while preserving private identity', () => {
|
|
135
|
+
const { First, Second, Namespace } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
136
|
+
${compileClass('First')}
|
|
137
|
+
${compileClass('Second')}
|
|
138
|
+
({ First, Second, Namespace: _getlex('Namespace') });
|
|
139
|
+
`);
|
|
140
|
+
const first = new First();
|
|
141
|
+
const second = new Second();
|
|
142
|
+
const a = new Namespace('first', 'urn:runtime');
|
|
143
|
+
const b = new Namespace('second', 'urn:runtime');
|
|
144
|
+
expect(first.looseEquals(a, b)).toBe(true);
|
|
145
|
+
expect(first.strictEquals(a, b)).toBe(false);
|
|
146
|
+
expect(first.equalBranch(a, b)).toBe(true);
|
|
147
|
+
expect(first.unequalBranch(a, b)).toBe(false);
|
|
148
|
+
expect(first.looseEquals(a, first.constantNamespace())).toBe(true);
|
|
149
|
+
expect(first.looseEquals(a, first.packageNamespace())).toBe(true);
|
|
150
|
+
expect(first.looseEquals(a, first.internalNamespace())).toBe(false);
|
|
151
|
+
expect(first.looseEquals(a, 'urn:runtime')).toBe(false);
|
|
152
|
+
expect(first.equalBranch('urn:runtime', b)).toBe(false);
|
|
153
|
+
expect(first.looseEquals(a, new Namespace('urn:different'))).toBe(false);
|
|
154
|
+
expect(first.unequalBranch(a, first.privateNamespace())).toBe(true);
|
|
155
|
+
expect(first.looseEquals(first.privateNamespace(), first.privateNamespace())).toBe(true);
|
|
156
|
+
expect(first.looseEquals(first.privateNamespace(), second.privateNamespace())).toBe(false);
|
|
157
|
+
expect(first.strictEquals(first.privateNamespace(), first.privateNamespace())).toBe(true);
|
|
158
|
+
expect(first.looseEquals(7, '7')).toBe(true);
|
|
159
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
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 buildScriptFunctionTraitAbc(privateInitializer = false, declaredMethod = 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(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(privateInitializer ? 6 : 5); str(''); str('ScriptClass'); str('Object'); str('initDecodeJson');
|
|
19
|
+
if (privateInitializer) str('captured');
|
|
20
|
+
u30(privateInitializer ? 3 : 2); bytes.push(0x16); u30(1);
|
|
21
|
+
if (privateInitializer) { bytes.push(declaredMethod ? 0x17 : 0x05); u30(1); }
|
|
22
|
+
u30(privateInitializer ? 2 : 0);
|
|
23
|
+
if (privateInitializer) { u30(2); u30(2); u30(1); }
|
|
24
|
+
u30(privateInitializer ? 6 : 4);
|
|
25
|
+
bytes.push(0x07); u30(1); u30(2); // ScriptClass
|
|
26
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
27
|
+
bytes.push(0x07); u30(privateInitializer ? 2 : 1); u30(4); // initDecodeJson QName
|
|
28
|
+
if (privateInitializer) {
|
|
29
|
+
bytes.push(0x09); u30(4); u30(1); // initDecodeJson namespace set
|
|
30
|
+
bytes.push(0x07); u30(1); u30(5); // captured public property
|
|
31
|
+
}
|
|
32
|
+
u30(4); for (let i = 0; i < 4; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
33
|
+
u30(0); // metadata
|
|
34
|
+
u30(1); // one class
|
|
35
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(0); // instance, no traits
|
|
36
|
+
u30(1); u30(0); // class info
|
|
37
|
+
u30(privateInitializer ? 2 : 1);
|
|
38
|
+
if (declaredMethod) { u30(1); u30(1); u30(1); bytes.push(0x04); u30(2); u30(0); }
|
|
39
|
+
else if (privateInitializer) { u30(1); u30(0); } // preceding independent script
|
|
40
|
+
u30(2); u30(declaredMethod ? 1 : privateInitializer ? 2 : 1);
|
|
41
|
+
u30(3); bytes.push(declaredMethod ? 0x01 : 0x05); u30(declaredMethod ? 0 : 1); u30(3);
|
|
42
|
+
if (privateInitializer && !declaredMethod) {
|
|
43
|
+
u30(1); bytes.push(0x04); u30(2); u30(0); // class trait, assigns owning script
|
|
44
|
+
}
|
|
45
|
+
const initCode = declaredMethod ? [0x47] : privateInitializer
|
|
46
|
+
? [0x5d, 4, 0x40, 3, 0x61, 3, 0x47]
|
|
47
|
+
: [0x5d, 3, 0x21, 0x61, 3, 0x47];
|
|
48
|
+
u30(4); // method bodies
|
|
49
|
+
const ctorCode = declaredMethod ? [0xd0, 0x5d, 3, 0x46, 3, 0, 0x61, 5, 0x47]
|
|
50
|
+
: privateInitializer ? [0xd0, 0x60, 4, 0x61, 5, 0x47] : [0x47];
|
|
51
|
+
body(0, ctorCode);
|
|
52
|
+
body(1, [0x47]);
|
|
53
|
+
body(2, initCode);
|
|
54
|
+
body(3, privateInitializer ? [0x24, 42, 0x48] : [0x47]);
|
|
55
|
+
return new Uint8Array(bytes);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('AVM2 script trait declarations', () => {
|
|
59
|
+
it('resolves a private script function through a namespace set from its initializer and owning class', () => {
|
|
60
|
+
const diagnostics = new DiagnosticsCollector();
|
|
61
|
+
const js = transpileAvm2(buildScriptFunctionTraitAbc(true), diagnostics);
|
|
62
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
63
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
64
|
+
const ScriptClass = new Function(`${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn ScriptClass;`)();
|
|
65
|
+
expect(new ScriptClass().captured()).toBe(42);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('links a package-internal method trait from a later script without an assignment initializer', () => {
|
|
69
|
+
const diagnostics = new DiagnosticsCollector();
|
|
70
|
+
const js = transpileAvm2(buildScriptFunctionTraitAbc(true, true), diagnostics);
|
|
71
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
72
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
73
|
+
const ScriptClass = new Function(`${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn ScriptClass;`)();
|
|
74
|
+
expect(new ScriptClass().captured).toBe(42);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('predeclares function traits before strict lookup in script initialization', () => {
|
|
78
|
+
const diagnostics = new DiagnosticsCollector();
|
|
79
|
+
const js = transpileAvm2(buildScriptFunctionTraitAbc(), diagnostics);
|
|
80
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
81
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
82
|
+
expect(js).toMatch(/_createAvm2ScriptScopes\([^,]+, [^\n]*"initDecodeJson"/);
|
|
83
|
+
|
|
84
|
+
const scopes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn _avm2ScriptScopeObjects;`)();
|
|
85
|
+
const scope = Object.values(scopes)[0];
|
|
86
|
+
expect(Object.prototype.hasOwnProperty.call(scope, 'initDecodeJson')).toBe(true);
|
|
87
|
+
expect(scope.initDecodeJson).toBeUndefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
import { AVM2_RUNTIME_BOOTSTRAP } from '../runtime/avm2-runtime.js';
|
|
4
|
+
|
|
5
|
+
describe('shared AVM2 runtime', () => {
|
|
6
|
+
it('gives each movie its own definitions, script slots, initialization queue, and memory', () => {
|
|
7
|
+
const hostGlobal = Object.create(globalThis);
|
|
8
|
+
const hostRuntime = new Function('globalThis', `${SWFLIB_SOURCE}\nreturn globalThis.__swoof_swflib;`)(hostGlobal);
|
|
9
|
+
const attachMovie = new Function('globalThis', '__swoof_swflib', `${AVM2_RUNTIME_BOOTSTRAP}
|
|
10
|
+
return {
|
|
11
|
+
_classes, _getDefinition, _getlexScoped, _registerGlobalSlot, _getGlobalSlot, _setGlobalSlot,
|
|
12
|
+
_queueAvm2ClassInitializer, _runAvm2Initializers, _memRead, _memWrite
|
|
13
|
+
};
|
|
14
|
+
`);
|
|
15
|
+
const parent = attachMovie(hostGlobal, hostRuntime);
|
|
16
|
+
const childGlobal = Object.create(hostGlobal);
|
|
17
|
+
const childRuntime = Object.create(hostRuntime);
|
|
18
|
+
const { ApplicationDomain, ByteArray } = hostRuntime.builtins;
|
|
19
|
+
const childDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
|
|
20
|
+
childRuntime.builtins = { ...hostRuntime.builtins, ApplicationDomain: { currentDomain: childDomain } };
|
|
21
|
+
childRuntime.setAvm2DefinitionLookup = () => {};
|
|
22
|
+
const child = attachMovie(childGlobal, childRuntime);
|
|
23
|
+
class ParentType {}
|
|
24
|
+
class ChildType {}
|
|
25
|
+
parent._classes['shared.Name'] = ParentType;
|
|
26
|
+
child._classes['shared.Name'] = ChildType;
|
|
27
|
+
|
|
28
|
+
expect(parent._getlexScoped('shared.Name', null, [])).toBe(ParentType);
|
|
29
|
+
expect(child._getlexScoped('shared.Name', null, [])).toBe(ChildType);
|
|
30
|
+
expect(hostRuntime.builtins.ApplicationDomain.currentDomain.getDefinition('shared.Name')).toBe(ParentType);
|
|
31
|
+
|
|
32
|
+
parent._registerGlobalSlot('abc', 0, 1, 'owner', 0);
|
|
33
|
+
child._registerGlobalSlot('abc', 0, 1, 'owner', 0);
|
|
34
|
+
parent._setGlobalSlot('abc', 0, 1, 'parent');
|
|
35
|
+
child._queueAvm2ClassInitializer(() => child._setGlobalSlot('abc', 0, 1, 'child'));
|
|
36
|
+
parent._runAvm2Initializers();
|
|
37
|
+
expect(childGlobal).not.toHaveProperty('owner', 'child');
|
|
38
|
+
child._runAvm2Initializers();
|
|
39
|
+
expect(parent._getGlobalSlot('abc', 0, 1)).toBe('parent');
|
|
40
|
+
expect(child._getGlobalSlot('abc', 0, 1)).toBe('child');
|
|
41
|
+
|
|
42
|
+
for (const domain of [ApplicationDomain.currentDomain, childDomain]) {
|
|
43
|
+
const memory = new ByteArray();
|
|
44
|
+
memory.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
|
|
45
|
+
domain.domainMemory = memory;
|
|
46
|
+
}
|
|
47
|
+
parent._memWrite(0x3a, 0, 12);
|
|
48
|
+
child._memWrite(0x3a, 0, 24);
|
|
49
|
+
expect(parent._memRead(0x35, 0)).toBe(12);
|
|
50
|
+
expect(child._memRead(0x35, 0)).toBe(24);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
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 buildSlotAbc(codeBytes) {
|
|
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
|
+
u16(16); u16(46);
|
|
11
|
+
u30(0); u30(0); u30(0);
|
|
12
|
+
u30(5); str(''); str('TestClass'); str('Sprite'); str('foo');
|
|
13
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
14
|
+
u30(0);
|
|
15
|
+
u30(4); bytes.push(0x07); u30(1); u30(2); bytes.push(0x07); u30(1); u30(3); bytes.push(0x07); u30(1); u30(4);
|
|
16
|
+
u30(3); for (let m = 0; m < 3; m++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
17
|
+
u30(0);
|
|
18
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1);
|
|
19
|
+
u30(3); bytes.push(0); u30(1); u30(0); u30(0); // foo instance slot ID 1
|
|
20
|
+
u30(1); u30(0);
|
|
21
|
+
u30(1); u30(2); u30(0);
|
|
22
|
+
u30(1); u30(0); u30(4); u30(2); u30(1); u30(3); u30(codeBytes.length);
|
|
23
|
+
for (const b of codeBytes) bytes.push(b);
|
|
24
|
+
u30(0); u30(0);
|
|
25
|
+
return new Uint8Array(bytes);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function buildInheritedSlotAbc() {
|
|
29
|
+
const bytes = [];
|
|
30
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
31
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
32
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
33
|
+
u16(16); u16(46);
|
|
34
|
+
u30(2); bytes.push(7); // int pool: index 1 is 7
|
|
35
|
+
u30(0); u30(0); // empty uints, doubles
|
|
36
|
+
u30(10);
|
|
37
|
+
['BaseSlot', 'ChildSlot', 'OtherSlot', 'Object', 'baseValue', 'childValue', 'otherValue', 'Number', 'int'].forEach(str);
|
|
38
|
+
u30(2); bytes.push(0x16); u30(1); // package namespace
|
|
39
|
+
u30(0); // ns sets
|
|
40
|
+
const names = [0, 1, 4, 2, 3, 5, 6, 7, 8, 9];
|
|
41
|
+
u30(names.length);
|
|
42
|
+
for (let i = 1; i < names.length; i++) { bytes.push(0x07); u30(1); u30(names[i]); }
|
|
43
|
+
u30(7); // methods
|
|
44
|
+
for (let i = 0; i < 7; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
45
|
+
u30(0); // metadata
|
|
46
|
+
u30(3); // instances
|
|
47
|
+
const instance = (name, superName, init, traitName, slotId, typeName, valueIndex = 0, valueKind = 0) => {
|
|
48
|
+
u30(name); u30(superName); bytes.push(0); u30(0); u30(init); u30(1);
|
|
49
|
+
u30(traitName); bytes.push(0); u30(slotId); u30(typeName); u30(valueIndex);
|
|
50
|
+
if (valueIndex) bytes.push(valueKind);
|
|
51
|
+
};
|
|
52
|
+
instance(1, 2, 0, 5, 1, 8); // BaseSlot.baseValue:Number, id 1
|
|
53
|
+
instance(3, 1, 1, 6, 2, 9); // ChildSlot.childValue:int, id 2
|
|
54
|
+
instance(4, 2, 2, 7, 1, 9, 1, 0x03); // OtherSlot.otherValue:int=7, id 1
|
|
55
|
+
for (let i = 3; i < 6; i++) { u30(i); u30(0); }
|
|
56
|
+
u30(1); u30(6); u30(0); // script
|
|
57
|
+
const bodies = [
|
|
58
|
+
[0x47], // base leaves Number's default NaN intact
|
|
59
|
+
[0x49, 0, 0xd0, 0x24, 33, 0x6d, 1, 0x47],
|
|
60
|
+
[0x47],
|
|
61
|
+
];
|
|
62
|
+
u30(bodies.length);
|
|
63
|
+
for (let i = 0; i < bodies.length; i++) {
|
|
64
|
+
const code = bodies[i];
|
|
65
|
+
u30(i); u30(2); u30(1); u30(1); u30(1); u30(code.length); bytes.push(...code); u30(0); u30(0);
|
|
66
|
+
}
|
|
67
|
+
return new Uint8Array(bytes);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('AVM2 slot operations', () => {
|
|
71
|
+
it('maps instance slot IDs to declared trait properties', () => {
|
|
72
|
+
// getlocal0; pushbyte 35; setslot 1; getlocal0; dup; getslot 1; setslot 1; returnvoid
|
|
73
|
+
const code = [0xd0, 0x24, 35, 0x6d, 1, 0xd0, 0x2a, 0x6c, 1, 0x6d, 1, 0x47];
|
|
74
|
+
const diagnostics = new DiagnosticsCollector();
|
|
75
|
+
const js = transpileAvm2(buildSlotAbc(code), diagnostics);
|
|
76
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
77
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
78
|
+
expect(js).toContain('_setSlot(this, 1, 35, true)');
|
|
79
|
+
expect(js).toContain('_getSlot(this, 1)');
|
|
80
|
+
const TestClass = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn TestClass;`)();
|
|
81
|
+
expect(new TestClass().foo).toBe(35);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('throws when a slot operation targets null or undefined', () => {
|
|
85
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}\nreturn { get: _getSlot, set: _setSlot };`)();
|
|
86
|
+
expect(() => helpers.get(null, 1)).toThrow(TypeError);
|
|
87
|
+
expect(() => helpers.set(undefined, 1, 3)).toThrow(TypeError);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('preserves inherited slots, dynamic slot storage, typed defaults, and per-class slot IDs', () => {
|
|
91
|
+
const diagnostics = new DiagnosticsCollector();
|
|
92
|
+
const js = transpileAvm2(buildInheritedSlotAbc(), diagnostics);
|
|
93
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
94
|
+
const runtime = new Function(`class ObjectBase {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn { BaseSlot, ChildSlot, OtherSlot, get: _getSlot, set: _setSlot };`)();
|
|
95
|
+
const base = new runtime.BaseSlot();
|
|
96
|
+
expect(Number.isNaN(base.baseValue)).toBe(true);
|
|
97
|
+
const child = new runtime.ChildSlot();
|
|
98
|
+
expect(child.baseValue).toBe(33);
|
|
99
|
+
expect(child.childValue).toBe(0);
|
|
100
|
+
expect(runtime.get(child, 1)).toBe(33); // inherited slot maps through the child class
|
|
101
|
+
expect(runtime.get(child, 2)).toBe(0);
|
|
102
|
+
runtime.set(child, 2, 22);
|
|
103
|
+
expect(child.childValue).toBe(22);
|
|
104
|
+
expect(runtime.get(child, 2)).toBe(22);
|
|
105
|
+
const other = new runtime.OtherSlot();
|
|
106
|
+
expect(runtime.get(other, 1)).toBe(7); // colliding slot ID is local to this class
|
|
107
|
+
runtime.set(other, 1, 44);
|
|
108
|
+
expect(other.otherValue).toBe(44);
|
|
109
|
+
runtime.set(other, 77, 66); // dynamic instance unknown slots use hidden per-instance storage
|
|
110
|
+
expect(runtime.get(other, 77)).toBe(66);
|
|
111
|
+
|
|
112
|
+
child.dynamicField = 'dynamic';
|
|
113
|
+
expect(child.dynamicField).toBe('dynamic');
|
|
114
|
+
expect(Object.keys(other)).not.toContain('__slots');
|
|
115
|
+
expect(child.constructor.__swoofDynamic).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
});
|