Permalink
Browse files

Fix isInstance for Class instances.

  • Loading branch information...
1 parent f340055 commit 76e18d73ee665e39706cf3f5137156afd565d3ab @mbebenita mbebenita committed Apr 9, 2013
Showing with 21 additions and 1 deletion.
  1. +4 −0 src/avm2/domain.js
  2. +1 −1 src/avm2/native.js
  3. +16 −0 src/avm2/tests/regress/correctness/pass/type-3.as
View
4 src/avm2/domain.js
@@ -276,6 +276,10 @@ var Domain = (function () {
}
};
+ var callable = Domain.coerceCallable(Class);
+ defineNonEnumerableProperty(Class, "call", callable.call);
+ defineNonEnumerableProperty(Class, "apply", callable.apply);
+
Class.instance = Class;
Class.toString = Class.prototype.toString;
View
2 src/avm2/native.js
@@ -301,7 +301,7 @@ var natives = (function () {
return true; // TODO: Fix me.
};
c.isInstance = function (value) {
- return true; // TODO: Fix me.
+ return value instanceof c.instance;
};
return c;
}
View
16 src/avm2/tests/regress/correctness/pass/type-3.as
@@ -0,0 +1,16 @@
+package {
+ class A { }
+ class B extends A { }
+ class C { }
+
+ trace("\"ABC\" is String - " + ("ABC" is String));
+ trace("A is Class - " + (A is Class));
+ trace("123 is Class - " + (123 is Class));
+ trace("new A() is Class - " + (new A() is Class));
+ trace("A === Class(A) - " + (A === Class(A)));
+ trace("B === Class(A) - " + (B === Class(A)));
+ trace("new A() is A - " + (new A() is A));
+ trace("new B() is A - " + (new B() is A));
+ trace("new C() is A - " + (new C() is A));
+ trace("-- DONE --");
+}

0 comments on commit 76e18d7

Please sign in to comment.