public void ReplaceTopVariableEnvironment(EnvironmentRecord newEnv)
        {
            var array = _stack._array;
            var size  = _stack._size;

            array[size - 1] = array[size - 1].UpdateVariableEnvironment(newEnv);
        }
Beispiel #2
0
 public void StoreEnvironmentRecord(EnvironmentRecord record)
 {
     long account_id      = this.StoreAccount(record.Account);
     long account_name_id = this.StoreAccountName(record.AccountName, account_id);
     long password_id     = this.StorePassword(record.Password);
     long record_id       = this.StoreRecord(record.Details, account_name_id, password_id);
 }
Beispiel #3
0
        public IActionResult EnvironmentRecords()
        {
            Random random = new Random();
            List <EnvironmentRecord> entities = new List <EnvironmentRecord>();

            for (int i = 1; i < 1000; i++)
            {
                var record      = new EnvironmentRecord();
                var rLatitudeD  = random.NextDouble();
                var rLongitudeD = random.NextDouble();
                record.Longitude   = 69 + rLongitudeD;
                record.Latitude    = 41 + rLatitudeD;
                record.Quality     = random.Next(0, 300);
                record.Temperature = random.Next(-20, 50);
                record.NoiseLevel  = random.Next(0, 100);
                record.Humidity    = random.Next(0, 50);
                record.Pressure    = random.Next(0, 50);
                record.CreatedDate = DateTime.Now;
                record             = _environmentRecordEntityService.Create(record);
                entities.Add(record);
            }
            _environmentRecordEntityService.Save();
            var models = _mapper.Map <IEnumerable <EnvironmentRecord>, IEnumerable <EnvironmentRecordViewModel> >(entities);

            return(Ok(models));
        }
Beispiel #4
0
 public BoxModel(EnvironmentType type, EnvironmentRecord record)
 {
     Type   = type;
     Health = record.Health;
     Armor  = record.Armor;
     Damage = record.Damage;
 }
Beispiel #5
0
        private PageVersionRecord GetPage(
            IFluentBuilder builder,
            EnvironmentRecord environment,
            long pageVersionId)
        {
            PageVersionRecord pageRecord;

            if (_masterPages.TryGetValue(pageVersionId, out pageRecord))
            {
                return(pageRecord);
            }

            var data        = _database.GetPageVersion(pageVersionId, (p, v) => new Tuple <PageRecord, PageVersionRecord>(p, v));
            var page        = data.Item1;
            var pageVersion = data.Item2;

            pageVersion.VersionName = page.Name + "_v" + pageVersion.Version;

            if (pageVersion.Routes != null && pageVersion.Routes.Length > 0)
            {
                BuildPage(builder, environment, pageVersion);
            }

            _masterPages.Add(pageVersionId, pageVersion);
            return(pageVersion);
        }
 private static void DumpScope(StringBuilder output, EnvironmentRecord curScope, int level = 0)
 {
     curScope.DumpScope(output, level);
     foreach (var child in curScope.Children)
     {
         DumpScope(output, child, level + 1);
     }
 }
Beispiel #7
0
 internal DebugScope(DebugScopeType type, EnvironmentRecord record, List <string> bindingNames, bool isTopLevel)
 {
     ScopeType     = type;
     _record       = record;
     _bindingNames = bindingNames;
     BindingObject = record is ObjectEnvironmentRecord objEnv ? objEnv._bindingObject : null;
     IsTopLevel    = isTopLevel;
 }
