Commit Graph

353 Commits

Author SHA1 Message Date
David Wendt 4655ebe73f Always push the constructed object on the stack. 2019-11-26 15:07:59 -05:00
David Wendt b9f02c290c Functions should be traceable. 2019-11-26 15:07:03 -05:00
David Wendt 0b1afcf8be Implement `ActionInstanceOf` (for non-interface types) 2019-11-26 14:51:06 -05:00
David Wendt 3c8d9b9c1c `new` should be called on the prototype - not the constructor function. This will allow different host object impls to subclass correctly. 2019-11-26 14:51:06 -05:00
David Wendt e8632bbcaa Implement `valueOf` for `Object` and fix the `toString` impl. 2019-11-26 14:51:06 -05:00
David Wendt 73c3b42cd4 Move `force_set` and `force_set_virtual` into the `Object` trait. They are now called `define_value` and `add_property`, respectively.
While I don't expect every host object to implement it correctly, this also gets rid of a lot of unnecessary `unwrap` calls that would allow a poorly-written Flash file to kill the interpreter.
2019-11-26 14:51:06 -05:00
David Wendt 983c0fb200 Add proto chain inspection to the object interface. 2019-11-26 14:51:06 -05:00
David Wendt 0e59e1c961 Allow host-provided constructors to override `new` and provide host objects to the AVM when a particular constructor is called. 2019-11-26 14:51:06 -05:00
David Wendt d25bdbacf8 Separate `Object` into an interface trait and a standard implementation. Host object implementations may bypass `ScriptObject` and directly interface with the AVM using this trait.
Note that host objects that do so will *not* have access to their standard representation from within member functions - you will need to extend the interface to accomodate for them. This is due to long-standing limitations with type IDs and downcasting with types that bear lifetimes - it's entirely an unsafe operation and exposing such a facility to safe Rust is unsound. However, this will at least let us separate out several things from ScriptObject that don't need to be there for the time being.
2019-11-26 14:51:05 -05:00
David Wendt 6dd40f8354 Split properties into a separate module. 2019-11-26 14:51:05 -05:00
David Wendt 813783881b Implement explicit prototypes on user-generated functions.
`Object::function` now returns a pre-allocated function object. You may supply it an explicit prototype to have it linked into the function object (which is why we have to return a cell).
2019-11-26 14:51:05 -05:00
David Wendt f347992eeb Add `as_usize` method to `Value` 2019-11-26 14:51:05 -05:00
David Wendt 207a157f20 Add missing usize conversion 2019-11-26 14:51:05 -05:00
kmeisthax fb34f73159 Manually constructing `Value` should no longer be necessary
Co-Authored-By: Nathan Adams <dinnerbone@dinnerbone.com>
2019-11-26 14:51:05 -05:00
David Wendt 1cb374da8a `ActionSetMember` accepts non-String names as parameters. 2019-11-26 14:51:04 -05:00
David Wendt fafad818d4 Implement `ActionInitObject` 2019-11-26 14:51:04 -05:00
David Wendt da315c7311 Fix docstrings on these modules 2019-11-26 14:51:04 -05:00
David Wendt b4e9b8442e Implement `isPropertyEnumerable` and `isPrototypeOf`. 2019-11-26 14:51:04 -05:00
David Wendt aa7997b658 Expose user-defined virtual properties to AVM code 2019-11-26 14:51:04 -05:00
David Wendt a8e1654c9e Implement `ActionNewMethod` and `ActionNewObject` 2019-11-26 14:51:04 -05:00
David Wendt 2f965d1c64 First stab at moving system builtins to explicit prototypes 2019-11-26 14:51:03 -05:00
Nathan Adams 882373d969 Object prototyping 2019-11-26 14:51:03 -05:00
Mike Welsh 6eaab8efdf
core: Merge #113, interworking of Rust + ActionScript
Internal support for interworking Rust and ActionScript code
2019-11-25 04:27:05 -08:00
David Wendt b8c24890fc Allow overwriting read-only virtual properties in scope chains.
The previous behavior had an oversight: if you tried to set a variable with the same name as an in-scope property, it would always try to overwrite that property. This can fail silently and doesn't match with Flash Player behavior. Now, an attempt to overwrite a read-only property is instead correctly rejected so that it can be defined in local scope.
2019-11-23 22:00:37 -05:00
dependabot-preview[bot] 2e75f06ee5 build(deps): bump gc-arena-derive from 0.1.1 to 0.2.0
Bumps [gc-arena-derive](https://github.com/kyren/gc-arena) from 0.1.1 to 0.2.0.
- [Release notes](https://github.com/kyren/gc-arena/releases)
- [Changelog](https://github.com/kyren/gc-arena/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kyren/gc-arena/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-22 18:07:50 +00:00
Nathan Adams ae064b62be chore: Change to no_drop from empty_drop for new gc-arena 2019-11-22 17:53:05 +00:00
dependabot-preview[bot] 238c575f16 build(deps): bump gc-arena from 0.1.1 to 0.2.0
Bumps [gc-arena](https://github.com/kyren/gc-arena) from 0.1.1 to 0.2.0.
- [Release notes](https://github.com/kyren/gc-arena/releases)
- [Changelog](https://github.com/kyren/gc-arena/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kyren/gc-arena/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-11-22 17:53:05 +00:00
David Wendt bae0476113 Don't panic when double-locking a stack frame. 2019-11-20 14:30:34 -05:00
David Wendt 17215cc787 Remove the `NoResult` variant of `ReturnValue` as it is no longer useful or in use. 2019-11-20 14:30:33 -05:00
David Wendt 8c1d25b0f7 Add conversions for all the same conversions regular `Value`s have, so that you don't have to constantly mark things as `ReturnValue::Immediate` 2019-11-20 14:30:33 -05:00
David Wendt e4eb930d44 Remove all references to stack continuations from our documentation. 2019-11-20 14:30:33 -05:00
David Wendt 5bf90653c4 Add implicit coercions to remove most instances of manually constructing a `ReturnValue`. 2019-11-20 14:30:33 -05:00
David Wendt 4b824370f4 Remove the stack continuation system. If we decide to structure this system in the same way in the future, we'll probably use async functions or something like that. 2019-11-20 14:30:33 -05:00
David Wendt 2aa5b62b44 Make most code that might touch user-defined functions falliable. 2019-11-20 14:30:32 -05:00
David Wendt a49af7815c Resolve all existing return values on the Rust stack. 2019-11-20 14:30:32 -05:00
David Wendt bb1cde5557 Avoid double borrow panic caused by unreasonably long lifetime of `.write()` temporary 2019-11-20 14:30:32 -05:00
David Wendt 7284794c0b Store the return value on the activation object when it's retired. 2019-11-20 14:30:32 -05:00
David Wendt e2dcf47c56 Add a method to force resolve a `ReturnValue` on the Rust stack via recursion. 2019-11-20 14:30:31 -05:00
David Wendt bc74b2fc4a Track the no-double-reader flag on a per-frame basis, and add a "run until current frame exits" routine. 2019-11-20 14:30:31 -05:00
David Wendt dd4462c104 Warn when attempting to attach a second continuation onto an existing stack frame, since we don't support that use case. 2019-11-20 14:30:31 -05:00
David Wendt a2ee7f9e3a Replace `Option<Value<'gc>>` with a dedicated `ReturnValue<'gc>` type with associated methods.
This type explicitly signals if an immediate value is to be returned, if a value is to be returned on the stack, or if no return value is to be generated. Holders of a `ReturnValue` can also use `and_then` to schedule a `StackContinuation` to be executed when and if that value is ready.

`StackContinuations` now yield `ReturnValues` as well, so they have a moderate level of composability. For example, if you need to get a property from an object and push it on the stack, you can return the result of calling `get` directly and the machinery ensures it eventually gets there.
2019-11-20 14:30:31 -05:00
David Wendt 2a3d324a33 Implement the "reschedule same continuation" behavior in AVM 2019-11-20 14:30:31 -05:00
David Wendt 40dbc535fc Remove force_get now that everything can read virtual properties correctly. 2019-11-20 14:30:30 -05:00
David Wendt e36a0d8350 Allow native functions to resolve on the AVM stack for whatever reason. 2019-11-20 14:30:30 -05:00
David Wendt 4dffe448e4 Get rid of the automatic `this` on stack continuations 2019-11-20 14:30:30 -05:00
David Wendt 9d422dc269 Allow getters to resolve on the AVM1 stack.
This involved yet another macro, `and_then!`, to avoid a ridiculous amount of duplicate code. It calls a continuation whenever it's value is ready, even if the value resolved on the Rust stack.

`locals_into_form_values` does not currently support this. It skips any property that does not resolve on the Rust stack. Future work is required to resolve this.
2019-11-20 14:30:30 -05:00
David Wendt a59fffbc4e Ensure that the value of the newly constructed `this` is returned in all cases.
This involves the use of a "stack continuation" system. Due to previous lifetime issues with using closures directly (see `8ea6c6234dba925ec5fbc61502627fb62b05916c`), we instead use a macro that constructs a `Collect`able type holding the things the continuation needs to continue working with. The syntax is largely similar to Rust closures but with the addition of an explicit list of bound variables, all of which must be `Collect`.
2019-11-20 14:30:29 -05:00
David Wendt a95861d596 Stack continuations can now directly manipulate the return value of an ActionScript function. 2019-11-20 14:30:29 -05:00
David Wendt 8485e919db Add a notion of "and_then" to activation objects.
This effectively constitutes the ability to assign arbitrary native contiuations to the AVM stack.
2019-11-20 14:30:29 -05:00
dependabot-preview[bot] 387feaf76c
build(deps): bump rand from 0.6.5 to 0.7.2 (#124) 2019-11-20 18:30:54 +00:00