Commit Graph

3074 Commits

Author SHA1 Message Date
TÖRÖK Attila b31ad28960 avm1: Make add_field_accessors! accept nested field names 2021-08-20 21:29:54 -06:00
TÖRÖK Attila 57ccb714c6 core,avm1: Extract ColorTransformParams from ColorTransformData 2021-08-20 21:29:54 -06:00
TÖRÖK Attila 2048bb9887 core,avm1: Move BitmapData implementation into core::bitmap from core::avm1::object
This enables exposing it to AVM2 as well in the future.
2021-08-20 21:29:54 -06:00
Ray Redondo 27e06af003
avm2: Initial MouseEvent stubs (#5065)
* avm2: Start MouseEvent stubs

* avm2: More MouseEvent work

* chore: clippy

* chore: fmt

Co-authored-by: Adrian Wielgosik <adrian.wielgosik@gmail.com>
2021-08-21 01:26:34 +02:00
Chris Midgley 58c907e985
avm2: implement string.split for undefined (#5064)
* avm2: implement string.split for undefined

* chore: cargo fmt

* dev: avoid explicit ArrayStorage
2021-08-18 18:02:41 +02:00
relrelb da7cd453cf chore: Fix png update 2021-08-18 09:01:21 +03:00
dependabot[bot] 0e408052b1 chore: Bump png from 0.16.8 to 0.17.0
Bumps [png](https://github.com/image-rs/image-png) from 0.16.8 to 0.17.0.
- [Release notes](https://github.com/image-rs/image-png/releases)
- [Changelog](https://github.com/image-rs/image-png/blob/master/CHANGES.md)
- [Commits](https://github.com/image-rs/image-png/commits)

---
updated-dependencies:
- dependency-name: png
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-18 09:01:21 +03:00
relrelb ac3c198bda chore: Appease clippy 2021-08-18 08:01:57 +03:00
dependabot[bot] b8a9e28acb chore: Bump bitstream-io from 1.1.0 to 1.2.0
Bumps [bitstream-io](https://github.com/tuffy/bitstream-io) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/tuffy/bitstream-io/releases)
- [Commits](https://github.com/tuffy/bitstream-io/compare/v1.1.0...v1.2.0)

---
updated-dependencies:
- dependency-name: bitstream-io
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-17 08:24:29 +03:00
dependabot[bot] a317a09d17 chore: Bump bitflags from 1.2.1 to 1.3.2
Bumps [bitflags](https://github.com/bitflags/bitflags) from 1.2.1 to 1.3.2.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/1.2.1...1.3.2)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-16 23:41:06 +03:00
Adrian Wielgosik f4da77c400 Use a more idiomatic pattern for unwrap-or-default 2021-08-15 21:55:49 +02:00
David Wendt f37a06241a chore: Clippy compliance with latest nightly compiler 2021-08-14 19:51:24 -06:00
Ray Redondo cfb2bb99d6 chore: appease clippy 2021-08-14 00:52:38 +02:00
Ray Redondo 638eaf4a55 avm2: Rename function, add runtime warnings 2021-08-14 00:52:38 +02:00
Ray Redondo 171a41b908 avm2: Add define_public_builtin_class_traits and repair Capabilities to use it 2021-08-14 00:52:38 +02:00
Ray Redondo c43f57e5f5 avm2: Implement `String.split` 2021-08-14 00:52:38 +02:00
Ray Redondo 22c6f7321e avm2: start flash.system.Capabilities stubs 2021-08-14 00:52:38 +02:00
Tal Hayon 332f1d47bb core: Reset mouse visible when loading movie to root (Fixes #4358) 2021-08-11 23:18:57 +02:00
David Wendt 84f17d1222 chore: Update `flash-lso`'s dependent commit ID 2021-08-09 18:47:03 -06:00
relrelb d40cf5aee4 avm1: Log internal error on `InvalidSwf`
This gives more percise error logs that ease finding their root
cause. Also remove `is_halting` and express it inline instead.
2021-08-03 14:40:59 -07:00
Tal Hayon 6762675bb5 core: Fixes several text edit font and bullet issues (parts of #1167) 2021-08-03 13:08:06 -07:00
dependabot[bot] 36e96b7272 chore: Bump serde from 1.0.126 to 1.0.127
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.126 to 1.0.127.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.126...v1.0.127)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-03 10:18:58 +03:00
Adrian Wielgosik b940e7f00f Extension: Sidestep CORS issues by offering to load the SWF in a tab 2021-08-02 21:28:16 +02:00
relrelb 141f886cdd avm1: Remove `TObject::set_proto`
The last usage of it was in `Player`, which anyway should operate
only on newly created objects that don't have any virtual properties
nor watchers. So it is safe to replace with `define_value`, that
also cannot fail.
2021-07-30 17:42:42 -07:00
relrelb fd3f9f34de avm1: Store `__proto__` as a regular property
`__proto__` seems to behave much like a regular data property. So
simply remove the `prototype` field of `ScriptObject` in favor of
storing the prototype in the general properties hash map.
2021-07-30 17:42:42 -07:00
relrelb 6b91239e28 avm1: Don't rely on prototypes during serialization
Instead, rely on the `TObject::as_*` methods to tell what kind the
serialized object is.
2021-07-24 04:12:34 -07:00
relrelb 06fce44665 avm1: Fix performance regression in `BitmapData::pixels_rgba`
It was regressed in #4822 when changed to use `flat_map`. But
currently Rust emits suboptimal code for such case. For now use
`Vec::with_capacity` manually to avoid unnecessary re-allocations.
2021-07-24 03:28:35 -07:00
EmperorBale 1dee1e4166 avm2: Implement flash.crypto.generateRandomBytes 2021-07-21 18:09:21 +02:00
David Wendt db86ca84b9 avm2: `get_property` does not mutate the underlying object (anymore) so it should not be flagged as mutably borrowing it. 2021-07-20 22:14:05 -04:00
David Wendt c30014baed avm2: Remove `ScriptObjectClass` and replace with separately implemented methods on `ClassObject` 2021-07-20 22:12:33 -04:00
David Wendt 4d89341e19 avm2: Cache the instance allocator on class objects 2021-07-20 22:12:33 -04:00
David Wendt 2c927f2b6b avm2: Make `coerce_to_type` take a class object instead of a multiname. 2021-07-20 22:12:33 -04:00
David Wendt bd2f758976 avm2: Don't call native initializers when coercing primitives into objects.
The former native initializer call was incorrect and would cause spurious coercion failures. Since existing code assumes the error fork of `coerce_to_object` means undefined or null, this was causing coercions and parameter typechecks against primitives to fail in the most general case.

Attempting to fix this by providing the primitive value as native initializer argument instead causes a stack overflow. This is because native initializer arguments still have to be typechecked, and in the most general case this means... coercing the primitive value we're already coercing into an object... into another object. This won't work.

Since primitive initializers aren't going to do anything that native coercions need to care about, I'm just removing the initializer call.
2021-07-20 22:12:32 -04:00
David Wendt 30b4c4386b avm2: Replace the `call_strict` mechanism with checking to see if free functions are unchecked. 2021-07-20 22:12:32 -04:00
David Wendt ddd73b3cd6 avm2: Supercalls should fall back to normal receiver access if there is no matching supertrait to use. 2021-07-20 22:12:31 -04:00
David Wendt e9b9d64cb6 avm2: Rename `StageObject::graphics_of` to just `graphics` 2021-07-20 22:12:30 -04:00
David Wendt 7871912d92 avm2: Calling ES4 class objects is treated as a coercion to that type. 2021-07-20 22:12:28 -04:00
David Wendt ef4b6876db core: MovieClips should initialize their AVM2 sides by calling `call_native_init`. 2021-07-20 22:12:28 -04:00
David Wendt b469ef8a3f avm2: Replace `deriver` language with `allocator` language 2021-07-20 22:12:28 -04:00
David Wendt 8af0481a23 avm2: Retire the use of "constructor" outside of literal reference to class initializer or instance initializer code.
Instead, the following terms are used:

 * Static classes, to refer to `Class<'gc>`. Shortened to "class" in contexts where this is not ambiguous.
 * Class objects, to refer to objects that represent a particular class. Also shortened to "class" in non-ambiguous contexts.

Downstream of this, the `base_constr` (referring to the class that a currently called trait has been pulled from) is now called `subclass_object` and several `TObject` methods have also been renamed.
2021-07-20 22:12:23 -04:00
David Wendt 6d907a0d10 avm2: Rename `ArrayObject::empty_array` to `ArrayObject::empty`. 2021-07-20 22:10:36 -04:00
David Wendt 05b7de7453 avm2: Avoid double iteration in `Names.contains_name` 2021-07-20 22:10:36 -04:00
David Wendt 6e2e686e0d avm2: Rename `Method::Entry` to `Method::Bytecode` 2021-07-20 22:10:35 -04:00
David Wendt b049f2e717 avm2: Rename `Method::from_builtin_only` to `Method::from_builtin` 2021-07-20 22:10:35 -04:00
David Wendt d4fcca9787 avm2: Rename `call_initializer` and `call_native_initializer` to `call_init` and `call_native_init` 2021-07-20 22:10:34 -04:00
David Wendt f5431a781e docs: Fix stale comments in avm2 2021-07-20 22:10:34 -04:00
David Wendt ccfa605260 avm2: Use `extend_from_slice` 2021-07-20 22:10:34 -04:00
David Wendt a60a499f31 avm2: Rename `resolve_parameter_value` to `resolve_parameter` 2021-07-20 22:10:33 -04:00
David Wendt 9e997e6571 avm2: Split out `Method` and `Executable`'s native fork into `NativeMethod` and `NativeExecutable`, respectively.
This also implies renaming the existing type alias of the same name to `NativeMethodImpl`.
2021-07-20 22:10:33 -04:00
David Wendt c7858f9447 avm2: Simplify/correct the value numerical checks 2021-07-20 22:10:32 -04:00
David Wendt 5018421eef avm2: Rename `SystemConstructors` to `SystemClasses` 2021-07-20 22:08:27 -04:00
David Wendt 2c2f03ba23 chore: Clippy compliance on Rust nightly 2021-07-20 22:05:37 -04:00
David Wendt d0478a1f40 avm2: Allow builtins to also hold parameter type metadata.
This is limited by the fact that we currently cannot store type metadata in static tables. I don't think it's necessary to do so as of yet as pretty much every actual parameter type I *could* shove in here turned out to be optional and broke tests if it wasn't. Still, it's probably useful enough for new classes to include.
2021-07-20 22:05:36 -04:00
David Wendt e38b1bc281 avm2: Make numbers appear to be of any numeric type that can represent them.
This also prevents an exception from being fired when testing `undefined` or `null`, which are valid inputs to `istype`.
2021-07-20 22:05:35 -04:00
David Wendt 974fe152ff avm2: Include the parameter coercions into `op_coerce` 2021-07-20 22:05:34 -04:00
David Wendt 8b48b79f5d avm2: Make the `pool_` and `table_` functions no longer take a superfluous mutation context.
This also adds a new `pool_multiname_static_any` method that treats zero as `*` instead of an error.
2021-07-20 22:05:33 -04:00
David Wendt abc9d0800a avm2: `undefined` is normalized to `null` for string and object coercions 2021-07-20 22:05:32 -04:00
David Wendt b779804075 avm2: Relax the maximum arguments check for functions called from native code. 2021-07-20 22:02:11 -04:00
David Wendt ae086d6aa7 avm2: Implement implicit coercion for primitive types 2021-07-20 22:02:10 -04:00
David Wendt 63cf6a7b47 avm2: Implement parameter typechecking for script functions.
This commit breaks 15 tests, mostly due to implicit coercion that happens at function call time. This will be implemented shortly.
2021-07-20 22:02:10 -04:00
David Wendt 65ffa0684b core: Use the new construct pathway for building AVM2 `TextFormat` objects 2021-07-20 22:02:09 -04:00
David Wendt 5c6c3191ef avm2: Enforce `final` on traits. 2021-07-20 22:02:09 -04:00
David Wendt 7d86c93ddc Check to make sure that overrides only apply to already-installed properties. 2021-07-20 22:02:08 -04:00
David Wendt 5662527c9e avm2: Enforce `interface` checks: classes cannot extend interfaces and cannot implement other classes. 2021-07-20 22:02:08 -04:00
David Wendt 7eca7d5331 avm2: Enforce `final` on classes 2021-07-20 22:02:07 -04:00
David Wendt 3888d5bb27 avm2: `install_dynamic_property` now checks to see if the object is sealed, and if so, throws an error. 2021-07-20 22:02:07 -04:00
David Wendt 03980f4f3d avm2: `Function.prototype`'s properties are not methods. 2021-07-20 22:02:06 -04:00
David Wendt c10a25fb3f avm2: Remove the special global constructor scope mode we added two commits ago. 2021-07-20 22:02:05 -04:00
David Wendt 0e40552c2a avm2: Don't instantiate classes or functions at trait install time. 2021-07-20 22:02:05 -04:00
David Wendt 377730301f avm2: Add a special object mode for `globals` so that it can get it's own scope during trait installation.
This is very wrong: Strictly speaking, we should not be instantiating anything that needs a scope when we install the trait. We just create a slot for it to go into. Script initializers are responsible for providing a scope stack to instantiate traits into.
2021-07-20 22:02:04 -04:00
David Wendt a112192c96 avm2: Remove `_slot_local` methods as we no longer do anything special with slots. 2021-07-20 22:02:04 -04:00
David Wendt 5dcc3a58f2 avm2: Remove lazy trait initialization 2021-07-20 22:02:03 -04:00
David Wendt 7e3c017a63 avm2: `broadcast_event` should use constructors for it's type checks. 2021-07-20 22:02:02 -04:00
David Wendt 1c72167287 avm2: Make `istype` use the constructor chain, not the prototype chain.
This pushes a few more ancillary changes:

 * `has_proto_in_chain` no longer checks interfaces (since it exists to serve `instanceof`, which does not respect them)
  * Interfaces no longer live on prototypes. They now live on class constructors.
2021-07-20 22:01:57 -04:00
David Wendt 713ab3e95c avm2: Remove all remaining accesses to `SystemPrototypes`, save for one technicality with the global scope prototype. 2021-07-20 22:00:34 -04:00
David Wendt f84f01b2a5 avm2: Adjust the `FunctionObject` associated constructors so that there's a path that doesn't require the user hit `SystemPrototypes`.
Because we have stuff running in early globals, we stlil need a more elaborate version of this function that *does* take `fn_proto`. We also can't pull `scope` from the activation since this gets called to install traits.
2021-07-20 22:00:34 -04:00
David Wendt e4201625a1 avm2: Split `StageObject` associated constructors into two versions: allocation-only (`for_display_object`) and allocation-and-initialization (`for_display_object_childless`).
The latter is intended for display objects that *do not* have children and can be both allocated and initialized in one shot. Hence the name.
2021-07-20 22:00:33 -04:00
David Wendt 46a4da9dc5 avm2: Remove `XmlObject::empty_object` as it does not appear to be in use and will need further elaboration when XML is unstubbed. 2021-07-20 22:00:32 -04:00
David Wendt 602895e2de avm2: Make `RegExpObject::from_regexp` pull it's own constructor and call it's own initializer.
This doesn't appear to actually be in use, but I'm doing it for completeness' sake.
2021-07-20 22:00:32 -04:00
David Wendt c167912f52 avm2: `PrimitiveObject::from_primitive` should now select it's own class and construct it.
This also includes protections on `String` to prevent it from overwriting itself. All user-constructed primitive objects start out boxing `Value::Undefined` and future constructor implementations should check what's already been boxed before overwriting it with user arguments.
2021-07-20 22:00:31 -04:00
David Wendt 261cb40a22 avm2: Make `NamespaceObject`'s sole associated method build and construct a `Namespace` instance. 2021-07-20 22:00:29 -04:00
David Wendt b30c7509ba avm2: Make `LoaderInfo`'s associated methods call initializers and pull their constrs/protos as necessary 2021-07-20 21:59:21 -04:00
David Wendt 60eb1b4409 avm2: Don't ask for a `proto` in `EventObject::from_event`.
For various reasons, this is kind of incomplete:

1. We need to support native event subclasses, so we can't just pull one class from `activation` (yet).
2. We can't run native instance initializers without overwriting the native object.

I expect these to be fixed in a future PR where I start adding native event types.
2021-07-20 21:59:21 -04:00
David Wendt 22fedf4dca avm2: Make all domain object construction (save for the global domain) pull the constructor and call it in `from_domain`.
This also adds `DomainObject::script_global`, which does the same thing but picks the `global` class instead of `ApplicationDomain`.
2021-07-20 21:59:20 -04:00
David Wendt 6fe44c3862 avm2: Clean up `ClassObject` initialization.
This also makes it more difficult to accidentally build a class without calling it's initializer. Native/builtin class initializers should also be running now, too.

The only minor bit of jank is that we need a class initialized bit to flag classes we've already run, because our current lazy-init design for traits causes classes to be constructed twice. This is temporary and I intend to remove it along with lazy-init traits.
2021-07-20 21:59:18 -04:00
David Wendt 31faf62baf avm2: Remove all alternative `ByteArrayObject` constructors.
The only way to build a `ByteArrayObject` now is to invoke it's constructor.
2021-07-20 21:58:06 -04:00
David Wendt 9604b525d5 avm2: Tie `ArrayObject`'s constructors to the system `Array` class.
This effectively turns calling `ArrayObject`'s associated methods into an alternate constructor path. We even make sure to run instance initializers. You also no longer have to grab the `array` system constructor, so we get to remove that code.
2021-07-20 21:58:05 -04:00
David Wendt 46db756f67 avm2: Don't run `Point`'s constructor twice when natively constructing one. 2021-07-20 21:58:04 -04:00
David Wendt c8cd6e0322 avm2: Split native and script instance initializers for non-constructable classes.
This also includes new errors for attempting to construct non-constructables like `System`.
2021-07-20 21:58:04 -04:00
David Wendt dcbb5e4284 avm2: Add a notion of native instance initializers.
Native initializers are a separate, parallel initialization chain intended for all object construction that is not directly triggered by `Op::Construct` and friends. This allows us to implement classes that cannot be directly constructed by user code, but can be constructed by native code or supercalled into from non-native.
2021-07-20 21:58:03 -04:00
David Wendt 4bc1d37029 avm2: Remove unnecessary manual accesses of the `constructor` property on prototypes.
All native object allocation in the project now pulls prototypes or constructors as necessary from the following sources:

 * System prototype or constructor lists
 * Instance `constr`s

This also resulted in the removal of a few unnecessary prototype accesses.
2021-07-20 21:57:56 -04:00
David Wendt afd5a65a1e avm2: Create a new list of system constructors alongside the existing list of system prototypes. 2021-07-20 21:55:30 -04:00
David Wendt b0c38c9d4a avm2: `Graphic` construction shouldn't use the `Shape` proto as it's base constructor.
This fixes the last broken test.
2021-07-20 21:55:29 -04:00
David Wendt 6deaa6f441 avm2: Remove the prototype setter exception as prototypes no longer provide setters to instances. 2021-07-20 21:55:29 -04:00
David Wendt a8fd0622b2 avm2: Filter traits in `call_instance_xyz` by the trait type before actually getting trait fields.
Fixes the `as3_virtual_properties` test, where the old approach would accidentally grab a `Getter` and then think there's no setter (there is, you just have to look further down the list).
2021-07-20 21:55:29 -04:00
David Wendt a2cd7443e8 avm2: Do not attempt to `super_init` the `LoaderInfo` object.
This is a temporary fix for failing tests; it is invalid in the sense that attempting to grab loader events will now fail. We can't actually correctly init the loader without two planned changes:

1. Moving all object initialization into the object helper functions (e.g. `LoaderInfoObject::from_movie`)
2. A notion of "native-only" constructors separate from the existing constructor chain

Once those are in place, loaders should be proper event dispatchers again.
2021-07-20 21:55:29 -04:00
David Wendt 1ad512e3c9 avm2: Allow constructing activation objects (since we now force instance constructors to run) 2021-07-20 21:55:28 -04:00
David Wendt 323da9ded3 avm2: Move the class association from prototypes to instances.
This also incurred a large number of ancillary changes, as it turns out nearly every native object is currently pulling a prototype and sticking it into an object. Right now, I have it instead pulling the constructor out of the prototype, but a future PR will also remove `system_prototypes` as well.

Other ancillary changes include:

 * `Domain` now supports partial initialization to avoid an order-of-events issue. Accessing domain memory on a partially-initialized `Domain` will panic.
 * `Domain` construction requires a full `activation` now, except for `global_scope` which needs to be initialized later with valid domain memory before user code runs.
 * Pretty much every native object constructor now takes a proto/constr pair
 * Trait lookup was rewritten to handle this. It's still buggy - seven tests don't work
 * `TObject.construct` now actually does the full object construction dance. This allows `ClassObject` to implement the ES4 object construction pathway directly while `FunctionObject` maintains ES3 compatibility.

This is a tentative commit; there are still seven failing tests that I need to fix.
2021-07-20 21:55:25 -04:00
David Wendt f26f193508 avm2: Store instance derivers as a `Class` property instead of keeping them only as a globals concept 2021-07-20 21:47:00 -04:00
David Wendt 47de2364c1 avm2: Split `Class` and `Function` object types 2021-07-20 21:46:54 -04:00