public static Completion EvaluateCall(IValue func, IValue @ref, Arguments arguments, bool tailCall) { IValue thisValue; if (@ref is ReferenceValue reference) { if (reference.IsPropertyReference()) { thisValue = reference.GetThisValue(); } else { if (!(reference.baseValue is EnvironmentRecord envRec)) { throw new InvalidOperationException("Utils.EvaluateCall: reference.baseValue is not a recognized IReferenceable"); } thisValue = envRec.WithBaseObject(); } } else { thisValue = UndefinedValue.Instance; } var argList = arguments.ArgumentListEvaluation(); if (argList.IsAbrupt()) { return(argList); } if (!(func is Callable functionObject)) { return(Completion.ThrowTypeError("Utils.EvaluateCall: func must be a function object.")); } if (tailCall) { throw new NotImplementedException("Utils.EvaluateCall: tail calls not implemented"); } return(functionObject.Call(thisValue, argList.Other)); }