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,166 @@
|
|
|
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 buildStaticGetlexAbc() {
|
|
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
|
+
u16(16); u16(46);
|
|
16
|
+
u30(0); u30(0); u30(0);
|
|
17
|
+
u30(6); str(''); str('SpilGamesServices'); str('Object'); str('_instance'); str('getInstance');
|
|
18
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
19
|
+
u30(0);
|
|
20
|
+
u30(5);
|
|
21
|
+
bytes.push(0x07); u30(1); u30(2); // class
|
|
22
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
23
|
+
bytes.push(0x07); u30(1); u30(4); // _instance
|
|
24
|
+
bytes.push(0x07); u30(1); u30(5); // getInstance
|
|
25
|
+
u30(4); for (let i = 0; i < 4; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
26
|
+
u30(0); // metadata
|
|
27
|
+
u30(1); // one class
|
|
28
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(0); // instance has no traits
|
|
29
|
+
u30(1); u30(2); // class initializer and trait count
|
|
30
|
+
u30(3); bytes.push(0); u30(1); u30(0); u30(0); // _instance slot 1
|
|
31
|
+
u30(4); bytes.push(1); u30(1); u30(3); // getInstance method 3
|
|
32
|
+
u30(1); u30(2); u30(0); // script init method 2, no traits
|
|
33
|
+
u30(4); // method bodies
|
|
34
|
+
body(0, [0x47]); body(1, [0x47]); body(2, [0x47]);
|
|
35
|
+
body(3, [0x60, 3, 0x48]); // getlex _instance; returnvalue
|
|
36
|
+
return new Uint8Array(bytes);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('AVM2 getlex', () => {
|
|
40
|
+
it('reads static members from the active class receiver before global fallback', () => {
|
|
41
|
+
const diagnostics = new DiagnosticsCollector();
|
|
42
|
+
const js = transpileAvm2(buildStaticGetlexAbc(), diagnostics);
|
|
43
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
44
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
45
|
+
expect(js).toContain('_getlexScoped("_instance", this, [])');
|
|
46
|
+
|
|
47
|
+
const previous = globalThis._instance;
|
|
48
|
+
const fallback = { source: 'global' };
|
|
49
|
+
const field = { source: 'class static' };
|
|
50
|
+
globalThis._instance = fallback;
|
|
51
|
+
try {
|
|
52
|
+
const Class = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn SpilGamesServices;`)();
|
|
53
|
+
expect(Class.getInstance()).toBeUndefined();
|
|
54
|
+
Class._instance = field;
|
|
55
|
+
expect(Class.getInstance()).toBe(field);
|
|
56
|
+
} finally {
|
|
57
|
+
if (previous === undefined) delete globalThis._instance;
|
|
58
|
+
else globalThis._instance = previous;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps the owning class when a declared static method is fetched as a callback', () => {
|
|
63
|
+
const diagnostics = new DiagnosticsCollector();
|
|
64
|
+
const js = transpileAvm2(buildStaticGetlexAbc(), diagnostics);
|
|
65
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
66
|
+
const { type, getlex } = new Function(`${AVM2_RUNTIME_STUB}
|
|
67
|
+
${js}
|
|
68
|
+
return { type: SpilGamesServices, getlex: _getlexScoped };
|
|
69
|
+
`)();
|
|
70
|
+
const field = {};
|
|
71
|
+
type._instance = field;
|
|
72
|
+
const callback = getlex('getInstance', type, []);
|
|
73
|
+
expect(callback).toBe(getlex('getInstance', type, []));
|
|
74
|
+
expect(callback.call({ _instance: 'wrong receiver' })).toBe(field);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('falls through an undefined script placeholder to the emitted class while preserving null', () => {
|
|
78
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}\nreturn { getlex: _getlexScoped, classes: _classes };`)();
|
|
79
|
+
const previous = Object.getOwnPropertyDescriptor(globalThis, 'API');
|
|
80
|
+
class API {}
|
|
81
|
+
try {
|
|
82
|
+
helpers.classes.API = API;
|
|
83
|
+
Object.defineProperty(globalThis, 'API', { value: undefined, writable: true, configurable: true });
|
|
84
|
+
expect(helpers.getlex('API', globalThis, [])).toBe(API);
|
|
85
|
+
globalThis.API = null;
|
|
86
|
+
expect(helpers.getlex('API', globalThis, [])).toBeNull();
|
|
87
|
+
} finally {
|
|
88
|
+
delete helpers.classes.API;
|
|
89
|
+
if (previous) Object.defineProperty(globalThis, 'API', previous);
|
|
90
|
+
else delete globalThis.API;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('redirects a leftover flash package name to the swoof class', () => {
|
|
95
|
+
const helpers = new Function(`
|
|
96
|
+
function GlowFilter() {}
|
|
97
|
+
var __swoof_swflib = { builtins: { GlowFilter }, packages: { filters: { GlowFilter } } };
|
|
98
|
+
${AVM2_RUNTIME_STUB}
|
|
99
|
+
return { classes: _classes, getlex: _getlex, read: _avm2GetProperty, findProp: _findProp, pkg: _swoofPackage, GlowFilter };
|
|
100
|
+
`)();
|
|
101
|
+
const GlowFilter = helpers.GlowFilter;
|
|
102
|
+
const missed = {};
|
|
103
|
+
expect(helpers.classes['flash.filters.GlowFilter']).toBe(GlowFilter);
|
|
104
|
+
expect(helpers.classes['swoof.filters.GlowFilter']).toBe(GlowFilter);
|
|
105
|
+
expect(helpers.classes['flash.filters::GlowFilter']).toBe(GlowFilter);
|
|
106
|
+
expect(helpers.getlex('flash.filters.GlowFilter')).toBe(GlowFilter);
|
|
107
|
+
expect(helpers.findProp('flash.filters.GlowFilter', null, [], true, false)['flash.filters.GlowFilter']).toBe(GlowFilter);
|
|
108
|
+
expect(helpers.read(missed, 'flash.filters.GlowFilter')).toBe(GlowFilter);
|
|
109
|
+
expect(helpers.pkg(function () { return undefined; }, function () { return helpers.getlex('flash.filters.GlowFilter'); })).toBe(GlowFilter);
|
|
110
|
+
expect(helpers.pkg(function () { throw new TypeError('missing'); }, function () { return GlowFilter; })).toBe(GlowFilter);
|
|
111
|
+
expect(helpers.pkg(function () { return GlowFilter; }, function () { throw new Error('unused'); })).toBe(GlowFilter);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('resolves qualified Flash built-ins through strict findprop before package getlex', () => {
|
|
115
|
+
const helpers = new Function(`
|
|
116
|
+
var EventDispatcher = function EventDispatcher() {};
|
|
117
|
+
var Timer = function Timer() {};
|
|
118
|
+
var MovieClip = function MovieClip() {};
|
|
119
|
+
var __swoof_swflib = { builtins: { EventDispatcher, Timer, MovieClip }, packages: {
|
|
120
|
+
flash: { events: { EventDispatcher }, utils: { Timer }, display: { MovieClip } }
|
|
121
|
+
}};
|
|
122
|
+
${AVM2_RUNTIME_STUB}
|
|
123
|
+
return { findProp: _findProp, getlex: _getlexScoped, classes: _classes };
|
|
124
|
+
`)();
|
|
125
|
+
|
|
126
|
+
expect(helpers.findProp('flash.events.EventDispatcher', null, [], true, false)).toBe(helpers.classes);
|
|
127
|
+
expect(helpers.getlex('flash.events.EventDispatcher', globalThis, [])).toBe(helpers.classes.EventDispatcher);
|
|
128
|
+
expect(helpers.findProp('flash.utils.Timer', null, [], true, false)).toBe(helpers.classes);
|
|
129
|
+
expect(helpers.getlex('flash.utils.Timer', globalThis, [])).toBe(helpers.classes.Timer);
|
|
130
|
+
expect(helpers.findProp('flash.display.MovieClip', null, [], true, false)).toBe(helpers.classes);
|
|
131
|
+
expect(helpers.getlex('flash.display.MovieClip', globalThis, [])).toBe(helpers.classes.MovieClip);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('resolves AVM2 namespace-set members by the namespace key actually present on the receiver', () => {
|
|
135
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}
|
|
136
|
+
return { get: _avm2GetProperty, set: _avm2SetProperty, del: _avm2DeleteProperty };
|
|
137
|
+
`)();
|
|
138
|
+
const key = '__avm2ns_23_358_frame1';
|
|
139
|
+
const fn = function () { return this.marker; };
|
|
140
|
+
const object = Object.create({ [key]: fn });
|
|
141
|
+
object.marker = 'receiver';
|
|
142
|
+
const keys = ['__avm2ns_5_458_frame1', key];
|
|
143
|
+
|
|
144
|
+
expect(helpers.get(object, 'frame1', keys)).toBe(fn);
|
|
145
|
+
helpers.set(object, 'frame1', 'updated', keys);
|
|
146
|
+
expect(object[key]).toBe('updated');
|
|
147
|
+
expect(helpers.del(object, 'frame1', keys)).toBe(true);
|
|
148
|
+
expect(Object.prototype.hasOwnProperty.call(object, key)).toBe(false);
|
|
149
|
+
expect(key in object).toBe(true); // inherited trait remains on the prototype
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('resolves callable methods past uninitialized namespace-set slots', () => {
|
|
153
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}
|
|
154
|
+
return { getMethod: _avm2GetMethod };
|
|
155
|
+
`)();
|
|
156
|
+
const object = Object.create({ overrideTargetTransform() { return 'method'; } });
|
|
157
|
+
object.__avm2ns_5_458_overrideTargetTransform = undefined;
|
|
158
|
+
const method = helpers.getMethod(object, 'overrideTargetTransform', [
|
|
159
|
+
'__avm2ns_5_458_overrideTargetTransform',
|
|
160
|
+
'overrideTargetTransform',
|
|
161
|
+
]);
|
|
162
|
+
|
|
163
|
+
expect(method).toBe(object.overrideTargetTransform);
|
|
164
|
+
expect(method.call(object)).toBe('method');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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 buildScriptGlobalSlotsAbc() {
|
|
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
|
+
|
|
11
|
+
u16(16); u16(46);
|
|
12
|
+
u30(0); u30(0); u30(0);
|
|
13
|
+
u30(4); str(''); str('scriptValue'); str('readBack');
|
|
14
|
+
u30(2); bytes.push(0x16); u30(1); // public package namespace
|
|
15
|
+
u30(0); // namespace sets
|
|
16
|
+
u30(3);
|
|
17
|
+
bytes.push(0x07); u30(1); u30(2); // scriptValue
|
|
18
|
+
bytes.push(0x07); u30(1); u30(3); // readBack
|
|
19
|
+
u30(1); // method count
|
|
20
|
+
u30(0); u30(0); u30(0); bytes.push(0); // method_info
|
|
21
|
+
u30(0); // metadata
|
|
22
|
+
u30(0); // classes
|
|
23
|
+
u30(1); u30(0); u30(2); // one script, init method 0, two traits
|
|
24
|
+
u30(1); bytes.push(0); u30(1); u30(0); u30(0); // scriptValue slot id 1
|
|
25
|
+
u30(2); bytes.push(0); u30(2); u30(0); u30(0); // readBack slot id 2
|
|
26
|
+
const code = [0x20, 0x6f, 1, 0x6e, 1, 0x6f, 2, 0x47]; // null -> slot 1 -> slot 2
|
|
27
|
+
u30(1); // method bodies
|
|
28
|
+
u30(0); u30(1); u30(1); u30(0); u30(1); u30(code.length);
|
|
29
|
+
for (const byte of code) bytes.push(byte);
|
|
30
|
+
u30(0); u30(0);
|
|
31
|
+
return new Uint8Array(bytes);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('AVM2 global slots', () => {
|
|
35
|
+
it('maps script global slot IDs to declared names for reads and writes', () => {
|
|
36
|
+
const diagnostics = new DiagnosticsCollector();
|
|
37
|
+
const js = transpileAvm2(buildScriptGlobalSlotsAbc(), diagnostics);
|
|
38
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
39
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
40
|
+
expect(js).toContain('_createAvm2ScriptScopes(');
|
|
41
|
+
expect(js).not.toContain('_registerGlobalSlot(');
|
|
42
|
+
expect(js).toContain('_setGlobalSlot(');
|
|
43
|
+
expect(js).toContain('_getGlobalSlot(');
|
|
44
|
+
|
|
45
|
+
const scopes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn _avm2ScriptScopeObjects;`)();
|
|
46
|
+
const scope = Object.values(scopes)[0];
|
|
47
|
+
expect(scope.scriptValue).toBeNull();
|
|
48
|
+
expect(scope.readBack).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('retains the numeric fallback for unmapped global slots', () => {
|
|
52
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}\nreturn { get: _getGlobalSlot, set: _setGlobalSlot };`)();
|
|
53
|
+
const id = `unmapped_${Date.now()}`;
|
|
54
|
+
helpers.set(id, 0, 7, 'fallback');
|
|
55
|
+
expect(helpers.get(id, 0, 7)).toBe('fallback');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps same-numbered slots and declaration scopes separate across scripts', () => {
|
|
59
|
+
const diagnostics = new DiagnosticsCollector();
|
|
60
|
+
const js = transpileAvm2(buildMultipleScriptScopesAbc(), diagnostics);
|
|
61
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
62
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
63
|
+
const scopes = new Function(`${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn _avm2ScriptScopeObjects;`)();
|
|
64
|
+
const [first, second] = Object.values(scopes);
|
|
65
|
+
expect(first.firstName).toBe('first');
|
|
66
|
+
expect(first.firstCopy).toBe('first');
|
|
67
|
+
expect(second.secondName).toBe('second');
|
|
68
|
+
expect(second.secondCopy).toBe('second');
|
|
69
|
+
expect(first.secondName).toBeUndefined();
|
|
70
|
+
expect(second.firstName).toBe('first'); // inherited declaration remains visible through the script scope chain
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function buildMultipleScriptScopesAbc() {
|
|
75
|
+
const bytes = [];
|
|
76
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
77
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
78
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
79
|
+
u16(16); u16(46);
|
|
80
|
+
u30(0); u30(0); u30(0);
|
|
81
|
+
u30(7); for (const s of ['firstName', 'firstCopy', 'secondName', 'secondCopy', 'first', 'second']) str(s);
|
|
82
|
+
u30(2); bytes.push(0x16); u30(0);
|
|
83
|
+
u30(0); // namespace sets
|
|
84
|
+
u30(5);
|
|
85
|
+
for (const nameIndex of [1, 2, 3, 4]) { bytes.push(0x07); u30(1); u30(nameIndex); }
|
|
86
|
+
u30(2); // script init methods
|
|
87
|
+
for (let i = 0; i < 2; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
88
|
+
u30(0); // metadata
|
|
89
|
+
u30(0); // classes
|
|
90
|
+
u30(2); // scripts
|
|
91
|
+
u30(0); u30(2);
|
|
92
|
+
u30(1); bytes.push(0); u30(1); u30(0); u30(0); // firstName slot 1
|
|
93
|
+
u30(2); bytes.push(0); u30(2); u30(0); u30(0); // firstCopy slot 2
|
|
94
|
+
u30(1); u30(2);
|
|
95
|
+
u30(3); bytes.push(0); u30(1); u30(0); u30(0); // secondName slot 1
|
|
96
|
+
u30(4); bytes.push(0); u30(2); u30(0); u30(0); // secondCopy slot 2
|
|
97
|
+
u30(2); // method bodies
|
|
98
|
+
const body = (method, stringIndex) => {
|
|
99
|
+
const code = [0x2c, stringIndex, 0x6f, 1, 0x6e, 1, 0x6f, 2, 0x47];
|
|
100
|
+
u30(method); u30(2); u30(1); u30(0); u30(1); u30(code.length);
|
|
101
|
+
for (const byte of code) bytes.push(byte);
|
|
102
|
+
u30(0); u30(0);
|
|
103
|
+
};
|
|
104
|
+
body(0, 5); body(1, 6);
|
|
105
|
+
return new Uint8Array(bytes);
|
|
106
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 buildClassAbc({ name, parent = 'Object', contract, isInterface = false, value }) {
|
|
6
|
+
const bytes = [];
|
|
7
|
+
const u16 = v => bytes.push(v & 255, (v >> 8) & 255);
|
|
8
|
+
const u30 = v => {
|
|
9
|
+
while (v >= 128) { bytes.push((v & 127) | 128); v >>>= 7; }
|
|
10
|
+
bytes.push(v);
|
|
11
|
+
};
|
|
12
|
+
const str = s => { const value = new TextEncoder().encode(s); u30(value.length); bytes.push(...value); };
|
|
13
|
+
const qname = (namespace, index) => { bytes.push(0x07); u30(namespace); u30(index); };
|
|
14
|
+
const method = () => { u30(0); u30(0); u30(0); bytes.push(0); };
|
|
15
|
+
const body = (methodIndex, code) => {
|
|
16
|
+
u30(methodIndex); u30(2); u30(1); u30(0); u30(1); u30(code.length);
|
|
17
|
+
bytes.push(...code); u30(0); u30(0);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
u16(16); u16(46);
|
|
21
|
+
u30(0); u30(0); u30(0);
|
|
22
|
+
const strings = ['', 'api', `api:${name}`, name, parent, contract || '', 'ping', 'status'];
|
|
23
|
+
u30(strings.length + 1);
|
|
24
|
+
for (const s of strings) str(s);
|
|
25
|
+
u30(4);
|
|
26
|
+
bytes.push(0x16); u30(1); // default public
|
|
27
|
+
bytes.push(0x16); u30(2); // api package
|
|
28
|
+
bytes.push(0x08); u30(3); // qualified interface member
|
|
29
|
+
u30(0);
|
|
30
|
+
u30(6);
|
|
31
|
+
qname(isInterface ? 2 : 1, 4); // class/interface name
|
|
32
|
+
qname(1, 5); // superclass
|
|
33
|
+
qname(2, 6); // implemented/extended interface
|
|
34
|
+
qname(isInterface ? 3 : 1, 7); // ping
|
|
35
|
+
qname(isInterface ? 3 : 1, 8); // status
|
|
36
|
+
u30(isInterface ? 5 : 3);
|
|
37
|
+
for (let i = 0; i < (isInterface ? 5 : 3); i++) method();
|
|
38
|
+
u30(0);
|
|
39
|
+
u30(1); // one instance and class
|
|
40
|
+
u30(1); u30(2); bytes.push(isInterface ? 4 : 0);
|
|
41
|
+
u30(contract ? 1 : 0); if (contract) u30(3);
|
|
42
|
+
u30(0); // iinit
|
|
43
|
+
u30(isInterface ? 3 : 1);
|
|
44
|
+
u30(4); bytes.push(1); u30(0); u30(2); // method ping
|
|
45
|
+
if (isInterface) {
|
|
46
|
+
u30(5); bytes.push(2); u30(0); u30(3); // get status
|
|
47
|
+
u30(5); bytes.push(3); u30(0); u30(4); // set status
|
|
48
|
+
}
|
|
49
|
+
u30(1); u30(0); // cinit, no static traits
|
|
50
|
+
u30(0); // scripts
|
|
51
|
+
u30(isInterface ? 0 : 2);
|
|
52
|
+
if (!isInterface) {
|
|
53
|
+
body(0, [0xd0, 0x49, 0, 0x47]); // super(); returnvoid
|
|
54
|
+
body(2, [0x24, value, 0x48]); // pushbyte value; returnvalue
|
|
55
|
+
}
|
|
56
|
+
return Uint8Array.from(bytes);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('AVM2 interface traits', () => {
|
|
60
|
+
it('links interface methods and accessors across ABCs and follows subclass overrides', () => {
|
|
61
|
+
const diagnostics = new DiagnosticsCollector();
|
|
62
|
+
const base = transpileAvm2(buildClassAbc({ name: 'Base', contract: 'IChild', value: 10 }), diagnostics);
|
|
63
|
+
const derived = transpileAvm2(buildClassAbc({ name: 'Derived', parent: 'Base', value: 42 }), diagnostics);
|
|
64
|
+
const child = transpileAvm2(buildClassAbc({ name: 'IChild', contract: 'IParent', isInterface: true }), diagnostics);
|
|
65
|
+
const parent = transpileAvm2(buildClassAbc({ name: 'IParent', isInterface: true }), diagnostics);
|
|
66
|
+
const unrelated = transpileAvm2(buildClassAbc({ name: 'IUnrelated', isInterface: true }), diagnostics);
|
|
67
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
68
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
69
|
+
|
|
70
|
+
const runtime = new Function(`${AVM2_RUNTIME_STUB}\n${base}\n${derived}\n${child}\n${parent}\n${unrelated}
|
|
71
|
+
_runAvm2Initializers();
|
|
72
|
+
return { Base, Derived, IChild, IParent, IUnrelated, asType: _asType, call: _avm2Call, read: _avm2GetProperty };
|
|
73
|
+
`)();
|
|
74
|
+
const { Base, Derived, IParent, IChild, IUnrelated, asType, call, read } = runtime;
|
|
75
|
+
const key = Object.getOwnPropertyNames(IParent.prototype).find(name => name.endsWith('_ping'));
|
|
76
|
+
const statusKey = Object.getOwnPropertyNames(IParent.prototype).find(name => name.endsWith('_status'));
|
|
77
|
+
const baseValue = new Base();
|
|
78
|
+
const derivedValue = new Derived();
|
|
79
|
+
expect(baseValue[key]()).toBe(10);
|
|
80
|
+
expect(derivedValue[key]()).toBe(42);
|
|
81
|
+
expect(read(derivedValue, key)()).toBe(42);
|
|
82
|
+
derivedValue[statusKey] = 'ready';
|
|
83
|
+
expect(derivedValue.status).toBe('ready');
|
|
84
|
+
expect(derivedValue[statusKey]).toBe('ready');
|
|
85
|
+
expect(asType(derivedValue, IParent)).toBe(derivedValue);
|
|
86
|
+
expect(asType(derivedValue, IChild)).toBe(derivedValue);
|
|
87
|
+
expect(asType(derivedValue, IUnrelated)).toBeNull();
|
|
88
|
+
const unrelatedKey = Object.getOwnPropertyNames(IUnrelated.prototype).find(name => name.endsWith('_ping'));
|
|
89
|
+
expect(derivedValue[unrelatedKey]).toBeUndefined();
|
|
90
|
+
expect(asType({ ping() {} }, IParent)).toBeNull();
|
|
91
|
+
expect(typeof ({ ping() {} })[key]).toBe('undefined');
|
|
92
|
+
expect(call(IParent, null, [derivedValue])).toBe(derivedValue);
|
|
93
|
+
expect(() => call(IParent, null, [{}])).toThrow(TypeError);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
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 u30(bytes, value) {
|
|
6
|
+
let n = value >>> 0;
|
|
7
|
+
while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; }
|
|
8
|
+
bytes.push(n);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function str(bytes, value) {
|
|
12
|
+
const encoded = new TextEncoder().encode(value);
|
|
13
|
+
u30(bytes, encoded.length);
|
|
14
|
+
for (const byte of encoded) bytes.push(byte);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function buildNamespaceSetAbc() {
|
|
18
|
+
const b = [16, 0, 46, 0];
|
|
19
|
+
u30(b, 0); u30(b, 0); u30(b, 0);
|
|
20
|
+
u30(b, 7);
|
|
21
|
+
for (const value of ['App', 'Object', 'foo', 'custom', 'read', 'bar']) str(b, value);
|
|
22
|
+
u30(b, 3); b.push(0x16); u30(b, 1); b.push(0x08); u30(b, 4);
|
|
23
|
+
u30(b, 2); u30(b, 2); u30(b, 2); u30(b, 1); // ns set: custom, then public
|
|
24
|
+
u30(b, 6);
|
|
25
|
+
b.push(0x07); u30(b, 1); u30(b, 1); // App
|
|
26
|
+
b.push(0x07); u30(b, 1); u30(b, 2); // Object
|
|
27
|
+
b.push(0x09); u30(b, 3); u30(b, 1); // foo in [custom, public]
|
|
28
|
+
b.push(0x07); u30(b, 1); u30(b, 5); // read
|
|
29
|
+
b.push(0x09); u30(b, 6); u30(b, 1); // bar shares foo's ns set
|
|
30
|
+
u30(b, 3); // methods
|
|
31
|
+
for (let i = 0; i < 3; i++) { u30(b, 0); u30(b, 0); u30(b, 0); b.push(0); }
|
|
32
|
+
u30(b, 0); // metadata
|
|
33
|
+
u30(b, 1); // classes
|
|
34
|
+
u30(b, 1); u30(b, 2); b.push(0); u30(b, 0); u30(b, 0); u30(b, 1);
|
|
35
|
+
u30(b, 4); b.push(1); u30(b, 1); u30(b, 1); // read method
|
|
36
|
+
u30(b, 2); u30(b, 0); // cinit
|
|
37
|
+
u30(b, 0); // scripts
|
|
38
|
+
u30(b, 3);
|
|
39
|
+
const body = (method, code) => {
|
|
40
|
+
u30(b, method); u30(b, 2); u30(b, 1); u30(b, 0); u30(b, 1); u30(b, code.length);
|
|
41
|
+
for (const byte of code) b.push(byte);
|
|
42
|
+
u30(b, 0); u30(b, 0);
|
|
43
|
+
};
|
|
44
|
+
body(0, [0x47]);
|
|
45
|
+
body(1, [0xd0, 0x66, 3, 0x29, 0xd0, 0x66, 5, 0x29, 0xd0, 0x66, 3, 0x48]);
|
|
46
|
+
body(2, [0x47]);
|
|
47
|
+
return new Uint8Array(b);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('AVM2 multiname namespace-set precedence', () => {
|
|
51
|
+
it('shares namespace prefixes and lookup entries across compiled property accesses', () => {
|
|
52
|
+
const diagnostics = new DiagnosticsCollector();
|
|
53
|
+
const js = transpileAvm2(buildNamespaceSetAbc(), diagnostics);
|
|
54
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
55
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
56
|
+
const prefix = js.match(/__avm2ns_8_uri_[0-9a-f]+_/)?.[0];
|
|
57
|
+
expect(prefix).toBeTruthy();
|
|
58
|
+
expect(js.split(prefix)).toHaveLength(2);
|
|
59
|
+
const calls = js.match(/_avm2GetProperty\(this, "foo", _ns[0-9a-f]+_\d+\(\d+\)\)/g);
|
|
60
|
+
expect(calls).toHaveLength(2);
|
|
61
|
+
expect(calls[0]).toBe(calls[1]);
|
|
62
|
+
const App = new Function(`${AVM2_RUNTIME_STUB}\n${js}\nreturn App;`)();
|
|
63
|
+
const target = new App();
|
|
64
|
+
const reads = [];
|
|
65
|
+
Object.defineProperty(target, prefix + 'foo', { get() { reads.push('custom foo'); return 'custom'; } });
|
|
66
|
+
Object.defineProperty(target, 'bar', { get() { reads.push('public bar'); return 'public'; } });
|
|
67
|
+
target.foo = 'public';
|
|
68
|
+
expect(target.read()).toBe('custom');
|
|
69
|
+
expect(reads).toEqual(['custom foo', 'public bar', 'custom foo']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('uses the first matching inherited, own, or public candidate for property operations', () => {
|
|
73
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}
|
|
74
|
+
return { get: _avm2GetProperty, set: _avm2SetProperty, del: _avm2DeleteProperty,
|
|
75
|
+
method: _avm2GetMethod };
|
|
76
|
+
`)();
|
|
77
|
+
const inherited = '__avm2ns_8_uri_inherited_foo';
|
|
78
|
+
const own = '__avm2ns_8_uri_own_foo';
|
|
79
|
+
const parent = { [inherited]: 'inherited-value', [inherited + 'Method']() { return this.marker; } };
|
|
80
|
+
const target = Object.create(parent);
|
|
81
|
+
target[own] = 'own-value';
|
|
82
|
+
target.foo = 'public-value';
|
|
83
|
+
target.marker = 'receiver';
|
|
84
|
+
const keys = [inherited, own, 'foo'];
|
|
85
|
+
|
|
86
|
+
expect(helpers.get(target, 'foo', keys)).toBe('inherited-value');
|
|
87
|
+
helpers.set(target, 'foo', 'changed', keys);
|
|
88
|
+
expect(target[inherited]).toBe('changed');
|
|
89
|
+
expect(parent[inherited]).toBe('inherited-value');
|
|
90
|
+
expect(target[own]).toBe('own-value');
|
|
91
|
+
expect(target.foo).toBe('public-value');
|
|
92
|
+
expect(helpers.del(target, 'foo', keys)).toBe(true);
|
|
93
|
+
expect(Object.hasOwn(target, inherited)).toBe(false);
|
|
94
|
+
expect(inherited in target).toBe(true);
|
|
95
|
+
expect(target.foo).toBe('public-value');
|
|
96
|
+
|
|
97
|
+
const callableKeys = [inherited + 'Method', own + 'Method', 'foo'];
|
|
98
|
+
parent[inherited + 'Method'] = function () { return this.marker; };
|
|
99
|
+
target[own + 'Method'] = function () { return 'own'; };
|
|
100
|
+
target.foo = function () { return 'public'; };
|
|
101
|
+
expect(helpers.method(target, 'foo', callableKeys).call(target)).toBe('receiver');
|
|
102
|
+
|
|
103
|
+
function First() { this.which = 'first'; }
|
|
104
|
+
function Second() { this.which = 'second'; }
|
|
105
|
+
target[inherited + 'Ctor'] = First;
|
|
106
|
+
target[own + 'Ctor'] = Second;
|
|
107
|
+
const ctor = helpers.get(target, 'Ctor', [inherited + 'Ctor', own + 'Ctor', 'Ctor']);
|
|
108
|
+
expect(new ctor().which).toBe('first');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('does not fall through to a public property omitted from the namespace set', () => {
|
|
112
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}
|
|
113
|
+
return { get: _avm2GetProperty, del: _avm2DeleteProperty };
|
|
114
|
+
`)();
|
|
115
|
+
const target = { foo: 'public-only' };
|
|
116
|
+
expect(helpers.get(target, 'foo', ['__avm2ns_8_uri_missing_foo'])).toBeUndefined();
|
|
117
|
+
expect(helpers.del(target, 'foo', ['__avm2ns_8_uri_missing_foo'])).toBe(true);
|
|
118
|
+
expect(target.foo).toBe('public-only');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('creates public dynamic members that are readable from a different namespace set', () => {
|
|
122
|
+
const helpers = new Function(`${AVM2_RUNTIME_STUB}
|
|
123
|
+
return { get: _avm2GetLateProperty, set: _avm2SetLateProperty,
|
|
124
|
+
setNamed: _avm2SetProperty, QName: _getlex('QName') };
|
|
125
|
+
`)();
|
|
126
|
+
const target = {};
|
|
127
|
+
const writer = ['__avm2ns_5_writer_', ''];
|
|
128
|
+
const reader = ['__avm2ns_5_reader_', ''];
|
|
129
|
+
let coercions = 0;
|
|
130
|
+
const key = { toString() { coercions++; return 'inspire'; } };
|
|
131
|
+
const stat = { val: 1.1 };
|
|
132
|
+
helpers.set(target, [null, key, writer], stat);
|
|
133
|
+
expect(coercions).toBe(1);
|
|
134
|
+
expect(target).toEqual({ inspire: stat });
|
|
135
|
+
expect(helpers.get(target, [null, 'inspire', reader])).toBe(stat);
|
|
136
|
+
|
|
137
|
+
helpers.setNamed(target, 'regen0', 1, [writer[0] + 'regen0', 'regen0']);
|
|
138
|
+
target[writer[0] + 'regen0'] = 2;
|
|
139
|
+
helpers.set(target, [null, 'regen0', writer], 3);
|
|
140
|
+
expect(target.regen0).toBe(1);
|
|
141
|
+
expect(target[writer[0] + 'regen0']).toBe(3);
|
|
142
|
+
|
|
143
|
+
const qualified = new helpers.QName('explicit', 'inspire');
|
|
144
|
+
helpers.set(target, [null, qualified, writer], 4);
|
|
145
|
+
expect(target.inspire).toBe(stat);
|
|
146
|
+
expect(helpers.get(target, [null, qualified, reader])).toBe(4);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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 compile(probeName, customUri) {
|
|
7
|
+
const bytes = [16, 0, 46, 0];
|
|
8
|
+
const u30 = value => bytes.push(value);
|
|
9
|
+
const methods = [
|
|
10
|
+
['privateClass', 0, [0x60, 3, 0x48]],
|
|
11
|
+
['customClass', 0, [0x60, 4, 0x48]],
|
|
12
|
+
['protectedClass', 0, [0x60, 5, 0x48]],
|
|
13
|
+
['isPrivate', 1, [0xd1, 0xb2, 3, 0x48]],
|
|
14
|
+
['asCustom', 1, [0xd1, 0x86, 4, 0x48]],
|
|
15
|
+
['coerceProtected', 1, [0xd1, 0x80, 5, 0x48]],
|
|
16
|
+
['isMissing', 1, [0xd1, 0xb2, 6, 0x48]],
|
|
17
|
+
['asPrivateFirst', 1, [0xd1, 0x86, 7, 0x48]],
|
|
18
|
+
['asCustomFirst', 1, [0xd1, 0x86, 8, 0x48]],
|
|
19
|
+
];
|
|
20
|
+
const names = [probeName, 'Object', 'Twin', customUri, 'shared private description', `${probeName}:protected`,
|
|
21
|
+
...methods.map(([name]) => name)];
|
|
22
|
+
u30(0); u30(0); u30(0);
|
|
23
|
+
u30(names.length + 1);
|
|
24
|
+
for (const name of names) {
|
|
25
|
+
const encoded = new TextEncoder().encode(name);
|
|
26
|
+
u30(encoded.length); bytes.push(...encoded);
|
|
27
|
+
}
|
|
28
|
+
u30(6);
|
|
29
|
+
bytes.push(0x16); u30(0); // public
|
|
30
|
+
bytes.push(0x05); u30(5); // private namespace ID 2
|
|
31
|
+
bytes.push(0x08); u30(4); // custom
|
|
32
|
+
bytes.push(0x18); u30(6); // protected
|
|
33
|
+
bytes.push(0x05); u30(5); // distinct private namespace ID 5, same description
|
|
34
|
+
u30(3);
|
|
35
|
+
u30(2); u30(2); u30(3); // private then custom
|
|
36
|
+
u30(2); u30(3); u30(2); // custom then private
|
|
37
|
+
u30(9 + methods.length);
|
|
38
|
+
const qname = (ns, name) => { bytes.push(0x07); u30(ns); u30(name); };
|
|
39
|
+
qname(1, 1); qname(1, 2); qname(2, 3); qname(3, 3); qname(4, 3); qname(5, 3);
|
|
40
|
+
bytes.push(0x09); u30(3); u30(1);
|
|
41
|
+
bytes.push(0x09); u30(3); u30(2);
|
|
42
|
+
methods.forEach((_, index) => qname(1, index + 7));
|
|
43
|
+
|
|
44
|
+
u30(methods.length + 2);
|
|
45
|
+
for (const params of [0, 0, ...methods.map(method => method[1])]) {
|
|
46
|
+
u30(params); u30(0); if (params) u30(0);
|
|
47
|
+
u30(0); bytes.push(0);
|
|
48
|
+
}
|
|
49
|
+
u30(0); // metadata
|
|
50
|
+
u30(4); // three distinct Twin classes and the public probe
|
|
51
|
+
for (const index of [3, 4, 5, 1]) {
|
|
52
|
+
u30(index); u30(2); bytes.push(0); u30(0); u30(0);
|
|
53
|
+
u30(index === 1 ? methods.length : 0);
|
|
54
|
+
if (index === 1) methods.forEach((_, member) => {
|
|
55
|
+
u30(member + 9); bytes.push(1); u30(0); u30(member + 2);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
for (let i = 0; i < 4; i++) { u30(1); u30(0); } // cinit and static traits
|
|
59
|
+
u30(0); // scripts
|
|
60
|
+
u30(methods.length + 1);
|
|
61
|
+
const body = (index, params, code) => {
|
|
62
|
+
u30(index); u30(1); u30(1 + params); u30(0); u30(0); u30(code.length);
|
|
63
|
+
bytes.push(...code); u30(0); u30(0);
|
|
64
|
+
};
|
|
65
|
+
body(0, 0, [0x47]);
|
|
66
|
+
methods.forEach(([, params, code], index) => body(index + 2, params, code));
|
|
67
|
+
const diagnostics = new DiagnosticsCollector();
|
|
68
|
+
const js = transpileAvm2(Uint8Array.from(bytes), diagnostics);
|
|
69
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
70
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
71
|
+
return js;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it('keeps named private, protected and custom type identities separate across ABC blocks', () => {
|
|
75
|
+
const { first, second, publicTwin, hasShortAlias } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
76
|
+
class Twin {}
|
|
77
|
+
// These URIs share the legacy 32-bit property-key hash.
|
|
78
|
+
${compile('FirstProbe', 'urn:collision:1b8gur1')}
|
|
79
|
+
${compile('SecondProbe', 'urn:collision:1b6osdk')}
|
|
80
|
+
({
|
|
81
|
+
first: new FirstProbe(), second: new SecondProbe(), publicTwin: new Twin(),
|
|
82
|
+
hasShortAlias: Object.hasOwn(_classes, 'Twin'),
|
|
83
|
+
});
|
|
84
|
+
`);
|
|
85
|
+
const privateA = new (first.privateClass())();
|
|
86
|
+
const privateB = new (second.privateClass())();
|
|
87
|
+
const customA = new (first.customClass())();
|
|
88
|
+
const customB = new (second.customClass())();
|
|
89
|
+
const protectedA = new (first.protectedClass())();
|
|
90
|
+
const protectedB = new (second.protectedClass())();
|
|
91
|
+
|
|
92
|
+
expect(hasShortAlias).toBe(false);
|
|
93
|
+
expect(first.isPrivate(privateA)).toBe(true);
|
|
94
|
+
expect(first.isPrivate(privateB)).toBe(false);
|
|
95
|
+
expect(first.isPrivate(publicTwin)).toBe(false);
|
|
96
|
+
expect(first.isMissing(privateA)).toBe(false);
|
|
97
|
+
expect(first.isMissing(publicTwin)).toBe(false);
|
|
98
|
+
expect(first.asCustom(customA)).toBe(customA);
|
|
99
|
+
expect(first.asCustom(customB)).toBeNull();
|
|
100
|
+
expect(first.coerceProtected(protectedA)).toBe(protectedA);
|
|
101
|
+
expect(() => first.coerceProtected(protectedB)).toThrow(/Cannot coerce/);
|
|
102
|
+
expect(first.asPrivateFirst(privateA)).toBe(privateA);
|
|
103
|
+
expect(first.asPrivateFirst(customA)).toBeNull();
|
|
104
|
+
expect(first.asCustomFirst(customA)).toBe(customA);
|
|
105
|
+
expect(first.asCustomFirst(privateA)).toBeNull();
|
|
106
|
+
});
|