예제 #1
0
        internal static IRef createSpecial(Context cx, object obj, string name)
        {
            IScriptable target = ScriptConvert.ToObjectOrNull(cx, obj);

            if (target == null)
            {
                throw ScriptRuntime.UndefReadError(obj, name);
            }

            Types type;

            if (name.Equals("__proto__"))
            {
                type = Types.Proto;
            }
            else if (name.Equals("__parent__"))
            {
                type = Types.Parent;
            }
            else
            {
                throw new ArgumentException(name);
            }

            if (!cx.HasFeature(Context.Features.ParentProtoProperties))
            {
                // Clear special after checking for valid name!
                type = Types.None;
            }

            return(new SpecialRef(target, type, name));
        }
예제 #2
0
        public IdEnumeration(object value, Context cx, bool enumValues)
        {
            obj = ScriptConvert.ToObjectOrNull(cx, value);
            if (obj != null)
            {
                // null or undefined do not cause errors but rather lead to empty
                // "for in" loop
                this.enumValues = enumValues;

                // enumInit should read all initial ids before returning
                // or "for (a.i in a)" would wrongly enumerate i in a as well
                ChangeObject();
            }
        }
예제 #3
0
        public object Set(Context cx, object value)
        {
            switch (type)
            {
            case Types.None:
                return(ScriptRuntime.setObjectProp(target, name, value, cx));

            case Types.Proto:
            case Types.Parent: {
                IScriptable obj = ScriptConvert.ToObjectOrNull(cx, value);
                if (obj != null)
                {
                    // Check that obj does not contain on its prototype/scope
                    // chain to prevent cycles
                    IScriptable search = obj;
                    do
                    {
                        if (search == target)
                        {
                            throw Context.ReportRuntimeErrorById("msg.cyclic.value", name);
                        }
                        if (type == Types.Proto)
                        {
                            search = search.GetPrototype();
                        }
                        else
                        {
                            search = search.ParentScope;
                        }
                    }while (search != null);
                }
                if (type == Types.Proto)
                {
                    target.SetPrototype(obj);
                }
                else
                {
                    target.ParentScope = obj;
                }
                return(obj);
            }

            default:
                throw Context.CodeBug();
            }
        }