Example #1
0
        public SetInstance Construct(object iterable)
        {
            // Create a new set.
            var result = new SetInstance(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 add function.
                    var addFunc = result["add"] as FunctionInstance;
                    if (addFunc == null)
                        throw new JavaScriptException(Engine, ErrorType.TypeError, "Missing 'add' function.");

                    // Call the add function for each value.
                    foreach (var value in TypeUtilities.Iterate(Engine, iterator))
                    {
                        addFunc.Call(result, value);
                    }
                }
            }

            return result;
        }
Example #2
0
 //     INITIALIZATION
 //_________________________________________________________________________________________
 /// <summary>
 /// Creates a new set iterator.
 /// </summary>
 /// <param name="prototype"> The next object in the prototype chain. </param>
 /// <param name="set"> The set to iterate over. </param>
 /// <param name="list"> The linked list to iterate over. </param>
 /// <param name="kind"> The type of values to return. </param>
 internal SetIterator(ObjectInstance prototype, SetInstance set, LinkedList<object> list, Kind kind)
     : base(prototype)
 {
     this.set = set;
     this.set.BeforeDelete += Set_BeforeDelete;
     this.list = list;
     this.kind = kind;
 }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="setInstance">The displayed SetInstance</param>
 internal SetInstanceDebugView(SetInstance setInstance)
 {
     this.setInstance = setInstance;
 }