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,100 @@
|
|
|
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 buildValidatorAbc(parameterType) {
|
|
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, localCount) => {
|
|
11
|
+
u30(methodIndex); u30(2); u30(localCount); u30(0); u30(1); u30(code.length);
|
|
12
|
+
for (const b of code) bytes.push(b);
|
|
13
|
+
u30(0); u30(0);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
u16(16); u16(46);
|
|
17
|
+
u30(2); u30(1); // integer default
|
|
18
|
+
u30(2); u30(1); // unsigned integer default
|
|
19
|
+
u30(0); // doubles
|
|
20
|
+
u30(parameterType ? 9 : 8);
|
|
21
|
+
str(''); str('Validator'); str('Object'); str('minimumVersion'); str('0'); str('extraArguments'); str('collect');
|
|
22
|
+
if (parameterType) str(parameterType);
|
|
23
|
+
u30(2); bytes.push(0x16); u30(1); // package namespace
|
|
24
|
+
u30(0); // namespace sets
|
|
25
|
+
u30(parameterType ? 7 : 6);
|
|
26
|
+
bytes.push(0x07); u30(1); u30(2); // Validator
|
|
27
|
+
bytes.push(0x07); u30(1); u30(3); // Object
|
|
28
|
+
bytes.push(0x07); u30(1); u30(4); // minimumVersion
|
|
29
|
+
bytes.push(0x07); u30(1); u30(6); // extraArguments
|
|
30
|
+
bytes.push(0x07); u30(1); u30(7); // collect
|
|
31
|
+
if (parameterType) { bytes.push(0x07); u30(1); u30(8); }
|
|
32
|
+
u30(4); // methods
|
|
33
|
+
u30(3); u30(0); u30(0); u30(0); u30(parameterType ? 6 : 0); u30(0);
|
|
34
|
+
bytes.push(0x0c); u30(1);
|
|
35
|
+
u30(parameterType ? 1 : 5);
|
|
36
|
+
bytes.push(parameterType === 'int' ? 0x03 : parameterType === 'uint' ? 0x04 : 0x01);
|
|
37
|
+
for (let i = 1; i < 3; i++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
38
|
+
u30(0); u30(0); u30(0); bytes.push(0x04); // collect has only rest arguments
|
|
39
|
+
u30(0); // metadata
|
|
40
|
+
u30(1); // classes
|
|
41
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1); // instance: iinit method 0
|
|
42
|
+
u30(5); bytes.push(1); u30(0); u30(3); // collect, method 3
|
|
43
|
+
u30(1); u30(0); // class initializer, no traits
|
|
44
|
+
u30(1); u30(2); u30(0); // script initializer, no traits
|
|
45
|
+
u30(4); // method bodies
|
|
46
|
+
body(0, [
|
|
47
|
+
0xd0, 0xd3, 0x61, 0x03, // this.minimumVersion = arg3
|
|
48
|
+
0xd0, 0x62, 0x04, 0x61, 0x04, // this.extraArguments = rest
|
|
49
|
+
0x47,
|
|
50
|
+
], 5);
|
|
51
|
+
body(1, [0x47], 1);
|
|
52
|
+
body(2, [0x47], 1);
|
|
53
|
+
body(3, [0xd1, 0x48], 2); // return rest
|
|
54
|
+
return new Uint8Array(bytes);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe('AVM2 optional arguments', () => {
|
|
58
|
+
it('uses an omitted optional constructor argument and preserves explicitly passed undefined', () => {
|
|
59
|
+
const diagnostics = new DiagnosticsCollector();
|
|
60
|
+
const abcBytes = buildValidatorAbc();
|
|
61
|
+
const js = transpileAvm2(abcBytes, diagnostics);
|
|
62
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
63
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
64
|
+
expect(js).toContain('if (arguments.length < 3) _l3 = "0";');
|
|
65
|
+
|
|
66
|
+
const Validator = new Function(`${AVM2_RUNTIME_STUB}\n${js}\nreturn Validator;`)();
|
|
67
|
+
expect(new Validator('name', null).minimumVersion).toBe('0');
|
|
68
|
+
expect(new Validator('name', null, undefined).minimumVersion).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('initializes a fresh array of rest arguments for constructors and methods', () => {
|
|
72
|
+
const diagnostics = new DiagnosticsCollector();
|
|
73
|
+
const js = transpileAvm2(buildValidatorAbc(), diagnostics);
|
|
74
|
+
const Validator = new Function(`${AVM2_RUNTIME_STUB}\n${js}\nreturn Validator;`)();
|
|
75
|
+
|
|
76
|
+
const omitted = new Validator('name', null);
|
|
77
|
+
const supplied = new Validator('name', null, undefined, 1, null, 'tail');
|
|
78
|
+
expect(omitted.minimumVersion).toBe('0');
|
|
79
|
+
expect(omitted.extraArguments).toEqual([]);
|
|
80
|
+
expect(supplied.minimumVersion).toBeUndefined();
|
|
81
|
+
expect(supplied.extraArguments).toEqual([1, null, 'tail']);
|
|
82
|
+
expect(omitted.collect('one', 2)).toEqual(['one', 2]);
|
|
83
|
+
const empty = omitted.collect();
|
|
84
|
+
expect(empty).toEqual([]);
|
|
85
|
+
expect(omitted.collect()).not.toBe(empty);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it.each([['int', -2], ['uint', 4294967294]])('coerces provided %s arguments after optional defaults', (type, negative) => {
|
|
89
|
+
const diagnostics = new DiagnosticsCollector();
|
|
90
|
+
const js = transpileAvm2(buildValidatorAbc(type), diagnostics);
|
|
91
|
+
const Validator = new Function(`${AVM2_RUNTIME_STUB}\n${js}\nreturn Validator;`)();
|
|
92
|
+
|
|
93
|
+
const frame = new Validator('name', null, 2.3273627562448382, 'idle');
|
|
94
|
+
expect(frame.minimumVersion).toBe(2);
|
|
95
|
+
expect(frame.extraArguments).toEqual(['idle']);
|
|
96
|
+
expect(new Validator('name', null, -2.75).minimumVersion).toBe(negative);
|
|
97
|
+
expect(new Validator('name', null).minimumVersion).toBe(1);
|
|
98
|
+
expect(new Validator('name', null, undefined).minimumVersion).toBe(0);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { runInNewContext } from 'node:vm';
|
|
3
|
+
import { AVM2_RUNTIME_STUB, transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
4
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
5
|
+
|
|
6
|
+
function buildAbc() {
|
|
7
|
+
const bytes = [16, 0, 46, 0];
|
|
8
|
+
const u30 = value => {
|
|
9
|
+
while (value >= 128) {
|
|
10
|
+
bytes.push((value & 127) | 128);
|
|
11
|
+
value >>>= 7;
|
|
12
|
+
}
|
|
13
|
+
bytes.push(value);
|
|
14
|
+
};
|
|
15
|
+
const names = ['Derived', 'Base', 'instanceScopes', 'classScopes', 'readInherited', 'makeClosure', 'scriptGlobal',
|
|
16
|
+
'marker', 'shared', 'initializerOwner', 'earlyBase', 'name'];
|
|
17
|
+
u30(0); u30(0); u30(0);
|
|
18
|
+
u30(names.length + 1);
|
|
19
|
+
for (const name of names) {
|
|
20
|
+
const encoded = new TextEncoder().encode(name);
|
|
21
|
+
u30(encoded.length);
|
|
22
|
+
bytes.push(...encoded);
|
|
23
|
+
}
|
|
24
|
+
u30(2); bytes.push(0x16); u30(0); // public namespace
|
|
25
|
+
u30(0);
|
|
26
|
+
u30(names.length + 1);
|
|
27
|
+
names.forEach((_, index) => { bytes.push(0x07); u30(1); u30(index + 1); });
|
|
28
|
+
|
|
29
|
+
const methods = [
|
|
30
|
+
[4, [0xd0, 0x67, 3, 0x61, 10, 0xd0, 0x49, 0, 0x47]], // iinit sees the class before constructsuper
|
|
31
|
+
[3, [0xd0, 0x67, 2, 0x61, 11, 0x47]], // cinit sees the closest ancestor before script startup
|
|
32
|
+
[0, [0x47]], // first script
|
|
33
|
+
[0, [
|
|
34
|
+
0xd0, 0x30, // this is the second script scope
|
|
35
|
+
0xd0, // receiver for initproperty
|
|
36
|
+
0x2c, 8, 0x24, 42, 0x2c, 12, 0x24, 24, 0x55, 2, 0x30, // marker scope
|
|
37
|
+
0x60, 2, 0x30, // push Base as the innermost class scope
|
|
38
|
+
0x60, 2, 0x58, 0, 0x1d, 0x1d, 0x68, 1, 0x47,
|
|
39
|
+
]],
|
|
40
|
+
[4, [0x67, 0, 0x67, 1, 0x67, 2, 0x67, 3, 0x56, 4, 0x48]],
|
|
41
|
+
[3, [0x67, 0, 0x67, 1, 0x67, 2, 0x56, 3, 0x48]],
|
|
42
|
+
[4, [0x60, 9, 0x60, 12, 0x56, 2, 0x48]], // getlex shared and name
|
|
43
|
+
[4, [0xd0, 0x30, 0x40, 8, 0x1d, 0x48]], // closure captures local scope too
|
|
44
|
+
[5, [0x67, 1, 0x67, 4, 0x56, 2, 0x48]],
|
|
45
|
+
[4, [0x64, 0x48]], // getglobalscope
|
|
46
|
+
];
|
|
47
|
+
u30(methods.length);
|
|
48
|
+
for (const _ of methods) {
|
|
49
|
+
u30(0); u30(0); u30(0); bytes.push(0);
|
|
50
|
+
}
|
|
51
|
+
const method = (name, index) => { u30(name); bytes.push(1); u30(0); u30(index); };
|
|
52
|
+
u30(0); // metadata
|
|
53
|
+
u30(1); // one class
|
|
54
|
+
u30(1); u30(2); bytes.push(0); u30(0); u30(0); // Derived extends Base, iinit 0
|
|
55
|
+
u30(4); method(3, 4); method(5, 6); method(6, 7); method(7, 9);
|
|
56
|
+
u30(1); u30(1); method(4, 5); // cinit, one static method
|
|
57
|
+
u30(2); // scripts
|
|
58
|
+
u30(2); u30(0); // first script
|
|
59
|
+
u30(3); u30(1); u30(1); bytes.push(4); u30(1); u30(0); // second script declares Derived
|
|
60
|
+
u30(methods.length);
|
|
61
|
+
methods.forEach(([scopeDepth, code], index) => {
|
|
62
|
+
u30(index); u30(5); u30(1); u30(scopeDepth); u30(scopeDepth + 4); u30(code.length);
|
|
63
|
+
bytes.push(...code); u30(0); u30(0);
|
|
64
|
+
});
|
|
65
|
+
return Uint8Array.from(bytes);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('AVM2 outer class scopes', () => {
|
|
69
|
+
it('uses the declaration scope for instance and static methods, even on a subclass receiver', () => {
|
|
70
|
+
const diagnostics = new DiagnosticsCollector();
|
|
71
|
+
const code = transpileAvm2(buildAbc(), diagnostics);
|
|
72
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
73
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
74
|
+
|
|
75
|
+
const { Base, Derived, scriptGlobal, run } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
76
|
+
class Base {}
|
|
77
|
+
_registerAvm2Class(Base, [], 0, 'Base', { staticValues: [['shared', 77]], lexical: ['shared'] });
|
|
78
|
+
${code}
|
|
79
|
+
({
|
|
80
|
+
Base, Derived, run: _runAvm2Initializers,
|
|
81
|
+
scriptGlobal: Object.values(_avm2ScriptScopeObjects)[1],
|
|
82
|
+
});
|
|
83
|
+
`);
|
|
84
|
+
|
|
85
|
+
run();
|
|
86
|
+
|
|
87
|
+
class MoreDerived extends Derived {}
|
|
88
|
+
const instance = new MoreDerived();
|
|
89
|
+
const classScopes = Derived.classScopes();
|
|
90
|
+
const instanceScopes = instance.instanceScopes();
|
|
91
|
+
const marker = classScopes[1];
|
|
92
|
+
expect(marker.marker).toBe(42);
|
|
93
|
+
expect(classScopes).toEqual([scriptGlobal, marker, Base]);
|
|
94
|
+
expect(instanceScopes).toEqual([scriptGlobal, marker, Base, Derived]);
|
|
95
|
+
expect(instance.initializerOwner).toBe(Derived);
|
|
96
|
+
expect(instance.scriptGlobal()).toBe(scriptGlobal);
|
|
97
|
+
expect(instance.readInherited()).toEqual([77, 24]);
|
|
98
|
+
expect(Derived.earlyBase).toBe(Base);
|
|
99
|
+
expect(instance.makeClosure()()).toEqual([marker, instance]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -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 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 body(bytes, methodIndex, code) {
|
|
18
|
+
u30(bytes, methodIndex); u30(bytes, 2); u30(bytes, 1); u30(bytes, 0); u30(bytes, 1); u30(bytes, code.length);
|
|
19
|
+
for (const byte of code) bytes.push(byte);
|
|
20
|
+
u30(bytes, 0); u30(bytes, 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function commonHeader(bytes, strings, multinameRecords, methodCount) {
|
|
24
|
+
bytes.push(16, 0, 46, 0);
|
|
25
|
+
u30(bytes, 0); u30(bytes, 0); u30(bytes, 0);
|
|
26
|
+
u30(bytes, strings.length + 1);
|
|
27
|
+
for (const value of strings) str(bytes, value);
|
|
28
|
+
u30(bytes, 3); bytes.push(0x16); u30(bytes, 1); bytes.push(0x17); u30(bytes, 2);
|
|
29
|
+
u30(bytes, 0);
|
|
30
|
+
u30(bytes, multinameRecords.length + 1);
|
|
31
|
+
for (const [nsIndex, nameIndex] of multinameRecords) { bytes.push(0x07); u30(bytes, nsIndex); u30(bytes, nameIndex); }
|
|
32
|
+
u30(bytes, methodCount);
|
|
33
|
+
for (let i = 0; i < methodCount; i++) { u30(bytes, 0); u30(bytes, 0); u30(bytes, 0); bytes.push(0); }
|
|
34
|
+
u30(bytes, 0); // metadata
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function buildInternalClassAbc(className = 'APIEventDispatcher') {
|
|
38
|
+
const bytes = [];
|
|
39
|
+
commonHeader(bytes,
|
|
40
|
+
['', 'com.newgrounds', className, 'Object', 'initialized', 'ready', 'instanceReady'],
|
|
41
|
+
[[2, 3], [1, 4], [2, 5], [1, 7]], 2);
|
|
42
|
+
u30(bytes, 1); // classes
|
|
43
|
+
u30(bytes, 1); u30(bytes, 2); bytes.push(0); u30(bytes, 0); u30(bytes, 0); u30(bytes, 0); // instance, no traits
|
|
44
|
+
u30(bytes, 1); u30(bytes, 1); // cinit 1, one static trait
|
|
45
|
+
u30(bytes, 3); bytes.push(0); u30(bytes, 1); u30(bytes, 0); u30(bytes, 0); // initialized slot
|
|
46
|
+
u30(bytes, 0); // scripts
|
|
47
|
+
u30(bytes, 2); // method bodies
|
|
48
|
+
body(bytes, 0, [0xd0, 0x60, 1, 0x66, 3, 0x61, 4, 0x47]); // copy cinit value to new instance
|
|
49
|
+
body(bytes, 1, [0xd0, 0x2c, 6, 0x61, 3, 0x47]); // class.initialized = "ready"
|
|
50
|
+
return new Uint8Array(bytes);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildConsumerAbc() {
|
|
54
|
+
const bytes = [];
|
|
55
|
+
commonHeader(bytes,
|
|
56
|
+
['', 'com.newgrounds', 'APIEventDispatcher', 'Object', 'instance'],
|
|
57
|
+
[[2, 3], [1, 5]], 1);
|
|
58
|
+
u30(bytes, 0); // classes
|
|
59
|
+
u30(bytes, 1); u30(bytes, 0); u30(bytes, 1); // script init 0, one trait
|
|
60
|
+
u30(bytes, 2); bytes.push(0); u30(bytes, 1); u30(bytes, 0); u30(bytes, 0); // global instance slot
|
|
61
|
+
u30(bytes, 1); // method bodies
|
|
62
|
+
body(bytes, 0, [0xd0, 0x5d, 1, 0x4a, 1, 0, 0x61, 2, 0x47]);
|
|
63
|
+
// getlocal0; findpropstrict internal class; constructprop; set global instance
|
|
64
|
+
return new Uint8Array(bytes);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe('AVM2 package-internal class lookup', () => {
|
|
68
|
+
it('constructs a class from another ABC through its package-internal QName', () => {
|
|
69
|
+
const diagnostics = new DiagnosticsCollector();
|
|
70
|
+
const classJs = transpileAvm2(buildInternalClassAbc(), diagnostics);
|
|
71
|
+
const consumerJs = transpileAvm2(buildConsumerAbc(), diagnostics);
|
|
72
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
73
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
74
|
+
|
|
75
|
+
const previous = Object.getOwnPropertyDescriptor(globalThis, 'instance');
|
|
76
|
+
try {
|
|
77
|
+
const classes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${classJs}\n${consumerJs}\n_runAvm2Initializers();\nreturn _classes;`)();
|
|
78
|
+
const Type = Object.values(classes).find(type => type.__swoofQualifiedName === 'com.newgrounds.APIEventDispatcher');
|
|
79
|
+
expect(globalThis.instance.constructor).toBe(Type);
|
|
80
|
+
expect(Type.name).toBe('APIEventDispatcher');
|
|
81
|
+
expect(classes['com.newgrounds.APIEventDispatcher']).toBeUndefined();
|
|
82
|
+
expect(classes[0]).toBeUndefined();
|
|
83
|
+
expect(globalThis.instance.instanceReady).toBe('ready');
|
|
84
|
+
const initializedKey = Object.keys(globalThis.instance.constructor).find((key) => key.includes('initialized'));
|
|
85
|
+
expect(globalThis.instance.constructor[initializedKey]).toBe('ready');
|
|
86
|
+
} finally {
|
|
87
|
+
if (previous) Object.defineProperty(globalThis, 'instance', previous);
|
|
88
|
+
else delete globalThis.instance;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('keeps numeric class ids isolated between ABC blocks', () => {
|
|
93
|
+
const diagnostics = new DiagnosticsCollector();
|
|
94
|
+
const first = transpileAvm2(buildInternalClassAbc('FirstBlockClass'), diagnostics);
|
|
95
|
+
const second = transpileAvm2(buildInternalClassAbc('SecondBlockClass'), diagnostics);
|
|
96
|
+
const firstTable = first.match(/var (_avm2ClassTable_[a-f0-9]+_[0-9]+) = Object\.create\(null\);/)?.[1];
|
|
97
|
+
const secondTable = second.match(/var (_avm2ClassTable_[a-f0-9]+_[0-9]+) = Object\.create\(null\);/)?.[1];
|
|
98
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
99
|
+
expect(firstTable).toBeTruthy();
|
|
100
|
+
expect(secondTable).toBeTruthy();
|
|
101
|
+
expect(firstTable).not.toBe(secondTable);
|
|
102
|
+
|
|
103
|
+
const classes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${first}\n${second}\nreturn [${firstTable}[0], ${secondTable}[0]];`)();
|
|
104
|
+
expect(classes.map((Class) => Class.name)).toEqual(['FirstBlockClass', 'SecondBlockClass']);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
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 methodInfo(bytes, count = 3) {
|
|
18
|
+
u30(bytes, count);
|
|
19
|
+
for (let i = 0; i < count; i++) { u30(bytes, 0); u30(bytes, 0); u30(bytes, 0); bytes.push(0); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function body(bytes, method, code) {
|
|
23
|
+
u30(bytes, method); u30(bytes, 2); u30(bytes, 1); u30(bytes, 0); u30(bytes, 1); u30(bytes, code.length);
|
|
24
|
+
for (const byte of code) bytes.push(byte);
|
|
25
|
+
u30(bytes, 0); u30(bytes, 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function buildBaseAbc() {
|
|
29
|
+
const b = [];
|
|
30
|
+
b.push(16, 0, 46, 0);
|
|
31
|
+
u30(b, 0); u30(b, 0); u30(b, 0);
|
|
32
|
+
u30(b, 8); for (const s of ['Base', 'Object', 'health', 'readHealth', 'getLabel', '88', 'fromBase']) str(b, s);
|
|
33
|
+
u30(b, 3); b.push(0x16); u30(b, 1); b.push(0x18); u30(b, 1);
|
|
34
|
+
u30(b, 0);
|
|
35
|
+
u30(b, 6);
|
|
36
|
+
b.push(0x07); u30(b, 1); u30(b, 1); // Base class
|
|
37
|
+
b.push(0x07); u30(b, 1); u30(b, 2); // Object
|
|
38
|
+
b.push(0x07); u30(b, 2); u30(b, 3); // protected health
|
|
39
|
+
b.push(0x07); u30(b, 1); u30(b, 4); // readHealth
|
|
40
|
+
b.push(0x07); u30(b, 2); u30(b, 5); // protected getLabel
|
|
41
|
+
methodInfo(b, 4);
|
|
42
|
+
u30(b, 0); // metadata
|
|
43
|
+
u30(b, 1); // class count
|
|
44
|
+
u30(b, 1); u30(b, 2); b.push(0x08); u30(b, 2); u30(b, 0); u30(b, 0); u30(b, 3);
|
|
45
|
+
u30(b, 3); b.push(0); u30(b, 1); u30(b, 0); u30(b, 0); // protected slot health
|
|
46
|
+
u30(b, 4); b.push(1); u30(b, 1); u30(b, 1); // public method readHealth
|
|
47
|
+
u30(b, 5); b.push(1); u30(b, 2); u30(b, 2); // protected getLabel
|
|
48
|
+
u30(b, 3); u30(b, 0); // cinit 3
|
|
49
|
+
u30(b, 0); // scripts
|
|
50
|
+
u30(b, 4); // bodies
|
|
51
|
+
body(b, 0, [0xd0, 0x2c, 6, 0x61, 3, 0x47]); // this.health = "88"
|
|
52
|
+
body(b, 1, [0xd0, 0x66, 3, 0x48]);
|
|
53
|
+
body(b, 2, [0x2c, 7, 0x48]); // return "fromBase"
|
|
54
|
+
body(b, 3, [0x47]);
|
|
55
|
+
return new Uint8Array(b);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildDerivedAbc() {
|
|
59
|
+
const b = [];
|
|
60
|
+
b.push(16, 0, 46, 0);
|
|
61
|
+
u30(b, 0); u30(b, 0); u30(b, 0);
|
|
62
|
+
u30(b, 9); for (const s of ['Derived', 'Base', 'Object', 'health', 'readHealth', 'getLabel', 'callBase', 'protected:Derived']) str(b, s);
|
|
63
|
+
u30(b, 4); b.push(0x16); u30(b, 1); b.push(0x18); u30(b, 2); b.push(0x18); u30(b, 8);
|
|
64
|
+
u30(b, 0);
|
|
65
|
+
u30(b, 8);
|
|
66
|
+
b.push(0x07); u30(b, 1); u30(b, 1); // Derived class
|
|
67
|
+
b.push(0x07); u30(b, 1); u30(b, 2); // Base superclass
|
|
68
|
+
b.push(0x07); u30(b, 1); u30(b, 3); // Object
|
|
69
|
+
b.push(0x07); u30(b, 2); u30(b, 4); // Base protected health namespace
|
|
70
|
+
b.push(0x07); u30(b, 1); u30(b, 5); // readHealth
|
|
71
|
+
b.push(0x07); u30(b, 2); u30(b, 6); // Base protected getLabel
|
|
72
|
+
b.push(0x07); u30(b, 1); u30(b, 7); // public callBase
|
|
73
|
+
methodInfo(b, 4);
|
|
74
|
+
u30(b, 0); // metadata
|
|
75
|
+
u30(b, 1); // class count
|
|
76
|
+
u30(b, 1); u30(b, 2); b.push(0x08); u30(b, 3); u30(b, 0); u30(b, 0); u30(b, 2);
|
|
77
|
+
u30(b, 5); b.push(1); u30(b, 1); u30(b, 1); // readHealth method
|
|
78
|
+
u30(b, 7); b.push(1); u30(b, 2); u30(b, 2); // callBase method
|
|
79
|
+
u30(b, 3); u30(b, 0); // cinit 3
|
|
80
|
+
u30(b, 0); // scripts
|
|
81
|
+
u30(b, 4); // bodies
|
|
82
|
+
body(b, 0, [0xd0, 0x49, 0x00, 0x47]); // constructsuper 0
|
|
83
|
+
body(b, 1, [0xd0, 0x66, 4, 0x48]); // read Base protected slot
|
|
84
|
+
body(b, 2, [0xd0, 0x45, 6, 0, 0x48]); // callsuper Base protected getLabel
|
|
85
|
+
body(b, 3, [0x47]);
|
|
86
|
+
return new Uint8Array(b);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
describe('AVM2 protected namespaces', () => {
|
|
90
|
+
it('lets a derived ABC read a base protected trait by declaring namespace URI', () => {
|
|
91
|
+
const diagnostics = new DiagnosticsCollector();
|
|
92
|
+
const baseJs = transpileAvm2(buildBaseAbc(), diagnostics);
|
|
93
|
+
const derivedJs = transpileAvm2(buildDerivedAbc(), diagnostics);
|
|
94
|
+
const baseProtectedHealth = /__avm2ns_24_uri_[0-9a-f]+_health/.exec(baseJs)?.[0];
|
|
95
|
+
expect(baseProtectedHealth).toBeTruthy();
|
|
96
|
+
expect(derivedJs).toContain(JSON.stringify(baseProtectedHealth));
|
|
97
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
98
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
99
|
+
|
|
100
|
+
const classes = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${baseJs}\n${derivedJs}\n_runAvm2Initializers();\nreturn { Base, Derived };`)();
|
|
101
|
+
expect(new classes.Base().readHealth()).toBe('88');
|
|
102
|
+
expect(new classes.Derived().readHealth()).toBe('88');
|
|
103
|
+
expect(new classes.Derived().callBase()).toBe('fromBase');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { AVM2_RUNTIME_STUB, transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
4
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
5
|
+
|
|
6
|
+
function compileClass(diagnostics, { name, pkg = 'app', parent = 'Object', value, isOverride = false, useSuper = false, inheritOnly = false, dataTraits = false, numberedDispatch = false }) {
|
|
7
|
+
const bytes = [16, 0, 46, 0];
|
|
8
|
+
const u30 = value => {
|
|
9
|
+
while (value >= 128) {
|
|
10
|
+
bytes.push((value & 127) | 128);
|
|
11
|
+
value >>>= 7;
|
|
12
|
+
}
|
|
13
|
+
bytes.push(value);
|
|
14
|
+
};
|
|
15
|
+
const qname = (namespace, index) => { bytes.push(0x07); u30(namespace); u30(index); };
|
|
16
|
+
const members = [
|
|
17
|
+
{ name: 3, kind: 1, attrs: isOverride ? 2 : 0, dispatchId: numberedDispatch && !isOverride ? 7 : 0,
|
|
18
|
+
code: [0x24, value, 0x48] },
|
|
19
|
+
{ name: 4, kind: 1, code: numberedDispatch ? [0xd0, 0x43, 7, 0, 0x48] : [0xd0, 0x46, 3, 0, 0x48] },
|
|
20
|
+
{ name: 5, kind: 2, attrs: isOverride ? 2 : 0, code: [0x24, value + 1, 0x48] },
|
|
21
|
+
];
|
|
22
|
+
if (inheritOnly) {
|
|
23
|
+
members.splice(2, 1);
|
|
24
|
+
members.shift();
|
|
25
|
+
} else if (!isOverride) {
|
|
26
|
+
members.push({ name: 5, kind: 3, params: 1, code: [0xd0, 0xd1, 0x61, 10, 0x47] });
|
|
27
|
+
}
|
|
28
|
+
if (useSuper) {
|
|
29
|
+
members.push(
|
|
30
|
+
{ name: 6, kind: 1, code: numberedDispatch ? [0xd0, 0x4b, 7, 0, 0x48] : [0xd0, 0x45, 3, 0, 0x48] },
|
|
31
|
+
{ name: 7, kind: 1, code: [0xd0, 0x04, 3, 0x48] }, // getsuper
|
|
32
|
+
{ name: 8, kind: 1, params: 1, code: [0xd0, 0xd1, 0x05, 5, 0x47] }, // setsuper
|
|
33
|
+
{ name: 9, kind: 1, code: [0xd0, 0x45, 11, 0, 0x48] }, // callsuper through a namespace set
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const declaresData = dataTraits && parent === 'Object';
|
|
37
|
+
const staticMembers = [];
|
|
38
|
+
if (dataTraits) {
|
|
39
|
+
members.push(
|
|
40
|
+
{ name: 13, kind: 1, code: [0xd0, 0x66, 12, 0x48] }, // getproperty protected slot
|
|
41
|
+
{ name: 14, kind: 1, params: 1, code: [0xd0, 0xd1, 0x61, 12, 0x47] }, // setproperty
|
|
42
|
+
{ name: 23, kind: 1, code: [0xd0, 0x6c, 1, 0x48] }, // getslot
|
|
43
|
+
{ name: 18, kind: 1, code: [0x60, 17, 0x48] }, // getlex static protected
|
|
44
|
+
);
|
|
45
|
+
if (declaresData) {
|
|
46
|
+
staticMembers.push({ name: 21, kind: 1, code: [0x60, 17, 0x48] });
|
|
47
|
+
} else {
|
|
48
|
+
members.push(
|
|
49
|
+
{ name: 15, kind: 1, code: [0xd0, 0x04, 12, 0x48] }, // getsuper
|
|
50
|
+
{ name: 16, kind: 1, params: 1, code: [0xd0, 0xd1, 0x05, 12, 0x47] }, // setsuper
|
|
51
|
+
);
|
|
52
|
+
staticMembers.push(
|
|
53
|
+
{ name: 18, kind: 1, code: [0x60, 17, 0x48] },
|
|
54
|
+
{ name: 19, kind: 1, params: 1, code: [0x5d, 17, 0xd1, 0x61, 17, 0x47] },
|
|
55
|
+
{ name: 20, kind: 1, code: [0x5d, 21, 0x46, 21, 0, 0x48] },
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
u30(0); u30(0); u30(0);
|
|
60
|
+
const strings = ['', pkg, `${pkg}:${name}`, name, parent, 'ping', 'virtualCall', 'level',
|
|
61
|
+
'superCall', 'superClosure', 'superSet', 'superMultiname', 'recorded',
|
|
62
|
+
'balance', 'readBalance', 'writeBalance', 'readSuperBalance', 'writeSuperBalance',
|
|
63
|
+
'shared', 'readShared', 'writeShared', 'callShared', 'sharedMethod', `${pkg}:${parent}`, 'int', 'readSlot'];
|
|
64
|
+
u30(strings.length + 1);
|
|
65
|
+
for (const str of strings) {
|
|
66
|
+
const encoded = new TextEncoder().encode(str);
|
|
67
|
+
u30(encoded.length);
|
|
68
|
+
bytes.push(...encoded);
|
|
69
|
+
}
|
|
70
|
+
u30(6);
|
|
71
|
+
bytes.push(0x16); u30(1); // public
|
|
72
|
+
bytes.push(0x16); u30(2); // package
|
|
73
|
+
bytes.push(0x18); u30(3); // instance's protected namespace
|
|
74
|
+
bytes.push(0x1a); u30(3); // class's static protected namespace
|
|
75
|
+
bytes.push(0x1a); u30(24); // parent's static protected namespace
|
|
76
|
+
u30(2); u30(2); u30(3); u30(1); // protected and public namespace set
|
|
77
|
+
u30(24);
|
|
78
|
+
qname(2, 4); qname(parent === 'Object' ? 1 : 2, 5);
|
|
79
|
+
qname(3, 6); qname(1, 7); qname(3, 8);
|
|
80
|
+
qname(1, 9); qname(1, 10); qname(1, 11); qname(1, 12); qname(1, 13);
|
|
81
|
+
bytes.push(0x09); u30(6); u30(1); // multiname ping
|
|
82
|
+
qname(3, 14); qname(1, 15); qname(1, 16); qname(1, 17); qname(1, 18);
|
|
83
|
+
qname(declaresData ? 4 : 5, 19); qname(1, 20); qname(1, 21); qname(1, 22);
|
|
84
|
+
qname(declaresData ? 4 : 5, 23); qname(1, 25); qname(1, 26);
|
|
85
|
+
u30(members.length + staticMembers.length + 2);
|
|
86
|
+
for (const { params = 0 } of [{}, {}, ...members, ...staticMembers]) {
|
|
87
|
+
u30(params); u30(0); if (params) u30(0);
|
|
88
|
+
u30(0); bytes.push(0);
|
|
89
|
+
}
|
|
90
|
+
u30(0); // metadata
|
|
91
|
+
u30(1); // class count
|
|
92
|
+
u30(1); u30(2); bytes.push(0x08); u30(3); // name, base, HasProtectedNs, protected namespace
|
|
93
|
+
u30(0); u30(0); // interface count, iinit
|
|
94
|
+
u30(members.length + Number(declaresData));
|
|
95
|
+
if (declaresData) { u30(12); bytes.push(0); u30(1); u30(22); u30(0); }
|
|
96
|
+
members.forEach(({ name, kind, attrs = 0, dispatchId = 0 }, index) => {
|
|
97
|
+
u30(name); bytes.push(kind | (attrs << 4)); u30(dispatchId); u30(index + 2);
|
|
98
|
+
});
|
|
99
|
+
u30(1); u30(staticMembers.length + Number(declaresData)); // cinit, static trait count
|
|
100
|
+
if (declaresData) { u30(17); bytes.push(0); u30(1); u30(22); u30(0); }
|
|
101
|
+
staticMembers.forEach(({ name, kind }, index) => {
|
|
102
|
+
u30(name); bytes.push(kind); u30(0); u30(members.length + index + 2);
|
|
103
|
+
});
|
|
104
|
+
u30(0); // script count
|
|
105
|
+
u30(members.length + staticMembers.length + 1);
|
|
106
|
+
[{ code: [0xd0, 0x49, 0, 0x47] }, ...members, ...staticMembers].forEach(({ code, params = 0 }, index) => {
|
|
107
|
+
u30(index === 0 ? 0 : index + 1);
|
|
108
|
+
u30(2); u30(1 + params); u30(0); u30(0); u30(code.length);
|
|
109
|
+
bytes.push(...code); u30(0); u30(0);
|
|
110
|
+
});
|
|
111
|
+
return transpileAvm2(Uint8Array.from(bytes), diagnostics);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
it('links each protected override family to the actual superclass across ABCs', () => {
|
|
115
|
+
const diagnostics = new DiagnosticsCollector();
|
|
116
|
+
const decoy = compileClass(diagnostics, { name: 'Base', pkg: 'unrelated', value: 7 });
|
|
117
|
+
const base = compileClass(diagnostics, { name: 'Base', value: 10 });
|
|
118
|
+
const child = compileClass(diagnostics, { name: 'Child', parent: 'Base', value: 20, isOverride: true, useSuper: true });
|
|
119
|
+
const grandchild = compileClass(diagnostics, { name: 'Grandchild', parent: 'Child', value: 30, isOverride: true });
|
|
120
|
+
const passive = compileClass(diagnostics, { name: 'Passive', parent: 'Grandchild', inheritOnly: true });
|
|
121
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
122
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
123
|
+
|
|
124
|
+
const { Base, Decoy, Child, Grandchild, Passive, read } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
125
|
+
let Decoy;
|
|
126
|
+
{ ${decoy}\n Decoy = Base; }
|
|
127
|
+
${base}\n${child}\n${grandchild}\n${passive}
|
|
128
|
+
({ Base, Decoy, Child, Grandchild, Passive, read: _avm2GetProperty });
|
|
129
|
+
`);
|
|
130
|
+
const key = (type, name) => Object.getOwnPropertyNames(type.prototype).find(key => key.endsWith(`_${name}`));
|
|
131
|
+
const baseMethod = key(Base, 'ping'), childMethod = key(Child, 'ping');
|
|
132
|
+
const instance = new Passive();
|
|
133
|
+
expect(instance).toBeInstanceOf(Grandchild);
|
|
134
|
+
|
|
135
|
+
expect(instance).toBeInstanceOf(Base);
|
|
136
|
+
expect(instance).toBeInstanceOf(Child);
|
|
137
|
+
expect(instance).not.toBeInstanceOf(Decoy);
|
|
138
|
+
expect(Base.prototype.virtualCall.call(instance)).toBe(30);
|
|
139
|
+
expect(Child.prototype.virtualCall.call(instance)).toBe(30);
|
|
140
|
+
expect(instance.virtualCall()).toBe(30);
|
|
141
|
+
expect(read(instance, baseMethod)).toBe(read(instance, childMethod));
|
|
142
|
+
expect(read(instance, baseMethod)()).toBe(30);
|
|
143
|
+
expect(read(instance, key(Decoy, 'ping'))).toBeUndefined();
|
|
144
|
+
expect(instance.superCall()).toBe(10);
|
|
145
|
+
expect(instance.superMultiname()).toBe(10);
|
|
146
|
+
expect(instance.superClosure()()).toBe(10);
|
|
147
|
+
const level = key(Base, 'level');
|
|
148
|
+
expect(instance[level]).toBe(31);
|
|
149
|
+
instance[level] = 12;
|
|
150
|
+
expect(instance.recorded).toBe(12);
|
|
151
|
+
instance.superSet(14);
|
|
152
|
+
expect(instance.recorded).toBe(14);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('shares instance slots between protected namespaces and resolves statics on the declaring class', () => {
|
|
156
|
+
const diagnostics = new DiagnosticsCollector();
|
|
157
|
+
const base = compileClass(diagnostics, { name: 'Base', value: 10, dataTraits: true });
|
|
158
|
+
const decoy = compileClass(diagnostics, { name: 'Base', pkg: 'unrelated', value: 7, dataTraits: true });
|
|
159
|
+
const child = compileClass(diagnostics, { name: 'Child', parent: 'Base', inheritOnly: true, dataTraits: true });
|
|
160
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
161
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
162
|
+
const { Base, Decoy, Child, read, getSlot } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
163
|
+
let Decoy;
|
|
164
|
+
{ ${decoy}\n Decoy = Base; }
|
|
165
|
+
${base}\n${child}
|
|
166
|
+
({ Base, Decoy, Child, read: _avm2GetProperty, getSlot: _getSlot });
|
|
167
|
+
`);
|
|
168
|
+
|
|
169
|
+
const baseSlot = Object.getOwnPropertyNames(Base.prototype).find(key => key.endsWith('_balance'));
|
|
170
|
+
const childSlot = Object.getOwnPropertyNames(Child.prototype).find(key => key.endsWith('_balance'));
|
|
171
|
+
const first = new Child();
|
|
172
|
+
const second = new Child();
|
|
173
|
+
expect(first.readBalance()).toBe(0);
|
|
174
|
+
first.writeBalance(7);
|
|
175
|
+
expect(first.readSuperBalance()).toBe(7);
|
|
176
|
+
expect(read(first, baseSlot)).toBe(7);
|
|
177
|
+
expect(read(first, childSlot)).toBe(7);
|
|
178
|
+
expect(first.readSlot()).toBe(7);
|
|
179
|
+
first.writeSuperBalance(8);
|
|
180
|
+
expect(getSlot(first, 1)).toBe(8);
|
|
181
|
+
expect(second.readBalance()).toBe(0);
|
|
182
|
+
const decoySlot = Object.getOwnPropertyNames(Decoy.prototype).find(key => key.endsWith('_balance'));
|
|
183
|
+
expect(read(first, decoySlot)).toBeUndefined();
|
|
184
|
+
|
|
185
|
+
const staticSlot = Object.getOwnPropertyNames(Base).find(key => key.endsWith('_shared'));
|
|
186
|
+
expect(Child.readShared()).toBe(0);
|
|
187
|
+
Child.writeShared(41);
|
|
188
|
+
expect(first.readShared()).toBe(41);
|
|
189
|
+
expect(Child.callShared()).toBe(41);
|
|
190
|
+
expect(getSlot(Base, 1)).toBe(41);
|
|
191
|
+
expect(getSlot(Decoy, 1)).toBe(0);
|
|
192
|
+
expect(read(Child, staticSlot)).toBeUndefined();
|
|
193
|
+
expect(Object.hasOwn(Child, staticSlot)).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('rebinds a zero-ID protected override for cross-ABC virtual calls and keeps lexical super dispatch', () => {
|
|
197
|
+
const diagnostics = new DiagnosticsCollector();
|
|
198
|
+
const base = compileClass(diagnostics, { name: 'Base', value: 10, numberedDispatch: true });
|
|
199
|
+
const derived = compileClass(diagnostics, {
|
|
200
|
+
name: 'Child', parent: 'Base', value: 20, numberedDispatch: true, isOverride: true, useSuper: true,
|
|
201
|
+
});
|
|
202
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
203
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
204
|
+
const { Base, Child } = runInNewContext(`${AVM2_RUNTIME_STUB}
|
|
205
|
+
${base}
|
|
206
|
+
${derived}
|
|
207
|
+
({ Base, Child });
|
|
208
|
+
`);
|
|
209
|
+
const child = new Child();
|
|
210
|
+
expect(new Base().virtualCall()).toBe(10);
|
|
211
|
+
expect(Base.prototype.virtualCall.call(child)).toBe(20);
|
|
212
|
+
expect(child.virtualCall()).toBe(20);
|
|
213
|
+
expect(child.superCall()).toBe(10);
|
|
214
|
+
});
|