Commit Graph

793 Commits

Author SHA1 Message Date
Mike Welsh e71099edd5 tests: Add primitive_type_globals test 2020-01-21 18:24:49 -08:00
Mike Welsh 8263d13fd0 avm1: Implement Number class 2020-01-21 18:24:49 -08:00
Mike Welsh b49357e46f avm1: Boxing a value calls the object constructor 2020-01-21 18:24:49 -08:00
Mike Welsh ccf62979a1 avm1: Implement String methods 2020-01-21 18:24:49 -08:00
Mike Welsh 5f12ce78b6 tests: Add string method tests 2020-01-21 18:24:49 -08:00
David Wendt 2f9d50cdb8 Very rudimentary/basic/not-good implementation of `String`, plus auto-boxing for primitive strings getting their methods taken. 2020-01-21 18:24:49 -08:00
David Wendt 4d1e49882b Add another object class for boxed primitive values, because the language demands it. 2020-01-21 18:24:49 -08:00
Mike Welsh 13b4cd4c1b avm1: Add Value::coerce_to_i32/u32/u16 methods
Add these methods that will explicilty coerce a value to an int,
following the wrapping behavior in the ECMAScript specs (ToInt32,
ToUInt32, ToUInt16).

This also fixed an off-by-one error for negative numbers in the
previous implementation.

