text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * Copyright (c) 2017-present, Facebook, Inc.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * All rights reserved.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * This source code is licensed under the BSD-style license found in the
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * LICENSE file in the root directory of this source tree. An additional grant
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * of patent rights can be found in the PATENTS file in the same directory.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            */
  
  exports.default = function (realm) {
    // ECMA262 23.2.1.1
    var func = new _index.NativeFunctionValue(realm, "Set", "Set", 0, function (context, _ref, argCount, NewTarget) {
      var _ref2 = _slicedToArray(_ref, 1),
          iterable = _ref2[0];
  
      // 1. If NewTarget is undefined, throw a TypeError exception.
      if (!NewTarget) {
        throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
      }
  
      // 2. Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", « [[SetData]] »).
      var set = (0, _index2.OrdinaryCreateFromConstructor)(realm, NewTarget, "SetPrototype", {
        $SetData: undefined
      });
  
      // 3. Set set's [[SetData]] internal slot to a new empty List.
      set.$SetData = [];
  
      // 4. If iterable is not present, let iterable be undefined.
      if (!iterable) iterable = realm.intrinsics.undefined;
  
      // 5. If iterable is either undefined or null, let iter be undefined.
      var iter = void 0,
          adder = void 0;
      if ((0, _index2.HasSomeCompatibleType)(realm, iterable, _index.UndefinedValue, _index.NullValue)) {
        adder = realm.intrinsics.undefined;
        iter = realm.intrinsics.undefined;
      } else {
        // 6. Else,
        // a. Let adder be ? Get(set, "add").
        adder = (0, _index2.Get)(realm, set, "add");
  
        // b. If IsCallable(adder) is false, throw a TypeError exception.
        if (!(0, _index2.IsCallable)(realm, adder)) {
          throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
        }
  
        // c. Let iter be ? GetIterator(iterable).
        iter = (0, _index2.GetIterator)(realm, iterable);
      }
  
      // 7. If iter is undefined, return set.
      if (iter instanceof _index.UndefinedValue) {
        return set;
      }
  
      // 8. Repeat
      while (true) {
        // a. Let next be ? IteratorStep(iter).
        var next = (0, _index2.IteratorStep)(realm, iter);
  
        // b. If next is false, return set.
        if (!next) return set;
  
        // c. Let nextValue be ? IteratorValue(next).
        var nextValue = (0, _index2.IteratorValue)(realm, next);
  
        // d. Let status be Call(adder, set, « nextValue.[[Value]] »).
        try {
          (0, _index2.Call)(realm, adder, set, [nextValue]);
        } catch (status) {
          if (status instanceof _completions.AbruptCompletion) {
            // e. If status is an abrupt completion, return ? IteratorClose(iter, status).
            throw (0, _index2.IteratorClose)(realm, iter, status);
          } else throw status;
        }
      }
  
      (0, _invariant2.default)(false);
    });
  
    // ECMA262 23.2.2.2
    func.defineNativeGetter(realm.intrinsics.SymbolSpecies, function (context) {
      // 1. Return the this value
      return context;
    });
  
    return func;
  };
  
  var _index = require("../../values/index.js");
  
  var _completions = require("../../completions.js");
  
  var _index2 = require("../../methods/index.js");
  
  var _invariant = require("../../invariant.js");
  
  var _invariant2 = _interopRequireDefault(_invariant);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  //# sourceMappingURL=Set.js.map