Commit Graph

2484 Commits

Author SHA1 Message Date
David Wendt cce68dbc21 Add trait methods for getting and setting the interfaces list. 2020-07-13 17:45:08 -04:00
David Wendt 563a515189 Add a test for loading interfaces into the AVM2.
This test will fail if the AVM2 implementation does not support bodyless methods or bare classes properly.
2020-07-13 17:45:07 -04:00
David Wendt 8f2d3315f3 Allow the construction of classes with no base class.
This is primarily used for interfaces, in case you can't guess by the previous commit.
2020-07-13 17:45:07 -04:00
David Wendt 5d89d4ed85 Allow methods to not hold a body.
Interface methods are specifically not allowed to be called: as a result, they don't get a method body. Existing code assumed a 1:1 relationship between methods and bodies, which causes spurious errors.
2020-07-13 17:45:07 -04:00
David Wendt 090fe56bd3 Wrap `BytecodeMethod` (and the bytecode half of `Executable`) in a `Gc`.
This is inspired by Dinnerbone's similar PR on the AVM1 side, where the Action half of that VM's `Executable` was reduced from 128 bytes to 16 by shoving it in a `Gc`. This won't be as dramatic but should still save some memory.

In fact, it should save a *lot* of memory in bytecode execution, where thanks to the previous commit's rebase, we now need to clone the current method once *for each instruction executed*. That is terrible, but should stop now.
2020-07-13 17:45:06 -04:00
David Wendt 97e005622b Invert the role of `Avm2` and it's `Activation`, similar to what was done with `Avm1` and it's `Activation`.
This also results in a far reduced role for `ReturnValue`, since I also took the liberty of removing most of it's use. Furthermore, I also made it apply equally to native and AVM2 code, which ensures all native implementations of methods don't double-borrow.

In AVM1, `ReturnValue` was actually removed entirely, because it's not needed. I attempted to do the same, but the fact that we're currently embedding `ScriptObjectData` in native objects means that we need it for virtual properties. Otherwise, virtual property implementations will see locked objects, which is bad.
2020-07-13 17:45:06 -04:00
David Wendt 5b5bf0719e Remove `Avm2Function` as it is no longer used. 2020-07-13 17:45:05 -04:00
David Wendt 098b034de0 Refactor method-related structs into a separate method module.
This also renames `NativeFunction` and `Avm2MethodEntry` to `NativeMethod` and `BytecodeMethod`, respectively.
2020-07-13 17:45:05 -04:00
David Wendt b6e05519cd Remove `Avm2ClassEntry`. It is no longer used. 2020-07-13 17:45:05 -04:00
David Wendt 12fc13da7f Clippy compliance for the last batch of commits. 2020-07-13 17:45:05 -04:00
David Wendt 041cb0b5c3 Resolve multiname constant zero as an error rather than a panic.
While some code that references pool multinames has zero as a valid index, we cannot validate exactly what the zero index is for a given index. Hence, callers instantiating multinames must check for zero and substitute the correct zero-value interpretation for their given type. If zero is an invalid value, it should ideally throw a different error than what's provided here.
2020-07-13 17:45:04 -04:00
David Wendt 0d2235d2e0 Resolve all remaining compilation issues with this refactor. 2020-07-13 17:45:04 -04:00
David Wendt 7684736bf7 `table_class` should resolve `Class`es straight from the current translation unit. 2020-07-13 17:45:04 -04:00
David Wendt 232c29dc5e Fix remaining problems with method loading using `callstatic` 2020-07-13 17:45:03 -04:00
David Wendt eaebd3c63c Make `Avm2MethodEntry` hold it's `TranslationUnit` rather than an `AbcFile`. 2020-07-13 17:45:03 -04:00
David Wendt 4467bc3193 Make `TranslationUnit` a GC-mandatory type (only referred to by `GcCell`). 2020-07-13 17:45:03 -04:00
David Wendt 60f3ae3ba7 Remove `Avm2ScriptEntry`. It is now obsolete and unused. 2020-07-13 17:45:02 -04:00
David Wendt f549d0146e Fix compilation bugs involved with automatic script initializer execution. 2020-07-13 17:45:02 -04:00
David Wendt b4f944b37b Wrap ABC loading inside of a `TranslationUnit`. 2020-07-13 17:45:01 -04:00
David Wendt 70e9030072 Decouple the entire trait machinery from ABC-provided traits.
This commit breaks the build: we still need to tell `Avm2` how to turn ABC traits into our own internal `Trait<'gc>`, `Class<'gc>`, and `Method<'gc>` types. We also need something to track which traits have already been instantiated, because `callstatic` would otherwise reinstantiate the trait in a different scope. (In fact, I think it *does* do exactly that right now...)
2020-07-13 17:45:01 -04:00
David Wendt 15a62d31cb Add an internal representation of `Trait`, separate from `swf::avm2::types::Trait`, which is specific to the ABC file format.
The intention is to completely replace all usage of `Avm2XYZEntry` with `Class`, `Trait`, and `Method`. This will allow runtime-provided global class traits to coexist with those provided by user code.
2020-07-13 17:45:01 -04:00
David Wendt 4cd30455de Excise `ReturnValue<'gc>` from all `TObject` methods.
Inspired by Dinnerbone's PR doing the exact same thing to AVM1.

