예제 #1
0
        private static ScriptValue Values([NotNull] ScriptArguments arg)
        {
            //https://tc39.github.io/ecma262/#sec-object.values
            var obj      = arg.Agent.ToObject(arg[0]);
            var nameList = EnumerableOwnProperties(arg.Agent, obj, EnumerateType.Value);

            return(ArrayIntrinsics.CreateArrayFromList(arg.Agent, nameList));
        }
예제 #2
0
        private static ScriptValue GetOwnPropertyKeys([NotNull] Agent agent, ScriptValue value, ScriptValue.Type type)
        {
            //https://tc39.github.io/ecma262/#sec-getownpropertykeys
            var obj      = agent.ToObject(value);
            var keys     = obj.OwnPropertyKeys();
            var nameList = keys.Where(x => x.ValueType == type);

            return(ArrayIntrinsics.CreateArrayFromList(agent, nameList));
        }
예제 #3
0
        private static ScriptValue OwnKeys([NotNull] ScriptArguments arg)
        {
            //https://tc39.github.io/ecma262/#sec-reflect.ownkeys
            if (!arg[0].IsObject)
            {
                throw arg.Agent.CreateTypeError();
            }

            var keys = ((ScriptObject)arg[0]).OwnPropertyKeys();

            return(ArrayIntrinsics.CreateArrayFromList(arg.Agent, keys));
        }
예제 #4
0
        private static IEnumerable <ScriptValue> EnumerableOwnProperties([NotNull] Agent agent, [NotNull] ScriptObject obj, EnumerateType type)
        {
            //https://tc39.github.io/ecma262/#sec-enumerableownproperties

            var ownKeys    = obj.OwnPropertyKeys();
            var properties = new List <ScriptValue>();

            foreach (var key in ownKeys)
            {
                if (key.IsString)
                {
                    var descriptor = obj.GetOwnProperty(key);
                    if (descriptor != null && descriptor.Enumerable)
                    {
                        switch (type)
                        {
                        case EnumerateType.Key:
                            properties.Add(key);
                            break;

                        case EnumerateType.Value:
                            properties.Add(obj.Get(key));
                            break;

                        case EnumerateType.KeyValue:
                            properties.Add(ArrayIntrinsics.CreateArrayFromList(agent, new[] { key, obj.Get(key) }));
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(type), type, null);
                        }
                    }
                }
            }
            return(properties);
        }