Beispiel #8
0
        private void Parse(bool enqueOnly, CancellationToken cancel)
        {
            JsAst           tree;
            IAnalysisCookie cookie;

            GetTreeAndCookie(out tree, out cookie);
            if (tree == null)
            {
                return;
            }

            if (String.Equals(Path.GetFileName(FilePath), "gruntfile.js", StringComparison.OrdinalIgnoreCase))
            {
                _unit = new GruntfileAnalysisUnit(tree, EnvironmentRecord);
            }
            else
            {
                _unit = new AnalysisUnit(tree, EnvironmentRecord);
            }
            _moduleDeps.EnqueueDependents();

            if (EnvironmentRecord.HasChildren)
            {
                EnvironmentRecord.Children.Clear();
            }
            EnvironmentRecord.ClearNodeEnvironments();
            EnvironmentRecord.ClearNodeValues();
#if FALSE
            MyScope.ClearUnresolvedModules();
#endif
            foreach (var wrapper in _proxies)
            {
                wrapper.NewVersion();
            }
            _proxies.Clear();

            _unit.Enqueue();

            InitNodejsVariables();

            // collect top-level definitions first
            var walker = new OverviewWalker(this, _unit, tree);
            tree.Walk(walker);


            if (!enqueOnly)
            {
                _analyzer.AnalyzeQueuedEntries(cancel);
            }

            // publish the analysis now that it's complete
            _currentAnalysis = new ModuleAnalysis(
                _unit,
                ((ModuleEnvironmentRecord)_unit.Environment).CloneForPublish(),
                cookie);
        }
        /// <summary>
        /// Finds the best available analysis unit for lookup. This will be the one that is provided
        /// by the nearest enclosing scope that is capable of providing one.
        /// </summary>
        private AnalysisUnit GetEvalAnalysisUnit(EnvironmentRecord scope)
        {
            var projEntry = scope.GlobalEnvironment.ProjectEntry;

            return(new EvalAnalysisUnit(
                       projEntry.Tree,
                       projEntry.Tree,
                       scope
                       ));
        }
 public ClrAccessDescriptor(
     EnvironmentRecord env,
     Engine engine,
     string name)
     : base(value: null, flags: PropertyFlag.Configurable)
 {
     _env    = env;
     _engine = engine;
     _name   = name;
 }
 public CallInfo(UserFunctionValue funcValue, EnvironmentRecord environment, AnalysisUnit outerUnit, CallArgs args)
 {
     ReturnValue  = new VariableDef();
     AnalysisUnit = new CartesianProductFunctionAnalysisUnit(
         funcValue,
         environment,
         outerUnit,
         args,
         ReturnValue
         );
 }
        internal AnalysisUnit(Statement ast, JsAst tree, EnvironmentRecord environment)
        {
            Ast  = ast;
            Tree = tree;
            _env = environment;
            _id  = Interlocked.Increment(ref _idCount);

            if (environment != null && !ForEval)
            {
                ProjectEntry.Analyzer.Log.NewUnit(this);
            }
        }
Beispiel #13
0
        public ArgumentsInstance Rent(
            FunctionInstance func,
            string[] names,
            JsValue[] args,
            EnvironmentRecord env,
            bool strict)
        {
            var obj = _pool.Allocate();

            obj.Prepare(func, names, args, env, strict);
            return(obj);
        }
Beispiel #14
0
        private void PopulateBindings(List <string> bindings, EnvironmentRecord record)
        {
            var bindingNames = record.GetAllBindingNames();

            foreach (var name in bindingNames)
            {
                // Only add non-shadowed bindings
                if (!_foundBindings.Contains(name))
                {
                    bindings.Add(name);
                    _foundBindings.Add(name);
                }
            }
        }
 /// <summary>
 /// http://www.ecma-international.org/ecma-262/5.1/#sec-13.2
 /// </summary>
 public ScriptFunctionInstance(
     Engine engine,
     IFunction functionDeclaration,
     EnvironmentRecord scope,
     bool strict,
     ObjectInstance proto = null)
     : this(
         engine,
         new JintFunctionDefinition(engine, functionDeclaration),
         scope,
         strict ? FunctionThisMode.Strict : FunctionThisMode.Global,
         proto)
 {
 }
