MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / constructor

Method constructor

src/lualib/WeakSet.ts:7–27  ·  view source on GitHub ↗
(values?: Iterable<T> | T[])

Source from the content-addressed store, hash-verified

5 private items = new LuaTable<T, boolean>();
6
7 constructor(values?: Iterable<T> | T[]) {
8 setmetatable(this.items, { __mode: "k" });
9 if (values === undefined) return;
10
11 const iterable = values as Iterable<T>;
12 if (iterable[Symbol.iterator]) {
13 // Iterate manually because WeakSet is compiled with ES5 which doesn't support Iterables in for...of
14 const iterator = iterable[Symbol.iterator]();
15 while (true) {
16 const result = iterator.next();
17 if (result.done) {
18 break;
19 }
20 this.items.set(result.value, true);
21 }
22 } else {
23 for (const value of values as T[]) {
24 this.items.set(value, true);
25 }
26 }
27 }
28
29 public add(value: T): this {
30 this.items.set(value, true);

Callers

nothing calls this directly

Calls 2

nextMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected