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,326 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import { AVM2_RUNTIME_STUB } from '../runtime/avm2-runtime.js';
|
|
4
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
5
|
+
import { transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
6
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
7
|
+
|
|
8
|
+
function buildE4XAbc(withDefaults = false) {
|
|
9
|
+
const bytes = [16, 0, 46, 0];
|
|
10
|
+
const u30 = value => bytes.push(value);
|
|
11
|
+
const namespaceQName = withDefaults ? 14 : 10;
|
|
12
|
+
const methods = [
|
|
13
|
+
['plain', 1, [0xd1, 0x66, 3, 0x48]],
|
|
14
|
+
['scoped', 1, [0xd1, 0x66, 4, 0x48]],
|
|
15
|
+
['all', 1, [0xd1, 0x66, 5, 0x48]],
|
|
16
|
+
['setScoped', 2, [0xd1, 0xd2, 0x61, 4, 0x47]],
|
|
17
|
+
['deleteScoped', 1, [0xd1, 0x6a, 4, 0x48]],
|
|
18
|
+
['descendantAttributes', 1, [0xd1, 0x59, 5, 0x48]],
|
|
19
|
+
['descendantItems', 1, [0xd1, 0x59, 6, 0x48]],
|
|
20
|
+
['lateAttribute', 3, [0xd1, 0xd2, 0xd3, 0x66, 7, 0x48]],
|
|
21
|
+
['lateChildren', 2, [0xd1, 0xd2, 0x66, 9, 0x48]],
|
|
22
|
+
['lateSet', 3, [0xd1, 0xd2, 0xd3, 0x61, 8, 0x47]],
|
|
23
|
+
['nodeNamespace', 1, [0xd1, 0x46, namespaceQName, 0, 0x48]],
|
|
24
|
+
['lookupNamespace', 2, [0xd1, 0xd2, 0x46, namespaceQName, 1, 0x48]],
|
|
25
|
+
['namespaceDeclarations', 1, [0xd1, 0x46, namespaceQName + 2, 0, 0x48]],
|
|
26
|
+
['inScopeNamespaces', 1, [0xd1, 0x46, namespaceQName + 3, 0, 0x48]],
|
|
27
|
+
['addNamespace', 2, [0xd1, 0xd2, 0x46, namespaceQName + 4, 1, 0x48]],
|
|
28
|
+
['removeNamespace', 2, [0xd1, 0xd2, 0x46, namespaceQName + 5, 1, 0x48]],
|
|
29
|
+
['lookupNamespacedChild', 3, [
|
|
30
|
+
0xd1, 0xd1, 0xd2, 0x46, namespaceQName, 1, 0xd3, 0x66, namespaceQName + 1, 0x48,
|
|
31
|
+
]],
|
|
32
|
+
];
|
|
33
|
+
if (withDefaults) {
|
|
34
|
+
methods.push(
|
|
35
|
+
['declaredDefault', 1, [0xd1, 0x66, 10, 0x48]],
|
|
36
|
+
['literalDefault', 1, [0x06, 3, 0xd1, 0x66, 10, 0x48], 0x40],
|
|
37
|
+
['lateDefault', 2, [0xd2, 0x07, 0xd1, 0x66, 10, 0x48], 0x40],
|
|
38
|
+
['defaultQName', 1, [0x60, 12, 0xd1, 0x42, 1, 0x48]],
|
|
39
|
+
['constructXML', 1, [0x60, 11, 0xd1, 0x42, 1, 0x48]],
|
|
40
|
+
['callXML', 1, [0x60, 11, 0x20, 0xd1, 0x41, 1, 0x48]],
|
|
41
|
+
['constructList', 1, [0x60, 13, 0xd1, 0x42, 1, 0x48]],
|
|
42
|
+
['descendantsDefault', 1, [0xd1, 0x59, 10, 0x48]],
|
|
43
|
+
['setDefaultChild', 2, [0xd1, 0xd2, 0x61, 10, 0x47]],
|
|
44
|
+
['deleteDefaultChild', 1, [0xd1, 0x6a, 10, 0x48]],
|
|
45
|
+
);
|
|
46
|
+
methods.push(['captureDefault', 1, [0x06, 3, 0x40, methods.length + 3, 0xd1, 0x07, 0x48], 0x40]);
|
|
47
|
+
}
|
|
48
|
+
const extraMethods = withDefaults ? [
|
|
49
|
+
[1, [0xd1, 0x66, 10, 0x48]],
|
|
50
|
+
[0, [0x06, 3, 0xd0, 0x30, 0x60, 2, 0x58, 0, 0x29, 0x47], 0x40],
|
|
51
|
+
] : [];
|
|
52
|
+
const namespaceString = withDefaults ? 9 : 6;
|
|
53
|
+
const strings = ['Fixture', 'Object', 'urn:product', 'id', 'item', ...(withDefaults ? ['XML', 'QName', 'XMLList'] : []),
|
|
54
|
+
'namespace', 'http://adobe.com/AS3/2006/builtin', 'namespaceDeclarations', 'inScopeNamespaces', 'addNamespace', 'removeNamespace',
|
|
55
|
+
...methods.map(([name]) => name)];
|
|
56
|
+
u30(0); u30(0); u30(0);
|
|
57
|
+
u30(strings.length + 1);
|
|
58
|
+
for (const name of strings) {
|
|
59
|
+
const encoded = new TextEncoder().encode(name);
|
|
60
|
+
u30(encoded.length); bytes.push(...encoded);
|
|
61
|
+
}
|
|
62
|
+
u30(4); bytes.push(0x16); u30(0); bytes.push(0x08); u30(3);
|
|
63
|
+
bytes.push(0x08); u30(namespaceString + 1); // AS3 builtin namespace
|
|
64
|
+
u30(2); u30(2); u30(1); u30(2); // public and product namespace set
|
|
65
|
+
const methodQName = namespaceQName + 6;
|
|
66
|
+
u30(methodQName + methods.length);
|
|
67
|
+
const qname = (kind, ns, name) => { bytes.push(kind); u30(ns); u30(name); };
|
|
68
|
+
qname(7, 1, 1); qname(7, 1, 2);
|
|
69
|
+
qname(0x0d, 1, 4); // @id
|
|
70
|
+
qname(0x0d, 2, 4); // @product::id
|
|
71
|
+
qname(0x0d, 0, 0); // @*::*
|
|
72
|
+
qname(7, 2, 5); // product::item
|
|
73
|
+
bytes.push(0x12); // RTQNameLA, runtime namespace and local name
|
|
74
|
+
bytes.push(0x10); u30(4); // RTQNameA id, runtime namespace
|
|
75
|
+
bytes.push(0x1b); u30(1); // MultinameL, runtime local name
|
|
76
|
+
if (withDefaults) { qname(7, 1, 5); qname(7, 1, 6); qname(7, 1, 7); qname(7, 1, 8); }
|
|
77
|
+
qname(7, 3, namespaceString);
|
|
78
|
+
bytes.push(0x11); // RTQNameL, runtime namespace and local name
|
|
79
|
+
qname(7, 3, namespaceString + 2);
|
|
80
|
+
qname(7, 3, namespaceString + 3);
|
|
81
|
+
qname(7, 3, namespaceString + 4);
|
|
82
|
+
qname(7, 3, namespaceString + 5);
|
|
83
|
+
methods.forEach((_, index) => qname(7, 1, index + namespaceString + 6));
|
|
84
|
+
|
|
85
|
+
u30(methods.length + extraMethods.length + 2);
|
|
86
|
+
for (const [params, flags = 0] of [[0], [0],
|
|
87
|
+
...methods.map(([, params, , flags]) => [params, flags]),
|
|
88
|
+
...extraMethods.map(([params, , flags]) => [params, flags])]) {
|
|
89
|
+
u30(params); u30(0);
|
|
90
|
+
for (let i = 0; i < params; i++) u30(0);
|
|
91
|
+
u30(0); bytes.push(flags);
|
|
92
|
+
}
|
|
93
|
+
u30(0); // metadata
|
|
94
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); // single class
|
|
95
|
+
u30(methods.length);
|
|
96
|
+
methods.forEach((_, index) => { u30(index + methodQName); bytes.push(1); u30(0); u30(index + 2); });
|
|
97
|
+
u30(1); u30(0); u30(Number(withDefaults)); // cinit, static traits, scripts
|
|
98
|
+
if (withDefaults) {
|
|
99
|
+
u30(methods.length + 3); u30(1);
|
|
100
|
+
u30(1); bytes.push(4); u30(1); u30(0); // script exports Fixture
|
|
101
|
+
}
|
|
102
|
+
u30(methods.length + extraMethods.length + 1);
|
|
103
|
+
const body = (index, params, code) => {
|
|
104
|
+
u30(index); u30(4); u30(params + 1); u30(0); u30(0); u30(code.length);
|
|
105
|
+
bytes.push(...code); u30(0); u30(0);
|
|
106
|
+
};
|
|
107
|
+
body(0, 0, [0x47]);
|
|
108
|
+
methods.forEach(([, params, code], index) => body(index + 2, params, code));
|
|
109
|
+
extraMethods.forEach(([params, code], index) => body(index + methods.length + 2, params, code));
|
|
110
|
+
return Uint8Array.from(bytes);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const product = 'urn:product';
|
|
114
|
+
const attribute = (namespaceURI, localName, value) => ({ nodeType: 2, namespaceURI, localName, value });
|
|
115
|
+
function element(namespaceURI, localName, attributes, childNodes = []) {
|
|
116
|
+
return {
|
|
117
|
+
nodeType: 1, namespaceURI, localName, attributes, childNodes,
|
|
118
|
+
lookupPrefix(uri) { return uri === product ? 'p' : null; },
|
|
119
|
+
setAttributeNS(uri, name, value) {
|
|
120
|
+
const [first, second] = name.split(':');
|
|
121
|
+
const localName = second ?? first;
|
|
122
|
+
this.attributes = this.attributes.filter(attr => attr.namespaceURI !== uri || attr.localName !== localName);
|
|
123
|
+
this.attributes.push({ ...attribute(uri, localName, value), prefix: second ? first : null });
|
|
124
|
+
},
|
|
125
|
+
removeAttributeNode(node) { this.attributes.splice(this.attributes.indexOf(node), 1); },
|
|
126
|
+
ownerDocument: { createElementNS(uri, name) { return element(uri, name, []); } },
|
|
127
|
+
appendChild(node) { this.childNodes.push(node); },
|
|
128
|
+
removeChild(node) { this.childNodes.splice(this.childNodes.indexOf(node), 1); },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
it('executes AVM2 E4X attribute and descendant selectors by namespace URI', () => {
|
|
133
|
+
const documentElement = element(null, 'root', [
|
|
134
|
+
attribute('http://www.w3.org/2000/xmlns/', 'p', product),
|
|
135
|
+
attribute(null, 'id', 'public'),
|
|
136
|
+
attribute(product, 'id', 'scoped'),
|
|
137
|
+
], [
|
|
138
|
+
element(product, 'item', [attribute(product, 'id', 'child')]),
|
|
139
|
+
element(null, 'item', [attribute(null, 'id', 'other')]),
|
|
140
|
+
]);
|
|
141
|
+
class DOMParser {
|
|
142
|
+
parseFromString() { return { documentElement }; }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const diagnostics = new DiagnosticsCollector();
|
|
146
|
+
const js = transpileAvm2(buildE4XAbc(), diagnostics);
|
|
147
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
148
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
149
|
+
const { fixture, xml, Namespace, QName, XMLList } = runInNewContext(`${SWFLIB_SOURCE}
|
|
150
|
+
${AVM2_RUNTIME_STUB}
|
|
151
|
+
${js}
|
|
152
|
+
({
|
|
153
|
+
fixture: new Fixture(), xml: new (_getlex('XML'))('<root/>'),
|
|
154
|
+
Namespace: _getlex('Namespace'), QName: _getlex('QName'), XMLList: _getlex('XMLList'),
|
|
155
|
+
});
|
|
156
|
+
`, { DOMParser });
|
|
157
|
+
const strings = list => Array.from({ length: list.length() }, (_, index) => String(list[index]));
|
|
158
|
+
const ns = new Namespace(product);
|
|
159
|
+
|
|
160
|
+
expect(fixture.plain(xml)).toBeInstanceOf(XMLList);
|
|
161
|
+
expect(strings(fixture.plain(xml))).toEqual(['public']);
|
|
162
|
+
expect(strings(fixture.scoped(xml))).toEqual(['scoped']);
|
|
163
|
+
expect(strings(fixture.all(xml))).toEqual(['public', 'scoped']);
|
|
164
|
+
expect(strings(fixture.lateAttribute(xml, ns, 'id'))).toEqual(['scoped']);
|
|
165
|
+
expect(strings(fixture.lateAttribute(xml, Namespace(), new QName(null, 'id')))).toEqual(['public', 'scoped']);
|
|
166
|
+
expect(strings(fixture.descendantAttributes(xml))).toEqual(['public', 'scoped', 'child', 'other']);
|
|
167
|
+
expect(fixture.descendantItems(xml).length()).toBe(1);
|
|
168
|
+
const children = fixture.lateChildren(xml, '*');
|
|
169
|
+
expect(children.length()).toBe(2);
|
|
170
|
+
expect(strings(fixture.all(children))).toEqual(['child', 'other']);
|
|
171
|
+
expect(() => fixture.setScoped(children, 'invalid')).toThrow(/multi-item XMLList/);
|
|
172
|
+
|
|
173
|
+
fixture.setScoped(xml, 'updated');
|
|
174
|
+
expect(strings(fixture.scoped(xml))).toEqual(['updated']);
|
|
175
|
+
expect(fixture.deleteScoped(xml)).toBe(true);
|
|
176
|
+
expect(fixture.scoped(xml).length()).toBe(0);
|
|
177
|
+
expect(strings(fixture.plain(xml))).toEqual(['public']);
|
|
178
|
+
fixture.lateSet(xml, ns, 'recreated');
|
|
179
|
+
expect(strings(fixture.scoped(xml))).toEqual(['recreated']);
|
|
180
|
+
expect(fixture.deleteScoped(children)).toBe(true);
|
|
181
|
+
expect(strings(fixture.all(children))).toEqual(['other']);
|
|
182
|
+
expect(strings(fixture.scoped(xml))).toEqual(['recreated']);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('uses dxns values for element selection, XML creation, and lexical closures', () => {
|
|
186
|
+
const root = element(null, 'root', [attribute(null, 'id', 'unchanged')], [
|
|
187
|
+
element(product, 'item', []), element('urn:local', 'item', []), element(null, 'item', []),
|
|
188
|
+
]);
|
|
189
|
+
const parsed = [];
|
|
190
|
+
class DOMParser {
|
|
191
|
+
parseFromString(source) {
|
|
192
|
+
parsed.push(source);
|
|
193
|
+
if (source.startsWith('<swoof-xml xmlns="urn:product">')) {
|
|
194
|
+
const created = element(product, 'created', [], [element(product, 'item', [])]);
|
|
195
|
+
const content = source.includes('<xml-list>') ? element(product, 'xml-list', [], [created]) : created;
|
|
196
|
+
return { documentElement: element(product, 'swoof-xml', [], [content]) };
|
|
197
|
+
}
|
|
198
|
+
return { documentElement: root };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const diagnostics = new DiagnosticsCollector();
|
|
202
|
+
const js = transpileAvm2(buildE4XAbc(true), diagnostics);
|
|
203
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
204
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
205
|
+
const { fixture, xml } = runInNewContext(`${SWFLIB_SOURCE}\n${AVM2_RUNTIME_STUB}\n${js}
|
|
206
|
+
_runAvm2Initializers();
|
|
207
|
+
({ fixture: new Fixture(), xml: new (_getlex('XML'))('<root/>') });
|
|
208
|
+
`, { DOMParser });
|
|
209
|
+
const uri = list => list[0]._xmlNode.namespaceURI;
|
|
210
|
+
|
|
211
|
+
expect(uri(fixture.declaredDefault(xml))).toBe(product);
|
|
212
|
+
expect(uri(fixture.literalDefault(xml))).toBe(product);
|
|
213
|
+
expect(uri(fixture.lateDefault(xml, 'urn:local'))).toBe('urn:local');
|
|
214
|
+
expect(uri(fixture.lateDefault(xml, ''))).toBeNull();
|
|
215
|
+
expect(uri(fixture.lateChildren(xml, 'item'))).toBe(product);
|
|
216
|
+
expect(uri(fixture.descendantsDefault(xml))).toBe(product);
|
|
217
|
+
expect(uri(fixture.declaredDefault(xml))).toBe(product);
|
|
218
|
+
expect(uri(fixture.captureDefault('urn:local')(xml))).toBe(product);
|
|
219
|
+
expect(String(fixture.plain(xml)[0])).toBe('unchanged');
|
|
220
|
+
const object = { item: 'public JS property' };
|
|
221
|
+
expect(fixture.literalDefault(object)).toBe('public JS property');
|
|
222
|
+
fixture.setDefaultChild(object, 'changed JS property');
|
|
223
|
+
expect(object.item).toBe('changed JS property');
|
|
224
|
+
expect(fixture.deleteDefaultChild(object)).toBe(true);
|
|
225
|
+
expect('item' in object).toBe(false);
|
|
226
|
+
expect(fixture.defaultQName('item').uri).toBe(product);
|
|
227
|
+
expect(uri(fixture.declaredDefault(fixture.constructXML('<created><item/></created>')))).toBe(product);
|
|
228
|
+
expect(uri(fixture.declaredDefault(fixture.callXML('<created><item/></created>')))).toBe(product);
|
|
229
|
+
expect(uri(fixture.constructList('<created/>'))).toBe(product);
|
|
230
|
+
expect(parsed).toContain('<swoof-xml xmlns="urn:product"><created><item/></created></swoof-xml>');
|
|
231
|
+
|
|
232
|
+
expect(fixture.deleteDefaultChild(xml)).toBe(true);
|
|
233
|
+
expect(fixture.declaredDefault(xml).length()).toBe(0);
|
|
234
|
+
expect(uri(fixture.lateDefault(xml, 'urn:local'))).toBe('urn:local');
|
|
235
|
+
fixture.setDefaultChild(xml, 'new');
|
|
236
|
+
expect(uri(fixture.declaredDefault(xml))).toBe(product);
|
|
237
|
+
expect(String(fixture.declaredDefault(xml)[0])).toBe('new');
|
|
238
|
+
fixture.setDefaultChild(xml, 'updated');
|
|
239
|
+
expect(String(fixture.declaredDefault(xml)[0])).toBe('updated');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('returns XML Namespace values that can drive a compiled RTQNameL selector', () => {
|
|
243
|
+
const xmlns = 'http://www.w3.org/2000/xmlns/';
|
|
244
|
+
const declaration = (prefix, uri) => ({ ...attribute(xmlns, prefix || 'xmlns', uri), prefix: prefix ? 'xmlns' : null });
|
|
245
|
+
const textNode = { nodeType: 3, textContent: 'content' };
|
|
246
|
+
const item = { ...element(product, 'item', [], [textNode]), prefix: 'p' };
|
|
247
|
+
const nested = element('urn:shared', 'nested', [declaration('p', 'urn:nested'), declaration('q', 'urn:shared'),
|
|
248
|
+
declaration('', 'urn:shared')]);
|
|
249
|
+
const documentElement = element('urn:default', 'root', [
|
|
250
|
+
declaration('p', product), declaration('', 'urn:default'), declaration('q', 'urn:shared'),
|
|
251
|
+
attribute(product, 'id', 'product-id'),
|
|
252
|
+
declaration('stamp', 'urn:stamp'), { ...attribute('urn:stamp', 'id', 'stamp-id'), prefix: 'stamp' },
|
|
253
|
+
], [item, nested]);
|
|
254
|
+
item.parentNode = nested.parentNode = documentElement;
|
|
255
|
+
textNode.parentNode = item;
|
|
256
|
+
class DOMParser {
|
|
257
|
+
parseFromString(source) { return { documentElement: source === '<empty/>' ? element(null, 'empty', []) : documentElement }; }
|
|
258
|
+
}
|
|
259
|
+
const diagnostics = new DiagnosticsCollector();
|
|
260
|
+
const js = transpileAvm2(buildE4XAbc(), diagnostics);
|
|
261
|
+
const { fixture, xml, empty, Namespace, XMLList } = runInNewContext(`${SWFLIB_SOURCE}
|
|
262
|
+
${AVM2_RUNTIME_STUB}
|
|
263
|
+
${js}
|
|
264
|
+
({ fixture: new Fixture(), xml: new (_getlex('XML'))('<root/>'), empty: new (_getlex('XML'))('<empty/>'),
|
|
265
|
+
Namespace: _getlex('Namespace'), XMLList: _getlex('XMLList') });
|
|
266
|
+
`, { DOMParser });
|
|
267
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
268
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
269
|
+
|
|
270
|
+
const own = fixture.nodeNamespace(xml);
|
|
271
|
+
expect(own).toBeInstanceOf(Namespace);
|
|
272
|
+
expect(own).toMatchObject({ prefix: '', uri: 'urn:default' });
|
|
273
|
+
expect(fixture.lookupNamespace(xml, '')).toMatchObject({ prefix: '', uri: 'urn:default' });
|
|
274
|
+
expect(fixture.lookupNamespace(xml, 'missing')).toBeUndefined();
|
|
275
|
+
|
|
276
|
+
const selected = fixture.lookupNamespacedChild(xml, 'p', 'item');
|
|
277
|
+
expect(selected.length()).toBe(1);
|
|
278
|
+
expect(fixture.nodeNamespace(selected)).toMatchObject({ prefix: 'p', uri: product });
|
|
279
|
+
expect(fixture.lookupNamespace(selected, 'p')).toMatchObject({ prefix: 'p', uri: product });
|
|
280
|
+
expect(fixture.lookupNamespace(xml.children()[1], 'p')).toMatchObject({ prefix: 'p', uri: 'urn:nested' });
|
|
281
|
+
expect(fixture.nodeNamespace(selected[0].children()[0])).toBeNull();
|
|
282
|
+
expect(() => fixture.nodeNamespace(new XMLList())).toThrow(/exactly one item/);
|
|
283
|
+
expect(() => fixture.nodeNamespace(xml.children())).toThrow(/exactly one item/);
|
|
284
|
+
|
|
285
|
+
const pairs = namespaces => Array.from(namespaces, ns => {
|
|
286
|
+
expect(ns).toBeInstanceOf(Namespace);
|
|
287
|
+
return [ns.prefix, ns.uri];
|
|
288
|
+
});
|
|
289
|
+
const declarations = fixture.namespaceDeclarations(xml);
|
|
290
|
+
expect(String(fixture.lateAttribute(xml, declarations[0], 'id')[0])).toBe('product-id');
|
|
291
|
+
expect(pairs(fixture.inScopeNamespaces(empty))).toEqual([['', '']]);
|
|
292
|
+
expect(pairs(declarations)).toEqual([
|
|
293
|
+
['p', product], ['', 'urn:default'], ['q', 'urn:shared'], ['stamp', 'urn:stamp'],
|
|
294
|
+
]);
|
|
295
|
+
expect(pairs(fixture.namespaceDeclarations(selected))).toEqual([]);
|
|
296
|
+
expect(pairs(fixture.inScopeNamespaces(selected))).toEqual([
|
|
297
|
+
['p', product], ['', 'urn:default'], ['q', 'urn:shared'], ['stamp', 'urn:stamp'],
|
|
298
|
+
]);
|
|
299
|
+
const nestedValue = xml.children()[1];
|
|
300
|
+
expect(pairs(fixture.namespaceDeclarations(nestedValue))).toEqual([['p', 'urn:nested']]);
|
|
301
|
+
expect(pairs(fixture.inScopeNamespaces(nestedValue))).toEqual([
|
|
302
|
+
['p', 'urn:nested'], ['q', 'urn:shared'], ['', 'urn:shared'], ['stamp', 'urn:stamp'],
|
|
303
|
+
]);
|
|
304
|
+
expect(() => fixture.inScopeNamespaces(xml.children())).toThrow(/exactly one item/);
|
|
305
|
+
|
|
306
|
+
const unused = new Namespace('unused', 'urn:unused');
|
|
307
|
+
expect(fixture.addNamespace(xml, unused)).toBe(xml);
|
|
308
|
+
expect(fixture.lookupNamespace(xml, 'unused')).toMatchObject({ prefix: 'unused', uri: 'urn:unused' });
|
|
309
|
+
expect(fixture.addNamespace(selected, unused)).toBe(selected[0]);
|
|
310
|
+
fixture.addNamespace(xml, new Namespace('other', 'urn:unused'));
|
|
311
|
+
expect(fixture.removeNamespace(xml, 'urn:unused')).toBe(xml);
|
|
312
|
+
expect(fixture.lookupNamespace(selected, 'unused')).toBeUndefined();
|
|
313
|
+
expect(fixture.lookupNamespace(xml, 'other').uri).toBe('urn:unused');
|
|
314
|
+
|
|
315
|
+
const required = fixture.lookupNamespace(xml, 'p');
|
|
316
|
+
expect(fixture.removeNamespace(xml, required)).toBe(xml);
|
|
317
|
+
expect(fixture.lookupNamespacedChild(xml, 'p', 'item').length()).toBe(1);
|
|
318
|
+
fixture.addNamespace(xml, new Namespace('p', 'urn:conflict'));
|
|
319
|
+
expect(fixture.lookupNamespace(xml, 'p').uri).toBe(product);
|
|
320
|
+
expect(fixture.removeNamespace(selected, required)).toBe(selected[0]);
|
|
321
|
+
fixture.removeNamespace(xml, 'urn:stamp');
|
|
322
|
+
expect(fixture.lookupNamespace(xml, 'stamp').uri).toBe('urn:stamp');
|
|
323
|
+
expect(fixture.addNamespace(xml, 'urn:unspecified')).toBe(xml);
|
|
324
|
+
expect(fixture.namespaceDeclarations(xml).some(ns => ns.uri === 'urn:unspecified')).toBe(false);
|
|
325
|
+
expect(() => fixture.removeNamespace(xml.children(), unused)).toThrow(/exactly one item/);
|
|
326
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { AVM2_RUNTIME_STUB, transpileAvm2 } from '../transpiler/avm2/avm2-transpiler.js';
|
|
3
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
4
|
+
|
|
5
|
+
function exceptionAbc() {
|
|
6
|
+
const namedCatch = [0x5a, 0, 0x2a, 0x30, 0x2b, 0x6d, 1, // bind thrown value to catch scope slot 1
|
|
7
|
+
0x65, 0, 0x6c, 1, 0x60, 8, 0x56, 2, 0x48]; // read as a slot and lexical name
|
|
8
|
+
const methods = [
|
|
9
|
+
{ params: 1, code: [0xd0, 0x30, 0x24, 90, 0xd1, 0x03, ...namedCatch,
|
|
10
|
+
0x24, 99, 0x2b, 0x56, 2, 0x48], exceptions: [[4, 6, 6, 7, 8], [4, 6, 6 + namedCatch.length, 0, 0]] },
|
|
11
|
+
{ params: 1, code: [0xd1, 0x66, 9, 0x29, 0xd1, 0x66, 10, 0x48, 0x29, 0x24, 42, 0x48],
|
|
12
|
+
exceptions: [[4, 8, 8, 0, 0]] },
|
|
13
|
+
{ params: 1, code: [0xd1, 0x03, 0x2a, 0xd6, 0x24, 19, 0xd7, 0x03, 0xd3, 0x2b, 0x56, 2, 0x48],
|
|
14
|
+
exceptions: [[0, 2, 2, 0, 0], [0, 8, 8, 0, 0]] },
|
|
15
|
+
{ params: 0, code: [0x10, 0xfc, 0xff, 0xff, 0x29, 0x47], exceptions: [[0, 4, 4, 0, 0]] },
|
|
16
|
+
];
|
|
17
|
+
const names = ['ExceptionFixture', 'Object', 'select', 'boundaries', 'rethrow', 'spin', 'TypeError', 'caught', 'before', 'inside',
|
|
18
|
+
'ExceptionBase', 'handlerWritesReceiver'];
|
|
19
|
+
const bytes = [16, 0, 46, 0, 0, 0, 0, names.length + 1];
|
|
20
|
+
for (const name of names) bytes.push(name.length, ...new TextEncoder().encode(name));
|
|
21
|
+
bytes.push(2, 0x16, 0, 0, names.length + 1);
|
|
22
|
+
for (let i = 1; i <= names.length; i++) bytes.push(7, 1, i);
|
|
23
|
+
const emptySignature = [0, 0, 0, 0];
|
|
24
|
+
bytes.push(methods.length + 4, ...emptySignature, ...emptySignature);
|
|
25
|
+
for (const { params } of methods) bytes.push(params, 0, ...Array(params).fill(0), 0, 0);
|
|
26
|
+
bytes.push(...emptySignature, ...emptySignature);
|
|
27
|
+
bytes.push(0, 2, 11, 2, 0, 0, methods.length + 2, 0); // base instance without traits
|
|
28
|
+
bytes.push(1, 11, 0, 0, 0, methods.length);
|
|
29
|
+
for (const [index] of methods.entries()) bytes.push(index + 3, 1, 0, index + 2);
|
|
30
|
+
bytes.push(methods.length + 3, 0, 1, 0, 0, methods.length + 4);
|
|
31
|
+
const empty = { code: [0x47], exceptions: [] };
|
|
32
|
+
const ctor = { code: [0x10, 0, 0, 0, 0xd0, 0x49, 0, 0x24, 9, 0x03,
|
|
33
|
+
0x29, 0xd0, 0x24, 27, 0x61, 12, 0x47], exceptions: [[7, 10, 10, 0, 0]] };
|
|
34
|
+
const bodies = [ctor, empty, ...methods, empty, empty];
|
|
35
|
+
for (const [index, { code, exceptions }] of bodies.entries()) {
|
|
36
|
+
bytes.push(index, 3, 4, 0, 2, code.length, ...code, exceptions.length, ...exceptions.flat(), 0);
|
|
37
|
+
}
|
|
38
|
+
return Uint8Array.from(bytes);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function compile() {
|
|
42
|
+
const diagnostics = new DiagnosticsCollector();
|
|
43
|
+
const compiled = transpileAvm2(exceptionAbc(), diagnostics);
|
|
44
|
+
expect(diagnostics.errors()).toEqual([]);
|
|
45
|
+
expect(diagnostics.warnings()).toEqual([]);
|
|
46
|
+
return new Function(`${AVM2_RUNTIME_STUB}\n${compiled}\nreturn new ExceptionFixture();`)();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('AVM2 exception dispatch', () => {
|
|
50
|
+
it('selects typed handlers first and resets local scope before binding a named catch', () => {
|
|
51
|
+
const instance = compile();
|
|
52
|
+
const error = new TypeError('typed');
|
|
53
|
+
expect(instance.select(error)).toEqual([error, error]);
|
|
54
|
+
expect(instance.select('arbitrary thrown value')).toEqual([99, 'arbitrary thrown value']);
|
|
55
|
+
expect(instance.select(null)).toEqual([99, null]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('protects only the declared bytecode interval and catches errors from property access', () => {
|
|
59
|
+
const instance = compile();
|
|
60
|
+
const error = new Error('outside');
|
|
61
|
+
expect(() => instance.boundaries({ get before() { throw error; } })).toThrow(error);
|
|
62
|
+
expect(instance.boundaries({ get inside() { throw new Error('inside'); } })).toBe(42);
|
|
63
|
+
expect(instance.boundaries({ inside: 28 })).toBe(28);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('preserves locals through a handler rethrow into the next matching range', () => {
|
|
67
|
+
const instance = compile();
|
|
68
|
+
const error = {};
|
|
69
|
+
const [preservedLocal, thrown] = instance.rethrow(error);
|
|
70
|
+
expect(preservedLocal).toBe(19);
|
|
71
|
+
expect(thrown).toBe(error);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('keeps the runtime execution guard outside the authored catch-all', () => {
|
|
75
|
+
expect(() => compile().spin()).toThrow('AVM2 execution limit exceeded');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('uses the initialized receiver in a derived constructor handler', () => {
|
|
79
|
+
expect(compile().handlerWritesReceiver).toBe(27);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { transpileAvm2, AVM2_RUNTIME_STUB } from '../transpiler/avm2/avm2-transpiler.js';
|
|
3
|
+
import { createAvm2Runtime } from '../runtime/avm2-runtime.js';
|
|
4
|
+
import { DiagnosticsCollector } from '../util/diagnostics.js';
|
|
5
|
+
|
|
6
|
+
function buildMinimalAbc(codeBytes) {
|
|
7
|
+
const bytes = [];
|
|
8
|
+
const u16 = (v) => bytes.push(v & 0xff, (v >> 8) & 0xff);
|
|
9
|
+
const u30 = (v) => { let n = v >>> 0; while (n >= 0x80) { bytes.push((n & 0x7f) | 0x80); n >>>= 7; } bytes.push(n); };
|
|
10
|
+
const str = (s) => { const enc = new TextEncoder().encode(s); u30(enc.length); for (const b of enc) bytes.push(b); };
|
|
11
|
+
u16(16); u16(46);
|
|
12
|
+
u30(0); u30(0); u30(0);
|
|
13
|
+
u30(5); str(''); str('TestClass'); str('Sprite'); str('foo');
|
|
14
|
+
u30(2); bytes.push(0x16); u30(1);
|
|
15
|
+
u30(0);
|
|
16
|
+
u30(4); bytes.push(0x07); u30(1); u30(2); bytes.push(0x07); u30(1); u30(3); bytes.push(0x07); u30(1); u30(4);
|
|
17
|
+
u30(3); for (let m = 0; m < 3; m++) { u30(0); u30(0); u30(0); bytes.push(0); }
|
|
18
|
+
u30(0);
|
|
19
|
+
u30(1); u30(1); u30(2); bytes.push(0); u30(0); u30(0); u30(1); u30(3); bytes.push(0); u30(1); u30(0); u30(0);
|
|
20
|
+
u30(1); u30(0);
|
|
21
|
+
u30(1); u30(2); u30(0);
|
|
22
|
+
u30(1); u30(0); u30(4); u30(4); u30(1); u30(3); u30(codeBytes.length);
|
|
23
|
+
for (const b of codeBytes) bytes.push(b);
|
|
24
|
+
u30(0); u30(1); u30(3); bytes.push(0); u30(1); u30(0); u30(0); // activation foo slot
|
|
25
|
+
return new Uint8Array(bytes);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function compile(code) {
|
|
29
|
+
const diagnostics = new DiagnosticsCollector();
|
|
30
|
+
const js = transpileAvm2(buildMinimalAbc(code), diagnostics);
|
|
31
|
+
expect(diagnostics.errors()).toHaveLength(0);
|
|
32
|
+
expect(diagnostics.warnings()).toHaveLength(0);
|
|
33
|
+
return js;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('AVM2 scope property lookup', () => {
|
|
37
|
+
it('searches the active scope stack from innermost to outermost before this', () => {
|
|
38
|
+
const findProp = new Function(`${AVM2_RUNTIME_STUB}\nreturn _findProp;`)();
|
|
39
|
+
const instance = { value: 'this' };
|
|
40
|
+
const outer = { value: 'outer' };
|
|
41
|
+
const activation = { value: 'activation' };
|
|
42
|
+
expect(findProp('value', instance, [outer, activation], true, false)).toBe(activation);
|
|
43
|
+
expect(findProp('value', instance, [outer], true, false)).toBe(outer);
|
|
44
|
+
expect(findProp('value', instance, [], true, false)).toBe(instance);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('uses global-only lookup for findpropglobal and throws for strict missing names', () => {
|
|
48
|
+
const findProp = new Function(`${AVM2_RUNTIME_STUB}\nreturn _findProp;`)();
|
|
49
|
+
const local = { answer: 42 };
|
|
50
|
+
expect(findProp('answer', local, [local], false, true)).toBe(globalThis);
|
|
51
|
+
expect(findProp('Math', local, [], true, true)).toBe(globalThis);
|
|
52
|
+
expect(findProp('missingName', local, [], false, false)).toBe(globalThis);
|
|
53
|
+
expect(() => findProp('missingName', local, [], true, false)).toThrow(ReferenceError);
|
|
54
|
+
expect(() => findProp('missingName', local, [], true, true)).toThrow(ReferenceError);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('resolves activation properties in emitted findpropstrict code', () => {
|
|
58
|
+
// Create an activation with the declared foo slot, push it as scope, then read foo into this.foo.
|
|
59
|
+
const code = [
|
|
60
|
+
0x57, // newactivation
|
|
61
|
+
0x63, 1, // setlocal1
|
|
62
|
+
0x62, 1, 0x30, // pushscope(local1)
|
|
63
|
+
0x5d, 3, // findpropstrict foo
|
|
64
|
+
0x24, 17, 0x61, 3, // found activation.foo = 17
|
|
65
|
+
0x5d, 3, // findpropstrict foo again
|
|
66
|
+
0x66, 3, // getproperty foo
|
|
67
|
+
0xd0, 0x2b, 0x61, 3, // this.foo = value
|
|
68
|
+
0x47, // returnvoid
|
|
69
|
+
];
|
|
70
|
+
const js = compile(code);
|
|
71
|
+
expect(js).toMatch(/_findProp\("foo", this, _avm2OuterScopes\.concat\(\[_t\d+\]\), true, false\)/);
|
|
72
|
+
expect(js).toMatch(/var _t\d+ = _l1;/);
|
|
73
|
+
const TestClass = new Function(`class Sprite {}\n${AVM2_RUNTIME_STUB}\n${js}\nreturn TestClass;`)();
|
|
74
|
+
expect(new TestClass().foo).toBe(17);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('emits global-only lookup for global strict and definition operations', () => {
|
|
78
|
+
const globalStrict = compile([0x5b, 3, 0x29, 0x47]);
|
|
79
|
+
expect(globalStrict).toContain('_findProp("foo", globalThis, [], true, true)');
|
|
80
|
+
const findDef = compile([0x5f, 3, 0x29, 0x47]);
|
|
81
|
+
expect(findDef).toContain('_findProp("foo", globalThis, [], true, true)');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('resolves imported Flash timers before inherited browser methods while keeping authored shadows', () => {
|
|
85
|
+
const host = Object.create(globalThis);
|
|
86
|
+
const browserTimer = function () { throw new TypeError('Illegal invocation'); };
|
|
87
|
+
const flashTimer = (callback, delay) => [callback(), delay];
|
|
88
|
+
Object.defineProperty(host, 'setInterval', { value: browserTimer, configurable: true });
|
|
89
|
+
const avm2 = createAvm2Runtime(host, { packages: { utils: { setInterval: flashTimer } } });
|
|
90
|
+
const [first, script] = avm2._createAvm2ScriptScopes('timers', [[], []]);
|
|
91
|
+
const scopeKeys = ['setInterval', 'flash.utils.setInterval'];
|
|
92
|
+
const callKeys = ['setInterval']; // the call multiname omits package namespaces
|
|
93
|
+
const receiver = avm2._findProp('setInterval', {}, [script], true, false, null, scopeKeys, script);
|
|
94
|
+
expect(avm2._avm2CallProperty(receiver, 'setInterval', [() => 8, 500], callKeys)).toEqual([8, 500]);
|
|
95
|
+
expect(avm2._getlexScoped('setInterval', {}, [script], null, scopeKeys, script)).toBe(flashTimer);
|
|
96
|
+
expect(avm2._getlex('flash.utils.setInterval')).toBe(flashTimer);
|
|
97
|
+
expect(avm2._getlex('flash.utils::setInterval')).toBe(flashTimer);
|
|
98
|
+
expect(avm2._findProp('setInterval', {}, [script], true, false, null, callKeys, script)).toBe(script);
|
|
99
|
+
|
|
100
|
+
Object.defineProperty(first, 'setInterval', { value() { return this; } });
|
|
101
|
+
const authored = avm2._findProp('setInterval', {}, [script], true, false, null, scopeKeys, script);
|
|
102
|
+
expect(avm2._avm2CallProperty(authored, 'setInterval', [], callKeys)).toBe(script);
|
|
103
|
+
const instance = { setInterval() {} };
|
|
104
|
+
expect(avm2._findProp('setInterval', instance, [script, instance], true, false, null, scopeKeys, script)).toBe(instance);
|
|
105
|
+
|
|
106
|
+
const replacement = () => 'authored global';
|
|
107
|
+
Object.defineProperty(host, 'setInterval', { value: replacement });
|
|
108
|
+
expect(avm2._getlexScoped('setInterval', {}, [host], null, scopeKeys)).toBe(replacement);
|
|
109
|
+
});
|
|
110
|
+
});
|