All files / near-membrane-shared/src Map.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 1/1
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48        14x   14x                       14x   14x   14x     14x 14x 14x 14x 14x 14x 14x 14x 14x 14x             14x 14x 14x 14x 14x    
import { ObjectLookupOwnGetter } from './Object';
import { ReflectDefineProperty, ReflectSetPrototypeOf } from './Reflect';
import { SymbolIterator, SymbolToStringTag } from './Symbol';
 
export const MapCtor = Map;
 
const { prototype: MapProto } = MapCtor;
 
const {
    clear: MapProtoClear,
    delete: MapProtoDelete,
    forEach: MapProtoForEach,
    get: MapProtoGet,
    has: MapProtoHas,
    keys: MapProtoKeys,
    values: MapProtoValues,
    [SymbolIterator]: MapProtoSymbolIterator,
    [SymbolToStringTag]: MapProtoSymbolToStringTag,
} = MapProto as any;
 
export const { entries: MapProtoEntries, set: MapProtoSet } = MapProto;
 
export const MapProtoSizeGetter = ObjectLookupOwnGetter(MapProto, 'size')!;
 
export function toSafeMap<T extends Map<any, any>>(map: T): T {
    ReflectSetPrototypeOf(map, null);
    map.clear = MapProtoClear;
    map.delete = MapProtoDelete;
    map.entries = MapProtoEntries;
    map.forEach = MapProtoForEach;
    map.get = MapProtoGet;
    map.has = MapProtoHas;
    map.keys = MapProtoKeys;
    map.set = MapProtoSet as any;
    ReflectDefineProperty(map, 'size', {
        __proto__: null,
        configurable: true,
        enumerable: true,
        get: MapProtoSizeGetter,
        set: undefined,
    } as PropertyDescriptor);
    map.values = MapProtoValues;
    (map as any)[SymbolIterator] = MapProtoSymbolIterator;
    (map as any)[SymbolToStringTag] = MapProtoSymbolToStringTag;
    ReflectSetPrototypeOf(map, MapProto);
    return map;
}