// ECMA-262 section 15.4.4.5 //private StringBuilder join(mdr.DArray array) { return join(array, null); } private StringBuilder join(mdr.DObject obj, string separator) { if (obj == null) { throw new ArgumentException("Object is null!"); } if (separator == null) { separator = ","; } StringBuilder strBuilder = new StringBuilder(string.Empty); var lengthField = obj.GetFieldByFieldId(mdr.Runtime.Instance.LengthFieldId); var length = Operations.Convert.ToInt32.Run(ref lengthField); if (length == 0) { return(strBuilder); } var element_0 = obj.GetField(0); if (element_0.ValueType != mdr.ValueTypes.Undefined && element_0.ValueType != mdr.ValueTypes.Null) { strBuilder.Append(Operations.Convert.ToString.Run(ref element_0)); } for (int k = 1; k < length; k++) { strBuilder.Append(separator); var element_k = obj.GetField(k); if (element_k.ValueType != mdr.ValueTypes.Undefined && element_k.ValueType != mdr.ValueTypes.Null) { strBuilder.Append(Operations.Convert.ToString.Run(ref element_k)); } } return(strBuilder); }
public static mdr.DArray CreateArgumentsObject(ref mdr.CallFrame callFrame, mdr.DObject context) { var metadata = (JSFunctionMetadata)callFrame.Function.Metadata; Debug.Assert(metadata.Scope.HasArgumentsSymbol, "Invalid situation, created arguments for the wrong scope!"); mdr.DArray arguments = null; if (metadata.Scope.IsEvalFunction) { //Read from context var tmp = new mdr.DValue(); context.GetField(JSFunctionArguments.Name, ref tmp); arguments = tmp.AsDArray(); } else { arguments = CreateArgumentsObject(ref callFrame); var parameters = metadata.FunctionIR.Parameters; Debug.Assert(arguments.Length >= parameters.Count, "arguments array is not large enough to hold all arguments."); for (var i = parameters.Count - 1; i >= 0; --i) { var symbol = parameters[i].Symbol; var paramIndex = symbol.ParameterIndex; Debug.Assert(paramIndex == i, "Invalid situation!, Parameter indexes don't match!"); if (symbol.SymbolType == JSSymbol.SymbolTypes.ClosedOnLocal) { var pd = context.AddOwnPropertyDescriptorByFieldId(symbol.FieldId, mdr.PropertyDescriptor.Attributes.Accessor | mdr.PropertyDescriptor.Attributes.NotConfigurable); context.Fields[pd.Index].Set(new ArgumentAccessor(arguments, paramIndex)); } } if (metadata.Scope.HasEval) { context.SetField(JSFunctionArguments.Name, arguments); } } return(arguments); }