Commit Graph

1223 Commits

Author SHA1 Message Date
dependabot-preview[bot] a1cf2d3ab8 build(deps): bump png from 0.15.1 to 0.15.2
Bumps [png](https://github.com/image-rs/image-png) from 0.15.1 to 0.15.2.
- [Release notes](https://github.com/image-rs/image-png/releases)
- [Changelog](https://github.com/image-rs/image-png/blob/master/CHANGES.md)
- [Commits](https://github.com/image-rs/image-png/compare/v0.15.1...v0.15.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-04 07:07:57 +00:00
Mike Welsh 29754eace8 web: Avoid `copyToChannel` on Safari
`AudioBuffer.copyToChannel` does not work on Safari, so switch to
using `getChannelData` to fill the audio buffers.

Limitations in wasm-bindgen prevent us from actually modifying the
data returned by `getChannelData` on the Rust side, so import a JS
function to fill the audio buffer (js-src/ruffle-imports.js).
2019-12-03 23:05:42 -08:00
Mike Welsh cbe0f873af tests: Add test for Object.addProperty 2019-12-03 15:01:39 -08:00
Mike Welsh 90b6858bb2 avm1: Fix return value of `Object.addProperty` 2019-12-03 14:59:37 -08:00
Mike Welsh 28364f7d00 avm1: Fix `this` object in GetMember/SetMember 2019-12-03 14:59:01 -08:00
Mike Welsh 1a1cdfa757 desktop: Allow audio creation to fail
Switch to NullAudioBackend if CpalAudioBackend fails to initialize.
(This happens on my laptop which doesn't have an audio device!)
2019-11-30 20:08:34 -08:00
Nathan Adams eb185982cd Add more Number(x) tests, and corrected primitive_as_number to match 2019-11-29 16:07:35 -08:00
Nathan Adams 85b9ffe102 core: Merge both test macros into a generic test_method 2019-11-29 13:12:00 -08:00
Nathan Adams 1f4405189a core: Make math test_std also take in versions 2019-11-29 13:12:00 -08:00
Nathan Adams 999bb128de core: Allow global test_std to test multiple swf versions 2019-11-29 13:12:00 -08:00
Nathan Adams 4c7d37c498 core: Added `avm_debug!` macro 2019-11-29 12:59:45 -08:00
Nathan Adams d1b73582ce core: Add feature `avm_debug` that toggles tracing avm actions and stack history 2019-11-29 12:59:45 -08:00
Mike Welsh d7ec4398b8
core: Merge #114, ECMA abstract comparisons 2019-11-29 12:52:57 -08:00
David Wendt 9ec85c3892 Add tests for SWF6 numerical coercions. 2019-11-28 21:32:10 -05:00
David Wendt f856243247 Primitive coercions should not yield an object just because valueOf is undefined. 2019-11-28 20:53:32 -05:00
David Wendt ec3ac4e5d6 `undefined` coerces to `0.0` on SWF6 2019-11-28 20:53:32 -05:00
David Wendt 89e060be4e Add a regression test for `_global` being a bare object 2019-11-28 20:53:31 -05:00
David Wendt 16259ad74a Calling uncallable values does not actually cause a runtime error in Flash; it just returns null.
This was discovered almost by accident: @Dinnerbone noticed that `_global == null`, and surmised that `valueOf` was the culprit. However, this doesn't really make sense: `_global` is a bare object, so it shouldn't have a `valueOf` (and in practice, it doesn't).

The ultimate cause of such an odd comparison is as such:

1. Flash coerces the `_global` object to a numerical primitive by calling `valueOf`.
2. `_global.valueOf` is undefined. Flash handles calls to any uncallable value by literally just having it return `undefined`. In other words, all values are implicitly callable as empty functions.
3. `undefined` is then compared to `null`. These two values *are* equal under abstract equality (`==`). Hence, `_global == null`.

For comparison, modern ECMAScript engines throw errors on calls to uncallable values; and won't attempt to use an invalid `valueOf` to coerce objects. So none of this applies to, say, standard JavaScript in your browser.
2019-11-28 20:53:31 -05:00
Nathan Adams 68760007fc Lessthan can return `undefined`, not just booleans 2019-11-28 20:53:30 -05:00
Nathan Adams 638231e7fb swf4 doesn't have NaN or Infinity 2019-11-28 20:53:20 -05:00
Nathan Adams 581d0940b2 NaN == NaN without coercion 2019-11-28 20:43:59 -05:00
Nathan Adams f33229a2a1 `_global` == null && `_global` == undefined 2019-11-28 20:43:58 -05:00
Nathan Adams ec5ed4f140 Change regression_test to use `actual, expected` so tools (like intelliJ) diff it correctly 2019-11-28 20:43:54 -05:00
Nathan Adams f5b78f6fb0 Typo in test filename 2019-11-28 20:41:26 -05:00
Nathan Adams bda72728ac Assume that NaN == NaN for ruffle 2019-11-28 20:41:25 -05:00
Nathan Adams c9c4749bb0 core: Added battery of tests for lessthan, greaterthan, equals and strictequals between swf4-swf7 2019-11-28 20:41:23 -05:00
Nathan Adams 3f4597f081 Add tests for lessthan 2019-11-28 20:31:02 -05:00
David Wendt 504f962256 Add a test for every string coercion I could find. 2019-11-28 20:28:46 -05:00
David Wendt 129d50bfa6 Implement ECMAScript compliant type coercions.
This includes ECMA-262 2ed `ToNumber`, `ToPrimitive` (Number), `ToString`, and abstract equality and less-than implementations. Note that `ToPrimitive` is only the "number hint" variant, and Flash specifically *never* calls `toString` like how ECMA-262 specifies.

Several builtins inherit numerical coercion - I'm not 100% sure if that's correct.

The following ActionScript opcodes now perform ECMA-262 style coercions:

`ActionAdd2` (uses `valueOf` / "ToPrimitive hint Number")
`ActionDecrement` (uses `valueOf`)
`ActionEquals2` (uses `valueOf`)
`ActionGetMember` (member names, uses `toString`)
`ActionIncrement` (uses `valueOf`)
`ActionLess2` (uses `valueOf`)
`ActionGreater` (uses `valueOf`)
`ActionSetMember` (member names, uses `toString`)
`ActionStringEquals` (uses `toString`)
`ActionStringGreater` (uses `toString`)
`ActionStringLess` (uses `toString`)
`ActionToNumber` (uses `valueOf`)
`ActionToString` (uses `toString`)
`ActionTrace` (uses `toString`)

The following functions now gained user-specified coercions via `toString`:
`_global.number` (uses `valueOf`)
`_global.is_nan` (uses `valueOf`)
Every function in `Math` (uses `valueOf`)
2019-11-28 20:23:39 -05:00
Mike Welsh 75fd2b6a52
core: Merge #100, Object prototypes
Object prototypes
2019-11-28 16:03:25 -08:00
Nathan Adams 2650433271 Fixed get_keys with prototypes 2019-11-27 22:30:31 +01:00
Nathan Adams 585c520b87 Added prototype_enumerate test, `for (key in obj)` 2019-11-27 21:46:21 +01:00
Nathan Adams fdbd16a5d9 Ignore extends_chain, that's NYI 2019-11-27 21:11:03 +01:00
Nathan Adams 57d8469e3b Added a test for isPrototypeOf 2019-11-27 21:09:14 +01:00
David Wendt 1eb4dfa696 Merge remote-tracking branch 'dinnerbone/feature/extends_test' into feature/prototyping 2019-11-27 14:58:47 -05:00
David Wendt 5999aded7a Merge remote-tracking branch 'dinnerbone/feature/prototype_tests' into feature/prototyping 2019-11-27 14:56:39 -05:00
David Wendt 46e58c3ecd Remove `ReturnValue.ignore` entirely, since you really *do* need to resolve `ReturnValue`s, even if you don't want the result. 2019-11-27 14:52:07 -05:00
Nathan Adams b0f0008596 Added test for hasOwnProperty 2019-11-27 20:51:40 +01:00
Nathan Adams 03713f32e9 Correct fla for object_prototypes 2019-11-27 20:46:09 +01:00
Nathan Adams b43436bdd2 Enable recursive_prototypes test as it now passes 2019-11-27 20:31:33 +01:00
David Wendt 2c87888e28 Implement prototype chain recursion limit of 255 prototypes.
In Flash, this also at least claims to halt ActionScript execution on the movie. No such implementation of AVM poisoning currently exists in Ruffle, primarily because it's unclear what gets poisoned and implementing some of these options isn't yet possible:

1. AVM (e.g. all movies) - we would need to make the AVM fail silently in this case. This is the most straightforward way to poison the movie, but I'm not sure if this is how Flash actually does it, or if it poisons...
2. Movie - the current structure of movies is incompatible with adding arbitrary data to them. We need to merge `moviefetch` in before we can attach data to loaded movies.
3. MovieClip - this would also be implementable but has problems. How do child MovieClips know that their parent has been poisoned, or vice versa? What if a movie clip is loaded from one movie and moved into another?

As a result, I have decided to hold off on implementing recursion poisoning until I know where it's supposed to go and how to implement that.
2019-11-27 08:59:16 -05:00
Nathan Adams e9ad733e68 Add a test to see if the avm crashes with recursive prototypes.
Spoilers: it does.
2019-11-26 23:38:34 +01:00
Nathan Adams de1f5417ec Added test for extending MovieClip prototype 2019-11-26 23:22:07 +01:00
Nathan Adams ffaf10b604 Add test for prototyping 2019-11-26 23:22:07 +01:00
Nathan Adams 3bcd9ed71b Added test for class & interface hierarchy 2019-11-26 22:42:11 +01:00
Mike Welsh 97512d024c ci: Bump cache version 2019-11-26 12:35:33 -08:00
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