private static FunctionObject MakeArgGetter(string name, EnvironmentRecord env) { var getter = Utils.CreateBuiltinFunction((@this, arguments) => { if (!(@this is GetterSetter thisObj)) { return(Completion.ThrowTypeError("Not allowed to call internal function on non getter/setter")); } return(thisObj.Env.GetBindingValue(thisObj.Name, false)); }, steps => new GetterSetter(steps, name, env)); return(getter); }
public Completion GetIdentifierReference(string name, bool strict) { var comp = EnvironmentRecord.HasBinding(name); if (comp.IsAbrupt()) { return(comp); } if (comp.Other == true) { return(Completion.NormalCompletion(new ReferenceValue(EnvironmentRecord, name, strict))); } else { if (Outer == null) { return(Completion.NormalCompletion(new ReferenceValue(UndefinedValue.Instance, name, strict))); } return(Outer.GetIdentifierReference(name, strict)); } }
public GetterSetter(Steps steps, string name, EnvironmentRecord env) : base(steps) { Name = name; Env = env; }
private Object CreateMappedArgumentsObject(FormalParameters formalParameters, IReadOnlyList <IValue> arguments, EnvironmentRecord env) { var map = Utils.ObjectCreate(null); var obj = new MappedArguments(map); var parameterNames = formalParameters.BoundNames(); int index; for (index = 0; index < arguments.Count; index++) { Utils.CreateDataProperty(obj, index.ToString(System.Globalization.CultureInfo.InvariantCulture), arguments[index]); } obj.DefinePropertyOrThrow("length", new PropertyDescriptor(new NumberValue(arguments.Count), true, false, true)); var mappedNames = new List <string>(); for (index = parameterNames.Count - 1; index >= 0; index--) { var name = parameterNames[index]; if (!mappedNames.Contains(name)) { mappedNames.Add(name); if (index < arguments.Count) { var g = MakeArgGetter(name, env); var p = MakeArgSetter(name, env); map.DefineOwnProperty(index.ToString(System.Globalization.CultureInfo.InvariantCulture), new PropertyDescriptor(p, g, false, true)); } } } DefinePropertyOrThrow("@@iterator", new PropertyDescriptor(Utils.CreateBuiltinFunction(ArrayPrototype.values), true, false, true)); DefinePropertyOrThrow("callee", new PropertyDescriptor(this, true, false, true)); return(obj); }