tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug717466.js (1843B)


      1 function Person(){}
      2 function Ninja(){}
      3 Ninja.prototype = new Person();
      4 function House(){}
      5 
      6 var empty = {};
      7 var person = new Person();
      8 var ninja = new Ninja();
      9 var house = new House();
     10 var string = new String();
     11 var bindNinja = Ninja.bind({});
     12 
     13 var array = {};
     14 array.__proto__ = Array.prototype;
     15 var array2 = {};
     16 array2.__proto__ = array.prototype;
     17 
     18 function test(v, v2) {
     19  return v instanceof v2;
     20 }
     21 function test2(v, v2) {
     22  return v instanceof v2;
     23 }
     24 function test3(v, v2) {
     25  return v instanceof v2;
     26 }
     27 function test4(v, v2) {
     28  return v instanceof v2;
     29 }
     30 
     31 // Test if specialized for object works
     32 for (var i=0; i!=41; i++) {
     33  assertEq(test(person, Person), true);
     34  assertEq(test(empty, Person), false);
     35  assertEq(test(ninja, Person), true);
     36  assertEq(test(house, Person), false);
     37  assertEq(test(string, Person), false);
     38  assertEq(test(new bindNinja(), Person), true);
     39  assertEq(test(new Ninja(), bindNinja), true);
     40  assertEq(test(string, String), true);
     41  assertEq(test(array, Array), true);
     42  assertEq(test(empty, Object), true);
     43  
     44  // Test if bailout works
     45  assertEq(test(0.1, Object), false);
     46  
     47  // Should generate TypeError
     48  var err = false;
     49  try {
     50    test(0.1, 5);
     51  } catch (e) { err = true; }
     52  assertEq(err, true);
     53  
     54  // Should generate TypeError
     55  var err = false;
     56  try {
     57    test(empty, empty);
     58  } catch (e) { err = true; }
     59  assertEq(err, true);
     60  
     61  // Should generate TypeError
     62  var err = false;
     63  try {
     64    test(5.0, empty);
     65  } catch (e) { err = true; }
     66  assertEq(err, true);
     67 }
     68 
     69 // Test if specialized for non-object lhs
     70 for (var i=0; i!=41; i++) {
     71  assertEq(test2(0.1, Object), false);
     72 }
     73 
     74 // Check if we don't regress on https://bugzilla.mozilla.org/show_bug.cgi?id=7635
     75 function Foo() {};
     76 theproto = {};
     77 Foo.prototype = theproto;
     78 
     79 for (var i=0; i!=41; i++) {
     80  assertEq(test3(theproto, Foo), false);
     81 }