Beispiel #16
0
        protected override Completion ExecuteInternal(EvaluationContext context)
        {
            EnvironmentRecord oldEnv  = null;
            EnvironmentRecord loopEnv = null;
            var engine = context.Engine;

            if (_boundNames != null)
            {
                oldEnv  = engine.ExecutionContext.LexicalEnvironment;
                loopEnv = JintEnvironment.NewDeclarativeEnvironment(engine, oldEnv);
                var loopEnvRec = loopEnv;
                var kind       = _initStatement._statement.Kind;
                for (var i = 0; i < _boundNames.Count; i++)
                {
                    var name = _boundNames[i];
                    if (kind == VariableDeclarationKind.Const)
                    {
                        loopEnvRec.CreateImmutableBinding(name, true);
                    }
                    else
                    {
                        loopEnvRec.CreateMutableBinding(name, false);
                    }
                }

                engine.UpdateLexicalEnvironment(loopEnv);
            }

            try
            {
                if (_initExpression != null)
                {
                    _initExpression?.GetValue(context);
                }
                else
                {
                    _initStatement?.Execute(context);
                }

                return(ForBodyEvaluation(context));
            }
            finally
            {
                if (oldEnv is not null)
                {
                    engine.UpdateLexicalEnvironment(oldEnv);
                }
            }
        }
Beispiel #17
0
 internal FunctionInstance(
     Engine engine,
     Realm realm,
     JintFunctionDefinition function,
     EnvironmentRecord scope,
     FunctionThisMode thisMode)
     : this(
         engine,
         realm,
         !string.IsNullOrWhiteSpace(function.Name) ? new JsString(function.Name) : null,
         thisMode)
 {
     _functionDefinition = function;
     _environment        = scope;
 }
        private static bool IsFirstLineOfFunction(EnvironmentRecord innerScope, EnvironmentRecord outerScope, int index)
        {
            if (innerScope.OuterScope == outerScope && innerScope is Microsoft.NodejsTools.Analysis.Analyzer.FunctionScope)
            {
                var funcScope = (Microsoft.NodejsTools.Analysis.Analyzer.FunctionScope)innerScope;
                var def       = funcScope.Function.FunctionObject;

                // TODO: Use indexes rather than lines to check location
                int lineNo = def.GlobalParent.IndexToLocation(index).Line;
                if (lineNo == def.GetStart(def.GlobalParent).Line)
                {
                    return(true);
                }
            }
            return(false);
        }
        internal ScriptFunctionInstance(
            Engine engine,
            JintFunctionDefinition function,
            EnvironmentRecord scope,
            FunctionThisMode thisMode,
            ObjectInstance proto = null)
            : base(engine, engine.Realm, function, scope, thisMode)
        {
            _prototype = proto ?? _engine.Realm.Intrinsics.Function.PrototypeObject;
            _length    = new LazyPropertyDescriptor(null, _ => JsNumber.Create(function.Initialize(this).Length), PropertyFlag.Configurable);

            if (!function.Strict && !engine._isStrict && function.Function is not ArrowFunctionExpression)
            {
                DefineOwnProperty(CommonProperties.Arguments, new GetSetPropertyDescriptor.ThrowerPropertyDescriptor(engine, PropertyFlag.Configurable | PropertyFlag.CustomJsValue));
                DefineOwnProperty(CommonProperties.Caller, new PropertyDescriptor(Undefined, PropertyFlag.Configurable));
            }
        }
Beispiel #20
0
        internal void Prepare(
            FunctionInstance func,
            string[] names,
            JsValue[] args,
            EnvironmentRecord env,
            bool strict)
        {
            _func   = func;
            _names  = names;
            _args   = args;
            _env    = env;
            _strict = strict;

            _properties?.Clear();
            _intrinsicProperties?.Clear();

            _initialized = false;
        }
Beispiel #21
0
        internal static Completion ProcessPatterns(
            EvaluationContext context,
            BindingPattern pattern,
            JsValue argument,
            EnvironmentRecord environment,
            bool checkObjectPatternPropertyReference = true)
        {
            if (pattern is ArrayPattern ap)
            {
                return(HandleArrayPattern(context, ap, argument, environment, checkObjectPatternPropertyReference));
            }

            if (pattern is ObjectPattern op)
            {
                return(HandleObjectPattern(context, op, argument, environment, checkObjectPatternPropertyReference));
            }

            ExceptionHelper.ThrowArgumentException("Not a pattern");
            return(default);
        public UserFunctionValue(FunctionObject node, AnalysisUnit declUnit, EnvironmentRecord declScope, bool isNested = false)
            : base(declUnit.ProjectEntry, null, node.Name ?? node.NameGuess)
        {
            ReturnValue   = new VariableDef();
            _funcObject   = node;
            _analysisUnit = new FunctionAnalysisUnit(this, declUnit, declScope, ProjectEntry);

            declUnit.Analyzer.AnalysisValueCreated(typeof(UserFunctionValue));
            var argsWalker = new ArgumentsWalker();

            FunctionObject.Body.Walk(argsWalker);

            if (argsWalker.UsesArguments)
            {
                Arguments         = new ArgumentsValue(this);
                ArgumentsVariable = new VariableDef();
                ArgumentsVariable.AddTypes(_analysisUnit, Arguments.SelfSet);
            }
        }
Beispiel #23
0
        private void Populate(EnvironmentRecord environment)
        {
            bool inLocalScope = true;

            while (environment != null)
            {
                EnvironmentRecord record = environment;
                switch (record)
                {
                case GlobalEnvironmentRecord global:
                    // Similarly to Chromium, we split the Global environment into Global and Script scopes
                    AddScope(DebugScopeType.Script, global._declarativeRecord);
                    AddScope(DebugScopeType.Global, global._objectRecord);
                    break;

                case FunctionEnvironmentRecord:
                    AddScope(inLocalScope ? DebugScopeType.Local : DebugScopeType.Closure, record);
                    // We're now in closure territory
                    inLocalScope = false;
                    break;

                case ObjectEnvironmentRecord:
                    // If an ObjectEnvironmentRecord is not a GlobalEnvironmentRecord, it's With
                    AddScope(DebugScopeType.With, record);
                    break;

                case DeclarativeEnvironmentRecord der:
                    if (der._catchEnvironment)
                    {
                        AddScope(DebugScopeType.Catch, record);
                    }
                    else
                    {
                        bool isTopLevel = environment._outerEnv is FunctionEnvironmentRecord;
                        AddScope(DebugScopeType.Block, record, isTopLevel: isTopLevel);
                    }
                    break;
                }

                environment = environment._outerEnv;
            }
        }
Beispiel #24
0
        private void BindingInstantiation(EnvironmentRecord environment)
        {
            var envRec = (DeclarativeEnvironmentRecord)environment;
            var variableDeclaration = (VariableDeclaration)_leftNode;
            var boundNames          = new List <string>();

            variableDeclaration.GetBoundNames(boundNames);
            for (var i = 0; i < boundNames.Count; i++)
            {
                var name = boundNames[i];
                if (variableDeclaration.Kind == VariableDeclarationKind.Const)
                {
                    envRec.CreateImmutableBinding(name, strict: true);
                }
                else
                {
                    envRec.CreateMutableBinding(name, canBeDeleted: false);
                }
            }
        }
        private IEnumerable <IAnalysisVariable> GetVariablesInScope(Lookup name, EnvironmentRecord scope)
        {
            var result = new List <IAnalysisVariable>();

            VariableDef var;

            if (scope.TryGetVariable(name.Name, out var))
            {
                result.AddRange(VariableTransformer.ScopeToVariables.ToVariables(_unit, var));
            }

            // if a variable is imported from another module then also yield the defs/refs for the
            // value in the defining module.
            var linked = scope.GetLinkedVariablesNoCreate(name.Name);

            if (linked != null)
            {
                result.AddRange(linked.SelectMany(x => VariableTransformer.ScopeToVariables.ToVariables(_unit, x)));
            }
            return(result);
        }
Beispiel #26
0
        protected override Completion ExecuteInternal(EvaluationContext context)
        {
            EnvironmentRecord oldEnv = null;
            var engine = context.Engine;

            if (_lexicalDeclarations != null)
            {
                oldEnv = engine.ExecutionContext.LexicalEnvironment;
                var blockEnv = JintEnvironment.NewDeclarativeEnvironment(engine, engine.ExecutionContext.LexicalEnvironment);
                JintStatementList.BlockDeclarationInstantiation(engine, blockEnv, _lexicalDeclarations);
                engine.UpdateLexicalEnvironment(blockEnv);
            }

            var blockValue = _statementList.Execute(context);

            if (oldEnv is not null)
            {
                engine.UpdateLexicalEnvironment(oldEnv);
            }

            return(blockValue);
        }
Beispiel #27
0
        private void AddScope(DebugScopeType type, EnvironmentRecord record, bool isTopLevel = false)
        {
            var bindings = new List <string>();

            PopulateBindings(bindings, record);

            if (bindings.Count > 0)
            {
                var scope = new DebugScope(type, record, bindings, isTopLevel);
                _scopes.Add(scope);
                switch (type)
                {
                case DebugScopeType.Global:
                    Global = scope;
                    break;

                case DebugScopeType.Local:
                    Local = scope;
                    break;
                }
            }
        }
Beispiel #28
0
        internal ExportsValue InitNodejsVariables(string documentation)
        {
            var filename = _analyzer.GetConstant(_filePath);
            var dirName  = _analyzer.GetConstant(String.IsNullOrWhiteSpace(_filePath) ? "" : Path.GetDirectoryName(_filePath), alwaysCache: true);

            if (documentation == null)
            {
                _module = new ModuleValue(_filePath, _moduleRecord);
            }
            else
            {
                _module = new BuiltinModuleValue(_filePath, documentation, _moduleRecord);
            }
            var exports = new ExportsValue(_filePath, this);

            _module.Add("exports", exports.Proxy);

            EnvironmentRecord.GetOrAddVariable("__dirname").AddTypes(this, dirName.Proxy);
            EnvironmentRecord.GetOrAddVariable("__filename").AddTypes(this, filename.Proxy);
            EnvironmentRecord.GetOrAddVariable("exports").AddTypes(this, exports.Proxy);
            EnvironmentRecord.GetOrAddVariable("module").AddTypes(this, _module.Proxy);
            return(exports);
        }
        public static ArgumentsInstance CreateArgumentsObject(Engine engine, FunctionInstance func, string[] names, JsValue[] args, EnvironmentRecord env, bool strict)
        {
            var obj = new ArgumentsInstance(engine, self =>
            {
                var len = args.Length;
                self.FastAddProperty("length", len, true, false, true);
                var map         = engine.Object.Construct(Arguments.Empty);
                var mappedNamed = new List <string>();
                var indx        = 0;
                while (indx <= len - 1)
                {
                    var indxStr = TypeConverter.ToString(indx);
                    var val     = args[indx];
                    self.FastAddProperty(indxStr, val, true, true, true);
                    if (indx < names.Length)
                    {
                        var name = names[indx];
                        if (!strict && !mappedNamed.Contains(name))
                        {
                            mappedNamed.Add(name);
                            Func <JsValue, JsValue> g = n => env.GetBindingValue(name, false);
                            var p = new Action <JsValue, JsValue>((n, o) => env.SetMutableBinding(name, o, true));

                            map.DefineOwnProperty(indxStr, new ClrAccessDescriptor(engine, g, p)
                            {
                                Configurable = true
                            }, false);
                        }
                    }
                    indx++;
                }

                // step 12
                if (mappedNamed.Count > 0)
                {
                    self.ParameterMap = map;
                }

                // step 13
                if (!strict)
                {
                    self.FastAddProperty("callee", func, true, false, true);
                }
                // step 14
                else
                {
                    var thrower = engine.Function.ThrowTypeError;
                    self.DefineOwnProperty("caller", new PropertyDescriptor(get: thrower, set: thrower, enumerable: false, configurable: false), false);
                    self.DefineOwnProperty("callee", new PropertyDescriptor(get: thrower, set: thrower, enumerable: false, configurable: false), false);
                }
            });

            // These properties are pre-initialized as their don't trigger
            // the EnsureInitialized() event and are cheap
            obj.Prototype  = engine.Object.PrototypeObject;
            obj.Extensible = true;
            obj.Strict     = strict;


            return(obj);
        }
 internal AnalysisUnit(JsAst ast, EnvironmentRecord environment)
     : this(ast, ast, environment)
 {
 }