Ejemplo n.º 1
0
        private EcmaObject ReadObject()
        {
            EcmaObject obj = new EcmaObject();

            if (ReadToken() != '}')
            {
                do
                {
                    if (ch != '"')
                    {
                        throw GetException();
                    }
                    string key = ReadString();
                    if (ch != ':' || ReadToken() == -1)
                    {
                        throw GetException();
                    }
                    obj.CreateDataPropertyOrThrow(key, ReadValue());
                    switch (ch)
                    {
                    case '}':
                        goto end;

                    case ',':
                        continue;

                    default:
                        throw GetException();
                    }
                } while (ReadToken() != -1);
            }
end:
            ReadToken();
            return(obj);
        }
Ejemplo n.º 2
0
        public void Serialize(EcmaValue value, TextWriter writer)
        {
            RuntimeObject holder = new EcmaObject();

            holder.CreateDataProperty(String.Empty, new EcmaValue(value));
            SerializeJsonProperty(writer, new Stack <RuntimeObject>(), holder, String.Empty);
        }
Ejemplo n.º 3
0
        public static EcmaValue CreateIterResultObject(EcmaValue value, bool done)
        {
            EcmaObject o = new EcmaObject();

            o.CreateDataProperty(WellKnownProperty.Value, value);
            o.CreateDataProperty(WellKnownProperty.Done, done);
            return(o);
        }
Ejemplo n.º 4
0
        public static EcmaValue Parse(EcmaValue value, EcmaValue reviver)
        {
            EcmaValue unfiltered = Parse(value.ToStringOrThrow());

            if (!reviver.IsCallable)
            {
                return(unfiltered);
            }
            RuntimeObject root = new EcmaObject();

            root.CreateDataPropertyOrThrow(String.Empty, unfiltered);
            return(InternalizeJsonProperty(root, String.Empty, reviver));
        }
Ejemplo n.º 5
0
        public static EcmaValue FromEntries(EcmaValue iterator)
        {
            EcmaObject obj = new EcmaObject();

            foreach (EcmaValue entry in iterator.ForOf())
            {
                if (entry.Type != EcmaValueType.Object)
                {
                    throw new EcmaTypeErrorException(InternalString.Error.EntryNotObject);
                }
                EcmaValue key   = entry[0];
                EcmaValue value = entry[1];
                obj.CreateDataProperty(EcmaPropertyKey.FromValue(key), value);
            }
            return(obj);
        }
Ejemplo n.º 6
0
        public static EcmaValue CloneValue(EcmaValue value, EcmaValue[] transfer, RuntimeRealm targetRealm)
        {
            Guard.ArgumentNotNull(targetRealm, "targetRealm");
            bool isPrimitive = value.Type != EcmaValueType.Object;

            RuntimeObject[] transferList = transfer != null?transfer.Select(v => v.ToObject()).ToArray() : new RuntimeObject[0];

            RuntimeObject obj;

            if (isPrimitive)
            {
                obj     = new EcmaObject();
                obj[""] = value;
            }
            else
            {
                obj = value.ToObject();
            }
            obj = obj.Clone(targetRealm, transferList);
            return(isPrimitive ? obj[""] : obj);
        }