diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 173356568..252491905 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -143,7 +143,8 @@ To add a test here, create a .swf file that runs `trace()` statements. You can d * [`mtasc`](http://web.archive.org/web/20210324063628/http://tech.motion-twin.com/mtasc.html) (ActionScript 2 only) * if you create a file `test.as` with a `class Test` with a `static function main` with the code you want to run, you can compile it using `mtasc -main -header 200:150:30 test.as -swf test.swf` * [`mxmlc`](https://helpx.adobe.com/air/kb/archived-air-sdk-version.html) (ActionScript 3 only) - * if you create a file `test.as`, you can compile it using `mxmlc test.as`. `mxmlc` is located in the `bin` folder of the downloadable AIR SDK. + * if you create a file `test.as` with a `class Test`, you can compile it using `mxmlc Test.as`. `mxmlc` is located in the `bin` folder of the downloadable AIR SDK. + * you may want to use docker instead -- something like `docker run -it --rm -v ${PWD}:/src jeko/airbuild mxmlc ./Test.as` works well Run the .swf in Flash Player and create a file `output.txt` with the contents of the trace statements. Add the `output.txt`, `test.swf` and either the `test.as` or `test.fla` file to a directory under `core/tests/swfs/avm1` (or `avm2`) named after what your test tests, and add a line in `regression_tests.rs` to have Ruffle run it. diff --git a/core/src/avm2/globals/string.rs b/core/src/avm2/globals/string.rs index c320bcb66..077c8498b 100644 --- a/core/src/avm2/globals/string.rs +++ b/core/src/avm2/globals/string.rs @@ -11,6 +11,7 @@ use crate::avm2::ArrayObject; use crate::avm2::Error; use crate::string_utils; use gc_arena::{GcCell, MutationContext}; +use std::iter; /// Implements `String`'s instance initializer. pub fn instance_init<'gc>( @@ -126,12 +127,16 @@ fn split<'gc>( args: &[Value<'gc>], ) -> Result, Error> { if let Some(this) = this { - if matches!(args.get(0).unwrap_or(&Value::Undefined), Value::Undefined) { - log::warn!("string.split(undefined) - not implemented"); + let delimiter = args.get(0).unwrap_or(&Value::Undefined); + if matches!(delimiter, Value::Undefined) { + let this = Value::from(this); + return Ok( + ArrayObject::from_storage(activation, iter::once(this).collect()) + .unwrap() + .into(), + ); } - if args - .get(0) - .unwrap_or(&Value::Undefined) + if delimiter .coerce_to_object(activation)? .as_regexp() .is_some() @@ -139,10 +144,7 @@ fn split<'gc>( log::warn!("string.split(regex) - not implemented"); } let this = Value::from(this).coerce_to_string(activation)?; - let delimiter = args - .get(0) - .unwrap_or(&Value::Undefined) - .coerce_to_string(activation)?; + let delimiter = delimiter.coerce_to_string(activation)?; let limit = match args.get(1).unwrap_or(&Value::Undefined) { Value::Undefined => usize::MAX, limit => limit.coerce_to_i32(activation)?.max(0) as usize, diff --git a/tests/tests/swfs/avm2/string_split/output.txt b/tests/tests/swfs/avm2/string_split/output.txt index f020ed42e..c6d56e57a 100644 --- a/tests/tests/swfs/avm2/string_split/output.txt +++ b/tests/tests/swfs/avm2/string_split/output.txt @@ -5,5 +5,6 @@ a,b,c // text.split("") a,.,b,.,c -// text.split() - unimplemented +// text.split() +a.b.c // text.split(regex) - unimplemented diff --git a/tests/tests/swfs/avm2/string_split/test.as b/tests/tests/swfs/avm2/string_split/test.as index 76a962489..a91f31b88 100644 --- a/tests/tests/swfs/avm2/string_split/test.as +++ b/tests/tests/swfs/avm2/string_split/test.as @@ -16,7 +16,8 @@ trace(text.split(".")); trace('// text.split("")'); trace(text.split("")); -trace('// text.split() - unimplemented'); +trace('// text.split()'); +trace(text.split()); trace('// text.split(regex) - unimplemented'); diff --git a/tests/tests/swfs/avm2/string_split/test.swf b/tests/tests/swfs/avm2/string_split/test.swf index 9618de290..e015dba6c 100644 Binary files a/tests/tests/swfs/avm2/string_split/test.swf and b/tests/tests/swfs/avm2/string_split/test.swf differ