@swf2es/player-hosts 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/LICENSE.third-party +759 -0
- package/README.md +43 -2
- package/dist/indexeddb.d.ts +27 -0
- package/dist/indexeddb.d.ts.map +1 -0
- package/dist/indexeddb.js +170 -0
- package/dist/indexeddb.js.map +1 -0
- package/dist/node-worker.d.ts +2 -0
- package/dist/node-worker.d.ts.map +1 -0
- package/dist/node-worker.js +12 -0
- package/dist/node-worker.js.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +43 -0
- package/dist/node.js.map +1 -0
- package/dist/precompiled.d.ts +31 -0
- package/dist/precompiled.d.ts.map +1 -0
- package/dist/precompiled.js +125 -0
- package/dist/precompiled.js.map +1 -0
- package/dist/stage3d.d.ts +13 -0
- package/dist/stage3d.d.ts.map +1 -0
- package/dist/stage3d.js +61 -0
- package/dist/stage3d.js.map +1 -0
- package/dist/thread/codegen/codegen.js +308 -0
- package/dist/thread/codegen/index.js +405 -0
- package/dist/thread/format/abc-names.js +126 -0
- package/dist/thread/format/actions.js +222 -0
- package/dist/thread/format/air-descriptor.js +63 -0
- package/dist/thread/format/api-versions.js +22 -0
- package/dist/thread/format/bitmap.js +199 -0
- package/dist/thread/format/button.js +60 -0
- package/dist/thread/format/compression.js +200 -0
- package/dist/thread/format/display.js +305 -0
- package/dist/thread/format/filters.js +136 -0
- package/dist/thread/format/font.js +168 -0
- package/dist/thread/format/index.js +26 -0
- package/dist/thread/format/pbj.js +484 -0
- package/dist/thread/format/shape.js +411 -0
- package/dist/thread/format/sound.js +91 -0
- package/dist/thread/format/swf.js +163 -0
- package/dist/thread/format/tags.js +58 -0
- package/dist/thread/format/text.js +135 -0
- package/dist/thread/format/zip.js +91 -0
- package/dist/thread/native/audio/binary.js +3 -0
- package/dist/thread/native/audio/index.js +72 -0
- package/dist/thread/native/base64.js +9 -0
- package/dist/thread/native/compress/binary.js +3 -0
- package/dist/thread/native/compress/index.js +145 -0
- package/dist/thread/native/instance.js +49 -0
- package/dist/thread/native/mp3/binary.js +3 -0
- package/dist/thread/native/mp3/index.js +48 -0
- package/dist/thread/native/render/binary.js +3 -0
- package/dist/thread/native/render/bitmap-kernel.js +591 -0
- package/dist/thread/native/render/draw-kernel.js +204 -0
- package/dist/thread/native/render/dxt-encoder.js +94 -0
- package/dist/thread/native/render/index.js +10 -0
- package/dist/thread/native/render/lines.js +122 -0
- package/dist/thread/native/render/module.js +26 -0
- package/dist/thread/native/render/pixel-ops.js +235 -0
- package/dist/thread/native/render/tessellator.js +250 -0
- package/dist/thread/player/avm1/amf.js +507 -0
- package/dist/thread/player/avm1/avm1.js +1304 -0
- package/dist/thread/player/avm1/bindings.js +214 -0
- package/dist/thread/player/avm1/classes.js +75 -0
- package/dist/thread/player/avm1/clips.js +229 -0
- package/dist/thread/player/avm1/compile.js +140 -0
- package/dist/thread/player/avm1/external.js +79 -0
- package/dist/thread/player/avm1/focus.js +278 -0
- package/dist/thread/player/avm1/globals/BitmapData.js +542 -0
- package/dist/thread/player/avm1/globals/Button.js +31 -0
- package/dist/thread/player/avm1/globals/Color.js +115 -0
- package/dist/thread/player/avm1/globals/ExternalInterface.js +310 -0
- package/dist/thread/player/avm1/globals/FileReference.js +217 -0
- package/dist/thread/player/avm1/globals/Key.js +60 -0
- package/dist/thread/player/avm1/globals/LoadVars.js +208 -0
- package/dist/thread/player/avm1/globals/LocalConnection.js +92 -0
- package/dist/thread/player/avm1/globals/MovieClip.js +1070 -0
- package/dist/thread/player/avm1/globals/MovieClipLoader.js +90 -0
- package/dist/thread/player/avm1/globals/NetConnection.js +261 -0
- package/dist/thread/player/avm1/globals/PrintJob.js +37 -0
- package/dist/thread/player/avm1/globals/Selection.js +62 -0
- package/dist/thread/player/avm1/globals/SharedObject.js +245 -0
- package/dist/thread/player/avm1/globals/Sound.js +238 -0
- package/dist/thread/player/avm1/globals/Stage.js +12 -0
- package/dist/thread/player/avm1/globals/StyleSheet.js +205 -0
- package/dist/thread/player/avm1/globals/TextField.js +396 -0
- package/dist/thread/player/avm1/globals/TextFormat.js +194 -0
- package/dist/thread/player/avm1/globals/TextSnapshot.js +88 -0
- package/dist/thread/player/avm1/globals/XML.js +396 -0
- package/dist/thread/player/avm1/globals/XMLNode.js +413 -0
- package/dist/thread/player/avm1/globals/XMLSocket.js +205 -0
- package/dist/thread/player/avm1/globals/drawing.js +202 -0
- package/dist/thread/player/avm1/globals/filters.js +635 -0
- package/dist/thread/player/avm1/globals/geom.js +600 -0
- package/dist/thread/player/avm1/input.js +483 -0
- package/dist/thread/player/avm1/keyboard.js +113 -0
- package/dist/thread/player/avm1/loads.js +352 -0
- package/dist/thread/player/avm1/net.js +219 -0
- package/dist/thread/player/avm1/paths.js +104 -0
- package/dist/thread/player/avm1/pointer.js +512 -0
- package/dist/thread/player/avm1/queue.js +303 -0
- package/dist/thread/player/avm1/sound.js +106 -0
- package/dist/thread/player/avm1/swf.js +141 -0
- package/dist/thread/player/avm1/timers.js +113 -0
- package/dist/thread/player/bitmap/bitmap.js +627 -0
- package/dist/thread/player/bitmap/draw.js +68 -0
- package/dist/thread/player/bitmap/dxt.js +11 -0
- package/dist/thread/player/bitmap/filters.js +656 -0
- package/dist/thread/player/bitmap/images.js +240 -0
- package/dist/thread/player/bitmap/kernel.js +65 -0
- package/dist/thread/player/bitmap/ops.js +1239 -0
- package/dist/thread/player/bitmap/pixel-bender.js +911 -0
- package/dist/thread/player/bitmap/png.js +139 -0
- package/dist/thread/player/bitmap/turbulence.js +89 -0
- package/dist/thread/player/clock.js +182 -0
- package/dist/thread/player/display/bitmapobject.js +25 -0
- package/dist/thread/player/display/bounds.js +520 -0
- package/dist/thread/player/display/buttonobject.js +305 -0
- package/dist/thread/player/display/color.js +40 -0
- package/dist/thread/player/display/container.js +150 -0
- package/dist/thread/player/display/display.js +14 -0
- package/dist/thread/player/display/displayobject.js +664 -0
- package/dist/thread/player/display/drawing.js +613 -0
- package/dist/thread/player/display/filters.js +285 -0
- package/dist/thread/player/display/geometry.js +189 -0
- package/dist/thread/player/display/gradients.js +117 -0
- package/dist/thread/player/display/graphicsdata.js +592 -0
- package/dist/thread/player/display/instantiate.js +71 -0
- package/dist/thread/player/display/matrix3d.js +373 -0
- package/dist/thread/player/display/morph.js +226 -0
- package/dist/thread/player/display/movieclip.js +680 -0
- package/dist/thread/player/display/perspective.js +193 -0
- package/dist/thread/player/display/scale9.js +236 -0
- package/dist/thread/player/display/shapeobject.js +131 -0
- package/dist/thread/player/display/shapes.js +407 -0
- package/dist/thread/player/display/textobjects.js +222 -0
- package/dist/thread/player/display/timeline.js +471 -0
- package/dist/thread/player/display/value-lists.js +40 -0
- package/dist/thread/player/display/videoobject.js +6 -0
- package/dist/thread/player/display/walk.js +127 -0
- package/dist/thread/player/files.js +334 -0
- package/dist/thread/player/hosts.js +207 -0
- package/dist/thread/player/input/avm1.js +82 -0
- package/dist/thread/player/input/context-menu.js +63 -0
- package/dist/thread/player/input/keyboard.js +458 -0
- package/dist/thread/player/input/pointer.js +863 -0
- package/dist/thread/player/input/text-editor.js +319 -0
- package/dist/thread/player/input/touch.js +209 -0
- package/dist/thread/player/localconnection.js +90 -0
- package/dist/thread/player/media/audio.js +376 -0
- package/dist/thread/player/media/dynamic-sound.js +90 -0
- package/dist/thread/player/media/extract.js +135 -0
- package/dist/thread/player/media/mp3.js +152 -0
- package/dist/thread/player/media/sounds.js +507 -0
- package/dist/thread/player/media/streaming-audio.js +133 -0
- package/dist/thread/player/player.js +616 -0
- package/dist/thread/player/playerglobal/air/net/WebSocket.js +250 -0
- package/dist/thread/player/playerglobal/air-library.js +8 -0
- package/dist/thread/player/playerglobal/flash/accessibility/Accessibility.js +21 -0
- package/dist/thread/player/playerglobal/flash/crypto/generateRandomBytes.js +32 -0
- package/dist/thread/player/playerglobal/flash/data/EncryptedLocalStore.js +61 -0
- package/dist/thread/player/playerglobal/flash/desktop/Clipboard.js +173 -0
- package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +179 -0
- package/dist/thread/player/playerglobal/flash/display/AVM1Movie.js +19 -0
- package/dist/thread/player/playerglobal/flash/display/Bitmap.js +58 -0
- package/dist/thread/player/playerglobal/flash/display/BitmapData.js +633 -0
- package/dist/thread/player/playerglobal/flash/display/DisplayObject.js +614 -0
- package/dist/thread/player/playerglobal/flash/display/DisplayObjectContainer.js +224 -0
- package/dist/thread/player/playerglobal/flash/display/Graphics.js +345 -0
- package/dist/thread/player/playerglobal/flash/display/InteractiveObject.js +87 -0
- package/dist/thread/player/playerglobal/flash/display/Loader.js +79 -0
- package/dist/thread/player/playerglobal/flash/display/LoaderInfo.js +128 -0
- package/dist/thread/player/playerglobal/flash/display/MovieClip.js +194 -0
- package/dist/thread/player/playerglobal/flash/display/NativeWindow.js +245 -0
- package/dist/thread/player/playerglobal/flash/display/Shader.js +26 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderData.js +85 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderInput.js +64 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderJob.js +181 -0
- package/dist/thread/player/playerglobal/flash/display/ShaderParameter.js +23 -0
- package/dist/thread/player/playerglobal/flash/display/Shape.js +13 -0
- package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +103 -0
- package/dist/thread/player/playerglobal/flash/display/Sprite.js +84 -0
- package/dist/thread/player/playerglobal/flash/display/Stage.js +231 -0
- package/dist/thread/player/playerglobal/flash/display/Stage3D.js +54 -0
- package/dist/thread/player/playerglobal/flash/display/shaders.js +228 -0
- package/dist/thread/player/playerglobal/flash/events/Event.js +58 -0
- package/dist/thread/player/playerglobal/flash/events/EventDispatcher.js +103 -0
- package/dist/thread/player/playerglobal/flash/events/GestureEvent.js +34 -0
- package/dist/thread/player/playerglobal/flash/events/HTTPStatusEvent.js +8 -0
- package/dist/thread/player/playerglobal/flash/events/KeyboardEvent.js +51 -0
- package/dist/thread/player/playerglobal/flash/events/MouseEvent.js +59 -0
- package/dist/thread/player/playerglobal/flash/events/PressAndTapGestureEvent.js +30 -0
- package/dist/thread/player/playerglobal/flash/events/TimerEvent.js +16 -0
- package/dist/thread/player/playerglobal/flash/events/TouchEvent.js +45 -0
- package/dist/thread/player/playerglobal/flash/external/ExternalInterface.js +73 -0
- package/dist/thread/player/playerglobal/flash/filesystem/File.js +340 -0
- package/dist/thread/player/playerglobal/flash/filesystem/FileStream.js +453 -0
- package/dist/thread/player/playerglobal/flash/filesystem/paths.js +156 -0
- package/dist/thread/player/playerglobal/flash/filesystem/writes.js +143 -0
- package/dist/thread/player/playerglobal/flash/filters/BevelFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/BitmapFilter.js +205 -0
- package/dist/thread/player/playerglobal/flash/filters/BlurFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/ColorMatrixFilter.js +11 -0
- package/dist/thread/player/playerglobal/flash/filters/ConvolutionFilter.js +26 -0
- package/dist/thread/player/playerglobal/flash/filters/DisplacementMapFilter.js +51 -0
- package/dist/thread/player/playerglobal/flash/filters/DropShadowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GlowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GradientBevelFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/GradientGlowFilter.js +4 -0
- package/dist/thread/player/playerglobal/flash/filters/ShaderFilter.js +53 -0
- package/dist/thread/player/playerglobal/flash/geom/Matrix3D.js +361 -0
- package/dist/thread/player/playerglobal/flash/geom/PerspectiveProjection.js +122 -0
- package/dist/thread/player/playerglobal/flash/geom/Transform.js +245 -0
- package/dist/thread/player/playerglobal/flash/geom/Utils3D.js +85 -0
- package/dist/thread/player/playerglobal/flash/globalization/Collator.js +149 -0
- package/dist/thread/player/playerglobal/flash/globalization/CurrencyFormatter.js +272 -0
- package/dist/thread/player/playerglobal/flash/globalization/CurrencyParseResult.js +21 -0
- package/dist/thread/player/playerglobal/flash/globalization/DateTimeFormatter.js +463 -0
- package/dist/thread/player/playerglobal/flash/globalization/LocaleID.js +144 -0
- package/dist/thread/player/playerglobal/flash/globalization/NumberFormatter.js +444 -0
- package/dist/thread/player/playerglobal/flash/globalization/NumberParseResult.js +22 -0
- package/dist/thread/player/playerglobal/flash/globalization/StringTools.js +59 -0
- package/dist/thread/player/playerglobal/flash/globalization/locale.js +190 -0
- package/dist/thread/player/playerglobal/flash/media/Camera.js +89 -0
- package/dist/thread/player/playerglobal/flash/media/Microphone.js +126 -0
- package/dist/thread/player/playerglobal/flash/media/Sound.js +543 -0
- package/dist/thread/player/playerglobal/flash/media/SoundMixer.js +74 -0
- package/dist/thread/player/playerglobal/flash/media/SoundTransform.js +40 -0
- package/dist/thread/player/playerglobal/flash/media/Video.js +43 -0
- package/dist/thread/player/playerglobal/flash/net/FileFilter.js +27 -0
- package/dist/thread/player/playerglobal/flash/net/FileReference.js +197 -0
- package/dist/thread/player/playerglobal/flash/net/LocalConnection.js +167 -0
- package/dist/thread/player/playerglobal/flash/net/NetConnection.js +155 -0
- package/dist/thread/player/playerglobal/flash/net/SharedObject.js +299 -0
- package/dist/thread/player/playerglobal/flash/net/Socket.js +282 -0
- package/dist/thread/player/playerglobal/flash/net/URLRequest.js +93 -0
- package/dist/thread/player/playerglobal/flash/net/URLStream.js +146 -0
- package/dist/thread/player/playerglobal/flash/net/XMLSocket.js +14 -0
- package/dist/thread/player/playerglobal/flash/net/local-modern.js +142 -0
- package/dist/thread/player/playerglobal/flash/net/local-values.js +217 -0
- package/dist/thread/player/playerglobal/flash/net/navigateToURL.js +29 -0
- package/dist/thread/player/playerglobal/flash/profiler/Telemetry.js +25 -0
- package/dist/thread/player/playerglobal/flash/sensors/Accelerometer.js +12 -0
- package/dist/thread/player/playerglobal/flash/system/ApplicationDomain.js +69 -0
- package/dist/thread/player/playerglobal/flash/system/Capabilities.js +163 -0
- package/dist/thread/player/playerglobal/flash/system/FSCommandHost.js +17 -0
- package/dist/thread/player/playerglobal/flash/system/Security.js +46 -0
- package/dist/thread/player/playerglobal/flash/system/SecurityDomain.js +21 -0
- package/dist/thread/player/playerglobal/flash/system/System.js +73 -0
- package/dist/thread/player/playerglobal/flash/system/Worker.js +112 -0
- package/dist/thread/player/playerglobal/flash/text/Font.js +95 -0
- package/dist/thread/player/playerglobal/flash/text/StaticText.js +16 -0
- package/dist/thread/player/playerglobal/flash/text/StyleSheet.js +65 -0
- package/dist/thread/player/playerglobal/flash/text/TextField.js +707 -0
- package/dist/thread/player/playerglobal/flash/text/TextRenderer.js +77 -0
- package/dist/thread/player/playerglobal/flash/text/engine/FontDescription.js +141 -0
- package/dist/thread/player/playerglobal/flash/text/engine/TabStop.js +46 -0
- package/dist/thread/player/playerglobal/flash/trace/Trace.js +17 -0
- package/dist/thread/player/playerglobal/flash/ui/ContextMenu.js +17 -0
- package/dist/thread/player/playerglobal/flash/ui/GameInput.js +19 -0
- package/dist/thread/player/playerglobal/flash/ui/Keyboard.js +27 -0
- package/dist/thread/player/playerglobal/flash/ui/Mouse.js +127 -0
- package/dist/thread/player/playerglobal/flash/ui/Multitouch.js +46 -0
- package/dist/thread/player/playerglobal/flash/utils/ByteArray.js +155 -0
- package/dist/thread/player/playerglobal/flash/utils/Timer.js +25 -0
- package/dist/thread/player/playerglobal/flash/xml/XMLDocument.js +74 -0
- package/dist/thread/player/playerglobal/index.js +224 -0
- package/dist/thread/player/playerglobal/libraries.js +10 -0
- package/dist/thread/player/playerglobal/playerglobal-library.js +22 -0
- package/dist/thread/player/playerglobal/toplevel.js +122 -0
- package/dist/thread/player/scripting/clipboard.js +146 -0
- package/dist/thread/player/scripting/code.js +900 -0
- package/dist/thread/player/scripting/evaluate.js +144 -0
- package/dist/thread/player/scripting/events.js +172 -0
- package/dist/thread/player/scripting/handover.js +182 -0
- package/dist/thread/player/scripting/lazy.js +38 -0
- package/dist/thread/player/scripting/lifecycle.js +272 -0
- package/dist/thread/player/scripting/loads.js +860 -0
- package/dist/thread/player/scripting/sha256.js +95 -0
- package/dist/thread/player/scripting/symbols.js +348 -0
- package/dist/thread/player/scripting/timers.js +434 -0
- package/dist/thread/player/scripting/workers.js +923 -0
- package/dist/thread/player/scripting.js +1018 -0
- package/dist/thread/player/stage.js +4 -0
- package/dist/thread/player/text/csm.js +113 -0
- package/dist/thread/player/text/css.js +167 -0
- package/dist/thread/player/text/fonts.js +97 -0
- package/dist/thread/player/text/layout.js +393 -0
- package/dist/thread/player/text/static.js +109 -0
- package/dist/thread/player/text/text.js +431 -0
- package/dist/thread/player/workers/thread.js +159 -0
- package/dist/thread/player/workers/wire.js +198 -0
- package/dist/thread/player-hosts/web-worker.js +19 -0
- package/dist/thread/runtime/avm1/activation.js +89 -0
- package/dist/thread/runtime/avm1/case.js +249 -0
- package/dist/thread/runtime/avm1/clips.js +334 -0
- package/dist/thread/runtime/avm1/control.js +280 -0
- package/dist/thread/runtime/avm1/errors.js +50 -0
- package/dist/thread/runtime/avm1/functions.js +249 -0
- package/dist/thread/runtime/avm1/globals/array.js +549 -0
- package/dist/thread/runtime/avm1/globals/broadcaster.js +131 -0
- package/dist/thread/runtime/avm1/globals/date.js +436 -0
- package/dist/thread/runtime/avm1/globals/global.js +344 -0
- package/dist/thread/runtime/avm1/globals/math.js +139 -0
- package/dist/thread/runtime/avm1/globals/number.js +93 -0
- package/dist/thread/runtime/avm1/globals/string.js +201 -0
- package/dist/thread/runtime/avm1/globals/timers.js +129 -0
- package/dist/thread/runtime/avm1/host.js +5 -0
- package/dist/thread/runtime/avm1/index.js +14 -0
- package/dist/thread/runtime/avm1/inheritance.js +132 -0
- package/dist/thread/runtime/avm1/numbers.js +298 -0
- package/dist/thread/runtime/avm1/objects.js +896 -0
- package/dist/thread/runtime/avm1/operators.js +170 -0
- package/dist/thread/runtime/avm1/realm.js +529 -0
- package/dist/thread/runtime/avm1/runtime.js +882 -0
- package/dist/thread/runtime/avm1/scope.js +385 -0
- package/dist/thread/runtime/avm1/urls.js +180 -0
- package/dist/thread/runtime/avm1/values.js +97 -0
- package/dist/thread/runtime/avm2/amf-classes.js +66 -0
- package/dist/thread/runtime/avm2/amf.js +801 -0
- package/dist/thread/runtime/avm2/array-conversion.js +100 -0
- package/dist/thread/runtime/avm2/builtin-library.js +21 -0
- package/dist/thread/runtime/avm2/cache-fill.js +86 -0
- package/dist/thread/runtime/avm2/classes.js +211 -0
- package/dist/thread/runtime/avm2/definitions.js +69 -0
- package/dist/thread/runtime/avm2/descriptors.js +5 -0
- package/dist/thread/runtime/avm2/dictionary-keys.js +295 -0
- package/dist/thread/runtime/avm2/domain-memory.js +75 -0
- package/dist/thread/runtime/avm2/domain.js +280 -0
- package/dist/thread/runtime/avm2/dynamic-properties.js +182 -0
- package/dist/thread/runtime/avm2/enumeration.js +393 -0
- package/dist/thread/runtime/avm2/errors.js +45 -0
- package/dist/thread/runtime/avm2/float-library.js +66 -0
- package/dist/thread/runtime/avm2/float.js +26 -0
- package/dist/thread/runtime/avm2/hooks.js +19 -0
- package/dist/thread/runtime/avm2/index.js +38 -0
- package/dist/thread/runtime/avm2/messages.js +177 -0
- package/dist/thread/runtime/avm2/method-factories.js +95 -0
- package/dist/thread/runtime/avm2/modules.js +105 -0
- package/dist/thread/runtime/avm2/names.js +248 -0
- package/dist/thread/runtime/avm2/natives/aliases.js +47 -0
- package/dist/thread/runtime/avm2/natives/array.js +390 -0
- package/dist/thread/runtime/avm2/natives/bytearray.js +1227 -0
- package/dist/thread/runtime/avm2/natives/case.js +88 -0
- package/dist/thread/runtime/avm2/natives/concurrent.js +199 -0
- package/dist/thread/runtime/avm2/natives/date.js +581 -0
- package/dist/thread/runtime/avm2/natives/define.js +130 -0
- package/dist/thread/runtime/avm2/natives/describe.js +351 -0
- package/dist/thread/runtime/avm2/natives/dictionary.js +12 -0
- package/dist/thread/runtime/avm2/natives/float-vector.js +81 -0
- package/dist/thread/runtime/avm2/natives/float.js +96 -0
- package/dist/thread/runtime/avm2/natives/index.js +64 -0
- package/dist/thread/runtime/avm2/natives/json.js +514 -0
- package/dist/thread/runtime/avm2/natives/number.js +162 -0
- package/dist/thread/runtime/avm2/natives/object.js +237 -0
- package/dist/thread/runtime/avm2/natives/proxy.js +75 -0
- package/dist/thread/runtime/avm2/natives/regexp.js +485 -0
- package/dist/thread/runtime/avm2/natives/shell-workers.js +404 -0
- package/dist/thread/runtime/avm2/natives/shell.js +557 -0
- package/dist/thread/runtime/avm2/natives/sort.js +377 -0
- package/dist/thread/runtime/avm2/natives/string.js +132 -0
- package/dist/thread/runtime/avm2/natives/sync.js +821 -0
- package/dist/thread/runtime/avm2/natives/toplevel.js +139 -0
- package/dist/thread/runtime/avm2/natives/vector-elements.js +46 -0
- package/dist/thread/runtime/avm2/natives/vector.js +406 -0
- package/dist/thread/runtime/avm2/natives/xml/access.js +633 -0
- package/dist/thread/runtime/avm2/natives/xml/build.js +291 -0
- package/dist/thread/runtime/avm2/natives/xml/chars.js +112 -0
- package/dist/thread/runtime/avm2/natives/xml/escape.js +38 -0
- package/dist/thread/runtime/avm2/natives/xml/names.js +204 -0
- package/dist/thread/runtime/avm2/natives/xml/node.js +272 -0
- package/dist/thread/runtime/avm2/natives/xml/operators.js +69 -0
- package/dist/thread/runtime/avm2/natives/xml/parser.js +356 -0
- package/dist/thread/runtime/avm2/natives/xml/strings.js +191 -0
- package/dist/thread/runtime/avm2/natives/xml/values.js +122 -0
- package/dist/thread/runtime/avm2/natives/xml/xml.js +645 -0
- package/dist/thread/runtime/avm2/number-strings.js +110 -0
- package/dist/thread/runtime/avm2/numbers.js +558 -0
- package/dist/thread/runtime/avm2/options.js +16 -0
- package/dist/thread/runtime/avm2/player-messages.js +550 -0
- package/dist/thread/runtime/avm2/property-cache.js +135 -0
- package/dist/thread/runtime/avm2/runtime.js +2644 -0
- package/dist/thread/runtime/avm2/traits.js +509 -0
- package/dist/thread/runtime/index.js +7 -0
- package/dist/web-worker.d.ts +2 -0
- package/dist/web-worker.d.ts.map +1 -0
- package/dist/web-worker.js +20 -0
- package/dist/web-worker.js.map +1 -0
- package/dist/websocket.d.ts +4 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +27 -0
- package/dist/websocket.js.map +1 -0
- package/dist/workers.d.ts +35 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +171 -0
- package/dist/workers.js.map +1 -0
- package/package.json +62 -3
- package/src/indexeddb.ts +227 -0
- package/src/node-worker.ts +13 -0
- package/src/node.ts +49 -0
- package/src/precompiled.ts +166 -0
- package/src/stage3d.ts +76 -0
- package/src/web-worker.ts +24 -0
- package/src/websocket.ts +32 -0
- package/src/workers.ts +255 -0
package/dist/workers.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long after a Web Worker's terminate it is taken to have stopped. A
|
|
3
|
+
* browser does not say, and Chrome lets a busy worker's script run on for
|
|
4
|
+
* some seconds (2.5 to 4 s measured, in Chrome 156) before it stops it by
|
|
5
|
+
* force; Firefox's and Safari's were not measured. The player stops a
|
|
6
|
+
* terminated worker's thread so only when the worker has not stopped
|
|
7
|
+
* itself first (scripting/workers.ts).
|
|
8
|
+
*/
|
|
9
|
+
const STOPPED_GRACE = 8000;
|
|
10
|
+
/** The workers started ahead, by script URL. */
|
|
11
|
+
const pools = new Map();
|
|
12
|
+
/** How many hosts not yet released use each pool, and the timer that lets an unused one go. */
|
|
13
|
+
const users = new Map();
|
|
14
|
+
/** How long a pool no player uses keeps its workers, for the next player a page makes. */
|
|
15
|
+
const IDLE = 10_000;
|
|
16
|
+
function use(url) {
|
|
17
|
+
const key = String(url);
|
|
18
|
+
const u = users.get(key) ?? { count: 0, idle: null };
|
|
19
|
+
if (u.idle !== null) {
|
|
20
|
+
clearTimeout(u.idle);
|
|
21
|
+
u.idle = null;
|
|
22
|
+
}
|
|
23
|
+
u.count++;
|
|
24
|
+
users.set(key, u);
|
|
25
|
+
}
|
|
26
|
+
function release(url) {
|
|
27
|
+
const key = String(url);
|
|
28
|
+
const u = users.get(key);
|
|
29
|
+
if (!u || --u.count > 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
u.idle = setTimeout(() => {
|
|
33
|
+
for (const spare of pools.get(key) ?? []) {
|
|
34
|
+
spare.settle();
|
|
35
|
+
spare.worker.terminate();
|
|
36
|
+
}
|
|
37
|
+
pools.delete(key);
|
|
38
|
+
users.delete(key);
|
|
39
|
+
}, IDLE);
|
|
40
|
+
}
|
|
41
|
+
/** The page's own modules that import a worker script from another origin, by its URL. */
|
|
42
|
+
const importers = new Map();
|
|
43
|
+
function spawn(url) {
|
|
44
|
+
const worker = construct(url);
|
|
45
|
+
// Answered with "ready" once the page's messages reach the worker.
|
|
46
|
+
worker.postMessage({ type: "ping" });
|
|
47
|
+
return worker;
|
|
48
|
+
}
|
|
49
|
+
function construct(url) {
|
|
50
|
+
try {
|
|
51
|
+
return new Worker(url, { type: "module" });
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// A browser starts a worker only on a script of the page's origin.
|
|
55
|
+
if (!(error instanceof DOMException && error.name === "SecurityError")) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const href = new URL(url, globalThis.location?.href).href;
|
|
59
|
+
let importer = importers.get(href);
|
|
60
|
+
if (importer === undefined) {
|
|
61
|
+
const source = `import ${JSON.stringify(href)};`;
|
|
62
|
+
importer = URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
|
|
63
|
+
importers.set(href, importer);
|
|
64
|
+
}
|
|
65
|
+
return new Worker(importer, { type: "module" });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Keep `count` workers started ahead for `url`; where the page cannot start one, fewer. */
|
|
69
|
+
function fill(url, count) {
|
|
70
|
+
const key = String(url);
|
|
71
|
+
let pool = pools.get(key);
|
|
72
|
+
if (!pool) {
|
|
73
|
+
pool = [];
|
|
74
|
+
pools.set(key, pool);
|
|
75
|
+
}
|
|
76
|
+
while (pool.length < count) {
|
|
77
|
+
let worker;
|
|
78
|
+
try {
|
|
79
|
+
worker = spawn(url);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// A policy that forbids the script: start() reports it.
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
let settle = () => { };
|
|
86
|
+
const spare = {
|
|
87
|
+
worker,
|
|
88
|
+
ready: false,
|
|
89
|
+
failed: null,
|
|
90
|
+
settled: new Promise((resolve) => {
|
|
91
|
+
settle = resolve;
|
|
92
|
+
}),
|
|
93
|
+
settle: () => settle(),
|
|
94
|
+
};
|
|
95
|
+
worker.onmessage = (event) => {
|
|
96
|
+
if (event.data?.type === "ready") {
|
|
97
|
+
spare.ready = true;
|
|
98
|
+
spare.settle();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
worker.onerror = (event) => {
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
spare.failed = event.message;
|
|
104
|
+
spare.settle();
|
|
105
|
+
};
|
|
106
|
+
pool.push(spare);
|
|
107
|
+
}
|
|
108
|
+
return pool;
|
|
109
|
+
}
|
|
110
|
+
/** The pool's first worker that has loaded, else its first that has not failed. */
|
|
111
|
+
function take(pool) {
|
|
112
|
+
for (const spare of pool.filter((s) => s.failed !== null)) {
|
|
113
|
+
spare.worker.terminate();
|
|
114
|
+
pool.splice(pool.indexOf(spare), 1);
|
|
115
|
+
}
|
|
116
|
+
const at = Math.max(pool.findIndex((s) => s.ready), 0);
|
|
117
|
+
return pool.splice(at, 1)[0];
|
|
118
|
+
}
|
|
119
|
+
/** Background workers on module Web Workers. */
|
|
120
|
+
export function webWorkerHost(options) {
|
|
121
|
+
const url = options.url ?? new URL("./thread/player-hosts/web-worker.js", import.meta.url);
|
|
122
|
+
const cores = globalThis.navigator
|
|
123
|
+
?.hardwareConcurrency;
|
|
124
|
+
const spares = options.spares ?? Math.min(4, Math.max(2, cores ?? 2));
|
|
125
|
+
use(url);
|
|
126
|
+
const pool = fill(url, spares);
|
|
127
|
+
let released = false;
|
|
128
|
+
return {
|
|
129
|
+
ready: Promise.all(pool.map((s) => s.settled)).then(() => { }),
|
|
130
|
+
release() {
|
|
131
|
+
if (!released) {
|
|
132
|
+
released = true;
|
|
133
|
+
release(url);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
start(init, receive, failed) {
|
|
137
|
+
const spare = take(fill(url, spares));
|
|
138
|
+
const worker = spare?.worker ?? spawn(url);
|
|
139
|
+
// One in its place, loaded once the page's thread is free.
|
|
140
|
+
fill(url, spares);
|
|
141
|
+
// Taken before it loaded, it still settles the ready of the host that started it ahead.
|
|
142
|
+
worker.onmessage = (event) => {
|
|
143
|
+
// A worker taken before it loaded says so first.
|
|
144
|
+
if (event.data?.type === "ready") {
|
|
145
|
+
spare?.settle();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
receive(event.data);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
worker.onerror = (event) => {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
spare?.settle();
|
|
154
|
+
worker.terminate();
|
|
155
|
+
failed(new Error(`a background worker's thread failed: ${event.message}`));
|
|
156
|
+
};
|
|
157
|
+
const start = { codegen: options.codegen, init };
|
|
158
|
+
worker.postMessage(start);
|
|
159
|
+
return {
|
|
160
|
+
post: (message) => worker.postMessage(message),
|
|
161
|
+
// A browser tells nobody when a Web Worker has stopped.
|
|
162
|
+
terminate: () => {
|
|
163
|
+
spare?.settle();
|
|
164
|
+
worker.terminate();
|
|
165
|
+
return new Promise((resolve) => setTimeout(resolve, STOPPED_GRACE));
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=workers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workers.js","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAiEA;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,gDAAgD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AAO,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;YAC9D,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC1B,OAAO;gBACL,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC9C,wDAAwD;gBACxD,SAAS,EAAE,GAAG,EAAE;oBACd,KAAK,EAAE,MAAM,EAAE,CAAC;oBAChB,MAAM,CAAC,SAAS,EAAE,CAAC;oBACnB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;gBACtE,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swf2es/player-hosts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Optional Node and WebSocket transports, worker threads, an IndexedDB module cache and precompiled modules for the swf2es player",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"swf",
|
|
7
|
+
"flash",
|
|
8
|
+
"player",
|
|
9
|
+
"websocket",
|
|
10
|
+
"web-worker",
|
|
11
|
+
"indexeddb"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://swf2es.github.io/swf2es/",
|
|
14
|
+
"bugs": "https://github.com/swf2es/swf2es/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/swf2es/swf2es.git",
|
|
18
|
+
"directory": "packages/player-hosts"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0 AND (Apache-2.0 OR MIT) AND MPL-2.0 AND W3C-20150513 AND Zlib AND LicenseRef-LZMA-SDK-Public-Domain AND CC0-1.0 AND SGI-B-2.0 AND BSD-2-Clause AND MIT",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
"./stage3d": {
|
|
24
|
+
"types": "./dist/stage3d.d.ts",
|
|
25
|
+
"default": "./dist/stage3d.js"
|
|
26
|
+
},
|
|
27
|
+
"./indexeddb": {
|
|
28
|
+
"types": "./dist/indexeddb.d.ts",
|
|
29
|
+
"default": "./dist/indexeddb.js"
|
|
30
|
+
},
|
|
31
|
+
"./precompiled": {
|
|
32
|
+
"types": "./dist/precompiled.d.ts",
|
|
33
|
+
"default": "./dist/precompiled.js"
|
|
34
|
+
},
|
|
35
|
+
"./node": {
|
|
36
|
+
"types": "./dist/node.d.ts",
|
|
37
|
+
"default": "./dist/node.js"
|
|
38
|
+
},
|
|
39
|
+
"./workers": {
|
|
40
|
+
"types": "./dist/workers.d.ts",
|
|
41
|
+
"default": "./dist/workers.js"
|
|
42
|
+
},
|
|
43
|
+
"./web-worker": {
|
|
44
|
+
"types": "./dist/web-worker.d.ts",
|
|
45
|
+
"default": "./dist/web-worker.js"
|
|
46
|
+
},
|
|
47
|
+
"./node-worker": {
|
|
48
|
+
"types": "./dist/node-worker.d.ts",
|
|
49
|
+
"default": "./dist/node-worker.js"
|
|
50
|
+
},
|
|
51
|
+
"./websocket": {
|
|
52
|
+
"types": "./dist/websocket.d.ts",
|
|
53
|
+
"default": "./dist/websocket.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"!dist/**/.tsbuildinfo",
|
|
59
|
+
"src",
|
|
60
|
+
"LICENSE.third-party"
|
|
61
|
+
],
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@swf2es/player": "0.1.0"
|
|
64
|
+
}
|
|
6
65
|
}
|
package/src/indexeddb.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// A ModuleCache in the browser's IndexedDB: the modules the compiler wrote
|
|
2
|
+
// for a page's SWFs, kept for its next load. A large application's module
|
|
3
|
+
// took 250 ms to compile and 10 ms to read back (see docs/architecture/modules.md,
|
|
4
|
+
// Caching modules). Anything that fails, a database that will not open, a
|
|
5
|
+
// quota, a store that is gone, makes a miss, and the player compiles.
|
|
6
|
+
import type { CachedModule, ModuleCache } from "@swf2es/player";
|
|
7
|
+
|
|
8
|
+
export interface IndexedDbModuleCacheOptions {
|
|
9
|
+
/** The database's name. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** About how many bytes the modules may take, as UTF-16; the least recently used go first. */
|
|
12
|
+
maxBytes?: number;
|
|
13
|
+
/** The IndexedDB to use: the global one by default. */
|
|
14
|
+
indexedDB?: IDBFactory;
|
|
15
|
+
/** How long to wait for the database to open, in ms, before doing without it. */
|
|
16
|
+
openTimeout?: number;
|
|
17
|
+
/** How long, in ms, to do without a database that did not open before trying again. */
|
|
18
|
+
retryAfter?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A ModuleCache that a host can close, letting go of its database. */
|
|
22
|
+
export interface IndexedDbModuleCache extends ModuleCache {
|
|
23
|
+
/** Close the database; a later get or put opens it again. */
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The database's version: 2 kept each module with its compile's log, 3 with their lengths too. */
|
|
28
|
+
const VERSION = 3;
|
|
29
|
+
const MODULES = "modules";
|
|
30
|
+
/** Each module's size and last use, apart from it, so that evicting reads no module. */
|
|
31
|
+
const ENTRIES = "entries";
|
|
32
|
+
const USED = "used";
|
|
33
|
+
|
|
34
|
+
interface Entry {
|
|
35
|
+
key: string;
|
|
36
|
+
bytes: number;
|
|
37
|
+
used: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A ModuleCache kept in IndexedDB, opened on its first use. A get marks its
|
|
42
|
+
* module used; a put evicts the least recently used until the modules fit
|
|
43
|
+
* in `maxBytes`, and stores nothing larger than that, once the page is
|
|
44
|
+
* idle: a large module's write that a load's next get waited behind took
|
|
45
|
+
* that get from 4 to 45 ms.
|
|
46
|
+
*/
|
|
47
|
+
export function indexedDbModuleCache(
|
|
48
|
+
options: IndexedDbModuleCacheOptions = {},
|
|
49
|
+
): IndexedDbModuleCache {
|
|
50
|
+
const {
|
|
51
|
+
name = "swf2es-modules",
|
|
52
|
+
maxBytes = 256 * 1024 * 1024,
|
|
53
|
+
openTimeout = 2000,
|
|
54
|
+
retryAfter = 30_000,
|
|
55
|
+
} = options;
|
|
56
|
+
let opened: Promise<IDBDatabase> | null = null;
|
|
57
|
+
// When a database that did not open may be tried again.
|
|
58
|
+
let retryAt = 0;
|
|
59
|
+
const database = () => {
|
|
60
|
+
if (opened === null || (retryAt !== 0 && Date.now() >= retryAt)) {
|
|
61
|
+
retryAt = 0;
|
|
62
|
+
const attempt = open(options.indexedDB ?? globalThis.indexedDB, name, openTimeout);
|
|
63
|
+
opened = attempt;
|
|
64
|
+
attempt.then(
|
|
65
|
+
(db) => {
|
|
66
|
+
// Another tab opening a later version: let go, and open again
|
|
67
|
+
// next time, unless this was let go of already for another.
|
|
68
|
+
db.onversionchange = () => {
|
|
69
|
+
db.close();
|
|
70
|
+
if (opened === attempt) {
|
|
71
|
+
opened = null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
() => {
|
|
76
|
+
if (opened === attempt) {
|
|
77
|
+
retryAt = Date.now() + retryAfter;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return opened;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
async get(key) {
|
|
88
|
+
const db = await database();
|
|
89
|
+
const stored = await request<unknown>(db.transaction(MODULES).objectStore(MODULES).get(key));
|
|
90
|
+
const module = stored as CachedModule | undefined;
|
|
91
|
+
if (
|
|
92
|
+
typeof module?.module !== "string" ||
|
|
93
|
+
typeof module.log !== "string" ||
|
|
94
|
+
!Array.isArray(module.lengths)
|
|
95
|
+
) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Marked used apart, in a store no get reads, and not waited for: a
|
|
100
|
+
// mark that fails leaves the module as read and its last use as it was.
|
|
101
|
+
try {
|
|
102
|
+
const entries = db.transaction(ENTRIES, "readwrite").objectStore(ENTRIES);
|
|
103
|
+
request<Entry | undefined>(entries.get(key)).then(
|
|
104
|
+
(entry) => {
|
|
105
|
+
if (entry) {
|
|
106
|
+
entries.put({ ...entry, used: Date.now() });
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
() => {},
|
|
110
|
+
);
|
|
111
|
+
} catch {
|
|
112
|
+
// No transaction: its last use stays as it was.
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
module: module.module,
|
|
117
|
+
log: module.log,
|
|
118
|
+
lengths: [...module.lengths] as [number, number],
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
async put(key, module) {
|
|
122
|
+
const bytes = (module.module.length + module.log.length) * 2;
|
|
123
|
+
if (bytes > maxBytes) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const db = await database();
|
|
128
|
+
await new Promise<void>((resolve) => idle(resolve));
|
|
129
|
+
const tx = db.transaction([MODULES, ENTRIES], "readwrite");
|
|
130
|
+
const modules = tx.objectStore(MODULES);
|
|
131
|
+
const entries = tx.objectStore(ENTRIES);
|
|
132
|
+
modules.put({ module: module.module, log: module.log, lengths: module.lengths }, key);
|
|
133
|
+
entries.put({ key, bytes, used: Date.now() } as Entry);
|
|
134
|
+
// Oldest first, the one just put among them.
|
|
135
|
+
const all = await request<Entry[]>(entries.index(USED).getAll());
|
|
136
|
+
let total = 0;
|
|
137
|
+
for (const entry of all) {
|
|
138
|
+
total += entry.bytes;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const entry of all) {
|
|
142
|
+
if (total <= maxBytes) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (entry.key !== key) {
|
|
147
|
+
modules.delete(entry.key);
|
|
148
|
+
entries.delete(entry.key);
|
|
149
|
+
total -= entry.bytes;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
await done(tx);
|
|
154
|
+
},
|
|
155
|
+
async delete(key) {
|
|
156
|
+
const tx = (await database()).transaction([MODULES, ENTRIES], "readwrite");
|
|
157
|
+
tx.objectStore(MODULES).delete(key);
|
|
158
|
+
tx.objectStore(ENTRIES).delete(key);
|
|
159
|
+
await done(tx);
|
|
160
|
+
},
|
|
161
|
+
close() {
|
|
162
|
+
const was = opened;
|
|
163
|
+
opened = null;
|
|
164
|
+
was?.then((db) => db.close()).catch(() => {});
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Run `f` when the page is next idle, or within a second; soon, where there is no requestIdleCallback. */
|
|
170
|
+
function idle(f: () => void): void {
|
|
171
|
+
if (typeof requestIdleCallback === "function") {
|
|
172
|
+
requestIdleCallback(() => f(), { timeout: 1000 });
|
|
173
|
+
} else {
|
|
174
|
+
setTimeout(f, 0);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The database, made if new; rejected if it does not open within `timeout` ms, as when another tab blocks an upgrade. */
|
|
179
|
+
function open(factory: IDBFactory, name: string, timeout: number): Promise<IDBDatabase> {
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
let late = false;
|
|
182
|
+
const timer = setTimeout(() => {
|
|
183
|
+
late = true;
|
|
184
|
+
reject(new Error(`IndexedDB ${name} did not open`));
|
|
185
|
+
}, timeout);
|
|
186
|
+
const opening = factory.open(name, VERSION);
|
|
187
|
+
opening.onupgradeneeded = () => {
|
|
188
|
+
// An older version's modules are another format's: dropped.
|
|
189
|
+
const db = opening.result;
|
|
190
|
+
for (const store of [...db.objectStoreNames]) {
|
|
191
|
+
db.deleteObjectStore(store);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
db.createObjectStore(MODULES);
|
|
195
|
+
db.createObjectStore(ENTRIES, { keyPath: "key" }).createIndex(USED, USED);
|
|
196
|
+
};
|
|
197
|
+
opening.onsuccess = () => {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
// Given up on already, it is closed.
|
|
200
|
+
if (late) {
|
|
201
|
+
opening.result.close();
|
|
202
|
+
} else {
|
|
203
|
+
resolve(opening.result);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
opening.onerror = () => {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
reject(opening.error);
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function request<T>(r: IDBRequest): Promise<T> {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
r.onsuccess = () => resolve(r.result as T);
|
|
216
|
+
r.onerror = () => reject(r.error);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Resolves once `tx` has committed; rejects if it aborts, a quota exceeded say. */
|
|
221
|
+
function done(tx: IDBTransaction): Promise<void> {
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
tx.oncomplete = () => resolve();
|
|
224
|
+
tx.onerror = () => reject(tx.error);
|
|
225
|
+
tx.onabort = () => reject(tx.error ?? new Error("IndexedDB transaction aborted"));
|
|
226
|
+
});
|
|
227
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// A worker_threads Worker running one background flash.system.Worker (node.ts).
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
3
|
+
import { runWorkerThread } from "@swf2es/player/worker";
|
|
4
|
+
|
|
5
|
+
const port = parentPort;
|
|
6
|
+
if (!port) {
|
|
7
|
+
throw new Error("node-worker.js runs only as a worker_threads Worker");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
runWorkerThread({
|
|
11
|
+
post: (message) => port.postMessage(message),
|
|
12
|
+
listen: (receive) => port.on("message", receive),
|
|
13
|
+
});
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Node's TCP transport for flash.net.Socket, and its threads for
|
|
2
|
+
// flash.system.Worker; imported only by hosts that opt in.
|
|
3
|
+
import { connect } from "node:net";
|
|
4
|
+
import { Worker } from "node:worker_threads";
|
|
5
|
+
import type { SocketHost, WorkerHost } from "@swf2es/player";
|
|
6
|
+
import type { ThreadStart } from "@swf2es/player/worker";
|
|
7
|
+
|
|
8
|
+
/** A host that connects ActionScript sockets to TCP directly from Node. */
|
|
9
|
+
export function nodeSocketHost(): SocketHost {
|
|
10
|
+
return {
|
|
11
|
+
connect(host, port, events) {
|
|
12
|
+
const socket = connect({ host, port });
|
|
13
|
+
socket.on("connect", () =>
|
|
14
|
+
events.open({
|
|
15
|
+
localAddress: socket.localAddress ?? "",
|
|
16
|
+
localPort: socket.localPort ?? 0,
|
|
17
|
+
remoteAddress: socket.remoteAddress ?? "",
|
|
18
|
+
remotePort: socket.remotePort ?? 0,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
socket.on("data", (bytes) => events.data(bytes));
|
|
22
|
+
socket.on("close", () => events.close());
|
|
23
|
+
socket.on("error", () => events.error("Error #2031: Socket Error."));
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
// Socket.flush has already combined its pending bytes into one chunk.
|
|
27
|
+
send: (bytes) => socket.write(bytes),
|
|
28
|
+
close: () => socket.destroy(),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Background workers on worker_threads Workers running node-worker.js, given codegen compiled. */
|
|
35
|
+
export function nodeWorkerHost(options: { codegen: WebAssembly.Module }): WorkerHost {
|
|
36
|
+
return {
|
|
37
|
+
start(init, receive, failed) {
|
|
38
|
+
const worker = new Worker(new URL("./node-worker.js", import.meta.url));
|
|
39
|
+
worker.on("message", receive);
|
|
40
|
+
worker.on("error", failed);
|
|
41
|
+
const start: ThreadStart = { codegen: options.codegen, init };
|
|
42
|
+
worker.postMessage(start);
|
|
43
|
+
return {
|
|
44
|
+
post: (message) => worker.postMessage(message),
|
|
45
|
+
terminate: () => worker.terminate(),
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|