Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

collection-strong.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. 'use strict';
  2. var defineProperty = require('../internals/object-define-property').f;
  3. var create = require('../internals/object-create');
  4. var redefineAll = require('../internals/redefine-all');
  5. var bind = require('../internals/function-bind-context');
  6. var anInstance = require('../internals/an-instance');
  7. var iterate = require('../internals/iterate');
  8. var defineIterator = require('../internals/define-iterator');
  9. var setSpecies = require('../internals/set-species');
  10. var DESCRIPTORS = require('../internals/descriptors');
  11. var fastKey = require('../internals/internal-metadata').fastKey;
  12. var InternalStateModule = require('../internals/internal-state');
  13. var setInternalState = InternalStateModule.set;
  14. var internalStateGetterFor = InternalStateModule.getterFor;
  15. module.exports = {
  16. getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) {
  17. var C = wrapper(function (that, iterable) {
  18. anInstance(that, C, CONSTRUCTOR_NAME);
  19. setInternalState(that, {
  20. type: CONSTRUCTOR_NAME,
  21. index: create(null),
  22. first: undefined,
  23. last: undefined,
  24. size: 0
  25. });
  26. if (!DESCRIPTORS) that.size = 0;
  27. if (iterable != undefined) iterate(iterable, that[ADDER], { that: that, AS_ENTRIES: IS_MAP });
  28. });
  29. var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
  30. var define = function (that, key, value) {
  31. var state = getInternalState(that);
  32. var entry = getEntry(that, key);
  33. var previous, index;
  34. // change existing entry
  35. if (entry) {
  36. entry.value = value;
  37. // create new entry
  38. } else {
  39. state.last = entry = {
  40. index: index = fastKey(key, true),
  41. key: key,
  42. value: value,
  43. previous: previous = state.last,
  44. next: undefined,
  45. removed: false
  46. };
  47. if (!state.first) state.first = entry;
  48. if (previous) previous.next = entry;
  49. if (DESCRIPTORS) state.size++;
  50. else that.size++;
  51. // add to index
  52. if (index !== 'F') state.index[index] = entry;
  53. } return that;
  54. };
  55. var getEntry = function (that, key) {
  56. var state = getInternalState(that);
  57. // fast case
  58. var index = fastKey(key);
  59. var entry;
  60. if (index !== 'F') return state.index[index];
  61. // frozen object case
  62. for (entry = state.first; entry; entry = entry.next) {
  63. if (entry.key == key) return entry;
  64. }
  65. };
  66. redefineAll(C.prototype, {
  67. // `{ Map, Set }.prototype.clear()` methods
  68. // https://tc39.es/ecma262/#sec-map.prototype.clear
  69. // https://tc39.es/ecma262/#sec-set.prototype.clear
  70. clear: function clear() {
  71. var that = this;
  72. var state = getInternalState(that);
  73. var data = state.index;
  74. var entry = state.first;
  75. while (entry) {
  76. entry.removed = true;
  77. if (entry.previous) entry.previous = entry.previous.next = undefined;
  78. delete data[entry.index];
  79. entry = entry.next;
  80. }
  81. state.first = state.last = undefined;
  82. if (DESCRIPTORS) state.size = 0;
  83. else that.size = 0;
  84. },
  85. // `{ Map, Set }.prototype.delete(key)` methods
  86. // https://tc39.es/ecma262/#sec-map.prototype.delete
  87. // https://tc39.es/ecma262/#sec-set.prototype.delete
  88. 'delete': function (key) {
  89. var that = this;
  90. var state = getInternalState(that);
  91. var entry = getEntry(that, key);
  92. if (entry) {
  93. var next = entry.next;
  94. var prev = entry.previous;
  95. delete state.index[entry.index];
  96. entry.removed = true;
  97. if (prev) prev.next = next;
  98. if (next) next.previous = prev;
  99. if (state.first == entry) state.first = next;
  100. if (state.last == entry) state.last = prev;
  101. if (DESCRIPTORS) state.size--;
  102. else that.size--;
  103. } return !!entry;
  104. },
  105. // `{ Map, Set }.prototype.forEach(callbackfn, thisArg = undefined)` methods
  106. // https://tc39.es/ecma262/#sec-map.prototype.foreach
  107. // https://tc39.es/ecma262/#sec-set.prototype.foreach
  108. forEach: function forEach(callbackfn /* , that = undefined */) {
  109. var state = getInternalState(this);
  110. var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3);
  111. var entry;
  112. while (entry = entry ? entry.next : state.first) {
  113. boundFunction(entry.value, entry.key, this);
  114. // revert to the last existing entry
  115. while (entry && entry.removed) entry = entry.previous;
  116. }
  117. },
  118. // `{ Map, Set}.prototype.has(key)` methods
  119. // https://tc39.es/ecma262/#sec-map.prototype.has
  120. // https://tc39.es/ecma262/#sec-set.prototype.has
  121. has: function has(key) {
  122. return !!getEntry(this, key);
  123. }
  124. });
  125. redefineAll(C.prototype, IS_MAP ? {
  126. // `Map.prototype.get(key)` method
  127. // https://tc39.es/ecma262/#sec-map.prototype.get
  128. get: function get(key) {
  129. var entry = getEntry(this, key);
  130. return entry && entry.value;
  131. },
  132. // `Map.prototype.set(key, value)` method
  133. // https://tc39.es/ecma262/#sec-map.prototype.set
  134. set: function set(key, value) {
  135. return define(this, key === 0 ? 0 : key, value);
  136. }
  137. } : {
  138. // `Set.prototype.add(value)` method
  139. // https://tc39.es/ecma262/#sec-set.prototype.add
  140. add: function add(value) {
  141. return define(this, value = value === 0 ? 0 : value, value);
  142. }
  143. });
  144. if (DESCRIPTORS) defineProperty(C.prototype, 'size', {
  145. get: function () {
  146. return getInternalState(this).size;
  147. }
  148. });
  149. return C;
  150. },
  151. setStrong: function (C, CONSTRUCTOR_NAME, IS_MAP) {
  152. var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator';
  153. var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME);
  154. var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME);
  155. // `{ Map, Set }.prototype.{ keys, values, entries, @@iterator }()` methods
  156. // https://tc39.es/ecma262/#sec-map.prototype.entries
  157. // https://tc39.es/ecma262/#sec-map.prototype.keys
  158. // https://tc39.es/ecma262/#sec-map.prototype.values
  159. // https://tc39.es/ecma262/#sec-map.prototype-@@iterator
  160. // https://tc39.es/ecma262/#sec-set.prototype.entries
  161. // https://tc39.es/ecma262/#sec-set.prototype.keys
  162. // https://tc39.es/ecma262/#sec-set.prototype.values
  163. // https://tc39.es/ecma262/#sec-set.prototype-@@iterator
  164. defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) {
  165. setInternalState(this, {
  166. type: ITERATOR_NAME,
  167. target: iterated,
  168. state: getInternalCollectionState(iterated),
  169. kind: kind,
  170. last: undefined
  171. });
  172. }, function () {
  173. var state = getInternalIteratorState(this);
  174. var kind = state.kind;
  175. var entry = state.last;
  176. // revert to the last existing entry
  177. while (entry && entry.removed) entry = entry.previous;
  178. // get next entry
  179. if (!state.target || !(state.last = entry = entry ? entry.next : state.state.first)) {
  180. // or finish the iteration
  181. state.target = undefined;
  182. return { value: undefined, done: true };
  183. }
  184. // return step by kind
  185. if (kind == 'keys') return { value: entry.key, done: false };
  186. if (kind == 'values') return { value: entry.value, done: false };
  187. return { value: [entry.key, entry.value], done: false };
  188. }, IS_MAP ? 'entries' : 'values', !IS_MAP, true);
  189. // `{ Map, Set }.prototype[@@species]` accessors
  190. // https://tc39.es/ecma262/#sec-get-map-@@species
  191. // https://tc39.es/ecma262/#sec-get-set-@@species
  192. setSpecies(CONSTRUCTOR_NAME);
  193. }
  194. };