Commit Graph

5139 Commits

Author SHA1 Message Date
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
relrelb d2eb46d3be chore: Reserve capacity for vectors
This avoids unnecessary re-allocations and thus should improve
performance in both memory and time terms.
2021-07-20 16:25:23 -07:00
dependabot[bot] ca2d17ade6 chore: Bump env_logger from 0.8.4 to 0.9.0
Bumps [env_logger](https://github.com/env-logger-rs/env_logger) from 0.8.4 to 0.9.0.
- [Release notes](https://github.com/env-logger-rs/env_logger/releases)
- [Changelog](https://github.com/env-logger-rs/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/env-logger-rs/env_logger/compare/v0.8.4...v0.9.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-19 23:49:40 +03:00
relrelb 536526a342 avm1: Rename `set_watcher` and `remove_watcher` to `watch` and `unwatch`
This better reflects their correspondence to `Object.watch` and
`Object.unwatch` respectively.
2021-07-18 23:19:19 +03:00
relrelb e8e0467673 avm1: Replace `get` + `call` with `call_method` 2021-07-18 23:19:19 +03:00
relrelb 3576a199cd avm1: Replace `set` + `set_attributes` with `define_value` 2021-07-18 23:19:19 +03:00
relrelb c609fa937d avm1: Remove unnecessary type annotations 2021-07-18 23:19:19 +03:00
relrelb ea73dbc367 avm1: Remove `StageObject::as_executable`
It was identical to the default implementation of `TObject`, and
thus unnecessary.
2021-07-18 23:19:19 +03:00
relrelb 3ddd8ff31c tests: Add as_set_prop_flags 2021-07-18 20:03:52 +03:00
relrelb 0367f6a8d4 avm1: Correct `ASSetPropFlags`
* The properties parameter is evaluated last. This is observable by
the order the `toString`/`valueOf` methods of the parameters are
called.
* Only `null` in the property list parameter configures all properties,
as opposed to `undefined`, `null`, numbers and booleans previously.
* Objects in the property list parameter are not handled specially.
Instead, they're also coerced to string and split by comma.
2021-07-18 20:03:52 +03:00