Commit Graph

3907 Commits

Author SHA1 Message Date
Aaron Hill 0cd6d13783
avm2: Stub ContextMenu.builtInItems (#7652) 2022-08-18 20:50:42 -04:00
Mike Welsh 7a53322cbb avm1: Wire up Button.blendMode 2022-08-18 16:38:17 -07:00
Mike Welsh 1e389112a1 avm1: Wire up MovieClip.blendMode 2022-08-18 16:38:17 -07:00
Mike Welsh b450b99e3e avm2: Wire up DisplayObject.blendMode 2022-08-18 16:38:17 -07:00
Mike Welsh 2e83bb570d core: Warn when setting a blend mode 2022-08-18 16:38:17 -07:00
Mike Welsh 7aee05cf75 core: Apply blend mode from PlaceObject tags
* Set blend mode in `DisplayObject::apply_place_object`.
 * Change `DisplayObject::set_blend_mode` to take `&self`.
2022-08-18 16:38:17 -07:00
Aaron Hill f7205a02a9 render: Add BlendMode infrastructure and implement BlendMode.ADD
Each render backend keeps track of a stack of BlenModes,
which are pushed and popped by 'core' as we render objects
in the displaay tree. For now, I've just implemented BlendMode.ADD,
which maps directly onto blend mode supported by each backend.

All other blend modes (besides 'NORMAL') will produce a warning
when we try to render using them. This may produce a very large amount
of log output, but it's simpler than emitting each warning only once,
and will help to point developers in the right direction when they
get otherwise inexplicable rendering issues (due to a blend mode
not being implemented).

The wgpu implementation is by far the most complicated, as we need
to construct a `RenderPipeline` for each possible
`(BlendMode, MaskState)`. I haven't been able to find any documentation
about the maximum supported number of (simultaneous) WebGPU render
pipelines - if this becomes an issue, we may need to register them
on-demand when a particular blend mode is requested.
2022-08-18 16:38:17 -07:00
Aaron Hill 1e18fc2227 avm2: Convert filters to ActionScript
We still don't implement the actual filter logic for `DisplayObject`,
but the classes themselves are fully implemented.
2022-08-17 12:55:03 -07:00
dowgird 038264a7a9 avm2: Implement stageFocusRect stub 2022-08-16 13:59:12 -05:00
relrelb 4d8e4111e3 core: Remove `AvmType`
Simply use `is_action_script_3()` instead.
2022-08-16 13:04:02 +03:00
Aaron Hill 6f20e8882d avm2: Implement DisplayObject.transform and most of Transform
This PR implements the 'DisplayObject.transform' getters/setters,
and most of the getters/setters in the `Transform` class

From testing in FP, it appears that each call to the
'DisplayObject.transform' property produces a new
'Transform' instance, which is permanently tied to the
owner 'DisplayObject'. All of the getters/setters in
`Transform` operate directly on owner `DisplayObject`.
However, note that the `Matrix` and `ColorTransform`
valuse *produced* the getter are plain ActionScript objects,
and have no further tie to the `DisplayObject`.

Using the `DisplayObject.transform` setter results in
values being *copied* from the input `Transform` object.
The input object retains its original owner `DisplayObject`.

Not implemented:
* Transform.concatenatedColorTransform
* Transform.pixelBounds

When a DisplayObject is not a descendant of the stage,
the `concatenatedMatrix` property produces a bizarre matrix:
a scale matrix that the depends on the global state quality.
Any DisplayObject that *is* a descendant of the stage has
a `concatenatedMatrix` that does not depend on the stage quality.
I'm not sure why the behavior occurs - for now, I just manually
mimic the values prdduced by FP. However, these values may indicate
that we need to do some internal scaling based on stage quality values,
and then 'undo' this in certain circumstances when constructing
an ActionScript matrix.

Unfortunately, some of the computed 'concatenatedMatrix' values
are off by f32::EPSILON. This is likely due to us storing some
internal values in pixels rather than twips (the rounding introduced
by round-trip twips conversions could cause this slight difference0.
For now, I've opted to mark these tests as 'approximate'.

To support this, I've extended our test framework to support providing
a regex that matches floating-point values in the output. This allows
us to print out 'Matrix.toString()' and still perform approximate
comparisons between strings of the format
'(a=0, b=0, c=0, d=0, tx=0, ty=0)'
2022-08-14 19:12:25 -07:00
Nathan Adams 824b4aa8d1 render: Moved render backend from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams 760da753fb render: Moved Transform from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams f088d8ac3a render: Moved color_transform from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams 35082b687f render: Moved shape_utils from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams b3afb59b53 render: Moved BoundingBox from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams 91a7047ebb render: Moved Matrix from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams 9fd8fd938e render: Moved render utils from core to render 2022-08-14 18:38:14 -07:00
Nathan Adams bc0c7cbccb render: Made new render crate, moved Bitmap stuff to it 2022-08-14 18:38:14 -07:00
Nathan Adams 94282dfe73 core: Moved render utils into own module 2022-08-14 18:38:14 -07:00
Nathan Adams 0bb14193c6 core: Moved Bitmap into its own module for refactoring rendering 2022-08-14 18:38:14 -07:00
Nathan Adams beab50cde7 core: Moved NullRenderer into its own module in preparation for refactoring 2022-08-14 18:38:14 -07:00
relrelb d70697b4f3 web: Refactor `WebNavigatorBackend`
Store `base_url` as `Option<Url>` instead of `Option<String>`, so
we don't need to parse it on each URL resolve.
2022-08-14 17:49:05 -07:00
Aaron Hill a99c7e381b avm2: Improve `Debug` impl for `StageObject`
This builds off of the previous work for `ScriptObject` and
`ClassObject`. We now print both the class name and the stored
`DisplayObject`.
2022-08-14 15:31:53 -05:00
Aaron Hill d6532c87c2 avm2: Stub TimerEvent.updateAfterEvent
This is the last stub needed for Wonderputt to reach the
main game screen.

As far as I know, ActionScript cannot observe a frame being rendered,
so implementing this method isn't actually necessary for correctness.

The benefit of implementing this would be to make certain animations
appear smoother, since we'll render changes to the scene without
needing to wait for the next frame. However, actually rendering
*immediately* after the event would require some refactoring -
we have a `&mut UpdateContext` while running timers, but we'd need
to bail out and obtain a `&mut Player`.
2022-08-13 19:24:56 +02:00
Aaron Hill ef4a955e65 avm2: Always get loaderInfo from the root object 2022-08-13 02:06:38 -07:00
relrelb 8a7e96b0d5 avm2: Split `names.rs`
Into `namespace.rs`, `multiname.rs` and `qname.rs`, for better code
organization.
2022-08-13 02:12:53 +03:00
Nathan Adams 7dff19b559 core: Use a fixed seed when using deterministic feature 2022-08-12 13:11:46 +03:00
Aaron Hill 4a42bae333 avm2: Fix ApplicationDomain property declarations
Many of the class property defintiions were wrong -
instance methods were defined as class properties,
and class properties were defined as instance properties.
2022-08-12 10:45:03 +02:00
Aaron Hill 91993eb872 avm2: Stub URLRequest.data
This allows Wonderputt to get further (it deliberately assigns
'null' to 'URLRequest.data'). We throw an exception for any other
value, to prevent confusing errors caused by attempting an
unexpected request to a web server with a missig body.
2022-08-12 10:14:36 +02:00
Aaron Hill 9d1f27484b avm2: Implement 'throw' opcode
We currently lack the ability to preserve the original
`Value<'gc>` in the error, so we're forced to stringify the error.

This means that only typeless 'catch' blocks will work properly -
however, they're the only kind of 'catch' block that we currently
implement. Implementing support for typed 'catch' blocks will naturally
allow us to preserve the original 'Value<'gc>' in the 'throw'
implementation, since we'll need to switch to a custom `Error<'gc>`
type.
2022-08-11 17:20:53 -05:00
Adrian Wielgosik 4a7cb51148 avm2: Make missing props on sealed classes throw properly 2022-08-11 21:28:18 +02:00
Aaron Hill 71571b9594 avm2: Add URLRequest.method and use it URLLoader 2022-08-11 19:50:58 +02:00
Aaron Hill ed0512ca9d avm2: Show class name in `ClassObject` Debug impl
Before: `ClassObject(GcCell(Gc { ptr: 0x7f69f8300a28 }))`
After:  `ClassObject { name: flash.net::URLRequest, ptr: 0x7fe9cc2e7820 }`
2022-08-11 18:54:11 +02:00
TÖRÖK Attila d5b86f60a1 avm2: Add `flash.system.LoaderContext`, stub `flash.system.SecurityDomain`
Also add AS stubs for the preexisting `flash.display.DisplayObjectContainer`
and `flash.system.ApplicationDomain` natively defined classes.
2022-08-11 10:01:03 +02:00
dowgird b6fd670410 address review comments 2022-08-10 01:34:08 +02:00
dowgird 38f50f83ef removed a now unused function, added a test 2022-08-10 01:34:08 +02:00
dowgird e5b0937461 changed catch_scope() back to taking MutationContext 2022-08-10 01:34:08 +02:00
dowgird 5ccc981357 Used install_instance_slots() instead of adding slots manually 2022-08-10 01:34:08 +02:00
dowgird fb0a984415 Rebase and fix clippy warnings. 2022-08-10 01:34:08 +02:00
dowgird 31ed697acd Fixes from review 2022-08-10 01:34:08 +02:00
dowgird 26b41199fb avm2: Implemented newcatch and basic exception handling 2022-08-10 01:34:08 +02:00
Adrian Wielgosik 54f9824ce0 avm1: Update drag in stopDrag() in case it wasn't called before 2022-08-10 00:20:09 +02:00
Nathan Adams 07da3f6c0f exporter: Add --skip-unsupported to skip (and not crash) avm2 movies 2022-08-09 23:19:42 +02:00
Nathan Adams 8efd69b525 core: Track 'actions since timeout check' globally instead of per Activation 2022-08-09 20:56:18 +03:00
Nathan Adams fb1ebcb9cc avm1: loadMovieNum with blank url is an unload, not a load - fixes #7337 2022-08-09 18:53:57 +03:00
Nathan Adams 4b19910791 audio: Avoid panic with supposed MP3s that are too small 2022-08-09 17:59:02 +03:00
TÖRÖK Attila 5e2804f992 avm2: Implement `flash.geom.Vector3D` 2022-08-08 22:15:09 +03:00
CUB3D 05bfa3770e chore: Fix warnings with cargo doc 2022-08-08 20:20:18 +03:00
relrelb e42a6b62e6 core: Require `target` in `NavigatorBackend::navigate_to_url`
Make the `target` parameter just a `String` instead of an `Option<String>`.
`None` is not needed as it's totally equivalent to an empty string.
2022-08-06 11:20:03 +03:00
Aaron Hill 2f8dde86af
avm2: Include class name in ScriptObject debug (#7512)
* avm2: Include class name in ScriptObject debug

Currently, the `ScriptObject` debug impl is almost useless -
while you determine if two printed objects are the same
by comparing the pointer value, you'll have no idea what
kind of object it actually is.

This PR now formats the `ScriptObject` output as a struct,
printing a (fake) "class" field containing the class name.

Before/after:

```
[ERROR ruffle_core::avm2::activation] AVM2 error: Cannot coerce Object(ScriptObject(ScriptObject(GcCell(Gc { ptr: 0x55f863936db8 })))) to an QName { ns: Private("Test.as$38"), name: "Second" }
[ERROR ruffle_core::avm2::activation] AVM2 error: Cannot coerce Object(ScriptObject(ScriptObject { class: "Object", ptr: 0x55ee0ad161e0 })) to an QName { ns: Private("Test.as$38"), name: "Second" }
```

Getting access to the class name from a `Debug` impl is tricky:

Developers can (and should be able to) insert logging statements
whereever they want, so any `GcCell` may be mutably borrowed.
Panics in debug impls are extremely frustrating to deal with,
so I've ensured that we only use `try_borrow` at each step.
If any of the attempted borrows fail, we print out an error message
in the "class_name" field, but we're still able to print the
rest of the `ScriptObject`.

Additionally, we have no access to a `MutationContext`, so we
cannot allocate a new `AvmString`. To get around this,
I've created a new method `QName::to_qualified_name_no_mc`,
which uses an `Either` to return a `WString` instead of allocating
an `AvmString`. This is more cumbersome to work with than the
nrmal `QName::to_qualified_name`, so we'll only want to use
it when we have no other choice.
2022-08-04 22:13:00 -07:00
Aaron Hill 2383e6850f avm2: Continue to process event when a handler produces an error
An exception thrown by one event handler shoud not prevent other event
handlers from running on this same event. Some SWFs like Wonderputt
depend on this behavior, as they have buggy event handlers that throw
errors.
2022-08-03 22:29:41 +03:00
Aaron Hill ad19c29c03 Remove `null` from `getChildByName` for missing child
This matches the behavior of Flash - no error is produced.
2022-08-03 21:45:59 +03:00
Adrian Wielgosik e214dd5ce5 avm2: Implement BitmapData.scroll/copyPixels, stub lock() 2022-08-01 22:31:42 +03:00
Adrian Wielgosik 17f090d1d5 avm2: Stub Loader.contentLoaderInfo 2022-08-01 22:31:42 +03:00
TÖRÖK Attila 820196d066 audio: Handle AudioCompression::UncompressedUnknownEndian in AudioMixer::make_seekable_decoder()
The same way as it is done in decoders::make_decoder().
2022-08-01 21:39:01 +03:00
Aaron Hill 2ce6679643
avm2: Store PropertyClass in `VtableData`
Calling `get_trait` copies the returned `Property`, so the caching
we performed in `PropertyClass` was never actually getting used.

Instead, we now store our `PropertyClass` values in a `Vec`
indexed by slot id. `set_property` and `init_property` now perform
coercions by going through the `VTable,` which writes the updated
`PropertyClass` back into the array.
2022-07-30 17:58:50 -07:00
Adrian Wielgosik 5be7f425f0 avm2: Migrate all Events to AS, remove EventData. 2022-07-30 12:34:12 -07:00
relrelb d01a03b4ca avm1: Correct `ActionURShift`
In SWF8 and SWF9, unsigned right shift actually has a signed result.
2022-07-29 14:44:21 -07:00
Ali MJ Al-Nasrawy 67fbc84ba3 don't rely on a rustc bug
context: https://github.com/rust-lang/rust/pull/98835
2022-07-29 15:27:46 -05:00
Aaron Hill 0d3e046b0e
avm2: Allow classes to reference their own type from a static variable
FP allows code like
`class Foo { static var INSTANCE: Foo = new Foo(); }`

However, this breaks our current property type coercion setup -
we cannot resolve the type `Foo` when setting the property `INSTANCE`,
since `Foo` is still being constructed.

Fortunately, we can perform this 'coercion' by just checking if
the object's class name and domain match the type name and domain
of the property.
2022-07-29 13:24:37 -07:00
Mike Welsh 30b185cbd4 audio: Reset symphonia decoder on loop 2022-07-28 21:25:33 -07:00
TÖRÖK Attila 7249db9052 audio: Fix crash/gap at the end of MP3 loops 2022-07-28 21:25:33 -07:00
Mike Welsh ffb57467eb audio: Add `AudioBackend::position_resolution`
This returns the approximate interval that the audio backend
updates the sound position information. This is used for syncing
animation to embedded "stream" audio tracks, and fixes some
stuttering in cases where the syncing was being too strict.
2022-07-28 21:25:33 -07:00
Mike Welsh 405c7194b0 audio: Remove `AudioBackend::preload_sound_stream` fns
No longer necessary now that web audio mixing is done on Rust side.
2022-07-28 21:25:33 -07:00
Aaron Hill f2deeb4de8 Fix typo 2022-07-27 22:38:49 -07:00
Aaron Hill 49d1a985ca avm2: Store `LoaderInfo` object on `MovieClip` and `Stage`
Previously, we would create a fresh `LoaderInfo` object each
time the `loaderInfo` property was accessed. However, users can
add event handlers to a `LoaderInfo`, so we need to create and
store exactly one `LoaderInfo` object per movie (and stage).

To verify that we're correctly handling the storage of `LoaderInfo`,
I've implemented firing the "init" event. This required a new
`on_frame_exit` hook, so that we can properly fire the "init"
event after the "exitFrame" for the initial frame but before
the "enterFrame" of the next frame.
2022-07-27 22:38:49 -07:00
EmperorBale d14b868c4f core: Simplify new_utf8_bytes 2022-07-25 10:52:56 -07:00
EmperorBale a2261cd556 chore: Formatting 2022-07-25 10:52:56 -07:00
EmperorBale d6604f538c wstr: Implement custom UTF-8 decoding routine 2022-07-25 10:52:56 -07:00
EmperorBale 6dab6ca557 avm2: Update set_data to convert bytes to string lossily 2022-07-25 10:52:56 -07:00
EmperorBale d79c68bbcd core: Implement AvmString::new_utf8_bytes_lossy 2022-07-25 10:52:56 -07:00
Aaron Hill 515c7bf518 Fix behavior when setting repeatCount, and improve tests 2022-07-24 20:43:00 -07:00
Aaron Hill b4f98190e9 avm2: Implement flash.utils.Timer and associated events
The current 'setInterval/setTimeout' implementation is
moved to 'core/src/timers.rs', and now works with both
AVM1 and AVM2 objects. The `flash.utils.Timer` class is implemented
mostly in ActionScript, with minimal modifications to the actual
Ruffle timer code.
2022-07-24 20:43:00 -07:00
relrelb 3bfe736262 core: Remove `From<Position<Twips>> for Transform`
Simply use `Matrix::translate` directly, which is more explicit and
intuitive.
2022-07-24 19:07:05 -07:00
relrelb bbfd272c15 avm1: Use `Matrix::scale`
Instead of a directly initialzed `Matrix`.
2022-07-24 22:11:31 +03:00
relrelb fc87a35572 core: Remove some dead `DisplayObject` methods 2022-07-23 22:22:20 +03:00
relrelb 8d30833d02 core: Don't use `saturating_sub` for `width` / `height`
Use regular subtraction, since it should never overflow.
Also remove `swf::Twips::saturating_sub`, which is now unused.
2022-07-23 10:33:12 -07:00
relrelb 29ae39a2d1 core: Remove unused parameter of `Avm1Button::from_swf_tag` 2022-07-23 10:18:53 -07:00
Rafał Dowgird fac32b488b
avm2: implement string replace(string, function) (#7456)
* avm2: implement string replace where pattern is string and replacement is a function

* * removed unnecessary vec!

  * fixed "no newline at the end of file"
2022-07-22 17:32:02 +03:00
Aaron Hill bb6f07ee1a
avm2: Add support for playerglobal instance allocators
This commit adds support for combining instance allocators with
ActionScript playerglobal class definitions. This is activated
by defining the metadata `[Ruffle(InstanceAllocator = "true")]`
on the ActionScript class definition.

The implementation of this feature is very similar to native methods:
`build_playerglobal` checks for the metadata described above,
and defines a const `NATIVE_INSTANCE_ALLOCATOR_TABLE` mapping
class ids to function pointers.

To demonstrate this feature, I've converted `Event` to ActionScript
(keeping the existing instance allocator function).
I've also converted `ActivityEvent` and `ContextMenuEvent` to
`ActionScript`, to demonstrate how this simplifies inheritance.
In a future PR, we can convert the remaining events to ActionScript,
and remove the `EventData` enum entirely.

Unfortunately, `flex-sdk`'s `asc.jar` compiler strips out all metadata
when the `-optimize` option is passed. As a result, I forked
`flex-sdk` and disabled this behavior:
https://github.com/ruffle-rs/flex-sdk/releases/tag/ruffle-1.0.0

The modified `asc.jar` (built from the forked repository)
is included in this PR, and replaces the our previous 'asc.jar'
downloaded from the official Flex SDK release.

* Change metadata to `[Ruffle(InstanceAllocator)]`

* Strip out metadata before saving bytecode
2022-07-20 23:11:46 -07:00
Mike Welsh ef838a3536 avm1: lineStyle scale mode defaults to normal 2022-07-19 15:01:17 -07:00
Mike Welsh 1980d6f420 canvas: Scale stroke width based on shape transform 2022-07-19 15:01:17 -07:00
relrelb 23fdc2b2ee chore: Appease clippy 2022-07-19 09:26:46 +03:00
Rafał Dowgird 934cb05371
avm2: implement string.replace(...) with fn, for now regex only. (#7429)
* avm2: implement string.replace(...) with fn, for now regex only.

  * string - added path for replacing regex with fn (replacing string
  with fn is still unimplemented)

  * regex - factored out common replace logic for when replacement is
  a string and when it is a function

  * added tests

* Addressed review comments

* removed tinkering cruft; formatting

* addressed review comments
2022-07-19 08:47:57 +03:00
relrelb 0e65617d4a avm2: Small cleanup in `RegExp::effective_replacement`
`char_indicies()` isn't really needed because the position is never
used.
So use the simpler `chars()` method instead.
2022-07-18 10:53:18 +03:00
Adrian Wielgosik 22d2810ef9 avm2: Migrate ContextMenu-related classes to AS 2022-07-17 11:05:37 -07:00
relrelb cad3cd8dbf avm2: Inline `Activation::run_stack_frame_for_script`
This reduces some complexity.
2022-07-15 17:15:14 -05:00
Aaron Hill af4f181856 avm2: Implement support for native methods in `playerglobal`
This commit adds support for marking methods as `native`
in ActionScript classes defined in playerglobal. The
`build_playerglobal` now checks for native methods, and
generates Rust code linking them to a corresponding Rust
function definition in the codebase.

To test this functionality, I've reimplemented several
functions as native methods (and moved related code to
pure ActionScript).
2022-07-15 11:43:49 -05:00
EmperorBale 95809f8a9b avm2: Make escape output for unicode characters, as well as characters that need padding 2022-07-15 15:29:55 +03:00
dowgird cfc9f51c5d avm2: implement $ patterns in regex replace 2022-07-13 15:48:25 -06:00
Rafał Dowgird 80d1a8449a
avm2: implement string.split for regex (#7363)
* avm2: implement string.split for regex

* Compressed the testing for regexp and unwrapping thereof

* * Moved the split logic into the regex object

  * Factored out a method for utf-16 matching

  * Added tests

* formatting

* * replaced manual counting with storage.length()

* clippy cleanup

* Address review comments

  * fix import path for WString
  * remove redundant variable in return statement
  * error passing via '?' instead of unwrap()
2022-07-11 19:47:05 +03:00
relrelb 9856a03797 avm1: Inline `apply_to_display_object` 2022-07-10 07:29:38 +03:00
relrelb 78ebf06f55 avm2: Extract `MethodFlags` enum 2022-07-09 20:34:53 +03:00
relrelb f643048c1c core: Introduce `Request`
Which holds both a URL and what was `RequestOptions` formerly.
2022-07-09 09:43:42 +03:00
relrelb 115f15806e chore: Fix `needless_borrow` clippy lints
Though https://github.com/rust-lang/rust-clippy/pull/8355 has been
merged, it seems to still report false-positives on nightly channel.

For now just fix the instances reported by stable clippy, and keep
`needless_borrow` allowed.
2022-07-08 14:14:30 +03:00
relrelb 2f4e31c6be avm1: Avoid allocation of some static strings
Prefer creating a static `AvmString` over allocating an owned one.
2022-07-06 09:19:12 +03:00
relrelb 9c1a05aaaf avm2: Re-use code in `coerce_to_number`
Use `string_to_f64` and `string_to_int`, as [`MathUtils::convertStringToNumber`](858d034a3b/core/MathUtils.cpp (L453-L466))
in avmplus does.
2022-07-06 09:04:15 +03:00
Mike Welsh 1963e47392 avm1: Increment register when preloading super (fix #7338)
The register index was not being increment when preloading the
`super` register which would cause issues when multiple registers
were preloaded.

Fixes #7338.
2022-07-03 12:51:07 -07:00
relrelb f0db6d8c60 avm1: Correct `parseFloat()`
Rewrite the implementation of `string_to_f64()` to match Flash behavior.
This affects `parseFloat()` as well as any `Value` to `f64` coercion.
2022-07-02 18:08:08 -07:00
relrelb 10af9435ae avm2: Minor `parseInt()/parseFloat()` tweaks
Alongside comment wordings, fix handling of non-`u8` characters by
replacing `as u8` conversions with `u8::try_from()`, that doesn't
wrap around, but rather fails gracefully.
2022-07-02 17:48:19 -07:00
Toad06 e219cb3b1c avm1: Fire `onData` function and event when calling `loadVariables` 2022-07-02 10:22:48 -07:00
relrelb 981fa0568c chore: `derive(Default)` for enums
It's available since stable Rust 1.62.0.
2022-07-02 09:23:04 -07:00
Aaron Hill b56eace008
avm2: Implement property type coercions
Properties can be declared with a type
(e.g. `var foo:MyClass = new MyClass();`). When
`set_property`/`init_property` is invoked for that property,
the VM will attempt to coerce the value to the provided type,
throwing an error if this fails. This can have observable behavior
consequences - if a property has type `integer`, for example, then
storing a floating point `Number` to that property will cause the
value to be coerced to an integer. Some SWFs (e.g. 'Solarmax') rely
on this behavior in order to implicitly coerce a floating point value
that's later used for array indexing.

This PR implements property type coercions in Ruffle. There are several
important considerations:

* The class lookup for property types needs to be done lazily, since
we can have a cycle between two classes (e.g. `var prop1:Class2;`
and `var prop2:Class1` in two different classes).
* The class lookup uses special rules (different from
  `resolve_definition`), and does *not* use `ScopeStack/`ScopeTree`
This means that a private class can specified as a property name -
the lookup will succeed without using a scope, even though
`flash.utils.getDefinitionByName` would fail with the same name
* The specialized 'Vector' classes (e.g "Vector$int") can be used
as property types, even though they cannot be lookup up normally.

Some Ruffle class definitions were previously using nonexistent
classes as property types (e.g. "BareObject") - these are fixed
in this PR.
2022-06-30 21:34:26 -07:00
Moulins c7bf11ece5 avm1: More accurate handling of preload/suppress flags in functions
- Handle the case where both preload aud suppress flags are
set for the same variable;
- Remove `arguments` field in `Activation`; instead use a normal
local definition;
- When `suppress_this` is set, inherit the `this` value from parent
activation. (This isn't entirely correct, as FP's `this` is mutable
and seems to be part of the scope chain, but this would require a
larger refactoring)
2022-06-29 16:02:13 -07:00
Moulins aa1e53e0e3 avm1: Refactor Executable::exec
- reduce rightwards drift by exiting early
- outline some code into separate methods on Avm1Function
2022-06-29 16:02:13 -07:00
Aaron Hill a79aa08f08
core: Free render backend resources on `BitmapData.dispose`
Currently, all three render backends hold on texture-related
resources indefinitely (`register_bitmap` pushes to a `Vec`,
and never removes anything). As a result, the resources used
by the render backend (which may include GPU memory) will grow
over time, even if the corresponding `BitmapData` has been deallocated.

This commit adds a new `unregister_bitmap` method, which is called from
`BitmapData.dispose`. All render backs are changed to now use an
`FnvHashMap<BitmapHandle, _>` instead of a `Vec`, allowing us to
remove individual entries.

Currently, we only call `unregister_bitmap in response to
`BitmapData.dispose` - when `BitmapData` is freed by the
garbage collector, `unregister_bitmap` is *not* called.
This will be addressed in a future PR.
2022-06-29 15:16:43 -07:00
Adrian Wielgosik 4d1bf7e00c avm2: Refactor AVM2 bare object creation 2022-06-29 15:12:39 -07:00
Adrian Wielgosik f31d4c2498 avm2: Remove SystemPrototypes. 2022-06-29 15:12:39 -07:00
Aaron Hill 1c5312d6c8 avm2: Declare 'dataFormat' property on URLLoader
This ensures that a sealed subclass can still access it.
2022-06-28 09:30:58 +03:00
David Wendt 632052f49e core: Manually fire late `added`/`addedToStage` events on AVM2 roots 2022-06-26 19:50:35 -07:00
Aaron Hill 9f1cd4dea8 avm2: Don't try to set MovieClip child with default name
Flash Player only sets children with explicit names.
2022-06-26 19:34:21 -07:00
Aaron Hill 53cdba96d3 avm2: Convert flash.geom.Matrix to ActionScript
I've kept the rust `flash.geom` module, even though it's now empty,
since we'll need to add things like `flash.geom.Transform` native
methods in the future.
2022-06-24 12:34:12 -05:00
relrelb 48e4d80d0a avm2: Implement `flash.net.SharedObjectFlushStatus` 2022-06-24 18:28:33 +03:00
relrelb 13d8565b12 avm2: Implement `flash.net.URLRequestMethod` 2022-06-24 18:28:33 +03:00
relrelb 4e29df5796 avm2: Implement `flash.net.URLRequestHeader` 2022-06-24 18:28:33 +03:00
relrelb 8398dc4ae8 avm2: Port `flash.net.URLLoaderDataFormat` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 781954bd86 avm2: Implement `flash.display.TriangleCulling` 2022-06-24 18:28:33 +03:00
relrelb 32df3b762c avm2: Port `flash.display.StageScaleMode` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 29692b4a49 avm2: Port `flash.display.StageQuality` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 121d17dd94 avm2: Port `flash.display.StageDisplayState` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 1f1c2b91cd avm2: Port `flash.display.StageAlign` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 1a8f6ef6aa avm2: Port `flash.display.SpreadMethod` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 206aee3d28 avm2: Implement `flash.display.ShaderPrecision` 2022-06-24 18:28:33 +03:00
relrelb f51d20ca64 avm2: Implement `flash.display.ShaderParameterType` 2022-06-24 18:28:33 +03:00
relrelb 790880a508 avm2: Port `flash.display.Scene` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 5817c1761b avm2: Stub `Array` in ActionScript 2022-06-24 18:28:33 +03:00
relrelb 3745ab57db avm2: Port `flash.display.SWFVersion` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 14830adb54 avm2: Port `flash.display.PixelSnapping` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb d6e1b8bbc1 avm2: Implement `flash.display.PNGEncoderOptions` 2022-06-24 18:28:33 +03:00
relrelb f0a8ba9b87 avm2: Port `flash.display.LineScaleMode` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 8b8b320064 avm2: Port `flash.display.JointStyle` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb e5806bb3d4 avm2: Implement `flash.display.JPEGXREncoderOptions` 2022-06-24 18:28:33 +03:00
relrelb 53401cc51d avm2: Implement `flash.display.JPEGEncoderOptions` 2022-06-24 18:28:33 +03:00
relrelb 6779e406ce avm2: Port `flash.display.InterpolationMethod` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 7c992b4664 avm2: Implement `flash.display.GraphicsPathWinding` 2022-06-24 18:28:33 +03:00
relrelb 3655e85f6c avm2: Implement `flash.display.GraphicsPathCommand` 2022-06-24 18:28:33 +03:00
relrelb 033d4ba6ad avm2: Stub `int` in ActionScript 2022-06-24 18:28:33 +03:00
relrelb ad4b06917b avm2: Port `flash.display.GradientType` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb a119bfa102 avm2: Implement `flash.display.FocusDirection` 2022-06-24 18:28:33 +03:00
relrelb 3165e942d8 avm2: Implement `flash.display.ColorCorrectionSupport` 2022-06-24 18:28:33 +03:00
relrelb c7a391ec36 avm2: Implement `flash.display.ColorCorrection` 2022-06-24 18:28:33 +03:00
relrelb 1ad020566e avm2: Port `flash.display.CapsStyle` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 0081b03c6e avm2: Implement `flash.display.BlendMode` 2022-06-24 18:28:33 +03:00
relrelb 23e5b3f0bb avm2: Implement `flash.display.BitmapEncodingColorSpace` 2022-06-24 18:28:33 +03:00
relrelb c7664206b3 avm2: Implement `flash.display.BitmapDataChannel` 2022-06-24 18:28:33 +03:00
relrelb 761d746c38 avm2: Port `flash.display.ActionScriptVersion` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb c6e04dfd2a avm2: Implement `flash.text.TextLineMetrics` 2022-06-24 18:28:33 +03:00
relrelb 546662a4f7 avm2: Implement `flash.text.TextInteractionMode` 2022-06-24 18:28:33 +03:00
relrelb d24c03349e avm2: Port `flash.text.TextFormatAlign` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 6108be135e avm2: Port `flash.text.TextFieldType` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 976cf2da39 avm2: Port `flash.text.TextFieldAutoSize` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 11f6e4abfb avm2: Implement `flash.text.TextExtent` 2022-06-24 18:28:33 +03:00
relrelb dcfe158f6c avm2: Implement `flash.text.TextDisplayMode` 2022-06-24 18:28:33 +03:00
relrelb 613bd8924a avm2: Implement `flash.text.TextColorType` 2022-06-24 18:28:33 +03:00
relrelb 8d024f2140 avm2: Implement `flash.text.GridFitType` 2022-06-24 18:28:33 +03:00
relrelb d1a22cf083 avm2: Implement `flash.text.FontType` 2022-06-24 18:28:33 +03:00
relrelb 45aff8f7ef avm2: Implement `flash.text.FontStyle` 2022-06-24 18:28:33 +03:00
relrelb 3abfac8ea6 avm2: Port `flash.utils.Endian` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 8228f7af6c avm2: Port `flash.utils.CompressionAlgorithm` to ActionScript 2022-06-24 18:28:33 +03:00
relrelb 801d95cdfa avm2: Implement `flash.geom.Orientation3D` 2022-06-24 18:28:33 +03:00
relrelb b38afb6c75 avm2: Implement `flash.geom.ColorTransform` 2022-06-24 18:28:33 +03:00
relrelb 668a25c404 avm2: Stub `uint` in ActionScript 2022-06-24 18:28:33 +03:00
Aaron Hill 6eb4b485f0
Merge pull request #7095 from adrian17/avm2-fix-bare-function-scope
avm2: Pull methods' scopes from vtable, not class
2022-06-23 00:10:17 -05:00
relrelb 017e35a82f avm2: Refactor `parseInt` implementation
Re-use some helper functions introduced in #7212, and fix some
minor inaccuracies.
2022-06-23 01:07:15 +03:00
Adrian Wielgosik 97cfaff347 avm2: Refactor a (class,scope,method) tuple to a ClassBoundMethod 2022-06-23 00:03:07 +02:00
Callum Thomson 1310f433f2
avm2: Implement escape() toplevel (#7281)
* AVM2: Implement escape()

* chore: Fix formatting

* avm2: Escape resolves non strings to null and use push to append

* chore: Fix nits

* avm2: Escape should coerce objects, add early returns
2022-06-22 08:43:22 +03:00
relrelb 0e0045425e avm2: Re-implement `parseFloat`
The AVM2 `parseFloat` implementation used to call into the AVM1 one,
which was not 100% accurate. De-couple it as a new implementation,
based on `MathUtils::convertStringToDouble` in `avmplus`:
https://github.com/adobe/avmplus/blob/master/core/MathUtils.cpp#L1229-L1439
2022-06-21 08:02:40 +03:00
relrelb 754579eb07 avm2: Port `AccessibilityProperties` to ActionScript 2022-06-18 20:00:56 +03:00
relrelb 786e8d92fb avm2: Introduce ActionScript entry-points
Previously all the `.as` files compiled into `playerglobal.swf`
were detected automatically using `walkdir`. While this might be
convenient, it can cause unexpected results when untracked `.as`
files exist. So instead, introduce two entry points - `stubs.as`
and `globals.as`, which include all stub ActionScript definitions,
and actual class implementations, respectively. This also simplifies
the `playerglobal.swf` build script a bit.
2022-06-18 18:26:57 +03:00
Aaron Hill 21eac9364f avm2: Use '.stub.as' suffix to indicate stub class
This removes the need for keeping an updating list in
'build_playerglobal', and made things easier for me
when porting classes to ActionScript.
2022-06-17 00:03:40 +03:00
relrelb f9596543c6 avm2: Remove unused `Rectangle` and `Point` classes/prototypes
They are now both implemented in pure ActionScript, and no Rust code
ever references them.
2022-06-16 22:42:50 +03:00
relrelb a9915c71bc avm2: Port `flash.geom.Rectangle` to ActionScript
`flash.geom.Rectangle` is a good candidate, since it doesn't have
any native function, and it depends only on `flash.geom.Point`,
which was already been ported to ActionScript in #7071.
2022-06-16 22:42:50 +03:00
Aaron Hill f629a91e53
avm2: Allow implementing classes in ActionScript in custom `playerglobal`
This PR adds support for building a custom `playerglobal.swf`, which can be used
to implement builtin Flash classes in ActionScript. This file is embedded into Ruffle
using `include_bytes!`, and loaded during initialization.
As an example, the `Point` class is reimplemented
in ActionScript, and `flash.text.AntiAliasType` is added.

The ActionScript compilation process is performed by `core/build.rs`.
See that file, along with `core/src/avm2/globals/README.md`, for
more details.
2022-06-15 22:00:17 +03:00
relrelb bd88e5e95a render: Remove unused `unmultiply_alpha_rgba` 2022-06-11 08:28:24 +03:00
Aaron Hill 3d84eb7d45 Remove now-unused `lowest_depth` method 2022-06-11 00:59:18 +03:00
Aaron Hill 6d9d155b15 avm2: Use render_list instead of depth_list in most cases
The `render_list` for a container always contains all of the children
under both AVM1 and AVM2 - howver, the depth_list may not contain
some children under AVM2.

When we're not performing some AVM1-specific operation
(e.g. `getInstanceAtDepth`, or dumping out AVM1 variables),
we should be using the render list.
2022-06-11 00:59:18 +03:00
Aaron Hill cc90796d8a avm2: More filter-related stubs
This stubs out BlurFilter, adds properties to GlowFilter,
and make the getter for  DisplayObject.filters return
an empty array instead of Undefined.

This is all of the filter-related code that 'Solarmax'
needs in order to reach the main screen (combined with
other unrelated changes I have yet to submit)
2022-06-10 19:35:48 +03:00
Aaron Hill dde21a2a60 chore: Fix latest Clippy warnings 2022-06-08 07:19:56 +03:00
Aaron Hill 487017e7c5 avm2: Properly handle Dictionary enumerants
Previously, there was an off-by-one bug in `get_enumerant_name`,
which caused us to produce a spurious 'null' as a key.
However, the 'dictionary_foreach' test only checked that certain
keys were present, so the presence of an additional key didn't break
the test.

This commit makes Dictionary enumerants behave in the same way as
Array enumerants - all of the object-specific enumerants
(in this case, the non-primitive dicitonar keys) come first,
followed by 'base' enumerants from ScriptObject (in this case,
primtive/String keys). Additionally, `setPropertyIsEnumerable` is now
ignored for `Dictionary`, consistent with Flash's behavior.

The `dictionary_foreach` test is updated to print out all of
the keys when inspecting the dictionary. Since the enumeration
order is unstable (under both Flash and Ruffle) due to the dependency
on pointer hashing, the test sorts the keys before printing them.
This ensures that we get stable output which is consistent between
Ruffle and Flash.
2022-06-07 00:39:42 +02:00
Aaron Hill a4b3dbed79 avm2: Allow accessing `stage.loaderInfo.loaderURL`
Flash Player allows this, and returns the path to the root SWF file.
The test only checks that the returned path contains 'test.swf',
to avoid depending on a platform-specific path.
2022-06-06 22:08:54 +03:00
Aaron Hill 9e4d13f201 avm2: Make `Array.pop` actually pop from the back
The loop to search for a `non_hole` was missing
a `break;`, so it would actually find the *first*
non-hole, rather than than the last. This was not caught
by the test, since there was only one "real" element
in the array (the other one was set on 'Array.prototype')
2022-06-04 23:28:06 +03:00
relrelb 53ef80f514 render: Introduce `RenderBackend::register_bitmap`
Since all `RenderBackend::register_bitmap_*` implementations are
identical now, move them to the default implementation of `RenderBackend`.

Also, turn `RenderBackend::register_bitmap_raw` into `RenderBackend::register_bitmap`,
which accepts a single `Bitmap` parameter.
2022-06-02 15:27:29 -07:00
relrelb 4fb77edfb1 render: Move `srgb_to_linear` to `common_tess`
Since it's the only user of it. Also make it mutate the float array
parameter instead of returning a new one, just to simply things a
bit.
2022-05-31 21:48:11 +03:00
relrelb cec9850a33 core: Use `swf::Matrix::translate` in more places
Replace direct instatiations of `swf::Matrix` where only `tx` and
`ty` are specified, and other fields are default.

This results in a slightly more shorter, readable code.
2022-05-29 21:33:53 +03:00
Toad06 61fa38e70f avm1: Correct `Value::as_bool(String)` in SWFv6 and below 2022-05-27 23:05:55 +03:00
Adrian Wielgosik f169070106 avm2: Pull methods' scopes from vtable, not class 2022-05-26 20:53:41 +02:00
Aaron Hill 15cb9a9ce6 Use `instance_scope` when making `super` method call
A method called with `super` is always an instance method,
so we should be using `instance_scope` for consistency with
`call_property`. This fixes a bug where a method cannot
access static class members (via `getlex`) when called bia
`super.method()`
2022-05-24 18:49:47 -06:00
Aaron Hill fd2d14618d
core: Correctly calculate the length passed to `resize_to_reader`
In several places, we read some data from a tag, and then pass
the original tag length to `resize_to_reader`. This is incorrect -
the provided length is used an an offset from the current position
in the reader, so we will extend past the end of the current tag if
we've already read some bytes.

In practice, this doesn't appear to cause any problems - AVM bytecode
has internal length fields, which end up ensuring that we will never
try to read past where the slice *should* end. However, if a `DoAbc`
tag is the last tag in the file, then we'll end up trying to use
`resize_to_reader` with an offset past the end of the movie.

This commit subtracts the number of already-read bytes from `tag_len`,
to ensure that we always construct a correctly-sized `SwfSlice`
2022-05-24 11:46:16 -07:00
Toad06 580a499e56 core: Run `update_drag` in `Player::handle_event` 2022-05-23 19:05:35 -07:00
Mike Welsh 32bf7e1412 chore: Appease clippy 2022-05-22 02:34:18 -07:00
bbb651 cf820b4f95 desktop: Add fullscreen command line option 2022-05-20 19:51:22 -07:00
relrelb e3da0d2bfd avm1: Simplify `XML.xmlDecl`
Store just the XML declaration string itself, rather than the attributes
it consists of. Then simply return it in ActionScript's `XML.xmlDecl`
property, without using `quick_xml::Writer` at all. This also matches
Flash behavior by capturing the XML declaration as-is, preserving
whitespaces, quotes, casing etc.
2022-05-20 18:46:19 -07:00
Daniel Jacobs cddf5796a3 avm2: Add more Event classes' methods and properties 2022-05-20 18:42:07 -07:00
David Wendt e926af7796 core: Prevent recursive execution of frame scripts on the same movie clip.
To be clear, recursive execution of frame scripts between *different* movie clips is still allowed.
2022-05-20 18:37:42 -07:00
David Wendt 85d98d8c07 core: Always clear the `EXECUTING_AVM2_FRAME_SCRIPT` flag, even if we didn't actually execute frames.
Prior to this commit, executing frame scripts on a movie that doesn't have them for this frame, or didn't advance to a new frame, would cause the the movie to ignore all gotos until the next time it ran a frame script.
2022-05-20 18:37:42 -07:00
Aaron Hill eaeecfcfbc Adjust error message 2022-05-20 11:41:17 -07:00
Aaron Hill 613a255fb3 Use binary literal 2022-05-20 11:41:17 -07:00
Aaron Hill d3689de25d Use QName::dynamic_name 2022-05-20 11:41:17 -07:00
Aaron Hill 7a870ad10a Make some methods private 2022-05-20 11:41:17 -07:00
Aaron Hill 8d8a7600d8 avm2: Partially implement `URLLoader` and related classes
This PR implements the `URLLoader` class, allowing AVM2 scripts
to load data from a URL. This requires several other related
classes (`URLLoaderDataFormat`, `URLRequest`, `IOError`) to be
implemented as well.

Currently implemented:
* Fetching from URLs using the 'navigator' backend
* The `text` and `binary` data formats (which store data
in a `String` or `ByteArray` respectively)
* The `open`, `complete`, and `ioError` events
* The `bytesLoaded`, `bytesTotal`, and `data` properties

Not yet implemented:
* The HTTP and security events
* All of the properties of `IOError`
* The properties on `URLRequest` (besides `url`)
* The "variables" data format

This should be enough to get some basic uses of `URLLoader` working
(e.g. simple GET requests to a particular website).

Note that in Flash's `playerglobal`, the `URLLoader` class is just
a think wrapper around the more general `URLStream`. However,
implementing `URLStream` will require changes to `Navigator``
to support notifications when data arrives in the stream. When
that happens, we should be able to re-use a large amount of the
code in this PR.
2022-05-20 11:41:17 -07:00
Toad06 39e46e5bd3 avm1: Remove `Value::from_bool` 2022-05-19 20:24:53 -06:00
TÖRÖK Attila 81749f900b avm2: Implement GradientType, InterpolationMethod, SpreadMethod in flash.display 2022-05-19 23:47:55 +02:00
Mike Welsh de99dcd37b core: Add `BitmapFormat::bytes_per_pixel` 2022-05-19 10:43:54 -07:00
Mike Welsh 48f7ff5f4d core: Add `Bitmap::to_rgba` 2022-05-19 10:43:54 -07:00
Mike Welsh e710f3fa0e core: Clean up `render::Bitmap`
* Make `BitmapFormat` a fieldless enum and move `data` to its own
   field for ease of use.
 * Make `Bitmap` fields private.
2022-05-19 10:43:54 -07:00
Mike Welsh 6615ed17f9 core: Verify bitmap length after decoding
Guarantee bitmap data after decoding has the expected length for
the given width+height+format. This eases the burden from backends
to worry about this. Pad or truncate the data if it doesn't have
the expected size.
2022-05-19 10:43:54 -07:00
Mike Welsh b88e77573d core: Handle greyscale PNGs
`render::decode_png` now handles greyscale or greyscale+alpha PNGs.
2022-05-19 10:43:54 -07:00
Toad06 b50f1201e1 avm1: `action_enumerate` can handle paths 2022-05-18 19:30:48 -07:00
David Wendt 1809ca611b avm2: Make dispatch list initialization lazy, so that it can run before constructors if necessary.
Due to various quirks of how timeline-initiated symbols interact with AVM2, it is possible for user code to gain a reference to uninitialized objects (especially `SimpleButton` which doesn't initialize until after `exitFrame`). It is still possible to attach event handlers to them that fire correctly, and movies expect to be able to.
2022-05-16 17:13:35 -07:00
Mike Welsh d1b65d9092 avm1: Pass ExecutionReason to `Object::call_method`
Internal function calls such as `toString` and event handlers
always used the base clip from the function itself, so add an
`ExecutionReason::InternalCall` to signify this and pass it along
to `call_method`.
2022-05-14 22:29:44 -07:00
Mike Welsh 4904b2cc97 avm1: Fix scope of function calls in SWFv5 vs. SWFv6+
Fix various scope behavior when executing a function:

 * For function calls in SWFv6+, functions are proper closures and
   close over the SWF version, base clip, and scope of their
   defining function.
 * Function calls in SWFv5 are not closures, and use the version,
   base clip, and scope of `this` when the function is called.

Fixes #5502.
2022-05-14 22:29:44 -07:00
Aaron Hill a453aa73af avm2: Don't consider declared return type for unchecked functions check
Testing under Flash shows that methods can be considered 'unchecked'
(allowing them to be called with more arguments than declared
parameters) even if they have a declared return type.

This is relied on by SteamBirds, which registers an event handler
which takes 0 parameters and an explicitly declared return type
2022-05-13 09:32:05 -07:00
Aaron Hill 8ff720dd9d
avm1: Allow new `unused_macro_rules` lint on `declare_properties`
This was recently added in https://github.com/rust-lang/rust/pull/96150
Some of the `__version` rules are currently unused, but I assume
that we still want to keep them for potential future use.
2022-05-13 09:31:46 -07:00
relrelb cab49ae6e1 swf: Introduce `Color::WHITE`
And use it where possible, to improve code readablity.
2022-05-12 12:12:06 -07:00
relrelb 0b0f8a1a7a swf: Introduce `Color::BLACK`
And use it where possible, to improve code readablity.
2022-05-12 12:12:06 -07:00
Aaron Hill 938d80146c avm2: Implement `TextField.background` getter/setter
There's already a `has_background` field on the underlying object
data, so we can just map this property to it.
2022-05-11 15:42:19 -07:00
Aaron Hill e39cfa8027 Define `String.fromCharCode` as both a public and AS3 method
This is relied on by SteamBirds
(https://www.kongregate.com/games/weasello/steambirds)
2022-05-11 15:42:19 -07:00
Mike Welsh f550abd18d web: Fix some warnings
Fix warnings caused by desktop-only code.
2022-05-09 22:28:43 -07:00
Mike Welsh 6547fcdf99 avm1: Remove `avm1::globals::display_object` module
This module is now mostly empty, so move the items up to `globals`.
`getDepth` was the only shared method, so declare this property
inline in each display object type. `Video` was also incorrectly
declaring `getDepth`.
2022-05-09 17:39:49 -07:00
Mike Welsh a97ae38008 avm1: Remove `toString` from display objects
`MovieClip` and others do not have a `toString`; instead, stage
objects are special cased to return their path when coerced to
string.
2022-05-09 17:39:49 -07:00
Mike Welsh 35d2f69396 avm1: Improve `StageObject::get_local_stored`
* Avoid an extraneous check to `ScriptObject::has_own_property`.
 * Avoid magic property branches if property name does not start
   with `_`.
2022-05-09 17:39:49 -07:00
Mike Welsh 2683686014 avm1: `_root`, `_parent`, `_global` are magic properties (fix #768)
Remove `_root`, `_parent` and `_global` from `MovieClip.prototype`.
Instead, these are "magic" properties similar to `_x` and `_y`.
Add `StageObject::resolve_path_property` to handle these, alongside
the `_levelN` property.

Fixes #768.
2022-05-09 17:39:49 -07:00
relrelb 781d091d42 swf: Return concrete data types in `Reader` methods
Where possible, return the specific data type instead of the generic
`Tag` type. Most reader methods do this already, so this brings the
rest in-line.
2022-05-09 14:59:38 -07:00
relrelb bce4075c69 core: Remove `url_from_relative_path`
The remaining caller was `SwfMovie::from_path`, which is now changed
to be simpler, and a little stricter (panics if `Url::from_file_path`
fails, though it shouldn't happen with canonicalized paths).
2022-05-09 10:06:52 -07:00
nosamu f39537f984 docs: Correct issue number in code comment 2022-05-08 14:27:15 +03:00
relrelb b46134dc43 avm1: Tiny cleanup in `Activation::set_target`
Use `Option::filter`.
2022-05-07 22:46:35 -07:00
Mike Welsh f20f53f555 avm1: Grab SWF version from executing clip
Remove the `swf_version` parameter from `Activation` constructors,
because this was incorrectly using the global or root SWF version
most times.

Instead, grab the SWF version for the activation directly from the
base clip.
2022-05-07 10:25:10 -07:00
Mike Welsh 1e9c464d94 avm1: Add version to MovieClip properties 2022-05-07 10:25:10 -07:00
Mike Welsh 4fa4c6ca84 avm1: Implement property version checking
Check SWF version of AVM1 properties and return undefined if they
are gated to a later version.
2022-05-07 10:25:10 -07:00
Mike Welsh e6cadf7de4 avm1: Use u16 for Property::attributes 2022-05-07 10:25:10 -07:00
relrelb 401f423ffa xml: Remove `XmlAttributesObject`
Use a bare `ScriptObject` instead. This matches Flash's behavior in
many aspects:
* Attribute values can now store arbitrary AVM1 values, rather than
just strings. These are coerced to string lazily on demand (e.g.
when coercing the whole XML node to a string).
* Attributes iteration order is the same as their definition order,
not sorted by their name.

Also fix some bugs in `XmlNode::lookup_namespace_uri` (renamed from
`lookup_uri_for_namespace`):
* Iterate attributes by their definition order, so the first matching
one is returned.
* The empty prefix matches every attribute that starts with "xmlns"
(with/without a colon).

And inline `XmlNode::lookup_namespace_for_uri` into `get_prefix_for_namespace`,
and fix some bugs in there as well:
* Iterate attributes by their definition order, so the first matching
one is returned.
* Match any attribute that start with "xmlns" (with/without a colon).
2022-05-07 10:24:45 -07:00
Mike Welsh 5730c8db94 core: Clamp color values in DefineBitsJPEG3 (fix #6893)
The colors in a DefineBitsJPEG3 tag should be premultiplied alpha,
but in some SWFs they are incorrectly not premultiplied. Flash
Player clamps the color values to the alpha in this case to allow
these images to work more as expected.

Fixes #6893.
2022-05-07 09:46:44 -07:00
relrelb 87ce0f56b7 core: Remove `NavigatorBackend::resolve_relative_url`
The resolved URL only used by `NavigatorBackend::fetch`. So simply
inline `NavigatorBackend::resolve_relative_url` into `NavigatorBackend::fetch`,
per implementation.
2022-05-07 09:06:53 -07:00
relrelb ea665d91f2 core: Introduce and use `Response::url` 2022-05-07 09:06:53 -07:00
relrelb 2517d8de4b core: Introduce struct `Response`
Currently it's a trivial wrapper around `Vec<u8>`, but more fields
will be added in the future (e.g. response URL, HTTP status code).
2022-05-07 09:06:53 -07:00
Mike Welsh 82ed6fcba7 core: Cleanup PlaceObject comments 2022-05-06 11:33:52 -07:00
Mike Welsh 0833bd0d18 core: Clip events can only be set on initial placement 2022-05-06 11:33:52 -07:00
Mike Welsh 8bf0114fdf core: DisplayObject clip depth can only be set on initial placement 2022-05-06 11:33:52 -07:00
Mike Welsh 32252b2ed4 core: DisplayObject name can only be set on initial placement 2022-05-06 11:33:52 -07:00
Mike Welsh aa66c31d6c core: Add comment about rewind behavior of is_visible 2022-05-06 11:33:52 -07:00
Mike Welsh b46c07830e core: Stub DisplayObject::background_color 2022-05-06 11:33:52 -07:00
Mike Welsh f8698d1cc9 core: Stub DisplayObject::blend_mode 2022-05-06 11:33:52 -07:00
Mike Welsh 2cebd47ad2 core: Stub DisplayObject:is_bitmap_cached 2022-05-06 11:33:52 -07:00
relrelb f6153ff7c1 chore: Appease clippy 2022-05-06 10:36:38 -07:00
relrelb d1d6b56615 avm1: Remove a stale TODO
Forgotten in #6785.
2022-05-03 10:22:43 -07:00
relrelb beee6cb067 avm1: Correct and cleanup `Array.sort` and `Array.sortOn`
* Mimic Flash's quicksort algorithm, rather than using Rust's
`sort_unstable_by`.
* Rename `flags` to `options`, as they are named in AS2 reference.
* Organize different sorting options using 3 simple functions:
`sort_compare`, `sort_compare_custom` and `sort_on_compare`.
2022-05-03 09:47:38 -07:00
Adrian Wielgosik b2f309fc35 avm1: Implement LocalConnection.domain() 2022-04-30 16:14:16 -07:00
relrelb babf49aaf9 chore: `.filter_map(..).next()` -> `.find_map(..)`
Per the rust-analyzer diagnostic: https://rust-analyzer.github.io/manual.html#replace-filter-map-next-with-find-map
2022-04-30 10:41:46 -07:00
Mike Welsh 1eb06908c8 core: Make PlayerBuilder::build infallible 2022-04-29 09:14:32 -07:00
Mike Welsh 3e15ca4cad core: Use `Arc::new_cyclic` in player initialization
Co-authored-by: relrelb <relrelbachar@gmail.com>

Change `UpdateContext::player` to not be an `Option`
2022-04-29 09:14:32 -07:00
Mike Welsh ddc28310f8 core: Clean up test_utils 2022-04-29 09:14:32 -07:00
Mike Welsh f48182ef3d core: Add various settings to PlayerBuilder 2022-04-29 09:14:32 -07:00
Mike Welsh 895508a0fb core: Remove Player::new
PlayerBuilder is effectively the Player constructor.
2022-04-29 09:14:32 -07:00
Mike Welsh e1e2b1008a core: Add PlayerBuilder 2022-04-29 09:14:32 -07:00
Mike Welsh 2453626dec core: Add MemoryStorageBackend::new 2022-04-29 09:14:32 -07:00
David Wendt 155672d482 core: Remove AS3-related `coerce_to_object` calls in `MovieClip` 2022-04-24 16:54:19 -07:00
David Wendt fe50e98f87 avm2: Remove `coerce_to_object` calls in `flash.text.TextField` 2022-04-24 16:54:19 -07:00
David Wendt afdae1f6c6 avm2: Remove `coerce_to_object` calls in `flash.media.Sound` 2022-04-24 16:54:19 -07:00
David Wendt 818526069e avm2: Remove `coerce_to_object` calls in `flash.events.MouseEvent` 2022-04-24 16:54:19 -07:00
David Wendt 5dc5ca06e3 avm2: Remove `coerce_to_object` calls in `flash.events.EventDispatcher` 2022-04-24 16:54:19 -07:00
David Wendt 4c736094c1 avm2: Remove `coerce_to_object` calls in `flash.display.Stage` 2022-04-24 16:54:19 -07:00
David Wendt cbc9937fcf avm2: Remove `coerce_to_object` calls in `flash.display.SimpleButton` 2022-04-24 16:54:19 -07:00
David Wendt 40ecae28d0 avm2: Remove `coerce_to_object` in `flash.display.MovieClip` 2022-04-24 16:54:19 -07:00
David Wendt 85b598a8da avm2: Remove `coerce_to_object` calls in `flash.display.DisplayObjectContainer` 2022-04-24 16:54:19 -07:00
David Wendt 7e7ee14d3b avm2: Remove `coerce_to_object` calls in `flash.display.DisplayObject`. 2022-04-24 16:54:19 -07:00
David Wendt 5f5f98ecdc avm2: Remove `coerce_to_object` calls in `flash.display.Bitmap` 2022-04-24 16:54:19 -07:00
David Wendt 5b5313bf95 avm2: Remove `coerce_to_object` calls in `String` impls 2022-04-24 16:54:19 -07:00
David Wendt e851b73570 avm2: Remove calls to `coerce_to_object` in `JSON` impls 2022-04-24 16:54:19 -07:00
David Wendt 88f4ebc2a3 avm2: Remove calls to `coerce_to_object` in `Function` impls 2022-04-24 16:54:19 -07:00
David Wendt 26e65368df avm2: Remove `coerce_to_object` calls in `Array` where possible, and replace with more descriptive error messages otherwise 2022-04-24 16:54:19 -07:00
David Wendt 1383901a94 avm2: Remove unnecessary usage of `coerce_to_object` in `avm2::globals`. 2022-04-24 16:54:19 -07:00
David Wendt 90b239f30d avm2: Add descriptive error messages for when `Vector` methods encounter `null`/`undefined`. 2022-04-24 16:54:19 -07:00
David Wendt e486efb4c6 avm2: Remove unnecessary usage of `coerce_to_object` in `ClassObject`. 2022-04-24 16:54:19 -07:00
David Wendt 0f2b77c138 avm2: Alter basic object operations to use more descriptive error messages. 2022-04-24 16:54:19 -07:00
David Wendt 4185acc5a8 avm2: Remove unnecessary usage of `coerce_to_object` in `avm2::events`. 2022-04-24 16:54:19 -07:00
David Wendt bb70086238 avm2: Replace a number of `coerce_to_object` calls with the previous commits' new messages as appropriate 2022-04-24 16:54:19 -07:00
David Wendt bea6744682 avm2: Add methods to `Value` and `Activation` for performing common coercions and returning a relevant error if they fail.
Those methods are:

 * `Value.coerce_to_receiver`: coerce to object for receivers
 * `Value.as_callable`: as_object for callables
 * `Activation.superclass_object`: get superclass of currently-called object
 * `Activation.resolve_class`: resolve scope value, unwrap `ClassObject`, and error out if either step fails

This accounts for ~80% of coercion-related errors in `Activation`.
2022-04-24 16:54:19 -07:00
David Wendt 2ec606c5cb avm2: Add utilities for formatting `Multiname`s and class instances' names. 2022-04-24 16:54:19 -07:00
relrelb 3dbde841df avm1: Remove `TObject::type_of`
It can be simply determined in `Value::type_of`.
2022-04-23 17:55:48 -07:00
Daniel Jacobs aa92c3c1bc core: scale_mode -> window_mode for set_window_mode 2022-04-22 19:31:23 +03:00
Mike Welsh e2e7ad0df2 avm2: Implement `flash.ui.Keyboard`
Add `Keyboard` key code constants and stub out other properties.
2022-04-21 21:40:04 -07:00
Mike Welsh 1cb3d389e8 core: Add some KeyCode variants 2022-04-21 21:40:04 -07:00
TÖRÖK Attila 7cbba5bc8f avm2: Stub flash.accessibility.AccessibilityProperties 2022-04-19 09:55:09 -07:00
relrelb 25d47da528 render: Improve CMYK to RGB conversion
Use integer arithmetic, which is more accurate and efficient.
2022-04-18 22:00:48 -07:00
Mike Welsh cdccc2a2db avm1: Array.sortOn does not inspect proto or virtual properties
`Array.sortOn` only looks at raw properties and does not inspect
the prototype chain or call virtual properties.
2022-04-18 08:34:04 -07:00
Mike Welsh 3305ac69c4 web: Support wmode parameter 2022-04-17 08:33:51 -07:00
relrelb 87e85e16da render: Make `rgb5_component` a lambda
This way the `compressed` parameter becomes implicit.
2022-04-16 13:52:59 -07:00
relrelb 8feeadf578 render: Use `std::borrow::Cow`
Also apply some nearby refactors.
2022-04-16 13:52:59 -07:00
relrelb eeaec947b3 render: Remove unneeded `pub`s
And remove the dead `glue_swf_jpeg_to_tables` function.
2022-04-16 13:52:59 -07:00
relrelb 9b4108444f render: Strip 16-bit PNG samples to 8-bit
PNGs with 16-bit samples were not being normalized to 8-bit, screwing up their
appearance.

Add the `STRIP_16` transformation using `Transformations::normalize_to_color8()`,
which is equivalent to `Transformations::EXPAND | Transformations::STRIP_16`.
Also warn in case `png` outputs a color type other than `Rgb` and `Rgba`.
Due to the `EXPAND` transformation, this may be only `Grayscale` or
`GrayscaleAlpha`. `Indexed` is converted to either `Rgb` or `Rgba`.

Fixes #6662.
2022-04-16 12:45:55 -07:00
Mike Welsh bce9398c0d avm1: Add Accessibility stub 2022-04-16 09:05:16 -07:00
Toad06 b2b1b5fa25 avm1: Correct `Add`, `Equals`, `Less` and `GetProperty` actions 2022-04-13 22:00:25 -07:00
Mike Welsh 146b8adc68 swf: Clean up LineStyle
* Remove LineStyle::color, instead using fill_style with
   FillStyle::Color to indicate solid color.
 * Store `flags` in the struct instead of separate bools/values.
 * Add getters/setters for ease of use.
 * Add builder-style methods for setting LineStyle properties.
 * Fix misnamed ALLOW_CLOSE flag to NO_CLOSE.
2022-04-11 22:50:40 -07:00
Mike Welsh c0dff98d84 chore: Fix len_zero warning in symphonia Mp3Decoder 2022-04-11 20:15:13 -07:00
Mike Welsh 24f00238a7 audio: Fix symphonia feature
This feature stopped building with the bump to symphonia 0.5, which
added a `Sync` bound to its traits.

 * Add `Sync` bounds to our own internal audio traits to match.
 * nellymoser::Decoder was also tweaked to add a Sync bound.
 * Lock the nellymoser dependency to a specific git commit.
2022-04-11 15:25:15 -07:00
Toad06 c6c1f553d5 avm1: Correct `Action::RandomNumber` 2022-04-11 11:02:08 -07:00
Toad06 e2528b04a7 avm1: Coerce booleans to `"1"` or `"0"` in SWFv4 2022-04-10 20:03:39 -07:00
Toad06 b221485288 avm1: Fix `Action::Divide` in SWFv4 2022-04-09 23:17:39 -07:00
Mike Welsh 91346f5fad avm1: Format floating-point numbers
Co-authored-by: Toad06 <gd.productions@laposte.net>
2022-04-09 22:40:59 -07:00
Mike Welsh 478f970fc8 chore: Appease clippy 2022-04-09 18:23:51 -07:00
Aaron Hill d7532ae654 avm2: Add stubs for `BitmapFilter`, `GlowFilter`, and `DisplayObject.filters`
This gets 'Rolling Hero' further in the startup process,
since it just tries to set a filter on an object.
2022-04-08 16:53:16 -07:00
relrelb ad42b9908f xml: Refactor `XmlNode` creation methods
Unify the previous 3 creation methods to a single `XmlNode::new`.
This allows supporting arbitrary `nodeType` values passed to the
`XMLNode` constructor.
2022-04-08 16:34:57 -07:00
relrelb 7497fb7008 core: Change `Player::set_root_movie` to accept a `SwfMovie`
Move the `Arc::new` to within the function.
2022-04-08 15:16:25 -07:00
Toad06 12737b8431 avm1: Fix `Number(String | Object)` in SWFv4 2022-04-08 10:41:21 -07:00
Mike Welsh 6ec3049e02 desktop: Use floats for audio start/endpoints calculation (fix #6569)
Integer math was used when calculating a sound's start/endpoints,
because it was assumed that the sound sample rate was always an
even divisor of 44100Hz. However, some third party tools can embed
MP3s with other samples rates, such as #6569 which has a 16000Hz
MP3. This could also occur for dynamically loaded MP3s. This
results in the sound starting at an incorrect position.

Use floating point math to ensure the correct position is
caluclated.

Fixes #6569.
2022-04-03 15:50:43 -07:00
Mike Welsh 9687365885 core: Remove morph shape preloading
Remove the preload step that would pre-create the shapes for each
morph shape ratio on SWF load. Instead, lazily crate the shapes
when they are needed.
2022-04-03 13:50:09 -07:00
Mike Welsh b1879f4b99 core: Fix divide-by-zero in Video::seek (fix #6605) 2022-04-03 11:33:52 -07:00
Toad06 055e1d4dc1 avm1: Fix `loadVariablesNum` / `Action::GetUrl2` 2022-04-03 10:32:31 -07:00
Toad06 e93d39fdfe avm1: `DefineLocal` also accepts dot and slash paths 2022-04-02 14:30:56 -07:00
relrelb c8e7bdbce2 core: Fix loading of unknown data
Loading unknown data is not considered an error on Flash; Both
`onLoadProgress` and `onLoadComplete` events are dispatched. But,
`onLoadProgress` reports 0 bytes loaded.
2022-04-02 12:50:43 -07:00
relrelb e06506c2b9 render: Implement `CMYK32` jpeg pixel format 2022-04-02 01:17:38 +03:00
Aaron Hill 4f23500779 avm2: Implement most of `flash.external.ExternalInterface`
This re-uses the logic we have for handling AVM1's `ExternalInterface`.
For now, serialization/deserialization of non-array objects is
left unimplemented.
2022-03-31 22:40:09 -07:00
Mike Welsh 659db7facc avm1: Add2 calls valueOf for objects 2022-03-31 16:57:07 -07:00
Adrian Wielgosik a929a4becd avm2: Do not borrow Object's lock just to get the bound method 2022-03-31 16:56:55 -07:00
Adrian Wielgosik 7e8738d82e avm2: Add ContextMenuEvent stub 2022-03-30 21:42:48 +02:00
Adrian Wielgosik ef64413b8c avm2: Support ContextMenuItem fields 2022-03-30 21:42:48 +02:00
Adrian Wielgosik ea56902d80 chore: cargo fmt 2022-03-30 21:42:48 +02:00
Adrian Wielgosik 90b1d4722c avm2: Add ContextMenuItem stub 2022-03-30 21:42:48 +02:00
Adrian Wielgosik 2389422c99 avm2: Add ioErrorEvent stub 2022-03-30 21:42:48 +02:00
Adrian Wielgosik 388dc6fe31 avm2: Add customItems to ContextMenu stub 2022-03-30 21:42:48 +02:00
Mike Welsh d920dfa9b0 core: Add padding on autosized TextFields 2022-03-29 22:22:32 -07:00
Mike Welsh a671d2977b core: Pre-multiply alpha when loading PNG/GIF data (fix #6559)
When decoding PNG/GIF data, convert the image to premultiplied
alpha so that it plays nicely with the renderer.

This applies to both dynamically loaded images and to PNG/GIF data
embedded inside a DefineBitsJPEG tag. This is in contrast to
DefineBitsLossless and DefineBitsJPEG tags w/ alpha, which are
already premultiplied in the SWF.

Also remove unnecessary clamps now that Rust defines casts as
saturating.

Fixes #6559.
2022-03-29 13:41:04 -07:00
Mike Welsh 9c50770c1c avm1: Return Value from `abstract_lt`
All callers converted the result to `Value` anyway.
2022-03-28 19:07:12 -07:00
Mike Welsh 98ea2f81b6 avm1: {} < {} returns false
The Less2 op returns false if the `valueOf` of either parameter
results in an object. The exception is display objects:
`mc < mc` returns undefined.
2022-03-28 19:07:12 -07:00
David Wendt b9da107339 core: Refactor `MovieClipLoader` broadcast messages into separate `Loader` associated functions.
These are *not* methods, because we cannot borrow both the update context and the loader at the same time. At least not without making loaders free-standing objects (`GcCell`s), which I don't want to do yet.
2022-03-27 18:55:38 -07:00
David Wendt ac7bb84e08 core: Report unexpected content type errors better. 2022-03-27 18:55:38 -07:00
David Wendt 27697c6611 chore: No, loading an image does not replace the clip with a bitmap. 2022-03-27 18:55:38 -07:00
David Wendt e1d18be7fa core: First pass at image loading through `loadMovie` et all 2022-03-27 18:55:38 -07:00
Toad06 4ad0253076 avm1: `String(function)` returns `[type Function]` 2022-03-27 11:39:44 -07:00
relrelb 1c576816b6 core: Refactor `LoadManager::load_form_into_load_vars`
Make it call `navigator.fetch()` directly rather than receiving an
existing `Future`.
2022-03-26 15:56:06 -07:00
relrelb f3c22d930b core: Refactor `LoadManager::load_form_into_object`
Make it call `navigator.fetch()` directly rather than receiving an
existing `Future`.
2022-03-26 15:56:06 -07:00
relrelb 83353e17c5 core: Refactor `LoadManager::load_movie_into_clip`
Make it call `navigator.fetch()` directly rather than receiving an
existing `Future`.
2022-03-26 15:56:06 -07:00
relrelb 7e4b3c1003 core: Refactor `LoadManager::load_root_movie`
Make it call `navigator.fetch()` directly rather than receiving an
existing `Future`.
2022-03-26 15:56:06 -07:00
Moulins 1bff5c517a Move back AvmString into ruffle_core::string
This allows removing the gc_arena dependency in ruffle_wstr
2022-03-26 13:42:57 -07:00
Moulins 1911aa9a6b Move core::string into separate ruffle_wstr crate. 2022-03-26 13:42:57 -07:00
relrelb 1230b5e713 swf: Use bitflags for `FontFlag` 2022-03-26 11:33:26 -07:00
relrelb 71a1757d29 swf: Make `Glyph::advance` non-`Option`
Simply use `0` instead of `None`.
2022-03-26 11:33:26 -07:00
relrelb 984342abf3 swf: Avoid some `Vec::resize` usages
Use the `vec![]` macro instead.
2022-03-26 11:33:26 -07:00
relrelb 8f7b8c4b76 xml: Make `XmlNodeData` a struct
The difference between element nodes and text nodes is very minor.
So instead of representing them by two distinct enum members, make
`XmlNodeData` a single unified struct that can represent both. A new
`node_type` field is introduced, in order to still distinguish
between element and text nodes. Also, Ruffle made some incorrect
assumptions, which are now corrected, including:

* Nodes can have any arbitrary `u8` type. This is resolved by the
introduction of the `node_type` field which is a `u8`.
* Text nodes can have children. This is resolved by simply not checking
for text nodes in `append_child` etc.
2022-03-26 10:12:47 -07:00
relrelb 161071e8c4 core: Re-implement `NullExecutor`
Make it a thin abstraction layer over either the `futures` or `wasm-bindgen-futures`
crates, as already done in `render/wgpu/src/uniform_buffer.rs`,
instead of a hand-made single-thread executor.

Ideally this would also be usable on desktop, but I didn't manage to
get `LocalPool` working with `winit` (it needs to post a task to the
`EventLoopProxy` as a wake procedure).
2022-03-26 10:03:42 -07:00
Moulins bb63ac2de7 wstr: fix memory leak
WString's Drop impl didn't actually drop anything
2022-03-25 18:36:00 -07:00
Toad06 c1119fdc0b avm1: Apply autosize to a new `EditText` from an SWF `DefineEditText` tag 2022-03-21 20:00:06 -07:00
Aaron Hill a281db3af6 Add `define_indirect_properties` helper macro for property/slot pairs
In both `FrameLabel` and `Scene`, we define multiple
'public property / private slot' pairs.
The public property has a getter which delegates to the private
property. There is no setter for the property, ensuring that
the private slot can only be modified from within Ruffle itself.

This PR adds a macro `define_indirect_properties` to abstract over
this pattern. Currently, it only supports the read-only property
pattern - however, it could be extended in the future to generate
a setter that invokes a caller-provided callback function.

This needs to be a macro (rather than a method) so that we can
generate a function with the property name hard-coded into it.
Using a closure that references an upvar will not work, since
`Method::from_builtin` requires a function pointer.
2022-03-21 19:00:25 -07:00
relrelb b7a60384cf xml: Inline `update_id_map`
Move its logic to `from_start_event`, where `XmlNode`s are created.
2022-03-20 11:04:48 +02:00
relrelb 724f4165d6 avm1: Implement `nodeName` and `nodeValue` setters
These are actually handled by the same function.
2022-03-19 16:31:24 -07:00
relrelb f9dff4191b xml: Remove `XmlNodeData::DocumentRoot`
Document roots (a.k.a. `XML` objects) are very similar to regular
element nodes (a.k.a. `XMLNode` objects). The primary difference is
that `XML` objects return `null` for their `nodeName`. But this can
be changed too; Setting `xml.nodeName = "someName"` will make `XML`
objects behave much like `XMLNode`. Moreover, many checks in Ruffle
that refuse to operate on document roots were wrong, and actually
these should be accepted as normal element nodes.
Besides the functional corrections, this also simplifies the code.
2022-03-19 16:31:24 -07:00
relrelb fa70cc07ab xml: Inline `text_from_text_event` and `is_whitespace_text` 2022-03-19 15:08:16 -07:00
relrelb b31e826ee6 core: Simplify `SwfMovie` parsing in `Loader`
This also slightly changes behavior: Previously `SwfMovie::from_data`
errors were propagated as `FetchError` and `display_root_movie_download_failed_message`
was called, offering the user to sidestep CORS by opening the SWF
in a new tab. But that wouldn't help, obviously, because no network
error is involved. Now, these errors are propagated as `InvalidSwf`,
and `display_root_movie_download_failed_message` is not called.
2022-03-17 20:31:59 -07:00
relrelb ad944800be core: Perfer `Loader`'s `FetchError`
`NetworkError` and `NetworkUnavailable` were rarely used, and they
were very similar to `FetchError`.
2022-03-17 20:31:59 -07:00