Commit Graph

956 Commits

Author SHA1 Message Date
David Wendt 33d26b9149 Shorten `Pin<Box<dyn Future<Output=Result<T,E>> + 'static>>` into `OwnedFuture<T,E>`.
This is technically stricter on `fetch` impls, but right now we can't support non-`'static` futures at all.
2020-02-22 00:02:45 -05:00
David Wendt aab339880d Implement `XML.load()`, with tests.
Interestingly enough, very little actually has to be done inside the async process for XML. The async process basically just fetches data and fires an event handler when it's done. Everything else is handled via a system builtin, `XML.onData`.
2020-02-22 00:02:45 -05:00
David Wendt 538a5f05e5 Add tests for various forms of `loadVariables`.
Surprisingly enough these tests passed without any changes, somehow.
2020-02-22 00:02:43 -05:00
David Wendt c00ecccd1f Basic, stub implementation of `MovieClipLoader.getProgress`, plus test.
This implementation just returns the size of the current loaded movie. The test is also deliberately written to be loose on timings so that it likely won't see a partially loaded movie. (I don't want it to be a test of load events, so I just wait a few frames, rather than the correct way of waiting for `onLoadComplete`.)

Until we support streaming file loads, we can't faithfully support these properties. Still, it's better to have them, just in case.
2020-02-22 00:02:42 -05:00
David Wendt 3f7e3a9ed8 Implement `MovieClipLoader.unloadClip`, with tests. 2020-02-22 00:02:41 -05:00
David Wendt a132226da4 Run `onLoadInit` at the *end* of a frame, rather than before the movie clip's own actions.
This is technically better, but it may make more sense to trigger `ClipEvent::Load` at the start of the next frame instead. Furthermore, I don't know if other forms of load events should trigger on the next frame (or end of the current one) like this.
2020-02-22 00:02:39 -05:00
David Wendt 55734619f7 `GetUrl2` can accept a `DisplayObject` as target in `LoadTargetFlag` mode.
I have no idea what happens to non-MovieClip objects, or if I'm really supposed to `coerce_to_string` here.
2020-02-22 00:02:36 -05:00
David Wendt d49c0e9bf7 Rewrite some of the unload and cliploader tests to be more generous with load timing.
Loads in Flash Player, like all web technologies, are asynchronous tasks of some kind (probably a separate thread). They appear to operate on some kind of a delay. If I `trace` each frame out, like in the previous version of `mcl_loadclip`, you get a series of events that look like this:

1. Parent frame 1
2. Parent frame 2
3. Event: onLoadStart
4. Event: onLoadProgress
5. Event: onLoadComplete
6. Parent frame 3
7. Event: onLoadInit

If I run that version of the test on Ruffle, everything happens after frame 1. This is an artifact of how we're testing asynchronous behavior in Ruffle. In order to guarantee test determinism, we have a dummy implementation of `fetch` that does a blocking load, and we poll all futures every frame of execution. This means that there is a very specific order of execution with these tests, which is good for testing, but probably isn't 100% accurate.

Flash Player appears to delay all loads by at least one frame, even loads that are coming from disk which should load immediately. I don't know if this is intentional or not, so I don't want to implement a load delay just for the sake of making tests pass. Ergo, I'm loosening the tests to just test the ability to load and unload movies, and fire events from a loader.

Specifically:

1. `mcl_loadclip` no longer traces out frames of the parent timeline
2. `unloadmovie` et. all use a target movie that doesn't fail the test until 10 frames have passed.

If someone can find a movie network that breaks with fast loading, then I'll consider implementing explicit frame delays for async tasks. Otherwise, this is how we're testing this.
2020-02-22 00:01:22 -05:00
David Wendt 8ece2d1b31 Add another ignored test, this time measuring the timing of load events broadcasted by `MovieClipLoader`. We're loading too early, which is why this is ignored. 2020-02-22 00:01:20 -05:00
David Wendt b56c3b6aed Fire events directly onto `broadcastMessage` instead of the individual event handlers on the `MovieClipLoader`, so that listeners run correctly.
Also, this fixes a double-borrow for `onClipInit`.
2020-02-22 00:01:19 -05:00
David Wendt 89e5dd97f3 Implement `MovieClipLoader.loadClip` 2020-02-22 00:01:19 -05:00
David Wendt 162b6b70f8 Allow unloading a movie by sending `None` to `replace_with_movie`.
This also adjusts `MovieClip.unloadMovie` to do just that, instead of removing the clip from the display list. We also have to unload clips when loading new movies into them, since `unloadMovie` desugars to loading `""` as the URL.
2020-02-22 00:01:19 -05:00
David Wendt 8ef4a94672 Add new tests for `unloadMovie`, `unloadMovieNum`, and `MovieClip.unloadMovie`.
They currently fail in Ruffle, so they're ignored.
2020-02-22 00:01:18 -05:00
David Wendt cc5dff4254 Add a test for `MovieClip.loadMovie`. 2020-02-22 00:01:17 -05:00
David Wendt 82d305a0f5 Add test for `loadmovienum` 2020-02-22 00:01:16 -05:00
David Wendt a9621da47d Add tests for `loadMovie`.
This test also includes changes to the SWF testing environment to allow asynchronous movie loads to execute.
2020-02-22 00:01:15 -05:00
David Wendt a8545ee277 Implement `onLoadInit` by pulling `LoadManager` into all clip load events. 2020-02-22 00:01:14 -05:00
David Wendt 7ff885a0de Implement `MovieClipLoader` event broadcasts for `onLoadStart`, `onLoadProgress`, `onLoadComplete`, and `onLoadError`.
Note that we do not implement `onLoadInit` yet - this requires some ability to trigger an event when another movie clip loads.
2020-02-22 00:01:14 -05:00
David Wendt db41bec91e Implement `MovieClipLoader`'s `addListener`, `removeListener`, and `broadcastMessage` methods.
Interestingly, this constitutes an implementation of `AsBroadcaster`. It appears Macromedia decided to implement event handling on `MovieClipLoader` in a very similar fashion to `AsBroadcaster`, down to invoking `broadcastMessage` and searching a `_listeners` property for listeners.
2020-02-22 00:01:12 -05:00
David Wendt b7d318a897 Implement `MovieClip.loadMovie`, `MovieClip.loadVariables`, and `MovieClip.unloadMovie`.
*De*implement the free function versions of the above, as well as their `Num` variants, since they don't actually exist as callables. Instead, the ActionScript compiler treats them as preprocessor functions that represent various forms of `ActionGetURL`/`ActionGetURL2`.
2020-02-21 23:59:13 -05:00
David Wendt 31b1364b82 Implement `unloadMovie` / `unloadMovieNum` 2020-02-21 23:58:00 -05:00
David Wendt b2b2a165fc Implement `loadVariables` and `loadVariablesNum`. 2020-02-21 23:58:00 -05:00
David Wendt c7539872f7 Add the ability to POST data from `fetch`, and allow methods that read AVM locals into form data to `GET` or `POST` them. 2020-02-21 23:58:00 -05:00
David Wendt 3fe6884c90 Refactor layer resolution into a separate function.
This function is part of `Avm1`, rather than a hypothetical `LayerManager`, because we're going to need to eventually construct layers differently for AVM2.
2020-02-21 23:57:59 -05:00
David Wendt ea28c2c4a2 Impl `loadMovie` / `loadMovieNum` (sans local variable support) 2020-02-21 23:57:59 -05:00
David Wendt 07637fe676 Replaced movies should start out playing. This fixes a regression from a previous rebase. 2020-02-21 23:57:58 -05:00
David Wendt 64b787b73f Implement `Collect` for `Loader`. (How did this compile without that?) 2020-02-21 23:57:58 -05:00
David Wendt d84e11ed40 Introduce a new top-level object, `LoadManager`, which is responsible for all asynchronous behavior in the program. Migrate the existing async impls to it. 2020-02-21 23:57:58 -05:00
David Wendt 2d7a4fef28 `Sound` methods that reference sounds by library export name should default to `_layer0`'s library if the `Sound` was created without a movie clip target. 2020-02-21 23:57:57 -05:00
David Wendt 6b78ec6e03 More thoroughly clean `MovieClip`s that have movies loaded into them. This does everything except wipe the object it's attached to - I need further testing to see how Flash handles that. 2020-02-21 23:57:57 -05:00
David Wendt 2a82d21966 Change the layer list from a static array to a `BTreeMap`.
Flash allows creating layers at any 31-bit height without issue, so this should support similar limitations.
2020-02-21 23:57:57 -05:00
David Wendt f4e4171ebe Make spawned futures falliable, and report those errors. 2020-02-21 23:57:56 -05:00
David Wendt 5ce499d11e Add separate libraries for each loaded movie. 2020-02-21 23:57:56 -05:00
David Wendt e0c0779bd0 Make sure to preload all loaded clips. 2020-02-21 23:57:55 -05:00
David Wendt 6da374c567 Implement loading movies into `_leveln` via `ActionGetUrl` 2020-02-21 23:57:55 -05:00
David Wendt ed799fd2b9 Split the player up into nine layers, each of which is a separate root movie clip. 2020-02-21 23:57:55 -05:00
David Wendt 8c9d290db7 Implement the MovieClip loading portion of `ActionGetURL2`. 2020-02-21 23:57:54 -05:00
David Wendt 5ed5876e9a Merge SWF data and version into a single structure. Refactor everything that interacts with it to use `SwfSlice`s. 2020-02-21 23:57:53 -05:00
David Wendt 250ec13c12 Implement LoadVariablesFlag.
This has some subtle problems: we cannot hold references to garbage-collected data in Futures, so we have to arrange for the AVM itself to forcibly root them for us. Then we get them back when our async code is ready to do something to the AVM.
2020-02-21 23:44:06 -05:00
David Wendt 55149b7b7e Reference count the Player and provide a weak reference in UpdateContext.
This allows the formation of `'static` futures that can still interact with a player. Async code will need to upgrade the weak reference in order to be able to interact with the player.
2020-02-21 23:44:06 -05:00
David Wendt 491d94c947 Pinbox all Futures.
Due to some strangeness with the way Rust implemented unsafe-to-move behavior, boxed futures are implicitly `Unpin`. Which is useless to us.

