Commit Graph

5173 Commits

Author SHA1 Message Date
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 b2c1299f79 tests: Add a test for bare calls on the ES4 class object 2021-07-20 22:12:28 -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 7dc86fdeb0 swf: Throw an error if an ABC bitstream calls for a parameter with more optional parameters than actual ones. 2021-07-20 22:10:30 -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 21a994ee8a tests: Actually run the `istypelate_coerce` test 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 2d3ef5493b tests: Add tests for default parameters, type checks, and implicit typecheck coercions 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 4122c1b96e swf: Default method parameters are indexed starting from the first optional parameter, not from zero. 2021-07-20 22:05:29 -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