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,232 @@
|
|
|
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
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
5
|
+
import { createAvm2Runtime } from '../runtime/avm2-runtime.js';
|
|
6
|
+
|
|
7
|
+
function buildMinimalAbc(codeBytes) {
|
|
8
|
+
const bytes = [];
|
|
9
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
10
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
11
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
12
|
+
u16(16); u16(46);
|
|
13
|
+
u30(0); u30(0); u30(0);
|
|
14
|
+
u30(5); str(''); str('TestClass'); str('Sprite'); str('foo');
|
|
15
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
16
|
+
u30(0);
|
|
17
|
+
u30(4); bytes.push(0x07); u30(1); u30(2); bytes.push(0x07); u30(1); u30(3); bytes.push(0x07); u30(1); u30(4);
|
|
18
|
+
u30(3); for (let m = 0; m < 3; m++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
19
|
+
u30(0);
|
|
20
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(0);
|
|
21
|
+
u30(1); u30(0);
|
|
22
|
+
u30(1); u30(2); u30(0);
|
|
23
|
+
u30(1); u30(0); u30(4); u30(2); u30(1); u30(3); u30(codeBytes.length);
|
|
24
|
+
for (const b of codeBytes) bytes.push(b);
|
|
25
|
+
u30(0); u30(0);
|
|
26
|
+
return new Uint8Array(bytes);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function buildCallMethodAbc(ctorCode, methodCode = [0xd1, 0x48], extraNames = []) {
|
|
30
|
+
const bytes = [];
|
|
31
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
32
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
33
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
34
|
+
const body = (methodIndex, code, localCount) => {
|
|
35
|
+
u30(methodIndex); u30(4); u30(localCount); u30(1); u30(3); u30(code.length);
|
|
36
|
+
for (const b of code) bytes.push(b);
|
|
37
|
+
u30(0); u30(0);
|
|
38
|
+
};
|
|
39
|
+
u16(16); u16(46);
|
|
40
|
+
u30(0); u30(0); u30(0);
|
|
41
|
+
const strings = ['', 'TestClass', 'Sprite', 'foo', 'callback', 'lexicalCallback', 'observed',
|
|
42
|
+
...extraNames.map(([name]) => name)];
|
|
43
|
+
if (extraNames.length) strings.push('http://adobe.com/AS3/2006/builtin');
|
|
44
|
+
u30(strings.length + 1); strings.forEach(str);
|
|
45
|
+
u30(extraNames.length ? 3 : 2); bytes.push(0x16); u30(1);
|
|
46
|
+
if (extraNames.length) { bytes.push(0x08); u30(strings.length); }
|
|
47
|
+
u30(0);
|
|
48
|
+
u30(7 + extraNames.length);
|
|
49
|
+
for (let i = 2; i <= 7; i++) { bytes.push(0x07); u30(1); u30(i); }
|
|
50
|
+
extraNames.forEach(([, namespace], i) => { bytes.push(0x07); u30(namespace); u30(i + 8); });
|
|
51
|
+
u30(4);
|
|
52
|
+
for (let m = 0; m < 3; m++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
53
|
+
u30(1); u30(0); u30(0); u30(0); bytes.push(0);
|
|
54
|
+
u30(0);
|
|
55
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1);
|
|
56
|
+
u30(3); bytes.push(0x01); u30(7); u30(3); // foo dispatch ID 7, method 3
|
|
57
|
+
u30(1); u30(0);
|
|
58
|
+
u30(1); u30(2); u30(0);
|
|
59
|
+
u30(2);
|
|
60
|
+
body(0, ctorCode, 2);
|
|
61
|
+
body(3, methodCode, 2);
|
|
62
|
+
u30(0); u30(0);
|
|
63
|
+
return new Uint8Array(bytes);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function compile(code) {
|
|
67
|
+
const diagnostics = new DiagnosticsCollector();
|
|
68
|
+
const js = transpileAvm2(buildMinimalAbc(code), diagnostics);
|
|
69
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
70
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
71
|
+
return js;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runWithCall(code, calls) {
|
|
75
|
+
const js = compile(code);
|
|
76
|
+
const env = new Function('calls', `class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn TestClass;`)(calls);
|
|
77
|
+
env.prototype.foo = function () {
|
|
78
|
+
'use strict';
|
|
79
|
+
calls.push(this);
|
|
80
|
+
};
|
|
81
|
+
new env();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('AVM2 property call receiver semantics', () => {
|
|
85
|
+
it('binds emitted method references with stable per-instance identity for event callbacks', () => {
|
|
86
|
+
const ctor = [
|
|
87
|
+
0xd0, 0x49, 0, // super()
|
|
88
|
+
0xd0, 0xd0, 0x66, 3, 0x61, 4, // this.callback = this.foo
|
|
89
|
+
0xd0, 0x60, 3, 0x61, 5, // this.lexicalCallback = foo
|
|
90
|
+
0x47,
|
|
91
|
+
];
|
|
92
|
+
const method = [0xd0, 0xd0, 0x61, 6, 0xd0, 0x48]; // this.observed = this; return this
|
|
93
|
+
const diagnostics = new DiagnosticsCollector();
|
|
94
|
+
const code = transpileAvm2(buildCallMethodAbc(ctor, method), diagnostics);
|
|
95
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
96
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
97
|
+
const { TestClass, Event, EventDispatcher, readProperty, otherReadProperty } = new Function(`
|
|
98
|
+
${SWFLIB_SOURCE}\n${AVM2_RUNTIME_STUB}\n${code}
|
|
99
|
+
return { TestClass, Event, EventDispatcher, readProperty: _avm2GetProperty,
|
|
100
|
+
otherReadProperty: __swoof_swflib.createAvm2Runtime(globalThis, __swoof_swflib)._avm2GetProperty };
|
|
101
|
+
`)();
|
|
102
|
+
const receiver = new TestClass();
|
|
103
|
+
const otherReceiver = new TestClass();
|
|
104
|
+
const dispatcher = new EventDispatcher();
|
|
105
|
+
expect(receiver.callback).toBe(receiver.lexicalCallback);
|
|
106
|
+
expect(receiver.callback).toBe(readProperty(receiver, 'foo', ['foo']));
|
|
107
|
+
expect(receiver.callback).toBe(otherReadProperty(receiver, 'foo'));
|
|
108
|
+
expect(receiver.callback).not.toBe(otherReceiver.callback);
|
|
109
|
+
dispatcher.addEventListener(Event.COMPLETE, receiver.callback);
|
|
110
|
+
dispatcher.dispatchEvent(new Event(Event.COMPLETE));
|
|
111
|
+
expect(receiver.observed).toBe(receiver);
|
|
112
|
+
expect(dispatcher.observed).toBeUndefined();
|
|
113
|
+
dispatcher.removeEventListener(Event.COMPLETE, receiver.lexicalCallback);
|
|
114
|
+
receiver.observed = null;
|
|
115
|
+
dispatcher.dispatchEvent(new Event(Event.COMPLETE));
|
|
116
|
+
expect(receiver.observed).toBeNull();
|
|
117
|
+
|
|
118
|
+
const assigned = function () { 'use strict'; return this; };
|
|
119
|
+
expect(readProperty({ assigned }, 'assigned')).toBe(assigned);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('callproperty invokes the function with the target object as this', () => {
|
|
123
|
+
const calls = [];
|
|
124
|
+
// getlocal0; callproperty foo, 0; pop; returnvoid
|
|
125
|
+
runWithCall([0xd0, 0x46, 3, 0, 0x29, 0x47], calls);
|
|
126
|
+
expect(calls).toHaveLength(1);
|
|
127
|
+
expect(calls[0]).toBeInstanceOf(Object);
|
|
128
|
+
expect(calls[0].constructor.name).toBe('TestClass');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('exposes release-player stack traces for AVM2 Error calls', () => {
|
|
132
|
+
const runtime = createAvm2Runtime(globalThis);
|
|
133
|
+
const error = new TypeError('test');
|
|
134
|
+
error.stack = 'TypeError: test\n at loadGame (file:///movie/bundle.js:4:3)\notherFrame@file:///movie/bundle.js:10:5';
|
|
135
|
+
const trace = 'TypeError: test\n at loadGame()\n at otherFrame()';
|
|
136
|
+
expect(runtime._avm2CallProperty(error, 'getStackTrace', [])).toBe(trace);
|
|
137
|
+
const method = runtime._avm2GetProperty(error, 'getStackTrace');
|
|
138
|
+
expect(method()).toBe(trace);
|
|
139
|
+
expect(runtime._avm2GetProperty(error, 'getStackTrace')).toBe(method);
|
|
140
|
+
expect(runtime._avm2GetProperty({}, 'getStackTrace')).toBeUndefined();
|
|
141
|
+
expect(runtime._avm2CallProperty({ getStackTrace: () => 'override' }, 'getStackTrace', [])).toBe('override');
|
|
142
|
+
error.stack = undefined;
|
|
143
|
+
expect(method()).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('calls AVM2 Array.sortOn in the builtin namespace with scoped sort flags', () => {
|
|
147
|
+
const ctor = [0xd0, 0x49, 0, 0xd0, 0x60, 11, 0x66, 12, 0x60, 11, 0x66, 13, 0xa9, 0x61, 6, 0x47];
|
|
148
|
+
const sortOn = [0xd1, 0x66, 8, 0xd1, 0x66, 9, 0xd1, 0x66, 10, 0x46, 7, 2, 0x48];
|
|
149
|
+
const names = [['sortOn', 2], ['rows', 1], ['fields', 1], ['options', 1], ['Array', 1],
|
|
150
|
+
['NUMERIC', 1], ['DESCENDING', 1]];
|
|
151
|
+
const diagnostics = new DiagnosticsCollector();
|
|
152
|
+
const code = transpileAvm2(buildCallMethodAbc(ctor, sortOn, names), diagnostics);
|
|
153
|
+
expect(diagnostics.all()).toEqual([]);
|
|
154
|
+
const { sorter, read } = new Function(`class Sprite {}
|
|
155
|
+
${AVM2_RUNTIME_STUB}
|
|
156
|
+
${code}
|
|
157
|
+
return { sorter: new TestClass(), read: _avm2GetProperty };
|
|
158
|
+
`)();
|
|
159
|
+
expect(sorter.observed).toBe(18);
|
|
160
|
+
expect(Array.prototype.sortOn).toBeUndefined();
|
|
161
|
+
expect(Array.NUMERIC).toBeUndefined();
|
|
162
|
+
|
|
163
|
+
const rows = [{ rand: 9 }, { rand: 105 }, { rand: 20 }];
|
|
164
|
+
sorter.foo({ rows, fields: 'rand', options: sorter.observed });
|
|
165
|
+
expect(rows.map(row => row.rand)).toEqual([105, 20, 9]);
|
|
166
|
+
|
|
167
|
+
const caseInsensitive = read(Array, 'CASEINSENSITIVE');
|
|
168
|
+
const numeric = read(Array, 'NUMERIC');
|
|
169
|
+
const descending = read(Array, 'DESCENDING');
|
|
170
|
+
const indexed = read(Array, 'RETURNINDEXEDARRAY');
|
|
171
|
+
const unique = read(Array, 'UNIQUESORT');
|
|
172
|
+
const records = [{ name: 'a', rank: 2 }, { name: 'B', rank: 1 }, { name: 'A', rank: 10 }];
|
|
173
|
+
expect(sorter.foo({ rows: records, fields: ['name', 'rank'],
|
|
174
|
+
options: [caseInsensitive | indexed, numeric | descending] })).toEqual([2, 0, 1]);
|
|
175
|
+
expect(sorter.foo({ rows: records, fields: 'name', options: caseInsensitive | unique })).toBe(0);
|
|
176
|
+
expect(records.map(record => record.name)).toEqual(['a', 'B', 'A']);
|
|
177
|
+
|
|
178
|
+
sorter.foo({ rows: records, fields: ['name', 'rank'], options: [indexed | caseInsensitive] });
|
|
179
|
+
expect(records.map(record => record.name)).toEqual(['A', 'B', 'a']);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('call invokes an extracted function with the explicit receiver', () => {
|
|
183
|
+
const calls = [];
|
|
184
|
+
// getlocal0; getproperty foo; getlocal0; call 0; pop; returnvoid
|
|
185
|
+
runWithCall([0xd0, 0x66, 3, 0xd0, 0x41, 0, 0x29, 0x47], calls);
|
|
186
|
+
expect(calls).toHaveLength(1);
|
|
187
|
+
expect(calls[0].constructor.name).toBe('TestClass');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it.each([
|
|
191
|
+
['call', [0x60, 1, 0x20, 0xd1, 0x41, 1, 0x48]],
|
|
192
|
+
['callproperty', [0x5d, 1, 0xd1, 0x46, 1, 1, 0x48]],
|
|
193
|
+
['callproplex', [0x5d, 1, 0xd1, 0x4c, 1, 1, 0x48]],
|
|
194
|
+
])('%s coerces to a generated class when called without new', (_, methodCode) => {
|
|
195
|
+
const diagnostics = new DiagnosticsCollector();
|
|
196
|
+
const js = transpileAvm2(buildCallMethodAbc([0xd0, 0x49, 0, 0x47], methodCode), diagnostics);
|
|
197
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
198
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
199
|
+
const env = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn {
|
|
200
|
+
TestClass, Class, call: _avm2Call,
|
|
201
|
+
};`)();
|
|
202
|
+
const value = new env.TestClass();
|
|
203
|
+
expect(value.foo(value)).toBe(value);
|
|
204
|
+
expect(value.foo(undefined)).toBeNull();
|
|
205
|
+
expect(() => value.foo({})).toThrow(TypeError);
|
|
206
|
+
expect(() => env.call(env.TestClass, null, [])).toThrow(TypeError);
|
|
207
|
+
expect(env.Class(env.TestClass)).toBe(env.TestClass);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('callproplex invokes the resolved function with null as this', () => {
|
|
211
|
+
const calls = [];
|
|
212
|
+
// getlocal0; callproplex foo, 0; pop; returnvoid
|
|
213
|
+
runWithCall([0xd0, 0x4c, 3, 0, 0x29, 0x47], calls);
|
|
214
|
+
expect(calls).toHaveLength(1);
|
|
215
|
+
expect(calls[0]).toBeNull();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('callmethod dispatches by ABC method dispatch ID', () => {
|
|
219
|
+
// getlocal0; pushbyte 42; callmethod dispatch ID 7 with one argument; pop; returnvoid
|
|
220
|
+
const code = [0xd0, 0x24, 42, 0x43, 7, 1, 0x29, 0x47];
|
|
221
|
+
const diagnostics = new DiagnosticsCollector();
|
|
222
|
+
const js = transpileAvm2(buildCallMethodAbc(code), diagnostics);
|
|
223
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
224
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
225
|
+
expect(js).toContain('_callMethodById(this, 7, [42])');
|
|
226
|
+
const env = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn {
|
|
227
|
+
TestClass, callMethod: _callMethodById,
|
|
228
|
+
};`)();
|
|
229
|
+
const receiver = new env.TestClass();
|
|
230
|
+
expect(env.callMethod(receiver, 7, [37])).toBe(37);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
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 buildInheritedDispatchAbc() {
|
|
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 trait = (nameIndex, dispatchId, methodIndex) => {
|
|
11
|
+
u30(nameIndex); bytes.push(0x01); u30(dispatchId); u30(methodIndex);
|
|
12
|
+
};
|
|
13
|
+
const body = (methodIndex, code) => {
|
|
14
|
+
u30(methodIndex); u30(2); u30(1); u30(0); u30(1); u30(code.length);
|
|
15
|
+
for (const b of code) bytes.push(b);
|
|
16
|
+
u30(0); u30(0);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
u16(16); u16(46);
|
|
20
|
+
u30(0); u30(0); u30(0);
|
|
21
|
+
u30(7); str(''); str('Base'); str('Sub'); str('foo'); str('superFoo'); str('Object');
|
|
22
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
23
|
+
u30(0);
|
|
24
|
+
u30(6);
|
|
25
|
+
bytes.push(0x07); u30(1); u30(2); // QName Base
|
|
26
|
+
bytes.push(0x07); u30(1); u30(3); // QName Sub
|
|
27
|
+
bytes.push(0x07); u30(1); u30(4); // QName foo
|
|
28
|
+
bytes.push(0x07); u30(1); u30(5); // QName superFoo
|
|
29
|
+
bytes.push(0x07); u30(1); u30(6); // QName Object
|
|
30
|
+
|
|
31
|
+
u30(8); // methods
|
|
32
|
+
for (let i = 0; i < 8; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
33
|
+
u30(0); // metadata
|
|
34
|
+
|
|
35
|
+
u30(2); // instances
|
|
36
|
+
u30(1); u30(5); bytes.push(0); u30(0); u30(0); u30(1); trait(3, 7, 3); // Base.foo
|
|
37
|
+
u30(2); u30(1); bytes.push(0); u30(0); u30(4); u30(2); trait(3, 7, 6); trait(4, 8, 7); // Sub overrides foo
|
|
38
|
+
u30(1); u30(0); // Base class info
|
|
39
|
+
u30(5); u30(0); // Sub class info
|
|
40
|
+
|
|
41
|
+
u30(1); u30(2); u30(0); // script init method 2
|
|
42
|
+
u30(5); // method bodies
|
|
43
|
+
body(0, [0x47]); // Base ctor
|
|
44
|
+
body(3, [0x24, 11, 0x48]); // Base.foo returns 11
|
|
45
|
+
body(4, [0xd0, 0x49, 0, 0x47]); // Sub ctor calls Base ctor
|
|
46
|
+
body(6, [0x24, 22, 0x48]); // Sub.foo override returns 22
|
|
47
|
+
body(7, [0xd0, 0x4b, 7, 0, 0x48]); // Sub.superFoo calls base dispatch 7
|
|
48
|
+
return new Uint8Array(bytes);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('AVM2 callsuperid', () => {
|
|
52
|
+
it('calls the base implementation by dispatch ID despite a subclass override', () => {
|
|
53
|
+
const diagnostics = new DiagnosticsCollector();
|
|
54
|
+
const js = transpileAvm2(buildInheritedDispatchAbc(), diagnostics);
|
|
55
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
56
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
57
|
+
expect(js).toContain('_callSuperById(this, 7, [], Sub)');
|
|
58
|
+
const env = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn { Base, Sub };`)();
|
|
59
|
+
const instance = new env.Sub();
|
|
60
|
+
expect(instance.foo()).toBe(22);
|
|
61
|
+
expect(instance.superFoo()).toBe(11);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('throws when the receiver is null or undefined', () => {
|
|
65
|
+
const helper = new Function(`${AVM2_RUNTIME_STUB}\nreturn _callSuperById;`)();
|
|
66
|
+
expect(() => helper(null, 7, [])).toThrow(TypeError);
|
|
67
|
+
expect(() => helper(undefined, 7, [])).toThrow(TypeError);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
function buildDispatchBlock(classes) {
|
|
72
|
+
const bytes = [16, 0, 46, 0];
|
|
73
|
+
const u30 = (value) => {
|
|
74
|
+
while (value >= 0x80) { bytes.push((value & 0x7f) | 0x80); value >>>= 7; }
|
|
75
|
+
bytes.push(value);
|
|
76
|
+
};
|
|
77
|
+
const names = ['Object', 'DispatchBase', 'DispatchMiddle', 'DispatchLeaf', 'probe', 'marker',
|
|
78
|
+
'virtualProbe', 'baseStaticProbe', 'middleSuperProbe', 'middleStaticProbe', 'nullStaticProbe', 'access', 'baseAutomatic', 'fresh', 'NativeBase'];
|
|
79
|
+
const qname = (name) => u30(names.indexOf(name) + 1);
|
|
80
|
+
bytes.push(0, 0, 0);
|
|
81
|
+
u30(names.length + 1);
|
|
82
|
+
for (const name of names) { u30(name.length); bytes.push(...new TextEncoder().encode(name)); }
|
|
83
|
+
bytes.push(2, 0x16, 0, 0);
|
|
84
|
+
u30(names.length + 1);
|
|
85
|
+
for (const name of names) { bytes.push(0x07, 1); qname(name); }
|
|
86
|
+
|
|
87
|
+
const methods = classes.flatMap(({ traits }) => [
|
|
88
|
+
{ code: [0x47] }, { code: [0xd0, 0x49, 0, 0x47] }, ...traits,
|
|
89
|
+
]);
|
|
90
|
+
u30(methods.length);
|
|
91
|
+
for (const { kind } of methods) {
|
|
92
|
+
if (kind === 3) bytes.push(1, 0, 0, 0, 0); // One untyped setter parameter.
|
|
93
|
+
else bytes.push(0, 0, 0, 0);
|
|
94
|
+
}
|
|
95
|
+
bytes.push(0); // metadata
|
|
96
|
+
u30(classes.length);
|
|
97
|
+
let methodOffset = 0;
|
|
98
|
+
for (const { name, parent, traits } of classes) {
|
|
99
|
+
qname(name); qname(parent);
|
|
100
|
+
bytes.push(0, 0); // flags, interfaces
|
|
101
|
+
u30(methodOffset + 1); u30(traits.length);
|
|
102
|
+
for (const [index, trait] of traits.entries()) {
|
|
103
|
+
qname(trait.name); bytes.push((trait.kind || 1) | (trait.override ? 0x20 : 0));
|
|
104
|
+
u30(trait.id); u30(methodOffset + 2 + index);
|
|
105
|
+
}
|
|
106
|
+
methodOffset += 2 + traits.length;
|
|
107
|
+
}
|
|
108
|
+
methodOffset = 0;
|
|
109
|
+
for (const { traits } of classes) { u30(methodOffset); bytes.push(0); methodOffset += 2 + traits.length; }
|
|
110
|
+
bytes.push(0); // scripts
|
|
111
|
+
u30(methods.length);
|
|
112
|
+
for (const [index, { code, kind }] of methods.entries()) {
|
|
113
|
+
u30(index); bytes.push(3, kind === 3 ? 2 : 1, 0, 0); u30(code.length); bytes.push(...code, 0, 0);
|
|
114
|
+
}
|
|
115
|
+
return Uint8Array.from(bytes);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
it('uses per-ABC method tables, inherited dispatch IDs and the lexical superclass with a cross-ABC receiver', () => {
|
|
119
|
+
const diagnostics = new DiagnosticsCollector();
|
|
120
|
+
const getMarker = [0xd0, 0x66, 6, 0x48];
|
|
121
|
+
const addToMarker = [0xd0, 0x66, 6, 0x24, 22, 0xa0, 0x48];
|
|
122
|
+
const callProbe = (opcode, index) => [0xd0, opcode, index, 0, 0x48];
|
|
123
|
+
const base = transpileAvm2(buildDispatchBlock([{ name: 'DispatchBase', parent: 'Object', traits: [
|
|
124
|
+
{ name: 'probe', id: 7, code: getMarker },
|
|
125
|
+
{ name: 'virtualProbe', id: 8, code: callProbe(0x43, 7) },
|
|
126
|
+
{ name: 'baseStaticProbe', id: 9, code: callProbe(0x44, 2) },
|
|
127
|
+
{ name: 'nullStaticProbe', id: 12, code: [0x20, 0x44, 2, 0, 0x48] },
|
|
128
|
+
] }]), diagnostics);
|
|
129
|
+
const derived = transpileAvm2(buildDispatchBlock([
|
|
130
|
+
{ name: 'DispatchMiddle', parent: 'DispatchBase', traits: [
|
|
131
|
+
{ name: 'probe', id: 0, override: true, code: addToMarker },
|
|
132
|
+
{ name: 'middleSuperProbe', id: 10, code: callProbe(0x4b, 7) },
|
|
133
|
+
{ name: 'middleStaticProbe', id: 11, code: callProbe(0x44, 2) },
|
|
134
|
+
] },
|
|
135
|
+
{ name: 'DispatchLeaf', parent: 'DispatchMiddle', traits: [] },
|
|
136
|
+
]), diagnostics);
|
|
137
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
138
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
139
|
+
const Leaf = new Function(`${AVM2_RUNTIME_STUB}\n${base}\n${derived}\nreturn _classes.DispatchLeaf;`)();
|
|
140
|
+
const leaf = new Leaf();
|
|
141
|
+
leaf.marker = 33;
|
|
142
|
+
expect(leaf.virtualProbe()).toBe(55);
|
|
143
|
+
expect(leaf.middleSuperProbe()).toBe(33);
|
|
144
|
+
expect(leaf.baseStaticProbe()).toBe(33);
|
|
145
|
+
expect(leaf.middleStaticProbe()).toBe(55);
|
|
146
|
+
expect(() => leaf.nullStaticProbe()).toThrow(TypeError);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('allocates zero-ID methods after inherited methods and accessor pairs across ABCs', () => {
|
|
150
|
+
const diagnostics = new DiagnosticsCollector();
|
|
151
|
+
const constant = (value) => [0x24, value, 0x48];
|
|
152
|
+
const call = (opcode, index) => [0xd0, opcode, index, 0, 0x48];
|
|
153
|
+
const base = transpileAvm2(buildDispatchBlock([{ name: 'DispatchBase', parent: 'Object', traits: [
|
|
154
|
+
{ name: 'probe', id: 41, code: constant(11) },
|
|
155
|
+
{ name: 'access', id: 0, kind: 2, code: constant(12) },
|
|
156
|
+
{ name: 'baseAutomatic', id: 0, code: constant(13) },
|
|
157
|
+
{ name: 'virtualProbe', id: 0, code: call(0x43, 7) },
|
|
158
|
+
] }]), diagnostics);
|
|
159
|
+
const derived = transpileAvm2(buildDispatchBlock([{ name: 'DispatchMiddle', parent: 'DispatchBase', traits: [
|
|
160
|
+
{ name: 'probe', id: 0, override: true, code: constant(21) },
|
|
161
|
+
{ name: 'fresh', id: 0, code: constant(22) },
|
|
162
|
+
{ name: 'middleSuperProbe', id: 0, code: call(0x4b, 4) },
|
|
163
|
+
{ name: 'middleStaticProbe', id: 0, code: call(0x43, 9) },
|
|
164
|
+
] }]), diagnostics);
|
|
165
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
166
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
167
|
+
|
|
168
|
+
const { Base, Middle, callById } = new Function(
|
|
169
|
+
`${AVM2_RUNTIME_STUB}
|
|
170
|
+
${base}
|
|
171
|
+
${derived}
|
|
172
|
+
return { Base: DispatchBase, Middle: DispatchMiddle, callById: _callMethodById };`,
|
|
173
|
+
)();
|
|
174
|
+
expect(new Base().virtualProbe()).toBe(13);
|
|
175
|
+
const instance = new Middle();
|
|
176
|
+
expect(instance.virtualProbe()).toBe(13);
|
|
177
|
+
expect(instance.middleSuperProbe()).toBe(11);
|
|
178
|
+
expect(instance.middleStaticProbe()).toBe(22);
|
|
179
|
+
expect(callById(instance, 4, [])).toBe(21);
|
|
180
|
+
expect(callById(instance, 41, [])).toBe(21);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('retains explicit IDs without guessing the method count of an unrecognized native superclass', () => {
|
|
184
|
+
const diagnostics = new DiagnosticsCollector();
|
|
185
|
+
const js = transpileAvm2(buildDispatchBlock([{ name: 'DispatchLeaf', parent: 'NativeBase', traits: [
|
|
186
|
+
{ name: 'probe', id: 41, code: [0x24, 11, 0x48] },
|
|
187
|
+
{ name: 'fresh', id: 0, code: [0x24, 22, 0x48] },
|
|
188
|
+
] }]), diagnostics);
|
|
189
|
+
const { Leaf, callById } = new Function(`${AVM2_RUNTIME_STUB}
|
|
190
|
+
_classes.NativeBase = class NativeBase {};
|
|
191
|
+
${js}
|
|
192
|
+
return { Leaf: DispatchLeaf, callById: _callMethodById };
|
|
193
|
+
`)();
|
|
194
|
+
const leaf = new Leaf();
|
|
195
|
+
expect(callById(leaf, 41, [])).toBe(11);
|
|
196
|
+
expect(callById(leaf, 4, [])).toBeUndefined();
|
|
197
|
+
expect(callById(leaf, 5, [])).toBeUndefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('inherits the complementary instance accessor when a subclass overrides one half across ABCs', () => {
|
|
201
|
+
const diagnostics = new DiagnosticsCollector();
|
|
202
|
+
const setMarker = [0xd0, 0xd1, 0x61, 6, 0x47];
|
|
203
|
+
const base = transpileAvm2(buildDispatchBlock([{ name: 'DispatchBase', parent: 'NativeBase', traits: [
|
|
204
|
+
{ name: 'access', id: 0, kind: 2, override: true, code: [0xd0, 0x66, 6, 0x24, 10, 0xa0, 0x48] },
|
|
205
|
+
] }]), diagnostics);
|
|
206
|
+
const derived = transpileAvm2(buildDispatchBlock([
|
|
207
|
+
{ name: 'DispatchMiddle', parent: 'DispatchBase', traits: [] },
|
|
208
|
+
{ name: 'DispatchLeaf', parent: 'DispatchMiddle', traits: [
|
|
209
|
+
{ name: 'access', id: 0, kind: 3, override: true, code: setMarker },
|
|
210
|
+
{ name: 'fresh', id: 0, kind: 2, code: [0x24, 42, 0x48] },
|
|
211
|
+
] },
|
|
212
|
+
]), diagnostics);
|
|
213
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
214
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
215
|
+
const { Base, Leaf, read, write } = new Function(`${AVM2_RUNTIME_STUB}
|
|
216
|
+
_classes.NativeBase = class NativeBase {
|
|
217
|
+
get access() { return this.marker; }
|
|
218
|
+
set access(value) { this.marker = value * 2; }
|
|
219
|
+
};
|
|
220
|
+
${base}
|
|
221
|
+
${derived}
|
|
222
|
+
return { Base: DispatchBase, Leaf: DispatchLeaf, read: _avm2GetProperty, write: _avm2SetProperty };
|
|
223
|
+
`)();
|
|
224
|
+
const baseOnly = new Base(), leaf = new Leaf();
|
|
225
|
+
write(baseOnly, 'access', 5, ['access']);
|
|
226
|
+
expect(read(baseOnly, 'access')).toBe(20);
|
|
227
|
+
write(leaf, 'access', 5, ['access']);
|
|
228
|
+
expect(read(leaf, 'access')).toBe(15);
|
|
229
|
+
expect(read(leaf, 'fresh')).toBe(42);
|
|
230
|
+
expect(() => write(leaf, 'fresh', 5, ['fresh'])).toThrow(TypeError);
|
|
231
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
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 buildClassInitializerAbc(mode, numbered) {
|
|
6
|
+
const singleton = mode === 'singleton';
|
|
7
|
+
const preSuperBase = mode === 'presuper-base';
|
|
8
|
+
const preSuperOverride = mode === 'presuper-override';
|
|
9
|
+
const preSuper = mode === 'presuper' || preSuperOverride;
|
|
10
|
+
const bytes = [];
|
|
11
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
12
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
13
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
14
|
+
const body = (methodIndex, code) => {
|
|
15
|
+
u30(methodIndex); u30(2); u30(methodIndex === 0 ? numbered?.localCount ?? 1 : 1); u30(0); u30(1); u30(code.length);
|
|
16
|
+
for (const b of code) bytes.push(b);
|
|
17
|
+
u30(0); u30(0);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
u16(16); u16(46);
|
|
21
|
+
u30(0); u30(0); u30(0);
|
|
22
|
+
u30(12); str(''); str(numbered?.name ?? (preSuperBase ? 'Base' : 'App')); str(numbered?.parent ?? (preSuper ? 'Base' : 'Object')); str('dispatcher');
|
|
23
|
+
str('initialized'); str('observed'); str('copied'); str('updated'); str('beforeSuper'); str('middle'); str('baseObserved');
|
|
24
|
+
u30(3); bytes.push(0x16); u30(1); bytes.push(0x05); u30(1); // public, private
|
|
25
|
+
u30(0);
|
|
26
|
+
u30(8);
|
|
27
|
+
bytes.push(0x07); u30(1); u30(2); // App
|
|
28
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
29
|
+
bytes.push(0x07); u30(singleton ? 2 : 1); u30(4); // dispatcher
|
|
30
|
+
bytes.push(0x07); u30(1); u30(6); // observed
|
|
31
|
+
bytes.push(0x07); u30(1); u30(7); // copied
|
|
32
|
+
bytes.push(0x07); u30(1); u30(9); // beforeSuper
|
|
33
|
+
bytes.push(0x07); u30(1); u30(11); // baseObserved
|
|
34
|
+
u30(3);
|
|
35
|
+
for (let i = 0; i < 3; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
36
|
+
u30(0); // metadata
|
|
37
|
+
u30(1); // classes
|
|
38
|
+
u30(1); u30(2); bytes.push(numbered ? 0x01 : 0); u30(0); u30(0);
|
|
39
|
+
const slots = numbered?.slots ?? (preSuper ? [[4, 0, 1, 5]] : []);
|
|
40
|
+
u30(slots.length);
|
|
41
|
+
for (const [name, kind, slot, value] of slots) {
|
|
42
|
+
u30(name); bytes.push(kind); u30(slot); u30(0); u30(value);
|
|
43
|
+
if (value) bytes.push(0x01);
|
|
44
|
+
}
|
|
45
|
+
u30(1); u30(1); u30(3); bytes.push(0); u30(1); u30(2); u30(0); // cinit 1, static Object slot dispatcher id 1
|
|
46
|
+
u30(0); // scripts
|
|
47
|
+
const cinit = singleton
|
|
48
|
+
? [0xd0, 0xd0, 0x42, 0, 0x61, 3, 0x47] // this.dispatcher = new this()
|
|
49
|
+
: [0xd0, 0x2c, 5, 0x61, 3, 0x47]; // this.dispatcher = "initialized"
|
|
50
|
+
let iinit = [0x47];
|
|
51
|
+
if (singleton) {
|
|
52
|
+
iinit = [0xd0, 0x30, 0xd0, 0x60, 3, 0x61, 4, 0x47]; // pushscope this; this.observed = getlex dispatcher
|
|
53
|
+
} else if (preSuperBase) {
|
|
54
|
+
iinit = [
|
|
55
|
+
0xd0, 0xd0, 0x66, 4, 0x61, 3, // this.dispatcher = this.observed
|
|
56
|
+
0xd0, 0x2c, 5, 0x61, 4, 0x47, // this.observed = "initialized"
|
|
57
|
+
];
|
|
58
|
+
} else if (preSuper) {
|
|
59
|
+
const writeObserved = [0xd0, 0x2c, 8, 0x61, 4]; // this.observed = "updated"
|
|
60
|
+
iinit = [
|
|
61
|
+
0xd0, 0x30, // pushscope this
|
|
62
|
+
...(preSuperOverride ? writeObserved : []),
|
|
63
|
+
0xd0, 0xd0, 0x66, 4, 0x49, 1, // super(this.observed)
|
|
64
|
+
...(preSuperOverride ? [] : writeObserved),
|
|
65
|
+
0xd0, 0x60, 4, 0x61, 5, 0x47, // this.copied = getlex observed
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
u30(3); // method bodies
|
|
69
|
+
body(0, numbered?.code ?? iinit); body(1, cinit); body(2, [0x47]);
|
|
70
|
+
return new Uint8Array(bytes);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function buildClassTraitDependencyAbc() {
|
|
74
|
+
const bytes = [16, 0, 46, 0];
|
|
75
|
+
const u30 = (...values) => { bytes.push(...values); }; // All fixture indices fit in one byte.
|
|
76
|
+
const strings = ['Physics', 'Coordinate', 'Consumer', 'Object', 'created'];
|
|
77
|
+
u30(0, 0, 0, strings.length + 1);
|
|
78
|
+
for (const name of strings) u30(name.length, ...Buffer.from(name));
|
|
79
|
+
u30(3, 0x16, 0, 0x16, 1); // The empty and Physics package namespaces.
|
|
80
|
+
u30(2, 2, 1, 2); // A multiname with both namespaces.
|
|
81
|
+
u30(6);
|
|
82
|
+
u30(0x07, 2, 2, 0x07, 2, 3, 0x07, 1, 4, 0x07, 1, 5, 0x09, 2, 1);
|
|
83
|
+
u30(6);
|
|
84
|
+
for (let index = 0; index < 6; index++) u30(0, 0, 0, 0); // Methods without arguments.
|
|
85
|
+
u30(0, 2); // Metadata and class count.
|
|
86
|
+
u30(1, 3, 0, 0, 0, 0); // Coordinate extends Object, instance initializer 0.
|
|
87
|
+
u30(2, 3, 0, 0, 2, 0); // Consumer extends Object, instance initializer 2.
|
|
88
|
+
u30(1, 0, 3, 1, 4, 0, 1, 0, 0); // cinit 1 and cinit 3. Consumer owns the created slot.
|
|
89
|
+
u30(2, 4, 1, 1, 4, 0, 0, 5, 1, 2, 4, 1, 1); // Two script Class traits.
|
|
90
|
+
u30(6);
|
|
91
|
+
for (let index = 0; index < 6; index++) {
|
|
92
|
+
const code = index === 3
|
|
93
|
+
? [0xd0, 0x30, 0xd0, 0x5d, 5, 0x4a, 5, 0, 0x61, 4, 0x47]
|
|
94
|
+
: [0x47]; // Consumer.cinit: this.created = new Coordinate().
|
|
95
|
+
u30(index, 2, 1, 0, 1, code.length, ...code, 0, 0);
|
|
96
|
+
}
|
|
97
|
+
return new Uint8Array(bytes);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
describe('AVM2 class initializer', () => {
|
|
101
|
+
it('runs cinit after class declaration and initializes static traits', () => {
|
|
102
|
+
const diagnostics = new DiagnosticsCollector();
|
|
103
|
+
const js = transpileAvm2(buildClassInitializerAbc(), diagnostics);
|
|
104
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
105
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
106
|
+
expect(js.indexOf('class App')).toBeLessThan(js.indexOf('_queueAvm2ClassInitializer'));
|
|
107
|
+
|
|
108
|
+
const result = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn App.dispatcher;`)();
|
|
109
|
+
expect(result).toBe('initialized');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('resolves a Class trait owned by an earlier script during cinit multiname construction', () => {
|
|
113
|
+
const diagnostics = new DiagnosticsCollector();
|
|
114
|
+
const js = transpileAvm2(buildClassTraitDependencyAbc(), diagnostics);
|
|
115
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
116
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
117
|
+
const { Coordinate, Consumer } = new Function(`${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn { Coordinate, Consumer };`)();
|
|
118
|
+
expect(Consumer.created).toBeInstanceOf(Coordinate);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('resolves a private static slot from the declaring class during instance initialization', () => {
|
|
122
|
+
const diagnostics = new DiagnosticsCollector();
|
|
123
|
+
const js = transpileAvm2(buildClassInitializerAbc('singleton'), diagnostics);
|
|
124
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
125
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
126
|
+
|
|
127
|
+
const App = new Function(`${AVM2_RUNTIME_STUB}\n${js}\n_runAvm2Initializers();\nreturn App;`)();
|
|
128
|
+
const key = App.__avm2StaticSlots[1];
|
|
129
|
+
const instance = App[key];
|
|
130
|
+
expect(instance).toBeInstanceOf(App);
|
|
131
|
+
expect(instance.observed).toBeNull(); // The singleton assignment succeeds after the constructor returns.
|
|
132
|
+
|
|
133
|
+
class Subclass extends App {}
|
|
134
|
+
Subclass[key] = 'a different static value';
|
|
135
|
+
expect(new Subclass().observed).toBe(instance);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('makes own instance defaults visible before constructsuper and rebinds the receiver scope', () => {
|
|
139
|
+
const diagnostics = new DiagnosticsCollector();
|
|
140
|
+
const js = transpileAvm2(buildClassInitializerAbc('presuper'), diagnostics);
|
|
141
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
142
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
143
|
+
|
|
144
|
+
class Base {
|
|
145
|
+
constructor(value) { this.superArgument = value; }
|
|
146
|
+
}
|
|
147
|
+
const App = new Function('Base', `${AVM2_RUNTIME_STUB}\n_classes.Base = Base;\n${js}\nreturn App;`)(Base);
|
|
148
|
+
const instance = new App();
|
|
149
|
+
expect(instance.superArgument).toBe('initialized');
|
|
150
|
+
expect(instance.copied).toBe('updated');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('exposes derived writes to a compiled base constructor and preserves the base writes', () => {
|
|
154
|
+
const diagnostics = new DiagnosticsCollector();
|
|
155
|
+
const base = transpileAvm2(buildClassInitializerAbc('presuper-base'), diagnostics);
|
|
156
|
+
const derived = transpileAvm2(buildClassInitializerAbc('presuper-override'), diagnostics);
|
|
157
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
158
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
159
|
+
|
|
160
|
+
const App = new Function(`${AVM2_RUNTIME_STUB}\n${base}\n${derived}\nreturn App;`)();
|
|
161
|
+
const instance = new App();
|
|
162
|
+
expect(instance.dispatcher).toBe('updated');
|
|
163
|
+
expect(instance.observed).toBe('initialized');
|
|
164
|
+
expect(instance.copied).toBe('initialized');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('shares derived numbered slot writes with the compiled base chain and live receiver', () => {
|
|
169
|
+
const diagnostics = new DiagnosticsCollector();
|
|
170
|
+
const base = transpileAvm2(buildClassInitializerAbc(null, {
|
|
171
|
+
name: 'Base', parent: 'Object', slots: [[5, 0, 1, 5]],
|
|
172
|
+
code: [
|
|
173
|
+
0xd0, 0xd0, 0x6c, 1, 0x61, 3, // dispatcher = slot 1
|
|
174
|
+
0xd0, 0xd0, 0x66, 4, 0x61, 7, // baseObserved = observed
|
|
175
|
+
0xd0, 0x2c, 5, 0x6d, 1, 0x47, // slot 1 = "initialized"
|
|
176
|
+
],
|
|
177
|
+
}), diagnostics);
|
|
178
|
+
const middle = transpileAvm2(buildClassInitializerAbc(null, {
|
|
179
|
+
name: 'Middle', parent: 'Base',
|
|
180
|
+
code: [0xd0, 0x2c, 10, 0x6d, 1, 0xd0, 0x49, 0, 0x47],
|
|
181
|
+
}), diagnostics);
|
|
182
|
+
const derived = transpileAvm2(buildClassInitializerAbc(null, {
|
|
183
|
+
name: 'App', parent: 'Middle', slots: [[4, 6, 2, 0]], localCount: 2,
|
|
184
|
+
code: [
|
|
185
|
+
0xd0, 0xd5, // local1 = pre-super receiver
|
|
186
|
+
0xd0, 0xd1, 0x6c, 1, 0x61, 6, // beforeSuper = inherited default
|
|
187
|
+
0xd0, 0x2c, 8, 0x6d, 1, // inherited slot 1 = "updated"
|
|
188
|
+
0xd0, 0x2c, 8, 0x6d, 2, // const slot 2 = "updated"
|
|
189
|
+
0xd0, 0x49, 0,
|
|
190
|
+
0xd0, 0xd1, 0x6c, 1, 0x61, 5, 0x47, // observe the base's write through the staged alias
|
|
191
|
+
],
|
|
192
|
+
}), diagnostics);
|
|
193
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
194
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
195
|
+
|
|
196
|
+
const { App, read, write } = new Function(`${AVM2_RUNTIME_STUB}\n${base}\n${middle}\n${derived}
|
|
197
|
+
return { App, read: _getSlot, write: _setSlot };
|
|
198
|
+
`)();
|
|
199
|
+
const instance = new App();
|
|
200
|
+
expect(instance.beforeSuper).toBe('initialized');
|
|
201
|
+
expect(instance.dispatcher).toBe('middle');
|
|
202
|
+
expect(instance.baseObserved).toBe('updated');
|
|
203
|
+
expect(instance.copied).toBe('initialized');
|
|
204
|
+
expect(read(instance, 2)).toBe('updated');
|
|
205
|
+
expect(() => write(instance, 2, 'duplicate', true)).toThrow(/more than once/);
|
|
206
|
+
expect(() => write(instance, 2, 'outside', false)).toThrow(/constant AVM2 slot/);
|
|
207
|
+
expect(read(new App(), 2)).toBe('updated');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('rejects a second compiled const initialization after constructsuper', () => {
|
|
211
|
+
const diagnostics = new DiagnosticsCollector();
|
|
212
|
+
const base = transpileAvm2(buildClassInitializerAbc('presuper-base'), diagnostics);
|
|
213
|
+
const derived = transpileAvm2(buildClassInitializerAbc(null, {
|
|
214
|
+
name: 'App', parent: 'Base', slots: [[4, 6, 1, 0]],
|
|
215
|
+
code: [0xd0, 0x2c, 8, 0x6d, 1, 0xd0, 0x49, 0, 0xd0, 0x2c, 5, 0x6d, 1, 0x47],
|
|
216
|
+
}), diagnostics);
|
|
217
|
+
const App = new Function(`${AVM2_RUNTIME_STUB}\n${base}\n${derived}\nreturn App;`)();
|
|
218
|
+
expect(() => new App()).toThrow(/more than once/);
|
|
219
|
+
});
|