Permalink
Browse files

Merge pull request #214 from mbebenita/master

Separate passing tests from failing tests.
  • Loading branch information...
2 parents fda35bb + 45d8c6f commit 4c1e5bbe29a7accc20cf9267619cb8b5cc53e05d @mbebenita mbebenita committed Apr 6, 2013
Showing with 273 additions and 94 deletions.
  1. +1 −1 src/avm2/compiler/builder.js
  2. +9 −6 src/avm2/compiler/inferrer.js
  3. +82 −78 src/avm2/runtime.js
  4. 0 src/avm2/tests/regress/correctness/{ → fail}/coerce-1.as
  5. 0 src/avm2/tests/regress/correctness/{ → fail}/coerce-2.as
  6. 0 src/avm2/tests/regress/correctness/{ → fail}/instance-0.as
  7. 0 src/avm2/tests/regress/correctness/{ → fail}/type-0.as
  8. 0 src/avm2/tests/regress/correctness/{ → fail}/type-3.as
  9. +0 −3 src/avm2/tests/regress/correctness/functions-0.as
  10. 0 src/avm2/tests/regress/correctness/{ → pass}/arrays-0.as
  11. 0 src/avm2/tests/regress/correctness/{ → pass}/arrays.as
  12. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper1.as
  13. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper2.as
  14. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper3.as
  15. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper4.as
  16. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper5.as
  17. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper6.as
  18. 0 src/avm2/tests/regress/correctness/{ → pass}/callsuper7.as
  19. +16 −0 src/avm2/tests/regress/correctness/pass/classes-1.as
  20. 0 src/avm2/tests/regress/correctness/{ → pass}/classes.as
  21. 0 src/avm2/tests/regress/correctness/{ → pass}/closure0.as
  22. 0 src/avm2/tests/regress/correctness/{ → pass}/coerce-0.as
  23. 0 src/avm2/tests/regress/correctness/{ → pass}/default.as
  24. 0 src/avm2/tests/regress/correctness/{ → pass}/dictionary1.as
  25. 0 src/avm2/tests/regress/correctness/{ → pass}/dynamic-0.as
  26. +34 −0 src/avm2/tests/regress/correctness/pass/flow.as
  27. 0 src/avm2/tests/regress/correctness/{ → pass}/for-1.as
  28. 0 src/avm2/tests/regress/correctness/{ → pass}/for.as
  29. +4 −0 src/avm2/tests/regress/correctness/pass/functions-0.as
  30. +39 −0 src/avm2/tests/regress/correctness/pass/interface-0.as
  31. 0 src/avm2/tests/regress/correctness/{ → pass}/interfaceCast.as
  32. 0 src/avm2/tests/regress/correctness/{ → pass}/literals-0.as
  33. 0 src/avm2/tests/regress/correctness/{ → pass}/many-0.as
  34. 0 src/avm2/tests/regress/correctness/{ → pass}/method-closures-0.as
  35. +4 −1 src/avm2/tests/regress/correctness/{ → pass}/method-closures-1.as
  36. 0 src/avm2/tests/regress/correctness/{ → pass}/names.as
  37. 0 src/avm2/tests/regress/correctness/{ → pass}/numbers-0.as
  38. +7 −0 src/avm2/tests/regress/correctness/pass/phi-0.as
  39. 0 src/avm2/tests/regress/correctness/{ → pass}/play.as
  40. 0 src/avm2/tests/regress/correctness/{ → pass}/prot-0.as
  41. 0 src/avm2/tests/regress/correctness/{ → pass}/prot-1.as
  42. 0 src/avm2/tests/regress/correctness/{ → pass}/prot-2.as
  43. +69 −0 src/avm2/tests/regress/correctness/pass/proxy-0.as
  44. 0 src/avm2/tests/regress/correctness/{ → pass}/register-0.as
  45. 0 src/avm2/tests/regress/correctness/{ → pass}/simple.as
  46. 0 src/avm2/tests/regress/correctness/{ → pass}/sort.as
  47. 0 src/avm2/tests/regress/correctness/{ → pass}/swap.as
  48. 0 src/avm2/tests/regress/correctness/{ → pass}/switch1.as
  49. 0 src/avm2/tests/regress/correctness/{ → pass}/switch2.as
  50. 0 src/avm2/tests/regress/correctness/{ → pass}/type-1.as
  51. 0 src/avm2/tests/regress/correctness/{ → pass}/type-2.as
  52. +1 −1 src/avm2/tests/regress/correctness/{ → pass}/vectors-1.as
  53. 0 src/avm2/tests/regress/correctness/{ → pass}/vectors-2.as
  54. +4 −1 src/avm2/tests/regress/correctness/{ → pass}/vectors-3.as
  55. 0 src/avm2/tests/regress/correctness/{ → pass}/vectors.as
  56. +3 −3 src/avm2/tests/regress/correctness/{ → pass}/verifier.as
