protected override void Initialize(EvaluationContext context) { var engine = context.Engine; var expression = (CallExpression)_expression; _calleeExpression = Build(engine, expression.Callee); var cachedArgumentsHolder = new CachedArgumentsHolder { JintArguments = new JintExpression[expression.Arguments.Count] };
protected override void Initialize() { var expression = (CallExpression)_expression; var cachedArgumentsHolder = new CachedArgumentsHolder { JintArguments = new JintExpression[expression.Arguments.Count] }; bool CanSpread(Node e) { return(e?.Type == Nodes.SpreadElement || e is AssignmentExpression ae && ae.Right?.Type == Nodes.SpreadElement); } bool cacheable = true; for (var i = 0; i < expression.Arguments.Count; i++) { var expressionArgument = expression.Arguments[i]; cachedArgumentsHolder.JintArguments[i] = Build(_engine, expressionArgument); cacheable &= expressionArgument.Type == Nodes.Literal; _hasSpreads |= CanSpread(expressionArgument); if (expressionArgument is ArrayExpression ae) { for (var elementIndex = 0; elementIndex < ae.Elements.Count; elementIndex++) { _hasSpreads |= CanSpread(ae.Elements[elementIndex]); } } } if (cacheable) { _cached = true; var arguments = System.Array.Empty <JsValue>(); if (cachedArgumentsHolder.JintArguments.Length > 0) { arguments = new JsValue[cachedArgumentsHolder.JintArguments.Length]; BuildArguments(cachedArgumentsHolder.JintArguments, arguments); } cachedArgumentsHolder.CachedArguments = arguments; } _cachedArguments = cachedArgumentsHolder; }