These will call `valueOf` if necessary. AVM code that requires an
integer will probably use one of these (`coerce_to_i32` usually).
2020-01-20 13:28:27 -08:00
dependabot-preview[bot] 87e96212e4 build(deps): bump syn from 1.0.13 to 1.0.14
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.13 to 1.0.14.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.13...1.0.14)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-20 18:56:56 +00:00
Nathan Adams 4ad6ef8b83 core: Implemented Key.getCode() 2020-01-17 15:11:38 -08:00
Nathan Adams adceceed5d avm1: Removed redundant double registration of Key 2020-01-17 15:11:38 -08:00
Nathan Adams cef7d3eba2 avm1: Implement Key constants 2020-01-17 15:11:38 -08:00
Mike Welsh 8cb4278903 tests: Use pretty_assertions for nice output on test fail 2020-01-17 13:54:39 -08:00
Mike Welsh cf7a564f2c core: Fix properties not resetting in goto when rewinding
Properties of a display object would not reset when rewinding if
it existed in both the initial and final frames of the goto.
This fixes the weapons toggles in UFA.
2020-01-16 09:58:33 -08:00
Mike Welsh 8448fc80ef avm1: Don't panic when calling ActionRandom with <= 0 2020-01-14 00:05:13 -08:00
Mike Welsh 4eef8a1821 tests: Add test for ActionCall 2020-01-14 00:04:11 -08:00
Mike Welsh 2d3801dac8 avm1: Implement ActionCall opcode 2020-01-14 00:04:11 -08:00
Nathan Adams fdf1d38d21 avm1: Implement remainder of Math 2020-01-13 15:57:56 -08:00
dependabot-preview[bot] 6c2f5143b3 build(deps): bump rand from 0.7.2 to 0.7.3
Bumps [rand](https://github.com/rust-random/rand) from 0.7.2 to 0.7.3.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-13 18:38:15 +00:00
Mike Welsh 001a931afe avm1: Avm1::pop should always succeed
Don't return a Result from `pop`. Instead, emit a warning and
return Undefined if there is an underflow.
2020-01-07 15:59:14 -08:00
Mike Welsh 170813ffbf audio: Assume little endian for PCM unknown endian sounds 2020-01-07 02:40:09 -08:00
Mike Welsh a28e97d8c3 avm1: Don't push returns from non-function stack frames 2020-01-06 20:49:05 -08:00
Mike Welsh 7e05da6147 avm1: Fix issues with traversing the scope chain in SetVariable
When setting a variable in a function-local scope, if that variable
has not been defined in the function scope, it should be defined in
the executing movieclip's scope. Previously it would get defined
in the function's scope. Changed Scope::overwrite to Scope::set,
and modified the behavior to stop traversing and define the value
when it hits a movie clip Target scope.

Also, modified With scopes to properly add onto the end of the scope
chain.
2020-01-06 20:49:05 -08:00
Mike Welsh a60fadf0bb tests: Add test for correct scope in SetVariable 2020-01-06 20:49:05 -08:00
David Wendt 0d1d0e8de7 Don't bother preserving the `Cow`ness of unescaped strings when we're going to clone them anyway. 2020-01-05 00:31:45 -05:00
David Wendt 7957434036 This is a copy type, copy it 2020-01-05 00:24:31 -05:00
David Wendt f8b5b8a032 Use `unwrap_or_default` where available 2020-01-05 00:22:36 -05:00
David Wendt ef7c5d7eb9 Move XML properties to separate functions rather than closures 2020-01-05 00:17:57 -05:00
David Wendt 14dba0d100 Log errors encountered when removing the children of a node we plan to parse XML into.
Also, remove a handful of unnecessary `#[allow(unused_must_use)]` instances.
2020-01-05 00:04:45 -05:00
David Wendt 464563a703 Change the no-double-introduction warning into a proper `assert!`. Add doc warning about the panic. 2020-01-05 00:00:29 -05:00
David Wendt 750e6e4370 Replace bare number constants for XML errors with symbolic `const` values 2020-01-04 23:56:10 -05:00
David Wendt fd541fabea Implement `status`.
I'm not entirely sure how to test this one - the list of errors that Flash kicks out for XML and the list of errors that `quick_xml` kicks out don't line up at all; so I just ensured that any error is a negative number (currently the one for OOM errors) and stuck whatever errors *did* match up together.

Consequently I don't know entirely *how* to write tests for this.
2020-01-04 19:00:49 -05:00
David Wendt fec95dd226 Add regression test for `idMap`. 2020-01-04 19:00:49 -05:00
David Wendt f3226537bf Implement `idMap`.
`idMap` is a strange property; it's only populated with nodes which had a given `id` *at the time of parsing*, and said nodes continue to be referenced even if the node is removed from the document. I have yet to find a way by which nodes can be deleted from `idMap`.

It also takes expandos, so this has to be a new retained object on the XML document. I originally considered not creating *another* `Object` impl and populating a regular `ScriptObject` with nodes, but that meant we couldn't lazy-instantiate their AVM1 side counterparts. Boo. :/
2020-01-04 19:00:48 -05:00
David Wendt 1722558d44 Add test for `XML.parseXML` 2020-01-04 19:00:47 -05:00
David Wendt 823e8602ff Impl `XML.parseXML` 2020-01-04 19:00:46 -05:00
David Wendt d00ef01965 Add a convenience method: `XMLNode.into_string` 2020-01-04 19:00:46 -05:00
David Wendt b4b722e1d6 Add another test for AVM1 XML's failure to roundtrip unsupported node types (e.g. comments). 2020-01-04 19:00:45 -05:00
David Wendt 2c790f1d41 Filter non-AS2 compatible nodes from toString output, and add non-SWF tests for XML filtering. 2020-01-04 19:00:45 -05:00
David Wendt ce1b958abb Add some more tests for XML namespace URIs. 2020-01-04 19:00:45 -05:00
David Wendt e2fa685d41 Fix tagname parsing.
There is a bug in `quick_xml` - or at least, I *think* it's a bug - where the `unescaped` method of `BytesStart` yields a bunch of attributes if you have slightly invalid crap in your tag like `xmlns:`. To work around it, I turned off unescaping; we're instead using `name` and ignoring unescaping. This will probably fail somewhere.
2020-01-04 19:00:44 -05:00
David Wendt e1034fce31 clippy compliance 2020-01-04 19:00:44 -05:00
David Wendt 7ac3204759 format prev commit 2020-01-04 19:00:43 -05:00
David Wendt d2aa3dd987 Add a test for `createElement` and `createTextNode`. 2020-01-04 19:00:43 -05:00
David Wendt db38982ffb For some reason, text nodes have an attributes object. 2020-01-04 19:00:42 -05:00
David Wendt 91155d6870 Text nodes have empty arrays for `childNodes` rather than being `undefined`. 2020-01-04 19:00:42 -05:00
David Wendt d28094a019 Implement `createElement` and `createTextNode`. 2020-01-04 19:00:42 -05:00
David Wendt 97bcb6b2dc Add an ignored test for `xmlDecl`.
Test is currently ignored because AS2 XML currently handles XML declarations in ways not compatible with our current parser. Investigating hacky ways around this.
2020-01-04 19:00:41 -05:00
David Wendt c02da74afa Expose the `<?xml ?>` declaration to ActionScript.
I can't write proper tests for this because our underlying XML parsing technology doesn't let us do what AS2 XML does: just copy the first xml tag out of the document and into a string. No, seriously, anything at the start of the parsed XML that starts with `<?xml` and ends with `?>` gets copied into Flash's moral equivalent of `xml::Document` as a string. We parse the whole thing, which is wrong, so we'll need to additionally retain the original xmldecl string in order to pass the test I wrote for this.
2020-01-04 19:00:41 -05:00
David Wendt ce0546fc2c Add test for `docTypeDecl`. 2020-01-04 19:00:40 -05:00
David Wendt a7a349b02b Expose `docTypeDecl` to ActionScript.
This also involves storing the `DocType` node on the document object and retrieving it later.
2020-01-04 19:00:40 -05:00
David Wendt a80aab1b08 Document roots can store an attributes object, even though they don't have attributes 2020-01-04 19:00:40 -05:00
David Wendt 6a472d32bb Filter incompatible nodes from the sibling and child lists. 2020-01-04 19:00:39 -05:00
David Wendt fd14d0c9df Doctype nodes should be represented as text nodes to ActionScript (if they somehow grab hold of them) 2020-01-04 19:00:38 -05:00
David Wendt 6b4bbee195 Create and store `DocType` nodes on the tree when we encounter a `<!DOCTYPE...>` tag. 2020-01-04 19:00:38 -05:00
David Wendt aa749dc1b0 Store the XML document version, encoding, and standalone flags. 2020-01-04 19:00:38 -05:00
David Wendt a869107480 The `DocumentRoot` node type should have it's own node type ID, and AS2 XML should filter it out. This also filters out comment nodes as text, which isn't technically wrong but we should do better 2020-01-04 19:00:37 -05:00
David Wendt 7965045d87 Add test for XMLNode.toString. 2020-01-04 19:00:37 -05:00
David Wendt 673f85f067 XMLNode type 1 is an element, not a text node. 2020-01-04 19:00:36 -05:00
David Wendt 88aa5f8004 Add extra whitespace to empty tags. 2020-01-04 19:00:36 -05:00
David Wendt 0c7a1fe667 Text and comment nodes are stored plain and must be escaped for XML 2020-01-04 19:00:36 -05:00
David Wendt c7e1f34a5d Print empty nodes as empty tags rather than start/end 2020-01-04 19:00:35 -05:00
David Wendt c76e5ce447 appendChild also refuses to orphan nodes already part of another XML tree. 2020-01-04 19:00:35 -05:00
David Wendt bff851e6a4 Add test for insertBefore 2020-01-04 19:00:34 -05:00
David Wendt 34cbe2e04b insertNode rejects child nodes that already have a parent 2020-01-04 19:00:34 -05:00
David Wendt 7b4a509ebc Avoid double-borrows when moving a child within it's parent 2020-01-04 19:00:33 -05:00
David Wendt 7753e20fe3 Add a test for XML.removeNode(). 2020-01-04 19:00:33 -05:00
David Wendt 30266b2ce7 remove_child should also ensure the child disowns the parent. 2020-01-04 19:00:33 -05:00
David Wendt 8c5dcfe662 Swap in newly constructed nodes *before* filling them with content.
Fixes a bug where new XML("<node />").childNode[0].parentNode did NOT refer to the overall document object, but to a phantom text node.

This is because the swap operation used to construct an XMLObject's node in-place was happening AFTER parsing, which means that referents already existed to the temporary XMLNode created by XMLObject::new. swap is not to be called after tree structure has been created; it does not update referents to the swapped nodes.

In the future I should examine the implications of explicitly reconstructing already existing nodes, e.g. through XML.apply(some_xml). Right now, the existing node will be swapped with a new one, and two nodes will exist pointing to the same script object, which is a huge problem with our overall design. We should, at the very least, disassociate swapped nodes from their script object, just in case they still have referents.

Ideally, we wouldn't have to swap nodes, but to avoid a swap, I'd have to instead have a second layer of indirection just to hold a rewritable pointer that every XMLObject points to. This isn't really worth it unless I HAVE to do it, so I'm not going to do it.
2020-01-04 19:00:32 -05:00
David Wendt 568d90f4dc Warn if XML.removeNode fails for whatever reason 2020-01-04 19:00:32 -05:00
David Wendt 1577f51730 Expose elided objects as pointers when debugging XML nodes 2020-01-04 19:00:32 -05:00
David Wendt 19ca11b08c Impl `toString` 2020-01-04 19:00:31 -05:00
David Wendt 513460e4e0 Implement `insertBefore` 2020-01-04 19:00:31 -05:00
David Wendt b0dce445b0 Impl `removeNode` 2020-01-04 19:00:29 -05:00
David Wendt 00319f14a8 Implement `namespaceURI` 2020-01-04 19:00:29 -05:00
David Wendt 73da72db98 Add a test for `appendChild`. 2020-01-04 19:00:28 -05:00
David Wendt 7c95eff048 Flag an error if we accidentally introduce a second script object by accident. 2020-01-04 19:00:28 -05:00
David Wendt abb2690367 When constructing new XML nodes or documents, always ensure that the new node we swap in is properly linked to the same script object so that we don't accidentally recreate them. 2020-01-04 19:00:28 -05:00
David Wendt 8939dae90c Implement `XMLNode.attributes` w/ read tests 2020-01-04 19:00:27 -05:00
David Wendt 6f48f3436f Expose `previousSibling` and `nextSibling` to ActionScript.
This commit also fixes a bug caused by excessive use of copypaste, which was detected by the included test.
2020-01-04 19:00:25 -05:00
David Wendt 223320c98c Expose `parentNode` to ActionScript 2020-01-04 19:00:24 -05:00
David Wendt 807725d7aa Expose `firstChild` and `lastChild` to ActionScript w/ tests 2020-01-04 19:00:24 -05:00
David Wendt 1d1e493e0e Refactor the child adoption process to ensure the child also adopts it's siblings. 2020-01-04 19:00:23 -05:00
David Wendt 48d68bebc4 Implement `hasChildNodes()` and add test 2020-01-04 19:00:23 -05:00
David Wendt c58e866236 Add test for `cloneNode` 2020-01-04 19:00:22 -05:00
David Wendt 881dcb76ab `cloneNode` without arguments is morally equivalent to `false` 2020-01-04 19:00:21 -05:00
David Wendt 8e33566d07 Add namespacing test 2020-01-04 19:00:21 -05:00
David Wendt 69a1ab1649 Expose namespace prefix and URI lookups to ActionScript.
Also, fix the previous commit's half-assed impl.
2020-01-04 19:00:20 -05:00
David Wendt fe7d2b5173 Extremely WIP impl of `lookup_uri_for_namespace` 2020-01-04 19:00:20 -05:00
David Wendt 55fa6ef09b Add node cloning support 2020-01-04 19:00:19 -05:00
David Wendt 37f6efb753 Expose `appendChild` to ActionScript 2020-01-04 19:00:19 -05:00
David Wendt 08c0f273a6 Add sibling links to nodes. 2020-01-04 19:00:18 -05:00
David Wendt 7e45dee8cf Clippy said so. 2020-01-04 19:00:18 -05:00
David Wendt eec449422b `XMLDocument.roots` is not necessary since you can just get the children of it's node form anyway... 2020-01-04 19:00:18 -05:00
David Wendt f8f569440f Add very basic XML test 2020-01-04 19:00:17 -05:00
David Wendt cfacd397cf Most XML properties return `null`, not `undefined`.
Furthermore, `prefix` does not distinguish between `<test>` and `<:test>` - they both have a `prefix` of `""`.
2020-01-04 19:00:17 -05:00
David Wendt b491dd034e Don't overflow stack when debug-printing an entire document, either. 2020-01-04 19:00:16 -05:00
David Wendt e47a1d1e38 Fix newly constructed XML trees not actually containing the XML they just parsed. 2020-01-04 19:00:16 -05:00
David Wendt 960e4dad90 Don't cause stack overflow when debug-printing XML nodes. 2020-01-04 19:00:16 -05:00
David Wendt bec60acc1e `XML.prototype` should be an `XMLObject` so that instances of `XML` can hold a node 2020-01-04 19:00:15 -05:00
David Wendt d058c83ac0 Document roots should accept children. 2020-01-04 19:00:15 -05:00
David Wendt 571c4bbd52 Cargo fmt compliance 2020-01-04 19:00:15 -05:00
David Wendt 0af248d81f Expose `childNodes` to ActionScript 2020-01-04 19:00:14 -05:00
David Wendt e7768d0802 Add methods to allow storing XML objects on the accompanying tree nodes, so that expando properties on child nodes will work. 2020-01-04 19:00:13 -05:00
David Wendt b06dd5d15e Add a special node to represent the document root in the node tree, and get rid of the explicit document reference type in `XMLObject`. 2020-01-04 19:00:12 -05:00
David Wendt 0fe0e4fe90 Separate `XMLName` into another module 2020-01-04 19:00:11 -05:00
David Wendt 3928c7cc51 Reject empty text nodes 2020-01-04 19:00:11 -05:00
David Wendt 7a9a16e598 Don't repeat yourself. 2020-01-04 19:00:11 -05:00
David Wendt bd1ea56cc3 Implement `XMLNode` properties that don't require child or attribute iteration. 2020-01-04 19:00:10 -05:00
David Wendt e2eb3d0bde Add a test of XMLDocument::from_str.
This test technically works, but the results were slightly surprising. If it turns out Flash works differently from `quick_xml`, we'll change this test to match Flash.
2020-01-04 19:00:10 -05:00
David Wendt 6ae5ae3038 Add Comment parsing support 2020-01-04 19:00:10 -05:00
David Wendt 4f5ac09b73 Expose XML document constructor, including text parsing ability 2020-01-04 19:00:09 -05:00
David Wendt 554f0dc1e5 Add XMLNode class and constructor impl 2020-01-04 19:00:07 -05:00
David Wendt 6a65e984ae Add a new `XMLObject` variant to the AVM1 object ecosystem.
This particular variant is actually a two-in-one deal: `XMLObject`s may either refer to a document or a node.
2020-01-04 18:58:42 -05:00
David Wendt 89c9753520 Add rudimentary custom DOM impl on top of `quick_xml`.
`quick_xml` was chosen due to it's high performance and support for zero-copy use cases. However, we are not using `minidom`, which is the already-extant DOM impl that uses `quick_xml` as it's parsing provider. This is because `minidom` nodes are not amenable to garbage collection.

Specifically: we want to be able to construct a new `Object` variant that holds part of an XML node. However, `minidom::Element` directly owns it's children, meaning that we can't hold references to it from within `Object` while also keeping those objects to the `'gc` lifetime. Hence, we provide a GC-exclusive DOM implementation.

I ruled out solutions such as holding an entire XML tree in an `Rc` and having AVM objects that shadow them. This works for `SwfSlice` because indexing an array is cheap; but traversing a tree can get very expensive. XML is used in many places in Flash Player, so it's important that we treat it like a first-class citizen.
2020-01-04 18:48:17 -05:00
Mike Welsh 4ce67535b0 tests: Add test for Color 2020-01-03 20:31:32 -08:00
Mike Welsh 36b3e5b34f avm1: Implement Color class 2020-01-03 20:31:32 -08:00
Mike Welsh 4bf29f677f avm1: Implement Sound.duration
Add AudioBackend::get_sound_duration.
2020-01-03 17:11:00 -08:00
Mike Welsh b9d24d9a49 avm1: First pass at implementing Sound.stop 2020-01-03 17:11:00 -08:00
Mike Welsh d0142f1d67 audio: Add AudioBackend::stop_sound 2020-01-03 17:11:00 -08:00
Mike Welsh 63dd92259b avm1: First pass of Sound object 2020-01-03 17:11:00 -08:00
dependabot-preview[bot] a01e5b7854 build(deps): bump syn from 1.0.12 to 1.0.13
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.12 to 1.0.13.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.12...1.0.13)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 19:15:37 +00:00
dependabot-preview[bot] b4a47e17da build(deps): bump generational-arena from 0.2.6 to 0.2.7
Bumps [generational-arena](https://github.com/fitzgen/generational-arena) from 0.2.6 to 0.2.7.
- [Release notes](https://github.com/fitzgen/generational-arena/releases)
- [Changelog](https://github.com/fitzgen/generational-arena/blob/master/CHANGELOG.md)
- [Commits](https://github.com/fitzgen/generational-arena/compare/0.2.6...0.2.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 19:14:43 +00:00
dependabot-preview[bot] 1048170235 build(deps): bump syn from 1.0.11 to 1.0.12
Bumps [syn](https://github.com/dtolnay/syn) from 1.0.11 to 1.0.12.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.11...1.0.12)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-03 08:24:29 +00:00
Mike Welsh 87158647d1 core: Implement keyPress button events 2019-12-24 03:06:03 -08:00
Mike Welsh 2f0963fa6c core: Fix button action with multiple conditions not firing (fix #195)
If a button event had both a keyPress condition and another
condition:

on(release, keyPress "A") { }

these actions would not fire on click, because it would still
check if the key was down (which doesn't apply to clicks!)

Fixes #195.
2019-12-22 15:55:03 -08:00
Nathan Adams 9000451d58 core: Implemented Mouse.show() & Mouse.hide() 2019-12-22 14:33:46 -08:00
Mike Welsh 4cdeec5b64 avm1: Fix number coercion in arithmetic ops
A lot of the arithmetic ops were still using SWFv4 style coercion
(`Value::into_number_v1`) even though they use full ECMA-262
coercion in SWF5+. This would cause `undefined` to turn into 0
isntead of NaN, for example.

Fixes disappearing player in Achievement Unlocked
(https://www.newgrounds.com/portal/view/474371)

It's possible even the older ops such as ActionAdd should do this,
too. Handcrafted bytecode will need to be used to test as you
cannot export these ops in newer SWF versions from the Flash IDE.
2019-12-22 03:01:58 -08:00
Mike Welsh c9e0bdeaf5 core: GC trace Button::object 2019-12-21 23:54:50 -08:00
Mike Welsh 1d8ae9154b tests: Add tests for AVM1 logical ops 2019-12-21 23:01:10 -08:00
Mike Welsh a4a307cf9a avm1: Use proper bool conversions for logical ops
ActionAnd, ActionOr, and ActionNot were incorrectly comparing
to 0. This only works for SWF<4. Now they all go through the
Value::as_bool method to handle version specific behavior.

Value::from_bool_v1 was also renamed to Value::from_bool.
2019-12-21 23:01:10 -08:00
Mike Welsh 00fdc74f1f tests: Add test for property updating in fast-forward gotos 2019-12-21 21:16:27 -08:00
Mike Welsh fd92bd5f78 core: Fix PlaceObject modifications in fast-forward gotos
When fast-forwarding with a goto, modifications were not taking
effect to objects that exist both in the starting and the final
frame.
2019-12-21 21:16:27 -08:00
Nathan Adams eedc4bbe24 core: Added Input backend, currently unimplemented, for polling user input 2019-12-21 19:08:06 -08:00
Nathan Adams 6c484fe29d core: Changed KeyCode into an enum that maps out every Flash key code 2019-12-21 19:08:06 -08:00
Mike Welsh d7df15989f core: Clear drag if object is removed while dragging 2019-12-21 16:28:41 -08:00
Mike Welsh 531e4d640d avm1: Implement StartDrag/EndDrag 2019-12-21 16:28:41 -08:00
Mike Welsh 713e959ce4 core: Implement DisplayObject::object for Button 2019-12-21 16:28:41 -08:00
Mike Welsh 4bd54cc2ea core: Fix DisplayObject::global_to_local and local_to_global 2019-12-21 16:28:41 -08:00
Mike Welsh f2d31b222b core: Implement DefineButtonCxform SWF tag
(Although nothing uses this... it was only used in SWF version 2
and below!)
2019-12-20 19:20:25 -08:00
dependabot-preview[bot] e8e0b83d23 build(deps): bump smallvec from 1.0.0 to 1.1.0
Bumps [smallvec](https://github.com/servo/rust-smallvec) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/servo/rust-smallvec/releases)
- [Commits](https://github.com/servo/rust-smallvec/compare/v1.0.0...v1.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-20 22:36:07 +00:00
Mike Welsh 4026e22bbf core: Handle DefineButtonSound SWF tag
This plays sounds whenever a button is hovered/clicked. Fixes
gun sounds in Pico's School.
2019-12-20 01:08:28 -08:00
Mike Welsh d459bbe010 avm1: Functions store their base clip
Functions now store their base clip (the code that contains the
executing bytecode). This is because `GotoFrame` and other actions
will execute on the clip the bytecode exists on, not on `this`.

(Note that `this.gotoAndStop` uses `GetMember` actions, which
worked correctly).

`Activation` now stores `target_clip`, and `Avm1::target_clip` and
`target_clip_or_root` grab this from the current stack frame.

Renamed `start_clip` to `base_clip` to match Flash conventions.
Removed `active_clip` as this was superfluous. Now you can use
`Avm1::target_clip_or_root`.

`UpdateContext` no longer contains `target_clip` etc.
2019-12-19 17:30:50 -08:00
Mike Welsh c4b446ff78 tests: Add test for functions closing over base clip 2019-12-19 17:30:50 -08:00
Mike Welsh 13c43ed171 tests: Update movieclip_hittest to verify points are in root coordinates 2019-12-19 12:35:56 -08:00
Mike Welsh 540b03090a avm1: hitTest point is actually in root coordinates (fix #185) 2019-12-19 12:35:56 -08:00
Nathan Adams f6f358b4de avm1: Expose TextFields and allow setting their .text 2019-12-19 10:19:43 -08:00
Mike Welsh c9a5d2dbb3 chore: Fix clippy lints in 1.40 2019-12-19 09:10:41 -08:00
Nathan Adams d3848f97ea avm1: Implemented MovieClip.hittest, without shape flag 2019-12-18 15:21:14 -08:00
Nathan Adams 5f6eea6f25 chore: Refactor system listeners into a reusable system 2019-12-18 15:15:56 -08:00
Mike Welsh 3a8256a993 avm1: Allow setting _name 2019-12-18 14:07:32 -08:00
Mike Welsh 9079b69991 avm1: Push Undefined when trying to construct invalid object 2019-12-18 13:47:01 -08:00
Mike Welsh bb6a4c119c avm1: Warn and clear operand stack if not empty after execution
Add a check and clear the stack if it isn't empty at the end of
`run_stack_till_empty`. This is probably a bug on our side
and we a good place for breakpoints.
2019-12-18 13:47:01 -08:00
Mike Welsh 8b9aedc4c8 avm1: Fix extra stack frame in event handlers
When running an clip event handler (e.g. onEnterFrame), a stack
frame is pushed to get the property value. However, this frame
was causing an extra Undefined to be pushed on the operand stack in
`Avm1::retire_stack_frame`, which would blow out the stack.

Now this stack frame is popped after the property is resolved and
before the function is executed. The function will push its own
stack frame when it executes.
2019-12-18 13:47:01 -08:00
Mike Welsh 3e003ed9dd avm1: Add missing stage.rs 2019-12-17 22:36:53 -08:00
Mike Welsh 3ebc1ed928 avm1: Stub out Stage properties
This is a very rough stub out of Stage.width and height to get
basic V-cams to start functioning.

TODO: Implement the different stage scaling modes. We will probably
want to add a "Stage" display object to handle this.
2019-12-17 22:28:44 -08:00
Mike Welsh 2af76e10f8 core: Mark scale/rotation as dirty when matrix changes 2019-12-17 22:06:34 -08:00
Mike Welsh 74aa127b74 avm1: Fix double borrow in Executable::exec 2019-12-17 21:35:22 -08:00
Mike Welsh 32953d5c5c avm1: Allow objects in ActionSetTarget2
Fixes 8-Bit Theater 3 soft locking on the first frame.
2019-12-17 18:32:25 -08:00
Mike Welsh a9baf72c53 avm1: Handle trailing / in slash paths 2019-12-17 04:00:01 -08:00
Mike Welsh 28faf2030b tests: Add failing case to slash_syntax test 2019-12-17 04:00:01 -08:00
Mike Welsh dae3e27fb3 avm1: Rename Library::instantiate_by_id 2019-12-17 03:27:05 -08:00
Mike Welsh fc3878d6d9 tests: Add tests for movie clip cloning/removing 2019-12-17 03:20:01 -08:00
Mike Welsh 1476930e0c avm1: Implement MovieClip.removeMovieClip 2019-12-17 03:20:01 -08:00
Mike Welsh 1668e823e6 avm1: Implement MovieClip.createEmptyMovieClip 2019-12-17 03:02:07 -08:00
Mike Welsh d33a8278d7 avm1: Implement MovieClip.duplicateMovieClip 2019-12-17 03:00:56 -08:00
Mike Welsh 009da39f12 avm1: Implement MovieClip.attachMovie 2019-12-17 03:00:56 -08:00
Mike Welsh d0504104b7 core: Use i32 for display object depth 2019-12-17 02:48:55 -08:00
Mike Welsh 4cb2cefc5b swf: Switch depth to u16 2019-12-17 02:48:55 -08:00
Mike Welsh 0f3bad8f1b core: Wrap Font in a Gc 2019-12-17 02:48:55 -08:00
Mike Welsh 289e0b8aff core: Handle ExportAssets SWF tag 2019-12-16 19:32:34 -08:00
Mike Welsh b6df9fded0 core: Remove boxes from library items 2019-12-16 19:32:34 -08:00
Nathan Adams 45e497826b avm1: Implement `Mouse` listeners & events (excluding scroll) 2019-12-16 19:22:10 -08:00
Mike Welsh c2f4633cdb avm1: Trace constant_pool in Collect for Activation 2019-12-16 16:14:49 -08:00
Mike Welsh c61842a72a tests: Add test for slash syntax 2019-12-16 15:33:57 -08:00
Mike Welsh f270a278c0 avm1: Push Undefined on GetVariable with invalid slash path 2019-12-16 15:33:16 -08:00
Mike Welsh 8b85212513 avm1: Handle .. in slash syntax 2019-12-16 15:24:25 -08:00
Mike Welsh f4f755e958 avm1: Remove warnings on _currentframe/_totalframe 2019-12-16 10:21:37 -08:00
Nathan Adams 84ff69854a avm1: Pass mouse events down to movie clips 2019-12-16 10:11:23 -08:00
Nathan Adams c8e42123cf avm1: Implemented `_xmouse` and `_ymouse` 2019-12-16 10:11:23 -08:00
Nathan Adams 783037e8cc chore: Removed array debug code that snuck in. Oops! 2019-12-16 09:56:46 -08:00
Mike Welsh e4af2502dc avm1: Fix mismatched action/init_action stack frames
DoAction was accidentally creating its stack frame using
Avm1::insert_stack_frame_for_init_action, causing a dummy
Undefined to be pushed and blowing out the stack.
2019-12-16 01:14:06 -08:00
Mike Welsh b2cdc19f55 tests: Add test for goto MovieClip methods 2019-12-16 00:52:27 -08:00
Mike Welsh bf0b777246 avm1: Use ECMA-262 ToInt32 modulo behavior
Everything is a double in ES land, so when converting a number to
int, the double is modulo'd to allow for wrapping 32-bit int
semantics.

See ToInt32 and ToUInt32 in the specs:
https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%202nd%20edition,%20August%201998.pdf
2019-12-16 00:52:27 -08:00
Mike Welsh 39f54b4a16 avm1: Add gotoAndPlay and gotoAndStop MovieClip methods 2019-12-16 00:52:27 -08:00
Mike Welsh a3e316847b core: Clamp goto frame in range 2019-12-16 00:52:27 -08:00
Mike Welsh fa5a168fad avm1: Clean up MovieClip prototype 2019-12-16 00:52:27 -08:00
Mike Welsh 46365c5702 avm1: Implement clip event method callbacks 2019-12-15 20:01:50 -08:00
Mike Welsh eb3aa1c878 core: Move `ClipAction` into crate::events 2019-12-15 19:22:23 -08:00
Mike Welsh 1fe170400c tests: Add clip_events regression test 2019-12-15 19:22:23 -08:00
Mike Welsh 76e94dda1c core: Implement "unload" clip event
Fire unload clip event when a movie clip is removed. Added
`ActionType` enum used by `ActionQueue::queue_actions` that
determines the type of action that is running (replaces `is_init`
parameter).
2019-12-15 19:00:16 -08:00
Mike Welsh 38ebdd9d05 core: Fire "load" and "enterFrame" clip events
MovieClips will now fire their "load" and "enterFrame" clip events.
Added `MovieClipFlags` to store various flags for the movie clip.
2019-12-15 19:00:16 -08:00
Mike Welsh 174426856f avm1: Use `EnumSet::from_bits` in `object::as_set_prop_func` 2019-12-15 14:26:43 -08:00
David Wendt d9aac0f2cf Adjust `SuperObject` based on actual Flash behavior. 2019-12-15 13:32:04 -08:00
David Wendt edf7a19eb7 Implement `Function.prototype.toString`. 2019-12-15 13:32:04 -08:00
David Wendt 33c66571f5 Allow `is_instance_of` to inspect the prototype chains of implemented interfaces.
This makes the `extends_chain` test pass.
2019-12-15 13:32:04 -08:00
David Wendt 854526923e Calls to `super` inherently bind to itself.
This requires some subclassing nonsense to be able to smuggle a self-reference into `SuperObject`s. When successfully smuggled, all calls to `call` will be invoked with the `super` object as `this`. This allows constructor chaining to work.

Note that not all `Object` trait methods are implemented on `SuperObject`, so things like `delete this.x` in super constructors will randomly fail. This should be fixed.
2019-12-15 13:32:04 -08:00
David Wendt 548f19ffbb `ActionExtends` uses the class's explicit prototype, not it's implicit prototype which should almost always be `Function.prototype`. 2019-12-15 13:32:04 -08:00
David Wendt eb06501492 Since `get_local` doesn't scale the prototype chain anymore, we don't need to change the prototype chain traversal anymore. 2019-12-15 13:32:04 -08:00
David Wendt e08cfcd288 Enable the `as2-oop` test since it now passes. 2019-12-15 13:32:04 -08:00