public int Push(CallStackElement item) { _stack.Push(item); if (_statistics.ContainsKey(item)) { return ++_statistics[item]; } else { _statistics.Add(item, 0); return 0; } }
public int Push(CallStackElement item) { _stack.Push(item); if (_statistics.ContainsKey(item)) { return(++_statistics[item]); } else { _statistics.Add(item, 0); return(0); } }
public void Visit(IncludeStmt includeStmt, object[] args) { kernel.RuntimeData.ScopeStack.Open(new LocalScope()); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CALL_FLAG); //kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_FORMAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_LOCAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(root.SubPlotMap[includeStmt.SubPlot].Content); CallStackElement elem = new CallStackElement(); elem.Destination = root.SubPlotMap[includeStmt.SubPlot]; elem.Location = includeStmt.Location; elem.ReturnDest = null; kernel.RuntimeData.CallStack.Push(elem); kernel.Next(); }
public void Visit(FunctionCallStmt funcCallStmt, object[] args) { FormalScope formalScope = new FormalScope(); foreach (KeyValuePair<string, Expr.Expression> actual in funcCallStmt.ParamMap) { Expr.RightValue rightValue = exprProcessor.Eval(actual.Value); formalScope.SetValue(actual.Key, rightValue); } kernel.RuntimeData.ScopeStack.Open(formalScope); kernel.RuntimeData.ScopeStack.Open(new LocalScope()); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CALL_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_LOCAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_FORMAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(root.FuncDefMap[funcCallStmt.Name].FuncDefContent); CallStackElement elem = new CallStackElement(); elem.Destination = root.FuncDefMap[funcCallStmt.Name]; elem.Location = funcCallStmt.Location; elem.ReturnDest = exprProcessor.GetVarName(funcCallStmt.ReturnDest); kernel.RuntimeData.CallStack.Push(elem); kernel.Next(); }
protected override object EvaluateInternal() { var callee = _calleeExpression.Evaluate(); var expression = (CallExpression)_expression; if (_isDebugMode) { _engine.DebugHandler.AddToDebugCallStack(expression); } // todo: implement as in http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.4 var cachedArguments = _cachedArguments; var arguments = System.Array.Empty <JsValue>(); if (_cached) { arguments = cachedArguments.CachedArguments; } else { if (cachedArguments.JintArguments.Length > 0) { if (_hasSpreads) { arguments = BuildArgumentsWithSpreads(cachedArguments.JintArguments); } else { arguments = _engine._jsValueArrayPool.RentArray(cachedArguments.JintArguments.Length); BuildArguments(cachedArguments.JintArguments, arguments); } } } var func = _engine.GetValue(callee, false); var r = callee as Reference; if (_maxRecursionDepth >= 0) { var stackItem = new CallStackElement(expression, func, r?.GetReferencedName()?.ToString() ?? "anonymous function"); var recursionDepth = _engine.CallStack.Push(stackItem); if (recursionDepth > _maxRecursionDepth) { _engine.CallStack.Pop(); ExceptionHelper.ThrowRecursionDepthOverflowException(_engine.CallStack, stackItem.ToString()); } } if (func._type == InternalTypes.Undefined) { ExceptionHelper.ThrowTypeError(_engine, r == null ? "" : $"Object has no method '{r.GetReferencedName()}'"); } if (!func.IsObject()) { if (!_engine._referenceResolver.TryGetCallable(_engine, callee, out func)) { ExceptionHelper.ThrowTypeError(_engine, r == null ? "" : $"Property '{r.GetReferencedName()}' of object is not a function"); } } if (!(func is ICallable callable)) { var message = $"{r?.GetReferencedName() ?? ""} is not a function"; return(ExceptionHelper.ThrowTypeError <object>(_engine, message)); } var thisObject = Undefined.Instance; if (r != null) { var baseValue = r.GetBase(); if ((baseValue._type & InternalTypes.ObjectEnvironmentRecord) == 0) { thisObject = r.GetThisValue(); } else { var env = (EnvironmentRecord)baseValue; thisObject = env.ImplicitThisValue(); } // is it a direct call to eval ? http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.2.1.1 if (r.GetReferencedName() == CommonProperties.Eval && callable is EvalFunctionInstance instance) { var value = instance.Call(thisObject, arguments, true); _engine._referencePool.Return(r); return(value); } } var result = callable.Call(thisObject, arguments); if (_isDebugMode) { _engine.DebugHandler.PopDebugCallStack(); } if (_maxRecursionDepth >= 0) { _engine.CallStack.Pop(); } if (!_cached && arguments.Length > 0) { _engine._jsValueArrayPool.ReturnArray(arguments); } _engine._referencePool.Return(r); return(result); }