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?!
This commit is contained in:
David Wendt 2020-03-08 22:21:45 -04:00
parent 4b66af8dc3
commit 16774aa055
5 changed files with 99 additions and 0 deletions

View File

@ -247,6 +247,7 @@ swf_tests! {
(as3_object_to_string, "avm2/object_to_string", 1),
(as3_function_to_string, "avm2/function_to_string", 1),
(as3_class_to_string, "avm2/class_to_string", 1),
(as3_es3_inheritance, "avm2/es3_inheritance", 1),
}
// TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough.

View File

@ -0,0 +1,67 @@
package {
public class Test {
}
}
function Test2() {
trace("Instance constructor");
}
Test2.prototype.method = function() {
trace("Instance method");
}
Test2.prototype.method2 = function() {
trace("Instance method 2");
}
function Test3() {
trace("Child instance constructor pre-super");
Test2.call(this);
trace("Child instance constructor post-super");
}
Test3.prototype = new Test2();
Test3.prototype.method = function() {
trace("Child instance method pre-super");
Test2.prototype.method.call(this);
trace("Child instance method post-super");
}
Test3.prototype.method3 = function() {
trace("Child instance method3 pre-super");
Test2.prototype.method.call(this);
trace("Child instance method3 post-super");
}
function Test4() {
trace("Grandchild instance constructor pre-super");
Test3.call(this);
trace("Grandchild instance constructor post-super");
}
Test4.prototype = new Test3();
Test4.prototype.method2 = function () {
trace("Grandchild instance method2 pre-super");
Test3.prototype.method2.call(this);
trace("Grandchild instance method2 post-super");
}
Test4.prototype.method3 = function () {
trace("Grandchild instance method3 pre-super");
Test3.prototype.method3.call(this);
trace("Grandchild instance method3 post-super");
}
trace("Script initializer");
var x = new Test3();
x.method();
x.method2();
x.method3();
var y = new Test4();
y.method();
y.method2();
y.method3();

View File

@ -0,0 +1,31 @@
Instance constructor
Child instance constructor pre-super
Instance constructor
Child instance constructor post-super
Script initializer
Child instance constructor pre-super
Instance constructor
Child instance constructor post-super
Child instance method pre-super
Instance method
Child instance method post-super
Instance method 2
Child instance method3 pre-super
Instance method
Child instance method3 post-super
Grandchild instance constructor pre-super
Child instance constructor pre-super
Instance constructor
Child instance constructor post-super
Grandchild instance constructor post-super
Child instance method pre-super
Instance method
Child instance method post-super
Grandchild instance method2 pre-super
Instance method 2
Grandchild instance method2 post-super
Grandchild instance method3 pre-super
Child instance method3 pre-super
Instance method
Child instance method3 post-super
Grandchild instance method3 post-super

Binary file not shown.

Binary file not shown.