On AVM2 we have a bit of a subtle issue: the base implementation of `set_property_local` and `init_property_local` *must* return `ReturnValue`s to avoid double-borrows. Each implementation of `TObject` must resolve them before returning.
2020-07-13 17:45:00 -04:00
David Wendt 3362ec09e8 chore: Clippy conformance 2020-07-13 17:45:00 -04:00
David Wendt fe283e6770 Silence this warning about occupied slots being an unused variant.
I don't know if I'm missing something, but I'm pretty sure this variant is reachable via `TObject::install_slot`.
2020-07-13 17:45:00 -04:00
David Wendt 6117288fe2 Add tests for `ifstricteq`, `ifstrictne`, and `strictequals`. 2020-07-13 17:44:59 -04:00
David Wendt 34ab8c8ce6 `NaN` is not special-cased in AS3. 2020-07-13 17:44:59 -04:00
David Wendt 34b3bbae63 *Correctly* implement `ifstricteq` and `ifstrictne`.
The previous implementation suffered from copypasta and was attempting to assert that both of it's values were `bool`.
2020-07-13 17:44:59 -04:00
David Wendt ecfd16cec9 Add global constants `undefined`, `null`, and `NaN`. 2020-07-13 17:44:58 -04:00
David Wendt 03a240ebcd Add tests for `valueOf`. 2020-07-13 17:44:58 -04:00
David Wendt b4d907bf2e Implement `strictequals`. 2020-07-13 17:44:58 -04:00
David Wendt 3b52dfe2ba Since we have an `es3_inheritance` test now, rename the existing inheritance test to `es4_inheritance`. 2020-07-13 17:44:57 -04:00
David Wendt cf6714d33c Implement and test `toLocaleString`.
This function has vague documentation about enabling locale-specific formatting in subclasses. As far as I can tell, none of the objects I implemented so far do anything different than `toString`, so I just have it use the same `TObject` property I set up for `toString`.
2020-07-13 17:44:57 -04:00
David Wendt 3558c3afa0 Add test of `Function.prototype.call` 2020-07-13 17:44:56 -04:00
David Wendt 16774aa055 Add a test for legacy / ES3 inheritance.
This was originally something *way* more evil: mixed inheritance between ES3 and ES4 classes. It didn't pan out due to fundamental limitations of the two object models. How the hell did Brendan Eich/Adobe/TC-39 expect ES4 classes to be adopted in already-existing codebases?!
2020-07-13 17:44:56 -04:00
David Wendt 4b66af8dc3 ES4 classes, while superficially similar to functions, are not functions and should not inherit from the `Function` prototype.
We still reuse the `FunctionObject` machinery internally. If necessary, we may want to split this into a separate `ClassObject` if some internal `TObject` method needs replacing for classes.
2020-07-13 17:44:55 -04:00
David Wendt 8b36751fbb Several built-in functions are not `public`, but instead live in the `AS3` namespace. This moves those functions there.
In practice not many movies will care about this, because the `AS3` namespace is open by default. You could opt-out of that, and I suppose that was there for using existing ES3 code in AS3 projects. ES4 would have had a similar ES4 namespace, which "JavaScript 2.0" code would need to opt into. Of course, ES4/JS2 never happened, so we just have this weird historical quirk here.
2020-07-13 17:44:55 -04:00
David Wendt 37cdcb3bce Add tests for `toString` on objects, functions, and classes. 2020-07-13 17:44:54 -04:00
David Wendt f493cf954f Make `toString` and `valueOf` methods of `TObject`, called `to_string` and `value_of` respectively.
The reason for this is that, in AVM2, `toString` and `valueOf` are not defined on the classes or prototypes of `Function` or `Class`. Instead, they use the `Object.prototype` versions of those functions. Ergo, string and primitive coercion are inherent object methods (the ones that get `[[DoubleSquareBrackets]]` in the ECMA standards). In Ruffle, our equivalent to `[[DoubleSquareBrackets]]` methods are methods on the `TObject` trait, so we're adding them there.

This mechanism will make implementing boxed value types (ala AVM1's `BoxedObject`) easier, too.

We also add some reasonable defaults for `ScriptObject` and `FunctionObject` which will appear on objects, functions, and classes.
2020-07-13 17:44:53 -04:00
David Wendt ba2c1f5750 Add test for `setPropertyIsEnumerable` 2020-07-13 17:44:39 -04:00
David Wendt f13e2ea3c4 Implement `setPropertyIsEnumerable` 2020-07-13 17:44:37 -04:00
David Wendt dc0cb00a03 Add a test for `propertyIsEnumerable`. 2020-07-13 17:44:37 -04:00
David Wendt 2afbcf450a Impl `propertyIsEnumerable` 2020-07-13 17:44:36 -04:00
David Wendt a0ca5891e4 Prevent instance traits from being accessible directly from prototypes. 2020-07-13 17:44:36 -04:00
David Wendt 307a95e5c4 `callproperty` and `callpropvoid` should *never* get callables from `base_proto`. 2020-07-13 17:44:35 -04:00
David Wendt 42cb8f57c8 Add a test for `has_own_property` in various class instance scenarios. 2020-07-13 17:44:35 -04:00
David Wendt 6e2508a79d Fix `any` name resolution, at least enough for the `has_own_property` test to work.
Private names now return `false`, and we run any names through trait lookups. This also means any namespace resolution can fail now, in case we need to throw a `VerifyError`.
2020-07-13 17:44:34 -04:00
David Wendt 8677804ea0 Actually enable the `isPrototypeOf` test. 2020-07-13 17:44:34 -04:00
David Wendt c6265bb50c Allow tracing booleans.
This requires implementing *some level* of coercions, even though this isn't the way to do it.
2020-07-13 17:44:34 -04:00
David Wendt 00186f7602 Free functions always have a `prototype`, this is a holdover from ES3. 2020-07-13 17:44:33 -04:00
David Wendt 0e89cb2175 Impl `Object.isPrototypeOf` w/ test 2020-07-13 17:44:33 -04:00