tor-browser

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

replacer-array-abrupt.js (1281B)


      1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-json.stringify
      5 description: >
      6  Abrupt completion from Get.
      7 info: |
      8  JSON.stringify ( value [ , replacer [ , space ] ] )
      9 
     10  [...]
     11  4. If Type(replacer) is Object, then
     12    [...]
     13    2. Let len be ? LengthOfArrayLike(replacer).
     14    3. Let k be 0.
     15    4. Repeat, while k < len,
     16      a. Let v be ? Get(replacer, ! ToString(k)).
     17 features: [Proxy]
     18 ---*/
     19 
     20 var abruptLength = new Proxy([], {
     21  get: function(_target, key) {
     22    if (key === 'length') {
     23      throw new Test262Error();
     24    }
     25  },
     26 });
     27 
     28 assert.throws(Test262Error, function() {
     29  JSON.stringify(null, abruptLength);
     30 });
     31 
     32 var abruptToPrimitive = {
     33  valueOf: function() {
     34    throw new Test262Error();
     35  },
     36 };
     37 
     38 var abruptToLength = new Proxy([], {
     39  get: function(_target, key) {
     40    if (key === 'length') {
     41      return abruptToPrimitive;
     42    }
     43  },
     44 });
     45 
     46 assert.throws(Test262Error, function() {
     47  JSON.stringify([], abruptToLength);
     48 });
     49 
     50 var abruptIndex = new Array(1);
     51 Object.defineProperty(abruptIndex, '0', {
     52  get: function() {
     53    throw new Test262Error();
     54  },
     55 });
     56 
     57 assert.throws(Test262Error, function() {
     58  JSON.stringify({}, abruptIndex);
     59 });
     60 
     61 reportCompare(0, 0);