michael@0: function Person(){} michael@0: function Ninja(){} michael@0: Ninja.prototype = new Person(); michael@0: function House(){} michael@0: michael@0: var empty = {}; michael@0: var person = new Person(); michael@0: var ninja = new Ninja(); michael@0: var house = new House(); michael@0: var string = new String(); michael@0: var bindNinja = Ninja.bind({}); michael@0: michael@0: var array = {}; michael@0: array.__proto__ = Array.prototype; michael@0: var array2 = {}; michael@0: array2.__proto__ = array.prototype; michael@0: michael@0: function test(v, v2) { michael@0: return v instanceof v2; michael@0: } michael@0: function test2(v, v2) { michael@0: return v instanceof v2; michael@0: } michael@0: function test3(v, v2) { michael@0: return v instanceof v2; michael@0: } michael@0: function test4(v, v2) { michael@0: return v instanceof v2; michael@0: } michael@0: michael@0: // Test if specialized for object works michael@0: for (var i=0; i!=41; i++) { michael@0: assertEq(test(person, Person), true); michael@0: assertEq(test(empty, Person), false); michael@0: assertEq(test(ninja, Person), true); michael@0: assertEq(test(house, Person), false); michael@0: assertEq(test(string, Person), false); michael@0: assertEq(test(new bindNinja(), Person), true); michael@0: assertEq(test(new Ninja(), bindNinja), true); michael@0: assertEq(test(string, String), true); michael@0: assertEq(test(array, Array), true); michael@0: assertEq(test(empty, Object), true); michael@0: michael@0: // Test if bailout works michael@0: assertEq(test(0.1, Object), false); michael@0: michael@0: // Should generate TypeError michael@0: var err = false; michael@0: try { michael@0: test(0.1, 5); michael@0: } catch (e) { err = true; } michael@0: assertEq(err, true); michael@0: michael@0: // Should generate TypeError michael@0: var err = false; michael@0: try { michael@0: test(empty, empty); michael@0: } catch (e) { err = true; } michael@0: assertEq(err, true); michael@0: michael@0: // Should generate TypeError michael@0: var err = false; michael@0: try { michael@0: test(5.0, empty); michael@0: } catch (e) { err = true; } michael@0: assertEq(err, true); michael@0: } michael@0: michael@0: // Test if specialized for non-object lhs michael@0: for (var i=0; i!=41; i++) { michael@0: assertEq(test2(0.1, Object), false); michael@0: } michael@0: michael@0: // Check if we don't regress on https://bugzilla.mozilla.org/show_bug.cgi?id=7635 michael@0: function Foo() {}; michael@0: theproto = {}; michael@0: Foo.prototype = theproto; michael@0: michael@0: for (var i=0; i!=41; i++) { michael@0: assertEq(test3(theproto, Foo), false); michael@0: } michael@0: