403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/src/lib/collections/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/src/lib/collections/weak-ref-map.js
import Type from '../type';

// eslint-disable-next-line @bitrix24/bitrix24-rules/no-typeof
const IS_WEAK_REF_SUPPORTED = typeof WeakRef !== 'undefined';

export default class WeakRefMap<K, V>
{
	#refs: Map<K, WeakRef> = new Map();
	#registry: FinalizationRegistry = null;

	constructor()
	{
		if (IS_WEAK_REF_SUPPORTED)
		{
			this.#registry = new FinalizationRegistry(this.#cleanupCallback.bind(this));
		}
	}

	clear(): void
	{
		if (!IS_WEAK_REF_SUPPORTED)
		{
			this.#refs.clear();

			return;
		}

		this.#refs.forEach((ref: WeakRef, key: K) => {
			const value = ref?.deref();
			if (!Type.isUndefined(value))
			{
				this.#registry.unregister(value);
			}
		});

		this.#refs.clear();
	}

	delete(key: K): boolean
	{
		if (!IS_WEAK_REF_SUPPORTED)
		{
			return this.#refs.delete(key);
		}

		const value = this.get(key);
		if (!Type.isUndefined(value))
		{
			this.#registry.unregister(value);
		}

		return this.#refs.delete(key);
	}

	get(key: K): V | undefined
	{
		if (!IS_WEAK_REF_SUPPORTED)
		{
			return this.#refs.get(key);
		}

		return this.#refs.get(key)?.deref();
	}

	has(key: K): boolean
	{
		if (!IS_WEAK_REF_SUPPORTED)
		{
			return this.#refs.has(key);
		}

		return !Type.isUndefined(this.#refs.get(key)?.deref());
	}

	set(key: K, value: V): this
	{
		if (!IS_WEAK_REF_SUPPORTED)
		{
			this.#refs.set(key, value);

			return this;
		}

		this.#refs.set(key, new WeakRef(value));
		this.#registry.register(value, key, value);

		return this;
	}

	#cleanupCallback(key: K): void
	{
		const ref = this.#refs.get(key);
		if (ref && !ref.deref())
		{
			this.#refs.delete(key);
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit