예제 #1
0
        private JSValue deepGet(Context context, bool forWrite, int depth)
        {
            JSValue res = null;

            var defsl = depth - definitionScopeLevel;

            while (defsl > 0)
            {
                defsl--;
                context = context._parent;
            }

            if (context != cacheContext || cacheRes == null)
            {
                if (lexicalScope)
                {
                    if (context._variables == null || !context._variables.TryGetValue(name, out res))
                    {
                        return(JSValue.NotExists);
                    }
                }
                else
                {
                    res = context.GetVariable(name, forWrite);
                }

                if ((!forWrite && IsDefined) ||
                    (res._attributes & JSValueAttributesInternal.SystemObject) == 0)
                {
                    cacheContext = context;
                    cacheRes     = res;
                }
            }
            else
            {
                res = cacheRes;
            }

            if (forWrite && res.NeedClone)
            {
                res      = context.GetVariable(name, forWrite);
                cacheRes = res;
            }

            return(res);
        }
예제 #2
0
        internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                var nameStr = key.ToString();
                var res     = _context.GetVariable(nameStr, forWrite);
                return(res);
            }

            return(base.GetProperty(key, forWrite, memberScope));
        }
예제 #3
0
        protected internal virtual JSValue GetVariable(string name, bool forWrite)
        {
            JSValue res = null;

            bool fromProto = _variables == null || (!_variables.TryGetValue(name, out res) && (_parent != null));

            if (fromProto)
            {
                res = _parent.GetVariable(name, forWrite);
            }

            if (res == null) // значит вышли из глобального контекста
            {
                if (_parent == null)
                {
                    return(null);
                }
                else
                {
                    if (forWrite)
                    {
                        res = new JSValue()
                        {
                            _valueType = JSValueType.NotExists
                        };
                        _variables[name] = res;
                    }
                    else
                    {
                        res = GlobalContext._globalPrototype.GetProperty(name, false, PropertyScope.Common);
                        if (res._valueType == JSValueType.NotExistsInObject)
                        {
                            res._valueType = JSValueType.NotExists;
                        }
                    }
                }
            }
            else if (fromProto)
            {
                _objectSource = _parent._objectSource;
            }
            else
            {
                if (forWrite && res.NeedClone)
                {
                    res = res.CloneImpl(false);
                    _variables[name] = res;
                }
            }

            return(res);
        }
예제 #4
0
        internal JSValue Get(Context context, bool forWrite, int scopeLevel)
        {
            context._objectSource = null;

            if (((definitionScopeLevel | scopeLevel) & int.MinValue) != 0)
            {
                return(context.GetVariable(name, forWrite));
            }

            if (context == cacheContext && !forWrite)
            {
                return(cacheRes);
            }

            return(deepGet(context, forWrite, scopeLevel));
        }