tor-browser

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

iter-map-fn-this-strict-strict.js (1558B)


      1 'use strict';
      2 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-array.from
      6 description: >
      7    `this` value of mapping function in strict mode (traversed via iterator)
      8 info: |
      9    [...]
     10    2. If mapfn is undefined, let mapping be false.
     11    3. else
     12       a. If IsCallable(mapfn) is false, throw a TypeError exception.
     13       b. If thisArg was supplied, let T be thisArg; else let T be undefined.
     14       c. Let mapping be true
     15    [...]
     16    6. If usingIterator is not undefined, then
     17       [...]
     18       g. Repeat
     19          [...]
     20          vii. If mapping is true, then
     21               1. Let mappedValue be Call(mapfn, T, «nextValue, k»).
     22 features: [Symbol.iterator]
     23 flags: [onlyStrict]
     24 ---*/
     25 
     26 var thisVals = [];
     27 var nextResult = {
     28  done: false,
     29  value: {}
     30 };
     31 var nextNextResult = {
     32  done: false,
     33  value: {}
     34 };
     35 var mapFn = function() {
     36  thisVals.push(this);
     37 };
     38 var items = {};
     39 
     40 items[Symbol.iterator] = function() {
     41  return {
     42    next: function() {
     43      var result = nextResult;
     44      nextResult = nextNextResult;
     45      nextNextResult = {
     46        done: true
     47      };
     48 
     49      return result;
     50    }
     51  };
     52 };
     53 
     54 Array.from(items, mapFn);
     55 
     56 assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2');
     57 assert.sameValue(thisVals[0], undefined, 'The value of thisVals[0] is expected to equal undefined');
     58 assert.sameValue(thisVals[1], undefined, 'The value of thisVals[1] is expected to equal undefined');
     59 
     60 reportCompare(0, 0);