Пример #1
0
 private EcmaValue TransformValue(RuntimeObject holder, EcmaPropertyKey property, EcmaValue value)
 {
     if (value.Type == EcmaValueType.Object)
     {
         EcmaValue toJson = value[WellKnownProperty.ToJSON];
         if (toJson.IsCallable)
         {
             value = toJson.Call(value, property.ToValue());
         }
     }
     if (replacer != EcmaValue.Undefined)
     {
         value = replacer.Call(holder, property.ToValue(), value);
     }
     if (value.Type == EcmaValueType.Object)
     {
         EcmaValue primitive = EcmaValueUtility.UnboxPrimitiveObject(value);
         switch (primitive.Type)
         {
         case EcmaValueType.Number:
         case EcmaValueType.String:
         case EcmaValueType.Boolean:
             return(primitive);
         }
     }
     return(value);
 }
Пример #2
0
 public void HandleResult(PromiseState state, EcmaValue value)
 {
     if (!this.Handled)
     {
         PromiseCallback callback = state == PromiseState.Rejected ? OnReject : OnFulfill;
         EcmaValue       resolver = state == PromiseState.Rejected ? RejectCallback : ResolveCallback;
         this.Handled = true;
         if (callback != null)
         {
             value = callback(value);
         }
         resolver.Call(EcmaValue.Undefined, value);
     }
 }
Пример #3
0
        public static EcmaValue SetInterval(EcmaValue fn, EcmaValue milliseconds, params EcmaValue[] args)
        {
            int timeout = milliseconds == default ? 0 : milliseconds.ToNumber().ToInt32();

            if (timeout > 0)
            {
                timeout = 0;
            }
            if (timeout >= 0)
            {
                timeout = System.Math.Max(4, timeout);
            }
            RuntimeExecutionHandle handle = RuntimeExecution.Enqueue(() => fn.Call(Undefined, args), timeout, RuntimeExecutionFlags.Cancellable | RuntimeExecutionFlags.Recurring);

            return(handle.Id);
        }
Пример #4
0
        private static EcmaValue InternalizeJsonProperty(RuntimeObject holder, EcmaPropertyKey property, EcmaValue reviver)
        {
            EcmaValue value = holder.Get(property);

            if (value.Type == EcmaValueType.Object)
            {
                RuntimeObject obj = value.ToObject();
                if (EcmaArray.IsArray(value))
                {
                    for (long i = 0, length = value[WellKnownProperty.Length].ToLength(); i < length; i++)
                    {
                        EcmaValue newValue = InternalizeJsonProperty(obj, i, reviver);
                        if (newValue.Type == EcmaValueType.Undefined)
                        {
                            obj.Delete(i);
                        }
                        else
                        {
                            obj.CreateDataProperty(i, newValue);
                        }
                    }
                }
                else
                {
                    foreach (EcmaPropertyKey key in obj.GetEnumerableOwnPropertyKeys().ToArray())
                    {
                        EcmaValue newValue = InternalizeJsonProperty(obj, key, reviver);
                        if (newValue.Type == EcmaValueType.Undefined)
                        {
                            obj.Delete(key);
                        }
                        else
                        {
                            obj.CreateDataProperty(key, newValue);
                        }
                    }
                }
            }
            return(reviver.Call(holder, property.ToValue(), value));
        }