The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. The keys must be objects and the values can be arbitrary values.
Inheritance: ObjectInstance
Esempio n. 1
0
        public WeakMapInstance Construct(object iterable)
        {
            // Create a new set.
            var result = new WeakMapInstance(this.InstancePrototype);

            // If iterable is not null or undefined, then iterate through the values and add them to the set.
            if (iterable != Undefined.Value && iterable != Null.Value)
            {
                var iterator = TypeUtilities.GetIterator(Engine, TypeConverter.ToObject(Engine, iterable));
                if (iterator != null)
                {
                    // Get a reference to the set function.
                    var setFunc = result["set"] as FunctionInstance;
                    if (setFunc == null)
                    {
                        throw new JavaScriptException(Engine, ErrorType.TypeError, "Missing 'set' function");
                    }

                    // Call the set function for each value.
                    foreach (var value in TypeUtilities.Iterate(Engine, iterator))
                    {
                        var obj = value as ObjectInstance;
                        if (obj == null)
                        {
                            throw new JavaScriptException(Engine, ErrorType.TypeError, $"Expected iterator return value to be an object, but was {value}");
                        }
                        setFunc.Call(result, obj[0], obj[1]);
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        public WeakMapInstance Construct(object iterable)
        {
            // Create a new set.
            var result = new WeakMapInstance(this.InstancePrototype);

            // If iterable is not null or undefined, then iterate through the values and add them to the set.
            if (iterable != Undefined.Value && iterable != Null.Value)
            {
                var iterator = TypeUtilities.GetIterator(Engine, TypeConverter.ToObject(Engine, iterable));
                if (iterator != null)
                {
                    // Get a reference to the set function.
                    var setFunc = result["set"] as FunctionInstance;
                    if (setFunc == null)
                        throw new JavaScriptException(Engine, ErrorType.TypeError, "Missing 'set' function");

                    // Call the set function for each value.
                    foreach (var value in TypeUtilities.Iterate(Engine, iterator))
                    {
                        var obj = value as ObjectInstance;
                        if (obj == null)
                            throw new JavaScriptException(Engine, ErrorType.TypeError, $"Expected iterator return value to be an object, but was {value}");
                        setFunc.Call(result, obj[0], obj[1]);
                    }
                }
            }

            return result;
        }
Esempio n. 3
0
        //     INITIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Creates a new map constructor.
        /// </summary>
        /// <param name="prototype"> The next object in the prototype chain. </param>
        internal WeakMapConstructor(ObjectInstance prototype)
            : base(prototype, __STUB__Construct, __STUB__Call)
        {
            // Initialize the constructor properties.
            var properties = new List <PropertyNameAndValue>();

            InitializeConstructorProperties(properties, "WeakMap", 0, WeakMapInstance.CreatePrototype(Engine, this));
            FastSetProperties(properties);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="weakMapInstance">The displayed WeakMapInstance</param>
 public WeakMapInstanceDebugView(WeakMapInstance weakMapInstance)
 {
     this.weakMapInstance = weakMapInstance;
 }