The reason for this is a little counter-intuitive. Actually, the fact that Rust supports memory pinning at all is a little odd, because the core language explicitly requires all types be movable. To get around this, Pin requires that all !Unpin types be *born pinned*. This is because you can't re-pin an already unpinned value in memory.

Anyway, this necessitates this silly API change.
2020-02-21 23:44:05 -05:00
David Wendt 00d25a768c Extremely basic impl of fetch/spawn methods for getting data off the web 2020-02-21 23:44:05 -05:00
David Wendt 2137b9f1fd Migrate `set_frame_rate` into the core `AudioBackend` trait 2020-02-21 23:44:05 -05:00
David Wendt c1cf73ccb3 Add a public method to trigger a player update.
User-defined player updates are treated the same as if a stage frame had been run: queued actions are executed and garbage is collected.
2020-02-21 23:44:04 -05:00
Mike Welsh f80c188048 core: Stop stream sounds when a clip is removed 2020-02-21 19:24:45 -08:00
Mike Welsh 6b503ac053 avm1: Fix DefineFunction2 preload order when _parent is undefined
The order is misdocumented in SWF19 (and also miscompiled assuming
this incorrect order by the Flash IDE!).

`_global` gets preloaded before `_parent`.
2020-02-20 12:58:26 -08:00
Mike Welsh dc1f99e2ba tests: Add test for misdocumented DefineFunction2 register preload 2020-02-20 12:58:26 -08:00
Mike Welsh 10fb6c7c04 tests: Add define_function2_preload test 2020-02-19 23:22:33 -08:00
Mike Welsh 19d0bf64a9 avm1: Preload _parent directly from base clip
When `_parent` is preloaded  in a `DefineFunction2` action,
we previously resolve it on the scope chain. This could cause
double borrow panics as the parent object could already be
borrowed, and also this matches the behavior of the official Flash
player.

