tor-browser

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

iter-cstm-ctor.js (1327B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-array.from
      5 description: Creating object with custom constructor (traversed via iterator)
      6 info: |
      7    [...]
      8    6. If usingIterator is not undefined, then
      9       a. If IsConstructor(C) is true, then
     10          i. Let A be Construct(C).
     11       b. Else,
     12          i. Let A be ArrayCreate(0).
     13       c. ReturnIfAbrupt(A).
     14 features: [Symbol.iterator]
     15 ---*/
     16 
     17 var thisVal, args;
     18 var callCount = 0;
     19 var C = function() {
     20  thisVal = this;
     21  args = arguments;
     22  callCount += 1;
     23 };
     24 var result;
     25 var items = {};
     26 items[Symbol.iterator] = function() {
     27  return {
     28    next: function() {
     29      return {
     30        done: true
     31      };
     32    }
     33  };
     34 };
     35 
     36 result = Array.from.call(C, items);
     37 
     38 assert(
     39  result instanceof C, 'The result of evaluating (result instanceof C) is expected to be true'
     40 );
     41 assert.sameValue(
     42  result.constructor,
     43  C,
     44  'The value of result.constructor is expected to equal the value of C'
     45 );
     46 assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1');
     47 assert.sameValue(thisVal, result, 'The value of thisVal is expected to equal the value of result');
     48 assert.sameValue(args.length, 0, 'The value of args.length is expected to be 0');
     49 
     50 reportCompare(0, 0);