tor-browser

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

S15.4.5.1_A1.3_T2.js (2392B)


      1 // Copyright 2009 the Sputnik authors.  All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-array-exotic-objects-defineownproperty-p-desc
      6 info: Set the value of property length of A to Uint32(length)
      7 es5id: 15.4.5.1_A1.3_T2
      8 description: Uint32 use ToNumber and ToPrimitve
      9 ---*/
     10 
     11 var x = [];
     12 x.length = {
     13  valueOf: function() {
     14    return 2
     15  }
     16 };
     17 assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2');
     18 
     19 x = [];
     20 x.length = {
     21  valueOf: function() {
     22    return 2
     23  },
     24  toString: function() {
     25    return 1
     26  }
     27 };
     28 assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2');
     29 
     30 x = [];
     31 x.length = {
     32  valueOf: function() {
     33    return 2
     34  },
     35  toString: function() {
     36    return {}
     37  }
     38 };
     39 assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2');
     40 
     41 try {
     42  x = [];
     43  x.length = {
     44    valueOf: function() {
     45      return 2
     46    },
     47    toString: function() {
     48      throw "error"
     49    }
     50  };
     51  assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2');
     52 }
     53 catch (e) {
     54  assert.notSameValue(e, "error", 'The value of e is not "error"');
     55 }
     56 
     57 x = [];
     58 x.length = {
     59  toString: function() {
     60    return 1
     61  }
     62 };
     63 assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1');
     64 
     65 x = [];
     66 x.length = {
     67  valueOf: function() {
     68    return {}
     69  },
     70  toString: function() {
     71    return 1
     72  }
     73 }
     74 assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1');
     75 
     76 try {
     77  x = [];
     78  x.length = {
     79    valueOf: function() {
     80      throw "error"
     81    },
     82    toString: function() {
     83      return 1
     84    }
     85  };
     86  x.length;
     87  throw new Test262Error('#7.1: x = []; x.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; x.length throw "error". Actual: ' + (x.length));
     88 }
     89 catch (e) {
     90  assert.sameValue(e, "error", 'The value of e is expected to be "error"');
     91 }
     92 
     93 try {
     94  x = [];
     95  x.length = {
     96    valueOf: function() {
     97      return {}
     98    },
     99    toString: function() {
    100      return {}
    101    }
    102  };
    103  x.length;
    104  throw new Test262Error('#8.1: x = []; x.length = {valueOf: function() {return {}}, toString: function() {return {}}}  x.length throw TypeError. Actual: ' + (x.length));
    105 }
    106 catch (e) {
    107  assert.sameValue(
    108    e instanceof TypeError,
    109    true,
    110    'The result of evaluating (e instanceof TypeError) is expected to be true'
    111  );
    112 }
    113 
    114 reportCompare(0, 0);