@@ -1121,7 +1121,7 @@ var c4TraceLevel = c4Options.register(new Option("tc4", "tc4", "number", 0, "Com
var key = pop();
assert (isConstant(key) && isString(key.value));
key = constant(Multiname.getPublicQualifiedName(key.value));
- properties.unshift(new KeyValuePair(key, value));
+ properties.push(new KeyValuePair(key, value));
}
push(new NewObject(properties));
break;
@@ -253,18 +253,20 @@ var TraitsType = (function () {
}
}
- traitsType.prototype.getTrait = function (mn, followSuperType) {
+ traitsType.prototype.getTrait = function (mn, isSetter, followSuperType) {
+ assert (arguments.length === 3);
+
if (followSuperType && this.isInstanceInfo()) {
var that = this;
do {
- var trait = that.getTrait(mn);
+ var trait = that.getTrait(mn, isSetter, false);
if (!trait) {
that = that.super();
}
} while (!trait && that);
return trait;
} else {
- return findTraitByName(this.traits, mn);
+ return findTraitByName(this.traits, mn, isSetter);
}
};
@@ -674,7 +676,8 @@ var Verifier = (function() {
// Try to find it in the scope stack.
for (var i = scope.length - 1; i >= 0; i--) {
if (scope[i] instanceof TraitsType) {
- var trait = scope[i].getTrait(mn, true);
+ // TODO: Should we be looking for getter / setter traits?
+ var trait = scope[i].getTrait(mn, false, true);
if (trait) {
ti().scopeDepth = scope.length - i - 1;
return scope[i];
@@ -743,7 +746,7 @@ var Verifier = (function() {
function getProperty(obj, mn) {
if (obj instanceof TraitsType && mn instanceof Multiname) {
- var trait = obj.getTrait(mn, true);
+ var trait = obj.getTrait(mn, false, true);
writer && writer.debugLn("getProperty(" + mn + ") -> " + trait);
if (trait) {
ti().trait = trait;
@@ -765,7 +768,7 @@ var Verifier = (function() {
function setProperty(obj, mn) {
if (obj instanceof TraitsType && mn instanceof Multiname) {
- var trait = obj.getTrait(mn, true);
+ var trait = obj.getTrait(mn, true, true);
writer && writer.debugLn("setProperty(" + mn + ") -> " + trait);
if (trait) {
ti().trait = trait;
View
@@ -1182,6 +1182,45 @@ var Runtime = (function () {
}
}
+ if (instance) {
+ this.applyProtectedBindings(instance.prototype, cls);
+ this.applyInterfaceBindings(instance.prototype, cls);
+ }
+
+ // Run the static initializer.
+ this.createFunction(classInfo.init, scope).call(cls);
+
+ // Seal constant traits in the class object.
+ compatibility && this.sealConstantTraits(cls, ci.traits);
+
+ // TODO: Seal constant traits in the instance object. This should be done after
+ // the instance constructor has executed.
+
+ if (traceClasses.value) {
+ domain.loadedClasses.push(cls);
+ domain.traceLoadedClasses();
+ }
+
+ return cls;
+ };
+
+ runtime.prototype.createInterface = function createInterface(classInfo) {
+ var ii = classInfo.instanceInfo;
+ release || assert(ii.isInterface());
+ if (traceExecution.value) {
+ var str = "Creating interface " + ii.name;
+ if (ii.interfaces.length) {
+ str += " implements " + ii.interfaces.map(function (name) {
+ return name.getName();
+ }).join(", ");
+ }
+ print(str);
+ }
+ return new Interface(classInfo);
+ };
+
+ runtime.prototype.applyProtectedBindings = function applyProtectedBindings(obj, cls) {
+
// Deal with the protected namespace bullshit. In AS3, if you have the following code:
//
// class A {
@@ -1207,56 +1246,54 @@ var Runtime = (function () {
// Then we need a binding from protected$A$foo -> protected$C$foo, and
// protected$B$foo -> protected$C$foo.
- function applyProtectedTraits(cls) {
- var map = Object.create(null);
+ var map = Object.create(null);
- // Walks up the inheritance hierarchy and collects the last defining namespace for each
- // protected member as well as all the protected namespaces from the first definition.
- (function gather(cls) {
- if (cls.baseClass) {
- gather(cls.baseClass);
- }
- var ii = cls.classInfo.instanceInfo;
- for (var i = 0; i < ii.traits.length; i++) {
- var trait = ii.traits[i];
- if (trait.isProtected()) {
- var name = trait.name.getName();
- if (!map[name]) {
- map[name] = {definingNamespace: ii.protectedNs, namespaces: [], trait: trait};
- }
- map[name].definingNamespace = ii.protectedNs;
+ // Walks up the inheritance hierarchy and collects the last defining namespace for each
+ // protected member as well as all the protected namespaces from the first definition.
+ (function gather(cls) {
+ if (cls.baseClass) {
+ gather(cls.baseClass);
+ }
+ var ii = cls.classInfo.instanceInfo;
+ for (var i = 0; i < ii.traits.length; i++) {
+ var trait = ii.traits[i];
+ if (trait.isProtected()) {
+ var name = trait.name.getName();
+ if (!map[name]) {
+ map[name] = {definingNamespace: ii.protectedNs, namespaces: [], trait: trait};
}
+ map[name].definingNamespace = ii.protectedNs;
}
- for (var name in map) {
- map[name].namespaces.push(ii.protectedNs);
- }
- })(cls);
-
- var openMethods = instance.prototype[VM_OPEN_METHODS];
- var vmBindings = instance.prototype[VM_BINDINGS];
+ }
for (var name in map) {
- var definingNamespace = map[name].definingNamespace;
- var protectedQn = Multiname.getQualifiedName(new Multiname([definingNamespace], name));
- var namespaces = map[name].namespaces;
- var trait = map[name].trait;
- for (var i = 0; i < namespaces.length; i++) {
- var qn = Multiname.getQualifiedName(new Multiname([namespaces[i]], name));
- if (qn !== protectedQn) {
- Counter.count("Protected Aliases");
- defineNonEnumerableGetter(instance.prototype, qn, makeForwardingGetter(protectedQn));
- defineNonEnumerableSetter(instance.prototype, qn, makeForwardingSetter(protectedQn));
- vmBindings.push(qn);
- if (trait.isMethod()) {
- openMethods[qn] = openMethods[protectedQn];
- }
+ map[name].namespaces.push(ii.protectedNs);
+ }
+ })(cls);
+
+ var openMethods = obj[VM_OPEN_METHODS];
+ var vmBindings = obj[VM_BINDINGS];
+ for (var name in map) {
+ var definingNamespace = map[name].definingNamespace;
+ var protectedQn = Multiname.getQualifiedName(new Multiname([definingNamespace], name));
+ var namespaces = map[name].namespaces;
+ var trait = map[name].trait;
+ for (var i = 0; i < namespaces.length; i++) {
+ var qn = Multiname.getQualifiedName(new Multiname([namespaces[i]], name));
+ if (qn !== protectedQn) {
+ Counter.count("Protected Aliases");
+ defineNonEnumerableGetter(obj, qn, makeForwardingGetter(protectedQn));
+ defineNonEnumerableSetter(obj, qn, makeForwardingSetter(protectedQn));
+ vmBindings.push(qn);
+ if (trait.isMethod()) {
+ openMethods[qn] = openMethods[protectedQn];
}
}
}
}
+ };
- if (instance) {
- applyProtectedTraits(cls);
- }
+ runtime.prototype.applyInterfaceBindings = function applyInterfaceBindings(obj, cls) {
+ var domain = this.domain;
cls.implementedInterfaces = [];
@@ -1296,7 +1333,6 @@ var Runtime = (function () {
cls.implementedInterfaces.push(interface);
applyInterfaceTraits(ii.interfaces);
- var bindings = instance.prototype;
var interfaceTraits = ii.traits;
for (var k = 0, l = interfaceTraits.length; k < l; k++) {
var interfaceTrait = interfaceTraits[k];
@@ -1313,47 +1349,15 @@ var Runtime = (function () {
}
}(interfaceTraitBindingQn);
Counter.count("Interface Aliases");
- defineNonEnumerableGetter(bindings, interfaceTraitQn, getter);
+ defineNonEnumerableGetter(obj, interfaceTraitQn, getter);
}
}
}
// Apply traits of all interfaces along the inheritance chain.
- var tmp = cls;
- while (tmp) {
- applyInterfaceTraits(tmp.classInfo.instanceInfo.interfaces);
- tmp = tmp.baseClass;
- }
-
- // Run the static initializer.
- this.createFunction(classInfo.init, scope).call(cls);
-
- // Seal constant traits in the class object.
- compatibility && this.sealConstantTraits(cls, ci.traits);
-
- // TODO: Seal constant traits in the instance object. This should be done after
- // the instance constructor has executed.
-
- if (traceClasses.value) {
- domain.loadedClasses.push(cls);
- domain.traceLoadedClasses();
- }
-
- return cls;
- };
-
- runtime.prototype.createInterface = function createInterface(classInfo) {
- var ii = classInfo.instanceInfo;
- release || assert(ii.isInterface());
- if (traceExecution.value) {
- var str = "Creating interface " + ii.name;
- if (ii.interfaces.length) {
- str += " implements " + ii.interfaces.map(function (name) {
- return name.getName();
- }).join(", ");
- }
- print(str);
+ while (cls) {
+ applyInterfaceTraits(cls.classInfo.instanceInfo.interfaces);
+ cls = cls.baseClass;
}
- return new Interface(classInfo);
};
/**
@@ -1,3 +0,0 @@
-trace(Math.pow.length);
-trace(Math.pow(4, 2));
-trace(Math.pow.length);
@@ -0,0 +1,16 @@
+package {
+ public class A {
+ function A() {
+ trace("Construct A");
+ }
+ }
+
+ var a = new A();
+ trace("-- SHOULD NOT CONSTRUCT AGAIN --");
+ A(a);
+ A(a);
+ A(a);
+ A(a);
+ A(a);
+ trace("-- DONE --");
+}
@@ -0,0 +1,34 @@
+function quickSort(arrayInput, left, right) {
+ var i = left;
+ var j = right;
+ var pivotPoint = arrayInput[Math.round((left+right)*.5)];
+ while (i<=j) {
+ while (arrayInput[i]<pivotPoint) {
+ i++;
+ }
+ while (arrayInput[j]>pivotPoint) {
+ j--;
+ }
+ if (i<=j) {
+ var tempStore = arrayInput[i];
+ arrayInput[i] = arrayInput[j];
+ i++;
+ arrayInput[j] = tempStore;
+ j--;
+ }
+ }
+ if (left<j) {
+ quickSort(arrayInput, left, j);
+ }
+ if (i<right) {
+ quickSort(arrayInput, i, right);
+ }
+ return;
+}
+
+var a = [];
+for (var i = 0; i < 100; i++) {
+ a.push(100 - i);
+}
+quickSort(a, 0, a.length - 1);
+trace(a);
@@ -0,0 +1,4 @@
+// TODO: Method lengths should be correct, even before methods are first called.
+// trace(Math.pow.length);
+trace(Math.pow(4, 2));
+trace(Math.pow.length);
@@ -0,0 +1,39 @@
+package {
+
+ interface IA
+ {
+ function foo() : void;
+ }
+
+ interface IB
+ {
+ function bar() : void;
+ }
+
+ class A implements IA
+ {
+ public function foo() : void
+ {
+ trace('bar');
+ }
+ }
+
+ class B extends A implements IB
+ {
+ public override function foo() : void
+ {
+ trace('bar');
+ }
+
+ public function bar() : void
+ {
+ trace('bar');
+ }
+ }
+
+ var ia : IA = new B();
+
+ ia.foo();
+
+ trace("-- DONE --");
+}
@@ -1,7 +1,10 @@
package {
class A {
static function foo() {
- return new A();
+ return new A().toString();
+ }
+ function toString() {
+ return "HELLO";
}
}
var f = A.foo;
@@ -0,0 +1,7 @@
+package {
+ function foo() {
+ var o = {"A": (1 || 2), "B" : 3};
+ trace(o.A);
+ }
+ foo();
+}
Oops, something went wrong.

0 comments on commit 4c1e5bb

Please sign in to comment.