Commit Graph

2217 Commits

Author SHA1 Message Date
David Wendt 67744650f1 Pass the ABC name and lazy init flag to the AVM2. 2020-07-13 17:44:25 -04:00
David Wendt 6cc3f7ecc3 Add a test for stored properties as well.
This test passed with no errors.
2020-07-13 17:44:24 -04:00
David Wendt 5abc78d3bd Add test of AVM2 virtual properties.
This tests:

 * Getter invocation
 * Setter invocation
 * Properties with one or the other, but not both
 * Inheritance
 * Superproperty getters and setters
 * Getters with inherited setter
 * Setters with inherited getter
2020-07-13 17:44:24 -04:00
David Wendt c5e3af2053 When resolving `get_property`, skip over virtual properties that do not have a defined getter. 2020-07-13 17:44:23 -04:00
David Wendt 54b792ef3a Ensure that called setters are properly resolved so that errors in setters propagate up the Rust stack correctly.
The previous system for handling setters would execute the setter and then return a value to indicate whether or not the caller needed to resolve a stack frame. However, no caller of `Property.set` actually did this. Ergo, errors in setters and getters would not resolve up the stack at the correct time.

This problem also exists in AVM1 but is far less noticable as AVM1 only has two very uncommon runtime errors and very few movies use `throw`.
2020-07-13 17:44:23 -04:00
David Wendt b8106d24d2 Ensure virtual setters are run when defined on a prototype.
Normally, `set_property` only affects the object it was called on, which makes sense: otherwise, we couldn't override values that originate from a class prototype without accidentally monkey-patching the prototype. However, virtual setters only exist in prototypes and need to be accessible from child objects.

The solution to this is to have a specific method to check if a virtual setter exists. Virtual setters are then resolved through the prototype chain. If no virtual setter exists, then the reciever object is handed the value.

Note that we always use the `reciever` object rather than `self` so that `setsuper` can work correctly. In `setsuper`, we resolve the base class, and then set properties on it with the actual object in question as it's reciever. If a virtual setter is called, it will get the actual object it should be manipulating; and otherwise, prototypes will not be modified or consulted.
2020-07-13 17:44:22 -04:00
David Wendt 665d7a4342 Implement `getsuper` and `setsuper`.
This required the reintroduction of dedicated reciever parameters to `Object.get_property_local` and `Object.set_property`, which I had removed from the AVM1 code I copied it from. It turns out being able to change the reciever was actually necessary in order to make super set/get work.
2020-07-13 17:44:22 -04:00
David Wendt 785832b7f3 Add `as3_inheritance` test, which is primarily designed to test method calls, constructor execution, and usage of `super`. 2020-07-13 17:44:22 -04:00
David Wendt e8fbac6cf2 Refactor the base_proto system to more accurately record what prototype methods come from.
The previous system primarily relied on `Executable` to automatically start and continue a super chain. This works, but only for class hierarchies without *override gaps* - methods that override another method not defined by the direct superclass of the method. In that case, the override method would be called twice as the `base_class` was moved up one prototype at a time, which is wrong.

The new system relies on the call site to accurately report the prototype from which the current method was retrieved from. Super calls then start the resolution process *from the superclass of this prototype*, to ensure that the already-called method is skipped.

It should be noted that the proper `base_class` for things like `callmethod`, `callstatic`, `call`, `get`/`set` methods, and other call opcodes that don't use property look-up are best-effort guesses that may need to be amended later with better tests.

To facilitate `base_proto` resolution, a new `Object` method has been added. It's similar to `get_property`, but instead returns the closest prototype that can resolve the given `QName`, rather than the actual property's `ReturnValue`. Call operations use this to resolve the `base_proto`, and then resolve the method being called in `base_proto`. The existing `exec_super` method was removed and a `base_proto` method added to `exec` and `call`.
2020-07-13 17:44:21 -04:00
David Wendt 43da7ac952 `resolve_multiname` should actually return it's prototype's return value. 2020-07-13 17:44:20 -04:00
David Wendt ab5a95c05b Add a test for various types of class methods. 2020-07-13 17:44:19 -04:00
David Wendt 1c3b9c50fe Implement prototype awareness for `get_property`, `has_property`, and `resolve_multiname`.
Furthermore, implement `has_own_property`.
2020-07-13 17:44:19 -04:00
David Wendt fa4369da72 Execute static class initializers.
This also fixes the lack of function prototype on classes.
2020-07-13 17:44:18 -04:00
David Wendt 687a82f643 Constructors should also inherit closure scope. 2020-07-13 17:44:18 -04:00
David Wendt 73966f1b31 Make sure that we actually call the super constructor, not our own constructor. 2020-07-13 17:44:17 -04:00
David Wendt 1b67bb94c8 Impl `callsuper`, `callsupervoid`, and `constructsuper`.
This works primarily by retaining the current superclass prototype in the activation object and then using it to retrieve the super method.

