Exemplo n.º 1
0
        public static EcmaValue Set(EcmaValue target, EcmaValue key, EcmaValue value, EcmaValue?receiver = default)
        {
            Guard.ArgumentIsObject(target);
            RuntimeObject obj = target.ToObject();

            return(obj.Set(EcmaPropertyKey.FromValue(key), value, receiver.HasValue ? receiver.Value.ToObject() : obj));
        }
Exemplo n.º 2
0
 public static EcmaValue DefineSetter([This] EcmaValue thisValue, EcmaValue key, EcmaValue setter)
 {
     Guard.RequireObjectCoercible(thisValue);
     return(thisValue.ToObject().DefineOwnProperty(EcmaPropertyKey.FromValue(key),
                                                   new EcmaPropertyDescriptor {
         Set = setter
     }));
 }
Exemplo n.º 3
0
        public static EcmaValue PropertyIsEnumerable([This] EcmaValue thisValue, EcmaValue key)
        {
            Guard.RequireObjectCoercible(thisValue);
            EcmaPropertyKey        pk = EcmaPropertyKey.FromValue(key);
            EcmaPropertyDescriptor pd = thisValue.ToObject().GetOwnProperty(pk);

            return(pd != null && pd.Enumerable);
        }
Exemplo n.º 4
0
 public EcmaValue this[EcmaValue key] {
     get { return(this[EcmaPropertyKey.FromValue(key)]); }
     set { this[EcmaPropertyKey.FromValue(key)] = value; }
 }
Exemplo n.º 5
0
        public static EcmaValue GetOwnPropertyDescriptor(EcmaValue target, EcmaValue key)
        {
            Guard.ArgumentIsObject(target);
            EcmaPropertyDescriptor descriptor = target.ToObject().GetOwnProperty(EcmaPropertyKey.FromValue(key));

            return(descriptor != null?descriptor.ToValue() : default);
Exemplo n.º 6
0
 public static EcmaValue Has(EcmaValue target, EcmaValue key)
 {
     Guard.ArgumentIsObject(target);
     return(target.ToObject().HasProperty(EcmaPropertyKey.FromValue(key)));
 }
Exemplo n.º 7
0
 public override IEnumerable <EcmaPropertyKey> GetOwnPropertyKeys()
 {
     return(Target.Keys.OfType <object>().Select(v => new EcmaValue(v)).Where(v => EcmaPropertyKey.IsPropertyKey(v)).Select(v => EcmaPropertyKey.FromValue(v)).Concat(base.GetOwnPropertyKeys()));
 }
Exemplo n.º 8
0
        public override IEnumerable <EcmaPropertyKey> GetOwnPropertyKeys()
        {
            RuntimeObject target = ThrowIfProxyRevoked();
            RuntimeObject trap   = handler.GetMethod(WellKnownProperty.OwnKeys);

            if (trap == null)
            {
                return(target.GetOwnPropertyKeys());
            }
            EcmaValue resultArray = trap.Call(handler, target);

            Guard.ArgumentIsObject(resultArray);
            List <EcmaPropertyKey> list = new List <EcmaPropertyKey>();
            long len = resultArray[WellKnownProperty.Length].ToLength();

            for (long i = 0; i < len; i++)
            {
                EcmaValue value = resultArray[i];
                if (!EcmaPropertyKey.IsPropertyKey(value))
                {
                    throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
                }
                EcmaPropertyKey key = EcmaPropertyKey.FromValue(value);
                if (list.Contains(key))
                {
                    throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
                }
                list.Add(key);
            }

            List <EcmaPropertyKey> targetKeys                = new List <EcmaPropertyKey>(target.GetOwnPropertyKeys());
            List <EcmaPropertyKey> targetConfigurableKeys    = new List <EcmaPropertyKey>();
            List <EcmaPropertyKey> targetNonConfigurableKeys = new List <EcmaPropertyKey>();

            foreach (EcmaPropertyKey key in targetKeys)
            {
                EcmaPropertyDescriptor descriptor = target.GetOwnProperty(key);
                (descriptor.Configurable != false ? targetConfigurableKeys : targetNonConfigurableKeys).Add(key);
            }
            if (target.IsExtensible && targetNonConfigurableKeys.Count == 0)
            {
                return(list);
            }
            if (!targetNonConfigurableKeys.TrueForAll(list.Contains))
            {
                throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
            }
            if (target.IsExtensible)
            {
                return(list);
            }
            if (!targetConfigurableKeys.TrueForAll(list.Contains))
            {
                throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
            }
            if (!list.TrueForAll(targetKeys.Contains))
            {
                throw new EcmaTypeErrorException(InternalString.Error.InvalidTrapResult);
            }
            return(list);
        }
Exemplo n.º 9
0
        public static EcmaValue LookupGetter([This] EcmaValue thisValue, EcmaValue key)
        {
            Guard.RequireObjectCoercible(thisValue);
            EcmaPropertyDescriptor descriptor = thisValue.ToObject().GetOwnProperty(EcmaPropertyKey.FromValue(key));

            return(descriptor.IsAccessorDescriptor ? descriptor.Get : default);
Exemplo n.º 10
0
 public static EcmaValue HasOwnProperty([This] EcmaValue thisValue, EcmaValue key)
 {
     Guard.RequireObjectCoercible(thisValue);
     return(thisValue.HasOwnProperty(EcmaPropertyKey.FromValue(key)));
 }