Addresses #398.
2020-02-19 23:22:33 -08:00
Mike Welsh 8d7e58011e avm1: undefined coerces to "" in SWFv6 and below
Except in the AVM1 trace op, which will print out "undefined".
2020-02-19 10:47:43 -08:00
Mike Welsh dfde98da7d tests: Add tests for coercing undefined to string in SWF6 2020-02-19 10:47:43 -08:00
Mike Welsh 452ac84f0e tests: Uncomment Number.POSITIVE_INFINITY/Number.NEGATIVE_INFINITY tests 2020-02-18 10:17:55 -08:00
Mike Welsh c073afb077 avm1: Use proper value for Number.MIN_VALUE
This is the smallest positive number, not the most negative value.
This is actually the smallest positive subnormal f64, which Rust
does not provide a constant for. This is ~5e-324.
2020-02-18 10:17:55 -08:00
Mike Welsh 6bbe1dbab8 avm1: Match Flash when converting exotic numbers to string (fix #361)
Match Flash's more closely when converting number to string:
 * NAN -> NaN
 * inf -> Infinity
 * -inf -> -Infinity
 * Use exponential notation for very large/very small

This is a little bit of a cheat by using Rust's number-to-string
formatting for exponentials, and shoving a sign in front of the
exponent.
2020-02-18 10:17:55 -08:00
Mike Welsh 324dd1c5e4 tests: Add swf_tests_approx macro
Use this macro to test numeric calculations that might have some
variance using approx_eq.
2020-02-17 15:42:29 -08:00
Mike Welsh b6249cdb73 tests: Add localToGlobal/globalToLocal test 2020-02-17 15:42:29 -08:00
Mike Welsh 2af21d87e0 avm1: Implement MovieClip.localToGlobal/globalToLocal 2020-02-17 15:42:29 -08:00
Mike Welsh cd94486f7e desktop: Fix stream audio from prematurely ending (fix #222) 2020-02-14 20:32:25 -08:00
Mike Welsh 7c406732c7 audio: Ensure stream sounds stop upon goto/loop (fix #370) 2020-02-14 20:32:25 -08:00
Mike Welsh 9ad069e11a avm1: Improve display object property setters for weird values
Setting a property such as _x to undefined or null should have no
effect. This was working for v7+ SWFs because it would coerce to
NaN and we toss out NaNs. But on v6 and below, these coerce to 0
and would end up setting the property to 0.

Explicitly check for undefined/null and bail out. Fixes #380.

Also adjust the _visible setter, since this actually coerces to a
number (because of its legacy from SWFv4). For example,
_visible = "" should have no effect.
2020-02-14 15:34:14 -08:00
Mike Welsh 3a1a73ae11 tests: Add more tests for display object properties
Add more _x = weirdo value tests, and copy the test into a v6 SWF.
(because undefined etc. can coerce to 0 instead of NaN in SWFv6).
2020-02-14 15:34:14 -08:00
Mike Welsh 7d14b98f3b avm1: Ignore undefined values in Color.setTransform
If a property is not set on the object passed to Color.setTransform,
then that channel is left unmodified. This fixes invisible objects
in some games (fixes #369, addresses #380).

Also improve handling of wrapping/invalid values to better match the
behavior in the Flash Player (some work pending on #193).
2020-02-13 18:06:27 -08:00
Mike Welsh 21f117e7bc avm1: Add Value::coerce_to_i16 2020-02-13 18:06:27 -08:00
Mike Welsh 19df074a79 tests: Add more tests for AVM1 Color object
Include not defined values, wrapping values, invalid values.
2020-02-13 18:06:27 -08:00
David Wendt 18516c8eac Pre-strip HTML from HTML tags, rather than skipping them. 2020-02-03 19:32:05 -05:00
David Wendt 7d225f8b55 Fix overflow when shifting `u8`s 2020-02-03 14:46:36 -05:00
David Wendt 3d6b00c1e4 Impl the remaining text layout properties 2020-02-03 14:46:36 -05:00
David Wendt 517e7ce9ff Add word-wrap for `measure_text` and caching for word-wrap calculations 2020-02-03 14:46:36 -05:00
David Wendt 5e808c8cd6 Adjust the wordwrap machinery to work in break points (indicies where new lines start) so we can cache them later 2020-02-03 14:46:35 -05:00
David Wendt fb8664c818 Implement wordWrap and multiline rendering, poorly 2020-02-03 14:46:35 -05:00
David Wendt 7df8eb7674 Impl `is_multiline`'s effect of respecting newlines 2020-02-03 14:46:35 -05:00
David Wendt f95ec777de Also impl storage of the `wordWrap` flag 2020-02-03 14:46:34 -05:00
David Wendt 819757e2b6 Fix text measurement now that the underlying SWF tags are correctly parsed as `Twips`.
Transform coordinates are always in twips, so we have to convert pixels to twips when evaluating the font, and then convert back when measuring.
2020-02-03 14:46:34 -05:00
David Wendt 63b7d172f4 `TextRecord.height` is also in `Twips`.
Notably, the `Text` rendering code does not appear to actually work in pixel scale.
2020-02-03 14:46:34 -05:00
David Wendt fde7715fb8 `EditText.height` is in `Twips` 2020-02-03 14:46:33 -05:00
David Wendt 75022f36d2 Pull `TextFormat` into the `font` module.
Also, since there's a separate function for attaching virtual properties to an AVM1 `TextField` object, let's use that!
2020-02-03 14:46:33 -05:00
David Wendt 4b3660bf2c Impl get/set for `is_multiline`. 2020-02-03 14:46:32 -05:00
David Wendt c1ff1d94d5 Pull the `EditText.evaluateFont` method into `Font`.
`Text` itself doesn't use this method, but it probably could with some changes.
2020-02-03 14:46:32 -05:00
David Wendt 81b7958090 Impl `textWidth` / `textHeight`, although it currently only works well for single-line scenarios. 2020-02-03 14:46:32 -05:00
David Wendt 2181f0d0d0 Impl `getNewTextFormat`/`setNewTextFormat`.
These don't actually do anything yet, because we don't track text spans, nor do we actually use those text spans to alter rendering or text layout.
2020-02-03 14:46:30 -05:00
David Wendt db56217f20 `TextFormat` does *not* coerce `undefined` or `null`; instead those both become `null`. 2020-02-03 14:46:30 -05:00
David Wendt 8449d964ef Implement `TextFormat` as a property bag. 2020-02-03 14:46:29 -05:00
David Wendt 2b0600ab1a Impl `createTextField`. 2020-02-03 14:46:29 -05:00
Mike Welsh 2ff76775e0 core: Empty movie clips can not be used as a mask
When a movie clip or button is used as a mask, the masking will be
disabled if that object has no children; the maskee will be
completely visible. An empty movie clip inside an empty movie clip
successfully masks.

An EditText can also not be used as a masker (although it can be
wrapped inside a movie clip, and then the text successfully masks).

Add a `TDisplayObject::allow_mask` trait method that will
return whether the object can be used as a mask.

This fixes characters not being visible in Dad 'n' Me.
2020-02-01 01:15:31 -08:00
Mike Welsh 2e304a81ef core: Flag as transformed-by-script after swapDepths 2020-01-31 19:44:42 -08:00
Mike Welsh a55a378a73 avm1: Improve comments in MovieClip depth methods 2020-01-31 19:44:42 -08:00
Mike Welsh 4d1f7c4d4a tests: Add movieclip depth method tests 2020-01-31 19:44:42 -08:00
Mike Welsh a4e175a790 avm1: Implement MovieClip.getNextHighestDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 4d12cd1566 avm1: Implement MovieClip.getDepth 2020-01-31 19:44:42 -08:00
Mike Welsh 9e337ede34 avm1: Implement MovieClip.swapDepths 2020-01-31 19:44:42 -08:00
dependabot-preview[bot] 2f98fd1a0e build(deps-dev): bump webpack-dev-server in /web/selfhosted
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 3.10.1 to 3.10.2.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v3.10.1...v3.10.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-31 19:44:42 -08:00
Mike Welsh 0d91fb423e core: Goto only runs if frame is an integer 2020-01-30 15:17:01 -08:00
Mike Welsh c079cb3bca core: Don't run frame actions when seeking past end of timeline
If you goto past the final loaded frame of a timeline, for example,
with gotoAndStop(9999), this seeks to the final frame on the
timeline, but it doesn't run the actions on this frame.

MovieClip::goto_frame now will not run the final frame actions if
the target frame was not reached.
2020-01-30 15:17:01 -08:00
Mike Welsh 8aae07bbf3 core: Frame labels are case insensitive 2020-01-30 15:17:01 -08:00
Mike Welsh a835573f3c tests: Add test for global GotoFrame action 2020-01-30 15:17:01 -08:00
Mike Welsh 62467bb880 avm1: Handle invalid parameters in GotoFrame2
Use the same code path for the global GotoFrame2 action and
MovieClip.gotoAndX, which properly handles out-of-range and invalid
values like NaN.

Fixes Disorderly hanging on game start
(https://www.newgrounds.com/portal/view/121896)
2020-01-30 15:17:01 -08:00
David Wendt a57d0e12b3 Do not apply a color filter at all unless rendering a bitmap or gradient.
This significantly improves render times, as browsers appear to apply filters in the most general, inefficient way possible.
2020-01-29 14:19:18 -05:00
dependabot-preview[bot] dc8858505d build(deps): bump smallvec from 1.1.0 to 1.2.0
Bumps [smallvec](https://github.com/servo/rust-smallvec) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/servo/rust-smallvec/releases)
- [Commits](https://github.com/servo/rust-smallvec/compare/v1.1.0...v1.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-29 18:42:28 +00:00
Mike Welsh 003cc414aa core: Create clips in execution order during a goto
The list of goto commands is now a Vec that will already be in order
of creation. This ensures that subsequent ActionScript in these clips
runs in the correct order.
2020-01-28 04:15:08 -08:00
Mike Welsh 81a1c05682 tests: Add goto_execution_order2 regression test
Tests execution order of children added during a goto.
2020-01-28 04:15:08 -08:00
Mike Welsh 7532e89aff avm1: Use `resolve_target_display_object` in `Color`
Fixes the boss damage blinking in Alien Hominid. Target was a path
string.
2020-01-27 23:35:41 -08:00
Mike Welsh 69f19f03c4 avm1: Output trace warning for invalid SetTarget (fix #332) 2020-01-27 23:35:41 -08:00
Mike Welsh a0032b9aa1 avm1: Better handling of movie clip paths strings (fix #317)
Ops and functions that take a movie clip path in String form have
a very forgiving syntax. These include:
 * `SetTarget`
 * `CloneSprite`
 * `RemoveSprite`
 * `swapDepths`

This change adds `Avm1::resolve_target_display_object` to parse
these paths correctly, along with `target_paths` test to test a
wide variety of formats.

This also applies to `GetVariable`/`SetVariable`, which accept
target paths to variables and is used by some SWF4/5 content.
(fixes #324, #337).
2020-01-27 23:35:41 -08:00
Mike Welsh 2751b89d4e avm1: Root clip should not have a name
Previously we set the name of the root clip to `_level0`. Top-level
clips should actually have no name (`_root._name` returns `""`).

However, when constructing a dot path, `_level0` still gets inserted
by `DisplayObject::path` for the top-level, so that `trace(_root)`
still correctly prints `_level0`.

TODO: When `loadMovieNum` gets merged in, the proper level # needs
to be returned by `.DisplayObject::path`.
2020-01-27 23:35:41 -08:00
Mike Welsh 0446644742 tests: Add target_path test 2020-01-27 23:35:41 -08:00
David Wendt db51ec9e3c Implement a separate `Object` impl for functions that holds an `Executable`. 2020-01-27 21:57:32 -05:00
David Wendt 8eeb9a5c60 This technically isn't a test of `toString`, so remove stuff from the test that it relies upon. 2020-01-27 21:50:11 -05:00
David Wendt d217f51c6c Don't crash if `Function.prototype.call` is called without arguments. 2020-01-27 21:50:10 -05:00
David Wendt 0470b8d0a7 Add a test for `Function.call` and `Function.apply` 2020-01-27 21:50:10 -05:00
David Wendt 2c0d892154 Implement Function.call/apply 2020-01-27 21:50:09 -05:00
Mike Welsh 4b7bac706b avm1: ActionNewMethod supports auto-boxing values
This allows `new ("FOO".bar)()`, although there is probably no
good reason to do this. :-)
2020-01-21 18:24:49 -08:00
Mike Welsh 70bec9437f tests: Boolean() returns undefined 2020-01-21 18:24:49 -08:00
Mike Welsh d9e7a6a960 avm1: Implement Boolean class 2020-01-21 18:24:49 -08:00
Mike Welsh e71099edd5 tests: Add primitive_type_globals test 2020-01-21 18:24:49 -08:00
Mike Welsh 8263d13fd0 avm1: Implement Number class 2020-01-21 18:24:49 -08:00
Mike Welsh b49357e46f avm1: Boxing a value calls the object constructor 2020-01-21 18:24:49 -08:00
Mike Welsh ccf62979a1 avm1: Implement String methods 2020-01-21 18:24:49 -08:00
Mike Welsh 5f12ce78b6 tests: Add string method tests 2020-01-21 18:24:49 -08:00
David Wendt 2f9d50cdb8 Very rudimentary/basic/not-good implementation of `String`, plus auto-boxing for primitive strings getting their methods taken. 2020-01-21 18:24:49 -08:00
David Wendt 4d1e49882b Add another object class for boxed primitive values, because the language demands it. 2020-01-21 18:24:49 -08:00
Mike Welsh 13b4cd4c1b avm1: Add Value::coerce_to_i32/u32/u16 methods
Add these methods that will explicilty coerce a value to an int,
following the wrapping behavior in the ECMAScript specs (ToInt32,
ToUInt32, ToUInt16).

This also fixed an off-by-one error for negative numbers in the
previous implementation.

These will call `valueOf` if necessary. AVM code that requires an
integer will probably use one of these (`coerce_to_i32` usually).
2020-01-20 13:28:27 -08:00
dependabot-preview[bot] 87e96212e4 build(deps): bump syn from 1.0.13 to 1.0.14
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.13 to 1.0.14.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.13...1.0.14)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-20 18:56:56 +00:00
Nathan Adams 4ad6ef8b83 core: Implemented Key.getCode() 2020-01-17 15:11:38 -08:00
Nathan Adams adceceed5d avm1: Removed redundant double registration of Key 2020-01-17 15:11:38 -08:00
Nathan Adams cef7d3eba2 avm1: Implement Key constants 2020-01-17 15:11:38 -08:00
Mike Welsh 8cb4278903 tests: Use pretty_assertions for nice output on test fail 2020-01-17 13:54:39 -08:00
Mike Welsh cf7a564f2c core: Fix properties not resetting in goto when rewinding
Properties of a display object would not reset when rewinding if
it existed in both the initial and final frames of the goto.
This fixes the weapons toggles in UFA.
2020-01-16 09:58:33 -08:00
Mike Welsh 8448fc80ef avm1: Don't panic when calling ActionRandom with <= 0 2020-01-14 00:05:13 -08:00
Mike Welsh 4eef8a1821 tests: Add test for ActionCall 2020-01-14 00:04:11 -08:00
Mike Welsh 2d3801dac8 avm1: Implement ActionCall opcode 2020-01-14 00:04:11 -08:00
Nathan Adams fdf1d38d21 avm1: Implement remainder of Math 2020-01-13 15:57:56 -08:00
dependabot-preview[bot] 6c2f5143b3 build(deps): bump rand from 0.7.2 to 0.7.3
Bumps [rand](https://github.com/rust-random/rand) from 0.7.2 to 0.7.3.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-13 18:38:15 +00:00
Mike Welsh 001a931afe avm1: Avm1::pop should always succeed
Don't return a Result from `pop`. Instead, emit a warning and
return Undefined if there is an underflow.
2020-01-07 15:59:14 -08:00
Mike Welsh 170813ffbf audio: Assume little endian for PCM unknown endian sounds 2020-01-07 02:40:09 -08:00
Mike Welsh a28e97d8c3 avm1: Don't push returns from non-function stack frames 2020-01-06 20:49:05 -08:00
Mike Welsh 7e05da6147 avm1: Fix issues with traversing the scope chain in SetVariable
When setting a variable in a function-local scope, if that variable
has not been defined in the function scope, it should be defined in
the executing movieclip's scope. Previously it would get defined
in the function's scope. Changed Scope::overwrite to Scope::set,
and modified the behavior to stop traversing and define the value
when it hits a movie clip Target scope.

Also, modified With scopes to properly add onto the end of the scope
chain.
2020-01-06 20:49:05 -08:00
Mike Welsh a60fadf0bb tests: Add test for correct scope in SetVariable 2020-01-06 20:49:05 -08:00
David Wendt 0d1d0e8de7 Don't bother preserving the `Cow`ness of unescaped strings when we're going to clone them anyway. 2020-01-05 00:31:45 -05:00
David Wendt 7957434036 This is a copy type, copy it 2020-01-05 00:24:31 -05:00
David Wendt f8b5b8a032 Use `unwrap_or_default` where available 2020-01-05 00:22:36 -05:00
David Wendt ef7c5d7eb9 Move XML properties to separate functions rather than closures 2020-01-05 00:17:57 -05:00
David Wendt 14dba0d100 Log errors encountered when removing the children of a node we plan to parse XML into.
Also, remove a handful of unnecessary `#[allow(unused_must_use)]` instances.
2020-01-05 00:04:45 -05:00
David Wendt 464563a703 Change the no-double-introduction warning into a proper `assert!`. Add doc warning about the panic. 2020-01-05 00:00:29 -05:00
David Wendt 750e6e4370 Replace bare number constants for XML errors with symbolic `const` values 2020-01-04 23:56:10 -05:00
David Wendt fd541fabea Implement `status`.
I'm not entirely sure how to test this one - the list of errors that Flash kicks out for XML and the list of errors that `quick_xml` kicks out don't line up at all; so I just ensured that any error is a negative number (currently the one for OOM errors) and stuck whatever errors *did* match up together.

Consequently I don't know entirely *how* to write tests for this.
2020-01-04 19:00:49 -05:00
David Wendt fec95dd226 Add regression test for `idMap`. 2020-01-04 19:00:49 -05:00
David Wendt f3226537bf Implement `idMap`.
`idMap` is a strange property; it's only populated with nodes which had a given `id` *at the time of parsing*, and said nodes continue to be referenced even if the node is removed from the document. I have yet to find a way by which nodes can be deleted from `idMap`.

It also takes expandos, so this has to be a new retained object on the XML document. I originally considered not creating *another* `Object` impl and populating a regular `ScriptObject` with nodes, but that meant we couldn't lazy-instantiate their AVM1 side counterparts. Boo. :/
2020-01-04 19:00:48 -05:00
David Wendt 1722558d44 Add test for `XML.parseXML` 2020-01-04 19:00:47 -05:00
David Wendt 823e8602ff Impl `XML.parseXML` 2020-01-04 19:00:46 -05:00
David Wendt d00ef01965 Add a convenience method: `XMLNode.into_string` 2020-01-04 19:00:46 -05:00
David Wendt b4b722e1d6 Add another test for AVM1 XML's failure to roundtrip unsupported node types (e.g. comments). 2020-01-04 19:00:45 -05:00
David Wendt 2c790f1d41 Filter non-AS2 compatible nodes from toString output, and add non-SWF tests for XML filtering. 2020-01-04 19:00:45 -05:00
David Wendt ce1b958abb Add some more tests for XML namespace URIs. 2020-01-04 19:00:45 -05:00
David Wendt e2fa685d41 Fix tagname parsing.
There is a bug in `quick_xml` - or at least, I *think* it's a bug - where the `unescaped` method of `BytesStart` yields a bunch of attributes if you have slightly invalid crap in your tag like `xmlns:`. To work around it, I turned off unescaping; we're instead using `name` and ignoring unescaping. This will probably fail somewhere.
2020-01-04 19:00:44 -05:00
David Wendt e1034fce31 clippy compliance 2020-01-04 19:00:44 -05:00
David Wendt 7ac3204759 format prev commit 2020-01-04 19:00:43 -05:00
David Wendt d2aa3dd987 Add a test for `createElement` and `createTextNode`. 2020-01-04 19:00:43 -05:00
David Wendt db38982ffb For some reason, text nodes have an attributes object. 2020-01-04 19:00:42 -05:00
David Wendt 91155d6870 Text nodes have empty arrays for `childNodes` rather than being `undefined`. 2020-01-04 19:00:42 -05:00
David Wendt d28094a019 Implement `createElement` and `createTextNode`. 2020-01-04 19:00:42 -05:00
David Wendt 97bcb6b2dc Add an ignored test for `xmlDecl`.
Test is currently ignored because AS2 XML currently handles XML declarations in ways not compatible with our current parser. Investigating hacky ways around this.
2020-01-04 19:00:41 -05:00
David Wendt c02da74afa Expose the `<?xml ?>` declaration to ActionScript.
I can't write proper tests for this because our underlying XML parsing technology doesn't let us do what AS2 XML does: just copy the first xml tag out of the document and into a string. No, seriously, anything at the start of the parsed XML that starts with `<?xml` and ends with `?>` gets copied into Flash's moral equivalent of `xml::Document` as a string. We parse the whole thing, which is wrong, so we'll need to additionally retain the original xmldecl string in order to pass the test I wrote for this.
2020-01-04 19:00:41 -05:00
David Wendt ce0546fc2c Add test for `docTypeDecl`. 2020-01-04 19:00:40 -05:00
David Wendt a7a349b02b Expose `docTypeDecl` to ActionScript.
This also involves storing the `DocType` node on the document object and retrieving it later.
2020-01-04 19:00:40 -05:00
David Wendt a80aab1b08 Document roots can store an attributes object, even though they don't have attributes 2020-01-04 19:00:40 -05:00
David Wendt 6a472d32bb Filter incompatible nodes from the sibling and child lists. 2020-01-04 19:00:39 -05:00
David Wendt fd14d0c9df Doctype nodes should be represented as text nodes to ActionScript (if they somehow grab hold of them) 2020-01-04 19:00:38 -05:00
David Wendt 6b4bbee195 Create and store `DocType` nodes on the tree when we encounter a `<!DOCTYPE...>` tag. 2020-01-04 19:00:38 -05:00
David Wendt aa749dc1b0 Store the XML document version, encoding, and standalone flags. 2020-01-04 19:00:38 -05:00
David Wendt a869107480 The `DocumentRoot` node type should have it's own node type ID, and AS2 XML should filter it out. This also filters out comment nodes as text, which isn't technically wrong but we should do better 2020-01-04 19:00:37 -05:00
David Wendt 7965045d87 Add test for XMLNode.toString. 2020-01-04 19:00:37 -05:00
David Wendt 673f85f067 XMLNode type 1 is an element, not a text node. 2020-01-04 19:00:36 -05:00
David Wendt 88aa5f8004 Add extra whitespace to empty tags. 2020-01-04 19:00:36 -05:00
David Wendt 0c7a1fe667 Text and comment nodes are stored plain and must be escaped for XML 2020-01-04 19:00:36 -05:00
David Wendt c7e1f34a5d Print empty nodes as empty tags rather than start/end 2020-01-04 19:00:35 -05:00
David Wendt c76e5ce447 appendChild also refuses to orphan nodes already part of another XML tree. 2020-01-04 19:00:35 -05:00
David Wendt bff851e6a4 Add test for insertBefore 2020-01-04 19:00:34 -05:00
David Wendt 34cbe2e04b insertNode rejects child nodes that already have a parent 2020-01-04 19:00:34 -05:00
David Wendt 7b4a509ebc Avoid double-borrows when moving a child within it's parent 2020-01-04 19:00:33 -05:00
David Wendt 7753e20fe3 Add a test for XML.removeNode(). 2020-01-04 19:00:33 -05:00
David Wendt 30266b2ce7 remove_child should also ensure the child disowns the parent. 2020-01-04 19:00:33 -05:00
David Wendt 8c5dcfe662 Swap in newly constructed nodes *before* filling them with content.
Fixes a bug where new XML("<node />").childNode[0].parentNode did NOT refer to the overall document object, but to a phantom text node.

This is because the swap operation used to construct an XMLObject's node in-place was happening AFTER parsing, which means that referents already existed to the temporary XMLNode created by XMLObject::new. swap is not to be called after tree structure has been created; it does not update referents to the swapped nodes.

In the future I should examine the implications of explicitly reconstructing already existing nodes, e.g. through XML.apply(some_xml). Right now, the existing node will be swapped with a new one, and two nodes will exist pointing to the same script object, which is a huge problem with our overall design. We should, at the very least, disassociate swapped nodes from their script object, just in case they still have referents.

Ideally, we wouldn't have to swap nodes, but to avoid a swap, I'd have to instead have a second layer of indirection just to hold a rewritable pointer that every XMLObject points to. This isn't really worth it unless I HAVE to do it, so I'm not going to do it.
2020-01-04 19:00:32 -05:00
David Wendt 568d90f4dc Warn if XML.removeNode fails for whatever reason 2020-01-04 19:00:32 -05:00
David Wendt 1577f51730 Expose elided objects as pointers when debugging XML nodes 2020-01-04 19:00:32 -05:00
David Wendt 19ca11b08c Impl `toString` 2020-01-04 19:00:31 -05:00
David Wendt 513460e4e0 Implement `insertBefore` 2020-01-04 19:00:31 -05:00
David Wendt b0dce445b0 Impl `removeNode` 2020-01-04 19:00:29 -05:00
David Wendt 00319f14a8 Implement `namespaceURI` 2020-01-04 19:00:29 -05:00
David Wendt 73da72db98 Add a test for `appendChild`. 2020-01-04 19:00:28 -05:00
David Wendt 7c95eff048 Flag an error if we accidentally introduce a second script object by accident. 2020-01-04 19:00:28 -05:00
David Wendt abb2690367 When constructing new XML nodes or documents, always ensure that the new node we swap in is properly linked to the same script object so that we don't accidentally recreate them. 2020-01-04 19:00:28 -05:00
David Wendt 8939dae90c Implement `XMLNode.attributes` w/ read tests 2020-01-04 19:00:27 -05:00
David Wendt 6f48f3436f Expose `previousSibling` and `nextSibling` to ActionScript.
This commit also fixes a bug caused by excessive use of copypaste, which was detected by the included test.
2020-01-04 19:00:25 -05:00
David Wendt 223320c98c Expose `parentNode` to ActionScript 2020-01-04 19:00:24 -05:00
David Wendt 807725d7aa Expose `firstChild` and `lastChild` to ActionScript w/ tests 2020-01-04 19:00:24 -05:00
David Wendt 1d1e493e0e Refactor the child adoption process to ensure the child also adopts it's siblings. 2020-01-04 19:00:23 -05:00
David Wendt 48d68bebc4 Implement `hasChildNodes()` and add test 2020-01-04 19:00:23 -05:00
David Wendt c58e866236 Add test for `cloneNode` 2020-01-04 19:00:22 -05:00
David Wendt 881dcb76ab `cloneNode` without arguments is morally equivalent to `false` 2020-01-04 19:00:21 -05:00
David Wendt 8e33566d07 Add namespacing test 2020-01-04 19:00:21 -05:00
David Wendt 69a1ab1649 Expose namespace prefix and URI lookups to ActionScript.
Also, fix the previous commit's half-assed impl.
2020-01-04 19:00:20 -05:00
David Wendt fe7d2b5173 Extremely WIP impl of `lookup_uri_for_namespace` 2020-01-04 19:00:20 -05:00
David Wendt 55fa6ef09b Add node cloning support 2020-01-04 19:00:19 -05:00
David Wendt 37f6efb753 Expose `appendChild` to ActionScript 2020-01-04 19:00:19 -05:00
David Wendt 08c0f273a6 Add sibling links to nodes. 2020-01-04 19:00:18 -05:00
David Wendt 7e45dee8cf Clippy said so. 2020-01-04 19:00:18 -05:00
David Wendt eec449422b `XMLDocument.roots` is not necessary since you can just get the children of it's node form anyway... 2020-01-04 19:00:18 -05:00
David Wendt f8f569440f Add very basic XML test 2020-01-04 19:00:17 -05:00
David Wendt cfacd397cf Most XML properties return `null`, not `undefined`.
Furthermore, `prefix` does not distinguish between `<test>` and `<:test>` - they both have a `prefix` of `""`.
2020-01-04 19:00:17 -05:00
David Wendt b491dd034e Don't overflow stack when debug-printing an entire document, either. 2020-01-04 19:00:16 -05:00
David Wendt e47a1d1e38 Fix newly constructed XML trees not actually containing the XML they just parsed. 2020-01-04 19:00:16 -05:00
David Wendt 960e4dad90 Don't cause stack overflow when debug-printing XML nodes. 2020-01-04 19:00:16 -05:00
David Wendt bec60acc1e `XML.prototype` should be an `XMLObject` so that instances of `XML` can hold a node 2020-01-04 19:00:15 -05:00
David Wendt d058c83ac0 Document roots should accept children. 2020-01-04 19:00:15 -05:00
David Wendt 571c4bbd52 Cargo fmt compliance 2020-01-04 19:00:15 -05:00
David Wendt 0af248d81f Expose `childNodes` to ActionScript 2020-01-04 19:00:14 -05:00
David Wendt e7768d0802 Add methods to allow storing XML objects on the accompanying tree nodes, so that expando properties on child nodes will work. 2020-01-04 19:00:13 -05:00
David Wendt b06dd5d15e Add a special node to represent the document root in the node tree, and get rid of the explicit document reference type in `XMLObject`. 2020-01-04 19:00:12 -05:00
David Wendt 0fe0e4fe90 Separate `XMLName` into another module 2020-01-04 19:00:11 -05:00
David Wendt 3928c7cc51 Reject empty text nodes 2020-01-04 19:00:11 -05:00
David Wendt 7a9a16e598 Don't repeat yourself. 2020-01-04 19:00:11 -05:00
David Wendt bd1ea56cc3 Implement `XMLNode` properties that don't require child or attribute iteration. 2020-01-04 19:00:10 -05:00
David Wendt e2eb3d0bde Add a test of XMLDocument::from_str.
This test technically works, but the results were slightly surprising. If it turns out Flash works differently from `quick_xml`, we'll change this test to match Flash.
2020-01-04 19:00:10 -05:00
David Wendt 6ae5ae3038 Add Comment parsing support 2020-01-04 19:00:10 -05:00
David Wendt 4f5ac09b73 Expose XML document constructor, including text parsing ability 2020-01-04 19:00:09 -05:00
David Wendt 554f0dc1e5 Add XMLNode class and constructor impl 2020-01-04 19:00:07 -05:00
David Wendt 6a65e984ae Add a new `XMLObject` variant to the AVM1 object ecosystem.
This particular variant is actually a two-in-one deal: `XMLObject`s may either refer to a document or a node.
2020-01-04 18:58:42 -05:00
David Wendt 89c9753520 Add rudimentary custom DOM impl on top of `quick_xml`.
`quick_xml` was chosen due to it's high performance and support for zero-copy use cases. However, we are not using `minidom`, which is the already-extant DOM impl that uses `quick_xml` as it's parsing provider. This is because `minidom` nodes are not amenable to garbage collection.

Specifically: we want to be able to construct a new `Object` variant that holds part of an XML node. However, `minidom::Element` directly owns it's children, meaning that we can't hold references to it from within `Object` while also keeping those objects to the `'gc` lifetime. Hence, we provide a GC-exclusive DOM implementation.

I ruled out solutions such as holding an entire XML tree in an `Rc` and having AVM objects that shadow them. This works for `SwfSlice` because indexing an array is cheap; but traversing a tree can get very expensive. XML is used in many places in Flash Player, so it's important that we treat it like a first-class citizen.
2020-01-04 18:48:17 -05:00
Mike Welsh 4ce67535b0 tests: Add test for Color 2020-01-03 20:31:32 -08:00
Mike Welsh 36b3e5b34f avm1: Implement Color class 2020-01-03 20:31:32 -08:00
Mike Welsh 4bf29f677f avm1: Implement Sound.duration
Add AudioBackend::get_sound_duration.
2020-01-03 17:11:00 -08:00
Mike Welsh b9d24d9a49 avm1: First pass at implementing Sound.stop 2020-01-03 17:11:00 -08:00
Mike Welsh d0142f1d67 audio: Add AudioBackend::stop_sound 2020-01-03 17:11:00 -08:00
Mike Welsh 63dd92259b avm1: First pass of Sound object 2020-01-03 17:11:00 -08:00
dependabot-preview[bot] a01e5b7854 build(deps): bump syn from 1.0.12 to 1.0.13
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.12 to 1.0.13.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.12...1.0.13)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 19:15:37 +00:00
dependabot-preview[bot] b4a47e17da build(deps): bump generational-arena from 0.2.6 to 0.2.7
Bumps [generational-arena](https://github.com/fitzgen/generational-arena) from 0.2.6 to 0.2.7.
- [Release notes](https://github.com/fitzgen/generational-arena/releases)
- [Changelog](https://github.com/fitzgen/generational-arena/blob/master/CHANGELOG.md)
- [Commits](https://github.com/fitzgen/generational-arena/compare/0.2.6...0.2.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 19:14:43 +00:00
dependabot-preview[bot] 1048170235 build(deps): bump syn from 1.0.11 to 1.0.12
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.11 to 1.0.12.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.11...1.0.12)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 08:24:29 +00:00
Mike Welsh 87158647d1 core: Implement keyPress button events 2019-12-24 03:06:03 -08:00
Mike Welsh 2f0963fa6c core: Fix button action with multiple conditions not firing (fix #195)
If a button event had both a keyPress condition and another
condition:

on(release, keyPress "A") { }

these actions would not fire on click, because it would still
check if the key was down (which doesn't apply to clicks!)

Fixes #195.
2019-12-22 15:55:03 -08:00
Nathan Adams 9000451d58 core: Implemented Mouse.show() & Mouse.hide() 2019-12-22 14:33:46 -08:00
Mike Welsh 4cdeec5b64 avm1: Fix number coercion in arithmetic ops
A lot of the arithmetic ops were still using SWFv4 style coercion
(`Value::into_number_v1`) even though they use full ECMA-262
coercion in SWF5+. This would cause `undefined` to turn into 0
isntead of NaN, for example.

Fixes disappearing player in Achievement Unlocked
(https://www.newgrounds.com/portal/view/474371)

It's possible even the older ops such as ActionAdd should do this,
too. Handcrafted bytecode will need to be used to test as you
cannot export these ops in newer SWF versions from the Flash IDE.
2019-12-22 03:01:58 -08:00
Mike Welsh c9e0bdeaf5 core: GC trace Button::object 2019-12-21 23:54:50 -08:00
Mike Welsh 1d8ae9154b tests: Add tests for AVM1 logical ops 2019-12-21 23:01:10 -08:00
Mike Welsh a4a307cf9a avm1: Use proper bool conversions for logical ops
ActionAnd, ActionOr, and ActionNot were incorrectly comparing
to 0. This only works for SWF<4. Now they all go through the
Value::as_bool method to handle version specific behavior.

Value::from_bool_v1 was also renamed to Value::from_bool.
2019-12-21 23:01:10 -08:00
Mike Welsh 00fdc74f1f tests: Add test for property updating in fast-forward gotos 2019-12-21 21:16:27 -08:00
Mike Welsh fd92bd5f78 core: Fix PlaceObject modifications in fast-forward gotos
When fast-forwarding with a goto, modifications were not taking
effect to objects that exist both in the starting and the final
frame.
2019-12-21 21:16:27 -08:00
Nathan Adams eedc4bbe24 core: Added Input backend, currently unimplemented, for polling user input 2019-12-21 19:08:06 -08:00
Nathan Adams 6c484fe29d core: Changed KeyCode into an enum that maps out every Flash key code 2019-12-21 19:08:06 -08:00
Mike Welsh d7df15989f core: Clear drag if object is removed while dragging 2019-12-21 16:28:41 -08:00
Mike Welsh 531e4d640d avm1: Implement StartDrag/EndDrag 2019-12-21 16:28:41 -08:00