For constructors, we implement the `constructor` property, which is probably not the correct way to do this.
2020-07-13 17:44:15 -04:00
David Wendt f3dee5c310 Add (currently failing) test for constructors. 2020-07-13 17:44:14 -04:00
David Wendt a77f676279 `construct` and `constructprop` should push the object that was just constructed. 2020-07-13 17:44:13 -04:00
David Wendt 0fc9b9a287 `construct` and `constructprop` should take their args in reverse-order like the call functions do. 2020-07-13 17:44:13 -04:00
David Wendt 9431e02802 The class function should use the *instance* initializer as it's callable, not the class initializer. 2020-07-13 17:44:13 -04:00
David Wendt bedf5cb459 Add a basic test for function calls. 2020-07-13 17:44:13 -04:00
David Wendt 38868fbdfe Args are pushed onto the stack in normal order, so we need to pop them off in reverse order. 2020-07-13 17:44:12 -04:00
David Wendt a2dfffc56e Add our first AVM2 regression test: hello world! 2020-07-13 17:44:09 -04:00
David Wendt 7d576203c9 Impl `coerce_a`.
This currently treats `coerce_a` as a no-op. Strictly speaking, this is for type verification purposes, but we currently don't type-verify ABC code. Ergo, this requires no VM support at this time.
2020-07-13 17:43:50 -04:00
David Wendt a0ab978bed Impl `callmethod`, `callproperty`, `callproplex`, `callpropvoid`, and `callstatic`.
Also, implement a method table that method traits can optionally add themselves to.

Also also, add the ability to invoke a method without a `this` object. This required a non-trivial refactoring of the activation machinery, and changes to the signature of `NativeFunction`, and all native AVM2 functions.
2020-07-13 17:43:49 -04:00
David Wendt 68cf9e8869 Upon encountering an `Err`, dispose of the current AVM2 stack.
In the future, the `unwrap_stack_frame` mechanism should be expanded upon to allow running exception handlers and recovering from a Rust error - but not today.
2020-07-13 17:43:49 -04:00
David Wendt a7ff2de476 Don't spam the test log with `Resolving Multiname` messages for each scope that gets checked 2020-07-13 17:43:48 -04:00
David Wendt dd6b0a8728 Remove unused reference to slot property fields 2020-07-13 17:43:48 -04:00
David Wendt bf45f7f161 Fix crash when reading or writing a property that redirects to a slot. 2020-07-13 17:43:48 -04:00
David Wendt 7792fd5581 Impl `trace`, which is a free function rather than an opcode this time. 2020-07-13 17:43:48 -04:00
David Wendt a557867c71 Add the entire class hierarchy of `MovieClip` and `Sprite`. 2020-07-13 17:43:47 -04:00
David Wendt f6e2ca1fe5 Clean up the current set of builtins to accurately reflect the namespace hierarchy. 2020-07-13 17:43:47 -04:00
David Wendt 38b1524a49 Fix the error messages for `findpropstrict` and `getlex` to be more informative. 2020-07-13 17:43:47 -04:00
David Wendt 843de29460 Impl `newobject` 2020-07-13 17:43:46 -04:00
David Wendt 7201f6c4fe Impl `debug`, `debugfile` and `debugline`. 2020-07-13 17:43:46 -04:00
David Wendt 1d1bad1ab4 Impl `getglobalscope` 2020-07-13 17:43:46 -04:00
David Wendt 074ba94c17 Impl `newfunction` and `newclass`.
Notably, this also removes `new_closure_scope` as it is not needed. AVM1 does not capture `with` scopes in closures, but AVM2 (as well as modern ECMAScript) does.
2020-07-13 17:43:46 -04:00
David Wendt 1fe73b3329 Impl `dup` 2020-07-13 17:43:45 -04:00
David Wendt 0ff1c04697 Impl `initproperty` 2020-07-13 17:43:45 -04:00
David Wendt 5042fc1bc7 Debug all multiname resolutions 2020-07-13 17:43:44 -04:00
David Wendt 5c0e095ab5 `getlex` does not support runtime multinames according to spec. 2020-07-13 17:43:44 -04:00
David Wendt 9e120c216b Propagate arguments into local registers when calling AVM functions. 2020-07-13 17:43:44 -04:00
David Wendt 5b00c1fd96 Ensure that `this` is properly populated into local registers. 2020-07-13 17:43:44 -04:00
David Wendt b2f5307213 Add `flash.display.Sprite` because Flash Builder tests demand it. 2020-07-13 17:43:42 -04:00
David Wendt 4ab9a46515 Impl `getscopeobject` 2020-07-13 17:43:41 -04:00
David Wendt 5f98a198cb Remove dead code in Activation 2020-07-13 17:43:41 -04:00
David Wendt 279d90ec22 Remove `define_value` from AVM2 objects.
We already have a menagerie of `install_*` functions for adding static properties to a an object; and we don't have to support any kind of asinine nonsense liks `ASSetPropFlags` here. Ergo, we don't need this.
2020-07-13 17:43:39 -04:00
David Wendt cbce8660bc Implement `deleteproperty`. 2020-07-13 17:43:37 -04:00
David Wendt d19d9ef90e Clean up unused variables 2020-07-13 17:43:35 -04:00
David Wendt 8b56973d29 Remove scope methods that aren't necessary.
In AVM1, these are necessary because `ActionGetVariable` et. all directly interface with the scope chain. In AVM2, you `findpropstrict` up the scope chain, which gives you a normal object that you can interact with as you like. Ergo, the scope chain doesn't need set/get property methods.
2020-07-13 17:43:34 -04:00