Exemple #1
0
        public IJsValue Evaluate(IEnvironment environment)
        {
            // TODO: Throw on cast failure
            var inspected = Inspected.Evaluate(environment) as IJsObject;
            if (inspected == null)
            {
                // Note: 'for (var m in undefined)' and 'for (var m in null)' is allowed...
                return JsUndefined.Value;
            }

            var propertyNames = (inspected.GetProperties()
                .Where(pd => pd.Enumerable)
                .Select(pd => pd.Name)
                .Distinct())
                .ToList();

            var bindingName = ((IAstWithName) Binding).Name;

            var bindingEnvironment = environment;
            if (DeclareBinding)
            {
                bindingEnvironment = new Environment(environment);
                bindingEnvironment.CreateReference(bindingName, JsUndefined.Value);
            }

            foreach (var propertyName in propertyNames)
            {
                bindingEnvironment.GetReference(bindingName).SetValue(null, environment.CreateString(propertyName));

                Block.Evaluate(bindingEnvironment);

                if (bindingEnvironment.ControlFlow.Break)
                {
                    break;
                }
                if (bindingEnvironment.ControlFlow.Return)
                {
                    break;
                }
            }
            return JsUndefined.Value;
        }
Exemple #2
0
        public override IJsValue Apply(IJsValue @this, IList<IJsValue> arguments)
        {
            if (Body == null)
            {
                return JsUndefined.Value;
            }
            var applyEnvironment =
                new Environment(
                    new BoundArgumentsEnvironment(
                        new FunctionEnvironment(Environment,
                                                this,
                                                @this,
                                                arguments),
                        Arguments,
                        arguments
                        )
                    );

            return Body.Evaluate(applyEnvironment);
        }