Ejemplo n.º 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);
 }
Ejemplo n.º 2
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));
        }