Esempio n. 1
0
 protected override PromiseState GetState(out EcmaValue value)
 {
     if (this.Count == 0 || this.All(v => v.State != PromiseState.Pending))
     {
         RuntimeObject    objectProto = RuntimeRealm.Current.GetRuntimeObject(WellKnownObject.ObjectPrototype);
         List <EcmaValue> values      = new List <EcmaValue>();
         foreach (PromiseAggregateHandler handler in this)
         {
             RuntimeObject obj = RuntimeObject.Create(objectProto);
             if (handler.State == PromiseState.Fulfilled)
             {
                 obj.CreateDataPropertyOrThrow(WellKnownProperty.Status, "fulfilled");
                 obj.CreateDataPropertyOrThrow(WellKnownProperty.Value, handler.Value);
             }
             else
             {
                 obj.CreateDataPropertyOrThrow(WellKnownProperty.Status, "rejected");
                 obj.CreateDataPropertyOrThrow(WellKnownProperty.Reason, handler.Value);
             }
             values.Add(obj);
         }
         value = new EcmaArray(values);
         return(PromiseState.Fulfilled);
     }
     return(base.GetState(out value));
 }
Esempio n. 2
0
        public static DateTimeFormatOptions CreateOptions(EcmaValue options, bool requiredDate, bool requiredTime, bool defaultsDate, bool defaultsTime)
        {
            RuntimeObject obj          = RuntimeObject.Create(options == default ? null : options.ToObject());
            bool          needDefaults = true;

            if (requiredDate)
            {
                needDefaults &= obj["weekday"] == default;
                needDefaults &= obj["year"] == default;
                needDefaults &= obj["month"] == default;
                needDefaults &= obj["day"] == default;
            }
            if (requiredTime)
            {
                needDefaults &= obj["hour"] == default;
                needDefaults &= obj["minute"] == default;
                needDefaults &= obj["second"] == default;
            }
            if (needDefaults)
            {
                if (defaultsDate)
                {
                    obj.CreateDataPropertyOrThrow("year", "numeric");
                    obj.CreateDataPropertyOrThrow("month", "numeric");
                    obj.CreateDataPropertyOrThrow("day", "numeric");
                }
                if (defaultsTime)
                {
                    obj.CreateDataPropertyOrThrow("hour", "numeric");
                    obj.CreateDataPropertyOrThrow("minute", "numeric");
                    obj.CreateDataPropertyOrThrow("second", "numeric");
                }
            }
            return(new DateTimeFormatOptions(obj));
        }
Esempio n. 3
0
        public static EcmaValue Of([This] EcmaValue thisValue, params EcmaValue[] elements)
        {
            if (!thisValue.IsCallable || !thisValue.ToObject().IsConstructor)
            {
                return(new EcmaArray(elements));
            }
            RuntimeObject arr = thisValue.Construct(elements.Length).ToObject();

            for (long i = 0, len = elements.Length; i < len; i++)
            {
                arr.CreateDataPropertyOrThrow(i, elements[i]);
            }
            arr.SetOrThrow(WellKnownProperty.Length, elements.Length);
            return(arr);
        }
Esempio n. 4
0
 public EcmaArray ToPartArray(EcmaPropertyKey annotationProperty, string[] annotations)
 {
     Guard.ArgumentNotNull(annotations, "annotations");
     if (annotations.Length != parts.Length)
     {
         throw new ArgumentException("Supplied array must have the same length of part array", "unitAnnotations");
     }
     return(new EcmaArray(parts.Select((v, i) => {
         RuntimeObject obj = v.ToValue().ToObject();
         if (annotations[i] != null)
         {
             obj.CreateDataPropertyOrThrow(annotationProperty, annotations[i]);
         }
         return obj.ToValue();
     }).ToArray()));
 }
Esempio n. 5
0
        public static EcmaValue Assign(EcmaValue target, params EcmaValue[] sources)
        {
            Guard.RequireObjectCoercible(target);
            RuntimeObject obj = ObjectConstructor.Object(null, target).ToObject();

            foreach (EcmaValue source in sources)
            {
                if (!source.IsNullOrUndefined)
                {
                    foreach (EcmaPropertyEntry e in source.ToObject().GetEnumerableOwnProperties(true))
                    {
                        obj.CreateDataPropertyOrThrow(e.Key, e.Value);
                    }
                }
            }
            return(obj);
        }