diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index acd11fce7..0cb97c03e 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -589,6 +589,9 @@ swf_tests! { (as3_simplebutton_constr_params, "avm2/simplebutton_constr_params", 1), (as3_place_object_replace, "avm2/place_object_replace", 2), (as3_place_object_replace_2, "avm2/place_object_replace_2", 3), + (as3_function_call_default, "avm2/function_call_default", 1), + (as3_function_call_types, "avm2/function_call_types", 1), + (as3_function_call_coercion, "avm2/function_call_coercion", 1), } // TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough. diff --git a/tests/tests/swfs/avm2/function_call_coercion/Test.as b/tests/tests/swfs/avm2/function_call_coercion/Test.as new file mode 100644 index 000000000..5975c6245 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_coercion/Test.as @@ -0,0 +1,201 @@ +package { + public class Test {} +} + +class CoercibleAsString { + public function toString() { + return "-99.13"; + } +} + +class CoercibleAsValue { + public function valueOf() { + return 23.16; + } +} + +function coerces_param_into_int(i: int) { + return i; +} + +function coerces_param_into_uint(i: uint) { + return i; +} + +function coerces_param_into_Number(i: Number) { + return i; +} + +function coerces_param_into_Boolean(i: Boolean) { + return i; +} + +function coerces_param_into_String(i: String) { + return i; +} + +function coerces_param_into_Object(i: Object) { + return i; +} + +trace("//coerces_param_into_int(undefined);"); +trace(coerces_param_into_int(undefined)); + +trace("//coerces_param_into_int(null);"); +trace(coerces_param_into_int(null)); + +trace("//coerces_param_into_int(true);"); +trace(coerces_param_into_int(true)); + +trace("//coerces_param_into_int(false);"); +trace(coerces_param_into_int(false)); + +trace("//coerces_param_into_int(5.12);"); +trace(coerces_param_into_int(5.12)); + +trace("//coerces_param_into_int(-6);"); +trace(coerces_param_into_int(-6)); + +trace("//coerces_param_into_int(\"12.23\");"); +trace(coerces_param_into_int("12.23")); + +trace("//coerces_param_into_int(new CoercibleAsString());"); +trace(coerces_param_into_int(new CoercibleAsString())); + +trace("//coerces_param_into_int(new CoercibleAsValue());"); +trace(coerces_param_into_int(new CoercibleAsValue())); + +trace("//coerces_param_into_uint(undefined);"); +trace(coerces_param_into_uint(undefined)); + +trace("//coerces_param_into_uint(null);"); +trace(coerces_param_into_uint(null)); + +trace("//coerces_param_into_uint(true);"); +trace(coerces_param_into_uint(true)); + +trace("//coerces_param_into_uint(false);"); +trace(coerces_param_into_uint(false)); + +trace("//coerces_param_into_uint(5.12);"); +trace(coerces_param_into_uint(5.12)); + +trace("//coerces_param_into_uint(-6);"); +trace(coerces_param_into_uint(-6)); + +trace("//coerces_param_into_uint(\"12.23\");"); +trace(coerces_param_into_uint("12.23")); + +trace("//coerces_param_into_uint(new CoercibleAsString());"); +trace(coerces_param_into_uint(new CoercibleAsString())); + +trace("//coerces_param_into_uint(new CoercibleAsValue());"); +trace(coerces_param_into_uint(new CoercibleAsValue())); + +trace("//coerces_param_into_Number(undefined);"); +trace(coerces_param_into_Number(undefined)); + +trace("//coerces_param_into_Number(null);"); +trace(coerces_param_into_Number(null)); + +trace("//coerces_param_into_Number(true);"); +trace(coerces_param_into_Number(true)); + +trace("//coerces_param_into_Number(false);"); +trace(coerces_param_into_Number(false)); + +trace("//coerces_param_into_Number(5.12);"); +trace(coerces_param_into_Number(5.12)); + +trace("//coerces_param_into_Number(-6);"); +trace(coerces_param_into_Number(-6)); + +trace("//coerces_param_into_Number(\"12.23\");"); +trace(coerces_param_into_Number("12.23")); + +trace("//coerces_param_into_Number(new CoercibleAsString());"); +trace(coerces_param_into_Number(new CoercibleAsString())); + +trace("//coerces_param_into_Number(new CoercibleAsValue());"); +trace(coerces_param_into_Number(new CoercibleAsValue())); + +trace("//coerces_param_into_Boolean(undefined);"); +trace(coerces_param_into_Boolean(undefined)); + +trace("//coerces_param_into_Boolean(null);"); +trace(coerces_param_into_Boolean(null)); + +trace("//coerces_param_into_Boolean(true);"); +trace(coerces_param_into_Boolean(true)); + +trace("//coerces_param_into_Boolean(false);"); +trace(coerces_param_into_Boolean(false)); + +trace("//coerces_param_into_Boolean(5.12);"); +trace(coerces_param_into_Boolean(5.12)); + +trace("//coerces_param_into_Boolean(-6);"); +trace(coerces_param_into_Boolean(-6)); + +trace("//coerces_param_into_Boolean(\"12.23\");"); +trace(coerces_param_into_Boolean("12.23")); + +trace("//coerces_param_into_Boolean(new CoercibleAsString());"); +trace(coerces_param_into_Boolean(new CoercibleAsString())); + +trace("//coerces_param_into_Boolean(new CoercibleAsValue());"); +trace(coerces_param_into_Boolean(new CoercibleAsValue())); + +trace("//coerces_param_into_String(undefined);"); +trace(coerces_param_into_String(undefined)); + +trace("//coerces_param_into_String(null);"); +trace(coerces_param_into_String(null)); + +trace("//coerces_param_into_String(true);"); +trace(coerces_param_into_String(true)); + +trace("//coerces_param_into_String(false);"); +trace(coerces_param_into_String(false)); + +trace("//coerces_param_into_String(5.12);"); +trace(coerces_param_into_String(5.12)); + +trace("//coerces_param_into_String(-6);"); +trace(coerces_param_into_String(-6)); + +trace("//coerces_param_into_String(\"12.23\");"); +trace(coerces_param_into_String("12.23")); + +trace("//coerces_param_into_String(new CoercibleAsString());"); +trace(coerces_param_into_String(new CoercibleAsString())); + +trace("//coerces_param_into_String(new CoercibleAsValue());"); +trace(coerces_param_into_String(new CoercibleAsValue())); + +trace("//coerces_param_into_Object(undefined);"); +trace(coerces_param_into_Object(undefined)); + +trace("//coerces_param_into_Object(null);"); +trace(coerces_param_into_Object(null)); + +trace("//coerces_param_into_Object(true);"); +trace(coerces_param_into_Object(true)); + +trace("//coerces_param_into_Object(false);"); +trace(coerces_param_into_Object(false)); + +trace("//coerces_param_into_Object(5.12);"); +trace(coerces_param_into_Object(5.12)); + +trace("//coerces_param_into_Object(-6);"); +trace(coerces_param_into_Object(-6)); + +trace("//coerces_param_into_Object(\"12.23\");"); +trace(coerces_param_into_Object("12.23")); + +trace("//coerces_param_into_Object(new CoercibleAsString());"); +trace(coerces_param_into_Object(new CoercibleAsString())); + +trace("//coerces_param_into_Object(new CoercibleAsValue());"); +trace(coerces_param_into_Object(new CoercibleAsValue())); \ No newline at end of file diff --git a/tests/tests/swfs/avm2/function_call_coercion/output.txt b/tests/tests/swfs/avm2/function_call_coercion/output.txt new file mode 100644 index 000000000..03d892a79 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_coercion/output.txt @@ -0,0 +1,108 @@ +//coerces_param_into_int(undefined); +0 +//coerces_param_into_int(null); +0 +//coerces_param_into_int(true); +1 +//coerces_param_into_int(false); +0 +//coerces_param_into_int(5.12); +5 +//coerces_param_into_int(-6); +-6 +//coerces_param_into_int("12.23"); +12 +//coerces_param_into_int(new CoercibleAsString()); +-99 +//coerces_param_into_int(new CoercibleAsValue()); +23 +//coerces_param_into_uint(undefined); +0 +//coerces_param_into_uint(null); +0 +//coerces_param_into_uint(true); +1 +//coerces_param_into_uint(false); +0 +//coerces_param_into_uint(5.12); +5 +//coerces_param_into_uint(-6); +4294967290 +//coerces_param_into_uint("12.23"); +12 +//coerces_param_into_uint(new CoercibleAsString()); +4294967197 +//coerces_param_into_uint(new CoercibleAsValue()); +23 +//coerces_param_into_Number(undefined); +NaN +//coerces_param_into_Number(null); +0 +//coerces_param_into_Number(true); +1 +//coerces_param_into_Number(false); +0 +//coerces_param_into_Number(5.12); +5.12 +//coerces_param_into_Number(-6); +-6 +//coerces_param_into_Number("12.23"); +12.23 +//coerces_param_into_Number(new CoercibleAsString()); +-99.13 +//coerces_param_into_Number(new CoercibleAsValue()); +23.16 +//coerces_param_into_Boolean(undefined); +false +//coerces_param_into_Boolean(null); +false +//coerces_param_into_Boolean(true); +true +//coerces_param_into_Boolean(false); +false +//coerces_param_into_Boolean(5.12); +true +//coerces_param_into_Boolean(-6); +true +//coerces_param_into_Boolean("12.23"); +true +//coerces_param_into_Boolean(new CoercibleAsString()); +true +//coerces_param_into_Boolean(new CoercibleAsValue()); +true +//coerces_param_into_String(undefined); +null +//coerces_param_into_String(null); +null +//coerces_param_into_String(true); +true +//coerces_param_into_String(false); +false +//coerces_param_into_String(5.12); +5.12 +//coerces_param_into_String(-6); +-6 +//coerces_param_into_String("12.23"); +12.23 +//coerces_param_into_String(new CoercibleAsString()); +-99.13 +//coerces_param_into_String(new CoercibleAsValue()); +[object CoercibleAsValue] +//coerces_param_into_Object(undefined); +null +//coerces_param_into_Object(null); +null +//coerces_param_into_Object(true); +true +//coerces_param_into_Object(false); +false +//coerces_param_into_Object(5.12); +5.12 +//coerces_param_into_Object(-6); +-6 +//coerces_param_into_Object("12.23"); +12.23 +//coerces_param_into_Object(new CoercibleAsString()); +-99.13 +//coerces_param_into_Object(new CoercibleAsValue()); +[object CoercibleAsValue] diff --git a/tests/tests/swfs/avm2/function_call_coercion/test.fla b/tests/tests/swfs/avm2/function_call_coercion/test.fla new file mode 100644 index 000000000..831019f41 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_coercion/test.fla differ diff --git a/tests/tests/swfs/avm2/function_call_coercion/test.swf b/tests/tests/swfs/avm2/function_call_coercion/test.swf new file mode 100644 index 000000000..e389fbe35 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_coercion/test.swf differ diff --git a/tests/tests/swfs/avm2/function_call_default/Test.as b/tests/tests/swfs/avm2/function_call_default/Test.as new file mode 100644 index 000000000..cecccf312 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_default/Test.as @@ -0,0 +1,19 @@ +package { + public class Test {} +} + +function testfunc(v1, v2, v3 = "Default string") { + trace(v1); + trace(v2); + trace(v3); +} + +function testfunc2(v1 = "Default string 0", v2 = "Default string 1", v3 = "Default string 2") { + trace(v1); + trace(v2); + trace(v3); +} + +testfunc("arg1", "arg2"); + +testfunc2("arg_again_1"); \ No newline at end of file diff --git a/tests/tests/swfs/avm2/function_call_default/output.txt b/tests/tests/swfs/avm2/function_call_default/output.txt new file mode 100644 index 000000000..9f36652b8 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_default/output.txt @@ -0,0 +1,6 @@ +arg1 +arg2 +Default string +arg_again_1 +Default string 1 +Default string 2 diff --git a/tests/tests/swfs/avm2/function_call_default/test.fla b/tests/tests/swfs/avm2/function_call_default/test.fla new file mode 100644 index 000000000..e84226824 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_default/test.fla differ diff --git a/tests/tests/swfs/avm2/function_call_default/test.swf b/tests/tests/swfs/avm2/function_call_default/test.swf new file mode 100644 index 000000000..e18d07953 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_default/test.swf differ diff --git a/tests/tests/swfs/avm2/function_call_types/Test.as b/tests/tests/swfs/avm2/function_call_types/Test.as new file mode 100644 index 000000000..8862e0a70 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_types/Test.as @@ -0,0 +1,11 @@ +package { + public class Test {} +} + +function testfunc(v1: int, v2: Boolean, v3: String) { + trace(v1); + trace(v2); + trace(v3); +} + +testfunc(5, true, "yes"); \ No newline at end of file diff --git a/tests/tests/swfs/avm2/function_call_types/output.txt b/tests/tests/swfs/avm2/function_call_types/output.txt new file mode 100644 index 000000000..a8cb08c69 --- /dev/null +++ b/tests/tests/swfs/avm2/function_call_types/output.txt @@ -0,0 +1,3 @@ +5 +true +yes diff --git a/tests/tests/swfs/avm2/function_call_types/test.fla b/tests/tests/swfs/avm2/function_call_types/test.fla new file mode 100644 index 000000000..e84226824 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_types/test.fla differ diff --git a/tests/tests/swfs/avm2/function_call_types/test.swf b/tests/tests/swfs/avm2/function_call_types/test.swf new file mode 100644 index 000000000..ee72631f1 Binary files /dev/null and b/tests/tests/swfs/avm2/function_call_types/test.swf differ